@mysten/signers 0.6.1 → 1.0.0

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 +45 -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 +30 -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
@@ -1,8 +1,8 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { secp256r1 } from '@noble/curves/p256';
5
- import { secp256k1 } from '@noble/curves/secp256k1';
4
+ import { p256 as secp256r1 } from '@noble/curves/nist.js';
5
+ import { secp256k1 } from '@noble/curves/secp256k1.js';
6
6
  import { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';
7
7
 
8
8
  /** The total number of bits in the DER bit string for the uncompressed public key. */
@@ -70,14 +70,22 @@ export function getConcatenatedSignature(signature: Uint8Array, keyScheme: strin
70
70
  const [r, s] = derElement.toJSON() as [string, string];
71
71
 
72
72
  switch (keyScheme) {
73
- case 'Secp256k1':
74
- return new secp256k1.Signature(BigInt(r), BigInt(s))
75
- .normalizeS()
76
- .toCompactRawBytes() as Uint8Array<ArrayBuffer>;
77
- case 'Secp256r1':
78
- return new secp256r1.Signature(BigInt(r), BigInt(s))
79
- .normalizeS()
80
- .toCompactRawBytes() as Uint8Array<ArrayBuffer>;
73
+ case 'Secp256k1': {
74
+ const sig = new secp256k1.Signature(BigInt(r), BigInt(s));
75
+ const normalized = sig.hasHighS()
76
+ ? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s))
77
+ : sig;
78
+
79
+ return normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;
80
+ }
81
+ case 'Secp256r1': {
82
+ const sig = new secp256r1.Signature(BigInt(r), BigInt(s));
83
+ const normalized = sig.hasHighS()
84
+ ? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))
85
+ : sig;
86
+
87
+ return normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;
88
+ }
81
89
  default:
82
90
  throw new Error('Unsupported key scheme');
83
91
  }
@@ -4,7 +4,7 @@
4
4
  import type { SignatureScheme } from '@mysten/sui/cryptography';
5
5
  import { Signer } from '@mysten/sui/cryptography';
6
6
  import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
7
- import { secp256r1 } from '@noble/curves/p256';
7
+ import { p256 as secp256r1 } from '@noble/curves/nist.js';
8
8
 
9
9
  // Convert from uncompressed (65 bytes) to compressed (33 bytes) format
10
10
  function getCompressedPublicKey(publicKey: Uint8Array) {
@@ -101,8 +101,11 @@ export class WebCryptoSigner extends Signer {
101
101
  bytes as BufferSource,
102
102
  );
103
103
 
104
- const signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
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;
105
108
 
106
- return signature.normalizeS().toCompactRawBytes() as Uint8Array<ArrayBuffer>;
109
+ return normalizedSig.toBytes('compact') as Uint8Array<ArrayBuffer>;
107
110
  }
108
111
  }
