@smithy/signature-v4a 3.2.8 → 3.3.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/dist-cjs/index.js +20 -22
- package/package.json +7 -7
package/dist-cjs/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const { REGION_SET_PARAM, KEY_TYPE_IDENTIFIER, ALGORITHM_IDENTIFIER_V4A, SignatureV4Base, prepareRequest, AMZ_DATE_HEADER, TOKEN_HEADER, getPayloadHash, hasHeader, SHA256_HEADER, getCanonicalHeaders, AUTH_HEADER, signatureV4aContainer } = require("@smithy/signature-v4");
|
|
2
|
+
const { toUint8Array, toHex } = require("@smithy/core/serde");
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
var serde = require('@smithy/core/serde');
|
|
5
|
-
|
|
6
|
-
const REGION_HEADER = signatureV4.REGION_SET_PARAM.toLowerCase();
|
|
4
|
+
const REGION_HEADER = REGION_SET_PARAM.toLowerCase();
|
|
7
5
|
const ONE_AS_4_BYTES = [0x00, 0x00, 0x00, 0x01];
|
|
8
6
|
const TWOFIFTYSIX_AS_4_BYTES = [0x00, 0x00, 0x01, 0x00];
|
|
9
7
|
const N_MINUS_TWO = [
|
|
@@ -11,7 +9,7 @@ const N_MINUS_TWO = [
|
|
|
11
9
|
0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x4f,
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
const createSigV4aScope = (shortDate, service) => `${shortDate}/${service}/${
|
|
12
|
+
const createSigV4aScope = (shortDate, service) => `${shortDate}/${service}/${KEY_TYPE_IDENTIFIER}`;
|
|
15
13
|
const getSigV4aSigningKey = async (sha256, accessKey, secretKey) => {
|
|
16
14
|
let outputBufferWriter = "";
|
|
17
15
|
const maxTrials = 254;
|
|
@@ -31,7 +29,7 @@ const getSigV4aSigningKey = async (sha256, accessKey, secretKey) => {
|
|
|
31
29
|
outputBufferWriter = buildFixedInputBuffer(outputBufferWriter, accessKey, trial);
|
|
32
30
|
const secretKey = inputKeyBuf.subarray(0, inputKeyLength);
|
|
33
31
|
const hash = new sha256(secretKey);
|
|
34
|
-
const hashVal =
|
|
32
|
+
const hashVal = toUint8Array(outputBufferWriter);
|
|
35
33
|
hash.update(hashVal);
|
|
36
34
|
const hashedOutput = await hash.digest();
|
|
37
35
|
if (isBiggerThanNMinus2(hashedOutput)) {
|
|
@@ -45,7 +43,7 @@ const getSigV4aSigningKey = async (sha256, accessKey, secretKey) => {
|
|
|
45
43
|
const buildFixedInputBuffer = (bufferInput, accessKey, counter) => {
|
|
46
44
|
let outputBuffer = bufferInput;
|
|
47
45
|
outputBuffer += ONE_AS_4_BYTES.map((value) => String.fromCharCode(value)).join("");
|
|
48
|
-
outputBuffer +=
|
|
46
|
+
outputBuffer += ALGORITHM_IDENTIFIER_V4A;
|
|
49
47
|
outputBuffer += String.fromCharCode(0x00);
|
|
50
48
|
outputBuffer += accessKey;
|
|
51
49
|
outputBuffer += String.fromCharCode(counter);
|
|
@@ -9908,7 +9906,7 @@ var require_elliptic = __commonJS({
|
|
|
9908
9906
|
var import_elliptic = __toESM(require_elliptic());
|
|
9909
9907
|
var export_Ec = import_elliptic.ec;
|
|
9910
9908
|
|
|
9911
|
-
class SignatureV4a extends
|
|
9909
|
+
class SignatureV4a extends SignatureV4Base {
|
|
9912
9910
|
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true, }) {
|
|
9913
9911
|
super({
|
|
9914
9912
|
applyChecksum,
|
|
@@ -9926,25 +9924,25 @@ class SignatureV4a extends signatureV4.SignatureV4Base {
|
|
|
9926
9924
|
const credentials = await this.credentialProvider();
|
|
9927
9925
|
this.validateResolvedCredentials(credentials);
|
|
9928
9926
|
const region = signingRegion ?? (await this.regionProvider());
|
|
9929
|
-
const request =
|
|
9927
|
+
const request = prepareRequest(requestToSign);
|
|
9930
9928
|
const { longDate, shortDate } = this.formatDate(signingDate);
|
|
9931
9929
|
const scope = createSigV4aScope(shortDate, signingService ?? this.service);
|
|
9932
9930
|
const pKey = await getSigV4aSigningKey(this.sha256, credentials.accessKeyId, credentials.secretAccessKey);
|
|
9933
|
-
request.headers[
|
|
9931
|
+
request.headers[AMZ_DATE_HEADER] = longDate;
|
|
9934
9932
|
if (credentials.sessionToken) {
|
|
9935
|
-
request.headers[
|
|
9933
|
+
request.headers[TOKEN_HEADER] = credentials.sessionToken;
|
|
9936
9934
|
}
|
|
9937
9935
|
request.headers[REGION_HEADER] = region;
|
|
9938
|
-
const payloadHash = await
|
|
9939
|
-
if (!
|
|
9940
|
-
request.headers[
|
|
9936
|
+
const payloadHash = await getPayloadHash(request, this.sha256);
|
|
9937
|
+
if (!hasHeader(SHA256_HEADER, request.headers) && this.applyChecksum) {
|
|
9938
|
+
request.headers[SHA256_HEADER] = payloadHash;
|
|
9941
9939
|
}
|
|
9942
|
-
const canonicalHeaders =
|
|
9940
|
+
const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
|
|
9943
9941
|
const canonicalRequest = this.createCanonicalRequest(request, canonicalHeaders, payloadHash);
|
|
9944
|
-
const stringToSign = await this.createStringToSign(longDate, scope, canonicalRequest,
|
|
9942
|
+
const stringToSign = await this.createStringToSign(longDate, scope, canonicalRequest, ALGORITHM_IDENTIFIER_V4A);
|
|
9945
9943
|
const signature = await this.getSignature(pKey, stringToSign);
|
|
9946
|
-
request.headers[
|
|
9947
|
-
`${
|
|
9944
|
+
request.headers[AUTH_HEADER] =
|
|
9945
|
+
`${ALGORITHM_IDENTIFIER_V4A} ` +
|
|
9948
9946
|
`Credential=${credentials.accessKeyId}/${scope}, ` +
|
|
9949
9947
|
`SignedHeaders=${this.getCanonicalHeaderList(canonicalHeaders)}, ` +
|
|
9950
9948
|
`Signature=${signature}`;
|
|
@@ -9954,13 +9952,13 @@ class SignatureV4a extends signatureV4.SignatureV4Base {
|
|
|
9954
9952
|
const ecdsa = new export_Ec("p256");
|
|
9955
9953
|
const key = ecdsa.keyFromPrivate(privateKey);
|
|
9956
9954
|
const hash = new this.sha256();
|
|
9957
|
-
hash.update(
|
|
9955
|
+
hash.update(toUint8Array(stringToSign));
|
|
9958
9956
|
const hashResult = await hash.digest();
|
|
9959
9957
|
const signature = key.sign(hashResult);
|
|
9960
|
-
return
|
|
9958
|
+
return toHex(new Uint8Array(signature.toDER()));
|
|
9961
9959
|
}
|
|
9962
9960
|
}
|
|
9963
9961
|
|
|
9964
|
-
|
|
9962
|
+
signatureV4aContainer.SignatureV4a = SignatureV4a;
|
|
9965
9963
|
|
|
9966
9964
|
exports.SignatureV4a = SignatureV4a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/signature-v4a",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Asymmetric addon for the @smithy/signature-v4 package",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
|
|
10
10
|
"build:elliptic": "node ./scripts/esbuild.mjs",
|
|
11
|
-
"build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline",
|
|
12
|
-
"build:types": "yarn g:tsc -p tsconfig.types.json",
|
|
11
|
+
"build:es:cjs": "premove dist-es && yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline",
|
|
12
|
+
"build:types": "premove dist-types && yarn g:tsc -p tsconfig.types.json",
|
|
13
13
|
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
|
|
14
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
14
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
15
15
|
"extract:docs": "api-extractor run --local",
|
|
16
16
|
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
17
17
|
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"sideEffects": true,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@smithy/core": "^3.
|
|
30
|
-
"@smithy/signature-v4": "^5.
|
|
31
|
-
"@smithy/types": "^4.
|
|
29
|
+
"@smithy/core": "^3.25.0",
|
|
30
|
+
"@smithy/signature-v4": "^5.5.0",
|
|
31
|
+
"@smithy/types": "^4.15.0",
|
|
32
32
|
"tslib": "^2.6.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|