@cubist-labs/cubesigner-sdk 0.1.77 → 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.
@@ -1,10 +1,437 @@
1
1
  import createClient from "openapi-fetch";
2
2
  import { paths } from "./schema";
3
- /** Type of http client.
4
- * @internal
5
- * */
3
+ import { SignerSessionData, SignerSessionLifetime, SignerSessionManager } from "./session/signer_session_manager";
4
+ import { CreateOidcUserOptions, IdentityProof, KeyInRoleInfo, KeyInfoApi, ListKeysResponse, ListRoleKeysResponse, ListRoleUsersResponse, ListRolesResponse, OidcIdentity, SessionsResponse, PublicKeyCredential, RoleInfo, UpdateKeyRequest, UpdateOrgRequest, UpdateOrgResponse, UpdateRoleRequest, UserIdInfo, UserInRoleInfo, UserInfo, SessionInfo, OrgInfo, RatchetConfig, OidcAuthResponse, EvmSignRequest, EvmSignResponse, Eth2SignRequest, Eth2SignResponse, Eth2StakeRequest, Eth2StakeResponse, Eth2UnstakeRequest, Eth2UnstakeResponse, BlobSignRequest, BlobSignResponse, BtcSignResponse, BtcSignRequest, SolanaSignRequest, SolanaSignResponse, AvaSignResponse, AvaTx, MfaRequestInfo, MemberRole } from "./schema_types";
5
+ import { AddFidoChallenge, MfaFidoChallenge, MfaReceipt, TotpChallenge } from "./mfa";
6
+ import { CubeSignerResponse } from "./signer_session";
7
+ import { Key, KeyType } from "./key";
8
+ import { PageOpts, Paginator } from "./paginator";
9
+ import { KeyPolicy } from "./role";
10
+ import { EnvInterface } from "./env";
11
+ /** @internal */
6
12
  export type Client = ReturnType<typeof createClient<paths>>;
