@cdk8s/awscdk-resolver 0.0.280 → 0.0.282

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 (33) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +5 -5
  4. package/node_modules/@aws-sdk/client-sso/package.json +4 -4
  5. package/node_modules/@aws-sdk/core/package.json +2 -2
  6. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  7. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  8. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  9. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  11. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  12. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  13. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  14. package/node_modules/@aws-sdk/nested-clients/package.json +4 -4
  15. package/node_modules/@aws-sdk/token-providers/package.json +2 -2
  16. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  17. package/node_modules/@smithy/signature-v4/dist-cjs/SignatureV4Base.js +1 -0
  18. package/node_modules/@smithy/signature-v4/dist-cjs/index.js +196 -92
  19. package/node_modules/@smithy/signature-v4/dist-cjs/signature-v4a-container.js +1 -0
  20. package/node_modules/@smithy/signature-v4/dist-es/SignatureV4.js +17 -73
  21. package/node_modules/@smithy/signature-v4/dist-es/SignatureV4Base.js +73 -0
  22. package/node_modules/@smithy/signature-v4/dist-es/index.js +4 -0
  23. package/node_modules/@smithy/signature-v4/dist-es/signature-v4a-container.js +3 -0
  24. package/node_modules/@smithy/signature-v4/dist-types/SignatureV4.d.ts +3 -59
  25. package/node_modules/@smithy/signature-v4/dist-types/SignatureV4Base.d.ts +69 -0
  26. package/node_modules/@smithy/signature-v4/dist-types/index.d.ts +4 -0
  27. package/node_modules/@smithy/signature-v4/dist-types/signature-v4a-container.d.ts +24 -0
  28. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/SignatureV4.d.ts +3 -59
  29. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/SignatureV4Base.d.ts +69 -0
  30. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/index.d.ts +4 -0
  31. package/node_modules/@smithy/signature-v4/dist-types/ts3.4/signature-v4a-container.d.ts +24 -0
  32. package/node_modules/@smithy/signature-v4/package.json +1 -1
  33. package/package.json +6 -6
@@ -20,23 +20,51 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ ALGORITHM_IDENTIFIER: () => ALGORITHM_IDENTIFIER,
24
+ ALGORITHM_IDENTIFIER_V4A: () => ALGORITHM_IDENTIFIER_V4A,
25
+ ALGORITHM_QUERY_PARAM: () => ALGORITHM_QUERY_PARAM,
26
+ ALWAYS_UNSIGNABLE_HEADERS: () => ALWAYS_UNSIGNABLE_HEADERS,
27
+ AMZ_DATE_HEADER: () => AMZ_DATE_HEADER,
28
+ AMZ_DATE_QUERY_PARAM: () => AMZ_DATE_QUERY_PARAM,
29
+ AUTH_HEADER: () => AUTH_HEADER,
30
+ CREDENTIAL_QUERY_PARAM: () => CREDENTIAL_QUERY_PARAM,
31
+ DATE_HEADER: () => DATE_HEADER,
32
+ EVENT_ALGORITHM_IDENTIFIER: () => EVENT_ALGORITHM_IDENTIFIER,
33
+ EXPIRES_QUERY_PARAM: () => EXPIRES_QUERY_PARAM,
34
+ GENERATED_HEADERS: () => GENERATED_HEADERS,
35
+ HOST_HEADER: () => HOST_HEADER,
36
+ KEY_TYPE_IDENTIFIER: () => KEY_TYPE_IDENTIFIER,
37
+ MAX_CACHE_SIZE: () => MAX_CACHE_SIZE,
38
+ MAX_PRESIGNED_TTL: () => MAX_PRESIGNED_TTL,
39
+ PROXY_HEADER_PATTERN: () => PROXY_HEADER_PATTERN,
40
+ REGION_SET_PARAM: () => REGION_SET_PARAM,
41
+ SEC_HEADER_PATTERN: () => SEC_HEADER_PATTERN,
42
+ SHA256_HEADER: () => SHA256_HEADER,
43
+ SIGNATURE_HEADER: () => SIGNATURE_HEADER,
44
+ SIGNATURE_QUERY_PARAM: () => SIGNATURE_QUERY_PARAM,
45
+ SIGNED_HEADERS_QUERY_PARAM: () => SIGNED_HEADERS_QUERY_PARAM,
23
46
  SignatureV4: () => SignatureV4,
47
+ SignatureV4Base: () => SignatureV4Base,
48
+ TOKEN_HEADER: () => TOKEN_HEADER,
49
+ TOKEN_QUERY_PARAM: () => TOKEN_QUERY_PARAM,
50
+ UNSIGNABLE_PATTERNS: () => UNSIGNABLE_PATTERNS,
51
+ UNSIGNED_PAYLOAD: () => UNSIGNED_PAYLOAD,
24
52
  clearCredentialCache: () => clearCredentialCache,
