@vercel/kms 0.1.3 → 0.2.1
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 +16 -0
- package/README.md +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/request.d.ts +0 -15
- package/dist/sign-message.d.ts +14 -3
- package/dist/sign-message.js +5 -2
- package/dist/sign-message.test.js +26 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/README.md +1 -1
- package/docs/functions/signMessage.md +5 -4
- package/docs/interfaces/SignMessageResult.md +39 -0
- package/package.json +2 -2
- package/docs/interfaces/FlattenedJWS.md +0 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @vercel/kms
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @vercel/oidc@3.8.9
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- b6ef92b: `signMessage` now returns `{ signature, keyId, algorithm }` instead of a Flattened JWS, with `signature` as a `Uint8Array`.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @vercel/oidc@3.8.8
|
|
18
|
+
|
|
3
19
|
## 0.1.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ const token = await signToken({
|
|
|
28
28
|
import { signMessage } from '@vercel/kms';
|
|
29
29
|
|
|
30
30
|
// `message` is a UTF-8 string or raw bytes (Uint8Array); it is base64-encoded
|
|
31
|
-
// internally. Returns
|
|
32
|
-
const signature = await signMessage({
|
|
31
|
+
// internally. Returns `{ signature, keyId, algorithm }`.
|
|
32
|
+
const { signature, keyId, algorithm } = await signMessage({
|
|
33
33
|
issuerId: 'issuer_abc123',
|
|
34
34
|
message: 'hello world',
|
|
35
35
|
});
|
|
@@ -77,4 +77,4 @@ Signs a message for an issuer.
|
|
|
77
77
|
- `region?: string` — Region for the regional KMS API host, e.g. `sfo1`, producing `https://api-<region>.vercel.com/v1`. Defaults to the `VERCEL_REGION` environment variable, falling back to `https://api.vercel.com/v1`. Ignored when `baseUrl` is set.
|
|
78
78
|
- `baseUrl?: string` — Override the API base URL. Takes precedence over `region`.
|
|
79
79
|
|
|
80
|
-
Returns `Promise<
|
|
80
|
+
Returns `Promise<{ signature: Uint8Array, keyId: string, algorithm: string }>` — the raw signature bytes, plus the key id and algorithm of the signing key.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { signToken, type SignTokenOptions } from './sign-token';
|
|
2
|
-
export { signMessage, type SignMessageOptions } from './sign-message';
|
|
2
|
+
export { signMessage, type SignMessageOptions, type SignMessageResult, } from './sign-message';
|
|
3
3
|
export { VercelKmsError } from './errors';
|
|
4
|
-
export type { FlattenedJWS } from './request';
|
package/dist/request.d.ts
CHANGED
|
@@ -14,21 +14,6 @@ export declare function resolveBaseUrl({ region, baseUrl, }: {
|
|
|
14
14
|
region?: string;
|
|
15
15
|
baseUrl?: string;
|
|
16
16
|
}): string;
|
|
17
|
-
/**
|
|
18
|
-
* A JOSE Flattened JWS, as returned by the message-signing endpoint.
|
|
19
|
-
*
|
|
20
|
-
* @see https://datatracker.ietf.org/doc/html/rfc7515#section-7.2.2
|
|
21
|
-
*/
|
|
22
|
-
export interface FlattenedJWS {
|
|
23
|
-
/** Base64url-encoded JWS payload. */
|
|
24
|
-
payload: string;
|
|
25
|
-
/** Base64url-encoded JWS signature. */
|
|
26
|
-
signature: string;
|
|
27
|
-
/** Base64url-encoded protected header. */
|
|
28
|
-
protected?: string;
|
|
29
|
-
/** Optional unprotected JWS header. */
|
|
30
|
-
header?: Record<string, unknown>;
|
|
31
|
-
}
|
|
32
17
|
/**
|
|
33
18
|
* Performs an authenticated POST to a Vercel KMS sign endpoint and returns the
|
|
34
19
|
* parsed JSON body. Throws {@link VercelKmsError} on a non-2xx response.
|
package/dist/sign-message.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type FlattenedJWS } from './request';
|
|
2
1
|
/**
|
|
3
2
|
* Options for {@link signMessage}.
|
|
4
3
|
*/
|
|
@@ -29,11 +28,23 @@ export interface SignMessageOptions {
|
|
|
29
28
|
*/
|
|
30
29
|
baseUrl?: string;
|
|
31
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of {@link signMessage}.
|
|
33
|
+
*/
|
|
34
|
+
export interface SignMessageResult {
|
|
35
|
+
/** Raw signature over the message bytes. */
|
|
36
|
+
signature: Uint8Array;
|
|
37
|
+
/** Key id of the signing key. Matches the JWKS `kid`. */
|
|
38
|
+
keyId: string;
|
|
39
|
+
/** Algorithm of the signing key. */
|
|
40
|
+
algorithm: string;
|
|
41
|
+
}
|
|
32
42
|
/**
|
|
33
43
|
* Signs a message for an issuer using its managed signing key and returns the
|
|
34
|
-
*
|
|
44
|
+
* raw signature over the message bytes, plus the `keyId` and `algorithm` of
|
|
45
|
+
* the key that produced it. The message may be provided as raw bytes
|
|
35
46
|
* (`Uint8Array`) or a UTF-8 `string`; it is base64-encoded before being sent.
|
|
36
47
|
*
|
|
37
48
|
* @throws {import('./errors').VercelKmsError} If the sign request fails.
|
|
38
49
|
*/
|
|
39
|
-
export declare function signMessage(options: SignMessageOptions): Promise<
|
|
50
|
+
export declare function signMessage(options: SignMessageOptions): Promise<SignMessageResult>;
|
package/dist/sign-message.js
CHANGED
|
@@ -30,17 +30,20 @@ async function signMessage(options) {
|
|
|
30
30
|
baseUrl: options.baseUrl
|
|
31
31
|
});
|
|
32
32
|
const oidcToken = await (0, import_resolve_token.resolveOidcToken)({ token });
|
|
33
|
-
const { signature } = await (0, import_request.postJson)({
|
|
33
|
+
const { signature, keyId, algorithm } = await (0, import_request.postJson)({
|
|
34
34
|
baseUrl,
|
|
35
35
|
path: `/kms/issuers/${encodeURIComponent(issuerId)}/sign/message`,
|
|
36
36
|
token: oidcToken,
|
|
37
37
|
body: { message: toBase64(message) }
|
|
38
38
|
});
|
|
39
|
-
return signature;
|
|
39
|
+
return { signature: fromBase64(signature), keyId, algorithm };
|
|
40
40
|
}
|
|
41
41
|
function toBase64(message) {
|
|
42
42
|
return (typeof message === "string" ? Buffer.from(message, "utf-8") : Buffer.from(message)).toString("base64");
|
|
43
43
|
}
|
|
44
|
+
function fromBase64(value) {
|
|
45
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
46
|
+
}
|
|
44
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
48
|
0 && (module.exports = {
|
|
46
49
|
signMessage
|
|
@@ -7,10 +7,22 @@ import_vitest.vi.mock("@vercel/oidc", () => ({
|
|
|
7
7
|
}));
|
|
8
8
|
const getVercelOidcTokenMock = import_vitest.vi.mocked(import_oidc.getVercelOidcToken);
|
|
9
9
|
const OIDC_TOKEN = "oidc-token";
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const SIGNATURE_B64 = "c2lnbmF0dXJl";
|
|
11
|
+
const SIGNATURE_BYTES = new Uint8Array([
|
|
12
|
+
115,
|
|
13
|
+
105,
|
|
14
|
+
103,
|
|
15
|
+
110,
|
|
16
|
+
97,
|
|
17
|
+
116,
|
|
18
|
+
117,
|
|
19
|
+
114,
|
|
20
|
+
101
|
|
21
|
+
]);
|
|
22
|
+
const SIGNED_MESSAGE = {
|
|
23
|
+
signature: SIGNATURE_B64,
|
|
24
|
+
keyId: "key_a",
|
|
25
|
+
algorithm: "EdDSA"
|
|
14
26
|
};
|
|
15
27
|
function fetchReturning(body, init) {
|
|
16
28
|
return async () => new Response(JSON.stringify(body), { status: 200, ...init });
|
|
@@ -21,14 +33,18 @@ function fetchReturning(body, init) {
|
|
|
21
33
|
getVercelOidcTokenMock.mockReset();
|
|
22
34
|
delete process.env.VERCEL_REGION;
|
|
23
35
|
});
|
|
24
|
-
(0, import_vitest.test)("signs a string message (UTF-8) and returns the
|
|
36
|
+
(0, import_vitest.test)("signs a string message (UTF-8) and returns the raw signature", async () => {
|
|
25
37
|
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
26
|
-
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(
|
|
38
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(SIGNED_MESSAGE));
|
|
27
39
|
const result = await (0, import_sign_message.signMessage)({
|
|
28
40
|
issuerId: "issuer_a",
|
|
29
41
|
message: "hello"
|
|
30
42
|
});
|
|
31
|
-
(0, import_vitest.expect)(result).toEqual(
|
|
43
|
+
(0, import_vitest.expect)(result).toEqual({
|
|
44
|
+
signature: SIGNATURE_BYTES,
|
|
45
|
+
keyId: "key_a",
|
|
46
|
+
algorithm: "EdDSA"
|
|
47
|
+
});
|
|
32
48
|
(0, import_vitest.expect)(getVercelOidcTokenMock).toHaveBeenCalledWith();
|
|
33
49
|
const [url, init] = fetchMock.mock.calls[0];
|
|
34
50
|
(0, import_vitest.expect)(url.toString()).toBe(
|
|
@@ -38,7 +54,7 @@ function fetchReturning(body, init) {
|
|
|
38
54
|
});
|
|
39
55
|
(0, import_vitest.test)("base64-encodes a Uint8Array message before sending", async () => {
|
|
40
56
|
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
41
|
-
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(
|
|
57
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(SIGNED_MESSAGE));
|
|
42
58
|
await (0, import_sign_message.signMessage)({
|
|
43
59
|
issuerId: "issuer_bytes",
|
|
44
60
|
// Raw bytes for "hello".
|
|
@@ -49,7 +65,7 @@ function fetchReturning(body, init) {
|
|
|
49
65
|
});
|
|
50
66
|
(0, import_vitest.test)("targets the regional host when a region is provided", async () => {
|
|
51
67
|
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
52
|
-
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(
|
|
68
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(SIGNED_MESSAGE));
|
|
53
69
|
await (0, import_sign_message.signMessage)({
|
|
54
70
|
issuerId: "issuer_region",
|
|
55
71
|
message: "bXNn",
|
|
@@ -61,7 +77,7 @@ function fetchReturning(body, init) {
|
|
|
61
77
|
);
|
|
62
78
|
});
|
|
63
79
|
(0, import_vitest.test)("uses an explicit token without fetching an OIDC token", async () => {
|
|
64
|
-
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(
|
|
80
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning(SIGNED_MESSAGE));
|
|
65
81
|
await (0, import_sign_message.signMessage)({
|
|
66
82
|
issuerId: "issuer_explicit",
|
|
67
83
|
message: "bXNn",
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.1
|
|
1
|
+
export declare const version = "0.2.1";
|
package/dist/version.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
version: () => version
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const version = "0.1
|
|
24
|
+
const version = "0.2.1";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
version
|
package/docs/README.md
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
## Interfaces
|
|
12
12
|
|
|
13
|
-
- [FlattenedJWS](interfaces/FlattenedJWS.md)
|
|
14
13
|
- [SignMessageOptions](interfaces/SignMessageOptions.md)
|
|
14
|
+
- [SignMessageResult](interfaces/SignMessageResult.md)
|
|
15
15
|
- [SignTokenOptions](interfaces/SignTokenOptions.md)
|
|
16
16
|
|
|
17
17
|
## Functions
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
# Function: signMessage()
|
|
6
6
|
|
|
7
|
-
> **signMessage**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`
|
|
7
|
+
> **signMessage**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`SignMessageResult`](../interfaces/SignMessageResult.md)\>
|
|
8
8
|
|
|
9
|
-
Defined in: [packages/kms/src/sign-message.ts:
|
|
9
|
+
Defined in: [packages/kms/src/sign-message.ts:55](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L55)
|
|
10
10
|
|
|
11
11
|
Signs a message for an issuer using its managed signing key and returns the
|
|
12
|
-
|
|
12
|
+
raw signature over the message bytes, plus the `keyId` and `algorithm` of
|
|
13
|
+
the key that produced it. The message may be provided as raw bytes
|
|
13
14
|
(`Uint8Array`) or a UTF-8 `string`; it is base64-encoded before being sent.
|
|
14
15
|
|
|
15
16
|
## Parameters
|
|
@@ -20,7 +21,7 @@ resulting JOSE Flattened JWS. The message may be provided as raw bytes
|
|
|
20
21
|
|
|
21
22
|
## Returns
|
|
22
23
|
|
|
23
|
-
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`
|
|
24
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`SignMessageResult`](../interfaces/SignMessageResult.md)\>
|
|
24
25
|
|
|
25
26
|
## Throws
|
|
26
27
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**@vercel/kms**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Interface: SignMessageResult
|
|
6
|
+
|
|
7
|
+
Defined in: [packages/kms/src/sign-message.ts:38](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L38)
|
|
8
|
+
|
|
9
|
+
Result of [signMessage](../functions/signMessage.md).
|
|
10
|
+
|
|
11
|
+
## Properties
|
|
12
|
+
|
|
13
|
+
### algorithm
|
|
14
|
+
|
|
15
|
+
> **algorithm**: `string`
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/kms/src/sign-message.ts:44](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L44)
|
|
18
|
+
|
|
19
|
+
Algorithm of the signing key.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### keyId
|
|
24
|
+
|
|
25
|
+
> **keyId**: `string`
|
|
26
|
+
|
|
27
|
+
Defined in: [packages/kms/src/sign-message.ts:42](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L42)
|
|
28
|
+
|
|
29
|
+
Key id of the signing key. Matches the JWKS `kid`.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### signature
|
|
34
|
+
|
|
35
|
+
> **signature**: [`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
|
|
36
|
+
|
|
37
|
+
Defined in: [packages/kms/src/sign-message.ts:40](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L40)
|
|
38
|
+
|
|
39
|
+
Raw signature over the message bytes.
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"require": "./dist/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"version": "0.1
|
|
17
|
+
"version": "0.2.1",
|
|
18
18
|
"repository": {
|
|
19
19
|
"directory": "packages/kms",
|
|
20
20
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/vercel/vercel/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@vercel/oidc": "3.8.
|
|
27
|
+
"@vercel/oidc": "3.8.9"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"prettier": "3.8.3",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
[**@vercel/kms**](../README.md)
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Interface: FlattenedJWS
|
|
6
|
-
|
|
7
|
-
Defined in: [packages/kms/src/request.ts:36](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/request.ts#L36)
|
|
8
|
-
|
|
9
|
-
A JOSE Flattened JWS, as returned by the message-signing endpoint.
|
|
10
|
-
|
|
11
|
-
## See
|
|
12
|
-
|
|
13
|
-
https://datatracker.ietf.org/doc/html/rfc7515#section-7.2.2
|
|
14
|
-
|
|
15
|
-
## Properties
|
|
16
|
-
|
|
17
|
-
### header?
|
|
18
|
-
|
|
19
|
-
> `optional` **header?**: [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `unknown`\>
|
|
20
|
-
|
|
21
|
-
Defined in: [packages/kms/src/request.ts:44](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/request.ts#L44)
|
|
22
|
-
|
|
23
|
-
Optional unprotected JWS header.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
### payload
|
|
28
|
-
|
|
29
|
-
> **payload**: `string`
|
|
30
|
-
|
|
31
|
-
Defined in: [packages/kms/src/request.ts:38](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/request.ts#L38)
|
|
32
|
-
|
|
33
|
-
Base64url-encoded JWS payload.
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
### protected?
|
|
38
|
-
|
|
39
|
-
> `optional` **protected?**: `string`
|
|
40
|
-
|
|
41
|
-
Defined in: [packages/kms/src/request.ts:42](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/request.ts#L42)
|
|
42
|
-
|
|
43
|
-
Base64url-encoded protected header.
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
### signature
|
|
48
|
-
|
|
49
|
-
> **signature**: `string`
|
|
50
|
-
|
|
51
|
-
Defined in: [packages/kms/src/request.ts:40](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/request.ts#L40)
|
|
52
|
-
|
|
53
|
-
Base64url-encoded JWS signature.
|