@cubist-labs/cubesigner-sdk 0.1.50 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +66 -13
  2. package/dist/src/client.d.ts +434 -7
  3. package/dist/src/client.js +1022 -18
  4. package/dist/src/ethers/index.d.ts +2 -4
  5. package/dist/src/ethers/index.js +11 -9
  6. package/dist/src/fido.d.ts +76 -0
  7. package/dist/src/fido.js +148 -0
  8. package/dist/src/index.d.ts +102 -30
  9. package/dist/src/index.js +126 -72
  10. package/dist/src/key.d.ts +15 -45
  11. package/dist/src/key.js +31 -93
  12. package/dist/src/mfa.d.ts +85 -14
  13. package/dist/src/mfa.js +158 -40
  14. package/dist/src/org.d.ts +237 -123
  15. package/dist/src/org.js +108 -213
  16. package/dist/src/paginator.d.ts +76 -0
  17. package/dist/src/paginator.js +99 -0
  18. package/dist/src/role.d.ts +76 -74
  19. package/dist/src/role.js +79 -136
  20. package/dist/src/schema.d.ts +1672 -520
  21. package/dist/src/schema.js +1 -1
  22. package/dist/src/schema_types.d.ts +103 -0
  23. package/dist/src/schema_types.js +3 -0
  24. package/dist/src/session/session_manager.js +2 -2
  25. package/dist/src/session/session_storage.js +1 -1
  26. package/dist/src/session/signer_session_manager.d.ts +16 -29
  27. package/dist/src/session/signer_session_manager.js +27 -78
  28. package/dist/src/signer_session.d.ts +232 -125
  29. package/dist/src/signer_session.js +149 -250
  30. package/dist/src/util.d.ts +20 -0
  31. package/dist/src/util.js +31 -2
  32. package/package.json +13 -11
  33. package/src/client.ts +1217 -7
  34. package/src/ethers/index.ts +11 -18
  35. package/src/index.ts +149 -101
  36. package/src/key.ts +28 -121
  37. package/src/mfa.ts +202 -0
  38. package/src/org.ts +126 -275
  39. package/src/paginator.ts +122 -0
  40. package/src/role.ts +108 -181
  41. package/src/schema.ts +1673 -520
  42. package/src/schema_types.ts +103 -0
  43. package/src/session/session_manager.ts +2 -2
  44. package/src/session/session_storage.ts +1 -1
  45. package/src/session/signer_session_manager.ts +38 -108
  46. package/src/signer_session.ts +164 -323
  47. package/src/util.ts +41 -0
package/dist/src/org.d.ts CHANGED
@@ -1,11 +1,19 @@
1
- import { CubeSigner, MfaRequestInfo } from ".";
2
- import { components } from "./client";
1
+ import { OrgInfo } from "./schema_types";
2
+ import { CubeSignerClient } from "./client";
3
3
  import { KeyType, Key } from "./key";
4
- import { MfaPolicy, Role } from "./role";
4
+ import { Role } from "./role";
5
+ import { PageOpts } from "./paginator";
5
6
  /** Organization id */
6
7
  export type OrgId = string;
7
8
  /** Org-wide policy */
8
- export type OrgPolicy = SourceIpAllowlistPolicy | OriginAllowlistPolicy | MaxDailyUnstakePolicy;
9
+ export type OrgPolicy = SourceIpAllowlistPolicy | OidcAuthSourcesPolicy | OriginAllowlistPolicy | MaxDailyUnstakePolicy;
10
+ /**
11
+ * Provides an allowlist of OIDC Issuers and audiences that are allowed to authenticate into this org.
12
+ * @example {"OidcAuthSources": { "https://accounts.google.com": [ "1234.apps.googleusercontent.com" ]}}
13
+ */
14
+ export interface OidcAuthSourcesPolicy {
15
+ OidcAuthSources: Record<string, string[]>;
16
+ }
9
17
  /**
10
18
  * Only allow requests from the specified origins.
11
19
  * @example {"OriginAllowlist": "*"}
@@ -27,31 +35,21 @@ export interface SourceIpAllowlistPolicy {
27
35
  export interface MaxDailyUnstakePolicy {
28
36
  MaxDailyUnstake: number;
29
37
  }
30
- type OrgInfo = components["schemas"]["OrgInfo"];
31
- type UserIdInfo = components["schemas"]["UserIdInfo"];
32
- export type OidcIdentity = components["schemas"]["OIDCIdentity"];
33
- export type MemberRole = components["schemas"]["MemberRole"];
34
- /** Options for a new OIDC user */
35
- export interface CreateOidcUserOptions {
36
- /** The role of an OIDC user, default is "Alien" */
37
- memberRole?: MemberRole;
38
- /** Optional MFA policy to associate with the user account */
39
- mfaPolicy?: MfaPolicy;
40
- }
41
38
  /** An organization. */
