@cubist-labs/cubesigner-sdk 0.4.254 → 0.4.260

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.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/cubist-labs/CubeSigner-TypeScript-SDK.git",
6
6
  "directory": "packages/sdk"
7
7
  },
8
- "version": "0.4.254",
8
+ "version": "0.4.260",
9
9
  "description": "CubeSigner TypeScript SDK",
10
10
  "license": "MIT OR Apache-2.0",
11
11
  "author": "Cubist, Inc.",
@@ -50,6 +50,7 @@ import type {
50
50
  Empty,
51
51
  UserOrgsResponse,
52
52
  CreateKeyImportKeyResponse,
53
+ CreatePolicyImportKeyResponse,
53
54
  ImportKeyRequest,
54
55
  UpdatePolicyRequest,
55
56
  ListPoliciesResponse,
@@ -147,6 +148,7 @@ import {
147
148
  type InvokePolicyRequest,
148
149
  type PolicySecretsInfo,
149
150
  type SetPolicySecretRequest,
151
+ type UpdatePolicySecretsRequest,
150
152
  type UploadWasmPolicyRequest,
151
153
  type UploadWasmPolicyResponse,
152
154
  type LoginRequest,
@@ -535,12 +537,16 @@ export class ApiClient extends BaseClient {
535
537
  * Update the org.
536
538
  *
537
539
  * @param request The JSON request to send to the API server.
540
+ * @param mfaReceipt Optional MFA receipt(s)
538
541
  * @returns Updated org information.
539
542
  */
540
- async orgUpdate(request: UpdateOrgRequest): Promise<UpdateOrgResponse> {
543
+ async orgUpdate(
544
+ request: UpdateOrgRequest,
545
+ mfaReceipt?: MfaReceipts,
546
+ ): Promise<CubeSignerResponse<UpdateOrgResponse>> {
541
547
  const o = op("/v0/org/{org_id}", "patch");
542
-
543
- return this.exec(o, { body: request });
548
+ const reqFn = (headers?: HeadersInit) => this.exec(o, { body: request, headers });
549
+ return await CubeSignerResponse.create(this.env, reqFn, mfaReceipt);
544
550
  }
545
551
 
546
552
  /**
@@ -1540,7 +1546,17 @@ export class ApiClient extends BaseClient {
1540
1546
 
1541
1547
  // #endregion
1542
1548
 
1543
- // #region POLICY: policy(Create|Get|List|Update|Delete|Invoke), policySecret(Set|Delete), policySecretsGet
1549
+ // #region POLICY: policyImportKeyCreate, policy(Create|Get|List|Update|Delete|Invoke), policySecret(Set|Delete), policySecrets(Get|Update)
1550
+
1551
+ /**
1552
+ * Request a fresh policy import key.
1553
+ *
1554
+ * @returns A fresh policy import key
1555
+ */
1556
+ async policyImportKeyCreate(): Promise<CreatePolicyImportKeyResponse> {
1557
+ const o = op("/v0/org/{org_id}/policy/import_key", "get");
1558
+ return await this.exec(o, {});
1559
+ }
1544
1560
 
1545
1561
  /**
1546
1562
  * Create a new named policy.
@@ -1698,6 +1714,22 @@ export class ApiClient extends BaseClient {
1698
1714
  return this.exec(o, {});
1699
1715
  }
1700
1716
 
1717
+ /**
1718
+ * Update org-level policy secrets metadata (e.g., the edit policy).
1719
+ *
1720
+ * @param request The update request.
1721
+ * @param mfaReceipt Optional MFA receipt(s).
1722
+ * @returns The updated policy secrets info.
1723
+ */
1724
+ async policySecretsUpdate(
1725
+ request: UpdatePolicySecretsRequest,
1726
+ mfaReceipt?: MfaReceipts,
1727
+ ): Promise<CubeSignerResponse<PolicySecretsInfo>> {
1728
+ const o = op("/v0/org/{org_id}/policy/secrets", "patch");
1729
+ const reqFn = async (headers?: HeadersInit) => this.exec(o, { body: request, headers });
1730
+ return await CubeSignerResponse.create(this.env, reqFn, mfaReceipt);
1731
+ }
1732
+
1701
1733
  /**
1702
1734
  * Delete an org-level policy secret.
1703
1735
  *
@@ -3166,6 +3198,65 @@ export class ApiClient extends BaseClient {
3166
3198
  ).then(assertOk);
3167
3199
  }
3168
3200
 
3201
+ /**
3202
+ * Initiate login via Sign-in With Solana (SIWS).
3203
+ *
3204
+ * The response contains a challenge which must be answered (via {@link siwsLoginComplete})
3205
+ * to obtain an OIDC token.
3206
+ *
3207
+ * @param env The environment to use
3208
+ * @param orgId The org to login to
3209
+ * @param body The request body
3210
+ * @param headers Optional headers to set
3211
+ * @returns The challenge that needs to be answered via {@link siwsLoginComplete}
3212
+ */
3213
+ static async siwsLoginInit(
3214
+ env: EnvInterface,
3215
+ orgId: string,
3216
+ body: schemas["SiwsInitRequest"],
3217
+ headers?: HeadersInit,
3218
+ ): Promise<schemas["SiwsInitResponse"]> {
3219
+ const o = op("/v0/org/{org_id}/oidc/siws", "post");
3220
+ return await retryOn5XX(() =>
3221
+ o({
3222
+ baseUrl: env.SignerApiRoot,
3223
+ params: { path: { org_id: orgId } },
3224
+ body,
3225
+ headers,
3226
+ }),
3227
+ ).then(assertOk);
3228
+ }
3229
+
3230
+ /**
3231
+ * Complete login via Sign-in With Solana (SIWS).
3232
+ *
3233
+ * The challenge returned by {@link siwsLoginInit} should be signed
3234
+ * and submitted via this API call to obtain an OIDC token, which can
3235
+ * then be used to log in via {@link oidcSessionCreate}.
3236
+ *
3237
+ * @param env The environment to use
3238
+ * @param orgId The org to login to
3239
+ * @param body The request body
3240
+ * @param headers Optional headers to set
3241
+ * @returns An OIDC token which can be used to log in via OIDC (see {@link oidcSessionCreate})
3242
+ */
3243
+ static async siwsLoginComplete(
3244
+ env: EnvInterface,
3245
+ orgId: string,
3246
+ body: schemas["SiwsCompleteRequest"],
3247
+ headers?: HeadersInit,
3248
+ ): Promise<schemas["SiwsCompleteResponse"]> {
3249
+ const o = op("/v0/org/{org_id}/oidc/siws", "patch");
3250
+ return await retryOn5XX(() =>
3251
+ o({
3252
+ baseUrl: env.SignerApiRoot,
3253
+ params: { path: { org_id: orgId } },
3254
+ body,
3255
+ headers,
3256
+ }),
3257
+ ).then(assertOk);
3258
+ }
3259
+
3169
3260
  /**
3170
3261
  * Initiate the login with passkey flow.
3171
3262
  *
package/src/key.ts CHANGED
@@ -29,8 +29,7 @@ import type {
29
29
  DiffieHellmanResponse,
30
30
  KeyInfoJwt,
31
31
  KeyAttestationQuery,
32
- BinanceApiProperties,
33
- CoinbaseApiProperties,
32
+ KeyPropertiesPatch,
34
33
  } from "./schema_types";
35
34
  import type {
36
35
  ApiClient,
@@ -118,6 +117,10 @@ export enum P256 {
118
117
  export const Mnemonic = "Mnemonic" as const;
119
118
  export type Mnemonic = typeof Mnemonic;
120
119
 
120
+ /** HmacSha256 key type */
121
+ export const HmacSha256 = "HmacSha256" as const;
122
+ export type HmacSha256 = typeof HmacSha256;
123
+
121
124
  /** Stark key type */
122
125
  export const Stark = "Stark" as const;
123
126
  export type Stark = typeof Stark;
@@ -127,12 +130,7 @@ export const BabyJubjub = "BabyJubjub" as const;
127
130
  export type BabyJubjub = typeof BabyJubjub;
128
131
 
129
132
  /** Key type */
130
- export type KeyType = Secp256k1 | Bls | Ed25519 | Mnemonic | Stark | P256 | BabyJubjub;
131
-
132
- /** The type representing all different kinds of key properties. */
133
- export type KeyPropertiesPatch =
134
- | ({ kind: "BinanceApi" } & BinanceApiProperties)
135
- | ({ kind: "CoinbaseApi" } & CoinbaseApiProperties);
133
+ export type KeyType = Secp256k1 | Bls | Ed25519 | Mnemonic | HmacSha256 | Stark | P256 | BabyJubjub;
136
134
 
137
135
  /**
138
136
  * A representation of a signing key.
@@ -852,6 +850,8 @@ export function fromSchemaKeyType(ty: SchemaKeyType): KeyType {
852
850
  return Ed25519.CoinbaseApi;
853
851
  case "Stark":
854
852
  return Stark;
853
+ case "HmacSha256":
854
+ return HmacSha256;
855
855
  case "Mnemonic":
856
856
  return Mnemonic;
857
857
  case "P256CosmosAddr":
package/src/org.ts CHANGED
@@ -29,6 +29,7 @@ import type {
29
29
  OrgExtData,
30
30
  AuditLogEntry,
31
31
  AuditLogRequest,
32
+ MfaReceipts,
32
33
  } from ".";
33
34
  import { Contact } from "./contact";
34
35
  import { C2FFunction, Key, MfaRequest, Role } from ".";
@@ -307,14 +308,26 @@ export class Org {
307
308
  return data.enabled;
308
309
  }
309
310
 
310
- /** Enable the org. */
311
- async enable() {
312
- await this.update({ enabled: true });
311
+ /**
312
+ * Enable the org.
313
+ *
314
+ * @param opts Optional parameters
315
+ * @param opts.mfaReceipt Optional MFA receipts
316
+ * @returns Org info
317
+ */
318
+ async enable(opts?: { mfaReceipt?: MfaReceipts }) {
319
+ return await this.update({ enabled: true }, opts?.mfaReceipt);
313
320
  }
314
321
 
315
- /** Disable the org. */
316
- async disable() {
317
- await this.update({ enabled: false });
322
+ /**
323
+ * Disable the org.
324
+ *
325
+ * @param opts Optional parameters
326
+ * @param opts.mfaReceipt Optional MFA receipts
327
+ * @returns Org info
328
+ */
329
+ async disable(opts?: { mfaReceipt?: MfaReceipts }) {
330
+ return await this.update({ enabled: false }, opts?.mfaReceipt);
318
331
  }
319
332
 
320
333
  /** @returns the policy for the org. */
@@ -333,10 +346,25 @@ export class Org {
333
346
  * Set the policy for the org.
334
347
  *
335
348
  * @param policy The new policy for the org.
349
+ * @param opts Optional parameters
350
+ * @param opts.mfaReceipt Optional MFA receipts
351
+ * @returns Org info
336
352
  */
337
- async setPolicy(policy: OrgPolicy[]) {
353
+ async setPolicy(policy: OrgPolicy[], opts?: { mfaReceipt?: MfaReceipts }) {
338
354
  const p = policy as unknown as Record<string, never>[];
339
- await this.update({ policy: p });
355
+ return await this.update({ policy: p }, opts?.mfaReceipt);
356
+ }
357
+
358
+ /**
359
+ * Set the edit policy for the org.
360
+ *
361
+ * @param editPolicy The new edit policy for the org.
362
+ * @param opts Optional parameters
363
+ * @param opts.mfaReceipt Optional MFA receipts
364
+ * @returns Org info
365
+ */
366
+ async setEditPolicy(editPolicy: EditPolicy, opts?: { mfaReceipt?: MfaReceipts }) {
367
+ return await this.update({ edit_policy: editPolicy }, opts?.mfaReceipt);
340
368
  }
341
369
 
342
370
  /**
@@ -346,9 +374,12 @@ export class Org {
346
374
  * It is analogous to how role policies apply to all sign requests performed by the corresponding role sessions.
347
375
  *
348
376
  * @param policy The new policy for the org.
377
+ * @param opts Optional parameters
378
+ * @param opts.mfaReceipt Optional MFA receipts
379
+ * @returns Org info
349
380
  */
350
- async setSignPolicy(policy: RolePolicy) {
351
- await this.update({ sign_policy: policy });
381
+ async setSignPolicy(policy: RolePolicy, opts?: { mfaReceipt?: MfaReceipts }) {
382
+ return await this.update({ sign_policy: policy }, opts?.mfaReceipt);
352
383
  }
353
384
 
354
385
  /**
@@ -365,9 +396,12 @@ export class Org {
365
396
  * Update the organization's extended properties (uncommon features not used by most users).
366
397
  *
367
398
  * @param props The new properties.
399
+ * @param opts Optional parameters
400
+ * @param opts.mfaReceipt Optional MFA receipts
401
+ * @returns Org info
368
402
  */
369
- async setExtendedProperties(props: OrgExtProps) {
370
- await this.update({ ext_props: props });
403
+ async setExtendedProperties(props: OrgExtProps, opts?: { mfaReceipt?: MfaReceipts }) {
404
+ return await this.update({ ext_props: props }, opts?.mfaReceipt);
371
405
  }
372
406
 
373
407
  /**
@@ -377,8 +411,14 @@ export class Org {
377
411
  * In other words, org admins can still assign unlimited number of keys to their alien users.
378
412
  *
379
413
  * @param alienKeyCountThreshold The new key count threshold.
380
- */
381
- async setAlienKeyCountThreshold(alienKeyCountThreshold: number) {
414
+ * @param opts Optional parameters
415
+ * @param opts.mfaReceipt Optional MFA receipts
416
+ * @returns Org info
417
+ */
418
+ async setAlienKeyCountThreshold(
419
+ alienKeyCountThreshold: number,
420
+ opts?: { mfaReceipt?: MfaReceipts },
421
+ ) {
382
422
  const data = { ...((await this.getExtendedProperties()) ?? {}) };
383
423
 
384
424
  // erase the metadata that cannot be updated
@@ -388,29 +428,37 @@ export class Org {
388
428
  // update 'alien_key_count_threshold' and keep everything else the same
389
429
  data.alien_key_count_threshold = alienKeyCountThreshold;
390
430
 
391
- await this.update({ ext_props: data });
431
+ return await this.update({ ext_props: data }, opts?.mfaReceipt);
392
432
  }
393
433
 
394
434
  /**
395
435
  * Set the notification endpoints for the org.
396
436
  *
397
437
  * @param notification_endpoints Endpoints.
438
+ * @param opts Optional parameters
439
+ * @param opts.mfaReceipt Optional MFA receipts
440
+ * @returns Org info
398
441
  */
399
- async setNotificationEndpoints(notification_endpoints: NotificationEndpointConfiguration[]) {
400
- await this.update({
401
- notification_endpoints,
402
- });
442
+ async setNotificationEndpoints(
443
+ notification_endpoints: NotificationEndpointConfiguration[],
444
+ opts?: { mfaReceipt?: MfaReceipts },
445
+ ) {
446
+ return await this.update({ notification_endpoints }, opts?.mfaReceipt);
403
447
  }
404
448
 
405
449
  /**
406
450
  * Set required MFA types for actions implicitly requiring MFA (see {@link MfaProtectedAction}).
407
451
  *
408
452
  * @param allowed_mfa_types Assignment of MFA types to actions that implicitly require MFA.
453
+ * @param opts Optional parameters
454
+ * @param opts.mfaReceipt Optional MFA receipts
455
+ * @returns Org info
409
456
  */
410
- async setAllowedMfaTypes(allowed_mfa_types: Partial<Record<MfaProtectedAction, MfaType[]>>) {
411
- await this.update({
412
- allowed_mfa_types,
413
- });
457
+ async setAllowedMfaTypes(
458
+ allowed_mfa_types: Partial<Record<MfaProtectedAction, MfaType[]>>,
459
+ opts?: { mfaReceipt?: MfaReceipts },
460
+ ) {
461
+ return await this.update({ allowed_mfa_types }, opts?.mfaReceipt);
414
462
  }
415
463
 
416
464
  /**
@@ -723,11 +771,17 @@ export class Org {
723
771
  * Note that this overwrites any existing configuration.
724
772
  *
725
773
  * @param configs Confidential Cloud Functions configuration.
726
- */
727
- async setC2FConfiguration(configs: C2FConfiguration) {
728
- await this.update({
729
- policy_engine_configuration: configs,
730
- });
774
+ * @param opts Optional parameters
775
+ * @param opts.mfaReceipt Optional MFA receipts
776
+ * @returns Org info
777
+ */
778
+ async setC2FConfiguration(configs: C2FConfiguration, opts?: { mfaReceipt?: MfaReceipts }) {
779
+ return await this.update(
780
+ {
781
+ policy_engine_configuration: configs,
782
+ },
783
+ opts?.mfaReceipt,
784
+ );
731
785
  }
732
786
 
733
787
  /**
package/src/role.ts CHANGED
@@ -484,8 +484,30 @@ export type NamedPolicyReference = {
484
484
  Reference: PolicyReference;
485
485
  };
486
486
 
487
+ /** Explicit "permit" vs "deny" policy outcome, with or without a descriptive message. */
488
+ export type Const = ConstOutcome | { outcome: ConstOutcome; message: string };
489
+
490
+ /** Explicit "permit" vs "deny" policy outcome. */
491
+ export type ConstOutcome = "Permit" | "Deny";
492
+
493
+ /**
494
+ * A {@link https://github.com/google/cel-spec Common Expression Language}
495
+ * policy to evaluate against the following context:
496
+ *
497
+ * ```json
498
+ * {
499
+ * "operation": OperationKind,
500
+ * "identity": <UserOrRoleId>,
501
+ * "body": <RequestBodyJson>
502
+ * }
503
+ * ```
504
+ */
505
+ export type Cel = { Cel: string };
506
+
487
507
  /** Key policies that restrict the requests that the signing endpoints accept */
488
508
  export type KeyDenyPolicy =
509
+ | Const
510
+ | Cel
489
511
  | OperationAllowlist
490
512
  | TxReceiver
491
513
  | TxDeposit
@@ -508,6 +530,7 @@ export type KeyDenyPolicy =
508
530
  | PolicyAnd
509
531
  | PolicyOr
510
532
  | PolicyNot
533
+ | PolicyIte
511
534
  | NamedPolicyReference;
512
535
 
513
536
  /**
@@ -545,6 +568,30 @@ export type RolePolicy = RolePolicyRule[];
545
568
 
546
569
  export type RolePolicyRule = KeyDenyPolicy | PolicyReference;
547
570
 
571
+ /** Conditional policy */
572
+ export type Conditional = {
573
+ /** The condition to evaluate first. */
574
+ if: KeyDenyPolicy;
575
+
576
+ /** The policy to apply when the condition evaluates to 'Permit'. */
577
+ then: KeyDenyPolicy;
578
+ };
579
+
580
+ /** One or more conditional policies */
581
+ export type Conditionals =
582
+ | Conditional
583
+ | {
584
+ conditionals: Conditional[];
585
+ };
586
+
587
+ /** If-then-else policy */
588
+ export type PolicyIte = {
589
+ IfThenElse: Conditionals & {
590
+ /** The policy to apply when none of the conditionals apply. */
591
+ else: KeyDenyPolicy;
592
+ };
593
+ };
594
+
548
595
  export type PolicyAnd = {
549
596
  And: KeyDenyPolicy[];
550
597
  };