@cubist-labs/cubesigner-sdk 0.2.24 → 0.3.1
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 +30 -28
- package/dist/cjs/package.json +41 -0
- package/dist/cjs/spec/env/beta.json +9 -0
- package/dist/cjs/spec/env/gamma.json +9 -0
- package/dist/cjs/spec/env/prod.json +9 -0
- package/dist/cjs/src/api.d.ts +634 -0
- package/dist/cjs/src/api.js +1309 -0
- package/dist/cjs/src/client.d.ts +575 -0
- package/dist/cjs/src/client.js +378 -0
- package/dist/cjs/src/env.d.ts +15 -0
- package/dist/cjs/src/env.js +35 -0
- package/dist/cjs/src/error.d.ts +29 -0
- package/dist/cjs/src/error.js +36 -0
- package/dist/cjs/src/events.d.ts +84 -0
- package/dist/cjs/src/events.js +195 -0
- package/dist/cjs/src/index.d.ts +203 -0
- package/dist/cjs/src/index.js +298 -0
- package/dist/cjs/src/key.d.ts +152 -0
- package/dist/cjs/src/key.js +242 -0
- package/dist/{src/fido.d.ts → cjs/src/mfa.d.ts} +33 -15
- package/dist/cjs/src/mfa.js +169 -0
- package/dist/cjs/src/org.d.ts +99 -0
- package/dist/cjs/src/org.js +95 -0
- package/dist/cjs/src/paginator.d.ts +76 -0
- package/dist/cjs/src/paginator.js +99 -0
- package/dist/cjs/src/response.d.ts +101 -0
- package/dist/cjs/src/response.js +164 -0
- package/dist/cjs/src/role.d.ts +283 -0
- package/dist/cjs/src/role.js +253 -0
- package/dist/cjs/src/schema.d.ts +6209 -0
- package/dist/cjs/src/schema.js +7 -0
- package/dist/cjs/src/schema_types.d.ts +113 -0
- package/dist/cjs/src/schema_types.js +3 -0
- package/dist/cjs/src/session/session_storage.d.ts +27 -0
- package/dist/cjs/src/session/session_storage.js +47 -0
- package/dist/cjs/src/session/signer_session_manager.d.ts +125 -0
- package/dist/cjs/src/session/signer_session_manager.js +239 -0
- package/dist/cjs/src/signer_session.d.ts +41 -0
- package/dist/cjs/src/signer_session.js +77 -0
- package/dist/cjs/src/user_export.d.ts +52 -0
- package/dist/cjs/src/user_export.js +129 -0
- package/dist/cjs/src/util.d.ts +56 -0
- package/dist/cjs/src/util.js +86 -0
- package/dist/esm/package.json +41 -0
- package/dist/esm/spec/env/beta.json +9 -0
- package/dist/esm/spec/env/gamma.json +9 -0
- package/dist/esm/spec/env/prod.json +9 -0
- package/dist/esm/src/api.d.ts +634 -0
- package/dist/esm/src/api.js +1299 -0
- package/dist/esm/src/client.d.ts +575 -0
- package/dist/esm/src/client.js +374 -0
- package/dist/esm/src/env.d.ts +15 -0
- package/dist/esm/src/env.js +9 -0
- package/dist/esm/src/error.d.ts +29 -0
- package/dist/esm/src/error.js +31 -0
- package/dist/esm/src/events.d.ts +84 -0
- package/dist/esm/src/events.js +189 -0
- package/dist/esm/src/index.d.ts +203 -0
- package/dist/esm/src/index.js +276 -0
- package/dist/esm/src/key.d.ts +152 -0
- package/dist/esm/src/key.js +236 -0
- package/dist/esm/src/mfa.d.ts +94 -0
- package/dist/esm/src/mfa.js +163 -0
- package/dist/esm/src/org.d.ts +99 -0
- package/dist/esm/src/org.js +91 -0
- package/dist/esm/src/paginator.d.ts +76 -0
- package/dist/esm/src/paginator.js +94 -0
- package/dist/esm/src/response.d.ts +101 -0
- package/dist/esm/src/response.js +159 -0
- package/dist/esm/src/role.d.ts +283 -0
- package/dist/esm/src/role.js +248 -0
- package/dist/esm/src/schema.d.ts +6209 -0
- package/dist/esm/src/schema.js +6 -0
- package/dist/esm/src/schema_types.d.ts +113 -0
- package/dist/esm/src/schema_types.js +2 -0
- package/dist/esm/src/session/session_storage.d.ts +27 -0
- package/dist/esm/src/session/session_storage.js +43 -0
- package/dist/esm/src/session/signer_session_manager.d.ts +125 -0
- package/dist/esm/src/session/signer_session_manager.js +235 -0
- package/dist/esm/src/signer_session.d.ts +41 -0
- package/dist/esm/src/signer_session.js +72 -0
- package/dist/esm/src/user_export.d.ts +52 -0
- package/dist/esm/src/user_export.js +99 -0
- package/dist/esm/src/util.d.ts +56 -0
- package/dist/esm/src/util.js +76 -0
- package/dist/package.json +13 -45
- package/dist/src/api.d.ts +29 -18
- package/dist/src/api.js +70 -17
- package/dist/src/client.d.ts +35 -14
- package/dist/src/client.js +12 -8
- package/dist/src/error.d.ts +29 -0
- package/dist/src/error.js +36 -0
- package/dist/src/events.d.ts +1 -1
- package/dist/src/events.js +1 -1
- package/dist/src/index.d.ts +8 -11
- package/dist/src/index.js +11 -25
- package/dist/src/key.d.ts +18 -7
- package/dist/src/key.js +52 -19
- package/dist/src/role.d.ts +46 -3
- package/dist/src/role.js +60 -8
- package/dist/src/schema.d.ts +206 -72
- package/dist/src/schema.js +1 -1
- package/dist/src/schema_types.d.ts +3 -0
- package/dist/src/schema_types.js +1 -1
- package/dist/src/session/signer_session_manager.d.ts +49 -13
- package/dist/src/session/signer_session_manager.js +104 -26
- package/dist/src/util.d.ts +14 -0
- package/dist/src/util.js +24 -27
- package/package.json +19 -46
- package/src/api.ts +81 -23
- package/src/client.ts +12 -8
- package/src/error.ts +42 -0
- package/src/events.ts +3 -1
- package/src/index.ts +12 -24
- package/src/key.ts +36 -18
- package/src/role.ts +78 -7
- package/src/schema.ts +269 -110
- package/src/schema_types.ts +3 -0
- package/src/session/session_storage.ts +0 -32
- package/src/session/signer_session_manager.ts +137 -28
- package/src/util.ts +19 -10
- package/tsconfig.json +1 -21
- package/LICENSE-APACHE +0 -177
- package/LICENSE-MIT +0 -25
- package/NOTICE +0 -13
- package/dist/examples/ethers.d.ts +0 -1
- package/dist/examples/ethers.js +0 -142
- package/dist/src/ethers/index.d.ts +0 -95
- package/dist/src/ethers/index.js +0 -208
- package/dist/src/fido.js +0 -148
- package/dist/src/session/cognito_manager.d.ts +0 -71
- package/dist/src/session/cognito_manager.js +0 -129
- package/dist/src/session/generic.d.ts +0 -47
- package/dist/src/session/generic.js +0 -3
- package/dist/src/session/management_session_manager.d.ts +0 -59
- package/dist/src/session/management_session_manager.js +0 -111
- package/dist/src/session/oidc_session_manager.d.ts +0 -78
- package/dist/src/session/oidc_session_manager.js +0 -142
- package/dist/src/session/session_manager.d.ts +0 -99
- package/dist/src/session/session_manager.js +0 -136
- package/dist/src/sign.d.ts +0 -114
- package/dist/src/sign.js +0 -248
- package/dist/test/sessions.d.ts +0 -35
- package/dist/test/sessions.js +0 -56
- package/src/ethers/index.ts +0 -249
- package/src/session/cognito_manager.ts +0 -161
- package/src/session/session_manager.ts +0 -165
package/package.json
CHANGED
|
@@ -1,68 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubist-labs/cubesigner-sdk",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.2.24",
|
|
3
|
+
"version": "0.3.1",
|
|
5
4
|
"description": "CubeSigner TypeScript SDK",
|
|
6
|
-
"homepage": "https://github.com/cubist-labs/CubeSigner-TypeScript-SDK",
|
|
7
|
-
"bugs": "https://github.com/cubist-labs/CubeSigner-TypeScript-SDK/issues",
|
|
8
5
|
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"author": "Cubist, Inc.",
|
|
7
|
+
"main": "dist/cjs/src/index.js",
|
|
9
8
|
"files": [
|
|
10
9
|
"tsconfig.json",
|
|
11
10
|
"src/**",
|
|
12
11
|
"dist/**",
|
|
13
|
-
"NOTICE",
|
|
14
|
-
"LICENSE-APACHE",
|
|
15
|
-
"LICENSE-MIT"
|
|
12
|
+
"../..NOTICE",
|
|
13
|
+
"../..LICENSE-APACHE",
|
|
14
|
+
"../..LICENSE-MIT"
|
|
16
15
|
],
|
|
17
|
-
"
|
|
18
|
-
|
|
16
|
+
"exports": {
|
|
17
|
+
"require": "./dist/cjs/src/index.js",
|
|
18
|
+
"import": "./dist/esm/src/index.js"
|
|
19
|
+
},
|
|
19
20
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
+
"build": "npm run build:cjs && npm run build:mjs",
|
|
22
|
+
"prepack": "npm run build",
|
|
23
|
+
"build:cjs": "tsc -p . --outDir dist/cjs --module commonjs --moduleResolution node",
|
|
24
|
+
"build:mjs": "tsc -p . --outDir dist/esm --module es2022",
|
|
25
|
+
"gen-schema": "openapi-typescript ./spec/openapi.json --output ./src/schema.ts",
|
|
21
26
|
"test": "jest --maxWorkers=1",
|
|
22
|
-
"
|
|
23
|
-
"typedoc": "typedoc",
|
|
24
|
-
"fix": "eslint . --ext .ts --fix",
|
|
25
|
-
"lint": "eslint . --ext .ts",
|
|
26
|
-
"fmt": "prettier --write .",
|
|
27
|
-
"fmt-check": "prettier --check .",
|
|
28
|
-
"gen-schema": "npx openapi-typescript ./spec/openapi.json --output ./src/schema.ts"
|
|
27
|
+
"typedoc": "typedoc"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"ethers": "6.7.1",
|
|
32
30
|
"openapi-fetch": "0.6.1"
|
|
33
31
|
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@hpke/core": "^1.2.5",
|
|
36
|
-
"@types/chai": "^4.3.11",
|
|
37
|
-
"@types/chai-as-promised": "^7.1.8",
|
|
38
|
-
"@types/jest": "^29.5.10",
|
|
39
|
-
"@types/node": "^20.10.4",
|
|
40
|
-
"@types/node-fetch": "^2.6.9",
|
|
41
|
-
"@types/tmp": "^0.2.6",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
|
43
|
-
"chai": "^4.3.10",
|
|
44
|
-
"chai-as-promised": "^7.1.1",
|
|
45
|
-
"dotenv": "^16.3.1",
|
|
46
|
-
"eslint": "^8.55.0",
|
|
47
|
-
"eslint-config-google": "^0.14.0",
|
|
48
|
-
"eslint-config-prettier": "^9.1.0",
|
|
49
|
-
"jest": "^29.7.0",
|
|
50
|
-
"openapi-typescript": "^6.7.1",
|
|
51
|
-
"otplib": "^12.0.1",
|
|
52
|
-
"prettier": "3.1.1",
|
|
53
|
-
"tmp": "^0.2.1",
|
|
54
|
-
"ts-jest": "^29.1.0",
|
|
55
|
-
"ts-node": "^10.9.1",
|
|
56
|
-
"typescript": "^5.3.3"
|
|
57
|
-
},
|
|
58
32
|
"optionalDependencies": {
|
|
59
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.470.0",
|
|
60
33
|
"@hpke/core": "^1.2.5"
|
|
61
34
|
},
|
|
62
|
-
"prettier": {
|
|
63
|
-
"printWidth": 100
|
|
64
|
-
},
|
|
65
35
|
"engines": {
|
|
66
36
|
"node": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"directories": {
|
|
39
|
+
"test": "test"
|
|
67
40
|
}
|
|
68
41
|
}
|
package/src/api.ts
CHANGED
|
@@ -34,6 +34,9 @@ import {
|
|
|
34
34
|
SessionInfo,
|
|
35
35
|
OrgInfo,
|
|
36
36
|
RatchetConfig,
|
|
37
|
+
Eip191SignRequest,
|
|
38
|
+
Eip712SignRequest,
|
|
39
|
+
Eip191Or712SignResponse,
|
|
37
40
|
EvmSignRequest,
|
|
38
41
|
EvmSignResponse,
|
|
39
42
|
Eth2SignRequest,
|
|
@@ -61,6 +64,7 @@ import {
|
|
|
61
64
|
import { encodeToBase64 } from "./util";
|
|
62
65
|
import { AddFidoChallenge, MfaFidoChallenge, MfaReceipt, TotpChallenge } from "./mfa";
|
|
63
66
|
import { CubeSignerResponse, mapResponse } from "./response";
|
|
67
|
+
import { ErrResponse } from "./error";
|
|
64
68
|
import { Key, KeyType } from "./key";
|
|
65
69
|
import { Page, PageOpts, PageQueryArgs, Paginator } from "./paginator";
|
|
66
70
|
import { KeyPolicy } from "./role";
|
|
@@ -110,28 +114,6 @@ export type FetchClient<Op extends keyof operations> = ReturnType<typeof createC
|
|
|
110
114
|
*/
|
|
111
115
|
export type FetchResponseSuccessData<T> = Required<FetchResponse<T>>["data"];
|
|
112
116
|
|
|
113
|
-
/**
|
|
114
|
-
* Error response type, thrown on non-successful responses.
|
|
115
|
-
*/
|
|
116
|
-
export class ErrResponse extends Error {
|
|
117
|
-
/** Operation that produced this error */
|
|
118
|
-
readonly operation?: keyof operations;
|
|
119
|
-
/** HTTP status code text (derived from `this.status`) */
|
|
120
|
-
readonly statusText?: string;
|
|
121
|
-
/** HTTP status code */
|
|
122
|
-
readonly status?: number;
|
|
123
|
-
/** HTTP response url */
|
|
124
|
-
readonly url?: string;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @param {Partial<ErrResponse>} init Initializer
|
|
128
|
-
*/
|
|
129
|
-
constructor(init: Partial<ErrResponse>) {
|
|
130
|
-
super(init.message);
|
|
131
|
-
Object.assign(this, init);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
117
|
/**
|
|
136
118
|
* Wrapper around an open-fetch client restricted to a single operation.
|
|
137
119
|
* The restriction applies only when type checking, the actual
|
|
@@ -246,9 +228,11 @@ export class OpClient<Op extends keyof operations> {
|
|
|
246
228
|
export function createHttpClient(baseUrl: string, authToken: string): Client {
|
|
247
229
|
return createClient<paths>({
|
|
248
230
|
baseUrl,
|
|
231
|
+
cache: "no-store",
|
|
249
232
|
headers: {
|
|
250
233
|
Authorization: authToken,
|
|
251
234
|
["User-Agent"]: `${NAME}@${VERSION}`,
|
|
235
|
+
["X-Cubist-Ts-Sdk"]: `${NAME}@${VERSION}`,
|
|
252
236
|
},
|
|
253
237
|
});
|
|
254
238
|
}
|
|
@@ -306,7 +290,7 @@ export class CubeSignerApi {
|
|
|
306
290
|
* @return {Promise<OpClient<Op>>} The client restricted to {@link op}
|
|
307
291
|
*/
|
|
308
292
|
private async client<Op extends keyof operations>(op: Op): Promise<OpClient<Op>> {
|
|
309
|
-
const fetchClient = await this.#sessionMgr.client();
|
|
293
|
+
const fetchClient = await this.#sessionMgr.client(op);
|
|
310
294
|
return new OpClient(op, fetchClient, this.#eventEmitter);
|
|
311
295
|
}
|
|
312
296
|
|
|
@@ -1176,6 +1160,64 @@ export class CubeSignerApi {
|
|
|
1176
1160
|
return await CubeSignerResponse.create(signFn, mfaReceipt);
|
|
1177
1161
|
}
|
|
1178
1162
|
|
|
1163
|
+
/**
|
|
1164
|
+
* Sign EIP-191 typed data.
|
|
1165
|
+
*
|
|
1166
|
+
* This requires the key to have a '"AllowEip191Signing"' {@link KeyPolicy}.
|
|
1167
|
+
*
|
|
1168
|
+
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
1169
|
+
* @param {BlobSignRequest} req What to sign
|
|
1170
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
1171
|
+
* @return {Promise<EvmSignResponse | AcceptedResponse>} Signature (or MFA approval request).
|
|
1172
|
+
*/
|
|
1173
|
+
async signEip191(
|
|
1174
|
+
key: Key | string,
|
|
1175
|
+
req: Eip191SignRequest,
|
|
1176
|
+
mfaReceipt?: MfaReceipt,
|
|
1177
|
+
): Promise<CubeSignerResponse<Eip191Or712SignResponse>> {
|
|
1178
|
+
const pubkey = typeof key === "string" ? (key as string) : key.materialId;
|
|
1179
|
+
const signFn = async (headers?: HeadersInit) => {
|
|
1180
|
+
const client = await this.client("eip191Sign");
|
|
1181
|
+
return await client.post("/v0/org/{org_id}/evm/eip191/sign/{pubkey}", {
|
|
1182
|
+
params: {
|
|
1183
|
+
path: { org_id: this.orgId, pubkey },
|
|
1184
|
+
},
|
|
1185
|
+
body: req,
|
|
1186
|
+
headers,
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
return await CubeSignerResponse.create(signFn, mfaReceipt);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Sign EIP-712 typed data.
|
|
1194
|
+
*
|
|
1195
|
+
* This requires the key to have a '"AllowEip712Signing"' {@link KeyPolicy}.
|
|
1196
|
+
*
|
|
1197
|
+
* @param {Key | string} key The key to sign with (either {@link Key} or its material ID).
|
|
1198
|
+
* @param {BlobSignRequest} req What to sign
|
|
1199
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt
|
|
1200
|
+
* @return {Promise<EvmSignResponse | AcceptedResponse>} Signature (or MFA approval request).
|
|
1201
|
+
*/
|
|
1202
|
+
async signEip712(
|
|
1203
|
+
key: Key | string,
|
|
1204
|
+
req: Eip712SignRequest,
|
|
1205
|
+
mfaReceipt?: MfaReceipt,
|
|
1206
|
+
): Promise<CubeSignerResponse<Eip191Or712SignResponse>> {
|
|
1207
|
+
const pubkey = typeof key === "string" ? (key as string) : key.materialId;
|
|
1208
|
+
const signFn = async (headers?: HeadersInit) => {
|
|
1209
|
+
const client = await this.client("eip712Sign");
|
|
1210
|
+
return await client.post("/v0/org/{org_id}/evm/eip712/sign/{pubkey}", {
|
|
1211
|
+
params: {
|
|
1212
|
+
path: { org_id: this.orgId, pubkey },
|
|
1213
|
+
},
|
|
1214
|
+
body: req,
|
|
1215
|
+
headers,
|
|
1216
|
+
});
|
|
1217
|
+
};
|
|
1218
|
+
return await CubeSignerResponse.create(signFn, mfaReceipt);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1179
1221
|
/**
|
|
1180
1222
|
* Sign an Eth2/Beacon-chain validation message.
|
|
1181
1223
|
*
|
|
@@ -1478,6 +1520,22 @@ export class CubeSignerApi {
|
|
|
1478
1520
|
return await CubeSignerResponse.create(completeFn, mfaReceipt);
|
|
1479
1521
|
}
|
|
1480
1522
|
// #endregion
|
|
1523
|
+
|
|
1524
|
+
// #region MISC: heartbeat()
|
|
1525
|
+
/**
|
|
1526
|
+
* Send a heartbeat / upcheck request.
|
|
1527
|
+
*
|
|
1528
|
+
* @return { Promise<void> } The response.
|
|
1529
|
+
*/
|
|
1530
|
+
async heartbeat(): Promise<void> {
|
|
1531
|
+
const client = await this.client("cube3signerHeartbeat");
|
|
1532
|
+
await client.post("/v1/org/{org_id}/cube3signer/heartbeat", {
|
|
1533
|
+
params: {
|
|
1534
|
+
path: { org_id: this.orgId },
|
|
1535
|
+
},
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
// #endregion
|
|
1481
1539
|
}
|
|
1482
1540
|
|
|
1483
1541
|
/**
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SignerSessionManager, SignerSessionStorage } from "./session/signer_session_manager";
|
|
2
|
-
import { CognitoSessionManager } from "./session/cognito_manager";
|
|
3
2
|
import { CubeSignerApi, OidcClient } from "./api";
|
|
4
3
|
import { KeyType, Key } from "./key";
|
|
5
4
|
import { OrgInfo, RatchetConfig } from "./schema_types";
|
|
@@ -49,15 +48,20 @@ export class CubeSignerClient extends CubeSignerApi {
|
|
|
49
48
|
/**
|
|
50
49
|
* Loads an existing management session and creates a {@link CubeSignerClient} instance.
|
|
51
50
|
*
|
|
51
|
+
* @param {SignerSessionStorage} storage Storage from which to load the session
|
|
52
52
|
* @return {Promise<CubeSignerClient>} New CubeSigner instance
|
|
53
53
|
*/
|
|
54
|
-
static async loadManagementSession(): Promise<CubeSignerClient> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
static async loadManagementSession(storage: SignerSessionStorage): Promise<CubeSignerClient> {
|
|
55
|
+
// Throw and actionable error if the management session file contains a Cognito session
|
|
56
|
+
const session = await storage.retrieve();
|
|
57
|
+
if ((session as unknown as { id_token: string }).id_token) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`It appears that the storage contains the old (Cognito) session; please update your session by updating your 'cs' to version 'v0.37.0' or later and then running 'cs login'`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const mgr = await SignerSessionManager.loadFromStorage(storage);
|
|
64
|
+
return new CubeSignerClient(mgr);
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { operations } from "./schema";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error response type, thrown on non-successful responses.
|
|
5
|
+
*/
|
|
6
|
+
export class ErrResponse extends Error {
|
|
7
|
+
/** Operation that produced this error */
|
|
8
|
+
readonly operation?: keyof operations;
|
|
9
|
+
/** HTTP status code text (derived from `this.status`) */
|
|
10
|
+
readonly statusText?: string;
|
|
11
|
+
/** HTTP status code */
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
/** HTTP response url */
|
|
14
|
+
readonly url?: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Partial<ErrResponse>} init Initializer
|
|
18
|
+
*/
|
|
19
|
+
constructor(init: Partial<ErrResponse>) {
|
|
20
|
+
super(init.message);
|
|
21
|
+
Object.assign(this, init);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An error that is thrown when a session has expired
|
|
27
|
+
*/
|
|
28
|
+
export class SessionExpiredError extends ErrResponse {
|
|
29
|
+
/**
|
|
30
|
+
* Constructor.
|
|
31
|
+
*
|
|
32
|
+
* @param {operations} operation The operation that was attempted
|
|
33
|
+
*/
|
|
34
|
+
constructor(operation?: keyof operations) {
|
|
35
|
+
super({
|
|
36
|
+
message: "Session has expired",
|
|
37
|
+
status: 403,
|
|
38
|
+
statusText: "Forbidden",
|
|
39
|
+
operation,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/events.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ErrResponse } from "./
|
|
1
|
+
import { ErrResponse } from "./error";
|
|
2
2
|
|
|
3
3
|
export type EventHandler<T> = (event: T) => Promise<void>;
|
|
4
4
|
export type ErrorEvent = ErrResponse;
|
|
5
|
+
|
|
6
|
+
/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
|
|
5
7
|
export interface SessionExpiredEvent {}
|
|
6
8
|
|
|
7
9
|
/**
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { envs, EnvInterface } from "./env";
|
|
|
2
2
|
import { Client, OidcClient } from "./api";
|
|
3
3
|
import { CubeSignerClient } from "./client";
|
|
4
4
|
import { Org } from "./org";
|
|
5
|
-
import { JsonFileSessionStorage } from "./session/session_storage";
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
7
|
SignerSessionStorage,
|
|
@@ -11,9 +10,6 @@ import {
|
|
|
11
10
|
} from "./session/signer_session_manager";
|
|
12
11
|
import { CubeSignerResponse } from "./response";
|
|
13
12
|
import { SignerSession } from "./signer_session";
|
|
14
|
-
import { CognitoSessionManager, CognitoSessionStorage } from "./session/cognito_manager";
|
|
15
|
-
import { configDir } from "./util";
|
|
16
|
-
import * as path from "path";
|
|
17
13
|
import { MfaReceipt } from "./mfa";
|
|
18
14
|
import { name, version } from "./../package.json";
|
|
19
15
|
import { IdentityProof, MfaRequestInfo, RatchetConfig, UserInfo } from "./schema_types";
|
|
@@ -23,7 +19,7 @@ export interface CubeSignerOptions {
|
|
|
23
19
|
/** The environment to use */
|
|
24
20
|
env?: EnvInterface;
|
|
25
21
|
/** The management authorization token */
|
|
26
|
-
sessionMgr?:
|
|
22
|
+
sessionMgr?: SignerSessionManager;
|
|
27
23
|
/** Optional organization id */
|
|
28
24
|
orgId?: string;
|
|
29
25
|
}
|
|
@@ -35,7 +31,7 @@ export interface CubeSignerOptions {
|
|
|
35
31
|
*/
|
|
36
32
|
export class CubeSigner {
|
|
37
33
|
readonly #env: EnvInterface;
|
|
38
|
-
readonly sessionMgr?:
|
|
34
|
+
readonly sessionMgr?: SignerSessionManager;
|
|
39
35
|
#csc?: CubeSignerClient;
|
|
40
36
|
|
|
41
37
|
/**
|
|
@@ -70,28 +66,22 @@ export class CubeSigner {
|
|
|
70
66
|
/**
|
|
71
67
|
* Loads an existing management session and creates a CubeSigner instance.
|
|
72
68
|
*
|
|
73
|
-
* @param {
|
|
74
|
-
* the session from. If not specified, the management session from the config
|
|
75
|
-
* directory will be loaded.
|
|
69
|
+
* @param {SignerSessionStorage} storage Session storage to load the session from.
|
|
76
70
|
* @return {Promise<CubeSigner>} New CubeSigner instance
|
|
77
71
|
*/
|
|
78
|
-
static async loadManagementSession(storage
|
|
72
|
+
static async loadManagementSession(storage: SignerSessionStorage): Promise<CubeSigner> {
|
|
79
73
|
return new CubeSigner(<CubeSignerOptions>{
|
|
80
|
-
sessionMgr: await
|
|
74
|
+
sessionMgr: await SignerSessionManager.loadFromStorage(storage),
|
|
81
75
|
});
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
/**
|
|
85
79
|
* Loads a signer session from a session storage (e.g., session file).
|
|
86
|
-
* @param {SignerSessionStorage} storage
|
|
87
|
-
* the session from. If not specified, the signer session from the config
|
|
88
|
-
* directory will be loaded.
|
|
80
|
+
* @param {SignerSessionStorage} storage Session storage to load the session from.
|
|
89
81
|
* @return {Promise<SignerSession>} New signer session
|
|
90
82
|
*/
|
|
91
|
-
static async loadSignerSession(storage
|
|
92
|
-
|
|
93
|
-
const sss = storage ?? new JsonFileSessionStorage(defaultFilePath);
|
|
94
|
-
return await SignerSession.loadSignerSession(sss);
|
|
83
|
+
static async loadSignerSession(storage: SignerSessionStorage): Promise<SignerSession> {
|
|
84
|
+
return await SignerSession.loadSignerSession(storage);
|
|
95
85
|
}
|
|
96
86
|
|
|
97
87
|
/**
|
|
@@ -290,6 +280,8 @@ export class CubeSigner {
|
|
|
290
280
|
}
|
|
291
281
|
}
|
|
292
282
|
|
|
283
|
+
/** Errors */
|
|
284
|
+
export * from "./error";
|
|
293
285
|
/** API */
|
|
294
286
|
export * from "./api";
|
|
295
287
|
/** Client */
|
|
@@ -316,16 +308,12 @@ export * from "./schema_types";
|
|
|
316
308
|
export * from "./signer_session";
|
|
317
309
|
/** Session storage */
|
|
318
310
|
export * from "./session/session_storage";
|
|
319
|
-
/** Session manager */
|
|
320
|
-
export * from "./session/session_manager";
|
|
321
|
-
/** Management session manager */
|
|
322
|
-
export * from "./session/cognito_manager";
|
|
323
311
|
/** Signer session manager */
|
|
324
312
|
export * from "./session/signer_session_manager";
|
|
313
|
+
/** Utils */
|
|
314
|
+
export * from "./util";
|
|
325
315
|
/** User-export decryption helper */
|
|
326
316
|
export { userExportDecrypt, userExportKeygen } from "./user_export";
|
|
327
|
-
/** Export ethers.js Signer */
|
|
328
|
-
export * as ethers from "./ethers";
|
|
329
317
|
|
|
330
318
|
/** CubeSigner SDK package name */
|
|
331
319
|
export const NAME: string = name;
|
package/src/key.ts
CHANGED
|
@@ -66,14 +66,18 @@ export function toKeyInfo(key: KeyInfoApi): KeyInfo {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* A representation of a signing key.
|
|
71
|
+
*/
|
|
70
72
|
export class Key {
|
|
71
73
|
/** The CubeSigner instance that this key is associated with */
|
|
72
|
-
readonly
|
|
74
|
+
protected readonly csc: CubeSignerClient;
|
|
75
|
+
/** The key information */
|
|
76
|
+
#data: KeyInfo;
|
|
73
77
|
|
|
74
78
|
/** The organization that this key is in */
|
|
75
79
|
get orgId() {
|
|
76
|
-
return this
|
|
80
|
+
return this.csc.orgId;
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
/**
|
|
@@ -81,13 +85,17 @@ export class Key {
|
|
|
81
85
|
* the type of key (such as a public key for BLS or an ethereum address for Secp)
|
|
82
86
|
* @example Key#0x8e3484687e66cdd26cf04c3647633ab4f3570148
|
|
83
87
|
*/
|
|
84
|
-
|
|
88
|
+
get id(): string {
|
|
89
|
+
return this.#data.key_id;
|
|
90
|
+
}
|
|
85
91
|
|
|
86
92
|
/**
|
|
87
93
|
* A unique identifier specific to the type of key, such as a public key or an ethereum address
|
|
88
94
|
* @example 0x8e3484687e66cdd26cf04c3647633ab4f3570148
|
|
89
95
|
*/
|
|
90
|
-
|
|
96
|
+
get materialId(): string {
|
|
97
|
+
return this.#data.material_id;
|
|
98
|
+
}
|
|
91
99
|
|
|
92
100
|
/**
|
|
93
101
|
* @description Hex-encoded, serialized public key. The format used depends on the key type:
|
|
@@ -95,7 +103,18 @@ export class Key {
|
|
|
95
103
|
* - BLS keys use 48-byte compressed BLS12-381 (ZCash) format
|
|
96
104
|
* @example 0x04d2688b6bc2ce7f9879b9e745f3c4dc177908c5cef0c1b64cff19ae7ff27dee623c64fe9d9c325c7fbbc748bbd5f607ce14dd83e28ebbbb7d3e7f2ffb70a79431
|
|
97
105
|
*/
|
|
98
|
-
|
|
106
|
+
get publicKey(): string {
|
|
107
|
+
return this.#data.public_key;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the cached properties of this key. The cached properties reflect the
|
|
112
|
+
* state of the last fetch or update (e.g., after awaiting `Key.enabled()`
|
|
113
|
+
* or `Key.disable()`).
|
|
114
|
+
*/
|
|
115
|
+
get cached(): KeyInfo {
|
|
116
|
+
return this.#data;
|
|
117
|
+
}
|
|
99
118
|
|
|
100
119
|
/** The type of key. */
|
|
101
120
|
async type(): Promise<KeyType> {
|
|
@@ -137,8 +156,8 @@ export class Key {
|
|
|
137
156
|
}
|
|
138
157
|
|
|
139
158
|
/**
|
|
140
|
-
* Get the policy for the
|
|
141
|
-
* @return {Promise<KeyPolicy>} The policy for the
|
|
159
|
+
* Get the policy for the key.
|
|
160
|
+
* @return {Promise<KeyPolicy>} The policy for the key.
|
|
142
161
|
*/
|
|
143
162
|
async policy(): Promise<KeyPolicy> {
|
|
144
163
|
const data = await this.fetch();
|
|
@@ -166,7 +185,7 @@ export class Key {
|
|
|
166
185
|
* Delete this key.
|
|
167
186
|
*/
|
|
168
187
|
async delete() {
|
|
169
|
-
await this
|
|
188
|
+
await this.csc.keyDelete(this.id);
|
|
170
189
|
}
|
|
171
190
|
|
|
172
191
|
// --------------------------------------------------------------------------
|
|
@@ -177,24 +196,23 @@ export class Key {
|
|
|
177
196
|
* Create a new key.
|
|
178
197
|
*
|
|
179
198
|
* @param {CubeSignerClient} csc The CubeSigner instance to use for signing.
|
|
180
|
-
* @param {
|
|
199
|
+
* @param {KeyInfoApi} data The JSON response from the API server.
|
|
181
200
|
* @internal
|
|
182
201
|
*/
|
|
183
202
|
constructor(csc: CubeSignerClient, data: KeyInfoApi) {
|
|
184
|
-
this
|
|
185
|
-
this
|
|
186
|
-
this.materialId = data.material_id;
|
|
187
|
-
this.publicKey = data.public_key;
|
|
203
|
+
this.csc = csc;
|
|
204
|
+
this.#data = toKeyInfo(data);
|
|
188
205
|
}
|
|
189
206
|
|
|
190
207
|
/**
|
|
191
208
|
* Update the key.
|
|
192
209
|
* @param {UpdateKeyRequest} request The JSON request to send to the API server.
|
|
193
210
|
* @return {KeyInfo} The JSON response from the API server.
|
|
211
|
+
* @internal
|
|
194
212
|
*/
|
|
195
213
|
private async update(request: UpdateKeyRequest): Promise<KeyInfo> {
|
|
196
|
-
|
|
197
|
-
return
|
|
214
|
+
this.#data = await this.csc.keyUpdate(this.id, request).then(toKeyInfo);
|
|
215
|
+
return this.#data;
|
|
198
216
|
}
|
|
199
217
|
|
|
200
218
|
/**
|
|
@@ -204,8 +222,8 @@ export class Key {
|
|
|
204
222
|
* @internal
|
|
205
223
|
*/
|
|
206
224
|
private async fetch(): Promise<KeyInfo> {
|
|
207
|
-
|
|
208
|
-
return
|
|
225
|
+
this.#data = await this.csc.keyGet(this.id).then(toKeyInfo);
|
|
226
|
+
return this.#data;
|
|
209
227
|
}
|
|
210
228
|
}
|
|
211
229
|
|