42
39
  export declare class Org {
43
40
  #private;
44
41
  /**
45
42
  * @description The org id
46
43
  * @example Org#c3b9379c-4e8c-4216-bd0a-65ace53cf98f
47
- * */
44
+ */
48
45
  get id(): OrgId;
49
46
  /** Human-readable name for the org */
50
47
  name(): Promise<string | undefined>;
51
- /** Set the human-readable name for the org.
48
+ /**
49
+ * Set the human-readable name for the org.
52
50
  * @param {string} name The new human-readable name for the org (must be alphanumeric).
53
51
  * @example my_org_name
54
- * */
52
+ */
55
53
  setName(name: string): Promise<void>;
56
54
  /** Is the org enabled? */
57
55
  enabled(): Promise<boolean>;
@@ -65,162 +63,278 @@ export declare class Org {
65
63
  * @param {OrgPolicy[]} policy The new policy for the org.
66
64
  * */
67
65
  setPolicy(policy: OrgPolicy[]): Promise<void>;
68
- /** Create a new signing key.
66
+ /**
67
+ * Create a new signing key.
69
68
  * @param {KeyType} type The type of key to create.
70
69
  * @param {string?} ownerId The owner of the key. Defaults to the session's user.
71
70
  * @return {Key[]} The new keys.
72
- * */
71
+ */
73
72
  createKey(type: KeyType, ownerId?: string): Promise<Key>;
74
- /** Create new signing keys.
73
+ /**
74
+ * Create new signing keys.
75
75
  * @param {KeyType} type The type of key to create.
76
- * @param {nummber} count The number of keys to create.
76
+ * @param {number} count The number of keys to create.
77
77
  * @param {string?} ownerId The owner of the keys. Defaults to the session's user.
78
78
  * @return {Key[]} The new keys.
79
- * */
79
+ */
80
80
  createKeys(type: KeyType, count: number, ownerId?: string): Promise<Key[]>;
81
81
  /**
82
- * Derives a key of the given type using the given derivation path and mnemonic.
82
+ * Derive a key of the given type using the given derivation path and mnemonic.
83
+ * The owner of the derived key will be the owner of the mnemonic.
83
84
  *
84
85
  * @param {KeyType} type Type of key to derive from the mnemonic.
85
86
  * @param {string} derivationPath Mnemonic derivation path used to generate new key.
86
87
  * @param {string} mnemonicId materialId of mnemonic key used to derive the new key.
87
- * @param {string} ownerId optional owner of the derived key.
88
88
  *
89
89
  * @return {Key} newly derived key.
90
90
  */
91
- deriveKey(type: KeyType, derivationPath: string, mnemonicId: string, ownerId?: string): Promise<Key>;
91
+ deriveKey(type: KeyType, derivationPath: string, mnemonicId: string): Promise<Key>;
92
92
  /**
93
- * Derives a set of keys of the given type using the given derivation paths and mnemonic.
93
+ * Derive a set of keys of the given type using the given derivation paths and mnemonic.
94
+ *
95
+ * The owner of the derived keys will be the owner of the mnemonic.
94
96
  *
95
97
  * @param {KeyType} type Type of key to derive from the mnemonic.
96
98
  * @param {string[]} derivationPaths Mnemonic derivation paths used to generate new key.
97
99
  * @param {string} mnemonicId materialId of mnemonic key used to derive the new key.
98
- * @param {string} ownerId optional owner of the derived key.
99
100
  *
100
101
  * @return {Key[]} newly derived keys.
101
102
  */
102
- deriveKeys(type: KeyType, derivationPaths: string[], mnemonicId: string, ownerId?: string): Promise<Key[]>;
103
- /**
104
- * Create a new user in the organization and sends an invitation to that user
105
- * @param {string} email Email of the user
106
- * @param {string} name The full name of the user
107
- */
108
- createUser(email: string, name: string): Promise<void>;
109
- /**
110
- * Create a new OIDC user
111
- * @param {OidcIdentity} identity The identity of the OIDC user
112
- * @param {string} email Email of the OIDC user
113
- * @param {CreateOidcUserOptions} opts Additional options for new OIDC users
114
- * @return {string} User id of the new user
115
- */
116
- createOidcUser(identity: OidcIdentity, email: string, opts?: CreateOidcUserOptions): Promise<string>;
117
- /**
118
- * Delete an existing OIDC user
119
- * @param {OidcIdentity} identity The identity of the OIDC user
120
- */
121
- deleteOidcUser(identity: OidcIdentity): Promise<{
103
+ deriveKeys(type: KeyType, derivationPaths: string[], mnemonicId: string): Promise<Key[]>;
104
+ /** Create a new user in the organization and sends an invitation to that user. */
105
+ get createUser(): (email: string, name: string, role?: "Alien" | "Member" | "Owner" | undefined) => Promise<void>;
106
+ /** Create a new OIDC user */
107
+ get createOidcUser(): (identity: {
108
+ iss: string;
109
+ sub: string;
110
+ }, email: string, opts?: import("./schema_types").CreateOidcUserOptions) => Promise<string>;
111
+ /** Delete an existing OIDC user */
112
+ get deleteOidcUser(): (identity: {
113
+ iss: string;
114
+ sub: string;
115
+ }) => Promise<{
122
116
  status: string;
123
117
  }>;
118
+ /** Checks if a given proof of OIDC authentication is valid. */
119
+ get verifyIdentity(): (proof: {
120
+ aud?: string | null | undefined;
121
+ email: string;
122
+ exp_epoch: number;
123
+ identity?: {
124
+ iss: string;
125
+ sub: string;
126
+ } | null | undefined;
127
+ user_info?: {
128
+ configured_mfa: ({
129
+ type: "totp";
130
+ } | {
131
+ id: string;
132
+ name: string;
133
+ type: "fido";
134
+ })[];
135
+ initialized: boolean;
136
+ user_id: string;
137
+ } | null | undefined;
138
+ } & {
139
+ id: string;
140
+ }) => Promise<void>;
141
+ /** List users in the organization */
142
+ get users(): () => Promise<{
143
+ email: string;
144
+ id: string;
145
+ }[]>;
124
146
  /**
125
- * List users in the organization
126
- * @return {UserIdInfo[]} List of users
127
- */
128
- users(): Promise<UserIdInfo[]>;
129
- /** Get a key by id.
147
+ * Get a key by id.
130
148
  * @param {string} keyId The id of the key to get.
131
149
  * @return {Key} The key.
132
- * */
150
+ */
133
151
  getKey(keyId: string): Promise<Key>;
134
- /** Get all keys in the org.
152
+ /**
153
+ * Get all keys in the org.
135
154
  * @param {KeyType?} type Optional key type to filter list for.
155
+ * @param {PageOpts} page Pagination options. Defaults to fetching the entire result set.
136
156
  * @return {Key} The key.
137
- * */
138
- keys(type?: KeyType): Promise<Key[]>;
139
- /** Create a new role.
157
+ */
158
+ keys(type?: KeyType, page?: PageOpts): Promise<Key[]>;
159
+ /**
160
+ * Create a new role.
161
+ *
140
162
  * @param {string?} name The name of the role.
141
163
  * @return {Role} The new role.
142
- * */
164
+ */
143
165
  createRole(name?: string): Promise<Role>;
144
- /** Get a role by id or name.
166
+ /**
167
+ * Get a role by id or name.
168
+ *
145
169
  * @param {string} roleId The id or name of the role to get.
146
170
  * @return {Role} The role.
147
- * */
171
+ */
148
172
  getRole(roleId: string): Promise<Role>;
149
- /** List all roles in the org.
173
+ /**
174
+ * List all roles in the org.
175
+ *
176
+ * @param {PageOpts} page Pagination options. Defaults to fetching the entire result set.
150
177
  * @return {Role[]} The roles.
151
- * */
152
- listRoles(): Promise<Role[]>;
153
- /** List all users in the org.
154
- * @return {User[]} The users.
155
- * */
156
- listUsers(): Promise<UserIdInfo[]>;
178
+ */
179
+ listRoles(page?: PageOpts): Promise<Role[]>;
180
+ /** List all users in the org. */
181
+ get listUsers(): () => Promise<{
182
+ email: string;
183
+ id: string;
184
+ }[]>;
157
185
  /**
158
186
  * Get a pending MFA request by its id.
159
- * @param {string} mfaId The id of the MFA request.
160
- * @return {Promise<MfaRequestInfo>} The MFA request.
161
187
  *
162
188
  * @deprecated Use {@link getMfaInfo()} instead.
163
189
  */
164
- mfaGet(mfaId: string): Promise<MfaRequestInfo>;
190
+ get mfaGet(): (mfaId: string) => Promise<{
191
+ expires_at: number;
192
+ id: string;
193
+ receipt?: {
194
+ confirmation: string;
195
+ final_approver: string;
196
+ timestamp: number;
197
+ } | null | undefined;
198
+ request: {
199
+ body?: Record<string, unknown> | null | undefined;
200
+ method: string;
201
+ path: string;
202
+ };
203
+ status: {
204
+ allowed_approvers: string[];
205
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
206
+ approved_by: {
207
+ [key: string]: {
208
+ [key: string]: {
209
+ timestamp: number;
210
+ };
211
+ };
212
+ };
213
+ count: number;
214
+ num_auth_factors: number;
215
+ };
216
+ }>;
165
217
  /**
166
218
  * Approve a pending MFA request.
167
219
  *
168
- * @param {string} mfaId The id of the MFA request.
169
- * @return {Promise<MfaRequestInfo>} The MFA request.
170
- *
171
220
  * @deprecated Use {@link approveMfaRequest()} instead.
172
221
  */
173
- mfaApprove(mfaId: string): Promise<MfaRequestInfo>;
174
- /**
175
- * Get a pending MFA request by its id.
176
- * @param {string} mfaId The id of the MFA request.
177
- * @return {Promise<MfaRequestInfo>} The MFA request.
178
- */
179
- getMfaInfo(mfaId: string): Promise<MfaRequestInfo>;
222
+ get mfaApprove(): (mfaId: string) => Promise<{
223
+ expires_at: number;
224
+ id: string;
225
+ receipt?: {
226
+ confirmation: string;
227
+ final_approver: string;
228
+ timestamp: number;
229
+ } | null | undefined;
230
+ request: {
231
+ body?: Record<string, unknown> | null | undefined;
232
+ method: string;
233
+ path: string;
234
+ };
235
+ status: {
236
+ allowed_approvers: string[];
237
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
238
+ approved_by: {
239
+ [key: string]: {
240
+ [key: string]: {
241
+ timestamp: number;
242
+ };
243
+ };
244
+ };
245
+ count: number;
246
+ num_auth_factors: number;
247
+ };
248
+ }>;
249
+ /** Get a pending MFA request by its id. */
250
+ get getMfaInfo(): (mfaId: string) => Promise<{
251
+ expires_at: number;
252
+ id: string;
253
+ receipt?: {
254
+ confirmation: string;
255
+ final_approver: string;
256
+ timestamp: number;
257
+ } | null | undefined;
258
+ request: {
259
+ body?: Record<string, unknown> | null | undefined;
260
+ method: string;
261
+ path: string;
262
+ };
263
+ status: {
264
+ allowed_approvers: string[];
265
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
266
+ approved_by: {
267
+ [key: string]: {
268
+ [key: string]: {
269
+ timestamp: number;
270
+ };
271
+ };
272
+ };
273
+ count: number;
274
+ num_auth_factors: number;
275
+ };
276
+ }>;
277
+ /** List pending MFA requests accessible to the current user. */
278
+ get listMfaInfos(): () => Promise<{
279
+ expires_at: number;
280
+ id: string;
281
+ receipt?: {
282
+ confirmation: string;
283
+ final_approver: string;
284
+ timestamp: number;
285
+ } | null | undefined;
286
+ request: {
287
+ body?: Record<string, unknown> | null | undefined;
288
+ method: string;
289
+ path: string;
290
+ };
291
+ status: {
292
+ allowed_approvers: string[];
293
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
294
+ approved_by: {
295
+ [key: string]: {
296
+ [key: string]: {
297
+ timestamp: number;
298
+ };
299
+ };
300
+ };
301
+ count: number;
302
+ num_auth_factors: number;
303
+ };
304
+ }[]>;
305
+ /** Approve a pending MFA request. */
306
+ get approveMfaRequest(): (mfaId: string) => Promise<{
307
+ expires_at: number;
308
+ id: string;
309
+ receipt?: {
310
+ confirmation: string;
311
+ final_approver: string;
312
+ timestamp: number;
313
+ } | null | undefined;
314
+ request: {
315
+ body?: Record<string, unknown> | null | undefined;
316
+ method: string;
317
+ path: string;
318
+ };
319
+ status: {
320
+ allowed_approvers: string[];
321
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
322
+ approved_by: {
323
+ [key: string]: {
324
+ [key: string]: {
325
+ timestamp: number;
326
+ };
327
+ };
328
+ };
329
+ count: number;
330
+ num_auth_factors: number;
331
+ };
332
+ }>;
180
333
  /**
181
- * Approve a pending MFA request.
182
- *
183
- * @param {string} mfaId The id of the MFA request.
184
- * @return {Promise<MfaRequestInfo>} The MFA request.
185
- */
186
- approveMfaRequest(mfaId: string): Promise<MfaRequestInfo>;
187
- /** Create a new org.
188
- * @param {CubeSigner} cs The CubeSigner instance.
334
+ * Create a new org.
335
+ * @param {CubeSignerClient} csc The CubeSigner instance.
189
336
  * @param {OrgInfo} data The JSON response from the API server.
190
337
  * @internal
191
- * */
192
- constructor(cs: CubeSigner, data: OrgInfo);
193
- /**
194
- * Approve a pending MFA request.
195
- *
196
- * @param {CubeSigner} cs The CubeSigner instance to use for requests
197
- * @param {string} orgId The org id of the MFA request
198
- * @param {string} mfaId The id of the MFA request
199
- * @return {Promise<MfaRequestInfo>} The result of the MFA request
200
338
  */
201
- static mfaApprove(cs: CubeSigner, orgId: string, mfaId: string): Promise<MfaRequestInfo>;
202
- /** Fetch org info.
203
- * @return {OrgInfo} The org info.
204
- * */
205
- private fetch;
206
- /** Update the org.
207
- * @param {UpdateOrgRequest} request The JSON request to send to the API server.
208
- * @return {UpdateOrgResponse} The JSON response from the API server.
209
- * */
210
- private update;
211
- /** List roles.
212
- * @param {CubeSigner} cs The CubeSigner instance to use for signing.
213
- * @param {string} orgId The id of the organization to which the role belongs.
214
- * @return {Role[]} Org roles.
215
- * @internal
216
- * */
217
- private static roles;
218
- /** List users.
219
- * @param {CubeSigner} cs The CubeSigner instance to use for signing.
220
- * @param {string} orgId The id of the organization to which the role belongs.
221
- * @return {User[]} Org users.
222
- * @internal
223
- * */
224
- private static users;
339
+ constructor(csc: CubeSignerClient, data: OrgInfo);
225
340
  }
226
- export {};