@mysten/signers 0.6.2 → 1.0.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +5 -2
  3. package/dist/aws/aws-client.d.mts +48 -0
  4. package/dist/aws/aws-client.d.mts.map +1 -0
  5. package/dist/aws/aws-client.mjs +46 -0
  6. package/dist/aws/aws-client.mjs.map +1 -0
  7. package/dist/aws/aws-kms-signer.d.mts +63 -0
  8. package/dist/aws/aws-kms-signer.d.mts.map +1 -0
  9. package/dist/aws/aws-kms-signer.mjs +78 -0
  10. package/dist/aws/aws-kms-signer.mjs.map +1 -0
  11. package/dist/aws/aws4fetch.d.mts +62 -0
  12. package/dist/aws/aws4fetch.d.mts.map +1 -0
  13. package/dist/aws/aws4fetch.mjs +313 -0
  14. package/dist/aws/aws4fetch.mjs.map +1 -0
  15. package/dist/aws/index.d.mts +3 -0
  16. package/dist/aws/index.mjs +3 -0
  17. package/dist/gcp/gcp-kms-client.d.mts +71 -0
  18. package/dist/gcp/gcp-kms-client.d.mts.map +1 -0
  19. package/dist/gcp/gcp-kms-client.mjs +104 -0
  20. package/dist/gcp/gcp-kms-client.mjs.map +1 -0
  21. package/dist/gcp/index.d.mts +2 -0
  22. package/dist/gcp/index.mjs +3 -0
  23. package/dist/ledger/index.d.mts +74 -0
  24. package/dist/ledger/index.d.mts.map +1 -0
  25. package/dist/ledger/index.mjs +110 -0
  26. package/dist/ledger/index.mjs.map +1 -0
  27. package/dist/ledger/objects.d.mts +10 -0
  28. package/dist/ledger/objects.d.mts.map +1 -0
  29. package/dist/ledger/objects.mjs +16 -0
  30. package/dist/ledger/objects.mjs.map +1 -0
  31. package/dist/utils/utils.mjs +71 -0
  32. package/dist/utils/utils.mjs.map +1 -0
  33. package/dist/webcrypto/index.d.mts +32 -0
  34. package/dist/webcrypto/index.d.mts.map +1 -0
  35. package/dist/webcrypto/index.mjs +70 -0
  36. package/dist/webcrypto/index.mjs.map +1 -0
  37. package/package.json +34 -28
  38. package/src/aws/aws-kms-signer.ts +0 -9
  39. package/src/gcp/gcp-kms-client.ts +0 -9
  40. package/src/ledger/index.ts +4 -5
  41. package/src/ledger/objects.ts +10 -34
  42. package/src/utils/utils.ts +18 -10
  43. package/src/webcrypto/index.ts +6 -3
  44. package/aws/package.json +0 -6
  45. package/dist/cjs/aws/aws-client.d.ts +0 -43
  46. package/dist/cjs/aws/aws-client.js +0 -79
  47. package/dist/cjs/aws/aws-client.js.map +0 -7
  48. package/dist/cjs/aws/aws-kms-signer.d.ts +0 -61
  49. package/dist/cjs/aws/aws-kms-signer.js +0 -114
  50. package/dist/cjs/aws/aws-kms-signer.js.map +0 -7
  51. package/dist/cjs/aws/aws4fetch.d.ts +0 -125
  52. package/dist/cjs/aws/aws4fetch.js +0 -382
  53. package/dist/cjs/aws/aws4fetch.js.map +0 -7
  54. package/dist/cjs/aws/index.d.ts +0 -5
  55. package/dist/cjs/aws/index.js +0 -25
  56. package/dist/cjs/aws/index.js.map +0 -7
  57. package/dist/cjs/gcp/gcp-kms-client.d.ts +0 -68
  58. package/dist/cjs/gcp/gcp-kms-client.js +0 -147
  59. package/dist/cjs/gcp/gcp-kms-client.js.map +0 -7
  60. package/dist/cjs/gcp/index.d.ts +0 -4
  61. package/dist/cjs/gcp/index.js +0 -25
  62. package/dist/cjs/gcp/index.js.map +0 -7
  63. package/dist/cjs/ledger/bcs.d.ts +0 -14
  64. package/dist/cjs/ledger/bcs.js +0 -85
  65. package/dist/cjs/ledger/bcs.js.map +0 -7
  66. package/dist/cjs/ledger/index.d.ts +0 -66
  67. package/dist/cjs/ledger/index.js +0 -158
  68. package/dist/cjs/ledger/index.js.map +0 -7
  69. package/dist/cjs/ledger/objects.d.ts +0 -5
  70. package/dist/cjs/ledger/objects.js +0 -60
  71. package/dist/cjs/ledger/objects.js.map +0 -7
  72. package/dist/cjs/package.json +0 -5
  73. package/dist/cjs/utils/utils.d.ts +0 -18
  74. package/dist/cjs/utils/utils.js +0 -85
  75. package/dist/cjs/utils/utils.js.map +0 -7
  76. package/dist/cjs/webcrypto/index.d.ts +0 -26
  77. package/dist/cjs/webcrypto/index.js +0 -112
  78. package/dist/cjs/webcrypto/index.js.map +0 -7
  79. package/dist/esm/aws/aws-client.d.ts +0 -43
  80. package/dist/esm/aws/aws-client.js +0 -59
  81. package/dist/esm/aws/aws-client.js.map +0 -7
  82. package/dist/esm/aws/aws-kms-signer.d.ts +0 -61
  83. package/dist/esm/aws/aws-kms-signer.js +0 -94
  84. package/dist/esm/aws/aws-kms-signer.js.map +0 -7
  85. package/dist/esm/aws/aws4fetch.d.ts +0 -125
  86. package/dist/esm/aws/aws4fetch.js +0 -362
  87. package/dist/esm/aws/aws4fetch.js.map +0 -7
  88. package/dist/esm/aws/index.d.ts +0 -5
  89. package/dist/esm/aws/index.js +0 -5
  90. package/dist/esm/aws/index.js.map +0 -7
  91. package/dist/esm/gcp/gcp-kms-client.d.ts +0 -68
  92. package/dist/esm/gcp/gcp-kms-client.js +0 -127
  93. package/dist/esm/gcp/gcp-kms-client.js.map +0 -7
  94. package/dist/esm/gcp/index.d.ts +0 -4
  95. package/dist/esm/gcp/index.js +0 -5
  96. package/dist/esm/gcp/index.js.map +0 -7
  97. package/dist/esm/ledger/bcs.d.ts +0 -14
  98. package/dist/esm/ledger/bcs.js +0 -70
  99. package/dist/esm/ledger/bcs.js.map +0 -7
  100. package/dist/esm/ledger/index.d.ts +0 -66
  101. package/dist/esm/ledger/index.js +0 -138
  102. package/dist/esm/ledger/index.js.map +0 -7
  103. package/dist/esm/ledger/objects.d.ts +0 -5
  104. package/dist/esm/ledger/objects.js +0 -40
  105. package/dist/esm/ledger/objects.js.map +0 -7
  106. package/dist/esm/package.json +0 -5
  107. package/dist/esm/utils/utils.d.ts +0 -18
  108. package/dist/esm/utils/utils.js +0 -65
  109. package/dist/esm/utils/utils.js.map +0 -7
  110. package/dist/esm/webcrypto/index.d.ts +0 -26
  111. package/dist/esm/webcrypto/index.js +0 -92
  112. package/dist/esm/webcrypto/index.js.map +0 -7
  113. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  114. package/dist/tsconfig.tsbuildinfo +0 -1
  115. package/gcp/package.json +0 -6
  116. package/ledger/package.json +0 -6
  117. package/src/ledger/bcs.ts +0 -87
  118. package/webcrypto/package.json +0 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # @mysten/signers
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 99d1e00: Add default export condition
8
+ - Updated dependencies [99d1e00]
9
+ - @mysten/ledgerjs-hw-app-sui@0.7.1
10
+ - @mysten/sui@2.3.2
11
+
12
+ ## 1.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - e00788c: Remove manual BCS serialization from ledger signer
17
+
18
+ **Breaking Changes:**
19
+ - **Removed `SuiMoveObject` export**: The custom BCS schema for Move objects has been removed. The
20
+ ledger signer now uses server-provided BCS bytes directly.
21
+ - **Client type change**: `LedgerSigner` and `getInputObjects` now accepts `ClientWithCoreApi`
22
+ instead of `SuiJsonRpcClient` (this is still compatible with `SuiJsonRpcClient`)
23
+
24
+ ### Minor Changes
25
+
26
+ - e00788c: Remove deprecated `signData()` method from `AwsKmsSigner`, `GcpKmsSigner`, and
27
+ `MultiSigSigner`. Use `sign()` method instead.
28
+ - e00788c: Update to use SuiJsonRpcClient instead of SuiClient
29
+
30
+ Updated all type signatures, internal usages, examples, and documentation to use
31
+ `SuiJsonRpcClient` from `@mysten/sui/jsonRpc` instead of the deprecated `SuiClient` from
32
+ `@mysten/sui/client`.
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [e00788c]
37
+ - Updated dependencies [e00788c]
38
+ - Updated dependencies [e00788c]
39
+ - Updated dependencies [e00788c]
40
+ - Updated dependencies [e00788c]
41
+ - Updated dependencies [e00788c]
42
+ - Updated dependencies [e00788c]
43
+ - Updated dependencies [e00788c]
44
+ - Updated dependencies [e00788c]
45
+ - Updated dependencies [e00788c]
46
+ - Updated dependencies [e00788c]
47
+ - Updated dependencies [e00788c]
48
+ - @mysten/sui@2.0.0
49
+
3
50
  ## 0.6.2
4
51
 
5
52
  ### Patch Changes
package/README.md CHANGED
@@ -174,12 +174,15 @@ cryptographic operations.
174
174
  import Transport from '@ledgerhq/hw-transport-node-hid';
175
175
  import SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';
176
176
  import { LedgerSigner } from '@mysten/signers/ledger';
177
- import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
177
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
178
178
  import { Transaction } from '@mysten/sui/transactions';
179
179
 
180
180
  const transport = await Transport.open(undefined);
181
181
  const ledgerClient = new SuiLedgerClient(transport);
182
- const suiClient = new SuiClient({ url: getFullnodeUrl('testnet') });
182
+ const suiClient = new SuiGrpcClient({
183
+ network: 'testnet',
184
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
185
+ });
183
186
 
184
187
  const signer = await LedgerSigner.fromDerivationPath(
185
188
  "m/44'/784'/0'/0'/0'",
@@ -0,0 +1,48 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,46 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,63 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,78 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,62 @@
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
@@ -0,0 +1 @@
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"}