Skip to content

Commit 2d5cd1f

Browse files
keplervitalolaszakosmraszyk
authored
feat(station): configurable station initialization (#482)
Co-authored-by: olaszakos <olaszakos@gmail.com> Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com>
1 parent c735436 commit 2d5cd1f

File tree

34 files changed

+3035
-581
lines changed

34 files changed

+3035
-581
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/wallet/src/generated/station/station.did

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,14 +2715,6 @@ type MeResult = variant {
27152715
Err : Error;
27162716
};
27172717

2718-
// The admin that is created in the station during the init process.
2719-
type AdminInitInput = record {
2720-
// The name of the user.
2721-
name : text;
2722-
// The identity of the admin.
2723-
identity : principal;
2724-
};
2725-
27262718
// An input type for configuring the upgrader canister.
27272719
type SystemUpgraderInput = variant {
27282720
// An existing upgrader canister.
@@ -2752,10 +2744,32 @@ type InitAccountInput = record {
27522744
metadata : vec AccountMetadata;
27532745
};
27542746

2747+
// The permissions for the account.
2748+
type InitAccountPermissionsInput = record {
2749+
// Who can read the account information.
2750+
read_permission : Allow;
2751+
// Who can request updates to the account.
2752+
configs_permission : Allow;
2753+
// Who can request transfers from the account.
2754+
transfer_permission : Allow;
2755+
// The approval policy for updates to the account.
2756+
configs_request_policy : opt RequestPolicyRule;
2757+
// The approval policy for transfers from the account.
2758+
transfer_request_policy : opt RequestPolicyRule;
2759+
};
2760+
2761+
// The initial account to create when initializing the canister for the first time.
2762+
type InitAccountWithPermissionsInput = record {
2763+
// The initial account to create.
2764+
account_init : InitAccountInput;
2765+
// The permissions for the account.
2766+
permissions : InitAccountPermissionsInput;
2767+
};
2768+
27552769
// The initial assets to create when initializing the canister for the first time, e.g., after disaster recovery.
27562770
type InitAssetInput = record {
27572771
// The UUID of the asset, if not provided a new UUID will be generated.
2758-
id : UUID;
2772+
id : opt UUID;
27592773
// The name of the asset.
27602774
name : text;
27612775
// The blockchain identifier (e.g., `ethereum`, `bitcoin`, `icp`, etc.)
@@ -2770,24 +2784,133 @@ type InitAssetInput = record {
27702784
metadata : vec AssetMetadata;
27712785
};
27722786

2773-
// The init configuration for the canister.
2787+
// The input type for creating a user group when initializing the canister for the first time.
2788+
type InitUserGroupInput = record {
2789+
// The id of the user group, if not provided a new UUID will be generated.
2790+
id : opt UUID;
2791+
// The name of the user group, must be unique.
2792+
name : text;
2793+
};
2794+
2795+
// The input type for adding identities to a user.
2796+
type UserIdentityInput = record {
2797+
// The identity of the user.
2798+
identity : principal;
2799+
};
2800+
2801+
// The users to create when initializing the canister for the first time.
2802+
type InitUserInput = record {
2803+
// The id of the user, if not provided a new UUID will be generated.
2804+
id : opt UUID;
2805+
// The name of the user.
2806+
name : text;
2807+
// The identities of the user.
2808+
identities : vec UserIdentityInput;
2809+
// The user groups to associate with the user (optional).
2810+
// If not provided it defaults to the [`Admin`,`Operator`] groups if default user groups are created,
2811+
// i.e., when the field `initial_config` in `SystemInit` has the form of `WithAllDefaults` or `WithDefaultPolicies`.
2812+
groups : opt vec UUID;
2813+
// The status of the user (e.g. `Active`).
2814+
status : UserStatus;
2815+
};
2816+
2817+
// The init type for initializing the permissions when first creating the canister.
2818+
type InitPermissionInput = record {
2819+
// The resource that the permission is for.
2820+
resource : Resource;
2821+
// The allow rules for who can access the resource.
2822+
allow : Allow;
2823+
};
2824+
2825+
// The init type for adding a request approval policy when initializing the canister for the first time.
2826+
type InitRequestPolicyInput = record {
2827+
// The id of the request policy, if not provided a new UUID will be generated.
2828+
id : opt UUID;
2829+
// The request specifier that identifies what operation this policy is for (e.g. "transfer").
2830+
specifier : RequestSpecifier;
2831+
// The rule to use for the request approval evaluation (e.g. "quorum").
2832+
rule : RequestPolicyRule;
2833+
};
2834+
2835+
// The init type for adding a named rule when initializing the canister for the first time.
2836+
type InitNamedRuleInput = record {
2837+
// The id of the named rule, if not provided a new UUID will be generated.
2838+
id : opt UUID;
2839+
// The name of the named rule.
2840+
name : text;
2841+
// The description of the named rule.
2842+
description : opt text;
2843+
// The rule to use for the named rule.
2844+
rule : RequestPolicyRule;
2845+
};
2846+
2847+
// The initial configuration for the station.
2848+
//
2849+
// Unless the `Complete` variant is used, the station will be initialized with default user
2850+
// groups, named rules (aka. approval rules), request policies, permissions, and assets.
27742851
//
2775-
// Only used when installing the canister for the first time.
2852+
// The default user groups for the station will be:
2853+
// - `Admin` with the UUID "00000000-0000-4000-8000-000000000000"
2854+
// - `Operator` with the UUID "00000000-0000-4000-8000-000000000001"
2855+
//
2856+
// The default named rules for the station will be:
2857+
// - `Admin approval` with a specified admin quorum
2858+
// - `Operator approval` with a specified operator and admin quorum
2859+
//
2860+
type InitialConfig = variant {
2861+
// Initialize the station with default user groups, named rules, policies, permissions, and assets.
2862+
// This does not create an initial account.
2863+
WithAllDefaults : record {
2864+
// The initial users to create.
2865+
users : vec InitUserInput;
2866+
// The initial admin quorum in the admin level approval rule.
2867+
admin_quorum : nat16;
2868+
// The initial operator quorum in the operator level approval rule.
2869+
operator_quorum : nat16;
2870+
};
2871+
// Initialize the station with default user groups, named rules, policies, permissions.
2872+
WithDefaultPolicies : record {
2873+
// The initial users to create.
2874+
users : vec InitUserInput;
2875+
// The initial accounts to create.
2876+
accounts : vec InitAccountInput;
2877+
// The initial assets to create.
2878+
assets : vec InitAssetInput;
2879+
// The initial admin quorum in the admin level approval rule.
2880+
admin_quorum : nat16;
2881+
// The initial operator quorum in the operator level approval rule.
2882+
operator_quorum : nat16;
2883+
};
2884+
// Initialize the station with all custom entries.
2885+
Complete : record {
2886+
// The initial users to create.
2887+
users : vec InitUserInput;
2888+
// The initial user groups to create.
2889+
user_groups : vec InitUserGroupInput;
2890+
// The initial permissions to create.
2891+
permissions : vec InitPermissionInput;
2892+
// The initial request policies to create.
2893+
request_policies : vec InitRequestPolicyInput;
2894+
// The initial named rules to create.
2895+
named_rules : vec InitNamedRuleInput;
2896+
// The initial accounts to create.
2897+
accounts : vec InitAccountWithPermissionsInput;
2898+
// The initial assets to create.
2899+
assets : vec InitAssetInput;
2900+
// The initial disaster recovery committee to create.
2901+
disaster_recovery_committee : opt DisasterRecoveryCommittee;
2902+
};
2903+
};
2904+
27762905
type SystemInit = record {
27772906
// The name of the station.
27782907
name : text;
2779-
// The list of admin principals to be associated with the station.
2780-
admins : vec AdminInitInput;
2781-
// Quorum of admins for initial policies.
2782-
quorum : opt nat16;
27832908
// The upgrader configuration.
27842909
upgrader : SystemUpgraderInput;
2785-
// An optional additional controller of the station and upgrader canisters.
2910+
// An additional controller of the station and upgrader canisters (optional).
27862911
fallback_controller : opt principal;
2787-
// Optional initial accounts to create.
2788-
accounts : opt vec InitAccountInput;
2789-
// Optional initial assets to create.
2790-
assets : opt vec InitAssetInput;
2912+
// The initial configuration to apply.
2913+
initial_config: InitialConfig;
27912914
};
27922915

27932916
// The upgrade configuration for the canister.

apps/wallet/src/generated/station/station.did.d.ts

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export interface AddressBookEntryCallerPrivileges {
128128
'can_edit' : boolean,
129129
}
130130
export interface AddressBookMetadata { 'key' : string, 'value' : string }
131-
export interface AdminInitInput { 'name' : string, 'identity' : Principal }
132131
export interface Allow {
133132
'user_groups' : Array<UUID>,
134133
'auth_scope' : AuthScope,
@@ -729,15 +728,74 @@ export interface InitAccountInput {
729728
'assets' : Array<UUID>,
730729
'seed' : AccountSeed,
731730
}
731+
export interface InitAccountPermissionsInput {
732+
'configs_request_policy' : [] | [RequestPolicyRule],
733+
'read_permission' : Allow,
734+
'configs_permission' : Allow,
735+
'transfer_request_policy' : [] | [RequestPolicyRule],
736+
'transfer_permission' : Allow,
737+
}
738+
export interface InitAccountWithPermissionsInput {
739+
'permissions' : InitAccountPermissionsInput,
740+
'account_init' : InitAccountInput,
741+
}
732742
export interface InitAssetInput {
733-
'id' : UUID,
743+
'id' : [] | [UUID],
734744
'decimals' : number,
735745
'standards' : Array<string>,
736746
'metadata' : Array<AssetMetadata>,
737747
'name' : string,
738748
'blockchain' : string,
739749
'symbol' : string,
740750
}
751+
export interface InitNamedRuleInput {
752+
'id' : [] | [UUID],
753+
'name' : string,
754+
'rule' : RequestPolicyRule,
755+
'description' : [] | [string],
756+
}
757+
export interface InitPermissionInput { 'resource' : Resource, 'allow' : Allow }
758+
export interface InitRequestPolicyInput {
759+
'id' : [] | [UUID],
760+
'rule' : RequestPolicyRule,
761+
'specifier' : RequestSpecifier,
762+
}
763+
export interface InitUserGroupInput { 'id' : [] | [UUID], 'name' : string }
764+
export interface InitUserInput {
765+
'id' : [] | [UUID],
766+
'status' : UserStatus,
767+
'groups' : [] | [Array<UUID>],
768+
'name' : string,
769+
'identities' : Array<UserIdentityInput>,
770+
}
771+
export type InitialConfig = {
772+
'WithDefaultPolicies' : {
773+
'assets' : Array<InitAssetInput>,
774+
'admin_quorum' : number,
775+
'accounts' : Array<InitAccountInput>,
776+
'users' : Array<InitUserInput>,
777+
'operator_quorum' : number,
778+
}
779+
} |
780+
{
781+
'WithAllDefaults' : {
782+
'admin_quorum' : number,
783+
'users' : Array<InitUserInput>,
784+
'operator_quorum' : number,
785+
}
786+
} |
787+
{
788+
'Complete' : {
789+
'permissions' : Array<InitPermissionInput>,
790+
'assets' : Array<InitAssetInput>,
791+
'request_policies' : Array<InitRequestPolicyInput>,
792+
'user_groups' : Array<InitUserGroupInput>,
793+
'accounts' : Array<InitAccountWithPermissionsInput>,
794+
'disaster_recovery_committee' : [] | [DisasterRecoveryCommittee],
795+
'users' : Array<InitUserInput>,
796+
'named_rules' : Array<InitNamedRuleInput>,
797+
}
798+
};
741799
export interface ListAccountTransfersInput {
742800
'account_id' : UUID,
743801
'status' : [] | [TransferStatusType],
@@ -1384,12 +1442,9 @@ export type SystemInfoResult = { 'Ok' : { 'system' : SystemInfo } } |
13841442
{ 'Err' : Error };
13851443
export interface SystemInit {
13861444
'name' : string,
1387-
'assets' : [] | [Array<InitAssetInput>],
1445+
'initial_config' : InitialConfig,
13881446
'fallback_controller' : [] | [Principal],
13891447
'upgrader' : SystemUpgraderInput,
1390-
'accounts' : [] | [Array<InitAccountInput>],
1391-
'admins' : Array<AdminInitInput>,
1392-
'quorum' : [] | [number],
13931448
}
13941449
export type SystemInstall = { 'Upgrade' : SystemUpgrade } |
13951450
{ 'Init' : SystemInit };
@@ -1487,6 +1542,7 @@ export interface UserGroupCallerPrivileges {
14871542
'can_delete' : boolean,
14881543
'can_edit' : boolean,
14891544
}
1545+
export interface UserIdentityInput { 'identity' : Principal }
14901546
export type UserPrivilege = { 'AddUserGroup' : null } |
14911547
{ 'ListRequestPolicies' : null } |
14921548
{ 'ListNamedRules' : null } |

0 commit comments

Comments
 (0)