@mysten/signers 0.0.0-experimental-20241206200358

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 (44) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +201 -0
  3. package/README.md +75 -0
  4. package/aws/package.json +6 -0
  5. package/dist/cjs/aws/aws-client.d.ts +43 -0
  6. package/dist/cjs/aws/aws-client.js +92 -0
  7. package/dist/cjs/aws/aws-client.js.map +7 -0
  8. package/dist/cjs/aws/aws-kms-signer.d.ts +60 -0
  9. package/dist/cjs/aws/aws-kms-signer.js +144 -0
  10. package/dist/cjs/aws/aws-kms-signer.js.map +7 -0
  11. package/dist/cjs/aws/aws4fetch.d.ts +125 -0
  12. package/dist/cjs/aws/aws4fetch.js +382 -0
  13. package/dist/cjs/aws/aws4fetch.js.map +7 -0
  14. package/dist/cjs/aws/index.d.ts +5 -0
  15. package/dist/cjs/aws/index.js +25 -0
  16. package/dist/cjs/aws/index.js.map +7 -0
  17. package/dist/cjs/aws/utils.d.ts +16 -0
  18. package/dist/cjs/aws/utils.js +50 -0
  19. package/dist/cjs/aws/utils.js.map +7 -0
  20. package/dist/cjs/package.json +5 -0
  21. package/dist/esm/aws/aws-client.d.ts +43 -0
  22. package/dist/esm/aws/aws-client.js +72 -0
  23. package/dist/esm/aws/aws-client.js.map +7 -0
  24. package/dist/esm/aws/aws-kms-signer.d.ts +60 -0
  25. package/dist/esm/aws/aws-kms-signer.js +124 -0
  26. package/dist/esm/aws/aws-kms-signer.js.map +7 -0
  27. package/dist/esm/aws/aws4fetch.d.ts +125 -0
  28. package/dist/esm/aws/aws4fetch.js +362 -0
  29. package/dist/esm/aws/aws4fetch.js.map +7 -0
  30. package/dist/esm/aws/index.d.ts +5 -0
  31. package/dist/esm/aws/index.js +5 -0
  32. package/dist/esm/aws/index.js.map +7 -0
  33. package/dist/esm/aws/utils.d.ts +16 -0
  34. package/dist/esm/aws/utils.js +30 -0
  35. package/dist/esm/aws/utils.js.map +7 -0
  36. package/dist/esm/package.json +5 -0
  37. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -0
  39. package/package.json +58 -0
  40. package/src/aws/aws-client.ts +131 -0
  41. package/src/aws/aws-kms-signer.ts +147 -0
  42. package/src/aws/aws4fetch.ts +502 -0
  43. package/src/aws/index.ts +9 -0
  44. package/src/aws/utils.ts +65 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ # @mysten/signers
