@mysten/signers 1.0.1 → 1.0.4
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/CHANGELOG.md +43 -0
- package/README.md +1 -1
- package/dist/aws/index.d.mts +1 -3
- package/dist/aws/index.mjs +2 -2
- package/dist/gcp/index.d.mts +1 -2
- package/dist/gcp/index.mjs +2 -2
- package/dist/ledger/index.d.mts +1 -74
- package/dist/ledger/index.mjs +2 -109
- package/dist/webcrypto/index.d.mts +1 -32
- package/dist/webcrypto/index.mjs +2 -69
- package/package.json +9 -19
- package/src/aws/index.ts +1 -6
- package/src/gcp/index.ts +1 -6
- package/src/ledger/index.ts +1 -160
- package/src/webcrypto/index.ts +1 -108
- package/dist/aws/aws-client.d.mts +0 -48
- package/dist/aws/aws-client.d.mts.map +0 -1
- package/dist/aws/aws-client.mjs +0 -46
- package/dist/aws/aws-client.mjs.map +0 -1
- package/dist/aws/aws-kms-signer.d.mts +0 -63
- package/dist/aws/aws-kms-signer.d.mts.map +0 -1
- package/dist/aws/aws-kms-signer.mjs +0 -78
- package/dist/aws/aws-kms-signer.mjs.map +0 -1
- package/dist/aws/aws4fetch.d.mts +0 -62
- package/dist/aws/aws4fetch.d.mts.map +0 -1
- package/dist/aws/aws4fetch.mjs +0 -313
- package/dist/aws/aws4fetch.mjs.map +0 -1
- package/dist/gcp/gcp-kms-client.d.mts +0 -71
- package/dist/gcp/gcp-kms-client.d.mts.map +0 -1
- package/dist/gcp/gcp-kms-client.mjs +0 -104
- package/dist/gcp/gcp-kms-client.mjs.map +0 -1
- package/dist/ledger/index.d.mts.map +0 -1
- package/dist/ledger/index.mjs.map +0 -1
- package/dist/ledger/objects.d.mts +0 -10
- package/dist/ledger/objects.d.mts.map +0 -1
- package/dist/ledger/objects.mjs +0 -16
- package/dist/ledger/objects.mjs.map +0 -1
- package/dist/utils/utils.mjs +0 -71
- package/dist/utils/utils.mjs.map +0 -1
- package/dist/webcrypto/index.d.mts.map +0 -1
- package/dist/webcrypto/index.mjs.map +0 -1
- package/src/aws/aws-client.ts +0 -107
- package/src/aws/aws-kms-signer.ts +0 -102
- package/src/aws/aws4fetch.ts +0 -502
- package/src/gcp/gcp-kms-client.ts +0 -156
- package/src/ledger/objects.ts +0 -32
- package/src/utils/utils.ts +0 -127
package/src/webcrypto/index.ts
CHANGED
|
@@ -1,111 +1,4 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
import { Signer } from '@mysten/sui/cryptography';
|
|
6
|
-
import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
|
|
7
|
-
import { p256 as secp256r1 } from '@noble/curves/nist.js';
|
|
8
|
-
|
|
9
|
-
// Convert from uncompressed (65 bytes) to compressed (33 bytes) format
|
|
10
|
-
function getCompressedPublicKey(publicKey: Uint8Array) {
|
|
11
|
-
const rawBytes = new Uint8Array(publicKey);
|
|
12
|
-
const x = rawBytes.slice(1, 33);
|
|
13
|
-
const y = rawBytes.slice(33, 65);
|
|
14
|
-
|
|
15
|
-
const prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;
|
|
16
|
-
|
|
17
|
-
const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
|
|
18
|
-
compressed[0] = prefix;
|
|
19
|
-
compressed.set(x, 1);
|
|
20
|
-
|
|
21
|
-
return compressed;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ExportedWebCryptoKeypair {
|
|
25
|
-
privateKey: CryptoKey;
|
|
26
|
-
publicKey: Uint8Array<ArrayBuffer>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class WebCryptoSigner extends Signer {
|
|
30
|
-
privateKey: CryptoKey;
|
|
31
|
-
|
|
32
|
-
#publicKey: Secp256r1PublicKey;
|
|
33
|
-
|
|
34
|
-
static async generate({ extractable = false }: { extractable?: boolean } = {}) {
|
|
35
|
-
const keypair = await globalThis.crypto.subtle.generateKey(
|
|
36
|
-
{
|
|
37
|
-
name: 'ECDSA',
|
|
38
|
-
namedCurve: 'P-256',
|
|
39
|
-
},
|
|
40
|
-
extractable,
|
|
41
|
-
['sign', 'verify'],
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);
|
|
45
|
-
|
|
46
|
-
return new WebCryptoSigner(
|
|
47
|
-
keypair.privateKey,
|
|
48
|
-
getCompressedPublicKey(new Uint8Array(publicKey)),
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Imports a keypair using the value returned by `export()`.
|
|
54
|
-
*/
|
|
55
|
-
static import(data: ExportedWebCryptoKeypair) {
|
|
56
|
-
return new WebCryptoSigner(data.privateKey, data.publicKey);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getKeyScheme(): SignatureScheme {
|
|
60
|
-
return 'Secp256r1';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
constructor(privateKey: CryptoKey, publicKey: Uint8Array) {
|
|
64
|
-
super();
|
|
65
|
-
this.privateKey = privateKey;
|
|
66
|
-
this.#publicKey = new Secp256r1PublicKey(publicKey);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Exports the keypair so that it can be stored in IndexedDB.
|
|
71
|
-
*/
|
|
72
|
-
export(): ExportedWebCryptoKeypair {
|
|
73
|
-
const exportedKeypair = {
|
|
74
|
-
privateKey: this.privateKey,
|
|
75
|
-
publicKey: this.#publicKey.toRawBytes(),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
Object.defineProperty(exportedKeypair, 'toJSON', {
|
|
79
|
-
enumerable: false,
|
|
80
|
-
value: () => {
|
|
81
|
-
throw new Error(
|
|
82
|
-
'The exported keypair must not be serialized. It must be stored in IndexedDB directly.',
|
|
83
|
-
);
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return exportedKeypair;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getPublicKey() {
|
|
91
|
-
return this.#publicKey;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {
|
|
95
|
-
const rawSignature = await globalThis.crypto.subtle.sign(
|
|
96
|
-
{
|
|
97
|
-
name: 'ECDSA',
|
|
98
|
-
hash: 'SHA-256',
|
|
99
|
-
},
|
|
100
|
-
this.privateKey,
|
|
101
|
-
bytes as BufferSource,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const signature = secp256r1.Signature.fromBytes(new Uint8Array(rawSignature));
|
|
105
|
-
const normalizedSig = signature.hasHighS()
|
|
106
|
-
? new secp256r1.Signature(signature.r, secp256r1.Point.Fn.neg(signature.s))
|
|
107
|
-
: signature;
|
|
108
|
-
|
|
109
|
-
return normalizedSig.toBytes('compact') as Uint8Array<ArrayBuffer>;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
4
|
+
export * from '@mysten/webcrypto-signer';
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { AwsClient } from "./aws4fetch.mjs";
|
|
2
|
-
import { Secp256k1PublicKey } from "@mysten/sui/keypairs/secp256k1";
|
|
3
|
-
import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
|
|
4
|
-
|
|
5
|
-
//#region src/aws/aws-client.d.ts
|
|
6
|
-
interface KmsCommands {
|
|
7
|
-
Sign: {
|
|
8
|
-
request: {
|
|
9
|
-
KeyId: string;
|
|
10
|
-
Message: string;
|
|
11
|
-
MessageType: 'RAW' | 'DIGEST';
|
|
12
|
-
SigningAlgorithm: 'ECDSA_SHA_256';
|
|
13
|
-
};
|
|
14
|
-
response: {
|
|
15
|
-
KeyId: string;
|
|
16
|
-
KeyOrigin: string;
|
|
17
|
-
Signature: string;
|
|
18
|
-
SigningAlgorithm: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
GetPublicKey: {
|
|
22
|
-
request: {
|
|
23
|
-
KeyId: string;
|
|
24
|
-
};
|
|
25
|
-
response: {
|
|
26
|
-
CustomerMasterKeySpec: string;
|
|
27
|
-
KeyId: string;
|
|
28
|
-
KeyOrigin: string;
|
|
29
|
-
KeySpec: string;
|
|
30
|
-
KeyUsage: string;
|
|
31
|
-
PublicKey: string;
|
|
32
|
-
SigningAlgorithms: string[];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
interface AwsClientOptions extends Partial<ConstructorParameters<typeof AwsClient>[0]> {}
|
|
37
|
-
declare class AwsKmsClient extends AwsClient {
|
|
38
|
-
constructor(options?: AwsClientOptions);
|
|
39
|
-
getPublicKey(keyId: string): Promise<Secp256r1PublicKey | Secp256k1PublicKey>;
|
|
40
|
-
runCommand<T extends keyof KmsCommands>(command: T, body: KmsCommands[T]['request'], {
|
|
41
|
-
region
|
|
42
|
-
}?: {
|
|
43
|
-
region?: string;
|
|
44
|
-
}): Promise<KmsCommands[T]['response']>;
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { AwsClientOptions, AwsKmsClient };
|
|
48
|
-
//# sourceMappingURL=aws-client.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws-client.d.mts","names":[],"sources":["../../src/aws/aws-client.ts"],"sourcesContent":[],"mappings":";;;;;UAUU,WAAA;;IAAA,OAAA,EAAA;MA6BO,KAAA,EAAA,MAAiB;MAA6C,OAAA,EAAA,MAAA;MAA7B,WAAA,EAAA,KAAA,GAAA,QAAA;MAAR,gBAAA,EAAA,eAAA;IAAO,CAAA;IAEpC,QAAA,EAAA;MACS,KAAA,EAAA,MAAA;MAkBW,SAAA,EAAA,MAAA;MAAA,SAAA,EAAA,MAAA;MAAA,gBAAA,EAAA,MAAA;IAmBC,CAAA;EACvB,CAAA;EACH,YAAA,EAAA;IAAY,OAAA,EAAA;MAEjB,KAAA,EAAA,MAAA;IAIS,CAAA;IAAY,QAAA,EAAA;MAApB,qBAAA,EAAA,MAAA;MA9C8B,KAAA,EAAA,MAAA;MAAS,SAAA,EAAA,MAAA;;;;;;;;UAF1B,gBAAA,SAAyB,QAAQ,6BAA6B;cAElE,YAAA,SAAqB,SAAA;wBACZ;+BAkBW,QAAA,qBAAA;6BAmBC,sBACvB,SACH,YAAY;;;;MAMhB,QAAQ,YAAY"}
|
package/dist/aws/aws-client.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { publicKeyFromDER } from "../utils/utils.mjs";
|
|
2
|
-
import { AwsClient } from "./aws4fetch.mjs";
|
|
3
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
4
|
-
import { Secp256k1PublicKey } from "@mysten/sui/keypairs/secp256k1";
|
|
5
|
-
import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
|
|
6
|
-
|
|
7
|
-
//#region src/aws/aws-client.ts
|
|
8
|
-
var AwsKmsClient = class extends AwsClient {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
if (!options.accessKeyId || !options.secretAccessKey) throw new Error("AWS Access Key ID and Secret Access Key are required");
|
|
11
|
-
if (!options.region) throw new Error("Region is required");
|
|
12
|
-
super({
|
|
13
|
-
region: options.region,
|
|
14
|
-
accessKeyId: options.accessKeyId,
|
|
15
|
-
secretAccessKey: options.secretAccessKey,
|
|
16
|
-
service: "kms",
|
|
17
|
-
...options
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
async getPublicKey(keyId) {
|
|
21
|
-
const publicKeyResponse = await this.runCommand("GetPublicKey", { KeyId: keyId });
|
|
22
|
-
if (!publicKeyResponse.PublicKey) throw new Error("Public Key not found for the supplied `keyId`");
|
|
23
|
-
const compressedKey = publicKeyFromDER(fromBase64(publicKeyResponse.PublicKey));
|
|
24
|
-
switch (publicKeyResponse.KeySpec) {
|
|
25
|
-
case "ECC_NIST_P256": return new Secp256r1PublicKey(compressedKey);
|
|
26
|
-
case "ECC_SECG_P256K1": return new Secp256k1PublicKey(compressedKey);
|
|
27
|
-
default: throw new Error("Unsupported key spec: " + publicKeyResponse.KeySpec);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async runCommand(command, body, { region = this.region } = {}) {
|
|
31
|
-
if (!region) throw new Error("Region is required");
|
|
32
|
-
const res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {
|
|
33
|
-
headers: {
|
|
34
|
-
"Content-Type": "application/x-amz-json-1.1",
|
|
35
|
-
"X-Amz-Target": `TrentService.${command}`
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify(body)
|
|
38
|
-
});
|
|
39
|
-
if (!res.ok) throw new Error(await res.text());
|
|
40
|
-
return res.json();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
export { AwsKmsClient };
|
|
46
|
-
//# sourceMappingURL=aws-client.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws-client.mjs","names":[],"sources":["../../src/aws/aws-client.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Secp256k1PublicKey } from '@mysten/sui/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\nimport { fromBase64 } from '@mysten/sui/utils';\n\nimport { publicKeyFromDER } from '../utils/utils.js';\nimport { AwsClient } from './aws4fetch.js';\n\ninterface KmsCommands {\n\tSign: {\n\t\trequest: {\n\t\t\tKeyId: string;\n\t\t\tMessage: string;\n\t\t\tMessageType: 'RAW' | 'DIGEST';\n\t\t\tSigningAlgorithm: 'ECDSA_SHA_256';\n\t\t};\n\t\tresponse: {\n\t\t\tKeyId: string;\n\t\t\tKeyOrigin: string;\n\t\t\tSignature: string;\n\t\t\tSigningAlgorithm: string;\n\t\t};\n\t};\n\tGetPublicKey: {\n\t\trequest: { KeyId: string };\n\t\tresponse: {\n\t\t\tCustomerMasterKeySpec: string;\n\t\t\tKeyId: string;\n\t\t\tKeyOrigin: string;\n\t\t\tKeySpec: string;\n\t\t\tKeyUsage: string;\n\t\t\tPublicKey: string;\n\t\t\tSigningAlgorithms: string[];\n\t\t};\n\t};\n}\n\nexport interface AwsClientOptions extends Partial<ConstructorParameters<typeof AwsClient>[0]> {}\n\nexport class AwsKmsClient extends AwsClient {\n\tconstructor(options: AwsClientOptions = {}) {\n\t\tif (!options.accessKeyId || !options.secretAccessKey) {\n\t\t\tthrow new Error('AWS Access Key ID and Secret Access Key are required');\n\t\t}\n\n\t\tif (!options.region) {\n\t\t\tthrow new Error('Region is required');\n\t\t}\n\n\t\tsuper({\n\t\t\tregion: options.region,\n\t\t\taccessKeyId: options.accessKeyId,\n\t\t\tsecretAccessKey: options.secretAccessKey,\n\t\t\tservice: 'kms',\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync getPublicKey(keyId: string) {\n\t\tconst publicKeyResponse = await this.runCommand('GetPublicKey', { KeyId: keyId });\n\n\t\tif (!publicKeyResponse.PublicKey) {\n\t\t\tthrow new Error('Public Key not found for the supplied `keyId`');\n\t\t}\n\n\t\tconst compressedKey = publicKeyFromDER(fromBase64(publicKeyResponse.PublicKey));\n\n\t\tswitch (publicKeyResponse.KeySpec) {\n\t\t\tcase 'ECC_NIST_P256':\n\t\t\t\treturn new Secp256r1PublicKey(compressedKey);\n\t\t\tcase 'ECC_SECG_P256K1':\n\t\t\t\treturn new Secp256k1PublicKey(compressedKey);\n\t\t\tdefault:\n\t\t\t\tthrow new Error('Unsupported key spec: ' + publicKeyResponse.KeySpec);\n\t\t}\n\t}\n\n\tasync runCommand<T extends keyof KmsCommands>(\n\t\tcommand: T,\n\t\tbody: KmsCommands[T]['request'],\n\t\t{\n\t\t\tregion = this.region!,\n\t\t}: {\n\t\t\tregion?: string;\n\t\t} = {},\n\t): Promise<KmsCommands[T]['response']> {\n\t\tif (!region) {\n\t\t\tthrow new Error('Region is required');\n\t\t}\n\n\t\tconst res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/x-amz-json-1.1',\n\t\t\t\t'X-Amz-Target': `TrentService.${command}`,\n\t\t\t},\n\t\t\tbody: JSON.stringify(body),\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(await res.text());\n\t\t}\n\n\t\treturn res.json();\n\t}\n}\n"],"mappings":";;;;;;;AAyCA,IAAa,eAAb,cAAkC,UAAU;CAC3C,YAAY,UAA4B,EAAE,EAAE;AAC3C,MAAI,CAAC,QAAQ,eAAe,CAAC,QAAQ,gBACpC,OAAM,IAAI,MAAM,uDAAuD;AAGxE,MAAI,CAAC,QAAQ,OACZ,OAAM,IAAI,MAAM,qBAAqB;AAGtC,QAAM;GACL,QAAQ,QAAQ;GAChB,aAAa,QAAQ;GACrB,iBAAiB,QAAQ;GACzB,SAAS;GACT,GAAG;GACH,CAAC;;CAGH,MAAM,aAAa,OAAe;EACjC,MAAM,oBAAoB,MAAM,KAAK,WAAW,gBAAgB,EAAE,OAAO,OAAO,CAAC;AAEjF,MAAI,CAAC,kBAAkB,UACtB,OAAM,IAAI,MAAM,gDAAgD;EAGjE,MAAM,gBAAgB,iBAAiB,WAAW,kBAAkB,UAAU,CAAC;AAE/E,UAAQ,kBAAkB,SAA1B;GACC,KAAK,gBACJ,QAAO,IAAI,mBAAmB,cAAc;GAC7C,KAAK,kBACJ,QAAO,IAAI,mBAAmB,cAAc;GAC7C,QACC,OAAM,IAAI,MAAM,2BAA2B,kBAAkB,QAAQ;;;CAIxE,MAAM,WACL,SACA,MACA,EACC,SAAS,KAAK,WAGX,EAAE,EACgC;AACtC,MAAI,CAAC,OACJ,OAAM,IAAI,MAAM,qBAAqB;EAGtC,MAAM,MAAM,MAAM,KAAK,MAAM,eAAe,OAAO,kBAAkB;GACpE,SAAS;IACR,gBAAgB;IAChB,gBAAgB,gBAAgB;IAChC;GACD,MAAM,KAAK,UAAU,KAAK;GAC1B,CAAC;AAEF,MAAI,CAAC,IAAI,GACR,OAAM,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC;AAGlC,SAAO,IAAI,MAAM"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AwsClientOptions, AwsKmsClient } from "./aws-client.mjs";
|
|
2
|
-
import { PublicKey, Signer } from "@mysten/sui/cryptography";
|
|
3
|
-
|
|
4
|
-
//#region src/aws/aws-kms-signer.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for initializing the AwsKmsSigner.
|
|
8
|
-
*/
|
|
9
|
-
interface AwsKmsSignerOptions {
|
|
10
|
-
/** AWS KMS Key ID used for signing */
|
|
11
|
-
kmsKeyId: string;
|
|
12
|
-
/** Options for setting up the AWS KMS client */
|
|
13
|
-
client: AwsKmsClient;
|
|
14
|
-
/** Public key */
|
|
15
|
-
publicKey: PublicKey;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Aws KMS Signer integrates AWS Key Management Service (KMS) with the Sui blockchain
|
|
19
|
-
* to provide signing capabilities using AWS-managed cryptographic keys.
|
|
20
|
-
*/
|
|
21
|
-
declare class AwsKmsSigner extends Signer {
|
|
22
|
-
#private;
|
|
23
|
-
/**
|
|
24
|
-
* Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.
|
|
25
|
-
* For example:
|
|
26
|
-
* ```
|
|
27
|
-
* const signer = await AwsKmsSigner.fromKeyId(keyId, options);
|
|
28
|
-
* ```
|
|
29
|
-
* @throws Will throw an error if required AWS credentials or region are not provided.
|
|
30
|
-
*/
|
|
31
|
-
constructor({
|
|
32
|
-
kmsKeyId,
|
|
33
|
-
client,
|
|
34
|
-
publicKey
|
|
35
|
-
}: AwsKmsSignerOptions);
|
|
36
|
-
/**
|
|
37
|
-
* Retrieves the key scheme used by this signer.
|
|
38
|
-
* @returns AWS supports only Secp256k1 and Secp256r1 schemes.
|
|
39
|
-
*/
|
|
40
|
-
getKeyScheme(): "ED25519" | "Secp256r1" | "Secp256k1" | "MultiSig" | "ZkLogin" | "Passkey";
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves the public key associated with this signer.
|
|
43
|
-
* @returns The Secp256k1PublicKey instance.
|
|
44
|
-
* @throws Will throw an error if the public key has not been initialized.
|
|
45
|
-
*/
|
|
46
|
-
getPublicKey(): PublicKey;
|
|
47
|
-
/**
|
|
48
|
-
* Signs the given data using AWS KMS.
|
|
49
|
-
* @param bytes - The data to be signed as a Uint8Array.
|
|
50
|
-
* @returns A promise that resolves to the signature as a Uint8Array.
|
|
51
|
-
* @throws Will throw an error if the public key is not initialized or if signing fails.
|
|
52
|
-
*/
|
|
53
|
-
sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
|
|
54
|
-
/**
|
|
55
|
-
* Prepares the signer by fetching and setting the public key from AWS KMS.
|
|
56
|
-
* It is recommended to initialize an `AwsKmsSigner` instance using this function.
|
|
57
|
-
* @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
|
|
58
|
-
*/
|
|
59
|
-
static fromKeyId(keyId: string, options: AwsClientOptions): Promise<AwsKmsSigner>;
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
export { AwsKmsSigner, AwsKmsSignerOptions };
|
|
63
|
-
//# sourceMappingURL=aws-kms-signer.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws-kms-signer.d.mts","names":[],"sources":["../../src/aws/aws-kms-signer.ts"],"sourcesContent":[],"mappings":";;;;;AAaA;AAaA;;AAeyB,UA5BR,mBAAA,CA4BQ;EAAQ;EAAa,QAAA,EAAA,MAAA;EAsBjC;EAUM,MAAA,EAxDV,YAwDU;EAAgC;EAAX,SAAA,EAtD5B,SAsD4B;;;;;;AA/CA,cAA3B,YAAA,SAAqB,MAAA,CAAM;;;;;;;;;;;;;;KAeM;;;;;;;;;;;kBAsBjC;;;;;;;cAUM,aAAa,QAAQ,WAAW;;;;;;2CAiBH,mBAAgB,QAAA"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { getConcatenatedSignature } from "../utils/utils.mjs";
|
|
2
|
-
import { AwsKmsClient } from "./aws-client.mjs";
|
|
3
|
-
import { SIGNATURE_FLAG_TO_SCHEME, Signer } from "@mysten/sui/cryptography";
|
|
4
|
-
import { fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
5
|
-
|
|
6
|
-
//#region src/aws/aws-kms-signer.ts
|
|
7
|
-
/**
|
|
8
|
-
* Aws KMS Signer integrates AWS Key Management Service (KMS) with the Sui blockchain
|
|
9
|
-
* to provide signing capabilities using AWS-managed cryptographic keys.
|
|
10
|
-
*/
|
|
11
|
-
var AwsKmsSigner = class AwsKmsSigner extends Signer {
|
|
12
|
-
#publicKey;
|
|
13
|
-
/** AWS KMS client instance */
|
|
14
|
-
#client;
|
|
15
|
-
/** AWS KMS Key ID used for signing */
|
|
16
|
-
#kmsKeyId;
|
|
17
|
-
/**
|
|
18
|
-
* Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.
|
|
19
|
-
* For example:
|
|
20
|
-
* ```
|
|
21
|
-
* const signer = await AwsKmsSigner.fromKeyId(keyId, options);
|
|
22
|
-
* ```
|
|
23
|
-
* @throws Will throw an error if required AWS credentials or region are not provided.
|
|
24
|
-
*/
|
|
25
|
-
constructor({ kmsKeyId, client, publicKey }) {
|
|
26
|
-
super();
|
|
27
|
-
if (!kmsKeyId) throw new Error("KMS Key ID is required");
|
|
28
|
-
this.#client = client;
|
|
29
|
-
this.#kmsKeyId = kmsKeyId;
|
|
30
|
-
this.#publicKey = publicKey;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves the key scheme used by this signer.
|
|
34
|
-
* @returns AWS supports only Secp256k1 and Secp256r1 schemes.
|
|
35
|
-
*/
|
|
36
|
-
getKeyScheme() {
|
|
37
|
-
return SIGNATURE_FLAG_TO_SCHEME[this.#publicKey.flag()];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Retrieves the public key associated with this signer.
|
|
41
|
-
* @returns The Secp256k1PublicKey instance.
|
|
42
|
-
* @throws Will throw an error if the public key has not been initialized.
|
|
43
|
-
*/
|
|
44
|
-
getPublicKey() {
|
|
45
|
-
return this.#publicKey;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Signs the given data using AWS KMS.
|
|
49
|
-
* @param bytes - The data to be signed as a Uint8Array.
|
|
50
|
-
* @returns A promise that resolves to the signature as a Uint8Array.
|
|
51
|
-
* @throws Will throw an error if the public key is not initialized or if signing fails.
|
|
52
|
-
*/
|
|
53
|
-
async sign(bytes) {
|
|
54
|
-
return getConcatenatedSignature(fromBase64((await this.#client.runCommand("Sign", {
|
|
55
|
-
KeyId: this.#kmsKeyId,
|
|
56
|
-
Message: toBase64(bytes),
|
|
57
|
-
MessageType: "RAW",
|
|
58
|
-
SigningAlgorithm: "ECDSA_SHA_256"
|
|
59
|
-
})).Signature), this.getKeyScheme());
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Prepares the signer by fetching and setting the public key from AWS KMS.
|
|
63
|
-
* It is recommended to initialize an `AwsKmsSigner` instance using this function.
|
|
64
|
-
* @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
|
|
65
|
-
*/
|
|
66
|
-
static async fromKeyId(keyId, options) {
|
|
67
|
-
const client = new AwsKmsClient(options);
|
|
68
|
-
return new AwsKmsSigner({
|
|
69
|
-
kmsKeyId: keyId,
|
|
70
|
-
client,
|
|
71
|
-
publicKey: await client.getPublicKey(keyId)
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
export { AwsKmsSigner };
|
|
78
|
-
//# sourceMappingURL=aws-kms-signer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws-kms-signer.mjs","names":["#client","#kmsKeyId","#publicKey"],"sources":["../../src/aws/aws-kms-signer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { PublicKey, SignatureFlag } from '@mysten/sui/cryptography';\nimport { SIGNATURE_FLAG_TO_SCHEME, Signer } from '@mysten/sui/cryptography';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\n\nimport { getConcatenatedSignature } from '../utils/utils.js';\nimport type { AwsClientOptions } from './aws-client.js';\nimport { AwsKmsClient } from './aws-client.js';\n\n/**\n * Configuration options for initializing the AwsKmsSigner.\n */\nexport interface AwsKmsSignerOptions {\n\t/** AWS KMS Key ID used for signing */\n\tkmsKeyId: string;\n\t/** Options for setting up the AWS KMS client */\n\tclient: AwsKmsClient;\n\t/** Public key */\n\tpublicKey: PublicKey;\n}\n\n/**\n * Aws KMS Signer integrates AWS Key Management Service (KMS) with the Sui blockchain\n * to provide signing capabilities using AWS-managed cryptographic keys.\n */\nexport class AwsKmsSigner extends Signer {\n\t#publicKey: PublicKey;\n\t/** AWS KMS client instance */\n\t#client: AwsKmsClient;\n\t/** AWS KMS Key ID used for signing */\n\t#kmsKeyId: string;\n\n\t/**\n\t * Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.\n\t * For example:\n\t * ```\n\t * const signer = await AwsKmsSigner.fromKeyId(keyId, options);\n\t * ```\n\t * @throws Will throw an error if required AWS credentials or region are not provided.\n\t */\n\tconstructor({ kmsKeyId, client, publicKey }: AwsKmsSignerOptions) {\n\t\tsuper();\n\t\tif (!kmsKeyId) throw new Error('KMS Key ID is required');\n\n\t\tthis.#client = client;\n\t\tthis.#kmsKeyId = kmsKeyId;\n\t\tthis.#publicKey = publicKey;\n\t}\n\n\t/**\n\t * Retrieves the key scheme used by this signer.\n\t * @returns AWS supports only Secp256k1 and Secp256r1 schemes.\n\t */\n\tgetKeyScheme() {\n\t\treturn SIGNATURE_FLAG_TO_SCHEME[this.#publicKey.flag() as SignatureFlag];\n\t}\n\n\t/**\n\t * Retrieves the public key associated with this signer.\n\t * @returns The Secp256k1PublicKey instance.\n\t * @throws Will throw an error if the public key has not been initialized.\n\t */\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\t/**\n\t * Signs the given data using AWS KMS.\n\t * @param bytes - The data to be signed as a Uint8Array.\n\t * @returns A promise that resolves to the signature as a Uint8Array.\n\t * @throws Will throw an error if the public key is not initialized or if signing fails.\n\t */\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n\t\tconst signResponse = await this.#client.runCommand('Sign', {\n\t\t\tKeyId: this.#kmsKeyId,\n\t\t\tMessage: toBase64(bytes),\n\t\t\tMessageType: 'RAW',\n\t\t\tSigningAlgorithm: 'ECDSA_SHA_256',\n\t\t});\n\n\t\t// Concatenate the signature components into a compact form\n\t\treturn getConcatenatedSignature(fromBase64(signResponse.Signature), this.getKeyScheme());\n\t}\n\n\t/**\n\t * Prepares the signer by fetching and setting the public key from AWS KMS.\n\t * It is recommended to initialize an `AwsKmsSigner` instance using this function.\n\t * @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).\n\t */\n\tstatic async fromKeyId(keyId: string, options: AwsClientOptions) {\n\t\tconst client = new AwsKmsClient(options);\n\n\t\tconst pubKey = await client.getPublicKey(keyId);\n\n\t\treturn new AwsKmsSigner({\n\t\t\tkmsKeyId: keyId,\n\t\t\tclient,\n\t\t\tpublicKey: pubKey,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;AA0BA,IAAa,eAAb,MAAa,qBAAqB,OAAO;CACxC;;CAEA;;CAEA;;;;;;;;;CAUA,YAAY,EAAE,UAAU,QAAQ,aAAkC;AACjE,SAAO;AACP,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,yBAAyB;AAExD,QAAKA,SAAU;AACf,QAAKC,WAAY;AACjB,QAAKC,YAAa;;;;;;CAOnB,eAAe;AACd,SAAO,yBAAyB,MAAKA,UAAW,MAAM;;;;;;;CAQvD,eAAe;AACd,SAAO,MAAKA;;;;;;;;CASb,MAAM,KAAK,OAAqD;AAS/D,SAAO,yBAAyB,YARX,MAAM,MAAKF,OAAQ,WAAW,QAAQ;GAC1D,OAAO,MAAKC;GACZ,SAAS,SAAS,MAAM;GACxB,aAAa;GACb,kBAAkB;GAClB,CAAC,EAGsD,UAAU,EAAE,KAAK,cAAc,CAAC;;;;;;;CAQzF,aAAa,UAAU,OAAe,SAA2B;EAChE,MAAM,SAAS,IAAI,aAAa,QAAQ;AAIxC,SAAO,IAAI,aAAa;GACvB,UAAU;GACV;GACA,WALc,MAAM,OAAO,aAAa,MAAM;GAM9C,CAAC"}
|
package/dist/aws/aws4fetch.d.mts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//#region src/aws/aws4fetch.d.ts
|
|
2
|
-
type AwsRequestInit = RequestInit & {
|
|
3
|
-
aws?: {
|
|
4
|
-
accessKeyId?: string;
|
|
5
|
-
secretAccessKey?: string;
|
|
6
|
-
sessionToken?: string;
|
|
7
|
-
service?: string;
|
|
8
|
-
region?: string;
|
|
9
|
-
cache?: Map<string, ArrayBuffer>;
|
|
10
|
-
datetime?: string;
|
|
11
|
-
signQuery?: boolean;
|
|
12
|
-
appendSessionToken?: boolean;
|
|
13
|
-
allHeaders?: boolean;
|
|
14
|
-
singleEncode?: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
declare class AwsClient {
|
|
18
|
-
accessKeyId: string;
|
|
19
|
-
secretAccessKey: string;
|
|
20
|
-
sessionToken: string | undefined;
|
|
21
|
-
service: string | undefined;
|
|
22
|
-
region: string | undefined;
|
|
23
|
-
cache: Map<any, any>;
|
|
24
|
-
retries: number;
|
|
25
|
-
initRetryMs: number;
|
|
26
|
-
/**
|
|
27
|
-
* @param {} options
|
|
28
|
-
*/
|
|
29
|
-
constructor({
|
|
30
|
-
accessKeyId,
|
|
31
|
-
secretAccessKey,
|
|
32
|
-
sessionToken,
|
|
33
|
-
service,
|
|
34
|
-
region,
|
|
35
|
-
cache,
|
|
36
|
-
retries,
|
|
37
|
-
initRetryMs
|
|
38
|
-
}: {
|
|
39
|
-
accessKeyId: string;
|
|
40
|
-
secretAccessKey: string;
|
|
41
|
-
sessionToken?: string;
|
|
42
|
-
service?: string;
|
|
43
|
-
region?: string;
|
|
44
|
-
cache?: Map<string, ArrayBuffer>;
|
|
45
|
-
retries?: number;
|
|
46
|
-
initRetryMs?: number;
|
|
47
|
-
});
|
|
48
|
-
sign(input: Request | {
|
|
49
|
-
toString: () => string;
|
|
50
|
-
}, init: AwsRequestInit): Promise<Request>;
|
|
51
|
-
/**
|
|
52
|
-
* @param {Request | { toString: () => string }} input
|
|
53
|
-
* @param {?AwsRequestInit} [init]
|
|
54
|
-
* @returns {Promise<Response>}
|
|
55
|
-
*/
|
|
56
|
-
fetch(input: Request | {
|
|
57
|
-
toString: () => string;
|
|
58
|
-
}, init: AwsRequestInit): Promise<Response>;
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
export { AwsClient };
|
|
62
|
-
//# sourceMappingURL=aws4fetch.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aws4fetch.d.mts","names":[],"sources":["../../src/aws/aws4fetch.ts"],"sourcesContent":[],"mappings":";KAsCK,cAAA,GAAiB;EAAjB,GAAA,CAAA,EAAA;IAAiB,WAAA,CAAA,EAAA,MAAA;IAOA,eAAA,CAAA,EAAA,MAAA;IAAZ,YAAA,CAAA,EAAA,MAAA;IAAG,OAAA,CAAA,EAAA,MAAA;IASA,MAAA,CAAA,EAAS,MAAA;IAMd,KAAA,CAAA,EAfE,GAeF,CAAA,MAAA,EAfc,WAed,CAAA;IAON,QAAA,CAAA,EAAA,MAAA;IACA,SAAA,CAAA,EAAA,OAAA;IACA,kBAAA,CAAA,EAAA,OAAA;IACA,UAAA,CAAA,EAAA,OAAA;IACA,YAAA,CAAA,EAAA,OAAA;EACA,CAAA;CACA;AACA,cApBW,SAAA,CAoBX;EAOoB,WAAA,EAAA,MAAA;EAAZ,eAAA,EAAA,MAAA;EAiBS,YAAA,EAAA,MAAA,GAAA,SAAA;EAA4C,OAAA,EAAA,MAAA,GAAA,SAAA;EAAyB,MAAA,EAAA,MAAA,GAAA,SAAA;EAAR,KAAA,EAtCxE,GAsCwE,CAAA,GAAA,EAAA,GAAA,CAAA;EAiC5D,OAAA,EAAA,MAAA;EAA4C,WAAA,EAAA,MAAA;EAAc;;;;;;;;;;;;;;;;;;YAlDpE,YAAY;;;;cAiBH;;WAA4C,iBAAiB,QAAQ;;;;;;eAiCpE;;WAA4C,iBAAc,QAAA"}
|