@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.
- package/CHANGELOG.md +555 -0
- package/README.md +200 -0
- package/aws/package.json +6 -0
- package/dist/cjs/aws/aws-client.d.ts +43 -0
- package/dist/cjs/aws/aws-client.js +79 -0
- package/dist/cjs/aws/aws-client.js.map +7 -0
- package/dist/cjs/aws/aws-kms-signer.d.ts +61 -0
- package/dist/cjs/aws/aws-kms-signer.js +114 -0
- package/dist/cjs/aws/aws-kms-signer.js.map +7 -0
- package/dist/cjs/aws/aws4fetch.d.ts +125 -0
- package/dist/cjs/aws/aws4fetch.js +382 -0
- package/dist/cjs/aws/aws4fetch.js.map +7 -0
- package/dist/cjs/aws/index.d.ts +5 -0
- package/dist/cjs/aws/index.js +25 -0
- package/dist/cjs/aws/index.js.map +7 -0
- package/dist/cjs/gcp/gcp-kms-client.d.ts +68 -0
- package/dist/cjs/gcp/gcp-kms-client.js +147 -0
- package/dist/cjs/gcp/gcp-kms-client.js.map +7 -0
- package/dist/cjs/gcp/index.d.ts +4 -0
- package/dist/cjs/gcp/index.js +25 -0
- package/dist/cjs/gcp/index.js.map +7 -0
- package/dist/cjs/ledger/bcs.d.ts +14 -0
- package/dist/cjs/ledger/bcs.js +85 -0
- package/dist/cjs/ledger/bcs.js.map +7 -0
- package/dist/cjs/ledger/index.d.ts +66 -0
- package/dist/cjs/ledger/index.js +158 -0
- package/dist/cjs/ledger/index.js.map +7 -0
- package/dist/cjs/ledger/objects.d.ts +5 -0
- package/dist/cjs/ledger/objects.js +60 -0
- package/dist/cjs/ledger/objects.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/utils/utils.d.ts +18 -0
- package/dist/cjs/utils/utils.js +85 -0
- package/dist/cjs/utils/utils.js.map +7 -0
- package/dist/cjs/webcrypto/index.d.ts +26 -0
- package/dist/cjs/webcrypto/index.js +112 -0
- package/dist/cjs/webcrypto/index.js.map +7 -0
- package/dist/esm/aws/aws-client.d.ts +43 -0
- package/dist/esm/aws/aws-client.js +59 -0
- package/dist/esm/aws/aws-client.js.map +7 -0
- package/dist/esm/aws/aws-kms-signer.d.ts +61 -0
- package/dist/esm/aws/aws-kms-signer.js +94 -0
- package/dist/esm/aws/aws-kms-signer.js.map +7 -0
- package/dist/esm/aws/aws4fetch.d.ts +125 -0
- package/dist/esm/aws/aws4fetch.js +362 -0
- package/dist/esm/aws/aws4fetch.js.map +7 -0
- package/dist/esm/aws/index.d.ts +5 -0
- package/dist/esm/aws/index.js +5 -0
- package/dist/esm/aws/index.js.map +7 -0
- package/dist/esm/gcp/gcp-kms-client.d.ts +68 -0
- package/dist/esm/gcp/gcp-kms-client.js +127 -0
- package/dist/esm/gcp/gcp-kms-client.js.map +7 -0
- package/dist/esm/gcp/index.d.ts +4 -0
- package/dist/esm/gcp/index.js +5 -0
- package/dist/esm/gcp/index.js.map +7 -0
- package/dist/esm/ledger/bcs.d.ts +14 -0
- package/dist/esm/ledger/bcs.js +70 -0
- package/dist/esm/ledger/bcs.js.map +7 -0
- package/dist/esm/ledger/index.d.ts +66 -0
- package/dist/esm/ledger/index.js +138 -0
- package/dist/esm/ledger/index.js.map +7 -0
- package/dist/esm/ledger/objects.d.ts +5 -0
- package/dist/esm/ledger/objects.js +40 -0
- package/dist/esm/ledger/objects.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/utils/utils.d.ts +18 -0
- package/dist/esm/utils/utils.js +65 -0
- package/dist/esm/utils/utils.js.map +7 -0
- package/dist/esm/webcrypto/index.d.ts +26 -0
- package/dist/esm/webcrypto/index.js +92 -0
- package/dist/esm/webcrypto/index.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/gcp/package.json +6 -0
- package/ledger/package.json +6 -0
- package/package.json +76 -0
- package/src/aws/aws-client.ts +107 -0
- package/src/aws/aws-kms-signer.ts +111 -0
- package/src/aws/aws4fetch.ts +502 -0
- package/src/aws/index.ts +9 -0
- package/src/gcp/gcp-kms-client.ts +165 -0
- package/src/gcp/index.ts +9 -0
- package/src/ledger/bcs.ts +87 -0
- package/src/ledger/index.ts +164 -0
- package/src/ledger/objects.ts +56 -0
- package/src/utils/utils.ts +119 -0
- package/src/webcrypto/index.ts +108 -0
- package/webcrypto/package.json +6 -0
|
@@ -0,0 +1,382 @@
|
|
|
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 aws4fetch_exports = {};
|
|
20
|
+
__export(aws4fetch_exports, {
|
|
21
|
+
AwsClient: () => AwsClient,
|
|
22
|
+
AwsV4Signer: () => AwsV4Signer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(aws4fetch_exports);
|
|
25
|
+
/**
|
|
26
|
+
* Original implementation https://github.com/mhart/aws4fetch, inlined to reduce external dependencies
|
|
27
|
+
* @license MIT <https://opensource.org/licenses/MIT>
|
|
28
|
+
* @copyright Michael Hart 2024
|
|
29
|
+
*/
|
|
30
|
+
const encoder = new TextEncoder();
|
|
31
|
+
const HOST_SERVICES = {
|
|
32
|
+
appstream2: "appstream",
|
|
33
|
+
cloudhsmv2: "cloudhsm",
|
|
34
|
+
email: "ses",
|
|
35
|
+
marketplace: "aws-marketplace",
|
|
36
|
+
mobile: "AWSMobileHubService",
|
|
37
|
+
pinpoint: "mobiletargeting",
|
|
38
|
+
queue: "sqs",
|
|
39
|
+
"git-codecommit": "codecommit",
|
|
40
|
+
"mturk-requester-sandbox": "mturk-requester",
|
|
41
|
+
"personalize-runtime": "personalize"
|
|
42
|
+
};
|
|
43
|
+
const UNSIGNABLE_HEADERS = /* @__PURE__ */ new Set([
|
|
44
|
+
"authorization",
|
|
45
|
+
"content-type",
|
|
46
|
+
"content-length",
|
|
47
|
+
"user-agent",
|
|
48
|
+
"presigned-expires",
|
|
49
|
+
"expect",
|
|
50
|
+
"x-amzn-trace-id",
|
|
51
|
+
"range",
|
|
52
|
+
"connection"
|
|
53
|
+
]);
|
|
54
|
+
class AwsClient {
|
|
55
|
+
/**
|
|
56
|
+
* @param {} options
|
|
57
|
+
*/
|
|
58
|
+
constructor({
|
|
59
|
+
accessKeyId,
|
|
60
|
+
secretAccessKey,
|
|
61
|
+
sessionToken,
|
|
62
|
+
service,
|
|
63
|
+
region,
|
|
64
|
+
cache,
|
|
65
|
+
retries,
|
|
66
|
+
initRetryMs
|
|
67
|
+
}) {
|
|
68
|
+
if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
|
|
69
|
+
if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
|
|
70
|
+
this.accessKeyId = accessKeyId;
|
|
71
|
+
this.secretAccessKey = secretAccessKey;
|
|
72
|
+
this.sessionToken = sessionToken;
|
|
73
|
+
this.service = service;
|
|
74
|
+
this.region = region;
|
|
75
|
+
this.cache = cache || /* @__PURE__ */ new Map();
|
|
76
|
+
this.retries = retries != null ? retries : 10;
|
|
77
|
+
this.initRetryMs = initRetryMs || 50;
|
|
78
|
+
}
|
|
79
|
+
async sign(input, init) {
|
|
80
|
+
if (input instanceof Request) {
|
|
81
|
+
const { method, url, headers, body } = input;
|
|
82
|
+
init = Object.assign({ method, url, headers }, init);
|
|
83
|
+
if (init.body == null && headers.has("Content-Type")) {
|
|
84
|
+
init.body = body != null && headers.has("X-Amz-Content-Sha256") ? body : await input.clone().arrayBuffer();
|
|
85
|
+
}
|
|
86
|
+
input = url;
|
|
87
|
+
}
|
|
88
|
+
const signer = new AwsV4Signer(
|
|
89
|
+
Object.assign({ url: input.toString() }, init, this, init && init.aws)
|
|
90
|
+
);
|
|
91
|
+
const signed = Object.assign({}, init, await signer.sign());
|
|
92
|
+
delete signed.aws;
|
|
93
|
+
try {
|
|
94
|
+
return new Request(signed.url.toString(), signed);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
if (e instanceof TypeError) {
|
|
97
|
+
return new Request(signed.url.toString(), Object.assign({ duplex: "half" }, signed));
|
|
98
|
+
}
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @param {Request | { toString: () => string }} input
|
|
104
|
+
* @param {?AwsRequestInit} [init]
|
|
105
|
+
* @returns {Promise<Response>}
|
|
106
|
+
*/
|
|
107
|
+
async fetch(input, init) {
|
|
108
|
+
for (let i = 0; i <= this.retries; i++) {
|
|
109
|
+
const fetched = fetch(await this.sign(input, init));
|
|
110
|
+
if (i === this.retries) {
|
|
111
|
+
return fetched;
|
|
112
|
+
}
|
|
113
|
+
const res = await fetched;
|
|
114
|
+
if (res.status < 500 && res.status !== 429) {
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
await new Promise(
|
|
118
|
+
(resolve) => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
throw new Error("An unknown error occurred, ensure retries is not negative");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
class AwsV4Signer {
|
|
125
|
+
/**
|
|
126
|
+
* @param {} options
|
|
127
|
+
*/
|
|
128
|
+
constructor({
|
|
129
|
+
method,
|
|
130
|
+
url,
|
|
131
|
+
headers,
|
|
132
|
+
body,
|
|
133
|
+
accessKeyId,
|
|
134
|
+
secretAccessKey,
|
|
135
|
+
sessionToken,
|
|
136
|
+
service,
|
|
137
|
+
region,
|
|
138
|
+
cache,
|
|
139
|
+
datetime,
|
|
140
|
+
signQuery,
|
|
141
|
+
appendSessionToken,
|
|
142
|
+
allHeaders,
|
|
143
|
+
singleEncode
|
|
144
|
+
}) {
|
|
145
|
+
if (url == null) throw new TypeError("url is a required option");
|
|
146
|
+
if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
|
|
147
|
+
if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
|
|
148
|
+
this.method = method || (body ? "POST" : "GET");
|
|
149
|
+
this.url = new URL(url);
|
|
150
|
+
this.headers = new Headers(headers || {});
|
|
151
|
+
this.body = body;
|
|
152
|
+
this.accessKeyId = accessKeyId;
|
|
153
|
+
this.secretAccessKey = secretAccessKey;
|
|
154
|
+
this.sessionToken = sessionToken;
|
|
155
|
+
let guessedService, guessedRegion;
|
|
156
|
+
if (!service || !region) {
|
|
157
|
+
[guessedService, guessedRegion] = guessServiceRegion(this.url, this.headers);
|
|
158
|
+
}
|
|
159
|
+
this.service = service || guessedService || "";
|
|
160
|
+
this.region = region || guessedRegion || "us-east-1";
|
|
161
|
+
this.cache = cache || /* @__PURE__ */ new Map();
|
|
162
|
+
this.datetime = datetime || (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
163
|
+
this.signQuery = signQuery;
|
|
164
|
+
this.appendSessionToken = appendSessionToken || this.service === "iotdevicegateway";
|
|
165
|
+
this.headers.delete("Host");
|
|
166
|
+
if (this.service === "s3" && !this.signQuery && !this.headers.has("X-Amz-Content-Sha256")) {
|
|
167
|
+
this.headers.set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD");
|
|
168
|
+
}
|
|
169
|
+
const params = this.signQuery ? this.url.searchParams : this.headers;
|
|
170
|
+
params.set("X-Amz-Date", this.datetime);
|
|
171
|
+
if (this.sessionToken && !this.appendSessionToken) {
|
|
172
|
+
params.set("X-Amz-Security-Token", this.sessionToken);
|
|
173
|
+
}
|
|
174
|
+
this.signableHeaders = ["host", ...this.headers.keys()].filter((header) => allHeaders || !UNSIGNABLE_HEADERS.has(header)).sort();
|
|
175
|
+
this.signedHeaders = this.signableHeaders.join(";");
|
|
176
|
+
this.canonicalHeaders = this.signableHeaders.map(
|
|
177
|
+
(header) => header + ":" + (header === "host" ? this.url.host : (this.headers.get(header) || "").replace(/\s+/g, " "))
|
|
178
|
+
).join("\n");
|
|
179
|
+
this.credentialString = [
|
|
180
|
+
this.datetime.slice(0, 8),
|
|
181
|
+
this.region,
|
|
182
|
+
this.service,
|
|
183
|
+
"aws4_request"
|
|
184
|
+
].join("/");
|
|
185
|
+
if (this.signQuery) {
|
|
186
|
+
if (this.service === "s3" && !params.has("X-Amz-Expires")) {
|
|
187
|
+
params.set("X-Amz-Expires", "86400");
|
|
188
|
+
}
|
|
189
|
+
params.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256");
|
|
190
|
+
params.set("X-Amz-Credential", this.accessKeyId + "/" + this.credentialString);
|
|
191
|
+
params.set("X-Amz-SignedHeaders", this.signedHeaders);
|
|
192
|
+
}
|
|
193
|
+
if (this.service === "s3") {
|
|
194
|
+
try {
|
|
195
|
+
this.encodedPath = decodeURIComponent(this.url.pathname.replace(/\+/g, " "));
|
|
196
|
+
} catch {
|
|
197
|
+
this.encodedPath = this.url.pathname;
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
this.encodedPath = this.url.pathname.replace(/\/+/g, "/");
|
|
201
|
+
}
|
|
202
|
+
if (!singleEncode) {
|
|
203
|
+
this.encodedPath = encodeURIComponent(this.encodedPath).replace(/%2F/g, "/");
|
|
204
|
+
}
|
|
205
|
+
this.encodedPath = encodeRfc3986(this.encodedPath);
|
|
206
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
207
|
+
this.encodedSearch = [...this.url.searchParams].filter(([k]) => {
|
|
208
|
+
if (!k) return false;
|
|
209
|
+
if (this.service === "s3") {
|
|
210
|
+
if (seenKeys.has(k)) return false;
|
|
211
|
+
seenKeys.add(k);
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}).map((pair) => pair.map((p) => encodeRfc3986(encodeURIComponent(p)))).sort(([k1, v1], [k2, v2]) => k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0).map((pair) => pair.join("=")).join("&");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @returns {Promise<{
|
|
218
|
+
* method: string
|
|
219
|
+
* url: URL
|
|
220
|
+
* headers: Headers
|
|
221
|
+
* body?: BodyInit | null
|
|
222
|
+
* }>}
|
|
223
|
+
*/
|
|
224
|
+
async sign() {
|
|
225
|
+
if (this.signQuery) {
|
|
226
|
+
this.url.searchParams.set("X-Amz-Signature", await this.signature());
|
|
227
|
+
if (this.sessionToken && this.appendSessionToken) {
|
|
228
|
+
this.url.searchParams.set("X-Amz-Security-Token", this.sessionToken);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
this.headers.set("Authorization", await this.authHeader());
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
method: this.method,
|
|
235
|
+
url: this.url,
|
|
236
|
+
headers: this.headers,
|
|
237
|
+
body: this.body
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @returns {Promise<string>}
|
|
242
|
+
*/
|
|
243
|
+
async authHeader() {
|
|
244
|
+
return [
|
|
245
|
+
"AWS4-HMAC-SHA256 Credential=" + this.accessKeyId + "/" + this.credentialString,
|
|
246
|
+
"SignedHeaders=" + this.signedHeaders,
|
|
247
|
+
"Signature=" + await this.signature()
|
|
248
|
+
].join(", ");
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @returns {Promise<string>}
|
|
252
|
+
*/
|
|
253
|
+
async signature() {
|
|
254
|
+
const date = this.datetime.slice(0, 8);
|
|
255
|
+
const cacheKey = [this.secretAccessKey, date, this.region, this.service].join();
|
|
256
|
+
let kCredentials = this.cache.get(cacheKey);
|
|
257
|
+
if (!kCredentials) {
|
|
258
|
+
const kDate = await hmac("AWS4" + this.secretAccessKey, date);
|
|
259
|
+
const kRegion = await hmac(kDate, this.region);
|
|
260
|
+
const kService = await hmac(kRegion, this.service);
|
|
261
|
+
kCredentials = await hmac(kService, "aws4_request");
|
|
262
|
+
this.cache.set(cacheKey, kCredentials);
|
|
263
|
+
}
|
|
264
|
+
return buf2hex(await hmac(kCredentials, await this.stringToSign()));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @returns {Promise<string>}
|
|
268
|
+
*/
|
|
269
|
+
async stringToSign() {
|
|
270
|
+
return [
|
|
271
|
+
"AWS4-HMAC-SHA256",
|
|
272
|
+
this.datetime,
|
|
273
|
+
this.credentialString,
|
|
274
|
+
buf2hex(await hash(await this.canonicalString()))
|
|
275
|
+
].join("\n");
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @returns {Promise<string>}
|
|
279
|
+
*/
|
|
280
|
+
async canonicalString() {
|
|
281
|
+
return [
|
|
282
|
+
this.method.toUpperCase(),
|
|
283
|
+
this.encodedPath,
|
|
284
|
+
this.encodedSearch,
|
|
285
|
+
this.canonicalHeaders + "\n",
|
|
286
|
+
this.signedHeaders,
|
|
287
|
+
await this.hexBodyHash()
|
|
288
|
+
].join("\n");
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @returns {Promise<string>}
|
|
292
|
+
*/
|
|
293
|
+
async hexBodyHash() {
|
|
294
|
+
let hashHeader = this.headers.get("X-Amz-Content-Sha256") || (this.service === "s3" && this.signQuery ? "UNSIGNED-PAYLOAD" : null);
|
|
295
|
+
if (hashHeader == null) {
|
|
296
|
+
if (this.body && typeof this.body !== "string" && !("byteLength" in this.body)) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
"body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
hashHeader = buf2hex(await hash(this.body || ""));
|
|
302
|
+
}
|
|
303
|
+
return hashHeader;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async function hmac(key, string) {
|
|
307
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
308
|
+
"raw",
|
|
309
|
+
typeof key === "string" ? encoder.encode(key) : key,
|
|
310
|
+
{ name: "HMAC", hash: { name: "SHA-256" } },
|
|
311
|
+
false,
|
|
312
|
+
["sign"]
|
|
313
|
+
);
|
|
314
|
+
return crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(string));
|
|
315
|
+
}
|
|
316
|
+
async function hash(content) {
|
|
317
|
+
return crypto.subtle.digest(
|
|
318
|
+
"SHA-256",
|
|
319
|
+
typeof content === "string" ? encoder.encode(content) : content
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const HEX_CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
|
|
323
|
+
function buf2hex(arrayBuffer) {
|
|
324
|
+
const buffer = new Uint8Array(arrayBuffer);
|
|
325
|
+
let out = "";
|
|
326
|
+
for (let idx = 0; idx < buffer.length; idx++) {
|
|
327
|
+
const n = buffer[idx];
|
|
328
|
+
out += HEX_CHARS[n >>> 4 & 15];
|
|
329
|
+
out += HEX_CHARS[n & 15];
|
|
330
|
+
}
|
|
331
|
+
return out;
|
|
332
|
+
}
|
|
333
|
+
function encodeRfc3986(urlEncodedStr) {
|
|
334
|
+
return urlEncodedStr.replace(/[!'()*]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase());
|
|
335
|
+
}
|
|
336
|
+
function guessServiceRegion(url, headers) {
|
|
337
|
+
const { hostname, pathname } = url;
|
|
338
|
+
if (hostname.endsWith(".on.aws")) {
|
|
339
|
+
const match2 = hostname.match(/^[^.]{1,63}\.lambda-url\.([^.]{1,63})\.on\.aws$/);
|
|
340
|
+
return match2 != null ? ["lambda", match2[1] || ""] : ["", ""];
|
|
341
|
+
}
|
|
342
|
+
if (hostname.endsWith(".r2.cloudflarestorage.com")) {
|
|
343
|
+
return ["s3", "auto"];
|
|
344
|
+
}
|
|
345
|
+
if (hostname.endsWith(".backblazeb2.com")) {
|
|
346
|
+
const match2 = hostname.match(/^(?:[^.]{1,63}\.)?s3\.([^.]{1,63})\.backblazeb2\.com$/);
|
|
347
|
+
return match2 != null ? ["s3", match2[1] || ""] : ["", ""];
|
|
348
|
+
}
|
|
349
|
+
const match = hostname.replace("dualstack.", "").match(/([^.]{1,63})\.(?:([^.]{0,63})\.)?amazonaws\.com(?:\.cn)?$/);
|
|
350
|
+
let service = match && match[1] || "";
|
|
351
|
+
let region = match && match[2];
|
|
352
|
+
if (region === "us-gov") {
|
|
353
|
+
region = "us-gov-west-1";
|
|
354
|
+
} else if (region === "s3" || region === "s3-accelerate") {
|
|
355
|
+
region = "us-east-1";
|
|
356
|
+
service = "s3";
|
|
357
|
+
} else if (service === "iot") {
|
|
358
|
+
if (hostname.startsWith("iot.")) {
|
|
359
|
+
service = "execute-api";
|
|
360
|
+
} else if (hostname.startsWith("data.jobs.iot.")) {
|
|
361
|
+
service = "iot-jobs-data";
|
|
362
|
+
} else {
|
|
363
|
+
service = pathname === "/mqtt" ? "iotdevicegateway" : "iotdata";
|
|
364
|
+
}
|
|
365
|
+
} else if (service === "autoscaling") {
|
|
366
|
+
const targetPrefix = (headers.get("X-Amz-Target") || "").split(".")[0];
|
|
367
|
+
if (targetPrefix === "AnyScaleFrontendService") {
|
|
368
|
+
service = "application-autoscaling";
|
|
369
|
+
} else if (targetPrefix === "AnyScaleScalingPlannerFrontendService") {
|
|
370
|
+
service = "autoscaling-plans";
|
|
371
|
+
}
|
|
372
|
+
} else if (region == null && service.startsWith("s3-")) {
|
|
373
|
+
region = service.slice(3).replace(/^fips-|^external-1/, "");
|
|
374
|
+
service = "s3";
|
|
375
|
+
} else if (service.endsWith("-fips")) {
|
|
376
|
+
service = service.slice(0, -5);
|
|
377
|
+
} else if (region && /-\d$/.test(service) && !/-\d$/.test(region)) {
|
|
378
|
+
[service, region] = [region, service];
|
|
379
|
+
}
|
|
380
|
+
return [HOST_SERVICES[service] || service, region || ""];
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=aws4fetch.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/aws/aws4fetch.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Original implementation https://github.com/mhart/aws4fetch, inlined to reduce external dependencies\n * @license MIT <https://opensource.org/licenses/MIT>\n * @copyright Michael Hart 2024\n */\n\nconst encoder = new TextEncoder();\n\n/** @type {Record<string, string>} */\nconst HOST_SERVICES: Record<string, string> = {\n\tappstream2: 'appstream',\n\tcloudhsmv2: 'cloudhsm',\n\temail: 'ses',\n\tmarketplace: 'aws-marketplace',\n\tmobile: 'AWSMobileHubService',\n\tpinpoint: 'mobiletargeting',\n\tqueue: 'sqs',\n\t'git-codecommit': 'codecommit',\n\t'mturk-requester-sandbox': 'mturk-requester',\n\t'personalize-runtime': 'personalize',\n};\n\n// https://github.com/aws/aws-sdk-js/blob/cc29728c1c4178969ebabe3bbe6b6f3159436394/lib/signers/v4.js#L190-L198\nconst UNSIGNABLE_HEADERS = new Set([\n\t'authorization',\n\t'content-type',\n\t'content-length',\n\t'user-agent',\n\t'presigned-expires',\n\t'expect',\n\t'x-amzn-trace-id',\n\t'range',\n\t'connection',\n]);\n\ntype AwsRequestInit = RequestInit & {\n\taws?: {\n\t\taccessKeyId?: string;\n\t\tsecretAccessKey?: string;\n\t\tsessionToken?: string;\n\t\tservice?: string;\n\t\tregion?: string;\n\t\tcache?: Map<string, ArrayBuffer>;\n\t\tdatetime?: string;\n\t\tsignQuery?: boolean;\n\t\tappendSessionToken?: boolean;\n\t\tallHeaders?: boolean;\n\t\tsingleEncode?: boolean;\n\t};\n};\n\nexport class AwsClient {\n\taccessKeyId: string;\n\tsecretAccessKey: string;\n\tsessionToken: string | undefined;\n\tservice: string | undefined;\n\tregion: string | undefined;\n\tcache: Map<any, any>;\n\tretries: number;\n\tinitRetryMs: number;\n\t/**\n\t * @param {} options\n\t */\n\tconstructor({\n\t\taccessKeyId,\n\t\tsecretAccessKey,\n\t\tsessionToken,\n\t\tservice,\n\t\tregion,\n\t\tcache,\n\t\tretries,\n\t\tinitRetryMs,\n\t}: {\n\t\taccessKeyId: string;\n\t\tsecretAccessKey: string;\n\t\tsessionToken?: string;\n\t\tservice?: string;\n\t\tregion?: string;\n\t\tcache?: Map<string, ArrayBuffer>;\n\t\tretries?: number;\n\t\tinitRetryMs?: number;\n\t}) {\n\t\tif (accessKeyId == null) throw new TypeError('accessKeyId is a required option');\n\t\tif (secretAccessKey == null) throw new TypeError('secretAccessKey is a required option');\n\t\tthis.accessKeyId = accessKeyId;\n\t\tthis.secretAccessKey = secretAccessKey;\n\t\tthis.sessionToken = sessionToken;\n\t\tthis.service = service;\n\t\tthis.region = region;\n\t\t/** @type {Map<string, ArrayBuffer>} */\n\t\tthis.cache = cache || new Map();\n\t\tthis.retries = retries != null ? retries : 10; // Up to 25.6 secs\n\t\tthis.initRetryMs = initRetryMs || 50;\n\t}\n\n\tasync sign(input: Request | { toString: () => string }, init: AwsRequestInit): Promise<Request> {\n\t\tif (input instanceof Request) {\n\t\t\tconst { method, url, headers, body } = input;\n\t\t\tinit = Object.assign({ method, url, headers }, init);\n\t\t\tif (init.body == null && headers.has('Content-Type')) {\n\t\t\t\tinit.body =\n\t\t\t\t\tbody != null && headers.has('X-Amz-Content-Sha256')\n\t\t\t\t\t\t? body\n\t\t\t\t\t\t: await input.clone().arrayBuffer();\n\t\t\t}\n\t\t\tinput = url;\n\t\t}\n\t\tconst signer = new AwsV4Signer(\n\t\t\tObject.assign({ url: input.toString() }, init, this, init && init.aws),\n\t\t);\n\t\tconst signed = Object.assign({}, init, await signer.sign());\n\t\tdelete signed.aws;\n\t\ttry {\n\t\t\treturn new Request(signed.url.toString(), signed);\n\t\t} catch (e) {\n\t\t\tif (e instanceof TypeError) {\n\t\t\t\t// https://bugs.chromium.org/p/chromium/issues/detail?id=1360943\n\t\t\t\treturn new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed));\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t/**\n\t * @param {Request | { toString: () => string }} input\n\t * @param {?AwsRequestInit} [init]\n\t * @returns {Promise<Response>}\n\t */\n\tasync fetch(input: Request | { toString: () => string }, init: AwsRequestInit) {\n\t\tfor (let i = 0; i <= this.retries; i++) {\n\t\t\tconst fetched = fetch(await this.sign(input, init));\n\t\t\tif (i === this.retries) {\n\t\t\t\treturn fetched; // No need to await if we're returning anyway\n\t\t\t}\n\t\t\tconst res = await fetched;\n\t\t\tif (res.status < 500 && res.status !== 429) {\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i)),\n\t\t\t);\n\t\t}\n\t\tthrow new Error('An unknown error occurred, ensure retries is not negative');\n\t}\n}\n\nexport class AwsV4Signer {\n\tmethod: any;\n\turl: URL;\n\theaders: Headers;\n\tbody: any;\n\taccessKeyId: any;\n\tsecretAccessKey: any;\n\tsessionToken: any;\n\tservice: any;\n\tregion: any;\n\tcache: any;\n\tdatetime: any;\n\tsignQuery: any;\n\tappendSessionToken: any;\n\tsignableHeaders: any[];\n\tsignedHeaders: any;\n\tcanonicalHeaders: any;\n\tcredentialString: string;\n\tencodedPath: string;\n\tencodedSearch: string;\n\t/**\n\t * @param {} options\n\t */\n\tconstructor({\n\t\tmethod,\n\t\turl,\n\t\theaders,\n\t\tbody,\n\t\taccessKeyId,\n\t\tsecretAccessKey,\n\t\tsessionToken,\n\t\tservice,\n\t\tregion,\n\t\tcache,\n\t\tdatetime,\n\t\tsignQuery,\n\t\tappendSessionToken,\n\t\tallHeaders,\n\t\tsingleEncode,\n\t}: {\n\t\tmethod?: string;\n\t\turl: string;\n\t\theaders?: HeadersInit;\n\t\tbody?: BodyInit | null;\n\t\taccessKeyId: string;\n\t\tsecretAccessKey: string;\n\t\tsessionToken?: string;\n\t\tservice?: string;\n\t\tregion?: string;\n\t\tcache?: Map<string, ArrayBuffer>;\n\t\tdatetime?: string;\n\t\tsignQuery?: boolean;\n\t\tappendSessionToken?: boolean;\n\t\tallHeaders?: boolean;\n\t\tsingleEncode?: boolean;\n\t}) {\n\t\tif (url == null) throw new TypeError('url is a required option');\n\t\tif (accessKeyId == null) throw new TypeError('accessKeyId is a required option');\n\t\tif (secretAccessKey == null) throw new TypeError('secretAccessKey is a required option');\n\n\t\tthis.method = method || (body ? 'POST' : 'GET');\n\t\tthis.url = new URL(url);\n\t\tthis.headers = new Headers(headers || {});\n\t\tthis.body = body;\n\n\t\tthis.accessKeyId = accessKeyId;\n\t\tthis.secretAccessKey = secretAccessKey;\n\t\tthis.sessionToken = sessionToken;\n\n\t\tlet guessedService, guessedRegion;\n\t\tif (!service || !region) {\n\t\t\t[guessedService, guessedRegion] = guessServiceRegion(this.url, this.headers);\n\t\t}\n\t\tthis.service = service || guessedService || '';\n\t\tthis.region = region || guessedRegion || 'us-east-1';\n\n\t\t/** @type {Map<string, ArrayBuffer>} */\n\t\tthis.cache = cache || new Map();\n\t\tthis.datetime = datetime || new Date().toISOString().replace(/[:-]|\\.\\d{3}/g, '');\n\t\tthis.signQuery = signQuery;\n\t\tthis.appendSessionToken = appendSessionToken || this.service === 'iotdevicegateway';\n\n\t\tthis.headers.delete('Host'); // Can't be set in insecure env anyway\n\n\t\tif (this.service === 's3' && !this.signQuery && !this.headers.has('X-Amz-Content-Sha256')) {\n\t\t\tthis.headers.set('X-Amz-Content-Sha256', 'UNSIGNED-PAYLOAD');\n\t\t}\n\n\t\tconst params = this.signQuery ? this.url.searchParams : this.headers;\n\n\t\tparams.set('X-Amz-Date', this.datetime);\n\t\tif (this.sessionToken && !this.appendSessionToken) {\n\t\t\tparams.set('X-Amz-Security-Token', this.sessionToken);\n\t\t}\n\n\t\t// headers are always lowercase in keys()\n\n\t\tthis.signableHeaders = ['host', ...((this.headers as any).keys() as string[])]\n\t\t\t.filter((header) => allHeaders || !UNSIGNABLE_HEADERS.has(header))\n\t\t\t.sort();\n\n\t\tthis.signedHeaders = this.signableHeaders.join(';');\n\n\t\t// headers are always trimmed:\n\t\t// https://fetch.spec.whatwg.org/#concept-header-value-normalize\n\t\tthis.canonicalHeaders = this.signableHeaders\n\t\t\t.map(\n\t\t\t\t(header) =>\n\t\t\t\t\theader +\n\t\t\t\t\t':' +\n\t\t\t\t\t(header === 'host'\n\t\t\t\t\t\t? this.url.host\n\t\t\t\t\t\t: (this.headers.get(header) || '').replace(/\\s+/g, ' ')),\n\t\t\t)\n\t\t\t.join('\\n');\n\n\t\tthis.credentialString = [\n\t\t\tthis.datetime.slice(0, 8),\n\t\t\tthis.region,\n\t\t\tthis.service,\n\t\t\t'aws4_request',\n\t\t].join('/');\n\n\t\tif (this.signQuery) {\n\t\t\tif (this.service === 's3' && !params.has('X-Amz-Expires')) {\n\t\t\t\tparams.set('X-Amz-Expires', '86400'); // 24 hours\n\t\t\t}\n\t\t\tparams.set('X-Amz-Algorithm', 'AWS4-HMAC-SHA256');\n\t\t\tparams.set('X-Amz-Credential', this.accessKeyId + '/' + this.credentialString);\n\t\t\tparams.set('X-Amz-SignedHeaders', this.signedHeaders);\n\t\t}\n\n\t\tif (this.service === 's3') {\n\t\t\ttry {\n\t\t\t\tthis.encodedPath = decodeURIComponent(this.url.pathname.replace(/\\+/g, ' '));\n\t\t\t} catch {\n\t\t\t\tthis.encodedPath = this.url.pathname;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.encodedPath = this.url.pathname.replace(/\\/+/g, '/');\n\t\t}\n\t\tif (!singleEncode) {\n\t\t\tthis.encodedPath = encodeURIComponent(this.encodedPath).replace(/%2F/g, '/');\n\t\t}\n\t\tthis.encodedPath = encodeRfc3986(this.encodedPath);\n\n\t\tconst seenKeys = new Set();\n\t\tthis.encodedSearch = [...this.url.searchParams]\n\t\t\t.filter(([k]) => {\n\t\t\t\tif (!k) return false; // no empty keys\n\t\t\t\tif (this.service === 's3') {\n\t\t\t\t\tif (seenKeys.has(k)) return false; // first val only for S3\n\t\t\t\t\tseenKeys.add(k);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t})\n\t\t\t.map((pair) => pair.map((p) => encodeRfc3986(encodeURIComponent(p))))\n\t\t\t.sort(([k1, v1], [k2, v2]) => (k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0))\n\t\t\t.map((pair) => pair.join('='))\n\t\t\t.join('&');\n\t}\n\n\t/**\n\t * @returns {Promise<{\n\t * method: string\n\t * url: URL\n\t * headers: Headers\n\t * body?: BodyInit | null\n\t * }>}\n\t */\n\tasync sign() {\n\t\tif (this.signQuery) {\n\t\t\tthis.url.searchParams.set('X-Amz-Signature', await this.signature());\n\t\t\tif (this.sessionToken && this.appendSessionToken) {\n\t\t\t\tthis.url.searchParams.set('X-Amz-Security-Token', this.sessionToken);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.headers.set('Authorization', await this.authHeader());\n\t\t}\n\n\t\treturn {\n\t\t\tmethod: this.method,\n\t\t\turl: this.url,\n\t\t\theaders: this.headers,\n\t\t\tbody: this.body,\n\t\t};\n\t}\n\n\t/**\n\t * @returns {Promise<string>}\n\t */\n\tasync authHeader() {\n\t\treturn [\n\t\t\t'AWS4-HMAC-SHA256 Credential=' + this.accessKeyId + '/' + this.credentialString,\n\t\t\t'SignedHeaders=' + this.signedHeaders,\n\t\t\t'Signature=' + (await this.signature()),\n\t\t].join(', ');\n\t}\n\n\t/**\n\t * @returns {Promise<string>}\n\t */\n\tasync signature() {\n\t\tconst date = this.datetime.slice(0, 8);\n\t\tconst cacheKey = [this.secretAccessKey, date, this.region, this.service].join();\n\t\tlet kCredentials = this.cache.get(cacheKey);\n\t\tif (!kCredentials) {\n\t\t\tconst kDate = await hmac('AWS4' + this.secretAccessKey, date);\n\t\t\tconst kRegion = await hmac(kDate, this.region);\n\t\t\tconst kService = await hmac(kRegion, this.service);\n\t\t\tkCredentials = await hmac(kService, 'aws4_request');\n\t\t\tthis.cache.set(cacheKey, kCredentials);\n\t\t}\n\t\treturn buf2hex(await hmac(kCredentials, await this.stringToSign()));\n\t}\n\n\t/**\n\t * @returns {Promise<string>}\n\t */\n\tasync stringToSign() {\n\t\treturn [\n\t\t\t'AWS4-HMAC-SHA256',\n\t\t\tthis.datetime,\n\t\t\tthis.credentialString,\n\t\t\tbuf2hex(await hash(await this.canonicalString())),\n\t\t].join('\\n');\n\t}\n\n\t/**\n\t * @returns {Promise<string>}\n\t */\n\tasync canonicalString() {\n\t\treturn [\n\t\t\tthis.method.toUpperCase(),\n\t\t\tthis.encodedPath,\n\t\t\tthis.encodedSearch,\n\t\t\tthis.canonicalHeaders + '\\n',\n\t\t\tthis.signedHeaders,\n\t\t\tawait this.hexBodyHash(),\n\t\t].join('\\n');\n\t}\n\n\t/**\n\t * @returns {Promise<string>}\n\t */\n\tasync hexBodyHash() {\n\t\tlet hashHeader =\n\t\t\tthis.headers.get('X-Amz-Content-Sha256') ||\n\t\t\t(this.service === 's3' && this.signQuery ? 'UNSIGNED-PAYLOAD' : null);\n\t\tif (hashHeader == null) {\n\t\t\tif (this.body && typeof this.body !== 'string' && !('byteLength' in this.body)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header',\n\t\t\t\t);\n\t\t\t}\n\t\t\thashHeader = buf2hex(await hash(this.body || ''));\n\t\t}\n\t\treturn hashHeader;\n\t}\n}\n\n/**\n * @param {string | BufferSource} key\n * @param {string} string\n * @returns {Promise<ArrayBuffer>}\n */\nasync function hmac(key: string | BufferSource, string: string): Promise<ArrayBuffer> {\n\tconst cryptoKey = await crypto.subtle.importKey(\n\t\t'raw',\n\t\ttypeof key === 'string' ? encoder.encode(key) : key,\n\t\t{ name: 'HMAC', hash: { name: 'SHA-256' } },\n\t\tfalse,\n\t\t['sign'],\n\t);\n\treturn crypto.subtle.sign('HMAC', cryptoKey, encoder.encode(string));\n}\n\nasync function hash(content: string | ArrayBufferLike): Promise<ArrayBuffer> {\n\treturn crypto.subtle.digest(\n\t\t'SHA-256',\n\t\t(typeof content === 'string' ? encoder.encode(content) : content) as ArrayBuffer,\n\t);\n}\n\nconst HEX_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];\n\nfunction buf2hex(arrayBuffer: ArrayBufferLike): string {\n\tconst buffer = new Uint8Array(arrayBuffer);\n\tlet out = '';\n\tfor (let idx = 0; idx < buffer.length; idx++) {\n\t\tconst n = buffer[idx];\n\n\t\tout += HEX_CHARS[(n >>> 4) & 0xf];\n\t\tout += HEX_CHARS[n & 0xf];\n\t}\n\treturn out;\n}\n\nfunction encodeRfc3986(urlEncodedStr: string): string {\n\treturn urlEncodedStr.replace(/[!'()*]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());\n}\n\nfunction guessServiceRegion(url: URL, headers: Headers): [string, string] {\n\tconst { hostname, pathname } = url;\n\n\tif (hostname.endsWith('.on.aws')) {\n\t\tconst match = hostname.match(/^[^.]{1,63}\\.lambda-url\\.([^.]{1,63})\\.on\\.aws$/);\n\t\treturn match != null ? ['lambda', match[1] || ''] : ['', ''];\n\t}\n\tif (hostname.endsWith('.r2.cloudflarestorage.com')) {\n\t\treturn ['s3', 'auto'];\n\t}\n\tif (hostname.endsWith('.backblazeb2.com')) {\n\t\tconst match = hostname.match(/^(?:[^.]{1,63}\\.)?s3\\.([^.]{1,63})\\.backblazeb2\\.com$/);\n\t\treturn match != null ? ['s3', match[1] || ''] : ['', ''];\n\t}\n\tconst match = hostname\n\t\t.replace('dualstack.', '')\n\t\t.match(/([^.]{1,63})\\.(?:([^.]{0,63})\\.)?amazonaws\\.com(?:\\.cn)?$/);\n\tlet service = (match && match[1]) || '';\n\tlet region = match && match[2];\n\n\tif (region === 'us-gov') {\n\t\tregion = 'us-gov-west-1';\n\t} else if (region === 's3' || region === 's3-accelerate') {\n\t\tregion = 'us-east-1';\n\t\tservice = 's3';\n\t} else if (service === 'iot') {\n\t\tif (hostname.startsWith('iot.')) {\n\t\t\tservice = 'execute-api';\n\t\t} else if (hostname.startsWith('data.jobs.iot.')) {\n\t\t\tservice = 'iot-jobs-data';\n\t\t} else {\n\t\t\tservice = pathname === '/mqtt' ? 'iotdevicegateway' : 'iotdata';\n\t\t}\n\t} else if (service === 'autoscaling') {\n\t\tconst targetPrefix = (headers.get('X-Amz-Target') || '').split('.')[0];\n\t\tif (targetPrefix === 'AnyScaleFrontendService') {\n\t\t\tservice = 'application-autoscaling';\n\t\t} else if (targetPrefix === 'AnyScaleScalingPlannerFrontendService') {\n\t\t\tservice = 'autoscaling-plans';\n\t\t}\n\t} else if (region == null && service.startsWith('s3-')) {\n\t\tregion = service.slice(3).replace(/^fips-|^external-1/, '');\n\t\tservice = 's3';\n\t} else if (service.endsWith('-fips')) {\n\t\tservice = service.slice(0, -5);\n\t} else if (region && /-\\d$/.test(service) && !/-\\d$/.test(region)) {\n\t\t[service, region] = [region, service];\n\t}\n\n\treturn [HOST_SERVICES[service] || service, region || ''];\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA;AAAA;AAAA;AAAA;AAAA;AAMA,MAAM,UAAU,IAAI,YAAY;AAGhC,MAAM,gBAAw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;",
|
|
6
|
+
"names": ["match"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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_exports = {};
|
|
20
|
+
__export(aws_exports, {
|
|
21
|
+
AwsKmsSigner: () => import_aws_kms_signer.AwsKmsSigner
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(aws_exports);
|
|
24
|
+
var import_aws_kms_signer = require("./aws-kms-signer.js");
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/aws/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { AwsClientOptions } from './aws-client.js';\nimport type { AwsKmsSignerOptions } from './aws-kms-signer.js';\nimport { AwsKmsSigner } from './aws-kms-signer.js';\n\nexport { AwsKmsSigner };\n\nexport type { AwsKmsSignerOptions, AwsClientOptions };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,4BAA6B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { KeyManagementServiceClient } from '@google-cloud/kms';
|
|
2
|
+
import type { PublicKey } from '@haneullabs/haneul/cryptography';
|
|
3
|
+
import { Signer } from '@haneullabs/haneul/cryptography';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for initializing the GcpKmsSigner.
|
|
6
|
+
*/
|
|
7
|
+
export interface GcpKmsSignerOptions {
|
|
8
|
+
/** The version name generated from `client.cryptoKeyVersionPath()` */
|
|
9
|
+
versionName: string;
|
|
10
|
+
/** Options for setting up the GCP KMS client */
|
|
11
|
+
client: KeyManagementServiceClient;
|
|
12
|
+
/** Public key */
|
|
13
|
+
publicKey: PublicKey;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* GCP KMS Signer integrates GCP Key Management Service (KMS) with the Haneul blockchain
|
|
17
|
+
* to provide signing capabilities using GCP-managed cryptographic keys.
|
|
18
|
+
*/
|
|
19
|
+
export declare class GcpKmsSigner extends Signer {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of GcpKmsSigner. It's expected to call the static `fromOptions`
|
|
23
|
+
* or `fromVersionName` method to create an instance.
|
|
24
|
+
* For example:
|
|
25
|
+
* ```
|
|
26
|
+
* const signer = await GcpKmsSigner.fromVersionName(versionName);
|
|
27
|
+
* ```
|
|
28
|
+
* @throws Will throw an error if required GCP credentials are not provided.
|
|
29
|
+
*/
|
|
30
|
+
constructor({ versionName, client, publicKey }: GcpKmsSignerOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the key scheme used by this signer.
|
|
33
|
+
* @returns GCP 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 GCP 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 GCP KMS.
|
|
51
|
+
* @throws Always throws an error indicating synchronous signing is unsupported.
|
|
52
|
+
* @deprecated use `sign` instead
|
|
53
|
+
*/
|
|
54
|
+
signData(): never;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a GCP KMS signer from the provided options.
|
|
57
|
+
* Expects the credentials file to be set as an env variable
|
|
58
|
+
* (GOOGLE_APPLICATION_CREDENTIALS).
|
|
59
|
+
*/
|
|
60
|
+
static fromOptions(options: {
|
|
61
|
+
projectId: string;
|
|
62
|
+
location: string;
|
|
63
|
+
keyRing: string;
|
|
64
|
+
cryptoKey: string;
|
|
65
|
+
cryptoKeyVersion: string;
|
|
66
|
+
}): Promise<GcpKmsSigner>;
|
|
67
|
+
static fromVersionName(versionName: string): Promise<GcpKmsSigner>;
|
|
68
|
+
}
|