@aws-sdk/signature-v4-multi-region 3.796.0 → 3.798.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/README.md +8 -2
- package/dist-cjs/index.js +55 -22
- package/dist-es/SignatureV4MultiRegion.js +62 -25
- package/dist-types/SignatureV4MultiRegion.d.ts +5 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@aws-sdk/signature-v4-multi-region)
|
|
5
5
|
|
|
6
6
|
See also https://github.com/aws/aws-sdk-js-v3/tree/main#functionality-requiring-aws-common-runtime-crt.
|
|
7
|
+
|
|
7
8
|
## Usage
|
|
8
9
|
|
|
9
10
|
This package contains optional dependency [`@aws-sdk/signature-v4-crt`](https://www.npmjs.com/package/@aws-sdk/signature-v4).
|
|
@@ -15,12 +16,17 @@ The `@aws-sdk/signature-v4-crt` is only supported in Node.js currently because i
|
|
|
15
16
|
|
|
16
17
|
Please refer to [this issue](https://github.com/aws/aws-sdk-js-v3/issues/2822) for more information.
|
|
17
18
|
|
|
19
|
+
Note: You can also use a native JS (non-CRT) implementation of the SigV4A signer, instructions for which are here:
|
|
20
|
+
https://github.com/aws/aws-sdk-js-v3/tree/main#functionality-requiring-aws-common-runtime-crt
|
|
21
|
+
|
|
22
|
+
Please refer to the note regarding bundle size in the link above, before deciding to use the JS SigV4A signer (including in browsers).
|
|
23
|
+
|
|
18
24
|
## Description
|
|
19
25
|
|
|
20
26
|
This package provides a SigV4-compatible request signer that wraps a pure-JS SigV4 signer
|
|
21
27
|
([`@aws-sdk/signature-v4`](https://www.npmjs.com/package/@aws-sdk/signature-v4)) for regional requests, and attempts to
|
|
22
28
|
call a native implementation of SigV4a signer([`@aws-sdk/signature-v4-crt`](https://www.npmjs.com/package/@aws-sdk/signature-v4))
|
|
23
|
-
it the request is
|
|
29
|
+
it the request is multi-region.
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
A multi-region request is identified by the `signingRegion` parameter. A request is multi-region if the `signingRegion`
|
|
26
32
|
parameter is set to `*`.
|
package/dist-cjs/index.js
CHANGED
|
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/SignatureV4MultiRegion.ts
|
|
30
30
|
var import_middleware_sdk_s3 = require("@aws-sdk/middleware-sdk-s3");
|
|
31
|
+
var import_signature_v4 = require("@smithy/signature-v4");
|
|
31
32
|
|
|
32
33
|
// src/signature-v4-crt-container.ts
|
|
33
34
|
var signatureV4CrtContainer = {
|
|
@@ -48,28 +49,43 @@ var SignatureV4MultiRegion = class {
|
|
|
48
49
|
}
|
|
49
50
|
async sign(requestToSign, options = {}) {
|
|
50
51
|
if (options.signingRegion === "*") {
|
|
51
|
-
if (this.signerOptions.runtime !== "node")
|
|
52
|
-
throw new Error("This request requires signing with SigV4Asymmetric algorithm. It's only available in Node.js");
|
|
53
52
|
return this.getSigv4aSigner().sign(requestToSign, options);
|
|
54
53
|
}
|
|
55
54
|
return this.sigv4Signer.sign(requestToSign, options);
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
58
57
|
* Sign with alternate credentials to the ones provided in the constructor.
|
|
58
|
+
* Note: This is only supported for SigV4a when using the CRT implementation.
|
|
59
59
|
*/
|
|
60
60
|
async signWithCredentials(requestToSign, credentials, options = {}) {
|
|
61
61
|
if (options.signingRegion === "*") {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const signer = this.getSigv4aSigner();
|
|
63
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
64
|
+
if (CrtSignerV4 && signer instanceof CrtSignerV4) {
|
|
65
|
+
return signer.signWithCredentials(requestToSign, credentials, options);
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`signWithCredentials with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
return this.sigv4Signer.signWithCredentials(requestToSign, credentials, options);
|
|
67
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Presign a request.
|
|
76
|
+
* Note: This is only supported for SigV4a when using the CRT implementation.
|
|
77
|
+
*/
|
|
68
78
|
async presign(originalRequest, options = {}) {
|
|
69
79
|
if (options.signingRegion === "*") {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
const signer = this.getSigv4aSigner();
|
|
81
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
82
|
+
if (CrtSignerV4 && signer instanceof CrtSignerV4) {
|
|
83
|
+
return signer.presign(originalRequest, options);
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`presign with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
73
89
|
}
|
|
74
90
|
return this.sigv4Signer.presign(originalRequest, options);
|
|
75
91
|
}
|
|
@@ -81,21 +97,38 @@ var SignatureV4MultiRegion = class {
|
|
|
81
97
|
}
|
|
82
98
|
getSigv4aSigner() {
|
|
83
99
|
if (!this.sigv4aSigner) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
101
|
+
const JsSigV4aSigner = import_signature_v4.signatureV4aContainer.SignatureV4a;
|
|
102
|
+
if (this.signerOptions.runtime === "node") {
|
|
103
|
+
if (!CrtSignerV4 && !JsSigV4aSigner) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
"Neither CRT nor JS SigV4a implementation is available. Please load either @aws-sdk/signature-v4-crt or @aws-sdk/signature-v4a. For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (CrtSignerV4 && typeof CrtSignerV4 === "function") {
|
|
109
|
+
this.sigv4aSigner = new CrtSignerV4({
|
|
110
|
+
...this.signerOptions,
|
|
111
|
+
signingAlgorithm: 1
|
|
112
|
+
});
|
|
113
|
+
} else if (JsSigV4aSigner && typeof JsSigV4aSigner === "function") {
|
|
114
|
+
this.sigv4aSigner = new JsSigV4aSigner({
|
|
115
|
+
...this.signerOptions
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Available SigV4a implementation is not a valid constructor. Please ensure you've properly imported @aws-sdk/signature-v4-crt or @aws-sdk/signature-v4a.For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
if (!JsSigV4aSigner || typeof JsSigV4aSigner !== "function") {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"JS SigV4a implementation is not available or not a valid constructor. Please check whether you have installed the @aws-sdk/signature-v4a package explicitly. The CRT implementation is not available for browsers. You must also register the package by calling [require('@aws-sdk/signature-v4a');] or an ESM equivalent such as [import '@aws-sdk/signature-v4a';]. For more information please go to https://github.com/aws/aws-sdk-js-v3#using-javascript-non-crt-implementation-of-sigv4a"
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
this.sigv4aSigner = new JsSigV4aSigner({
|
|
129
|
+
...this.signerOptions
|
|
130
|
+
});
|
|
94
131
|
}
|
|
95
|
-
this.sigv4aSigner = new CrtSignerV4({
|
|
96
|
-
...this.signerOptions,
|
|
97
|
-
signingAlgorithm: 1
|
|
98
|
-
});
|
|
99
132
|
}
|
|
100
133
|
return this.sigv4aSigner;
|
|
101
134
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SignatureV4S3Express } from "@aws-sdk/middleware-sdk-s3";
|
|
2
|
+
import { signatureV4aContainer, } from "@smithy/signature-v4";
|
|
2
3
|
import { signatureV4CrtContainer } from "./signature-v4-crt-container";
|
|
3
4
|
export class SignatureV4MultiRegion {
|
|
4
5
|
sigv4aSigner;
|
|
@@ -10,25 +11,41 @@ export class SignatureV4MultiRegion {
|
|
|
10
11
|
}
|
|
11
12
|
async sign(requestToSign, options = {}) {
|
|
12
13
|
if (options.signingRegion === "*") {
|
|
13
|
-
if (this.signerOptions.runtime !== "node")
|
|
14
|
-
throw new Error("This request requires signing with SigV4Asymmetric algorithm. It's only available in Node.js");
|
|
15
14
|
return this.getSigv4aSigner().sign(requestToSign, options);
|
|
16
15
|
}
|
|
17
16
|
return this.sigv4Signer.sign(requestToSign, options);
|
|
18
17
|
}
|
|
19
18
|
async signWithCredentials(requestToSign, credentials, options = {}) {
|
|
20
19
|
if (options.signingRegion === "*") {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const signer = this.getSigv4aSigner();
|
|
21
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
22
|
+
if (CrtSignerV4 && signer instanceof CrtSignerV4) {
|
|
23
|
+
return signer.signWithCredentials(requestToSign, credentials, options);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`signWithCredentials with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. ` +
|
|
27
|
+
`Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. ` +
|
|
28
|
+
`You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +
|
|
29
|
+
`or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. ` +
|
|
30
|
+
`For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt`);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
return this.sigv4Signer.signWithCredentials(requestToSign, credentials, options);
|
|
26
34
|
}
|
|
27
35
|
async presign(originalRequest, options = {}) {
|
|
28
36
|
if (options.signingRegion === "*") {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
const signer = this.getSigv4aSigner();
|
|
38
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
39
|
+
if (CrtSignerV4 && signer instanceof CrtSignerV4) {
|
|
40
|
+
return signer.presign(originalRequest, options);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`presign with signingRegion '*' is only supported when using the CRT dependency @aws-sdk/signature-v4-crt. ` +
|
|
44
|
+
`Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. ` +
|
|
45
|
+
`You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +
|
|
46
|
+
`or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. ` +
|
|
47
|
+
`For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt`);
|
|
48
|
+
}
|
|
32
49
|
}
|
|
33
50
|
return this.sigv4Signer.presign(originalRequest, options);
|
|
34
51
|
}
|
|
@@ -40,26 +57,46 @@ export class SignatureV4MultiRegion {
|
|
|
40
57
|
}
|
|
41
58
|
getSigv4aSigner() {
|
|
42
59
|
if (!this.sigv4aSigner) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
throw new Error(
|
|
60
|
+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
|
|
61
|
+
const JsSigV4aSigner = signatureV4aContainer.SignatureV4a;
|
|
62
|
+
if (this.signerOptions.runtime === "node") {
|
|
63
|
+
if (!CrtSignerV4 && !JsSigV4aSigner) {
|
|
64
|
+
throw new Error("Neither CRT nor JS SigV4a implementation is available. " +
|
|
65
|
+
"Please load either @aws-sdk/signature-v4-crt or @aws-sdk/signature-v4a. " +
|
|
66
|
+
"For more information please go to " +
|
|
67
|
+
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt");
|
|
68
|
+
}
|
|
69
|
+
if (CrtSignerV4 && typeof CrtSignerV4 === "function") {
|
|
70
|
+
this.sigv4aSigner = new CrtSignerV4({
|
|
71
|
+
...this.signerOptions,
|
|
72
|
+
signingAlgorithm: 1,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else if (JsSigV4aSigner && typeof JsSigV4aSigner === "function") {
|
|
76
|
+
this.sigv4aSigner = new JsSigV4aSigner({
|
|
77
|
+
...this.signerOptions,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error("Available SigV4a implementation is not a valid constructor. " +
|
|
82
|
+
"Please ensure you've properly imported @aws-sdk/signature-v4-crt or @aws-sdk/signature-v4a." +
|
|
83
|
+
"For more information please go to " +
|
|
84
|
+
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt");
|
|
85
|
+
}
|
|
48
86
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
else {
|
|
88
|
+
if (!JsSigV4aSigner || typeof JsSigV4aSigner !== "function") {
|
|
89
|
+
throw new Error("JS SigV4a implementation is not available or not a valid constructor. " +
|
|
90
|
+
"Please check whether you have installed the @aws-sdk/signature-v4a package explicitly. The CRT implementation is not available for browsers. " +
|
|
91
|
+
"You must also register the package by calling [require('@aws-sdk/signature-v4a');] " +
|
|
92
|
+
"or an ESM equivalent such as [import '@aws-sdk/signature-v4a';]. " +
|
|
55
93
|
"For more information please go to " +
|
|
56
|
-
"https://github.com/aws/aws-sdk-js-v3#
|
|
57
|
-
|
|
94
|
+
"https://github.com/aws/aws-sdk-js-v3#using-javascript-non-crt-implementation-of-sigv4a");
|
|
95
|
+
}
|
|
96
|
+
this.sigv4aSigner = new JsSigV4aSigner({
|
|
97
|
+
...this.signerOptions,
|
|
98
|
+
});
|
|
58
99
|
}
|
|
59
|
-
this.sigv4aSigner = new CrtSignerV4({
|
|
60
|
-
...this.signerOptions,
|
|
61
|
-
signingAlgorithm: 1,
|
|
62
|
-
});
|
|
63
100
|
}
|
|
64
101
|
return this.sigv4aSigner;
|
|
65
102
|
}
|
|
@@ -11,7 +11,6 @@ export type SignatureV4MultiRegionInit = SignatureV4Init & SignatureV4CryptoInit
|
|
|
11
11
|
* dynamically, the signer wraps native module SigV4a signer and JS SigV4 signer. It signs the request with SigV4a
|
|
12
12
|
* algorithm if the request needs to be signed with `*` region. Otherwise, it signs the request with normal SigV4
|
|
13
13
|
* signer.
|
|
14
|
-
* Note that SigV4a signer is only supported in Node.js now because it depends on a native dependency.
|
|
15
14
|
* @internal
|
|
16
15
|
*/
|
|
17
16
|
export declare class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
|
|
@@ -22,8 +21,13 @@ export declare class SignatureV4MultiRegion implements RequestPresigner, Request
|
|
|
22
21
|
sign(requestToSign: HttpRequest, options?: RequestSigningArguments): Promise<HttpRequest>;
|
|
23
22
|
/**
|
|
24
23
|
* Sign with alternate credentials to the ones provided in the constructor.
|
|
24
|
+
* Note: This is only supported for SigV4a when using the CRT implementation.
|
|
25
25
|
*/
|
|
26
26
|
signWithCredentials(requestToSign: HttpRequest, credentials: AwsCredentialIdentity, options?: RequestSigningArguments): Promise<HttpRequest>;
|
|
27
|
+
/**
|
|
28
|
+
* Presign a request.
|
|
29
|
+
* Note: This is only supported for SigV4a when using the CRT implementation.
|
|
30
|
+
*/
|
|
27
31
|
presign(originalRequest: HttpRequest, options?: RequestPresigningArguments): Promise<HttpRequest>;
|
|
28
32
|
presignWithCredentials(originalRequest: HttpRequest, credentials: AwsCredentialIdentity, options?: RequestPresigningArguments): Promise<HttpRequest>;
|
|
29
33
|
private getSigv4aSigner;
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/signature-v4-multi-region",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.798.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline signature-v4-multi-region",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
|
+
"build:browser": "node ./test-browser/browser-build/esbuild",
|
|
8
9
|
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
|
|
9
10
|
"build:types": "tsc -p tsconfig.types.json",
|
|
10
11
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
11
12
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
|
|
12
13
|
"test": "yarn g:vitest run",
|
|
14
|
+
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.ts",
|
|
15
|
+
"test:browser": "yarn build:browser && yarn g:vitest run -c vitest.config.browser.ts",
|
|
13
16
|
"test:watch": "yarn g:vitest watch"
|
|
14
17
|
},
|
|
15
18
|
"main": "./dist-cjs/index.js",
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
},
|
|
22
25
|
"license": "Apache-2.0",
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@aws-sdk/middleware-sdk-s3": "3.
|
|
27
|
+
"@aws-sdk/middleware-sdk-s3": "3.798.0",
|
|
25
28
|
"@aws-sdk/types": "3.775.0",
|
|
26
29
|
"@smithy/protocol-http": "^5.1.0",
|
|
27
30
|
"@smithy/signature-v4": "^5.1.0",
|