@cubist-labs/cubesigner-sdk 0.2.28 → 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 -1
- package/dist/src/api.js +66 -1
- package/dist/src/client.d.ts +35 -14
- package/dist/src/client.js +12 -8
- package/dist/src/events.js +1 -1
- package/dist/src/index.d.ts +6 -11
- package/dist/src/index.js +9 -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 +38 -14
- package/dist/src/session/signer_session_manager.js +93 -33
- package/dist/src/util.d.ts +14 -0
- package/dist/src/util.js +24 -27
- package/package.json +19 -46
- package/src/api.ts +79 -0
- package/src/client.ts +12 -8
- package/src/events.ts +2 -0
- package/src/index.ts +10 -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 +124 -36
- 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 -215
- 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 -253
- 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.28",
|
|
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.2",
|
|
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,
|
|
@@ -225,9 +228,11 @@ export class OpClient<Op extends keyof operations> {
|
|
|
225
228
|
export function createHttpClient(baseUrl: string, authToken: string): Client {
|
|
226
229
|
return createClient<paths>({
|
|
227
230
|
baseUrl,
|
|
231
|
+
cache: "no-store",
|
|
228
232
|
headers: {
|
|
229
233
|
Authorization: authToken,
|
|
230
234
|
["User-Agent"]: `${NAME}@${VERSION}`,
|
|
235
|
+
["X-Cubist-Ts-Sdk"]: `${NAME}@${VERSION}`,
|
|
231
236
|
},
|
|
232
237
|
});
|
|
233
238
|
}
|
|
@@ -1155,6 +1160,64 @@ export class CubeSignerApi {
|
|
|
1155
1160
|
return await CubeSignerResponse.create(signFn, mfaReceipt);
|
|
1156
1161
|
}
|
|
1157
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
|
+
|
|
1158
1221
|
/**
|
|
1159
1222
|
* Sign an Eth2/Beacon-chain validation message.
|
|
1160
1223
|
*
|
|
@@ -1457,6 +1520,22 @@ export class CubeSignerApi {
|
|
|
1457
1520
|
return await CubeSignerResponse.create(completeFn, mfaReceipt);
|
|
1458
1521
|
}
|
|
1459
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
|
|
1460
1539
|
}
|
|
1461
1540
|
|
|
1462
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/events.ts
CHANGED
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
|
/**
|
|
@@ -318,16 +308,12 @@ export * from "./schema_types";
|
|
|
318
308
|
export * from "./signer_session";
|
|
319
309
|
/** Session storage */
|
|
320
310
|
export * from "./session/session_storage";
|
|
321
|
-
/** Session manager */
|
|
322
|
-
export * from "./session/session_manager";
|
|
323
|
-
/** Management session manager */
|
|
324
|
-
export * from "./session/cognito_manager";
|
|
325
311
|
/** Signer session manager */
|
|
326
312
|
export * from "./session/signer_session_manager";
|
|
313
|
+
/** Utils */
|
|
314
|
+
export * from "./util";
|
|
327
315
|
/** User-export decryption helper */
|
|
328
316
|
export { userExportDecrypt, userExportKeygen } from "./user_export";
|
|
329
|
-
/** Export ethers.js Signer */
|
|
330
|
-
export * as ethers from "./ethers";
|
|
331
317
|
|
|
332
318
|
/** CubeSigner SDK package name */
|
|
333
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
|
|
package/src/role.ts
CHANGED
|
@@ -48,6 +48,13 @@ export type TxDepositPubkey = { TxDeposit: { kind: DepositContract; pubkey: stri
|
|
|
48
48
|
*/
|
|
49
49
|
export type TxDepositRole = { TxDeposit: { kind: DepositContract; role_id: string } };
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Only allow connections from clients whose IP addresses match any of these IPv4 CIDR blocks.
|
|
53
|
+
*
|
|
54
|
+
* @example { SourceIpAllowlist: [ "123.456.78.9/16" ] }
|
|
55
|
+
*/
|
|
56
|
+
export type SourceIpAllowlist = { SourceIpAllowlist: string[] };
|
|
57
|
+
|
|
51
58
|
/** All different kinds of sensitive operations. */
|
|
52
59
|
export enum OperationKind {
|
|
53
60
|
BlobSign = "BlobSign", // eslint-disable-line no-unused-vars
|
|
@@ -100,6 +107,17 @@ export type RequireMfa = {
|
|
|
100
107
|
export const AllowRawBlobSigning = "AllowRawBlobSigning" as const;
|
|
101
108
|
export type AllowRawBlobSigning = typeof AllowRawBlobSigning;
|
|
102
109
|
|
|
110
|
+
/** Allow EIP-191 signing */
|
|
111
|
+
export const AllowEip191Signing = "AllowEip191Signing" as const;
|
|
112
|
+
export type AllowEip191Signing = typeof AllowEip191Signing;
|
|
113
|
+
|
|
114
|
+
/** Allow EIP-712 signing */
|
|
115
|
+
export const AllowEip712Signing = "AllowEip712Signing" as const;
|
|
116
|
+
export type AllowEip712Signing = typeof AllowEip712Signing;
|
|
117
|
+
|
|
118
|
+
/** Key policies that restrict the requests that the signing endpoints accept */
|
|
119
|
+
type KeyDenyPolicy = TxReceiver | TxDeposit | SourceIpAllowlist | RequireMfa;
|
|
120
|
+
|
|
103
121
|
/**
|
|
104
122
|
* Key policy
|
|
105
123
|
*
|
|
@@ -124,7 +142,15 @@ export type AllowRawBlobSigning = typeof AllowRawBlobSigning;
|
|
|
124
142
|
* }
|
|
125
143
|
* ]
|
|
126
144
|
*/
|
|
127
|
-
export type KeyPolicy = (
|
|
145
|
+
export type KeyPolicy = (
|
|
146
|
+
| KeyDenyPolicy
|
|
147
|
+
| AllowRawBlobSigning
|
|
148
|
+
| AllowEip191Signing
|
|
149
|
+
| AllowEip712Signing
|
|
150
|
+
)[];
|
|
151
|
+
|
|
152
|
+
/** Role policy */
|
|
153
|
+
export type RolePolicy = KeyDenyPolicy[];
|
|
128
154
|
|
|
129
155
|
/** A key guarded by a policy. */
|
|
130
156
|
export class KeyWithPolicies {
|
|
@@ -154,15 +180,30 @@ export class KeyWithPolicies {
|
|
|
154
180
|
/** Roles. */
|
|
155
181
|
export class Role {
|
|
156
182
|
readonly #csc: CubeSignerClient;
|
|
183
|
+
/** The role information */
|
|
184
|
+
#data: RoleInfo;
|
|
157
185
|
|
|
158
186
|
/** Human-readable name for the role */
|
|
159
|
-
|
|
187
|
+
get name(): string | undefined {
|
|
188
|
+
return this.#data.name ?? undefined;
|
|
189
|
+
}
|
|
160
190
|
|
|
161
191
|
/**
|
|
162
192
|
* The ID of the role.
|
|
163
193
|
* @example Role#bfe3eccb-731e-430d-b1e5-ac1363e6b06b
|
|
164
194
|
*/
|
|
165
|
-
|
|
195
|
+
get id(): string {
|
|
196
|
+
return this.#data.role_id;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @return {RoleInfo} the cached properties of this role. The cached properties
|
|
201
|
+
* reflect the state of the last fetch or update (e.g., after awaiting
|
|
202
|
+
* `Role.enabled()` or `Role.disable()`).
|
|
203
|
+
*/
|
|
204
|
+
get cached(): RoleInfo {
|
|
205
|
+
return this.#data;
|
|
206
|
+
}
|
|
166
207
|
|
|
167
208
|
/** Delete the role. */
|
|
168
209
|
async delete(): Promise<void> {
|
|
@@ -185,6 +226,35 @@ export class Role {
|
|
|
185
226
|
await this.update({ enabled: false });
|
|
186
227
|
}
|
|
187
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Set new policy (overwriting any policies previously set for this role)
|
|
231
|
+
* @param {RolePolicy} policy The new policy to set
|
|
232
|
+
*/
|
|
233
|
+
async setPolicy(policy: RolePolicy) {
|
|
234
|
+
await this.update({ policy: policy as unknown as Record<string, never>[] });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Append to existing role policy. This append is not atomic---it uses
|
|
239
|
+
* {@link policy} to fetch the current policy and then {@link setPolicy}
|
|
240
|
+
* to set the policy---and should not be used in across concurrent sessions.
|
|
241
|
+
*
|
|
242
|
+
* @param {RolePolicy} policy The policy to append to the existing one.
|
|
243
|
+
*/
|
|
244
|
+
async appendPolicy(policy: RolePolicy) {
|
|
245
|
+
const existing = await this.policy();
|
|
246
|
+
await this.setPolicy([...existing, ...policy]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get the policy for the role.
|
|
251
|
+
* @return {Promise<RolePolicy>} The policy for the role.
|
|
252
|
+
*/
|
|
253
|
+
async policy(): Promise<RolePolicy> {
|
|
254
|
+
const data = await this.fetch();
|
|
255
|
+
return (data.policy ?? []) as unknown as RolePolicy;
|
|
256
|
+
}
|
|
257
|
+
|
|
188
258
|
/**
|
|
189
259
|
* The list of all users with access to the role.
|
|
190
260
|
* @example [
|
|
@@ -301,8 +371,7 @@ export class Role {
|
|
|
301
371
|
*/
|
|
302
372
|
constructor(csc: CubeSignerClient, data: RoleInfo) {
|
|
303
373
|
this.#csc = csc;
|
|
304
|
-
this
|
|
305
|
-
this.name = data.name ?? undefined;
|
|
374
|
+
this.#data = data;
|
|
306
375
|
}
|
|
307
376
|
|
|
308
377
|
/**
|
|
@@ -312,7 +381,8 @@ export class Role {
|
|
|
312
381
|
* @return {Promise<RoleInfo>} The updated role information.
|
|
313
382
|
*/
|
|
314
383
|
private async update(request: UpdateRoleRequest): Promise<RoleInfo> {
|
|
315
|
-
|
|
384
|
+
this.#data = await this.#csc.roleUpdate(this.id, request);
|
|
385
|
+
return this.#data;
|
|
316
386
|
}
|
|
317
387
|
|
|
318
388
|
/**
|
|
@@ -322,6 +392,7 @@ export class Role {
|
|
|
322
392
|
* @internal
|
|
323
393
|
*/
|
|
324
394
|
private async fetch(): Promise<RoleInfo> {
|
|
325
|
-
|
|
395
|
+
this.#data = await this.#csc.roleGet(this.id);
|
|
396
|
+
return this.#data;
|
|
326
397
|
}
|
|
327
398
|
}
|