@cubist-labs/cubesigner-sdk 0.1.26 → 0.1.77
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/README.md +94 -33
- package/dist/src/ethers/index.d.ts +25 -5
- package/dist/src/ethers/index.js +58 -16
- package/dist/src/fido.d.ts +76 -0
- package/dist/src/fido.js +148 -0
- package/dist/src/index.d.ts +148 -35
- package/dist/src/index.js +320 -53
- package/dist/src/key.d.ts +64 -8
- package/dist/src/key.js +91 -19
- package/dist/src/org.d.ts +98 -9
- package/dist/src/org.js +144 -29
- package/dist/src/paginator.d.ts +76 -0
- package/dist/src/paginator.js +99 -0
- package/dist/src/role.d.ts +20 -8
- package/dist/src/role.js +7 -5
- package/dist/src/schema.d.ts +2395 -393
- package/dist/src/schema.js +1 -1
- package/dist/src/session/cognito_manager.d.ts +59 -0
- package/dist/src/session/cognito_manager.js +111 -0
- package/dist/src/session/session_manager.d.ts +15 -0
- package/dist/src/session/session_manager.js +21 -2
- package/dist/src/session/session_storage.js +1 -1
- package/dist/src/session/signer_session_manager.d.ts +24 -12
- package/dist/src/session/signer_session_manager.js +45 -20
- package/dist/src/signer_session.d.ts +136 -38
- package/dist/src/signer_session.js +187 -80
- package/dist/src/util.d.ts +20 -0
- package/dist/src/util.js +31 -2
- package/package.json +12 -7
- package/src/ethers/index.ts +88 -16
- package/src/fido.ts +166 -0
- package/src/index.ts +366 -77
- package/src/key.ts +112 -16
- package/src/org.ts +200 -37
- package/src/paginator.ts +122 -0
- package/src/role.ts +24 -11
- package/src/schema.ts +2458 -449
- package/src/session/{management_session_manager.ts → cognito_manager.ts} +13 -15
- package/src/session/session_manager.ts +25 -1
- package/src/session/session_storage.ts +1 -1
- package/src/session/signer_session_manager.ts +57 -27
- package/src/signer_session.ts +266 -89
- package/src/util.ts +41 -0
- package/src/session/oidc_session_manager.ts +0 -193
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { CubeSigner, Key,
|
|
1
|
+
import { CubeSigner, Key, KeyInfo, MfaReceipt, IdentityProof, MfaFidoChallenge } from ".";
|
|
2
2
|
import { components, paths } from "./client";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { JsonMap } from "./util";
|
|
4
|
+
import { PublicKeyCredential } from "./fido";
|
|
5
|
+
import { NewSessionResponse, SignerSessionManager, SignerSessionStorage } from "./session/signer_session_manager";
|
|
5
6
|
export type EvmSignRequest = paths["/v1/org/{org_id}/eth1/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
|
|
6
7
|
export type Eth2SignRequest = paths["/v1/org/{org_id}/eth2/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
|
|
7
8
|
export type Eth2StakeRequest = paths["/v1/org/{org_id}/eth2/stake"]["post"]["requestBody"]["content"]["application/json"];
|
|
8
9
|
export type Eth2UnstakeRequest = paths["/v1/org/{org_id}/eth2/unstake/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
|
|
9
10
|
export type BlobSignRequest = paths["/v1/org/{org_id}/blob/sign/{key_id}"]["post"]["requestBody"]["content"]["application/json"];
|
|
10
11
|
export type BtcSignRequest = paths["/v0/org/{org_id}/btc/sign/{pubkey}"]["post"]["requestBody"]["content"]["application/json"];
|
|
11
|
-
export type SolanaSignRequest = paths["/
|
|
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"];
|
|
12
14
|
export type EvmSignResponse = components["responses"]["Eth1SignResponse"]["content"]["application/json"];
|
|
13
15
|
export type Eth2SignResponse = components["responses"]["Eth2SignResponse"]["content"]["application/json"];
|
|
14
16
|
export type Eth2StakeResponse = components["responses"]["StakeResponse"]["content"]["application/json"];
|
|
@@ -17,25 +19,69 @@ export type BlobSignResponse = components["responses"]["BlobSignResponse"]["cont
|
|
|
17
19
|
export type BtcSignResponse = components["responses"]["BtcSignResponse"]["content"]["application/json"];
|
|
18
20
|
export type SolanaSignResponse = components["responses"]["SolanaSignResponse"]["content"]["application/json"];
|
|
19
21
|
export type MfaRequestInfo = components["responses"]["MfaRequestInfo"]["content"]["application/json"];
|
|
22
|
+
export type AvaSignResponse = components["responses"]["AvaSignResponse"]["content"]["application/json"];
|
|
20
23
|
export type AcceptedResponse = components["schemas"]["AcceptedResponse"];
|
|
21
24
|
export type ErrorResponse = components["schemas"]["ErrorResponse"];
|
|
22
25
|
export type BtcSignatureKind = components["schemas"]["BtcSignatureKind"];
|
|
23
26
|
/** MFA request kind */
|
|
24
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
|
+
};
|
|
25
58
|
type SignFn<U> = (headers?: HeadersInit) => Promise<U | AcceptedResponse>;
|
|
59
|
+
export interface MfaRequired {
|
|
60
|
+
/** Org id */
|
|
61
|
+
org_id: string;
|
|
62
|
+
/** MFA request id */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Optional MFA session */
|
|
65
|
+
session?: NewSessionResponse | null;
|
|
66
|
+
}
|
|
26
67
|
/**
|
|
27
|
-
* A response of a
|
|
68
|
+
* A response of a CubeSigner request.
|
|
28
69
|
*/
|
|
29
70
|
export declare class SignResponse<U> {
|
|
30
71
|
#private;
|
|
31
|
-
/** @return {
|
|
72
|
+
/** @return {string} The MFA id associated with this request */
|
|
73
|
+
mfaId(): string;
|
|
74
|
+
/** @return {boolean} True if this request requires an MFA approval */
|
|
32
75
|
requiresMfa(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Returns session information to use for any MFA approval requests (if any was included in the response).
|
|
78
|
+
* @return {ClientSessionInfo | undefined}
|
|
79
|
+
*/
|
|
80
|
+
mfaSessionInfo(): NewSessionResponse | undefined;
|
|
33
81
|
/** @return {U} The signed data */
|
|
34
82
|
data(): U;
|
|
35
83
|
/**
|
|
36
|
-
* Approves the MFA request using a given
|
|
37
|
-
*
|
|
38
|
-
* Note: This only works for MFA requests that require a single approval.
|
|
84
|
+
* Approves the MFA request using a given session and a TOTP code.
|
|
39
85
|
*
|
|
40
86
|
* @param {SignerSession} session Signer session to use
|
|
41
87
|
* @param {string} code 6-digit TOTP code
|
|
@@ -43,25 +89,43 @@ export declare class SignResponse<U> {
|
|
|
43
89
|
*/
|
|
44
90
|
approveTotp(session: SignerSession, code: string): Promise<SignResponse<U>>;
|
|
45
91
|
/**
|
|
46
|
-
* Approves the MFA request using CubeSigner
|
|
47
|
-
*
|
|
48
|
-
* Note: This only works for MFA requests that require a single approval.
|
|
92
|
+
* Approves the MFA request using a given `CubeSigner` instance (i.e., its management session).
|
|
49
93
|
*
|
|
94
|
+
* @param {CubeSigner} cs CubeSigner whose session to use
|
|
50
95
|
* @return {SignResponse<U>} The result of signing with the approval
|
|
51
96
|
*/
|
|
52
|
-
approve(): Promise<SignResponse<U>>;
|
|
97
|
+
approve(cs: CubeSigner): Promise<SignResponse<U>>;
|
|
98
|
+
/**
|
|
99
|
+
* @param {MfaReceipt} mfaReceipt The MFA receipt
|
|
100
|
+
* @return {Promise<SignResponse<U>>} The result of signing after MFA approval
|
|
101
|
+
*/
|
|
102
|
+
signWithMfaApproval(mfaReceipt: MfaReceipt): Promise<SignResponse<U>>;
|
|
53
103
|
/**
|
|
54
104
|
* Constructor.
|
|
55
105
|
*
|
|
56
|
-
* @param {CubeSigner} cs The CubeSigner instance to use for requests
|
|
57
|
-
* @param {string} orgId The org id of the corresponding signing request
|
|
58
106
|
* @param {SignFn} signFn The signing function that this response is from.
|
|
59
107
|
* This argument is used to resend requests with
|
|
60
108
|
* different headers if needed.
|
|
61
109
|
* @param {U | AcceptedResponse} resp The response as returned by the OpenAPI
|
|
62
110
|
* client.
|
|
63
111
|
*/
|
|
64
|
-
constructor(
|
|
112
|
+
constructor(signFn: SignFn<U>, resp: U | AcceptedResponse);
|
|
113
|
+
/**
|
|
114
|
+
* 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.
|
|
118
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
119
|
+
* @return {Promise<SignResponse<U>>} New instance of this class.
|
|
120
|
+
*/
|
|
121
|
+
static create<U>(signFn: SignFn<U>, mfaReceipt?: MfaReceipt): Promise<SignResponse<U>>;
|
|
122
|
+
/**
|
|
123
|
+
* Returns HTTP headers containing a given MFA receipt.
|
|
124
|
+
*
|
|
125
|
+
* @param {MfaReceipt} mfaReceipt MFA receipt
|
|
126
|
+
* @return {HeadersInit} Headers including that receipt
|
|
127
|
+
*/
|
|
128
|
+
static getMfaHeaders(mfaReceipt?: MfaReceipt): HeadersInit | undefined;
|
|
65
129
|
}
|
|
66
130
|
/** Signer session info. Can only be used to revoke a token, but not for authentication. */
|
|
67
131
|
export declare class SignerSessionInfo {
|
|
@@ -83,13 +147,14 @@ export declare class SignerSessionInfo {
|
|
|
83
147
|
/** Signer session. */
|
|
84
148
|
export declare class SignerSession {
|
|
85
149
|
#private;
|
|
86
|
-
|
|
87
|
-
|
|
150
|
+
sessionMgr: SignerSessionManager;
|
|
151
|
+
/** Org id */
|
|
152
|
+
get orgId(): string;
|
|
88
153
|
/**
|
|
89
154
|
* Returns the list of keys that this token grants access to.
|
|
90
155
|
* @return {Key[]} The list of keys.
|
|
91
156
|
*/
|
|
92
|
-
keys(): Promise<
|
|
157
|
+
keys(): Promise<KeyInfo[]>;
|
|
93
158
|
/**
|
|
94
159
|
* Approve a pending MFA request using TOTP.
|
|
95
160
|
*
|
|
@@ -98,75 +163,108 @@ export declare class SignerSession {
|
|
|
98
163
|
* @return {Promise<MfaRequestInfo>} The current status of the MFA request
|
|
99
164
|
*/
|
|
100
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>;
|
|
101
187
|
/**
|
|
102
188
|
* Submit an EVM sign request.
|
|
103
189
|
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
104
190
|
* @param {EvmSignRequest} req What to sign.
|
|
191
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt.
|
|
105
192
|
* @return {Promise<EvmSignResponse | AcceptedResponse>} Signature
|
|
106
193
|
*/
|
|
107
|
-
signEvm(key: Key | string, req: EvmSignRequest): Promise<SignResponse<EvmSignResponse>>;
|
|
194
|
+
signEvm(key: Key | string, req: EvmSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<EvmSignResponse>>;
|
|
108
195
|
/**
|
|
109
196
|
* Submit an 'eth2' sign request.
|
|
110
197
|
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
111
198
|
* @param {Eth2SignRequest} req What to sign.
|
|
199
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
112
200
|
* @return {Promise<Eth2SignResponse | AcceptedResponse>} Signature
|
|
113
201
|
*/
|
|
114
|
-
signEth2(key: Key | string, req: Eth2SignRequest): Promise<SignResponse<Eth2SignResponse>>;
|
|
202
|
+
signEth2(key: Key | string, req: Eth2SignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2SignResponse>>;
|
|
115
203
|
/**
|
|
116
204
|
* Sign a stake request.
|
|
117
205
|
* @param {Eth2StakeRequest} req The request to sign.
|
|
206
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
118
207
|
* @return {Promise<Eth2StakeResponse | AcceptedResponse>} The response.
|
|
119
208
|
*/
|
|
120
|
-
stake(req: Eth2StakeRequest): Promise<SignResponse<Eth2StakeResponse>>;
|
|
209
|
+
stake(req: Eth2StakeRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2StakeResponse>>;
|
|
121
210
|
/**
|
|
122
211
|
* Sign an unstake request.
|
|
123
212
|
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
124
213
|
* @param {Eth2UnstakeRequest} req The request to sign.
|
|
214
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
125
215
|
* @return {Promise<Eth2UnstakeResponse | AcceptedResponse>} The response.
|
|
126
216
|
*/
|
|
127
|
-
unstake(key: Key | string, req: Eth2UnstakeRequest): Promise<SignResponse<Eth2UnstakeResponse>>;
|
|
217
|
+
unstake(key: Key | string, req: Eth2UnstakeRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<Eth2UnstakeResponse>>;
|
|
128
218
|
/**
|
|
129
219
|
* Sign a raw blob.
|
|
130
220
|
* @param {Key | string} key The key to sign with (either {@link Key} or its ID).
|
|
131
221
|
* @param {BlobSignRequest} req What to sign
|
|
222
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
132
223
|
* @return {Promise<BlobSignResponse | AcceptedResponse>} The response.
|
|
133
224
|
*/
|
|
134
|
-
signBlob(key: Key | string, req: BlobSignRequest): Promise<SignResponse<BlobSignResponse>>;
|
|
225
|
+
signBlob(key: Key | string, req: BlobSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<BlobSignResponse>>;
|
|
135
226
|
/**
|
|
136
227
|
* Sign a bitcoin message.
|
|
137
228
|
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
138
229
|
* @param {BtcSignRequest} req What to sign
|
|
230
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
139
231
|
* @return {Promise<BtcSignResponse | AcceptedResponse>} The response.
|
|
140
232
|
*/
|
|
141
|
-
signBtc(key: Key | string, req: BtcSignRequest): Promise<SignResponse<BtcSignResponse>>;
|
|
233
|
+
signBtc(key: Key | string, req: BtcSignRequest, mfaReceipt?: MfaReceipt): Promise<SignResponse<BtcSignResponse>>;
|
|
142
234
|
/**
|
|
143
235
|
* Sign a solana message.
|
|
144
236
|
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
145
237
|
* @param {SolanaSignRequest} req What to sign
|
|
238
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
146
239
|
* @return {Promise<SolanaSignResponse | AcceptedResponse>} The response.
|
|
147
240
|
*/
|
|
148
|
-
signSolana(key: Key | string, req: SolanaSignRequest): Promise<SignResponse<SolanaSignResponse>>;
|
|
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>>;
|
|
250
|
+
/**
|
|
251
|
+
* Obtain a proof of authentication.
|
|
252
|
+
*
|
|
253
|
+
* @return {Promise<IdentityProof>} Proof of authentication
|
|
254
|
+
*/
|
|
255
|
+
proveIdentity(): Promise<IdentityProof>;
|
|
149
256
|
/**
|
|
150
257
|
* Loads an existing signer session from storage.
|
|
151
|
-
* @param {CubeSigner} cs The CubeSigner instance
|
|
152
258
|
* @param {SignerSessionStorage} storage The session storage to use
|
|
153
259
|
* @return {Promise<SingerSession>} New signer session
|
|
154
260
|
*/
|
|
155
|
-
static loadSignerSession(
|
|
156
|
-
/**
|
|
157
|
-
* Loads an existing OIDC session from storage
|
|
158
|
-
* @param {CubeSigner} cs The CubeSigner instance
|
|
159
|
-
* @param {OidcSessionStorage} storage The storage to use
|
|
160
|
-
* @return {Promise<SignerSession>} New signer session
|
|
161
|
-
*/
|
|
162
|
-
static loadOidcSession(cs: CubeSigner, storage: OidcSessionStorage): Promise<SignerSession>;
|
|
261
|
+
static loadSignerSession(storage: SignerSessionStorage): Promise<SignerSession>;
|
|
163
262
|
/**
|
|
164
263
|
* Constructor.
|
|
165
|
-
* @param {
|
|
166
|
-
* @param {OidcSessionManager | SignerSessionManager} sessionMgr The session manager to use
|
|
264
|
+
* @param {SignerSessionManager} sessionMgr The session manager to use
|
|
167
265
|
* @internal
|
|
168
266
|
*/
|
|
169
|
-
constructor(
|
|
267
|
+
constructor(sessionMgr: SignerSessionManager);
|
|
170
268
|
/**
|
|
171
269
|
* Static method for revoking a token (used both from {SignerSession} and {SignerSessionInfo}).
|
|
172
270
|
* @param {CubeSigner} cs CubeSigner instance
|