@cubist-labs/cubesigner-sdk 0.4.228 → 0.4.229

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.228",
8
+ "version": "0.4.229",
9
9
  "description": "CubeSigner TypeScript SDK",
10
10
  "license": "MIT OR Apache-2.0",
11
11
  "author": "Cubist, Inc.",
@@ -66,6 +66,7 @@ import type {
66
66
  RoleInfoJwt,
67
67
  KeyAttestationQuery,
68
68
  RoleAttestationQuery,
69
+ ErrorResponse,
69
70
  } from "../schema_types";
70
71
  import { encodeToBase64 } from "../util";
71
72
  import {
@@ -82,74 +83,75 @@ import { Page, Paginator } from "../paginator";
82
83
  import type { KeyPolicy } from "../role";
83
84
  import { loadSubtleCrypto } from "../user_export";
84
85
  import type * as policy from "../policy";
85
- import type {
86
- AddIdentityRequest,
87
- AvaChain,
88
- EnvInterface,
89
- EotsCreateNonceRequest,
90
- EotsCreateNonceResponse,
91
- EotsSignRequest,
92
- EotsSignResponse,
93
- JrpcResponse,
94
- JsonArray,
95
- ListIdentityResponse,
96
- ListKeyRolesResponse,
97
- ListKeysResponse,
98
- ListRoleKeysResponse,
99
- ListRoleUsersResponse,
100
- ListRolesResponse,
101
- MmiJrpcMethod,
102
- PendingMessageInfo,
103
- PendingMessageSignResponse,
104
- RatchetConfig,
105
- Scope,
106
- SessionData,
107
- SessionLifetime,
108
- SessionsResponse,
109
- TaprootSignRequest,
110
- TaprootSignResponse,
111
- BabylonRegistrationRequest,
112
- BabylonRegistrationResponse,
113
- BabylonStakingRequest,
114
- BabylonStakingResponse,
115
- UpdateUserMembershipRequest,
116
- HistoricalTx,
117
- ListHistoricalTxResponse,
118
- PublicOrgInfo,
119
- ImportDeriveKeyProperties,
120
- PasswordResetRequest,
121
- EmailOtpResponse,
122
- AuthenticationRequest,
123
- AuthenticationResponse,
124
- CreateKeyProperties,
125
- InvitationAcceptRequest,
126
- MfaReceipts,
127
- SuiSignRequest,
128
- SuiSignResponse,
129
- QueryMetricsRequest,
130
- QueryMetricsResponse,
131
- CreateOrgRequest,
132
- KeyTypeAndDerivationPath,
133
- DeriveMultipleKeyTypesProperties,
134
- ContactInfo,
135
- ListContactsResponse,
136
- JsonValue,
137
- EditPolicy,
138
- UpdateContactRequest,
139
- AddressMap,
140
- RolePolicy,
141
- InvokePolicyResponse,
142
- InvokePolicyRequest,
143
- UploadWasmPolicyRequest,
144
- UploadWasmPolicyResponse,
145
- LoginRequest,
146
- PasskeyAssertAnswer,
147
- schemas,
148
- KeyWithPoliciesInfo,
149
- GetRoleKeyOptions,
150
- GetUserByEmailResponse,
151
- GetUserByOidcResponse,
152
- EmailTemplatePurpose,
86
+ import {
87
+ type AddIdentityRequest,
88
+ type AvaChain,
89
+ type EnvInterface,
90
+ type EotsCreateNonceRequest,
91
+ type EotsCreateNonceResponse,
92
+ type EotsSignRequest,
93
+ type EotsSignResponse,
94
+ type JrpcResponse,
95
+ type JsonArray,
96
+ type ListIdentityResponse,
97
+ type ListKeyRolesResponse,
98
+ type ListKeysResponse,
99
+ type ListRoleKeysResponse,
100
+ type ListRoleUsersResponse,
101
+ type ListRolesResponse,
102
+ type MmiJrpcMethod,
103
+ type PendingMessageInfo,
104
+ type PendingMessageSignResponse,
105
+ type RatchetConfig,
106
+ type Scope,
107
+ type SessionData,
108
+ type SessionLifetime,
109
+ type SessionsResponse,
110
+ type TaprootSignRequest,
111
+ type TaprootSignResponse,
112
+ type BabylonRegistrationRequest,
113
+ type BabylonRegistrationResponse,
114
+ type BabylonStakingRequest,
115
+ type BabylonStakingResponse,
116
+ type UpdateUserMembershipRequest,
117
+ type HistoricalTx,
118
+ type ListHistoricalTxResponse,
119
+ type PublicOrgInfo,
120
+ type ImportDeriveKeyProperties,
121
+ type PasswordResetRequest,
122
+ type EmailOtpResponse,
123
+ type AuthenticationRequest,
124
+ type AuthenticationResponse,
125
+ type CreateKeyProperties,
126
+ type InvitationAcceptRequest,
127
+ type MfaReceipts,
128
+ type SuiSignRequest,
129
+ type SuiSignResponse,
130
+ type QueryMetricsRequest,
131
+ type QueryMetricsResponse,
132
+ type CreateOrgRequest,
133
+ type KeyTypeAndDerivationPath,
134
+ type DeriveMultipleKeyTypesProperties,
135
+ type ContactInfo,
136
+ type ListContactsResponse,
137
+ type JsonValue,
138
+ type EditPolicy,
139
+ type UpdateContactRequest,
140
+ type AddressMap,
141
+ type RolePolicy,
142
+ type InvokePolicyResponse,
143
+ type InvokePolicyRequest,
144
+ type UploadWasmPolicyRequest,
145
+ type UploadWasmPolicyResponse,
146
+ type LoginRequest,
147
+ type PasskeyAssertAnswer,
148
+ type schemas,
149
+ type KeyWithPoliciesInfo,
150
+ type GetRoleKeyOptions,
151
+ type GetUserByEmailResponse,
152
+ type GetUserByOidcResponse,
153
+ type EmailTemplatePurpose,
154
+ ErrResponse,
153
155
  } from "../index";
154
156
  import { assertOk, op, type Op, type Operation, apiFetch } from "../fetch";
155
157
  import { BaseClient, type ClientConfig, signerSessionFromSessionInfo } from "./base_client";
@@ -2713,9 +2715,35 @@ export class ApiClient extends BaseClient {
2713
2715
  method: method,
2714
2716
  params: params,
2715
2717
  };
2716
- const func = async (headers?: HeadersInit) => this.exec(o, { headers, body });
2717
- const resp = (await CubeSignerResponse.create(this.env, func)).data();
2718
- return resp;
2718
+ const func = async (headers?: HeadersInit) => {
2719
+ const resp = await this.exec(o, { headers, body });
2720
+ if (resp.error) {
2721
+ const data = resp.error.data as ErrorResponse | undefined;
2722
+ throw new ErrResponse({
2723
+ message: resp.error.message,
2724
+ errorCode: data?.error_code,
2725
+ requestId: data?.request_id,
2726
+ });
2727
+ }
2728
+ return resp;
2729
+ };
2730
+ const resp = await CubeSignerResponse.create(this.env, func);
2731
+ return resp.data();
2732
+ }
2733
+
2734
+ /**
2735
+ * Retrieve a proof of this session's CubeSigner identity.
2736
+ *
2737
+ * @returns a JWT that can be validated against the JWKS from {@link customerProofJwksUrl}.
2738
+ */
2739
+ async getCustomerProof(): Promise<string> {
2740
+ const resp = await this.mmi("custodian_getCustomerProof", []);
2741
+ const jwt = resp.result?.jwt;
2742
+ if (!jwt || typeof jwt !== "string") {
2743
+ console.warn("Unexpected getCustomerProof response", resp);
2744
+ throw new Error("The type JWT included in the customer proof response is not string");
2745
+ }
2746
+ return jwt;
2719
2747
  }
2720
2748
 
2721
2749
  /**
@@ -2770,6 +2798,15 @@ export class ApiClient extends BaseClient {
2770
2798
  return new URL(`${this.env.SignerApiRoot.replace(/\/$/, "")}${url}`);
2771
2799
  }
2772
2800
 
2801
+ /**
2802
+ * @returns JSON Web Key Set (JWKS) URL with the keys used for validating JWTs returned by the {@link customerProof} method.
2803
+ */
2804
+ customerProofJwksUrl(): URL {
2805
+ const url = "/v0/mmi/v3/.well-known/jwks.json";
2806
+ op(url, "get"); // just to type check the url above
2807
+ return new URL(`${this.env.SignerApiRoot.replace(/\/$/, "")}${url}`);
2808
+ }
2809
+
2773
2810
  // #endregion
2774
2811
 
2775
2812
  /**