@aws-sdk/signature-v4
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -22,2 +22,2 @@ import { Credentials, HashConstructor } from "@aws-sdk/types"; | ||
*/ | ||
export declare function getSigningKey(sha256Constructor: HashConstructor, credentials: Credentials, shortDate: string, region: string, service: string): Promise<Uint8Array>; | ||
export declare const getSigningKey: (sha256Constructor: HashConstructor, credentials: Credentials, shortDate: string, region: string, service: string) => Promise<Uint8Array>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clearCredentialCache = exports.getSigningKey = exports.createScope = void 0; | ||
const util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding"); | ||
const constants_1 = require("./constants"); | ||
@@ -30,4 +31,5 @@ const signingKeyCache = {}; | ||
*/ | ||
function getSigningKey(sha256Constructor, credentials, shortDate, region, service) { | ||
const cacheKey = `${shortDate}:${region}:${service}:` + `${credentials.accessKeyId}:${credentials.sessionToken}`; | ||
const getSigningKey = async (sha256Constructor, credentials, shortDate, region, service) => { | ||
const credsHash = await hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId); | ||
const cacheKey = `${shortDate}:${region}:${service}:${util_hex_encoding_1.toHex(credsHash)}:${credentials.sessionToken}`; | ||
if (cacheKey in signingKeyCache) { | ||
@@ -40,14 +42,8 @@ return signingKeyCache[cacheKey]; | ||
} | ||
return (signingKeyCache[cacheKey] = new Promise((resolve, reject) => { | ||
let keyPromise = Promise.resolve(`AWS4${credentials.secretAccessKey}`); | ||
for (const signable of [shortDate, region, service, constants_1.KEY_TYPE_IDENTIFIER]) { | ||
keyPromise = keyPromise.then((intermediateKey) => hmac(sha256Constructor, intermediateKey, signable)); | ||
keyPromise.catch(() => { }); | ||
} | ||
keyPromise.then(resolve, (reason) => { | ||
delete signingKeyCache[cacheKey]; | ||
reject(reason); | ||
}); | ||
})); | ||
} | ||
let key = `AWS4${credentials.secretAccessKey}`; | ||
for (const signable of [shortDate, region, service, constants_1.KEY_TYPE_IDENTIFIER]) { | ||
key = await hmac(sha256Constructor, key, signable); | ||
} | ||
return (signingKeyCache[cacheKey] = key); | ||
}; | ||
exports.getSigningKey = getSigningKey; | ||
@@ -69,2 +65,2 @@ /** | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlZGVudGlhbERlcml2YXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY3JlZGVudGlhbERlcml2YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBRUEsMkNBQWtFO0FBRWxFLE1BQU0sZUFBZSxHQUEyQyxFQUFFLENBQUM7QUFDbkUsTUFBTSxVQUFVLEdBQWtCLEVBQUUsQ0FBQztBQUVyQzs7Ozs7O0dBTUc7QUFDSCxTQUFnQixXQUFXLENBQUMsU0FBaUIsRUFBRSxNQUFjLEVBQUUsT0FBZTtJQUM1RSxPQUFPLEdBQUcsU0FBUyxJQUFJLE1BQU0sSUFBSSxPQUFPLElBQUksK0JBQW1CLEVBQUUsQ0FBQztBQUNwRSxDQUFDO0FBRkQsa0NBRUM7QUFFRDs7Ozs7Ozs7Ozs7R0FXRztBQUNILFNBQWdCLGFBQWEsQ0FDM0IsaUJBQWtDLEVBQ2xDLFdBQXdCLEVBQ3hCLFNBQWlCLEVBQ2pCLE1BQWMsRUFDZCxPQUFlO0lBRWYsTUFBTSxRQUFRLEdBQUcsR0FBRyxTQUFTLElBQUksTUFBTSxJQUFJLE9BQU8sR0FBRyxHQUFHLEdBQUcsV0FBVyxDQUFDLFdBQVcsSUFBSSxXQUFXLENBQUMsWUFBWSxFQUFFLENBQUM7SUFDakgsSUFBSSxRQUFRLElBQUksZUFBZSxFQUFFO1FBQy9CLE9BQU8sZUFBZSxDQUFDLFFBQVEsQ0FBQyxDQUFDO0tBQ2xDO0lBRUQsVUFBVSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQztJQUMxQixPQUFPL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biAgfSk7XG59XG5cbmZ1bmN0aW9uIGhtYWMoY3RvcjogSGFzaENvbnN0cnVjdG9yLCBzZWNyZXQ6IFNvdXJjZURhdGEsIGRhdGE6IFNvdXJjZURhdGEpOiBQcm9taXNlPFVpbnQ4QXJyYXk+IHtcbiAgY29uc3QgaGFzaCA9IG5ldyBjdG9yKHNlY3JldCk7XG4gIGhhc2gudXBkYXRlKGRhdGEpO1xuICByZXR1cm4gaGFzaC5kaWdlc3QoKTtcbn1cbiJdfQ== |
@@ -22,2 +22,2 @@ import { Credentials, HashConstructor } from "@aws-sdk/types"; | ||
*/ | ||
export declare function getSigningKey(sha256Constructor: HashConstructor, credentials: Credentials, shortDate: string, region: string, service: string): Promise<Uint8Array>; | ||
export declare const getSigningKey: (sha256Constructor: HashConstructor, credentials: Credentials, shortDate: string, region: string, service: string) => Promise<Uint8Array>; |
@@ -1,2 +0,3 @@ | ||
import { __values } from "tslib"; | ||
import { __awaiter, __generator, __values } from "tslib"; | ||
import { toHex } from "@aws-sdk/util-hex-encoding"; | ||
import { KEY_TYPE_IDENTIFIER, MAX_CACHE_SIZE } from "./constants"; | ||
@@ -27,37 +28,49 @@ var signingKeyCache = {}; | ||
*/ | ||
export function getSigningKey(sha256Constructor, credentials, shortDate, region, service) { | ||
var cacheKey = shortDate + ":" + region + ":" + service + ":" + (credentials.accessKeyId + ":" + credentials.sessionToken); | ||
if (cacheKey in signingKeyCache) { | ||
return signingKeyCache[cacheKey]; | ||
} | ||
cacheQueue.push(cacheKey); | ||
while (cacheQueue.length > MAX_CACHE_SIZE) { | ||
delete signingKeyCache[cacheQueue.shift()]; | ||
} | ||
return (signingKeyCache[cacheKey] = new Promise(function (resolve, reject) { | ||
var e_1, _a; | ||
var keyPromise = Promise.resolve("AWS4" + credentials.secretAccessKey); | ||
var _loop_1 = function (signable) { | ||
keyPromise = keyPromise.then(function (intermediateKey) { return hmac(sha256Constructor, intermediateKey, signable); }); | ||
keyPromise.catch(function () { }); | ||
}; | ||
try { | ||
for (var _b = __values([shortDate, region, service, KEY_TYPE_IDENTIFIER]), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var signable = _c.value; | ||
_loop_1(signable); | ||
} | ||
export var getSigningKey = function (sha256Constructor, credentials, shortDate, region, service) { return __awaiter(void 0, void 0, void 0, function () { | ||
var credsHash, cacheKey, key, _a, _b, signable, e_1_1; | ||
var e_1, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: return [4 /*yield*/, hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId)]; | ||
case 1: | ||
credsHash = _d.sent(); | ||
cacheKey = shortDate + ":" + region + ":" + service + ":" + toHex(credsHash) + ":" + credentials.sessionToken; | ||
if (cacheKey in signingKeyCache) { | ||
return [2 /*return*/, signingKeyCache[cacheKey]]; | ||
} | ||
cacheQueue.push(cacheKey); | ||
while (cacheQueue.length > MAX_CACHE_SIZE) { | ||
delete signingKeyCache[cacheQueue.shift()]; | ||
} | ||
key = "AWS4" + credentials.secretAccessKey; | ||
_d.label = 2; | ||
case 2: | ||
_d.trys.push([2, 7, 8, 9]); | ||
_a = __values([shortDate, region, service, KEY_TYPE_IDENTIFIER]), _b = _a.next(); | ||
_d.label = 3; | ||
case 3: | ||
if (!!_b.done) return [3 /*break*/, 6]; | ||
signable = _b.value; | ||
return [4 /*yield*/, hmac(sha256Constructor, key, signable)]; | ||
case 4: | ||
key = _d.sent(); | ||
_d.label = 5; | ||
case 5: | ||
_b = _a.next(); | ||
return [3 /*break*/, 3]; | ||
case 6: return [3 /*break*/, 9]; | ||
case 7: | ||
e_1_1 = _d.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3 /*break*/, 9]; | ||
case 8: | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
return [7 /*endfinally*/]; | ||
case 9: return [2 /*return*/, (signingKeyCache[cacheKey] = key)]; | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
keyPromise.then(resolve, function (reason) { | ||
delete signingKeyCache[cacheKey]; | ||
reject(reason); | ||
}); | ||
})); | ||
} | ||
}); | ||
}); }; | ||
/** | ||
@@ -77,2 +90,2 @@ * @internal | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlZGVudGlhbERlcml2YXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY3JlZGVudGlhbERlcml2YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUVBLE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxjQUFjLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFFbEUsSUFBTSxlQUFlLEdBQTJDLEVBQUUsQ0FBQztBQUNuRSxJQUFNLFVBQVUsR0FBa0IsRUFBRSxDQUFDO0FBRXJDOzs7Ozs7R0FNRztBQUNILE1BQU0sVUFBVSxXQUFXLENBQUMsU0FBaUIsRUFBRSxNQUFjLEVBQUUsT0FBZTtJQUM1RSxPQUFVLFNBQVMsU0FBSSxNQUFNLFNBQUksT0FBTyxTQUFJLG1CQUFxQixDQUFDO0FBQ3BFLENBQUM7QUFFRDs7Ozs7Ozs7Ozs7R0FXRztBQUNILE1BQU0sVUFBVSxhQUFhLENBQzNCLGlCQUFrQyxFQUNsQyxXQUF3QixFQUN4QixTQUFpQixFQUNqQixNQUFjLEVBQ2QsT0FBZTtJQUVmLElBQU0sUUFBUSxHQUFNLFNBQVMsU0FBSSxNQUFNLFNBQUksT0FBTyxNQUFHLElBQU0sV0FBVyxDQUFDLFdBQVcsU0FBSSxXQUFXLENBQUMsWUFBYyxDQUFBLENBQUM7SUFDakgsSUFBSSxRQUFRLElBQUksZUFBZSxFQUFFO1FBQy9CLE9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XNzS2V5fWApO1xuXG4gICAgZm9yIChjb25zdCBzaWduYWJsZSBvZiBbc2hvcnREYXRlLCByZWdpb24sIHNlcnZpY2UsIEtFWV9UWVBFX0lERU5USUZJRVJdKSB7XG4gICAgICBrZXlQcm9taXNlID0ga2V5UHJvbWlzZS50aGVuPFVpbnQ4QXJyYXk+KChpbnRlcm1lZGlhdGVLZXkpID0+IGhtYWMoc2hhMjU2Q29uc3RydWN0b3IsIGludGVybWVkaWF0ZUtleSwgc2lnbmFibGUpKTtcbiAgICAgIGtleVByb21pc2UuY2F0Y2goKCkgPT4ge30pO1xuICAgIH1cblxuICAgIChrZXlQcm9taXNlIGFzIFByb21pc2U8VWludDhBcnJheT4pLnRoZW4ocmVzb2x2ZSwgKHJlYXNvbikgPT4ge1xuICAgICAgZGVsZXRlIHNpZ25pbmdLZXlDYWNoZVtjYWNoZUtleV07XG4gICAgICByZWplY3QocmVhc29uKTtcbiAgICB9KTtcbiAgfSkpO1xufVxuXG4vKipcbiAqIEBpbnRlcm5hbFxuICovXG5leHBvcnQgZnVuY3Rpb24gY2xlYXJDcmVkZW50aWFsQ2FjaGUoKTogdm9pZCB7XG4gIGNhY2hlUXVldWUubGVuZ3RoID0gMDtcbiAgT2JqZWN0LmtleXMoc2lnbmluZ0tleUNhY2hlKS5mb3JFYWNoKChjYWNoZUtleSkgPT4ge1xuICAgIGRlbGV0ZSBzaWduaW5nS2V5Q2FjaGVbY2FjaGVLZXldO1xuICB9KTtcbn1cblxuZnVuY3Rpb24gaG1hYyhjdG9yOiBIYXNoQ29uc3RydWN0b3IsIHNlY3JldDogU291cmNlRGF0YSwgZGF0YTogU291cmNlRGF0YSk6IFByb21pc2U8VWludDhBcnJheT4ge1xuICBjb25zdCBoYXNoID0gbmV3IGN0b3Ioc2VjcmV0KTtcbiAgaGFzaC51cGRhdGUoZGF0YSk7XG4gIHJldHVybiBoYXNoLmRpZ2VzdCgpO1xufVxuIl19 | ||
//# sourceMappingURL=data:application/json;base64,eyJ2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Moc2lnbmluZ0tleUNhY2hlKS5mb3JFYWNoKChjYWNoZUtleSkgPT4ge1xuICAgIGRlbGV0ZSBzaWduaW5nS2V5Q2FjaGVbY2FjaGVLZXldO1xuICB9KTtcbn1cblxuZnVuY3Rpb24gaG1hYyhjdG9yOiBIYXNoQ29uc3RydWN0b3IsIHNlY3JldDogU291cmNlRGF0YSwgZGF0YTogU291cmNlRGF0YSk6IFByb21pc2U8VWludDhBcnJheT4ge1xuICBjb25zdCBoYXNoID0gbmV3IGN0b3Ioc2VjcmV0KTtcbiAgaGFzaC51cGRhdGUoZGF0YSk7XG4gIHJldHVybiBoYXNoLmRpZ2VzdCgpO1xufVxuIl19 |
{ | ||
"name": "@aws-sdk/signature-v4", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "A standalone implementation of the AWS Signature V4 request signing algorithm", | ||
@@ -22,5 +22,5 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@aws-sdk/is-array-buffer": "3.0.0", | ||
"@aws-sdk/util-hex-encoding": "3.0.0", | ||
"@aws-sdk/util-uri-escape": "3.0.0", | ||
"@aws-sdk/is-array-buffer": "3.1.0", | ||
"@aws-sdk/util-hex-encoding": "3.1.0", | ||
"@aws-sdk/util-uri-escape": "3.1.0", | ||
"tslib": "^1.8.0" | ||
@@ -30,5 +30,5 @@ }, | ||
"@aws-crypto/sha256-js": "^1.0.0", | ||
"@aws-sdk/protocol-http": "3.0.0", | ||
"@aws-sdk/types": "3.0.0", | ||
"@aws-sdk/util-buffer-from": "3.0.0", | ||
"@aws-sdk/protocol-http": "3.1.0", | ||
"@aws-sdk/types": "3.1.0", | ||
"@aws-sdk/util-buffer-from": "3.1.0", | ||
"@types/jest": "^26.0.4", | ||
@@ -35,0 +35,0 @@ "jest": "^26.1.0", |
# @aws-sdk/signature-v4 | ||
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/signature-v4/rc.svg)](https://www.npmjs.com/package/@aws-sdk/signature-v4) | ||
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/signature-v4/latest.svg)](https://www.npmjs.com/package/@aws-sdk/signature-v4) | ||
[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/signature-v4.svg)](https://www.npmjs.com/package/@aws-sdk/signature-v4) |
import { Credentials, HashConstructor, SourceData } from "@aws-sdk/types"; | ||
import { toHex } from "@aws-sdk/util-hex-encoding"; | ||
import { KEY_TYPE_IDENTIFIER, MAX_CACHE_SIZE } from "./constants"; | ||
const signingKeyCache: { [key: string]: Promise<Uint8Array> } = {}; | ||
const signingKeyCache: { [key: string]: Uint8Array } = {}; | ||
const cacheQueue: Array<string> = []; | ||
@@ -31,3 +32,3 @@ | ||
*/ | ||
export function getSigningKey( | ||
export const getSigningKey = async ( | ||
sha256Constructor: HashConstructor, | ||
@@ -38,4 +39,5 @@ credentials: Credentials, | ||
service: string | ||
): Promise<Uint8Array> { | ||
const cacheKey = `${shortDate}:${region}:${service}:` + `${credentials.accessKeyId}:${credentials.sessionToken}`; | ||
): Promise<Uint8Array> => { | ||
const credsHash = await hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId); | ||
const cacheKey = `${shortDate}:${region}:${service}:${toHex(credsHash)}:${credentials.sessionToken}`; | ||
if (cacheKey in signingKeyCache) { | ||
@@ -50,17 +52,9 @@ return signingKeyCache[cacheKey]; | ||
return (signingKeyCache[cacheKey] = new Promise((resolve, reject) => { | ||
let keyPromise: Promise<SourceData> = Promise.resolve(`AWS4${credentials.secretAccessKey}`); | ||
let key: SourceData = `AWS4${credentials.secretAccessKey}`; | ||
for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) { | ||
key = await hmac(sha256Constructor, key, signable); | ||
} | ||
return (signingKeyCache[cacheKey] = key as Uint8Array); | ||
}; | ||
for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) { | ||
keyPromise = keyPromise.then<Uint8Array>((intermediateKey) => hmac(sha256Constructor, intermediateKey, signable)); | ||
keyPromise.catch(() => {}); | ||
} | ||
(keyPromise as Promise<Uint8Array>).then(resolve, (reason) => { | ||
delete signingKeyCache[cacheKey]; | ||
reject(reason); | ||
}); | ||
})); | ||
} | ||
/** | ||
@@ -67,0 +61,0 @@ * @internal |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3268
378968
+ Added@aws-sdk/is-array-buffer@3.1.0(transitive)
+ Added@aws-sdk/util-hex-encoding@3.1.0(transitive)
+ Added@aws-sdk/util-uri-escape@3.1.0(transitive)
- Removed@aws-sdk/is-array-buffer@3.0.0(transitive)
- Removed@aws-sdk/util-hex-encoding@3.0.0(transitive)
- Removed@aws-sdk/util-uri-escape@3.0.0(transitive)