@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,61 +1,19 @@
1
- import { CubeSigner, Key, KeyInfo, MfaReceipt, IdentityProof, MfaFidoChallenge } from ".";
2
- import { components, paths } from "./client";
3
- import { JsonMap } from "./util";
4
- import { PublicKeyCredential } from "./fido";
5
- import { NewSessionResponse, SignerSessionManager, SignerSessionStorage } from "./session/signer_session_manager";
6
- export type EvmSignRequest = paths["/v1/org/{org_id}/eth1/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
7
- export type Eth2SignRequest = paths["/v1/org/{org_id}/eth2/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
8
- export type Eth2StakeRequest = paths["/v1/org/{org_id}/eth2/stake"]["post"]["requestBody"]["content"]["application/json"];
9
- export type Eth2UnstakeRequest = paths["/v1/org/{org_id}/eth2/unstake/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
10
- export type BlobSignRequest = paths["/v1/org/{org_id}/blob/sign/{key_id}"]["post"]["requestBody"]["content"]["application/json"];
11
- export type BtcSignRequest = paths["/v0/org/{org_id}/btc/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
12
- export type SolanaSignRequest = paths["/v0/org/{org_id}/solana/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
13
- export type AvaSignRequest = paths["/v0/org/{org_id}/ava/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
14
- export type EvmSignResponse = components["responses"]["Eth1SignResponse"]["content"]["application/json"];
15
- export type Eth2SignResponse = components["responses"]["Eth2SignResponse"]["content"]["application/json"];
16
- export type Eth2StakeResponse = components["responses"]["StakeResponse"]["content"]["application/json"];
17
- export type Eth2UnstakeResponse = components["responses"]["UnstakeResponse"]["content"]["application/json"];
18
- export type BlobSignResponse = components["responses"]["BlobSignResponse"]["content"]["application/json"];
19
- export type BtcSignResponse = components["responses"]["BtcSignResponse"]["content"]["application/json"];
20
- export type SolanaSignResponse = components["responses"]["SolanaSignResponse"]["content"]["application/json"];
21
- export type MfaRequestInfo = components["responses"]["MfaRequestInfo"]["content"]["application/json"];
22
- export type AvaSignResponse = components["responses"]["AvaSignResponse"]["content"]["application/json"];
23
- export type AcceptedResponse = components["schemas"]["AcceptedResponse"];
24
- export type ErrorResponse = components["schemas"]["ErrorResponse"];
25
- export type BtcSignatureKind = components["schemas"]["BtcSignatureKind"];
26
- /** MFA request kind */
27
- export type MfaType = components["schemas"]["MfaType"];
28
- /** Ava P- or X-chain transaction */
29
- export type AvaTx = {
30
- P: AvaPChainTx;
31
- } | {
32
- X: AvaXChainTx;
33
- };
34
- /** Ava P-chain transaction */
35
- export type AvaPChainTx = {
36
- AddPermissionlessValidator: JsonMap;
37
- } | {
38
- AddSubnetValidator: JsonMap;
39
- } | {
40
- AddValidator: JsonMap;
41
- } | {
42
- CreateChain: JsonMap;
43
- } | {
44
- CreateSubnet: JsonMap;
45
- } | {
46
- Export: JsonMap;
47
- } | {
48
- Import: JsonMap;
49
- };
50
- /** Ava X-chain transaction */
51
- export type AvaXChainTx = {
52
- Base: JsonMap;
53
- } | {
54
- Export: JsonMap;
55
- } | {
56
- Import: JsonMap;
57
- };
58
- type SignFn<U> = (headers?: HeadersInit) => Promise<U | AcceptedResponse>;
1
+ import { CubeSigner, MfaReceipt, KeyInfo } from ".";
2
+ import { CubeSignerClient } from "./client";
3
+ import { AcceptedResponse, NewSessionResponse } from "./schema_types";
4
+ import { SignerSessionManager, SignerSessionStorage } from "./session/signer_session_manager";
5
+ type Response<U> = U | AcceptedResponse;
6
+ type RequestFn<U> = (headers?: HeadersInit) => Promise<Response<U>>;
7
+ type MapFn<U, V> = (u: U) => V;
8
+ /**
9
+ * Takes a {@link Response<U>} and a {@link MapFn<U, V>} function and returns
10
+ * a {@link Response<V>} that maps the value of the original response when its status code is 200.
11
+ *
12
+ * @param {Response<U>} resp Original response
13
+ * @param {Map<U, V>} mapFn Map to apply to the response value when its status code is 200.
14
+ * @return {Response<V>} Response whose value for status code 200 is mapped from U to V
15
+ */
16
+ export declare function mapResponse<U, V>(resp: Response<U>, mapFn: MapFn<U, V>): Response<V>;
59
17
  export interface MfaRequired {
60
18
  /** Org id */
61
19
  org_id: string;
@@ -67,7 +25,7 @@ export interface MfaRequired {
67
25
  /**
68
26
  * A response of a CubeSigner request.
69
27
  */
70
- export declare class SignResponse<U> {
28
+ export declare class CubeSignerResponse<U> {
71
29
  #private;
72
30
  /** @return {string} The MFA id associated with this request */
73
31
  mfaId(): string;
@@ -78,47 +36,46 @@ export declare class SignResponse<U> {
78
36
  * @return {ClientSessionInfo | undefined}
79
37
  */
80
38
  mfaSessionInfo(): NewSessionResponse | undefined;
81
- /** @return {U} The signed data */
39
+ /** @return {U} The response data, if no MFA is required */
82
40
  data(): U;
83
41
  /**
84
42
  * Approves the MFA request using a given session and a TOTP code.
85
43
  *
86
44
  * @param {SignerSession} session Signer session to use
87
45
  * @param {string} code 6-digit TOTP code
88
- * @return {SignResponse<U>} The result of signing with the approval
46
+ * @return {CubeSignerResponse<U>} The result of signing with the approval
89
47
  */
90
- approveTotp(session: SignerSession, code: string): Promise<SignResponse<U>>;
48
+ approveTotp(session: SignerSession, code: string): Promise<CubeSignerResponse<U>>;
91
49
  /**
92
- * Approves the MFA request using a given `CubeSigner` instance (i.e., its management session).
50
+ * Approves the MFA request using a given `CubeSignerClient` instance (i.e., its session).
93
51
  *
94
52
  * @param {CubeSigner} cs CubeSigner whose session to use
95
- * @return {SignResponse<U>} The result of signing with the approval
53
+ * @return {CubeSignerResponse<U>} The result of signing with the approval
96
54
  */
97
- approve(cs: CubeSigner): Promise<SignResponse<U>>;
55
+ approve(cs: CubeSigner): Promise<CubeSignerResponse<U>>;
98
56
  /**
99
57
  * @param {MfaReceipt} mfaReceipt The MFA receipt
100
- * @return {Promise<SignResponse<U>>} The result of signing after MFA approval
58
+ * @return {Promise<CubeSignerResponse<U>>} The result of signing after MFA approval
101
59
  */
102
- signWithMfaApproval(mfaReceipt: MfaReceipt): Promise<SignResponse<U>>;
60
+ signWithMfaApproval(mfaReceipt: MfaReceipt): Promise<CubeSignerResponse<U>>;
103
61
  /**
104
62
  * Constructor.
105
63
  *
106
- * @param {SignFn} signFn The signing function that this response is from.
107
- * This argument is used to resend requests with
108
- * different headers if needed.
109
- * @param {U | AcceptedResponse} resp The response as returned by the OpenAPI
110
- * client.
64
+ * @param {RequestFn} requestFn
65
+ * The signing function that this response is from.
66
+ * This argument is used to resend requests with different headers if needed.
67
+ * @param {U | AcceptedResponse} resp The response as returned by the OpenAPI client.
111
68
  */
112
- constructor(signFn: SignFn<U>, resp: U | AcceptedResponse);
69
+ constructor(requestFn: RequestFn<U>, resp: U | AcceptedResponse);
113
70
  /**
114
71
  * Static constructor.
115
- * @param {SignFn} signFn The signing function that this response is from.
116
- * This argument is used to resend requests with
117
- * different headers if needed.
72
+ * @param {RequestFn} requestFn
73
+ * The request function that this response is from.
74
+ * This argument is used to resend requests with different headers if needed.
118
75
  * @param {MfaReceipt} mfaReceipt Optional MFA receipt
119
- * @return {Promise<SignResponse<U>>} New instance of this class.
76
+ * @return {Promise<CubeSignerResponse<U>>} New instance of this class.
120
77
  */
121
- static create<U>(signFn: SignFn<U>, mfaReceipt?: MfaReceipt): Promise<SignResponse<U>>;
78
+ static create<U>(requestFn: RequestFn<U>, mfaReceipt?: MfaReceipt): Promise<CubeSignerResponse<U>>;
122
79
  /**
123
80
  * Returns HTTP headers containing a given MFA receipt.
124
81
  *
@@ -131,128 +88,201 @@ export declare class SignResponse<U> {
131
88
  export declare class SignerSessionInfo {
132
89
  #private;
133
90
  readonly purpose: string;
134
- /** Revoke this token */
91
+ /** Revoke this session */
135
92
  revoke(): Promise<void>;
136
93
  /**
137
94
  * Internal constructor.
138
- * @param {CubeSigner} cs CubeSigner instance to use when calling `revoke`
139
- * @param {string} orgId Organization ID
140
- * @param {string} roleId Role ID
141
- * @param {string} hash The hash of the token; can be used for revocation but not for auth
95
+ * @param {CubeSignerClient} cs CubeSigner instance to use when calling `revoke`
96
+ * @param {string} sessionId The ID of the session; can be used for revocation but not for auth
142
97
  * @param {string} purpose Session purpose
143
98
  * @internal
144
99
  */
145
- constructor(cs: CubeSigner, orgId: string, roleId: string, hash: string, purpose: string);
100
+ constructor(cs: CubeSignerClient, sessionId: string, purpose: string);
146
101
  }
147
- /** Signer session. */
102
+ /**
103
+ * Signer session.
104
+ *
105
+ * @deprecated Use {@link CubeSignerClient} instead.
106
+ */
148
107
  export declare class SignerSession {
149
108
  #private;
150
- sessionMgr: SignerSessionManager;
109
+ /** Deprecated */
110
+ get sessionMgr(): SignerSessionManager;
151
111
  /** Org id */
152
112
  get orgId(): string;
153
113
  /**
154
114
  * Returns the list of keys that this token grants access to.
155
- * @return {Key[]} The list of keys.
115
+ * @return {KeyInfo[]} The list of keys.
156
116
  */
157
117
  keys(): Promise<KeyInfo[]>;
158
- /**
159
- * Approve a pending MFA request using TOTP.
160
- *
161
- * @param {string} mfaId The MFA request to approve
162
- * @param {string} code The TOTP code
163
- * @return {Promise<MfaRequestInfo>} The current status of the MFA request
164
- */
165
- totpApprove(mfaId: string, code: string): Promise<MfaRequestInfo>;
166
- /**
167
- * Initiate approval of an existing MFA request using FIDO.
168
- * @param {string} mfaId The MFA request ID.
169
- * @return {Promise<MfaFidoChallenge>} A challenge that needs to be answered to complete the approval.
170
- */
171
- fidoApproveStart(mfaId: string): Promise<MfaFidoChallenge>;
172
- /**
173
- * Complete a previously initiated MFA request approval using FIDO.
174
- * @param {string} mfaId The MFA request ID
175
- * @param {string} challengeId The challenge ID
176
- * @param {PublicKeyCredential} credential The answer to the challenge
177
- * @return {Promise<MfaRequestInfo>} The current status of the MFA request.
178
- */
179
- fidoApproveComplete(mfaId: string, challengeId: string, credential: PublicKeyCredential): Promise<MfaRequestInfo>;
180
- /**
181
- * Get a pending MFA request by its id.
182
- * @param {CubeSigner} cs Management session to use (this argument will be removed in future versions)
183
- * @param {string} mfaId The id of the MFA request.
184
- * @return {Promise<MfaRequestInfo>} The MFA request.
185
- */
186
- getMfaInfo(cs: CubeSigner, mfaId: string): Promise<MfaRequestInfo>;
187
- /**
188
- * Submit an EVM sign request.
189
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
190
- * @param {EvmSignRequest} req What to sign.
191
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt.
192
- * @return {Promise<EvmSignResponse | AcceptedResponse>} Signature
193
- */
194
- signEvm(key: Key | string, req: EvmSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<EvmSignResponse>>;
195
- /**
196
- * Submit an 'eth2' sign request.
197
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
198
- * @param {Eth2SignRequest} req What to sign.
199
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
200
- * @return {Promise<Eth2SignResponse | AcceptedResponse>} Signature
201
- */
202
- signEth2(key: Key | string, req: Eth2SignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2SignResponse>>;
203
- /**
204
- * Sign a stake request.
205
- * @param {Eth2StakeRequest} req The request to sign.
206
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
207
- * @return {Promise<Eth2StakeResponse | AcceptedResponse>} The response.
208
- */
209
- stake(req: Eth2StakeRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2StakeResponse>>;
210
- /**
211
- * Sign an unstake request.
212
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
213
- * @param {Eth2UnstakeRequest} req The request to sign.
214
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
215
- * @return {Promise<Eth2UnstakeResponse | AcceptedResponse>} The response.
216
- */
217
- unstake(key: Key | string, req: Eth2UnstakeRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2UnstakeResponse>>;
218
- /**
219
- * Sign a raw blob.
220
- * @param {Key | string} key The key to sign with (either {@link Key} or its ID).
221
- * @param {BlobSignRequest} req What to sign
222
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
223
- * @return {Promise<BlobSignResponse | AcceptedResponse>} The response.
224
- */
225
- signBlob(key: Key | string, req: BlobSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<BlobSignResponse>>;
226
- /**
227
- * Sign a bitcoin message.
228
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
229
- * @param {BtcSignRequest} req What to sign
230
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
231
- * @return {Promise<BtcSignResponse | AcceptedResponse>} The response.
232
- */
233
- signBtc(key: Key | string, req: BtcSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<BtcSignResponse>>;
234
- /**
235
- * Sign a solana message.
236
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
237
- * @param {SolanaSignRequest} req What to sign
238
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
239
- * @return {Promise<SolanaSignResponse | AcceptedResponse>} The response.
240
- */
241
- signSolana(key: Key | string, req: SolanaSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<SolanaSignResponse>>;
242
- /**
243
- * Sign an Avalanche P- or X-chain message.
244
- * @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
245
- * @param {AvaTx} tx Avalanche message (transaction) to sign
246
- * @param {MfaReceipt} mfaReceipt Optional MFA receipt
247
- * @return {Promise<AvaSignResponse | AcceptedResponse>} The response.
248
- */
249
- signAva(key: Key | string, tx: AvaTx, mfaReceipt?: MfaReceipt): Promise<SignResponse<AvaSignResponse>>;
118
+ /** Approve a pending MFA request using TOTP. */
119
+ get totpApprove(): (mfaId: string, code: string) => Promise<{
120
+ expires_at: number;
121
+ id: string;
122
+ receipt?: {
123
+ confirmation: string;
124
+ final_approver: string;
125
+ timestamp: number;
126
+ } | null | undefined;
127
+ request: {
128
+ body?: Record<string, unknown> | null | undefined;
129
+ method: string;
130
+ path: string;
131
+ };
132
+ status: {
133
+ allowed_approvers: string[];
134
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
135
+ approved_by: {
136
+ [key: string]: {
137
+ [key: string]: {
138
+ timestamp: number;
139
+ };
140
+ };
141
+ };
142
+ count: number;
143
+ num_auth_factors: number;
144
+ };
145
+ }>;
146
+ /** Initiate approval of an existing MFA request using FIDO. */
147
+ get fidoApproveStart(): (mfaId: string) => Promise<import("./mfa").MfaFidoChallenge>;
148
+ /** Get a pending MFA request by its id. */
149
+ get getMfaInfo(): (mfaId: string) => Promise<{
150
+ expires_at: number;
151
+ id: string;
152
+ receipt?: {
153
+ confirmation: string;
154
+ final_approver: string;
155
+ timestamp: number;
156
+ } | null | undefined;
157
+ request: {
158
+ body?: Record<string, unknown> | null | undefined;
159
+ method: string;
160
+ path: string;
161
+ };
162
+ status: {
163
+ allowed_approvers: string[];
164
+ allowed_mfa_types?: ("CubeSigner" | "Totp" | "Fido")[] | null | undefined;
165
+ approved_by: {
166
+ [key: string]: {
167
+ [key: string]: {
168
+ timestamp: number;
169
+ };
170
+ };
171
+ };
172
+ count: number;
173
+ num_auth_factors: number;
174
+ };
175
+ }>;
176
+ /** Submit an EVM sign request. */
177
+ get signEvm(): (key: string | import("./key").Key, req: {
178
+ chain_id: number;
179
+ tx: Record<string, never>;
180
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
181
+ rlp_signed_tx: string;
182
+ }>>;
183
+ /** Submit an 'eth2' sign request. */
184
+ get signEth2(): (key: string | import("./key").Key, req: {
185
+ eth2_sign_request: Record<string, never>;
186
+ network: "mainnet" | "prater" | "goerli" | "holesky";
187
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
188
+ signature: string;
189
+ }>>;
190
+ /** Sign a stake request. */
191
+ get stake(): (req: {
192
+ chain_id: number;
193
+ deposit_type: "Canonical" | "Wrapper";
194
+ staking_amount_gwei?: number | undefined;
195
+ unsafe_conf?: {
196
+ deposit_contract_addr?: string | null | undefined;
197
+ genesis_fork_version?: string | null | undefined;
198
+ } | null | undefined;
199
+ validator_key?: string | null | undefined;
200
+ withdrawal_addr: string;
201
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
202
+ created_validator_key_id: string;
203
+ deposit_tx: {
204
+ chain_id: number;
205
+ deposit_txn: Record<string, never>;
206
+ new_validator_pk: string;
207
+ };
208
+ }>>;
209
+ /** Sign an unstake request. */
210
+ get unstake(): (key: string | import("./key").Key, req: {
211
+ epoch?: string | null | undefined;
212
+ fork: {
213
+ current_version: string;
214
+ epoch: string;
215
+ previous_version: string;
216
+ };
217
+ genesis_data: {
218
+ genesis_fork_version: string;
219
+ genesis_time: string;
220
+ genesis_validators_root: string;
221
+ };
222
+ network: "mainnet" | "prater" | "goerli" | "holesky";
223
+ validator_index: string;
224
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
225
+ message: {
226
+ epoch: string;
227
+ validator_index: string;
228
+ };
229
+ signature: string;
230
+ }>>;
231
+ /** Sign a raw blob.*/
232
+ get signBlob(): (key: string | import("./key").Key, req: {
233
+ message_base64: string;
234
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
235
+ signature: string;
236
+ }>>;
237
+ /** Sign a bitcoin message. */
238
+ get signBtc(): (key: string | import("./key").Key, req: {
239
+ sig_kind: {
240
+ Segwit: {
241
+ input_index: number;
242
+ script_code: string;
243
+ sighash_type: "All" | "None" | "Single" | "AllPlusAnyoneCanPay" | "NonePlusAnyoneCanPay" | "SinglePlusAnyoneCanPay";
244
+ value: number;
245
+ };
246
+ };
247
+ tx: Record<string, never>;
248
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
249
+ signature: string;
250
+ }>>;
251
+ /** Sign a solana message. */
252
+ get signSolana(): (key: string | import("./key").Key, req: {
253
+ message_base64: string;
254
+ }, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
255
+ signature: string;
256
+ }>>;
257
+ /** Sign an Avalanche P- or X-chain message. */
258
+ get signAva(): (key: string | import("./key").Key, tx: import("./schema_types").AvaTx, mfaReceipt?: MfaReceipt | undefined) => Promise<CubeSignerResponse<{
259
+ signature: string;
260
+ }>>;
250
261
  /**
251
262
  * Obtain a proof of authentication.
252
- *
253
- * @return {Promise<IdentityProof>} Proof of authentication
254
263
  */
255
- proveIdentity(): Promise<IdentityProof>;
264
+ get proveIdentity(): () => Promise<{
265
+ aud?: string | null | undefined;
266
+ email: string;
267
+ exp_epoch: number;
268
+ identity?: {
269
+ iss: string;
270
+ sub: string;
271
+ } | null | undefined;
272
+ user_info?: {
273
+ configured_mfa: ({
274
+ type: "totp";
275
+ } | {
276
+ id: string;
277
+ name: string;
278
+ type: "fido";
279
+ })[];
280
+ initialized: boolean;
281
+ user_id: string;
282
+ } | null | undefined;
283
+ } & {
284
+ id: string;
285
+ }>;
256
286
  /**
257
287
  * Loads an existing signer session from storage.
258
288
  * @param {SignerSessionStorage} storage The session storage to use
@@ -265,14 +295,5 @@ export declare class SignerSession {
265
295
  * @internal
266
296
  */
267
297
  constructor(sessionMgr: SignerSessionManager);
268
- /**
269
- * Static method for revoking a token (used both from {SignerSession} and {SignerSessionInfo}).
270
- * @param {CubeSigner} cs CubeSigner instance
271
- * @param {string} orgId Organization ID
272
- * @param {string} roleId Role ID
273
- * @param {string} sessionId Signer session ID
274
- * @internal
275
- */
276
- static revoke(cs: CubeSigner, orgId: string, roleId: string, sessionId: string): Promise<void>;
277
298
  }
278
299
  export {};