25
53
  createScope: () => createScope,
26
54
  getCanonicalHeaders: () => getCanonicalHeaders,
27
55
  getCanonicalQuery: () => getCanonicalQuery,
28
56
  getPayloadHash: () => getPayloadHash,
29
57
  getSigningKey: () => getSigningKey,
58
+ hasHeader: () => hasHeader,
30
59
  moveHeadersToQuery: () => moveHeadersToQuery,
31
- prepareRequest: () => prepareRequest
60
+ prepareRequest: () => prepareRequest,
61
+ signatureV4aContainer: () => signatureV4aContainer
32
62
  });
33
63
  module.exports = __toCommonJS(src_exports);
34
64
 
35
65
  // src/SignatureV4.ts
36
66
 
37
- var import_util_middleware = require("@smithy/util-middleware");
38
-
39
- var import_util_utf84 = require("@smithy/util-utf8");
67
+ var import_util_utf85 = require("@smithy/util-utf8");
40
68
 
41
69
  // src/constants.ts
42
70
  var ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
@@ -46,6 +74,7 @@ var SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
46
74
  var EXPIRES_QUERY_PARAM = "X-Amz-Expires";
47
75
  var SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
48
76
  var TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
77
+ var REGION_SET_PARAM = "X-Amz-Region-Set";
49
78
  var AUTH_HEADER = "authorization";
50
79
  var AMZ_DATE_HEADER = AMZ_DATE_QUERY_PARAM.toLowerCase();
51
80
  var DATE_HEADER = "date";
@@ -53,6 +82,7 @@ var GENERATED_HEADERS = [AUTH_HEADER, AMZ_DATE_HEADER, DATE_HEADER];
53
82
  var SIGNATURE_HEADER = SIGNATURE_QUERY_PARAM.toLowerCase();
54
83
  var SHA256_HEADER = "x-amz-content-sha256";
55
84
  var TOKEN_HEADER = TOKEN_QUERY_PARAM.toLowerCase();