7
- /** Re-export schema.
8
- * @internal
9
- * */
10
- export * from "./schema";
13
+ export { paths };
14
+ /**
15
+ * Client to use to send requests to CubeSigner services
16
+ * when authenticating using a CubeSigner session token.
17
+ */
18
+ export declare class CubeSignerClient {
19
+ #private;
20
+ /** Underlying session manager */
21
+ get sessionMgr(): SignerSessionManager;
22
+ /**
23
+ * Constructor.
24
+ * @param {SignerSessionManager} sessionMgr The session manager to use
25
+ * @param {string?} orgId Optional organization ID; if omitted, uses the org ID from the session manager.
26
+ */
27
+ constructor(sessionMgr: SignerSessionManager, orgId?: string);
28
+ /**
29
+ * Returns a new instance of this class using the same session manager but targeting a different organization.
30
+ *
31
+ * @param {string} orgId The organization ID.
32
+ * @return {CubeSignerClient} A new instance of this class using the same session manager but targeting different organization.
33
+ */
34
+ withOrg(orgId?: string): CubeSignerClient;
35
+ /** Org id */
36
+ get orgId(): string;
37
+ /**
38
+ * Obtain information about the current user.
39
+ *
40
+ * @return {Promise<UserInfo>} Retrieves information about the current user.
41
+ */
42
+ userGet(): Promise<UserInfo>;
43
+ /**
44
+ * Creates a request to change user's TOTP. This request returns a new TOTP challenge
45
+ * that must be answered by calling `userResetTotpComplete`
46
+ *
47
+ * @param {MfaReceipt} mfaReceipt MFA receipt to include in HTTP headers
48
+ */
49
+ userResetTotpInit(mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<TotpChallenge>>;
50
+ /**
51
+ * Answer the TOTP challenge issued by `userResetTotpInit`. If successful, user's
52
+ * TOTP configuration will be updated to that of the TOTP challenge.
53
+ *
54
+ * @param {string} totpId - The ID of the TOTP challenge
55
+ * @param {string} code - The TOTP code that should verify against the TOTP configuration from the challenge.
56
+ */
57
+ userResetTotpComplete(totpId: string, code: string): Promise<void>;
58
+ /**
59
+ * Verifies a given TOTP code against the current user's TOTP configuration.
60
+ * Throws an error if the verification fails.
61
+ *
62
+ * @param {string} code Current TOTP code
63
+ */
64
+ userVerifyTotp(code: string): Promise<void>;
65
+ /**
66
+ * Initiate adding a new FIDO device. MFA may be required. This returns a challenge that must
67
+ * be answered with `userRegisterFidoComplete` (after MFA approvals).
68
+ *
69
+ * @param {string} name The name of the new device.
70
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt to include in HTTP headers
71
+ * @return {Promise<CubeSignerResponse<AddFidoChallenge>>} A challenge that must be answered in order to complete FIDO registration.
72
+ */
73
+ userRegisterFidoInit(name: string, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<AddFidoChallenge>>;
74
+ /**
75
+ * Complete a previously initiated request to add a new FIDO device.
76
+ * @param {string} challengeId The ID of the challenge returned by the remote end.
77
+ * @param {PublicKeyCredential} credential The answer to the challenge.
78
+ */
79
+ userRegisterFidoComplete(challengeId: string, credential: PublicKeyCredential): Promise<void>;
80
+ /**
81
+ * Obtain information about the current organization.
82
+ * @return {Org} Information about the organization.
83
+ */
84
+ orgGet(): Promise<OrgInfo>;
85
+ /**
86
+ * Update the org.
87
+ * @param {UpdateOrgRequest} request The JSON request to send to the API server.
88
+ * @return {UpdateOrgResponse} Updated org information.
89
+ */
90
+ orgUpdate(request: UpdateOrgRequest): Promise<UpdateOrgResponse>;
91
+ /**
92
+ * Create a new (first-party) user in the organization and send an email invitation to that user.
93
+ *
94
+ * @param {string} email Email of the user
95
+ * @param {string} name The full name of the user
96
+ * @param {MemberRole} role Optional role. Defaults to "alien.
97
+ */
98
+ orgUserInvite(email: string, name: string, role?: MemberRole): Promise<void>;
99
+ /**
100
+ * List users.
101
+ * @return {User[]} Org users.
102
+ */
103
+ orgUsersList(): Promise<UserIdInfo[]>;
104
+ /**
105
+ * Create a new OIDC user. This can be a first-party "Member" or third-party "Alien".
106
+ * @param {OidcIdentity} identity The identity of the OIDC user
107
+ * @param {string} email Email of the OIDC user
108
+ * @param {CreateOidcUserOptions} opts Additional options for new OIDC users
109
+ * @return {string} User id of the new user
110
+ */
111
+ orgUserCreateOidc(identity: OidcIdentity, email: string, opts?: CreateOidcUserOptions): Promise<string>;
112
+ /**
113
+ * Delete an existing OIDC user.
114
+ * @param {OidcIdentity} identity The identity of the OIDC user
115
+ */
116
+ orgUserDeleteOidc(identity: OidcIdentity): Promise<{
117
+ status: string;
118
+ }>;
119
+ /**
120
+ * Get a key by its id.
121
+ *
122
+ * @param {string} keyId The id of the key to get.
123
+ * @return {KeyInfoApi} The key information.
124
+ */
125
+ keyGet(keyId: string): Promise<KeyInfoApi>;
126
+ /**
127
+ * Update key.
128
+ * @param {string} keyId The ID of the key to update.
129
+ * @param {UpdateKeyRequest} request The JSON request to send to the API server.
130
+ * @return {KeyInfoApi} The JSON response from the API server.
131
+ */
132
+ keyUpdate(keyId: string, request: UpdateKeyRequest): Promise<KeyInfoApi>;
133
+ /**
134
+ * Deletes a key.
135
+ *
136
+ * @param {string} keyId - Key id
137
+ */
138
+ keyDelete(keyId: string): Promise<void>;
139
+ /**
140
+ * Create new signing keys.
141
+ *
142
+ * @param {KeyType} keyType The type of key to create.
143
+ * @param {number} count The number of keys to create.
144
+ * @param {string?} ownerId The owner of the keys. Defaults to the session's user.
145
+ * @return {KeyInfoApi[]} The new keys.
146
+ */
147
+ keysCreate(keyType: KeyType, count: number, ownerId?: string): Promise<KeyInfoApi[]>;
148
+ /**
149
+ * Derive a set of keys of a specified type using a supplied derivation path and an existing long-lived mnemonic.
150
+ *
151
+ * The owner of the derived key will be the owner of the mnemonic.
152
+ *
153
+ * @param {KeyType} keyType The type of key to create.
154
+ * @param {string[]} derivationPaths Derivation paths from which to derive new keys.
155
+ * @param {string} mnemonicId materialId of mnemonic key used to derive the new key.
156
+ *
157
+ * @return {KeyInfoApi[]} The newly derived keys.
158
+ */
159
+ keysDerive(keyType: KeyType, derivationPaths: string[], mnemonicId: string): Promise<KeyInfoApi[]>;
160
+ /**
161
+ * List all keys in the org.
162
+ * @param {KeyType?} type Optional key type to filter list for.
163
+ * @param {PageOpts?} page Pagination options. Defaults to fetching the entire result set.
164
+ * @return {Paginator<ListKeysResponse, KeyInfoApi>} Paginator for iterating over keys.
165
+ */
166
+ keysList(type?: KeyType, page?: PageOpts): Paginator<ListKeysResponse, KeyInfoApi>;
167
+ /**
168
+ * Create a new role.
169
+ *
170
+ * @param {string?} name The optional name of the role.
171
+ * @return {string} The ID of the new role.
172
+ */
173
+ roleCreate(name?: string): Promise<string>;
174
+ /**
175
+ * Get a role by its id (or name).
176
+ * @param {string} roleId The id of the role to get.
177
+ * @return {RoleInfo} The role.
178
+ */
179
+ roleGet(roleId: string): Promise<RoleInfo>;
180
+ /**
181
+ * Update a role.
182
+ *
183
+ * @param {string} roleId The ID of the role to update.
184
+ * @param {UpdateRoleRequest} request The update request.
185
+ * @return {Promise<RoleInfo>} The updated role information.
186
+ */
187
+ roleUpdate(roleId: string, request: UpdateRoleRequest): Promise<RoleInfo>;
188
+ /**
189
+ * Delete a role by its ID.
190
+ *
191
+ * @param {string} roleId The ID of the role to delete.
192
+ */
193
+ roleDelete(roleId: string): Promise<void>;
194
+ /**
195
+ * List all roles in the org.
196
+ *
197
+ * @param {PageOpts} page Pagination options. Defaults to fetching the entire result set.
198
+ * @return {RoleInfo} Paginator for iterating over roles.
199
+ */
200
+ rolesList(page?: PageOpts): Paginator<ListRolesResponse, RoleInfo>;
201
+ /**
202
+ * Add existing keys to an existing role.
203
+ *
204
+ * @param {string} roleId The ID of the role
205
+ * @param {string[]} keyIds The IDs of the keys to add to the role.
206
+ * @param {KeyPolicy?} policy The optional policy to apply to each key.
207
+ */
208
+ roleKeysAdd(roleId: string, keyIds: string[], policy?: KeyPolicy): Promise<void>;
209
+ /**
210
+ * Remove an existing key from an existing role.
211
+ *
212
+ * @param {string} roleId The ID of the role
213
+ * @param {string} keyId The ID of the key to remove from the role
214
+ */
215
+ roleKeysRemove(roleId: string, keyId: string): Promise<void>;
216
+ /**
217
+ * List all keys in a role.
218
+ *
219
+ * @param {string} roleId The ID of the role whose keys to retrieve.
220
+ * @param {PageOpts} page Pagination options. Defaults to fetching the entire result set.
221
+ * @return {Paginator<ListRoleKeysResponse, KeyInRoleInfo>} Paginator for iterating over the keys in the role.
222
+ */
223
+ roleKeysList(roleId: string, page?: PageOpts): Paginator<ListRoleKeysResponse, KeyInRoleInfo>;
224
+ /**
225
+ * Add an existing user to an existing role.
226
+ *
227
+ * @param {string} roleId The ID of the role.
228
+ * @param {string} userId The ID of the user to add to the role.
229
+ */
230
+ roleUserAdd(roleId: string, userId: string): Promise<void>;
231
+ /**
232
+ * List all users in a role.
233
+ *
234
+ * @param {string} roleId The ID of the role whose users to retrieve.
235
+ * @param {PageOpts} page Pagination options. Defaults to fetching the entire result set.
236
+ * @return {Paginator<ListRoleUsersResponse, UserInRoleInfo>} Paginator for iterating over the users in the role.
237
+ */
238
+ roleUsersList(roleId: string, page?: PageOpts): Paginator<ListRoleUsersResponse, UserInRoleInfo>;
239
+ /**
240
+ * Create a new signer session for a given role.
241
+ *
242
+ * @param {string} roleId Role ID
243
+ * @param {string} purpose The purpose of the session
244
+ * @param {string[]} scopes Session scopes. Only `sign:*` scopes are allowed.
245
+ * @param {SignerSessionLifetime} lifetimes Lifetime settings
246
+ * @return {Promise<SignerSessionData>} New signer session info.
247
+ */
248
+ sessionCreateForRole(roleId: string, purpose: string, scopes?: string[], lifetimes?: SignerSessionLifetime): Promise<SignerSessionData>;
249
+ /**
250
+ * Revoke a session.
251
+ *
252
+ * @param {string} sessionId The ID of the session to revoke.
253
+ */
254
+ sessionRevoke(sessionId: string): Promise<void>;
255
+ /**
256
+ * Returns a paginator for iterating over all signer sessions optionally filtered by a role.
257
+ *
258
+ * @param {string?} roleId If set, limit to sessions for this role only.
259
+ * @param {PageOpts?} page Pagination options. Defaults to fetching the entire result set.
260
+ * @return {Promise<SignerSessionInfo[]>} Signer sessions for this role.
261
+ */
262
+ sessionsList(roleId?: string, page?: PageOpts): Paginator<SessionsResponse, SessionInfo>;
263
+ /**
264
+ * Returns the list of keys that this session has access to.
265
+ * @return {Key[]} The list of keys.
266
+ */
267
+ sessionKeysList(): Promise<KeyInfoApi[]>;
268
+ /**
269
+ * Obtain proof of authentication using the current CubeSigner session.
270
+ *
271
+ * @return {Promise<IdentityProof>} Proof of authentication
272
+ */
273
+ identityProve(): Promise<IdentityProof>;
274
+ /**
275
+ * Checks if a given identity proof is valid.
276
+ *
277
+ * @param {IdentityProof} proof The proof of authentication.
278
+ */
279
+ identityVerify(proof: IdentityProof): Promise<void>;
280
+ /**
281
+ * Retrieves existing MFA request.
282
+ *
283
+ * @param {string} mfaId MFA request ID
284
+ * @return {Promise<MfaRequestInfo>} MFA request information
285
+ */
286
+ mfaGet(mfaId: string): Promise<MfaRequestInfo>;
287
+ /**
288
+ * List pending MFA requests accessible to the current user.
289
+ *
290
+ * @return {Promise<MfaRequestInfo[]>} The MFA requests.
291
+ */
292
+ mfaList(): Promise<MfaRequestInfo[]>;
293
+ /**
294
+ * Approve a pending MFA request using the current session.
295
+ *
296
+ * @param {string} mfaId The id of the MFA request
297
+ * @return {Promise<MfaRequestInfo>} The result of the MFA request
298
+ */
299
+ mfaApprove(mfaId: string): Promise<MfaRequestInfo>;
300
+ /**
301
+ * Approve a pending MFA request using TOTP.
302
+ *
303
+ * @param {string} mfaId The MFA request to approve
304
+ * @param {string} code The TOTP code
305
+ * @return {Promise<MfaRequestInfo>} The current status of the MFA request
306
+ */
307
+ mfaApproveTotp(mfaId: string, code: string): Promise<MfaRequestInfo>;
308
+ /**
309
+ * Initiate approval of an existing MFA request using FIDO.
310
+ *
311
+ * @param {string} mfaId The MFA request ID.
312
+ * @return {Promise<MfaFidoChallenge>} A challenge that needs to be answered to complete the approval.
313
+ */
314
+ mfaApproveFidoInit(mfaId: string): Promise<MfaFidoChallenge>;
315
+ /**
316
+ * Complete a previously initiated MFA request approval using FIDO.
317
+ *
318
+ * @param {string} mfaId The MFA request ID
319
+ * @param {string} challengeId The challenge ID
320
+ * @param {PublicKeyCredential} credential The answer to the challenge
321
+ * @return {Promise<MfaRequestInfo>} The current status of the MFA request.
322
+ */
323
+ mfaApproveFidoComplete(mfaId: string, challengeId: string, credential: PublicKeyCredential): Promise<MfaRequestInfo>;
324
+ /**
325
+ * Sign an EVM transaction.
326
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
327
+ * @param {EvmSignRequest} req What to sign.
328
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt.
329
+ * @return {Promise<EvmSignResponse | AcceptedResponse>} Signature (or MFA approval request).
330
+ */
331
+ signEvm(key: Key | string, req: EvmSignRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<EvmSignResponse>>;
332
+ /**
333
+ * Sign an Eth2/Beacon-chain validation message.
334
+ *
335
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
336
+ * @param {Eth2SignRequest} req What to sign.
337
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
338
+ * @return {Promise<Eth2SignResponse | AcceptedResponse>} Signature
339
+ */
340
+ signEth2(key: Key | string, req: Eth2SignRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<Eth2SignResponse>>;
341
+ /**
342
+ * Sign an Eth2/Beacon-chain deposit (or staking) message.
343
+ *
344
+ * @param {Eth2StakeRequest} req The request to sign.
345
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
346
+ * @return {Promise<Eth2StakeResponse | AcceptedResponse>} The response.
347
+ */
348
+ signStake(req: Eth2StakeRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<Eth2StakeResponse>>;
349
+ /**
350
+ * Sign an Eth2/Beacon-chain unstake/exit request.
351
+ *
352
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
353
+ * @param {Eth2UnstakeRequest} req The request to sign.
354
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
355
+ * @return {Promise<Eth2UnstakeResponse | AcceptedResponse>} The response.
356
+ */
357
+ signUnstake(key: Key | string, req: Eth2UnstakeRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<Eth2UnstakeResponse>>;
358
+ /**
359
+ * Sign an Avalanche P- or X-chain message.
360
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
361
+ * @param {AvaTx} tx Avalanche message (transaction) to sign
362
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
363
+ * @return {Promise<AvaSignResponse | AcceptedResponse>} The response.
364
+ */
365
+ signAva(key: Key | string, tx: AvaTx, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<AvaSignResponse>>;
366
+ /**
367
+ * Sign a raw blob.
368
+ *
369
+ * This requires the key to have a '"AllowRawBlobSigning"' policy. This is because
370
+ * signing arbitrary messages is, in general, dangerous (and you should instead
371
+ * prefer typed end-points as used by, for example, `signEvm`). For Secp256k1 keys,
372
+ * for example, you **must** call this function with a message that is 32 bytes long and
373
+ * the output of a secure hash function.
374
+ *
375
+ * This function returns signatures serialized as;
376
+ *
377
+ * - ECDSA signatures are serialized as big-endian r and s plus recovery-id
378
+ * byte v, which can in general take any of the values 0, 1, 2, or 3.
379
+ *
380
+ * - EdDSA signatures are serialized in the standard format.
381
+ *
382
+ * - BLS signatures are not supported on the blob-sign endpoint.
383
+ *
384
+ * @param {Key | string} key The key to sign with (either {@link Key} or its ID).
385
+ * @param {BlobSignRequest} req What to sign
386
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
387
+ * @return {Promise<BlobSignResponse | AcceptedResponse>} The response.
388
+ */
389
+ signBlob(key: Key | string, req: BlobSignRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<BlobSignResponse>>;
390
+ /**
391
+ * Sign a Bitcoin message.
392
+ *
393
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
394
+ * @param {BtcSignRequest} req What to sign
395
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
396
+ * @return {Promise<BtcSignResponse | AcceptedResponse>} The response.
397
+ */
398
+ signBtc(key: Key | string, req: BtcSignRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<BtcSignResponse>>;
399
+ /**
400
+ * Sign a Solana message.
401
+ *
402
+ * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
403
+ * @param {SolanaSignRequest} req What to sign
404
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt
405
+ * @return {Promise<SolanaSignResponse | AcceptedResponse>} The response.
406
+ */
407
+ signSolana(key: Key | string, req: SolanaSignRequest, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<SolanaSignResponse>>;
408
+ /** HTTPS client */
409
+ private client;
410
+ }
411
+ /**
412
+ * Client to use to send requests to CubeSigner services
413
+ * when authenticating using an OIDC token.
414
+ */
415
+ export declare class OidcClient {
416
+ #private;
417
+ /**
418
+ * @param {EnvInterface} env CubeSigner deployment
419
+ * @param {string} orgId Target organization ID
420
+ * @param {string} oidcToken User's OIDC token
421
+ */
422
+ constructor(env: EnvInterface, orgId: string, oidcToken: string);
423
+ /**
424
+ * Exchange an OIDC token for a CubeSigner session token.
425
+ * @param {List<string>} scopes The scopes for the new session
426
+ * @param {RatchetConfig} lifetimes Lifetimes of the new session.
427
+ * @param {MfaReceipt} mfaReceipt Optional MFA receipt (id + confirmation code)
428
+ * @return {Promise<CubeSignerResponse<OidcAuthResponse>>} The session data.
429
+ */
430
+ sessionCreate(scopes: Array<string>, lifetimes?: RatchetConfig, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<OidcAuthResponse>>;
431
+ /**
432
+ * Exchange an OIDC token for a proof of authentication.
433
+ *
434
+ * @return {Promise<IdentityProof>} Proof of authentication
435
+ */
436
+ identityProve(): Promise<IdentityProof>;
437
+ }