2
+
3
+ ## 0.0.0-experimental-20241206200358
4
+
5
+ ### Minor Changes
6
+
7
+ - e0885ca: renamed package to @mysten/signers and inlines aws4fetch
8
+
9
+ ## 0.0.10
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [ec2dc7f]
14
+ - Updated dependencies [ec2dc7f]
15
+ - @mysten/sui@1.16.0
16
+
17
+ ## 0.0.9
18
+
19
+ ### Patch Changes
20
+
21
+ - @mysten/sui@1.15.1
22
+
23
+ ## 0.0.8
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [6460e45]
28
+ - @mysten/sui@1.15.0
29
+
30
+ ## 0.0.7
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [938fb6e]
35
+ - @mysten/sui@1.14.4
36
+
37
+ ## 0.0.6
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [d5a23d7]
42
+ - @mysten/sui@1.14.3
43
+
44
+ ## 0.0.5
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [e7bc63e]
49
+ - @mysten/sui@1.14.2
50
+
51
+ ## 0.0.4
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [69ef100]
56
+ - @mysten/sui@1.14.1
57
+
58
+ ## 0.0.3
59
+
60
+ ### Patch Changes
61
+
62
+ - 02c9e46: Fix exports on the bundled package
63
+
64
+ ## 0.0.2
65
+
66
+ ### Patch Changes
67
+
68
+ - b3f3925: Introduces @mysten/kms which initially exposes a Sui AWS KMS signer
69
+ - Updated dependencies [c24814b]
70
+ - @mysten/sui@1.14.0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Sui KMS Signers
2
+
3
+ The Sui KMS Signers package provides a set of tools for securely signing transactions using Key
4
+ Management Services (KMS) like AWS KMS.
5
+
6
+ ## Table of Contents
7
+
8
+ - [AWS KMS Signer](#aws-kms-signer)
9
+ - [Usage](#usage)
10
+ - [API](#api)
11
+ - [fromKeyId](#fromkeyid)
12
+ - [Parameters](#parameters)
13
+ - [Examples](#examples)
14
+
15
+ ## AWS KMS Signer
16
+
17
+ The AWS KMS Signer allows you to leverage AWS's Key Management Service to sign Sui transactions.
18
+
19
+ ### Usage
20
+
21
+ ```typescript
22
+ import { AwsKmsSigner } from '@mysten/signers/aws';
23
+
24
+ const prepareSigner = async () => {
25
+ const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;
26
+
27
+ return AwsKmsSigner.fromKeyId(AWS_KMS_KEY_ID, {
28
+ region: AWS_REGION,
29
+ accessKeyId: AWS_ACCESS_KEY_ID,
30
+ secretAccessKey: AWS_SECRET_ACCESS_KEY,
31
+ });
32
+ };
33
+ ```
34
+
35
+ ### API
36
+
37
+ #### fromKeyId
38
+
39
+ Create an AWS KMS signer from AWS Key ID and AWS credentials. This method initializes the signer
40
+ with the necessary AWS credentials and region information, allowing it to interact with AWS KMS to
41
+ perform cryptographic operations.
42
+
43
+ ##### Parameters
44
+
45
+ - `keyId`
46
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
47
+ The AWS KMS key ID.
48
+ - `options`
49
+ **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An
50
+ object containing AWS credentials and region.
51
+ - `region`
52
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
53
+ The AWS region.
54
+ - `accessKeyId`
55
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
56
+ The AWS access key ID.
57
+ - `secretAccessKey`
58
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
59
+ The AWS secret access key.
60
+
61
+ ##### Examples
62
+
63
+ ```typescript
64
+ const signer = await AwsKmsSigner.fromKeyId('your-kms-key-id', {
65
+ region: 'us-west-2',
66
+ accessKeyId: 'your-access-key-id',
67
+ secretAccessKey: 'your-secret-access-key',
68
+ });
69
+ ```
70
+
71
+ Returns
72
+ **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[AwsKmsSigner](./src/aws/aws-kms-signer.ts)>**
73
+ An instance of AwsKmsSigner.
74
+
75
+ **Notice**: AWS Signer requires Node >=20 due to dependency on `crypto`
@@ -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 '@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 {};
@@ -0,0 +1,92 @@
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_asn1_ts = require("asn1-ts");
28
+ var import_aws4fetch = require("./aws4fetch.js");
29
+ var import_utils2 = require("./utils.js");
30
+ class AwsKmsClient extends import_aws4fetch.AwsClient {
31
+ constructor(options = {}) {
32
+ if (!options.accessKeyId || !options.secretAccessKey) {
33
+ throw new Error("AWS Access Key ID and Secret Access Key are required");
34
+ }
35
+ if (!options.region) {
36
+ throw new Error("Region is required");
37
+ }
38
+ super({
39
+ region: options.region,
40
+ accessKeyId: options.accessKeyId,
41
+ secretAccessKey: options.secretAccessKey,
42
+ service: "kms",
43
+ ...options
44
+ });
45
+ }
46
+ async getPublicKey(keyId) {
47
+ const publicKeyResponse = await this.runCommand("GetPublicKey", { KeyId: keyId });
48
+ if (!publicKeyResponse.PublicKey) {
49
+ throw new Error("Public Key not found for the supplied `keyId`");
50
+ }
51
+ const publicKey = (0, import_utils.fromBase64)(publicKeyResponse.PublicKey);
52
+ const encodedData = publicKey;
53
+ const derElement = new import_asn1_ts.DERElement();
54
+ derElement.fromBytes(encodedData);
55
+ if (!(derElement.tagClass === import_asn1_ts.ASN1TagClass.universal && derElement.construction === import_asn1_ts.ASN1Construction.constructed)) {
56
+ throw new Error("Unexpected ASN.1 structure");
57
+ }
58
+ const components = derElement.components;
59
+ const publicKeyElement = components[1];
60
+ if (!publicKeyElement) {
61
+ throw new Error("Public Key not found in the DER structure");
62
+ }
63
+ const compressedKey = (0, import_utils2.compressPublicKeyClamped)(publicKeyElement.bitString);
64
+ switch (publicKeyResponse.KeySpec) {
65
+ case "ECC_NIST_P256":
66
+ return new import_secp256r1.Secp256r1PublicKey(compressedKey);
67
+ case "ECC_SECG_P256K1":
68
+ return new import_secp256k1.Secp256k1PublicKey(compressedKey);
69
+ default:
70
+ throw new Error("Unsupported key spec: " + publicKeyResponse.KeySpec);
71
+ }
72
+ }
73
+ async runCommand(command, body, {
74
+ region = this.region
75
+ } = {}) {
76
+ if (!region) {
77
+ throw new Error("Region is required");
78
+ }
79
+ const res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {
80
+ headers: {
81
+ "Content-Type": "application/x-amz-json-1.1",
82
+ "X-Amz-Target": `TrentService.${command}`
83
+ },
84
+ body: JSON.stringify(body)
85
+ });
86
+ if (!res.ok) {
87
+ throw new Error(await res.text());
88
+ }
89
+ return res.json();
90
+ }
91
+ }
92
+ //# 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 '@mysten/sui/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\nimport { fromBase64 } from '@mysten/sui/utils';\nimport { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';\n\nimport { AwsClient } from './aws4fetch.js';\nimport { compressPublicKeyClamped } from './utils.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 publicKey = fromBase64(publicKeyResponse.PublicKey);\n\n\t\tconst encodedData: Uint8Array = publicKey;\n\t\tconst derElement = new DERElement();\n\t\tderElement.fromBytes(encodedData);\n\n\t\t// Validate the ASN.1 structure of the public key\n\t\tif (\n\t\t\t!(\n\t\t\t\tderElement.tagClass === ASN1TagClass.universal &&\n\t\t\t\tderElement.construction === ASN1Construction.constructed\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error('Unexpected ASN.1 structure');\n\t\t}\n\n\t\tconst components = derElement.components;\n\t\tconst publicKeyElement = components[1];\n\n\t\tif (!publicKeyElement) {\n\t\t\tthrow new Error('Public Key not found in the DER structure');\n\t\t}\n\n\t\tconst compressedKey = compressPublicKeyClamped(publicKeyElement.bitString);\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;AAC3B,qBAA2D;AAE3D,uBAA0B;AAC1B,IAAAA,gBAAyC;AAiClC,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,gBAAY,yBAAW,kBAAkB,SAAS;AAExD,UAAM,cAA0B;AAChC,UAAM,aAAa,IAAI,0BAAW;AAClC,eAAW,UAAU,WAAW;AAGhC,QACC,EACC,WAAW,aAAa,4BAAa,aACrC,WAAW,iBAAiB,gCAAiB,cAE7C;AACD,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC7C;AAEA,UAAM,aAAa,WAAW;AAC9B,UAAM,mBAAmB,WAAW,CAAC;AAErC,QAAI,CAAC,kBAAkB;AACtB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC5D;AAEA,UAAM,oBAAgB,wCAAyB,iBAAiB,SAAS;AAEzE,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
+ }
@@ -0,0 +1,60 @@
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(): "ED25519" | "Secp256k1" | "Secp256r1" | "MultiSig" | "ZkLogin";
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>;
49
+ /**
50
+ * Synchronous signing is not supported by AWS KMS.
51
+ * @throws Always throws an error indicating synchronous signing is unsupported.
52
+ */
53
+ signData(): never;
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
+ }