85
+ var HOST_HEADER = "host";
56
86
  var ALWAYS_UNSIGNABLE_HEADERS = {
57
87
  authorization: true,
58
88
  "cache-control": true,
@@ -72,7 +102,9 @@ var ALWAYS_UNSIGNABLE_HEADERS = {
72
102
  };
73
103
  var PROXY_HEADER_PATTERN = /^proxy-/;
74
104
  var SEC_HEADER_PATTERN = /^sec-/;
105
+ var UNSIGNABLE_PATTERNS = [/^proxy-/i, /^sec-/i];
75
106
  var ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
107
+ var ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
76
108
  var EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
77
109
  var UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
78
110
  var MAX_CACHE_SIZE = 50;
@@ -131,27 +163,6 @@ var getCanonicalHeaders = /* @__PURE__ */ __name(({ headers }, unsignableHeaders
131
163
  return canonical;
132
164
  }, "getCanonicalHeaders");
133
165
 
134
- // src/getCanonicalQuery.ts
135
- var import_util_uri_escape = require("@smithy/util-uri-escape");
136
- var getCanonicalQuery = /* @__PURE__ */ __name(({ query = {} }) => {
137
- const keys = [];
138
- const serialized = {};
139
- for (const key of Object.keys(query)) {
140
- if (key.toLowerCase() === SIGNATURE_HEADER) {
141
- continue;
142
- }
143
- const encodedKey = (0, import_util_uri_escape.escapeUri)(key);
144
- keys.push(encodedKey);
145
- const value = query[key];
146
- if (typeof value === "string") {
147
- serialized[encodedKey] = `${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value)}`;
148
- } else if (Array.isArray(value)) {
149
- serialized[encodedKey] = value.slice(0).reduce((encoded, value2) => encoded.concat([`${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value2)}`]), []).sort().join("&");
150
- }
151
- }
152
- return keys.sort().map((key) => serialized[key]).filter((serialized2) => serialized2).join("&");
153
- }, "getCanonicalQuery");
154
-
155
166
  // src/getPayloadHash.ts
156
167
  var import_is_array_buffer = require("@smithy/is-array-buffer");
157
168
 
@@ -337,6 +348,33 @@ var prepareRequest = /* @__PURE__ */ __name((request) => {
337
348
  return request;
338
349
  }, "prepareRequest");
339
350
 
351
+ // src/SignatureV4Base.ts
352
+
353
+ var import_util_middleware = require("@smithy/util-middleware");
354
+
355
+ var import_util_utf84 = require("@smithy/util-utf8");
356
+
357
+ // src/getCanonicalQuery.ts
358
+ var import_util_uri_escape = require("@smithy/util-uri-escape");
359
+ var getCanonicalQuery = /* @__PURE__ */ __name(({ query = {} }) => {
360
+ const keys = [];
361
+ const serialized = {};
362
+ for (const key of Object.keys(query)) {
363
+ if (key.toLowerCase() === SIGNATURE_HEADER) {
364
+ continue;
365
+ }
366
+ const encodedKey = (0, import_util_uri_escape.escapeUri)(key);
367
+ keys.push(encodedKey);
368
+ const value = query[key];
369
+ if (typeof value === "string") {
370
+ serialized[encodedKey] = `${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value)}`;
371
+ } else if (Array.isArray(value)) {
372
+ serialized[encodedKey] = value.slice(0).reduce((encoded, value2) => encoded.concat([`${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value2)}`]), []).sort().join("&");
373
+ }
374
+ }
375
+ return keys.sort().map((key) => serialized[key]).filter((serialized2) => serialized2).join("&");
376
+ }, "getCanonicalQuery");
377
+
340
378
  // src/utilDate.ts
341
379
  var iso8601 = /* @__PURE__ */ __name((time) => toDate(time).toISOString().replace(/\.\d{3}Z$/, "Z"), "iso8601");
342
380
  var toDate = /* @__PURE__ */ __name((time) => {
@@ -352,8 +390,11 @@ var toDate = /* @__PURE__ */ __name((time) => {
352
390
  return time;
353
391
  }, "toDate");
354
392
 
355
- // src/SignatureV4.ts
356
- var SignatureV4 = class {
393
+ // src/SignatureV4Base.ts
394
+ var SignatureV4Base = class {
395
+ static {
396
+ __name(this, "SignatureV4Base");
397
+ }
357
398
  constructor({
358
399
  applyChecksum,
359
400
  credentials,
@@ -362,7 +403,6 @@ var SignatureV4 = class {
362
403
  sha256,
363
404
  uriEscapePath = true
364
405
  }) {
365
- this.headerFormatter = new HeaderFormatter();
366
406
  this.service = service;
367
407
  this.sha256 = sha256;
368
408
  this.uriEscapePath = uriEscapePath;
@@ -370,6 +410,84 @@ var SignatureV4 = class {
370
410
  this.regionProvider = (0, import_util_middleware.normalizeProvider)(region);
371
411
  this.credentialProvider = (0, import_util_middleware.normalizeProvider)(credentials);
372
412
  }
413
+ createCanonicalRequest(request, canonicalHeaders, payloadHash) {
414
+ const sortedHeaders = Object.keys(canonicalHeaders).sort();
415
+ return `${request.method}
416
+ ${this.getCanonicalPath(request)}
417
+ ${getCanonicalQuery(request)}
418
+ ${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
419
+
420
+ ${sortedHeaders.join(";")}
421
+ ${payloadHash}`;
422
+ }
423
+ async createStringToSign(longDate, credentialScope, canonicalRequest, algorithmIdentifier) {
424
+ const hash = new this.sha256();
425
+ hash.update((0, import_util_utf84.toUint8Array)(canonicalRequest));
426
+ const hashedRequest = await hash.digest();
427
+ return `${algorithmIdentifier}
428
+ ${longDate}
429
+ ${credentialScope}
430
+ ${(0, import_util_hex_encoding.toHex)(hashedRequest)}`;
431
+ }
432
+ getCanonicalPath({ path }) {
433
+ if (this.uriEscapePath) {
434
+ const normalizedPathSegments = [];
435
+ for (const pathSegment of path.split("/")) {
436
+ if (pathSegment?.length === 0)
437
+ continue;
438
+ if (pathSegment === ".")
439
+ continue;
440
+ if (pathSegment === "..") {
441
+ normalizedPathSegments.pop();
442
+ } else {
443
+ normalizedPathSegments.push(pathSegment);
444
+ }
445
+ }
446
+ const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
447
+ const doubleEncoded = (0, import_util_uri_escape.escapeUri)(normalizedPath);
448
+ return doubleEncoded.replace(/%2F/g, "/");
449
+ }
450
+ return path;
451
+ }
452
+ validateResolvedCredentials(credentials) {
453
+ if (typeof credentials !== "object" || // @ts-expect-error: Property 'accessKeyId' does not exist on type 'object'.ts(2339)
454
+ typeof credentials.accessKeyId !== "string" || // @ts-expect-error: Property 'secretAccessKey' does not exist on type 'object'.ts(2339)
455
+ typeof credentials.secretAccessKey !== "string") {
456
+ throw new Error("Resolved credential object is not valid");
457
+ }
458
+ }
459
+ formatDate(now) {
460
+ const longDate = iso8601(now).replace(/[\-:]/g, "");
461
+ return {
462
+ longDate,
463
+ shortDate: longDate.slice(0, 8)
464
+ };
465
+ }
466
+ getCanonicalHeaderList(headers) {
467
+ return Object.keys(headers).sort().join(";");
468
+ }
469
+ };
470
+
471
+ // src/SignatureV4.ts
472
+ var SignatureV4 = class extends SignatureV4Base {
473
+ constructor({
474
+ applyChecksum,
475
+ credentials,
476
+ region,
477
+ service,
478
+ sha256,
479
+ uriEscapePath = true
480
+ }) {
481
+ super({
482
+ applyChecksum,
483
+ credentials,
484
+ region,
485
+ service,
486
+ sha256,
487
+ uriEscapePath
488
+ });
489
+ this.headerFormatter = new HeaderFormatter();
490
+ }
373
491
  static {
374
492
  __name(this, "SignatureV4");
375
493
  }
@@ -387,7 +505,7 @@ var SignatureV4 = class {
387
505
  const credentials = await this.credentialProvider();
388
506
  this.validateResolvedCredentials(credentials);
389
507
  const region = signingRegion ?? await this.regionProvider();
390
- const { longDate, shortDate } = formatDate(signingDate);
508
+ const { longDate, shortDate } = this.formatDate(signingDate);
391
509
  if (expiresIn > MAX_PRESIGNED_TTL) {
392
510
  return Promise.reject(
393
511
  "Signature version 4 presigned URLs must have an expiration date less than one week in the future"
@@ -403,7 +521,7 @@ var SignatureV4 = class {
403
521
  request.query[AMZ_DATE_QUERY_PARAM] = longDate;
404
522
  request.query[EXPIRES_QUERY_PARAM] = expiresIn.toString(10);
405
523
  const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
406
- request.query[SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders);
524
+ request.query[SIGNED_HEADERS_QUERY_PARAM] = this.getCanonicalHeaderList(canonicalHeaders);
407
525
  request.query[SIGNATURE_QUERY_PARAM] = await this.getSignature(
408
526
  longDate,
409
527
  scope,
@@ -425,7 +543,7 @@ var SignatureV4 = class {
425
543
  }
426
544
  async signEvent({ headers, payload }, { signingDate = /* @__PURE__ */ new Date(), priorSignature, signingRegion, signingService }) {
427
545
  const region = signingRegion ?? await this.regionProvider();
428
- const { shortDate, longDate } = formatDate(signingDate);
546
+ const { shortDate, longDate } = this.formatDate(signingDate);
429
547
  const scope = createScope(shortDate, region, signingService ?? this.service);
430
548
  const hashedPayload = await getPayloadHash({ headers: {}, body: payload }, this.sha256);
431
549
  const hash = new this.sha256();
@@ -462,9 +580,9 @@ var SignatureV4 = class {
462
580
  const credentials = await this.credentialProvider();
463
581
  this.validateResolvedCredentials(credentials);
464
582
  const region = signingRegion ?? await this.regionProvider();
465
- const { shortDate } = formatDate(signingDate);
583
+ const { shortDate } = this.formatDate(signingDate);
466
584
  const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate, signingService));
467
- hash.update((0, import_util_utf84.toUint8Array)(stringToSign));
585
+ hash.update((0, import_util_utf85.toUint8Array)(stringToSign));
468
586
  return (0, import_util_hex_encoding.toHex)(await hash.digest());
469
587
  }
470
588
  async signRequest(requestToSign, {
@@ -478,7 +596,7 @@ var SignatureV4 = class {
478
596
  this.validateResolvedCredentials(credentials);
479
597
  const region = signingRegion ?? await this.regionProvider();
480
598
  const request = prepareRequest(requestToSign);
481
- const { longDate, shortDate } = formatDate(signingDate);
599
+ const { longDate, shortDate } = this.formatDate(signingDate);
482
600
  const scope = createScope(shortDate, region, signingService ?? this.service);
483
601
  request.headers[AMZ_DATE_HEADER] = longDate;
484
602
  if (credentials.sessionToken) {
@@ -495,73 +613,29 @@ var SignatureV4 = class {
495
613
  this.getSigningKey(credentials, region, shortDate, signingService),
496
614
  this.createCanonicalRequest(request, canonicalHeaders, payloadHash)
497
615
  );
498
- request.headers[AUTH_HEADER] = `${ALGORITHM_IDENTIFIER} Credential=${credentials.accessKeyId}/${scope}, SignedHeaders=${getCanonicalHeaderList(canonicalHeaders)}, Signature=${signature}`;
616
+ request.headers[AUTH_HEADER] = `${ALGORITHM_IDENTIFIER} Credential=${credentials.accessKeyId}/${scope}, SignedHeaders=${this.getCanonicalHeaderList(canonicalHeaders)}, Signature=${signature}`;
499
617
  return request;
500
618
  }
501
- createCanonicalRequest(request, canonicalHeaders, payloadHash) {
502
- const sortedHeaders = Object.keys(canonicalHeaders).sort();
503
- return `${request.method}
504
- ${this.getCanonicalPath(request)}
505
- ${getCanonicalQuery(request)}
506
- ${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
507
-
508
- ${sortedHeaders.join(";")}
509
- ${payloadHash}`;
510
- }
511
- async createStringToSign(longDate, credentialScope, canonicalRequest) {
512
- const hash = new this.sha256();
513
- hash.update((0, import_util_utf84.toUint8Array)(canonicalRequest));
514
- const hashedRequest = await hash.digest();
515
- return `${ALGORITHM_IDENTIFIER}
516
- ${longDate}
517
- ${credentialScope}
518
- ${(0, import_util_hex_encoding.toHex)(hashedRequest)}`;
519
- }
520
- getCanonicalPath({ path }) {
521
- if (this.uriEscapePath) {
522
- const normalizedPathSegments = [];
523
- for (const pathSegment of path.split("/")) {
524
- if (pathSegment?.length === 0)
525
- continue;
526
- if (pathSegment === ".")
527
- continue;
528
- if (pathSegment === "..") {
529
- normalizedPathSegments.pop();
530
- } else {
531
- normalizedPathSegments.push(pathSegment);
532
- }
533
- }
534
- const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
535
- const doubleEncoded = (0, import_util_uri_escape.escapeUri)(normalizedPath);
536
- return doubleEncoded.replace(/%2F/g, "/");
537
- }
538
- return path;
539
- }
540
619
  async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) {
541
- const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest);
620
+ const stringToSign = await this.createStringToSign(
621
+ longDate,
622
+ credentialScope,
623
+ canonicalRequest,
624
+ ALGORITHM_IDENTIFIER
625
+ );
542
626
  const hash = new this.sha256(await keyPromise);
543
- hash.update((0, import_util_utf84.toUint8Array)(stringToSign));
627
+ hash.update((0, import_util_utf85.toUint8Array)(stringToSign));
544
628
  return (0, import_util_hex_encoding.toHex)(await hash.digest());
545
629
  }
546
630
  getSigningKey(credentials, region, shortDate, service) {
547
631
  return getSigningKey(this.sha256, credentials, shortDate, region, service || this.service);
548
632
  }
549
- validateResolvedCredentials(credentials) {
550
- if (typeof credentials !== "object" || // @ts-expect-error: Property 'accessKeyId' does not exist on type 'object'.ts(2339)
551
- typeof credentials.accessKeyId !== "string" || // @ts-expect-error: Property 'secretAccessKey' does not exist on type 'object'.ts(2339)
552
- typeof credentials.secretAccessKey !== "string") {
553
- throw new Error("Resolved credential object is not valid");
554
- }
555
- }
556
633
  };
557
- var formatDate = /* @__PURE__ */ __name((now) => {
558
- const longDate = iso8601(now).replace(/[\-:]/g, "");
559
- return {
560
- longDate,
561
- shortDate: longDate.slice(0, 8)
562
- };
563
- }, "formatDate");
564
- var getCanonicalHeaderList = /* @__PURE__ */ __name((headers) => Object.keys(headers).sort().join(";"), "getCanonicalHeaderList");
634
+
635
+ // src/signature-v4a-container.ts
636
+ var signatureV4aContainer = {
637
+ SignatureV4a: null
638
+ };
565
639
  // Annotate the CommonJS export names for ESM import in node:
566
640
 
567
641
  0 && (module.exports = {
@@ -570,9 +644,39 @@ var getCanonicalHeaderList = /* @__PURE__ */ __name((headers) => Object.keys(hea
570
644
  getPayloadHash,
571
645
  moveHeadersToQuery,
572
646
  prepareRequest,
647
+ SignatureV4Base,
648
+ hasHeader,
573
649
  SignatureV4,
650
+ ALGORITHM_QUERY_PARAM,
651
+ CREDENTIAL_QUERY_PARAM,
652
+ AMZ_DATE_QUERY_PARAM,
653
+ SIGNED_HEADERS_QUERY_PARAM,
654
+ EXPIRES_QUERY_PARAM,
655
+ SIGNATURE_QUERY_PARAM,
656
+ TOKEN_QUERY_PARAM,
657
+ REGION_SET_PARAM,
658
+ AUTH_HEADER,
659
+ AMZ_DATE_HEADER,
660
+ DATE_HEADER,
661
+ GENERATED_HEADERS,
662
+ SIGNATURE_HEADER,
663
+ SHA256_HEADER,
664
+ TOKEN_HEADER,
665
+ HOST_HEADER,
666
+ ALWAYS_UNSIGNABLE_HEADERS,
667
+ PROXY_HEADER_PATTERN,
668
+ SEC_HEADER_PATTERN,
669
+ UNSIGNABLE_PATTERNS,
670
+ ALGORITHM_IDENTIFIER,
671
+ ALGORITHM_IDENTIFIER_V4A,
672
+ EVENT_ALGORITHM_IDENTIFIER,
673
+ UNSIGNED_PAYLOAD,
674
+ MAX_CACHE_SIZE,
675
+ KEY_TYPE_IDENTIFIER,
676
+ MAX_PRESIGNED_TTL,
574
677
  createScope,
575
678
  getSigningKey,
576
- clearCredentialCache
679
+ clearCredentialCache,
680
+ signatureV4aContainer
577
681
  });
578
682
 
@@ -0,0 +1 @@
1
+ module.exports = require("./index.js");
@@ -1,33 +1,32 @@
1
1
  import { toHex } from "@smithy/util-hex-encoding";
2
- import { normalizeProvider } from "@smithy/util-middleware";
3
- import { escapeUri } from "@smithy/util-uri-escape";
4
2
  import { toUint8Array } from "@smithy/util-utf8";
5
3
  import { ALGORITHM_IDENTIFIER, ALGORITHM_QUERY_PARAM, AMZ_DATE_HEADER, AMZ_DATE_QUERY_PARAM, AUTH_HEADER, CREDENTIAL_QUERY_PARAM, EVENT_ALGORITHM_IDENTIFIER, EXPIRES_QUERY_PARAM, MAX_PRESIGNED_TTL, SHA256_HEADER, SIGNATURE_QUERY_PARAM, SIGNED_HEADERS_QUERY_PARAM, TOKEN_HEADER, TOKEN_QUERY_PARAM, } from "./constants";
6
4
  import { createScope, getSigningKey } from "./credentialDerivation";
7
5
  import { getCanonicalHeaders } from "./getCanonicalHeaders";
8
- import { getCanonicalQuery } from "./getCanonicalQuery";
9
6
  import { getPayloadHash } from "./getPayloadHash";
10
7
  import { HeaderFormatter } from "./HeaderFormatter";
11
8
  import { hasHeader } from "./headerUtil";
12
9
  import { moveHeadersToQuery } from "./moveHeadersToQuery";
13
10
  import { prepareRequest } from "./prepareRequest";
14
- import { iso8601 } from "./utilDate";
15
- export class SignatureV4 {
11
+ import { SignatureV4Base } from "./SignatureV4Base";
12
+ export class SignatureV4 extends SignatureV4Base {
16
13
  constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true, }) {
14
+ super({
15
+ applyChecksum,
16
+ credentials,
17
+ region,
18
+ service,
19
+ sha256,
20
+ uriEscapePath,
21
+ });
17
22
  this.headerFormatter = new HeaderFormatter();
18
- this.service = service;
19
- this.sha256 = sha256;
20
- this.uriEscapePath = uriEscapePath;
21
- this.applyChecksum = typeof applyChecksum === "boolean" ? applyChecksum : true;
22
- this.regionProvider = normalizeProvider(region);
23
- this.credentialProvider = normalizeProvider(credentials);
24
23
  }
25
24
  async presign(originalRequest, options = {}) {
26
25
  const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, hoistableHeaders, signingRegion, signingService, } = options;
27
26
  const credentials = await this.credentialProvider();
28
27
  this.validateResolvedCredentials(credentials);
29
28
  const region = signingRegion ?? (await this.regionProvider());
30
- const { longDate, shortDate } = formatDate(signingDate);
29
+ const { longDate, shortDate } = this.formatDate(signingDate);
31
30
  if (expiresIn > MAX_PRESIGNED_TTL) {
32
31
  return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
33
32
  }
@@ -41,7 +40,7 @@ export class SignatureV4 {
41
40
  request.query[AMZ_DATE_QUERY_PARAM] = longDate;
42
41
  request.query[EXPIRES_QUERY_PARAM] = expiresIn.toString(10);
43
42
  const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
44
- request.query[SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders);
43
+ request.query[SIGNED_HEADERS_QUERY_PARAM] = this.getCanonicalHeaderList(canonicalHeaders);
45
44
  request.query[SIGNATURE_QUERY_PARAM] = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, await getPayloadHash(originalRequest, this.sha256)));
46
45
  return request;
47
46
  }
@@ -61,7 +60,7 @@ export class SignatureV4 {
61
60
  }
62
61
  async signEvent({ headers, payload }, { signingDate = new Date(), priorSignature, signingRegion, signingService }) {
63
62
  const region = signingRegion ?? (await this.regionProvider());
64
- const { shortDate, longDate } = formatDate(signingDate);
63
+ const { shortDate, longDate } = this.formatDate(signingDate);
65
64
  const scope = createScope(shortDate, region, signingService ?? this.service);
66
65
  const hashedPayload = await getPayloadHash({ headers: {}, body: payload }, this.sha256);
67
66
  const hash = new this.sha256();
@@ -95,7 +94,7 @@ export class SignatureV4 {
95
94
  const credentials = await this.credentialProvider();
96
95
  this.validateResolvedCredentials(credentials);
97
96
  const region = signingRegion ?? (await this.regionProvider());
98
- const { shortDate } = formatDate(signingDate);
97
+ const { shortDate } = this.formatDate(signingDate);
99
98
  const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate, signingService));
100
99
  hash.update(toUint8Array(stringToSign));
101
100
  return toHex(await hash.digest());
@@ -105,7 +104,7 @@ export class SignatureV4 {
105
104
  this.validateResolvedCredentials(credentials);
106
105
  const region = signingRegion ?? (await this.regionProvider());
107
106
  const request = prepareRequest(requestToSign);
108
- const { longDate, shortDate } = formatDate(signingDate);
107
+ const { longDate, shortDate } = this.formatDate(signingDate);
109
108
  const scope = createScope(shortDate, region, signingService ?? this.service);
110
109
  request.headers[AMZ_DATE_HEADER] = longDate;
111
110
  if (credentials.sessionToken) {
@@ -120,52 +119,12 @@ export class SignatureV4 {
120
119
  request.headers[AUTH_HEADER] =
121
120
  `${ALGORITHM_IDENTIFIER} ` +
122
121
  `Credential=${credentials.accessKeyId}/${scope}, ` +
123
- `SignedHeaders=${getCanonicalHeaderList(canonicalHeaders)}, ` +
122
+ `SignedHeaders=${this.getCanonicalHeaderList(canonicalHeaders)}, ` +
124
123
  `Signature=${signature}`;
125
124
  return request;
126
125
  }
127
- createCanonicalRequest(request, canonicalHeaders, payloadHash) {
128
- const sortedHeaders = Object.keys(canonicalHeaders).sort();
129
- return `${request.method}
130
- ${this.getCanonicalPath(request)}
131
- ${getCanonicalQuery(request)}
132
- ${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
133
-
134
- ${sortedHeaders.join(";")}
135
- ${payloadHash}`;
136
- }
137
- async createStringToSign(longDate, credentialScope, canonicalRequest) {
138
- const hash = new this.sha256();
139
- hash.update(toUint8Array(canonicalRequest));
140
- const hashedRequest = await hash.digest();
141
- return `${ALGORITHM_IDENTIFIER}
142
- ${longDate}
143
- ${credentialScope}
144
- ${toHex(hashedRequest)}`;
145
- }
146
- getCanonicalPath({ path }) {
147
- if (this.uriEscapePath) {
148
- const normalizedPathSegments = [];
149
- for (const pathSegment of path.split("/")) {
150
- if (pathSegment?.length === 0)
151
- continue;
152
- if (pathSegment === ".")
153
- continue;
154
- if (pathSegment === "..") {
155
- normalizedPathSegments.pop();
156
- }
157
- else {
158
- normalizedPathSegments.push(pathSegment);
159
- }
160
- }
161
- const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
162
- const doubleEncoded = escapeUri(normalizedPath);
163
- return doubleEncoded.replace(/%2F/g, "/");
164
- }
165
- return path;
166
- }
167
126
  async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) {
168
- const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest);
127
+ const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest, ALGORITHM_IDENTIFIER);
169
128
  const hash = new this.sha256(await keyPromise);
170
129
  hash.update(toUint8Array(stringToSign));
171
130
  return toHex(await hash.digest());
@@ -173,19 +132,4 @@ ${toHex(hashedRequest)}`;
173
132
  getSigningKey(credentials, region, shortDate, service) {
174
133
  return getSigningKey(this.sha256, credentials, shortDate, region, service || this.service);
175
134
  }
176
- validateResolvedCredentials(credentials) {
177
- if (typeof credentials !== "object" ||
178
- typeof credentials.accessKeyId !== "string" ||
179
- typeof credentials.secretAccessKey !== "string") {
180
- throw new Error("Resolved credential object is not valid");
181
- }
182
- }
183
135
  }
184
- const formatDate = (now) => {
185
- const longDate = iso8601(now).replace(/[\-:]/g, "");
186
- return {
187
- longDate,
188
- shortDate: longDate.slice(0, 8),
189
- };
190
- };
191
- const getCanonicalHeaderList = (headers) => Object.keys(headers).sort().join(";");
@@ -0,0 +1,73 @@
1
+ import { toHex } from "@smithy/util-hex-encoding";
2
+ import { normalizeProvider } from "@smithy/util-middleware";
3
+ import { escapeUri } from "@smithy/util-uri-escape";
4
+ import { toUint8Array } from "@smithy/util-utf8";
5
+ import { getCanonicalQuery } from "./getCanonicalQuery";
6
+ import { iso8601 } from "./utilDate";
7
+ export class SignatureV4Base {
8
+ constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true, }) {
9
+ this.service = service;
10
+ this.sha256 = sha256;
11
+ this.uriEscapePath = uriEscapePath;
12
+ this.applyChecksum = typeof applyChecksum === "boolean" ? applyChecksum : true;
13
+ this.regionProvider = normalizeProvider(region);
14
+ this.credentialProvider = normalizeProvider(credentials);
15
+ }
16
+ createCanonicalRequest(request, canonicalHeaders, payloadHash) {
17
+ const sortedHeaders = Object.keys(canonicalHeaders).sort();
18
+ return `${request.method}
19
+ ${this.getCanonicalPath(request)}
20
+ ${getCanonicalQuery(request)}
21
+ ${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
22
+
23
+ ${sortedHeaders.join(";")}
24
+ ${payloadHash}`;
25
+ }
26
+ async createStringToSign(longDate, credentialScope, canonicalRequest, algorithmIdentifier) {
27
+ const hash = new this.sha256();
28
+ hash.update(toUint8Array(canonicalRequest));
29
+ const hashedRequest = await hash.digest();
30
+ return `${algorithmIdentifier}
31
+ ${longDate}
32
+ ${credentialScope}
33
+ ${toHex(hashedRequest)}`;
34
+ }
35
+ getCanonicalPath({ path }) {
36
+ if (this.uriEscapePath) {
37
+ const normalizedPathSegments = [];
38
+ for (const pathSegment of path.split("/")) {
39
+ if (pathSegment?.length === 0)
40
+ continue;
41
+ if (pathSegment === ".")
42
+ continue;
43
+ if (pathSegment === "..") {
44
+ normalizedPathSegments.pop();
45
+ }
46
+ else {
47
+ normalizedPathSegments.push(pathSegment);
48
+ }
49
+ }
50
+ const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
51
+ const doubleEncoded = escapeUri(normalizedPath);
52
+ return doubleEncoded.replace(/%2F/g, "/");
53
+ }
54
+ return path;
55
+ }
56
+ validateResolvedCredentials(credentials) {
57
+ if (typeof credentials !== "object" ||
58
+ typeof credentials.accessKeyId !== "string" ||
59
+ typeof credentials.secretAccessKey !== "string") {
60
+ throw new Error("Resolved credential object is not valid");
61
+ }
62
+ }
63
+ formatDate(now) {
64
+ const longDate = iso8601(now).replace(/[\-:]/g, "");
65
+ return {
66
+ longDate,
67
+ shortDate: longDate.slice(0, 8),
68
+ };
69
+ }
70
+ getCanonicalHeaderList(headers) {
71
+ return Object.keys(headers).sort().join(";");
72
+ }
73
+ }
@@ -1,7 +1,11 @@
1
1
  export * from "./SignatureV4";
2
+ export * from "./constants";
2
3
  export { getCanonicalHeaders } from "./getCanonicalHeaders";
3
4
  export { getCanonicalQuery } from "./getCanonicalQuery";
4
5
  export { getPayloadHash } from "./getPayloadHash";
5
6
  export { moveHeadersToQuery } from "./moveHeadersToQuery";
6
7
  export { prepareRequest } from "./prepareRequest";
7
8
  export * from "./credentialDerivation";
9
+ export { SignatureV4Base } from "./SignatureV4Base";
10
+ export { hasHeader } from "./headerUtil";
11
+ export * from "./signature-v4a-container";
@@ -0,0 +1,3 @@
1
+ export const signatureV4aContainer = {
2
+ SignatureV4a: null,
3
+ };