@haneullabs/signers 0.1.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 (88) hide show
  1. package/CHANGELOG.md +555 -0
  2. package/README.md +200 -0
  3. package/aws/package.json +6 -0
  4. package/dist/cjs/aws/aws-client.d.ts +43 -0
  5. package/dist/cjs/aws/aws-client.js +79 -0
  6. package/dist/cjs/aws/aws-client.js.map +7 -0
  7. package/dist/cjs/aws/aws-kms-signer.d.ts +61 -0
  8. package/dist/cjs/aws/aws-kms-signer.js +114 -0
  9. package/dist/cjs/aws/aws-kms-signer.js.map +7 -0
  10. package/dist/cjs/aws/aws4fetch.d.ts +125 -0
  11. package/dist/cjs/aws/aws4fetch.js +382 -0
  12. package/dist/cjs/aws/aws4fetch.js.map +7 -0
  13. package/dist/cjs/aws/index.d.ts +5 -0
  14. package/dist/cjs/aws/index.js +25 -0
  15. package/dist/cjs/aws/index.js.map +7 -0
  16. package/dist/cjs/gcp/gcp-kms-client.d.ts +68 -0
  17. package/dist/cjs/gcp/gcp-kms-client.js +147 -0
  18. package/dist/cjs/gcp/gcp-kms-client.js.map +7 -0
  19. package/dist/cjs/gcp/index.d.ts +4 -0
  20. package/dist/cjs/gcp/index.js +25 -0
  21. package/dist/cjs/gcp/index.js.map +7 -0
  22. package/dist/cjs/ledger/bcs.d.ts +14 -0
  23. package/dist/cjs/ledger/bcs.js +85 -0
  24. package/dist/cjs/ledger/bcs.js.map +7 -0
  25. package/dist/cjs/ledger/index.d.ts +66 -0
  26. package/dist/cjs/ledger/index.js +158 -0
  27. package/dist/cjs/ledger/index.js.map +7 -0
  28. package/dist/cjs/ledger/objects.d.ts +5 -0
  29. package/dist/cjs/ledger/objects.js +60 -0
  30. package/dist/cjs/ledger/objects.js.map +7 -0
  31. package/dist/cjs/package.json +5 -0
  32. package/dist/cjs/utils/utils.d.ts +18 -0
  33. package/dist/cjs/utils/utils.js +85 -0
  34. package/dist/cjs/utils/utils.js.map +7 -0
  35. package/dist/cjs/webcrypto/index.d.ts +26 -0
  36. package/dist/cjs/webcrypto/index.js +112 -0
  37. package/dist/cjs/webcrypto/index.js.map +7 -0
  38. package/dist/esm/aws/aws-client.d.ts +43 -0
  39. package/dist/esm/aws/aws-client.js +59 -0
  40. package/dist/esm/aws/aws-client.js.map +7 -0
  41. package/dist/esm/aws/aws-kms-signer.d.ts +61 -0
  42. package/dist/esm/aws/aws-kms-signer.js +94 -0
  43. package/dist/esm/aws/aws-kms-signer.js.map +7 -0
  44. package/dist/esm/aws/aws4fetch.d.ts +125 -0
  45. package/dist/esm/aws/aws4fetch.js +362 -0
  46. package/dist/esm/aws/aws4fetch.js.map +7 -0
  47. package/dist/esm/aws/index.d.ts +5 -0
  48. package/dist/esm/aws/index.js +5 -0
  49. package/dist/esm/aws/index.js.map +7 -0
  50. package/dist/esm/gcp/gcp-kms-client.d.ts +68 -0
  51. package/dist/esm/gcp/gcp-kms-client.js +127 -0
  52. package/dist/esm/gcp/gcp-kms-client.js.map +7 -0
  53. package/dist/esm/gcp/index.d.ts +4 -0
  54. package/dist/esm/gcp/index.js +5 -0
  55. package/dist/esm/gcp/index.js.map +7 -0
  56. package/dist/esm/ledger/bcs.d.ts +14 -0
  57. package/dist/esm/ledger/bcs.js +70 -0
  58. package/dist/esm/ledger/bcs.js.map +7 -0
  59. package/dist/esm/ledger/index.d.ts +66 -0
  60. package/dist/esm/ledger/index.js +138 -0
  61. package/dist/esm/ledger/index.js.map +7 -0
  62. package/dist/esm/ledger/objects.d.ts +5 -0
  63. package/dist/esm/ledger/objects.js +40 -0
  64. package/dist/esm/ledger/objects.js.map +7 -0
  65. package/dist/esm/package.json +5 -0
  66. package/dist/esm/utils/utils.d.ts +18 -0
  67. package/dist/esm/utils/utils.js +65 -0
  68. package/dist/esm/utils/utils.js.map +7 -0
  69. package/dist/esm/webcrypto/index.d.ts +26 -0
  70. package/dist/esm/webcrypto/index.js +92 -0
  71. package/dist/esm/webcrypto/index.js.map +7 -0
  72. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  73. package/dist/tsconfig.tsbuildinfo +1 -0
  74. package/gcp/package.json +6 -0
  75. package/ledger/package.json +6 -0
  76. package/package.json +76 -0
  77. package/src/aws/aws-client.ts +107 -0
  78. package/src/aws/aws-kms-signer.ts +111 -0
  79. package/src/aws/aws4fetch.ts +502 -0
  80. package/src/aws/index.ts +9 -0
  81. package/src/gcp/gcp-kms-client.ts +165 -0
  82. package/src/gcp/index.ts +9 -0
  83. package/src/ledger/bcs.ts +87 -0
  84. package/src/ledger/index.ts +164 -0
  85. package/src/ledger/objects.ts +56 -0
  86. package/src/utils/utils.ts +119 -0
  87. package/src/webcrypto/index.ts +108 -0
  88. package/webcrypto/package.json +6 -0
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # Haneul KMS Signers
2
+
3
+ The Haneul KMS Signers package provides a set of tools for securely signing transactions using Key
4
+ Management Services (KMS) like AWS KMS and GCP KMS.
5
+
6
+ ## Table of Contents
7
+
8
+ - [Haneul KMS Signers](#haneul-kms-signers)
9
+ - [Table of Contents](#table-of-contents)
10
+ - [AWS KMS Signer](#aws-kms-signer)
11
+ - [Usage](#usage)
12
+ - [API](#api)
13
+ - [fromKeyId](#fromkeyid)
14
+ - [Parameters](#parameters)
15
+ - [Examples](#examples)
16
+ - [GCP KMS Signer](#gcp-kms-signer)
17
+ - [Usage](#usage-1)
18
+ - [fromOptions](#fromoptions)
19
+ - [Parameters](#parameters-1)
20
+ - [Examples](#examples-1)
21
+ - [Ledger Signer](#ledger-signer)
22
+ - [Usage](#usage-2)
23
+ - [fromDerivationPath](#fromderivationpath)
24
+ - [Parameters](#parameters-2)
25
+ - [Examples](#examples-2)
26
+
27
+ ## AWS KMS Signer
28
+
29
+ The AWS KMS Signer allows you to leverage AWS's Key Management Service to sign Haneul transactions.
30
+
31
+ ### Usage
32
+
33
+ ```typescript
34
+ import { AwsKmsSigner } from '@haneullabs/signers/aws';
35
+
36
+ const prepareSigner = async () => {
37
+ const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;
38
+
39
+ return AwsKmsSigner.fromKeyId(AWS_KMS_KEY_ID, {
40
+ region: AWS_REGION,
41
+ accessKeyId: AWS_ACCESS_KEY_ID,
42
+ secretAccessKey: AWS_SECRET_ACCESS_KEY,
43
+ });
44
+ };
45
+ ```
46
+
47
+ ### API
48
+
49
+ #### fromKeyId
50
+
51
+ Create an AWS KMS signer from AWS Key ID and AWS credentials. This method initializes the signer
52
+ with the necessary AWS credentials and region information, allowing it to interact with AWS KMS to
53
+ perform cryptographic operations.
54
+
55
+ ##### Parameters
56
+
57
+ - `keyId`
58
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
59
+ The AWS KMS key ID.
60
+ - `options`
61
+ **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An
62
+ object containing AWS credentials and region.
63
+ - `region`
64
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
65
+ The AWS region.
66
+ - `accessKeyId`
67
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
68
+ The AWS access key ID.
69
+ - `secretAccessKey`
70
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
71
+ The AWS secret access key.
72
+
73
+ ##### Examples
74
+
75
+ ```typescript
76
+ const signer = await AwsKmsSigner.fromKeyId('your-kms-key-id', {
77
+ region: 'us-west-2',
78
+ accessKeyId: 'your-access-key-id',
79
+ secretAccessKey: 'your-secret-access-key',
80
+ });
81
+ ```
82
+
83
+ Returns
84
+ **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[AwsKmsSigner](https://github.com/GeunhwaJeong/haneul-ts-sdks/blob/main/packages/signers/src/aws/aws-kms-signer.ts)>**
85
+ An instance of AwsKmsSigner.
86
+
87
+ **Notice**: AWS Signer requires Node >=20 due to dependency on `crypto`
88
+
89
+ ## GCP KMS Signer
90
+
91
+ The GCP KMS Signer allows you to leverage Google Cloud's Key Management Service to sign Haneul
92
+ transactions.
93
+
94
+ ### Usage
95
+
96
+ #### fromOptions
97
+
98
+ Create a GCP KMS signer from the provided options. This method initializes the signer with the
99
+ necessary GCP credentials and configuration, allowing it to interact with GCP KMS to perform
100
+ cryptographic operations.
101
+
102
+ ##### Parameters
103
+
104
+ - `options`
105
+ **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An
106
+ object containing GCP credentials and configuration.
107
+ - `projectId`
108
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
109
+ The GCP project ID.
110
+ - `location`
111
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
112
+ The GCP location.
113
+ - `keyRing`
114
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
115
+ The GCP key ring.
116
+ - `cryptoKey`
117
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
118
+ The GCP crypto key.
119
+ - `cryptoKeyVersion`
120
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
121
+ The GCP crypto key version.
122
+
123
+ ##### Examples
124
+
125
+ ```typescript
126
+ const signer = await GcpKmsSigner.fromOptions({
127
+ projectId: 'your-google-project-id',
128
+ location: 'your-google-location',
129
+ keyRing: 'your-google-keyring',
130
+ cryptoKey: 'your-google-key-name',
131
+ cryptoKeyVersion: 'your-google-key-name-version',
132
+ });
133
+
134
+ // Retrieve the public key and get the Haneul address
135
+ const publicKey = signer.getPublicKey();
136
+ console.log(publicKey.toHaneulAddress());
137
+
138
+ // Define a test message
139
+ const testMessage = 'Hello, GCP KMS Signer!';
140
+ const messageBytes = new TextEncoder().encode(testMessage);
141
+
142
+ // Sign the test message
143
+ const { signature } = await signer.signPersonalMessage(messageBytes);
144
+
145
+ // Verify the signature against the public key
146
+ const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
147
+ console.log(isValid); // Should print true if the signature is valid
148
+ ```
149
+
150
+ ## Ledger Signer
151
+
152
+ The Ledger Signer allows you to leverage a Ledger hardware wallet to sign Haneul transactions.
153
+
154
+ ### Usage
155
+
156
+ #### fromDerivationPath
157
+
158
+ Creates a Ledger signer from the provided options. This method initializes the signer with the
159
+ necessary configuration, allowing it to interact with a Ledger hardare wallet to perform
160
+ cryptographic operations.
161
+
162
+ ##### Parameters
163
+
164
+ - `options`
165
+ **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An
166
+ object containing GCP credentials and configuration.
167
+ - `projectId`
168
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
169
+ The GCP project ID.
170
+
171
+ ##### Examples
172
+
173
+ ```typescript
174
+ import Transport from '@ledgerhq/hw-transport-node-hid';
175
+ import HaneulLedgerClient from '@haneullabs/ledgerjs-hw-app-haneul';
176
+ import { LedgerSigner } from '@haneullabs/signers/ledger';
177
+ import { getFullnodeUrl, HaneulClient } from '@haneullabs/haneul/client';
178
+ import { Transaction } from '@haneullabs/haneul/transactions';
179
+
180
+ const transport = await Transport.open(undefined);
181
+ const ledgerClient = new HaneulLedgerClient(transport);
182
+ const haneulClient = new HaneulClient({ url: getFullnodeUrl('testnet') });
183
+
184
+ const signer = await LedgerSigner.fromDerivationPath(
185
+ "m/44'/784'/0'/0'/0'",
186
+ ledgerClient,
187
+ haneulClient,
188
+ );
189
+
190
+ // Log the Haneul address:
191
+ console.log(signer.toHaneulAddress());
192
+
193
+ // Define a test transaction:
194
+ const testTransaction = new Transaction();
195
+ const transactionBytes = await testTransaction.build();
196
+
197
+ // Sign a test transaction:
198
+ const { signature } = await signer.signTransaction(transactionBytes);
199
+ console.log(signature);
200
+ ```
@@ -0,0 +1,6 @@
1
+ {
2
+ "private": true,
3
+ "import": "../dist/esm/aws/index.js",
4
+ "main": "../dist/cjs/aws/index.js",
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,43 @@
1
+ import { Secp256k1PublicKey } from '@haneullabs/haneul/keypairs/secp256k1';
2
+ import { Secp256r1PublicKey } from '@haneullabs/haneul/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 {};
@@ -0,0 +1,79 @@
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("@haneullabs/haneul/keypairs/secp256k1");
25
+ var import_secp256r1 = require("@haneullabs/haneul/keypairs/secp256r1");
26
+ var import_utils = require("@haneullabs/haneul/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
@@ -0,0 +1,7 @@
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 '@haneullabs/haneul/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';\nimport { fromBase64 } from '@haneullabs/haneul/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\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BAAmB;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
+ }
@@ -0,0 +1,61 @@
1
+ import type { PublicKey } from '@haneullabs/haneul/cryptography';
2
+ import { Signer } from '@haneullabs/haneul/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 Haneul 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
+ }
@@ -0,0 +1,114 @@
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("@haneullabs/haneul/cryptography");
32
+ var import_utils = require("@haneullabs/haneul/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
@@ -0,0 +1,7 @@
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 '@haneullabs/haneul/cryptography';\nimport { SIGNATURE_FLAG_TO_SCHEME, Signer } from '@haneullabs/haneul/cryptography';\nimport { fromBase64, toBase64 } from '@haneullabs/haneul/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 Haneul 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;AA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;
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 {};