package/aws/package.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "private": true,
3
- "import": "../dist/esm/aws/index.js",
4
- "main": "../dist/cjs/aws/index.js",
5
- "sideEffects": false
6
- }
@@ -1,43 +0,0 @@
1
- import { Secp256k1PublicKey } from '@mysten/sui/keypairs/secp256k1';
2
- import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
3
- import { AwsClient } from './aws4fetch.js';
4
- interface KmsCommands {
5
- Sign: {
6
- request: {
7
- KeyId: string;
8
- Message: string;
9
- MessageType: 'RAW' | 'DIGEST';
10
- SigningAlgorithm: 'ECDSA_SHA_256';
11
- };
12
- response: {
13
- KeyId: string;
14
- KeyOrigin: string;
15
- Signature: string;
16
- SigningAlgorithm: string;
17
- };
18
- };
19
- GetPublicKey: {
20
- request: {
21
- KeyId: string;
22
- };
23
- response: {
24
- CustomerMasterKeySpec: string;
25
- KeyId: string;
26
- KeyOrigin: string;
27
- KeySpec: string;
28
- KeyUsage: string;
29
- PublicKey: string;
30
- SigningAlgorithms: string[];
31
- };
32
- };
33
- }
34
- export interface AwsClientOptions extends Partial<ConstructorParameters<typeof AwsClient>[0]> {
35
- }
36
- export declare class AwsKmsClient extends AwsClient {
37
- constructor(options?: AwsClientOptions);
38
- getPublicKey(keyId: string): Promise<Secp256r1PublicKey | Secp256k1PublicKey>;
39
- runCommand<T extends keyof KmsCommands>(command: T, body: KmsCommands[T]['request'], { region, }?: {
40
- region?: string;
41
- }): Promise<KmsCommands[T]['response']>;
42
- }
43
- export {};
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var aws_client_exports = {};
20
- __export(aws_client_exports, {
21
- AwsKmsClient: () => AwsKmsClient
22
- });
23
- module.exports = __toCommonJS(aws_client_exports);
24
- var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
25
- var import_secp256r1 = require("@mysten/sui/keypairs/secp256r1");
26
- var import_utils = require("@mysten/sui/utils");
27
- var import_utils2 = require("../utils/utils.js");
28
- var import_aws4fetch = require("./aws4fetch.js");
29
- class AwsKmsClient extends import_aws4fetch.AwsClient {
30
- constructor(options = {}) {
31
- if (!options.accessKeyId || !options.secretAccessKey) {
32
- throw new Error("AWS Access Key ID and Secret Access Key are required");
33
- }
34
- if (!options.region) {
35
- throw new Error("Region is required");
36
- }
37
- super({
38
- region: options.region,
39
- accessKeyId: options.accessKeyId,
40
- secretAccessKey: options.secretAccessKey,
41
- service: "kms",
42
- ...options
43
- });
44
- }
45
- async getPublicKey(keyId) {
46
- const publicKeyResponse = await this.runCommand("GetPublicKey", { KeyId: keyId });
47
- if (!publicKeyResponse.PublicKey) {
48
- throw new Error("Public Key not found for the supplied `keyId`");
49
- }
50
- const compressedKey = (0, import_utils2.publicKeyFromDER)((0, import_utils.fromBase64)(publicKeyResponse.PublicKey));
51
- switch (publicKeyResponse.KeySpec) {
52
- case "ECC_NIST_P256":
53
- return new import_secp256r1.Secp256r1PublicKey(compressedKey);
54
- case "ECC_SECG_P256K1":
55
- return new import_secp256k1.Secp256k1PublicKey(compressedKey);
56
- default:
57
- throw new Error("Unsupported key spec: " + publicKeyResponse.KeySpec);
58
- }
59
- }
60
- async runCommand(command, body, {
61
- region = this.region
62
- } = {}) {
63
- if (!region) {
64
- throw new Error("Region is required");
65
- }
66
- const res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {
67
- headers: {
68
- "Content-Type": "application/x-amz-json-1.1",
69
- "X-Amz-Target": `TrentService.${command}`
70
- },
71
- body: JSON.stringify(body)
72
- });
73
- if (!res.ok) {
74
- throw new Error(await res.text());
75
- }
76
- return res.json();
77
- }
78
- }
79
- //# sourceMappingURL=aws-client.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/aws/aws-client.ts"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AACnC,uBAAmC;AACnC,mBAA2B;AAE3B,IAAAA,gBAAiC;AACjC,uBAA0B;AAiCnB,MAAM,qBAAqB,2BAAU;AAAA,EAC3C,YAAY,UAA4B,CAAC,GAAG;AAC3C,QAAI,CAAC,QAAQ,eAAe,CAAC,QAAQ,iBAAiB;AACrD,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,QAAI,CAAC,QAAQ,QAAQ;AACpB,YAAM,IAAI,MAAM,oBAAoB;AAAA,IACrC;AAEA,UAAM;AAAA,MACL,QAAQ,QAAQ;AAAA,MAChB,aAAa,QAAQ;AAAA,MACrB,iBAAiB,QAAQ;AAAA,MACzB,SAAS;AAAA,MACT,GAAG;AAAA,IACJ,CAAC;AAAA,EACF;AAAA,EAEA,MAAM,aAAa,OAAe;AACjC,UAAM,oBAAoB,MAAM,KAAK,WAAW,gBAAgB,EAAE,OAAO,MAAM,CAAC;AAEhF,QAAI,CAAC,kBAAkB,WAAW;AACjC,YAAM,IAAI,MAAM,+CAA+C;AAAA,IAChE;AAEA,UAAM,oBAAgB,oCAAiB,yBAAW,kBAAkB,SAAS,CAAC;AAE9E,YAAQ,kBAAkB,SAAS;AAAA,MAClC,KAAK;AACJ,eAAO,IAAI,oCAAmB,aAAa;AAAA,MAC5C,KAAK;AACJ,eAAO,IAAI,oCAAmB,aAAa;AAAA,MAC5C;AACC,cAAM,IAAI,MAAM,2BAA2B,kBAAkB,OAAO;AAAA,IACtE;AAAA,EACD;AAAA,EAEA,MAAM,WACL,SACA,MACA;AAAA,IACC,SAAS,KAAK;AAAA,EACf,IAEI,CAAC,GACiC;AACtC,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI,MAAM,oBAAoB;AAAA,IACrC;AAEA,UAAM,MAAM,MAAM,KAAK,MAAM,eAAe,MAAM,mBAAmB;AAAA,MACpE,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,gBAAgB,gBAAgB,OAAO;AAAA,MACxC;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,IAC1B,CAAC;AAED,QAAI,CAAC,IAAI,IAAI;AACZ,YAAM,IAAI,MAAM,MAAM,IAAI,KAAK,CAAC;AAAA,IACjC;AAEA,WAAO,IAAI,KAAK;AAAA,EACjB;AACD;",
6
- "names": ["import_utils"]
7
- }
@@ -1,61 +0,0 @@
1
- import type { PublicKey } from '@mysten/sui/cryptography';
2
- import { Signer } from '@mysten/sui/cryptography';
3
- import type { AwsClientOptions } from './aws-client.js';
4
- import { AwsKmsClient } from './aws-client.js';
5
- /**
6
- * Configuration options for initializing the AwsKmsSigner.
7
- */
8
- export interface AwsKmsSignerOptions {
9
- /** AWS KMS Key ID used for signing */
10
- kmsKeyId: string;
11
- /** Options for setting up the AWS KMS client */
12
- client: AwsKmsClient;
13
- /** Public key */
14
- publicKey: PublicKey;
15
- }
16
- /**
17
- * Aws KMS Signer integrates AWS Key Management Service (KMS) with the Sui blockchain
18
- * to provide signing capabilities using AWS-managed cryptographic keys.
19
- */
20
- export declare class AwsKmsSigner extends Signer {
21
- #private;
22
- /**
23
- * Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.
24
- * For example:
25
- * ```
26
- * const signer = await AwsKmsSigner.fromKeyId(keyId, options);
27
- * ```
28
- * @throws Will throw an error if required AWS credentials or region are not provided.
29
- */
30
- constructor({ kmsKeyId, client, publicKey }: AwsKmsSignerOptions);
31
- /**
32
- * Retrieves the key scheme used by this signer.
33
- * @returns AWS supports only Secp256k1 and Secp256r1 schemes.
34
- */
35
- getKeyScheme(): "Secp256k1" | "Secp256r1" | "ED25519" | "MultiSig" | "ZkLogin" | "Passkey";
36
- /**
37
- * Retrieves the public key associated with this signer.
38
- * @returns The Secp256k1PublicKey instance.
39
- * @throws Will throw an error if the public key has not been initialized.
40
- */
41
- getPublicKey(): PublicKey;
42
- /**
43
- * Signs the given data using AWS KMS.
44
- * @param bytes - The data to be signed as a Uint8Array.
45
- * @returns A promise that resolves to the signature as a Uint8Array.
46
- * @throws Will throw an error if the public key is not initialized or if signing fails.
47
- */
48
- sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
49
- /**
50
- * Synchronous signing is not supported by AWS KMS.
51
- * @throws Always throws an error indicating synchronous signing is unsupported.
52
- * @deprecated use `sign` instead
53
- */
54
- signData(): never;
55
- /**
56
- * Prepares the signer by fetching and setting the public key from AWS KMS.
57
- * It is recommended to initialize an `AwsKmsSigner` instance using this function.
58
- * @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
59
- */
60
- static fromKeyId(keyId: string, options: AwsClientOptions): Promise<AwsKmsSigner>;
61
- }
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __typeError = (msg) => {
7
- throw TypeError(msg);
8
- };
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
- var aws_kms_signer_exports = {};
27
- __export(aws_kms_signer_exports, {
28
- AwsKmsSigner: () => AwsKmsSigner
29
- });
30
- module.exports = __toCommonJS(aws_kms_signer_exports);
31
- var import_cryptography = require("@mysten/sui/cryptography");
32
- var import_utils = require("@mysten/sui/utils");
33
- var import_utils2 = require("../utils/utils.js");
34
- var import_aws_client = require("./aws-client.js");
35
- var _publicKey, _client, _kmsKeyId;
36
- const _AwsKmsSigner = class _AwsKmsSigner extends import_cryptography.Signer {
37
- /**
38
- * Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.
39
- * For example:
40
- * ```
41
- * const signer = await AwsKmsSigner.fromKeyId(keyId, options);
42
- * ```
43
- * @throws Will throw an error if required AWS credentials or region are not provided.
44
- */
45
- constructor({ kmsKeyId, client, publicKey }) {
46
- super();
47
- __privateAdd(this, _publicKey);
48
- /** AWS KMS client instance */
49
- __privateAdd(this, _client);
50
- /** AWS KMS Key ID used for signing */
51
- __privateAdd(this, _kmsKeyId);
52
- if (!kmsKeyId) throw new Error("KMS Key ID is required");
53
- __privateSet(this, _client, client);
54
- __privateSet(this, _kmsKeyId, kmsKeyId);
55
- __privateSet(this, _publicKey, publicKey);
56
- }
57
- /**
58
- * Retrieves the key scheme used by this signer.
59
- * @returns AWS supports only Secp256k1 and Secp256r1 schemes.
60
- */
61
- getKeyScheme() {
62
- return import_cryptography.SIGNATURE_FLAG_TO_SCHEME[__privateGet(this, _publicKey).flag()];
63
- }
64
- /**
65
- * Retrieves the public key associated with this signer.
66
- * @returns The Secp256k1PublicKey instance.
67
- * @throws Will throw an error if the public key has not been initialized.
68
- */
69
- getPublicKey() {
70
- return __privateGet(this, _publicKey);
71
- }
72
- /**
73
- * Signs the given data using AWS KMS.
74
- * @param bytes - The data to be signed as a Uint8Array.
75
- * @returns A promise that resolves to the signature as a Uint8Array.
76
- * @throws Will throw an error if the public key is not initialized or if signing fails.
77
- */
78
- async sign(bytes) {
79
- const signResponse = await __privateGet(this, _client).runCommand("Sign", {
80
- KeyId: __privateGet(this, _kmsKeyId),
81
- Message: (0, import_utils.toBase64)(bytes),
82
- MessageType: "RAW",
83
- SigningAlgorithm: "ECDSA_SHA_256"
84
- });
85
- return (0, import_utils2.getConcatenatedSignature)((0, import_utils.fromBase64)(signResponse.Signature), this.getKeyScheme());
86
- }
87
- /**
88
- * Synchronous signing is not supported by AWS KMS.
89
- * @throws Always throws an error indicating synchronous signing is unsupported.
90
- * @deprecated use `sign` instead
91
- */
92
- signData() {
93
- throw new Error("KMS Signer does not support sync signing");
94
- }
95
- /**
96
- * Prepares the signer by fetching and setting the public key from AWS KMS.
97
- * It is recommended to initialize an `AwsKmsSigner` instance using this function.
98
- * @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
99
- */
100
- static async fromKeyId(keyId, options) {
101
- const client = new import_aws_client.AwsKmsClient(options);
102
- const pubKey = await client.getPublicKey(keyId);
103
- return new _AwsKmsSigner({
104
- kmsKeyId: keyId,
105
- client,
106
- publicKey: pubKey
107
- });
108
- }
109
- };
110
- _publicKey = new WeakMap();
111
- _client = new WeakMap();
112
- _kmsKeyId = new WeakMap();
113
- let AwsKmsSigner = _AwsKmsSigner;
114
- //# sourceMappingURL=aws-kms-signer.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/aws/aws-kms-signer.ts"],
4
- "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 * Synchronous signing is not supported by AWS KMS.\n\t * @throws Always throws an error indicating synchronous signing is unsupported.\n\t * @deprecated use `sign` instead\n\t */\n\tsignData(): never {\n\t\tthrow new Error('KMS Signer does not support sync signing');\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAiD;AACjD,mBAAqC;AAErC,IAAAA,gBAAyC;AAEzC,wBAA6B;AAR7B;AA0BO,MAAM,gBAAN,MAAM,sBAAqB,2BAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAexC,YAAY,EAAE,UAAU,QAAQ,UAAU,GAAwB;AACjE,UAAM;AAfP;AAEA;AAAA;AAEA;AAAA;AAYC,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM,wBAAwB;AAEvD,uBAAK,SAAU;AACf,uBAAK,WAAY;AACjB,uBAAK,YAAa;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe;AACd,WAAO,6CAAyB,mBAAK,YAAW,KAAK,CAAkB;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,KAAK,OAAqD;AAC/D,UAAM,eAAe,MAAM,mBAAK,SAAQ,WAAW,QAAQ;AAAA,MAC1D,OAAO,mBAAK;AAAA,MACZ,aAAS,uBAAS,KAAK;AAAA,MACvB,aAAa;AAAA,MACb,kBAAkB;AAAA,IACnB,CAAC;AAGD,eAAO,4CAAyB,yBAAW,aAAa,SAAS,GAAG,KAAK,aAAa,CAAC;AAAA,EACxF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAkB;AACjB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,UAAU,OAAe,SAA2B;AAChE,UAAM,SAAS,IAAI,+BAAa,OAAO;AAEvC,UAAM,SAAS,MAAM,OAAO,aAAa,KAAK;AAE9C,WAAO,IAAI,cAAa;AAAA,MACvB,UAAU;AAAA,MACV;AAAA,MACA,WAAW;AAAA,IACZ,CAAC;AAAA,EACF;AACD;AAnFC;AAEA;AAEA;AALM,IAAM,eAAN;",
6
- "names": ["import_utils"]
7
- }
@@ -1,125 +0,0 @@
1
- type AwsRequestInit = RequestInit & {
2
- aws?: {
3
- accessKeyId?: string;
4
- secretAccessKey?: string;
5
- sessionToken?: string;
6
- service?: string;
7
- region?: string;
8
- cache?: Map<string, ArrayBuffer>;
9
- datetime?: string;
10
- signQuery?: boolean;
11
- appendSessionToken?: boolean;
12
- allHeaders?: boolean;
13
- singleEncode?: boolean;
14
- };
15
- };
16
- export declare class AwsClient {
17
- accessKeyId: string;
18
- secretAccessKey: string;
19
- sessionToken: string | undefined;
20
- service: string | undefined;
21
- region: string | undefined;
22
- cache: Map<any, any>;
23
- retries: number;
24
- initRetryMs: number;
25
- /**
26
- * @param {} options
27
- */
28
- constructor({ accessKeyId, secretAccessKey, sessionToken, service, region, cache, retries, initRetryMs, }: {
29
- accessKeyId: string;
30
- secretAccessKey: string;
31
- sessionToken?: string;
32
- service?: string;
33
- region?: string;
34
- cache?: Map<string, ArrayBuffer>;
35
- retries?: number;
36
- initRetryMs?: number;
37
- });
38
- sign(input: Request | {
39
- toString: () => string;
40
- }, init: AwsRequestInit): Promise<Request>;
41
- /**
42
- * @param {Request | { toString: () => string }} input
43
- * @param {?AwsRequestInit} [init]
44
- * @returns {Promise<Response>}
45
- */
46
- fetch(input: Request | {
47
- toString: () => string;
48
- }, init: AwsRequestInit): Promise<Response>;
49
- }
50
- export declare class AwsV4Signer {
51
- method: any;
52
- url: URL;
53
- headers: Headers;
54
- body: any;
55
- accessKeyId: any;
56
- secretAccessKey: any;
57
- sessionToken: any;
58
- service: any;
59
- region: any;
60
- cache: any;
61
- datetime: any;
62
- signQuery: any;
63
- appendSessionToken: any;
64
- signableHeaders: any[];
65
- signedHeaders: any;
66
- canonicalHeaders: any;
67
- credentialString: string;
68
- encodedPath: string;
69
- encodedSearch: string;
70
- /**
71
- * @param {} options
72
- */
73
- constructor({ method, url, headers, body, accessKeyId, secretAccessKey, sessionToken, service, region, cache, datetime, signQuery, appendSessionToken, allHeaders, singleEncode, }: {
74
- method?: string;
75
- url: string;
76
- headers?: HeadersInit;
77
- body?: BodyInit | null;
78
- accessKeyId: string;
79
- secretAccessKey: string;
80
- sessionToken?: string;
81
- service?: string;
82
- region?: string;
83
- cache?: Map<string, ArrayBuffer>;
84
- datetime?: string;
85
- signQuery?: boolean;
86
- appendSessionToken?: boolean;
87
- allHeaders?: boolean;
88
- singleEncode?: boolean;
89
- });
90
- /**
91
- * @returns {Promise<{
92
- * method: string
93
- * url: URL
94
- * headers: Headers
95
- * body?: BodyInit | null
96
- * }>}
97
- */
98
- sign(): Promise<{
99
- method: any;
100
- url: URL;
101
- headers: Headers;
102
- body: any;
103
- }>;
104
- /**
105
- * @returns {Promise<string>}
106
- */
107
- authHeader(): Promise<string>;
108
- /**
109
- * @returns {Promise<string>}
110
- */
111
- signature(): Promise<string>;
112
- /**
113
- * @returns {Promise<string>}
114
- */
115
- stringToSign(): Promise<string>;
116
- /**
117
- * @returns {Promise<string>}
118
- */
119
- canonicalString(): Promise<string>;
120
- /**
121
- * @returns {Promise<string>}
122
- */
123
- hexBodyHash(): Promise<string>;
124
- }
125
- export {};