@cubist-labs/cubesigner-sdk 0.4.231 → 0.4.237

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/src/bucket.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { Ace, AceAttribute } from "./acl";
2
+ import type { BucketAction, schemas } from "./schema_types";
3
+
4
+ /** Access control entry for policy buckets */
5
+ export type BucketAce = Ace<
6
+ BucketAction,
7
+ {
8
+ policy_ids?: AceAttribute<string>;
9
+ bucket_keys?: AceAttribute<string>;
10
+ }
11
+ >;
12
+
13
+ /** Policy bucket information (like the one from {@link schemas} but with more precise `acl`) */
14
+ export type BucketInfo = schemas["BucketInfo"] & {
15
+ acl?: BucketAce[];
16
+ };
17
+
18
+ /**
19
+ * Coerce the less accurate `BucketInfo` type from the OpenAPI schema to a more accurate {@link BucketInfo}.
20
+ *
21
+ * @param b The bucket info received on the wire.
22
+ * @returns The exact same value coerced to the {@link BucketInfo} type.
23
+ */
24
+ export function coerceBucketInfo(b: schemas["BucketInfo"]): BucketInfo {
25
+ return {
26
+ ...b,
27
+ // TODO: parse once we add Zod
28
+ acl: b.acl as BucketAce[],
29
+ };
30
+ }
@@ -54,7 +54,6 @@ import type {
54
54
  UpdatePolicyRequest,
55
55
  ListPoliciesResponse,
56
56
  PolicyType,
57
- PolicyInfo,
58
57
  DiffieHellmanRequest,
59
58
  DiffieHellmanResponse,
60
59
  KeyInfoJwt,
@@ -67,6 +66,9 @@ import type {
67
66
  KeyAttestationQuery,
68
67
  RoleAttestationQuery,
69
68
  ErrorResponse,
69
+ ListBucketsResponse,
70
+ UpdateBucketRequest,
71
+ PolicyInfo,
70
72
  } from "../schema_types";
71
73
  import { encodeToBase64 } from "../util";
72
74
  import {
@@ -152,6 +154,9 @@ import {
152
154
  type GetUserByOidcResponse,
153
155
  type EmailTemplatePurpose,
154
156
  ErrResponse,
157
+ coerceBucketInfo,
158
+ coercePolicyInfo,
159
+ type BucketInfo,
155
160
  } from "../index";
156
161
  import { assertOk, op, type Op, type Operation, apiFetch } from "../fetch";
157
162
  import { BaseClient, type ClientConfig, signerSessionFromSessionInfo } from "./base_client";
@@ -485,7 +490,7 @@ export class ApiClient extends BaseClient {
485
490
 
486
491
  // #endregion
487
492
 
488
- // #region ORGS: orgGet, orgUpdate, orgUpdateUserMembership, orgCreateOrg, orgQueryMetrics, orgConfigureEmail
493
+ // #region ORGS: orgGet, orgUpdate, orgUpdateUserMembership, orgCreateOrg, orgQueryMetrics, orgGetEmailConfig, orgConfigureEmail, orgDeleteEmailConfig
489
494
 
490
495
  /**
491
496
  * Obtain information about an org
@@ -590,6 +595,21 @@ export class ApiClient extends BaseClient {
590
595
  );
591
596
  }
592
597
 
598
+ /**
599
+ * Get email configuration for a given purpose.
600
+ *
601
+ * @param purpose The email template kind to get
602
+ * @returns The email configuration
603
+ */
604
+ async orgGetEmailConfig(
605
+ purpose: EmailTemplatePurpose,
606
+ ): Promise<schemas["GetEmailConfigResponse"]> {
607
+ const o = op("/v0/org/{org_id}/emails/{purpose}", "get");
608
+ return this.exec(o, {
609
+ params: { path: { purpose } },
610
+ });
611
+ }
612
+
593
613
  /**
594
614
  * Configure email template
595
615
  *
@@ -608,6 +628,20 @@ export class ApiClient extends BaseClient {
608
628
  });
609
629
  }
610
630
 
631
+ /**
632
+ * Delete email configuration for a given purpose.
633
+ *
634
+ * @param purpose The email template kind to delete
635
+ * @returns An empty response
636
+ */
637
+ async orgDeleteEmailConfig(purpose: EmailTemplatePurpose): Promise<Empty> {
638
+ const o = op("/v0/org/{org_id}/emails/{purpose}", "delete");
639
+ return this.exec(o, {
640
+ params: { path: { purpose } },
641
+ body: {},
642
+ });
643
+ }
644
+
611
645
  // #endregion
612
646
 
613
647
  // #region ORG USERS: orgUserInvite, orgUserDelete, orgUsersList, orgUserGet, orgUserGetByEmail, orgUserCreateOidc, orgUserDeleteOidc
@@ -1496,14 +1530,14 @@ export class ApiClient extends BaseClient {
1496
1530
  acl?: JsonValue[],
1497
1531
  ): Promise<PolicyInfo> {
1498
1532
  const o = op("/v0/org/{org_id}/policies", "post");
1499
- return (await this.exec(o, {
1533
+ return await this.exec(o, {
1500
1534
  body: {
1501
1535
  name,
1502
1536
  policy_type: type,
1503
1537
  rules,
1504
1538
  acl,
1505
1539
  },
1506
- })) as PolicyInfo;
1540
+ }).then(coercePolicyInfo);
1507
1541
  }
1508
1542
 
1509
1543
  /**
@@ -1515,9 +1549,9 @@ export class ApiClient extends BaseClient {
1515
1549
  */
1516
1550
  async policyGet(policyId: string, version: policy.Version): Promise<PolicyInfo> {
1517
1551
  const o = op("/v0/org/{org_id}/policies/{policy_id}/{version}", "get");
1518
- return (await this.exec(o, {
1552
+ return await this.exec(o, {
1519
1553
  params: { path: { policy_id: policyId, version } },
1520
- })) as PolicyInfo;
1554
+ }).then(coercePolicyInfo);
1521
1555
  }
1522
1556
 
1523
1557
  /**
@@ -1554,17 +1588,13 @@ export class ApiClient extends BaseClient {
1554
1588
  mfaReceipt?: MfaReceipts,
1555
1589
  ): Promise<CubeSignerResponse<PolicyInfo>> {
1556
1590
  const o = op("/v0/org/{org_id}/policies/{policy_id}", "patch");
1557
- const signFn = async (headers?: HeadersInit) =>
1591
+ const reqFn = async (headers?: HeadersInit) =>
1558
1592
  this.exec(o, {
1559
1593
  params: { path: { policy_id: policyId } },
1560
1594
  body: request,
1561
1595
  headers,
1562
- });
1563
- return (await CubeSignerResponse.create(
1564
- this.env,
1565
- signFn,
1566
- mfaReceipt,
1567
- )) as CubeSignerResponse<PolicyInfo>;
1596
+ }).then((resp) => mapResponse(resp, coercePolicyInfo));
1597
+ return await CubeSignerResponse.create(this.env, reqFn, mfaReceipt);
1568
1598
  }
1569
1599
 
1570
1600
  /**
@@ -1609,6 +1639,62 @@ export class ApiClient extends BaseClient {
1609
1639
 
1610
1640
  // #endregion
1611
1641
 
1642
+ // #region BUCKET: bucket(Get|List|Update)
1643
+
1644
+ /**
1645
+ * List available meta information about all policy buckets in the org.
1646
+ *
1647
+ * @param page Pagination options. Defaults to fetching the entire result set.
1648
+ * @returns Paginator for iterating over policy buckets.
1649
+ */
1650
+ bucketsList(page?: PageOpts): Paginator<ListBucketsResponse, BucketInfo[]> {
1651
+ const o = op("/v0/org/{org_id}/policy/buckets", "get");
1652
+ return Paginator.items(
1653
+ page ?? Page.default(),
1654
+ (pageQuery) => this.exec(o, { params: { query: { ...pageQuery } } }),
1655
+ (r) => r.buckets,
1656
+ (r) => r.last_evaluated_key,
1657
+ ) as Paginator<ListBucketsResponse, BucketInfo[]>;
1658
+ }
1659
+
1660
+ /**
1661
+ * Get the meta information of a policy KV store bucket.
1662
+ *
1663
+ * @param bucketName The name of the bucket to get
1664
+ * @returns The bucket information
1665
+ */
1666
+ async bucketGet(bucketName: string): Promise<BucketInfo> {
1667
+ const o = op("/v0/org/{org_id}/policy/buckets/{bucket_name}", "get");
1668
+ return await this.exec(o, {
1669
+ params: { path: { bucket_name: bucketName } },
1670
+ }).then(coerceBucketInfo);
1671
+ }
1672
+
1673
+ /**
1674
+ * Set or update meta information for a policy KV store bucket.
1675
+ *
1676
+ * @param bucketName The name of the bucket to update.
1677
+ * @param request The update request
1678
+ * @param mfaReceipt Option MFA receipt(s)
1679
+ * @returns The updated bucket information
1680
+ */
1681
+ async bucketUpdate(
1682
+ bucketName: string,
1683
+ request: UpdateBucketRequest,
1684
+ mfaReceipt?: MfaReceipts,
1685
+ ): Promise<CubeSignerResponse<BucketInfo>> {
1686
+ const o = op("/v0/org/{org_id}/policy/buckets/{bucket_name}", "patch");
1687
+ const reqFn = async (headers?: HeadersInit) =>
1688
+ this.exec(o, {
1689
+ params: { path: { bucket_name: bucketName } },
1690
+ body: request,
1691
+ headers,
1692
+ }).then((resp) => mapResponse(resp, coerceBucketInfo));
1693
+ return await CubeSignerResponse.create(this.env, reqFn, mfaReceipt);
1694
+ }
1695
+
1696
+ // #endregion
1697
+
1612
1698
  // #region WASM: wasm(PolicyUpload)
1613
1699
 
1614
1700
  /**
package/src/index.ts CHANGED
@@ -34,6 +34,8 @@ export * from "./contact";
34
34
  export * from "./scopes";
35
35
  /** Policies */
36
36
  export * from "./policy";
37
+ /** Buckets */
38
+ export * from "./bucket";
37
39
  /** Access control */
38
40
  export * from "./acl";
39
41
  /** Utils */
package/src/org.ts CHANGED
@@ -292,6 +292,12 @@ export class Org {
292
292
  return (data.policy ?? []) as unknown as OrgPolicy[];
293
293
  }
294
294
 
295
+ /** @returns the sign policy for the org. */
296
+ async signPolicy(): Promise<RolePolicy> {
297
+ const data = await this.fetch();
298
+ return (data.sign_policy ?? []) as unknown as RolePolicy;
299
+ }
300
+
295
301
  /**
296
302
  * Set the policy for the org.
297
303
  *
@@ -302,6 +308,18 @@ export class Org {
302
308
  await this.update({ policy: p });
303
309
  }
304
310
 
311
+ /**
312
+ * Set the sign policy for the org.
313
+ *
314
+ * This is a global sign policy that applies to every sign operation (every key, every role) in the org.
315
+ * It is analogous to how role policies apply to all sign requests performed by the corresponding role sessions.
316
+ *
317
+ * @param policy The new policy for the org.
318
+ */
319
+ async setSignPolicy(policy: RolePolicy) {
320
+ await this.update({ sign_policy: policy });
321
+ }
322
+
305
323
  /**
306
324
  * Retrieve the organization's extended properties (uncommon features not used by most users).
307
325
  *
package/src/policy.ts CHANGED
@@ -10,15 +10,15 @@ import type {
10
10
  KeyPolicyRule,
11
11
  MfaReceipts,
12
12
  PolicyAttachedToId,
13
- PolicyInfo,
14
13
  PolicyType,
15
14
  RolePolicy,
16
15
  RolePolicyRule,
17
16
  UpdatePolicyRequest,
18
17
  WasmRule,
19
- Acl,
20
18
  AceAttribute,
21
19
  PolicyAction,
20
+ Ace,
21
+ PolicyInfo,
22
22
  } from ".";
23
23
 
24
24
  import { loadSubtleCrypto } from ".";
@@ -32,7 +32,7 @@ export type PolicyRule = KeyPolicyRule | RolePolicyRule | WasmRule;
32
32
  * A helper type for {@link PolicyInfo} with a more detailed `acl` type.
33
33
  */
34
34
  type NamedPolicyInfo = PolicyInfo & {
35
- acl?: Acl<PolicyAction, PolicyCtx>;
35
+ acl?: PolicyAcl;
36
36
  };
37
37
 
38
38
  /**
@@ -67,7 +67,10 @@ export type C2FInfo = WasmPolicyInfo;
67
67
  export type Version = `v${number}` | `latest`;
68
68
 
69
69
  /** A policy access control entry. */
70
- export type PolicyAcl = Acl<PolicyAction, PolicyCtx>;
70
+ export type PolicyAce = Ace<PolicyAction, PolicyCtx>;
71
+
72
+ /** A policy access control list. */
73
+ export type PolicyAcl = PolicyAce[];
71
74
 
72
75
  /** Additional contexts when using policies. */
73
76
  export type PolicyCtx = {
@@ -476,7 +479,7 @@ export class C2FFunction extends NamedPolicy {
476
479
  // upload the policy object
477
480
  const hash = await uploadWasmFunction(this.apiClient, policy);
478
481
 
479
- // update this policy with the new policy verison.
482
+ // update this policy with the new policy version.
480
483
  const body: UpdatePolicyRequest = { rules: [{ hash }] };
481
484
  this.data = (await this.update(body, mfaReceipt)) as C2FInfo;
482
485
  }
package/src/role.ts CHANGED
@@ -29,6 +29,9 @@ import type { RoleAttestationClaims, RoleAttestationQuery } from "./schema_types
29
29
 
30
30
  type NameOrAddressOrNull = string | null;
31
31
 
32
+ /** Only allow the following operations */
33
+ export type OperationAllowlist = { OperationAllowlist: OperationKind[] };
34
+
32
35
  /**
33
36
  * Restrict the receiver for EVM transactions.
34
37
  *
@@ -310,6 +313,13 @@ export type BtcSegwitValueLimitWindow = {
310
313
  */
311
314
  export type SourceIpAllowlist = { SourceIpAllowlist: string[] };
312
315
 
316
+ /**
317
+ * Disallow signing until the specified Unix timestamp (in seconds since epoch).
318
+ *
319
+ * @example { TimeLock: 1750000000 }
320
+ */
321
+ export type TimeLock = { TimeLock: number };
322
+
313
323
  export type HttpRequestComparer = "Eq" | { EvmTx: EvmTxCmp } | { SolanaTx: SolanaTxCmp };
314
324
 
315
325
  /**
@@ -476,6 +486,7 @@ export type NamedPolicyReference = {
476
486
 
477
487
  /** Key policies that restrict the requests that the signing endpoints accept */
478
488
  export type KeyDenyPolicy =
489
+ | OperationAllowlist
479
490
  | TxReceiver
480
491
  | TxDeposit
481
492
  | TxValueLimit
@@ -487,6 +498,7 @@ export type KeyDenyPolicy =
487
498
  | SuiTxReceivers
488
499
  | BtcTxReceivers
489
500
  | SourceIpAllowlist
501
+ | TimeLock
490
502
  | SolanaInstructionPolicy
491
503
  | BtcSegwitValueLimit
492
504
  | RequireMfa