@vercel/kms 0.0.0 → 0.1.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 +13 -0
- package/LICENSE +202 -0
- package/README.md +79 -2
- package/dist/errors.d.ts +20 -0
- package/dist/errors.js +41 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +34 -0
- package/dist/request.d.ts +41 -0
- package/dist/request.js +105 -0
- package/dist/request.test.js +39 -0
- package/dist/resolve-token.d.ts +9 -0
- package/dist/resolve-token.js +36 -0
- package/dist/sign-message.d.ts +39 -0
- package/dist/sign-message.js +47 -0
- package/dist/sign-message.test.d.ts +1 -0
- package/dist/sign-message.test.js +97 -0
- package/dist/sign-token.d.ts +37 -0
- package/dist/sign-token.js +44 -0
- package/dist/sign-token.test.d.ts +1 -0
- package/dist/sign-token.test.js +82 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +28 -0
- package/docs/README.md +20 -0
- package/docs/classes/VercelKmsError.md +190 -0
- package/docs/functions/signMessage.md +27 -0
- package/docs/functions/signToken.md +26 -0
- package/docs/interfaces/FlattenedJWS.md +53 -0
- package/docs/interfaces/SignMessageOptions.md +71 -0
- package/docs/interfaces/SignTokenOptions.md +89 -0
- package/package.json +46 -11
- /package/{index.js → dist/request.test.d.ts} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sign_message_exports = {};
|
|
20
|
+
__export(sign_message_exports, {
|
|
21
|
+
signMessage: () => signMessage
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sign_message_exports);
|
|
24
|
+
var import_request = require("./request");
|
|
25
|
+
var import_resolve_token = require("./resolve-token");
|
|
26
|
+
async function signMessage(options) {
|
|
27
|
+
const { issuerId, message, token } = options;
|
|
28
|
+
const baseUrl = (0, import_request.resolveBaseUrl)({
|
|
29
|
+
region: options.region,
|
|
30
|
+
baseUrl: options.baseUrl
|
|
31
|
+
});
|
|
32
|
+
const oidcToken = await (0, import_resolve_token.resolveOidcToken)({ token });
|
|
33
|
+
const { signature } = await (0, import_request.postJson)({
|
|
34
|
+
baseUrl,
|
|
35
|
+
path: `/kms/issuers/${encodeURIComponent(issuerId)}/sign/message`,
|
|
36
|
+
token: oidcToken,
|
|
37
|
+
body: { message: toBase64(message) }
|
|
38
|
+
});
|
|
39
|
+
return signature;
|
|
40
|
+
}
|
|
41
|
+
function toBase64(message) {
|
|
42
|
+
return (typeof message === "string" ? Buffer.from(message, "utf-8") : Buffer.from(message)).toString("base64");
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
signMessage
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_oidc = require("@vercel/oidc");
|
|
4
|
+
var import_sign_message = require("./sign-message");
|
|
5
|
+
import_vitest.vi.mock("@vercel/oidc", () => ({
|
|
6
|
+
getVercelOidcToken: import_vitest.vi.fn()
|
|
7
|
+
}));
|
|
8
|
+
const getVercelOidcTokenMock = import_vitest.vi.mocked(import_oidc.getVercelOidcToken);
|
|
9
|
+
const OIDC_TOKEN = "oidc-token";
|
|
10
|
+
const SIGNATURE = {
|
|
11
|
+
payload: "cGF5bG9hZA",
|
|
12
|
+
signature: "c2ln",
|
|
13
|
+
protected: "cHJvdGVjdGVk"
|
|
14
|
+
};
|
|
15
|
+
function fetchReturning(body, init) {
|
|
16
|
+
return async () => new Response(JSON.stringify(body), { status: 200, ...init });
|
|
17
|
+
}
|
|
18
|
+
(0, import_vitest.describe)("signMessage", () => {
|
|
19
|
+
(0, import_vitest.beforeEach)(() => {
|
|
20
|
+
import_vitest.vi.restoreAllMocks();
|
|
21
|
+
getVercelOidcTokenMock.mockReset();
|
|
22
|
+
delete process.env.VERCEL_REGION;
|
|
23
|
+
});
|
|
24
|
+
(0, import_vitest.test)("signs a string message (UTF-8) and returns the flattened JWS", async () => {
|
|
25
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
26
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ signature: SIGNATURE }));
|
|
27
|
+
const result = await (0, import_sign_message.signMessage)({
|
|
28
|
+
issuerId: "issuer_a",
|
|
29
|
+
message: "hello"
|
|
30
|
+
});
|
|
31
|
+
(0, import_vitest.expect)(result).toEqual(SIGNATURE);
|
|
32
|
+
(0, import_vitest.expect)(getVercelOidcTokenMock).toHaveBeenCalledWith();
|
|
33
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
34
|
+
(0, import_vitest.expect)(url.toString()).toBe(
|
|
35
|
+
"https://api.vercel.com/v1/kms/issuers/issuer_a/sign/message"
|
|
36
|
+
);
|
|
37
|
+
(0, import_vitest.expect)(JSON.parse(init?.body)).toEqual({ message: "aGVsbG8=" });
|
|
38
|
+
});
|
|
39
|
+
(0, import_vitest.test)("base64-encodes a Uint8Array message before sending", async () => {
|
|
40
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
41
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ signature: SIGNATURE }));
|
|
42
|
+
await (0, import_sign_message.signMessage)({
|
|
43
|
+
issuerId: "issuer_bytes",
|
|
44
|
+
// Raw bytes for "hello".
|
|
45
|
+
message: new Uint8Array([104, 101, 108, 108, 111])
|
|
46
|
+
});
|
|
47
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
48
|
+
(0, import_vitest.expect)(JSON.parse(init?.body)).toEqual({ message: "aGVsbG8=" });
|
|
49
|
+
});
|
|
50
|
+
(0, import_vitest.test)("targets the regional host when a region is provided", async () => {
|
|
51
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
52
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ signature: SIGNATURE }));
|
|
53
|
+
await (0, import_sign_message.signMessage)({
|
|
54
|
+
issuerId: "issuer_region",
|
|
55
|
+
message: "bXNn",
|
|
56
|
+
region: "sfo1"
|
|
57
|
+
});
|
|
58
|
+
const [url] = fetchMock.mock.calls[0];
|
|
59
|
+
(0, import_vitest.expect)(url.toString()).toBe(
|
|
60
|
+
"https://api-sfo1.vercel.com/v1/kms/issuers/issuer_region/sign/message"
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
(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({ signature: SIGNATURE }));
|
|
65
|
+
await (0, import_sign_message.signMessage)({
|
|
66
|
+
issuerId: "issuer_explicit",
|
|
67
|
+
message: "bXNn",
|
|
68
|
+
token: "my-token"
|
|
69
|
+
});
|
|
70
|
+
(0, import_vitest.expect)(getVercelOidcTokenMock).not.toHaveBeenCalled();
|
|
71
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
72
|
+
(0, import_vitest.expect)((init?.headers).authorization).toBe(
|
|
73
|
+
"Bearer my-token"
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
(0, import_vitest.test)("throws a VercelKmsError when message signing is not allowed", async () => {
|
|
77
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
78
|
+
import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(
|
|
79
|
+
fetchReturning(
|
|
80
|
+
{
|
|
81
|
+
error: {
|
|
82
|
+
code: "message_signing_not_allowed",
|
|
83
|
+
message: "use sign-token"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{ status: 403, statusText: "Forbidden" }
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
await (0, import_vitest.expect)(
|
|
90
|
+
(0, import_sign_message.signMessage)({ issuerId: "x", message: "bXNn" })
|
|
91
|
+
).rejects.toMatchObject({
|
|
92
|
+
name: "VercelKmsError",
|
|
93
|
+
status: 403,
|
|
94
|
+
code: "message_signing_not_allowed"
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link signToken}.
|
|
3
|
+
*/
|
|
4
|
+
export interface SignTokenOptions {
|
|
5
|
+
/** The ID of the issuer whose signing key should sign the token. */
|
|
6
|
+
issuerId: string;
|
|
7
|
+
/** The claims to include in the token. */
|
|
8
|
+
claims?: Record<string, unknown>;
|
|
9
|
+
/** Additional headers to include in the token. */
|
|
10
|
+
headers?: Record<string, unknown>;
|
|
11
|
+
/** The time-to-live for the token, in seconds. Defaults to 300. */
|
|
12
|
+
ttl?: number | null;
|
|
13
|
+
/**
|
|
14
|
+
* An explicit Vercel OIDC token to authenticate with. When omitted, the
|
|
15
|
+
* function's OIDC token is fetched automatically via `@vercel/oidc`.
|
|
16
|
+
*/
|
|
17
|
+
token?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Region for the regional KMS API host, e.g. `sfo1`, producing
|
|
20
|
+
* `https://api-<region>.vercel.com/v1`. Defaults to the `VERCEL_REGION`
|
|
21
|
+
* environment variable, falling back to the global `api.vercel.com` host.
|
|
22
|
+
* Ignored when `baseUrl` is provided.
|
|
23
|
+
*/
|
|
24
|
+
region?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Override the API base URL. Takes precedence over `region`.
|
|
27
|
+
* @default "https://api-<region>.vercel.com/v1" or "https://api.vercel.com/v1"
|
|
28
|
+
*/
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Signs a JWT for an issuer using its managed signing key and returns the
|
|
33
|
+
* compact JWT string.
|
|
34
|
+
*
|
|
35
|
+
* @throws {import('./errors').VercelKmsError} If the sign request fails.
|
|
36
|
+
*/
|
|
37
|
+
export declare function signToken(options: SignTokenOptions): Promise<string>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sign_token_exports = {};
|
|
20
|
+
__export(sign_token_exports, {
|
|
21
|
+
signToken: () => signToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sign_token_exports);
|
|
24
|
+
var import_request = require("./request");
|
|
25
|
+
var import_resolve_token = require("./resolve-token");
|
|
26
|
+
async function signToken(options) {
|
|
27
|
+
const { issuerId, claims = {}, headers = {}, ttl = 300, token } = options;
|
|
28
|
+
const baseUrl = (0, import_request.resolveBaseUrl)({
|
|
29
|
+
region: options.region,
|
|
30
|
+
baseUrl: options.baseUrl
|
|
31
|
+
});
|
|
32
|
+
const oidcToken = await (0, import_resolve_token.resolveOidcToken)({ token });
|
|
33
|
+
const { token: signedToken } = await (0, import_request.postJson)({
|
|
34
|
+
baseUrl,
|
|
35
|
+
path: `/kms/issuers/${encodeURIComponent(issuerId)}/sign/token`,
|
|
36
|
+
token: oidcToken,
|
|
37
|
+
body: { claims, headers, ttl }
|
|
38
|
+
});
|
|
39
|
+
return signedToken;
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
signToken
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_oidc = require("@vercel/oidc");
|
|
4
|
+
var import_sign_token = require("./sign-token");
|
|
5
|
+
var import_errors = require("./errors");
|
|
6
|
+
import_vitest.vi.mock("@vercel/oidc", () => ({
|
|
7
|
+
getVercelOidcToken: import_vitest.vi.fn()
|
|
8
|
+
}));
|
|
9
|
+
const getVercelOidcTokenMock = import_vitest.vi.mocked(import_oidc.getVercelOidcToken);
|
|
10
|
+
const OIDC_TOKEN = "oidc-token";
|
|
11
|
+
const SIGNED_TOKEN = "signed.jwt.token";
|
|
12
|
+
function fetchReturning(body, init) {
|
|
13
|
+
return async () => new Response(JSON.stringify(body), { status: 200, ...init });
|
|
14
|
+
}
|
|
15
|
+
(0, import_vitest.describe)("signToken", () => {
|
|
16
|
+
(0, import_vitest.beforeEach)(() => {
|
|
17
|
+
import_vitest.vi.restoreAllMocks();
|
|
18
|
+
getVercelOidcTokenMock.mockReset();
|
|
19
|
+
delete process.env.VERCEL_REGION;
|
|
20
|
+
});
|
|
21
|
+
(0, import_vitest.test)("signs a token and returns the JWT string", async () => {
|
|
22
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
23
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ token: SIGNED_TOKEN }));
|
|
24
|
+
const result = await (0, import_sign_token.signToken)({
|
|
25
|
+
issuerId: "issuer_a",
|
|
26
|
+
claims: { sub: "user" }
|
|
27
|
+
});
|
|
28
|
+
(0, import_vitest.expect)(result).toBe(SIGNED_TOKEN);
|
|
29
|
+
(0, import_vitest.expect)(getVercelOidcTokenMock).toHaveBeenCalledWith();
|
|
30
|
+
(0, import_vitest.expect)(fetchMock).toHaveBeenCalledTimes(1);
|
|
31
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
32
|
+
(0, import_vitest.expect)(url.toString()).toBe(
|
|
33
|
+
"https://api.vercel.com/v1/kms/issuers/issuer_a/sign/token"
|
|
34
|
+
);
|
|
35
|
+
(0, import_vitest.expect)(init?.method).toBe("POST");
|
|
36
|
+
(0, import_vitest.expect)((init?.headers).authorization).toBe(
|
|
37
|
+
`Bearer ${OIDC_TOKEN}`
|
|
38
|
+
);
|
|
39
|
+
(0, import_vitest.expect)(JSON.parse(init?.body)).toEqual({
|
|
40
|
+
claims: { sub: "user" },
|
|
41
|
+
headers: {},
|
|
42
|
+
ttl: 300
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
(0, import_vitest.test)("targets the regional host when a region is provided", async () => {
|
|
46
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
47
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ token: SIGNED_TOKEN }));
|
|
48
|
+
await (0, import_sign_token.signToken)({ issuerId: "issuer_region", region: "sfo1" });
|
|
49
|
+
const [url] = fetchMock.mock.calls[0];
|
|
50
|
+
(0, import_vitest.expect)(url.toString()).toBe(
|
|
51
|
+
"https://api-sfo1.vercel.com/v1/kms/issuers/issuer_region/sign/token"
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
(0, import_vitest.test)("uses an explicit token without fetching an OIDC token", async () => {
|
|
55
|
+
const fetchMock = import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(fetchReturning({ token: SIGNED_TOKEN }));
|
|
56
|
+
await (0, import_sign_token.signToken)({ issuerId: "issuer_explicit", token: "my-token" });
|
|
57
|
+
(0, import_vitest.expect)(getVercelOidcTokenMock).not.toHaveBeenCalled();
|
|
58
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
59
|
+
(0, import_vitest.expect)((init?.headers).authorization).toBe(
|
|
60
|
+
"Bearer my-token"
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
(0, import_vitest.test)("throws a VercelKmsError mapping the API error envelope", async () => {
|
|
64
|
+
getVercelOidcTokenMock.mockResolvedValue(OIDC_TOKEN);
|
|
65
|
+
import_vitest.vi.spyOn(globalThis, "fetch").mockImplementation(
|
|
66
|
+
fetchReturning(
|
|
67
|
+
{ error: { code: "issuer_not_found", message: "nope", issuerId: "x" } },
|
|
68
|
+
{ status: 404, statusText: "Not Found" }
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
await (0, import_vitest.expect)((0, import_sign_token.signToken)({ issuerId: "x" })).rejects.toMatchObject({
|
|
72
|
+
name: "VercelKmsError",
|
|
73
|
+
status: 404,
|
|
74
|
+
code: "issuer_not_found",
|
|
75
|
+
message: "nope",
|
|
76
|
+
metadata: { issuerId: "x" }
|
|
77
|
+
});
|
|
78
|
+
await (0, import_vitest.expect)((0, import_sign_token.signToken)({ issuerId: "x" })).rejects.toBeInstanceOf(
|
|
79
|
+
import_errors.VercelKmsError
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.1.1";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var version_exports = {};
|
|
20
|
+
__export(version_exports, {
|
|
21
|
+
version: () => version
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(version_exports);
|
|
24
|
+
const version = "0.1.1";
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
version
|
|
28
|
+
});
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
**@vercel/kms**
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# @vercel/kms
|
|
6
|
+
|
|
7
|
+
## Classes
|
|
8
|
+
|
|
9
|
+
- [VercelKmsError](classes/VercelKmsError.md)
|
|
10
|
+
|
|
11
|
+
## Interfaces
|
|
12
|
+
|
|
13
|
+
- [FlattenedJWS](interfaces/FlattenedJWS.md)
|
|
14
|
+
- [SignMessageOptions](interfaces/SignMessageOptions.md)
|
|
15
|
+
- [SignTokenOptions](interfaces/SignTokenOptions.md)
|
|
16
|
+
|
|
17
|
+
## Functions
|
|
18
|
+
|
|
19
|
+
- [signMessage](functions/signMessage.md)
|
|
20
|
+
- [signToken](functions/signToken.md)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
[**@vercel/kms**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Class: VercelKmsError
|
|
6
|
+
|
|
7
|
+
Defined in: [packages/kms/src/errors.ts:7](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/errors.ts#L7)
|
|
8
|
+
|
|
9
|
+
Error thrown when a Vercel KMS request fails. Mirrors the API error envelope
|
|
10
|
+
`{ error: { code, message, ...meta } }`: `code` and `message` come from the
|
|
11
|
+
response body when present, and any remaining fields are exposed on
|
|
12
|
+
[VercelKmsError.metadata](#metadata).
|
|
13
|
+
|
|
14
|
+
## Extends
|
|
15
|
+
|
|
16
|
+
- [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
17
|
+
|
|
18
|
+
## Constructors
|
|
19
|
+
|
|
20
|
+
### Constructor
|
|
21
|
+
|
|
22
|
+
> **new VercelKmsError**(`__namedParameters`): `VercelKmsError`
|
|
23
|
+
|
|
24
|
+
Defined in: [packages/kms/src/errors.ts:15](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/errors.ts#L15)
|
|
25
|
+
|
|
26
|
+
#### Parameters
|
|
27
|
+
|
|
28
|
+
##### \_\_namedParameters
|
|
29
|
+
|
|
30
|
+
###### code
|
|
31
|
+
|
|
32
|
+
`string`
|
|
33
|
+
|
|
34
|
+
###### message
|
|
35
|
+
|
|
36
|
+
`string`
|
|
37
|
+
|
|
38
|
+
###### metadata?
|
|
39
|
+
|
|
40
|
+
[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `unknown`\> = `{}`
|
|
41
|
+
|
|
42
|
+
###### status
|
|
43
|
+
|
|
44
|
+
`number`
|
|
45
|
+
|
|
46
|
+
#### Returns
|
|
47
|
+
|
|
48
|
+
`VercelKmsError`
|
|
49
|
+
|
|
50
|
+
#### Overrides
|
|
51
|
+
|
|
52
|
+
`Error.constructor`
|
|
53
|
+
|
|
54
|
+
## Properties
|
|
55
|
+
|
|
56
|
+
### code
|
|
57
|
+
|
|
58
|
+
> `readonly` **code**: `string`
|
|
59
|
+
|
|
60
|
+
Defined in: [packages/kms/src/errors.ts:11](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/errors.ts#L11)
|
|
61
|
+
|
|
62
|
+
Machine-readable error code from the API (e.g. `issuer_not_found`).
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### message
|
|
67
|
+
|
|
68
|
+
> **message**: `string`
|
|
69
|
+
|
|
70
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
71
|
+
|
|
72
|
+
#### Inherited from
|
|
73
|
+
|
|
74
|
+
`Error.message`
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### metadata
|
|
79
|
+
|
|
80
|
+
> `readonly` **metadata**: [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `unknown`\>
|
|
81
|
+
|
|
82
|
+
Defined in: [packages/kms/src/errors.ts:13](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/errors.ts#L13)
|
|
83
|
+
|
|
84
|
+
Any additional fields the API attached to the error envelope.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### name
|
|
89
|
+
|
|
90
|
+
> **name**: `string`
|
|
91
|
+
|
|
92
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076
|
|
93
|
+
|
|
94
|
+
#### Inherited from
|
|
95
|
+
|
|
96
|
+
`Error.name`
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### stack?
|
|
101
|
+
|
|
102
|
+
> `optional` **stack?**: `string`
|
|
103
|
+
|
|
104
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
105
|
+
|
|
106
|
+
#### Inherited from
|
|
107
|
+
|
|
108
|
+
`Error.stack`
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### status
|
|
113
|
+
|
|
114
|
+
> `readonly` **status**: `number`
|
|
115
|
+
|
|
116
|
+
Defined in: [packages/kms/src/errors.ts:9](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/errors.ts#L9)
|
|
117
|
+
|
|
118
|
+
HTTP status code of the failed response.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### prepareStackTrace?
|
|
123
|
+
|
|
124
|
+
> `static` `optional` **prepareStackTrace?**: (`err`, `stackTraces`) => `any`
|
|
125
|
+
|
|
126
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:28
|
|
127
|
+
|
|
128
|
+
Optional override for formatting stack traces
|
|
129
|
+
|
|
130
|
+
#### Parameters
|
|
131
|
+
|
|
132
|
+
##### err
|
|
133
|
+
|
|
134
|
+
[`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
135
|
+
|
|
136
|
+
##### stackTraces
|
|
137
|
+
|
|
138
|
+
`CallSite`[]
|
|
139
|
+
|
|
140
|
+
#### Returns
|
|
141
|
+
|
|
142
|
+
`any`
|
|
143
|
+
|
|
144
|
+
#### See
|
|
145
|
+
|
|
146
|
+
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
147
|
+
|
|
148
|
+
#### Inherited from
|
|
149
|
+
|
|
150
|
+
`Error.prepareStackTrace`
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### stackTraceLimit
|
|
155
|
+
|
|
156
|
+
> `static` **stackTraceLimit**: `number`
|
|
157
|
+
|
|
158
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:30
|
|
159
|
+
|
|
160
|
+
#### Inherited from
|
|
161
|
+
|
|
162
|
+
`Error.stackTraceLimit`
|
|
163
|
+
|
|
164
|
+
## Methods
|
|
165
|
+
|
|
166
|
+
### captureStackTrace()
|
|
167
|
+
|
|
168
|
+
> `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`
|
|
169
|
+
|
|
170
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:21
|
|
171
|
+
|
|
172
|
+
Create .stack property on a target object
|
|
173
|
+
|
|
174
|
+
#### Parameters
|
|
175
|
+
|
|
176
|
+
##### targetObject
|
|
177
|
+
|
|
178
|
+
`object`
|
|
179
|
+
|
|
180
|
+
##### constructorOpt?
|
|
181
|
+
|
|
182
|
+
[`Function`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function)
|
|
183
|
+
|
|
184
|
+
#### Returns
|
|
185
|
+
|
|
186
|
+
`void`
|
|
187
|
+
|
|
188
|
+
#### Inherited from
|
|
189
|
+
|
|
190
|
+
`Error.captureStackTrace`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**@vercel/kms**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: signMessage()
|
|
6
|
+
|
|
7
|
+
> **signMessage**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`FlattenedJWS`](../interfaces/FlattenedJWS.md)\>
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/kms/src/sign-message.ts:42](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-message.ts#L42)
|
|
10
|
+
|
|
11
|
+
Signs a message for an issuer using its managed signing key and returns the
|
|
12
|
+
resulting JOSE Flattened JWS. The message may be provided as raw bytes
|
|
13
|
+
(`Uint8Array`) or a UTF-8 `string`; it is base64-encoded before being sent.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### options
|
|
18
|
+
|
|
19
|
+
[`SignMessageOptions`](../interfaces/SignMessageOptions.md)
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`FlattenedJWS`](../interfaces/FlattenedJWS.md)\>
|
|
24
|
+
|
|
25
|
+
## Throws
|
|
26
|
+
|
|
27
|
+
If the sign request fails.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[**@vercel/kms**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: signToken()
|
|
6
|
+
|
|
7
|
+
> **signToken**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/kms/src/sign-token.ts:41](https://github.com/vercel/vercel-internal/blob/main/packages/kms/src/sign-token.ts#L41)
|
|
10
|
+
|
|
11
|
+
Signs a JWT for an issuer using its managed signing key and returns the
|
|
12
|
+
compact JWT string.
|
|
13
|
+
|
|
14
|
+
## Parameters
|
|
15
|
+
|
|
16
|
+
### options
|
|
17
|
+
|
|
18
|
+
[`SignTokenOptions`](../interfaces/SignTokenOptions.md)
|
|
19
|
+
|
|
20
|
+
## Returns
|
|
21
|
+
|
|
22
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
|
23
|
+
|
|
24
|
+
## Throws
|
|
25
|
+
|
|
26
|
+
If the sign request fails.
|
|
@@ -0,0 +1,53 @@
|
|
|
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.
|