@redmix/api 9.0.0-canary.580 → 9.0.0-canary.582
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/auth/index.d.ts +2 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +10 -49
- package/dist/auth/parseJWT.js +3 -26
- package/dist/auth/verifiers/base64Sha1Verifier.d.ts +1 -1
- package/dist/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -1
- package/dist/auth/verifiers/base64Sha1Verifier.js +18 -37
- package/dist/auth/verifiers/base64Sha256Verifier.d.ts +1 -1
- package/dist/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -1
- package/dist/auth/verifiers/base64Sha256Verifier.js +18 -37
- package/dist/auth/verifiers/common.d.ts +8 -8
- package/dist/auth/verifiers/common.d.ts.map +1 -1
- package/dist/auth/verifiers/common.js +19 -58
- package/dist/auth/verifiers/index.d.ts +2 -2
- package/dist/auth/verifiers/index.d.ts.map +1 -1
- package/dist/auth/verifiers/index.js +8 -33
- package/dist/auth/verifiers/jwtVerifier.d.ts +1 -1
- package/dist/auth/verifiers/jwtVerifier.d.ts.map +1 -1
- package/dist/auth/verifiers/jwtVerifier.js +17 -47
- package/dist/auth/verifiers/secretKeyVerifier.d.ts +1 -1
- package/dist/auth/verifiers/secretKeyVerifier.d.ts.map +1 -1
- package/dist/auth/verifiers/secretKeyVerifier.js +7 -26
- package/dist/auth/verifiers/sha1Verifier.d.ts +1 -1
- package/dist/auth/verifiers/sha1Verifier.d.ts.map +1 -1
- package/dist/auth/verifiers/sha1Verifier.js +18 -37
- package/dist/auth/verifiers/sha256Verifier.d.ts +1 -1
- package/dist/auth/verifiers/sha256Verifier.d.ts.map +1 -1
- package/dist/auth/verifiers/sha256Verifier.js +18 -37
- package/dist/auth/verifiers/skipVerifier.d.ts +1 -1
- package/dist/auth/verifiers/skipVerifier.d.ts.map +1 -1
- package/dist/auth/verifiers/skipVerifier.js +4 -23
- package/dist/auth/verifiers/timestampSchemeVerifier.d.ts +1 -1
- package/dist/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -1
- package/dist/auth/verifiers/timestampSchemeVerifier.js +18 -33
- package/dist/cache/clients/BaseClient.js +4 -23
- package/dist/cache/clients/InMemoryClient.d.ts +1 -1
- package/dist/cache/clients/InMemoryClient.d.ts.map +1 -1
- package/dist/cache/clients/InMemoryClient.js +6 -35
- package/dist/cache/clients/MemcachedClient.d.ts +1 -1
- package/dist/cache/clients/MemcachedClient.d.ts.map +1 -1
- package/dist/cache/clients/MemcachedClient.js +6 -35
- package/dist/cache/clients/RedisClient.d.ts +2 -2
- package/dist/cache/clients/RedisClient.d.ts.map +1 -1
- package/dist/cache/clients/RedisClient.js +6 -35
- package/dist/cache/errors.js +3 -26
- package/dist/cache/index.d.ts +5 -5
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +14 -52
- package/dist/cjs/auth/index.d.ts +51 -0
- package/dist/cjs/auth/index.d.ts.map +1 -0
- package/dist/cjs/auth/index.js +129 -0
- package/dist/cjs/auth/parseJWT.d.ts +6 -0
- package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
- package/dist/cjs/auth/parseJWT.js +57 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/common.d.ts +104 -0
- package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/common.js +99 -0
- package/dist/cjs/auth/verifiers/index.d.ts +8 -0
- package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/index.js +38 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +26 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.js +86 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +14 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.js +40 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts +13 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/skipVerifier.js +37 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +81 -0
- package/dist/cjs/bins/redwood.d.ts +9 -0
- package/dist/cjs/bins/redwood.d.ts.map +1 -0
- package/dist/cjs/bins/rwfw.d.ts +3 -0
- package/dist/cjs/bins/rwfw.d.ts.map +1 -0
- package/dist/cjs/bins/tsc.d.ts +3 -0
- package/dist/cjs/bins/tsc.d.ts.map +1 -0
- package/dist/{bins → cjs/bins}/tsc.js +2 -2
- package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
- package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/BaseClient.js +27 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/InMemoryClient.js +100 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/MemcachedClient.js +75 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/RedisClient.js +79 -0
- package/dist/cjs/cache/errors.d.ts +4 -0
- package/dist/cjs/cache/errors.d.ts.map +1 -0
- package/dist/cjs/cache/errors.js +33 -0
- package/dist/cjs/cache/index.d.ts +35 -0
- package/dist/cjs/cache/index.d.ts.map +1 -0
- package/dist/cjs/cache/index.js +171 -0
- package/dist/cjs/cors.d.ts +16 -0
- package/dist/cjs/cors.d.ts.map +1 -0
- package/dist/cjs/cors.js +93 -0
- package/dist/cjs/errors.d.ts +5 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +38 -0
- package/dist/cjs/event.d.ts +3 -0
- package/dist/cjs/event.d.ts.map +1 -0
- package/dist/cjs/event.js +34 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/logger/index.d.ts +179 -0
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.js +195 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transforms.d.ts +35 -0
- package/dist/cjs/transforms.d.ts.map +1 -0
- package/dist/cjs/transforms.js +98 -0
- package/dist/cjs/types.d.ts +25 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/validations/errors.d.ts +101 -0
- package/dist/cjs/validations/errors.d.ts.map +1 -0
- package/dist/cjs/validations/errors.js +298 -0
- package/dist/cjs/validations/validations.d.ts +222 -0
- package/dist/cjs/validations/validations.d.ts.map +1 -0
- package/dist/cjs/validations/validations.js +351 -0
- package/dist/cjs/webhooks/index.d.ts +76 -0
- package/dist/cjs/webhooks/index.d.ts.map +1 -0
- package/dist/cjs/webhooks/index.js +107 -0
- package/dist/cors.d.ts +1 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js +7 -30
- package/dist/errors.js +3 -26
- package/dist/event.js +5 -28
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +4 -27
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -46
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +6 -48
- package/dist/package.json +1 -0
- package/dist/transforms.js +6 -33
- package/dist/types.js +1 -16
- package/dist/validations/errors.d.ts +1 -1
- package/dist/validations/errors.d.ts.map +1 -1
- package/dist/validations/errors.js +8 -66
- package/dist/validations/validations.js +8 -44
- package/dist/webhooks/index.d.ts +3 -3
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/index.js +25 -46
- package/package.json +53 -18
- /package/dist/{bins → cjs/bins}/redwood.js +0 -0
- /package/dist/{bins → cjs/bins}/rwfw.js +0 -0
@@ -0,0 +1,77 @@
|
|
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 base64Sha256Verifier_exports = {};
|
20
|
+
__export(base64Sha256Verifier_exports, {
|
21
|
+
default: () => base64Sha256Verifier_default,
|
22
|
+
verifySignature: () => verifySignature
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(base64Sha256Verifier_exports);
|
25
|
+
var import_crypto = require("crypto");
|
26
|
+
var import_common = require("./common.js");
|
27
|
+
function toNormalizedJsonString(payload) {
|
28
|
+
return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
|
29
|
+
return s.slice(0, 3) + s.slice(3).toUpperCase();
|
30
|
+
});
|
31
|
+
}
|
32
|
+
const createSignature = ({
|
33
|
+
payload,
|
34
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET
|
35
|
+
}) => {
|
36
|
+
const algorithm = "sha256";
|
37
|
+
const hmac = (0, import_crypto.createHmac)(algorithm, Buffer.from(secret, "base64"));
|
38
|
+
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
39
|
+
const digest = hmac.update(payload).digest();
|
40
|
+
return digest.toString("base64");
|
41
|
+
};
|
42
|
+
const verifySignature = ({
|
43
|
+
payload,
|
44
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
45
|
+
signature
|
46
|
+
}) => {
|
47
|
+
try {
|
48
|
+
const webhookSignature = Buffer.from(signature || "", "base64");
|
49
|
+
const hmac = (0, import_crypto.createHmac)("sha256", Buffer.from(secret, "base64"));
|
50
|
+
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
51
|
+
const digest = hmac.update(payload).digest();
|
52
|
+
if (webhookSignature.length === digest.length && (0, import_crypto.timingSafeEqual)(digest, webhookSignature)) {
|
53
|
+
return true;
|
54
|
+
}
|
55
|
+
throw new import_common.WebhookVerificationError();
|
56
|
+
} catch (error) {
|
57
|
+
throw new import_common.WebhookVerificationError(
|
58
|
+
`${import_common.VERIFICATION_ERROR_MESSAGE}: ${error.message}`
|
59
|
+
);
|
60
|
+
}
|
61
|
+
};
|
62
|
+
const base64Sha256Verifier = (_options) => {
|
63
|
+
return {
|
64
|
+
sign: ({ payload, secret }) => {
|
65
|
+
return createSignature({ payload, secret });
|
66
|
+
},
|
67
|
+
verify: ({ payload, secret, signature }) => {
|
68
|
+
return verifySignature({ payload, secret, signature });
|
69
|
+
},
|
70
|
+
type: "base64Sha256Verifier"
|
71
|
+
};
|
72
|
+
};
|
73
|
+
var base64Sha256Verifier_default = base64Sha256Verifier;
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
75
|
+
0 && (module.exports = {
|
76
|
+
verifySignature
|
77
|
+
});
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import type { Base64Sha1Verifier } from './base64Sha1Verifier.js';
|
2
|
+
import type { Base64Sha256Verifier } from './base64Sha256Verifier.js';
|
3
|
+
import type { JwtVerifier } from './jwtVerifier.js';
|
4
|
+
import type { SecretKeyVerifier } from './secretKeyVerifier.js';
|
5
|
+
import type { Sha1Verifier } from './sha1Verifier.js';
|
6
|
+
import type { Sha256Verifier } from './sha256Verifier.js';
|
7
|
+
import type { SkipVerifier } from './skipVerifier.js';
|
8
|
+
import type { TimestampSchemeVerifier } from './timestampSchemeVerifier.js';
|
9
|
+
export declare const verifierLookup: {
|
10
|
+
skipVerifier: (_options?: VerifyOptions) => SkipVerifier;
|
11
|
+
secretKeyVerifier: (_options?: VerifyOptions) => SecretKeyVerifier;
|
12
|
+
sha1Verifier: (_options?: VerifyOptions) => Sha1Verifier;
|
13
|
+
sha256Verifier: (_options?: VerifyOptions) => Sha256Verifier;
|
14
|
+
base64Sha1Verifier: (_options?: VerifyOptions) => Base64Sha1Verifier;
|
15
|
+
base64Sha256Verifier: (_options?: VerifyOptions) => Base64Sha256Verifier;
|
16
|
+
timestampSchemeVerifier: (options?: VerifyOptions) => TimestampSchemeVerifier;
|
17
|
+
jwtVerifier: (options?: VerifyOptions) => JwtVerifier;
|
18
|
+
};
|
19
|
+
export type SupportedVerifiers = SkipVerifier | SecretKeyVerifier | Sha1Verifier | Sha256Verifier | Base64Sha1Verifier | Base64Sha256Verifier | TimestampSchemeVerifier | JwtVerifier;
|
20
|
+
export type SupportedVerifierTypes = keyof typeof verifierLookup;
|
21
|
+
export declare const DEFAULT_WEBHOOK_SECRET: string;
|
22
|
+
export declare const VERIFICATION_ERROR_MESSAGE = "You don't have access to invoke this function.";
|
23
|
+
export declare const VERIFICATION_SIGN_MESSAGE = "Unable to sign payload";
|
24
|
+
/**
|
25
|
+
* @const {number} DEFAULT_TOLERANCE - Five minutes
|
26
|
+
*/
|
27
|
+
export declare const DEFAULT_TOLERANCE: number;
|
28
|
+
/**
|
29
|
+
* Class representing a WebhookError
|
30
|
+
* @extends Error
|
31
|
+
*/
|
32
|
+
declare class WebhookError extends Error {
|
33
|
+
/**
|
34
|
+
* Create a WebhookError.
|
35
|
+
* @param {string} message - The error message
|
36
|
+
* */
|
37
|
+
constructor(message: string);
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* Class representing a WebhookVerificationError
|
41
|
+
* @extends WebhookError
|
42
|
+
*/
|
43
|
+
export declare class WebhookVerificationError extends WebhookError {
|
44
|
+
/**
|
45
|
+
* Create a WebhookVerificationError.
|
46
|
+
* @param {string} message - The error message
|
47
|
+
* */
|
48
|
+
constructor(message?: string);
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* Class representing a WebhookSignError
|
52
|
+
* @extends WebhookError
|
53
|
+
*/
|
54
|
+
export declare class WebhookSignError extends WebhookError {
|
55
|
+
/**
|
56
|
+
* Create a WebhookSignError.
|
57
|
+
* @param {string} message - The error message
|
58
|
+
* */
|
59
|
+
constructor(message?: string);
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* VerifyOptions
|
63
|
+
*
|
64
|
+
* Used when verifying a signature based on the verifier's requirements
|
65
|
+
*
|
66
|
+
* @param {string} signatureHeader - Optional Header that contains the signature
|
67
|
+
* to verify. Will default to DEFAULT_WEBHOOK_SIGNATURE_HEADER
|
68
|
+
* @param {(signature: string) => string} signatureTransformer - Optional
|
69
|
+
* function that receives the signature from the headers and returns a new
|
70
|
+
* signature to use in the Verifier
|
71
|
+
* @param {number} currentTimestampOverride - Optional timestamp to use as the
|
72
|
+
* "current" timestamp, in msec
|
73
|
+
* @param {number} eventTimestamp - Optional timestamp to use as the event
|
74
|
+
* timestamp, in msec. If this is provided the webhook verification will fail
|
75
|
+
* if the eventTimestamp is too far from the current time (or the time passed
|
76
|
+
* as the `currentTimestampOverride` option)
|
77
|
+
* @param {number} tolerance - Optional tolerance in msec
|
78
|
+
* @param {string} issuer - Options JWT issuer for JWTVerifier
|
79
|
+
*/
|
80
|
+
export interface VerifyOptions {
|
81
|
+
signatureHeader?: string;
|
82
|
+
signatureTransformer?: (signature: string) => string;
|
83
|
+
currentTimestampOverride?: number;
|
84
|
+
eventTimestamp?: number;
|
85
|
+
tolerance?: number;
|
86
|
+
issuer?: string;
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* WebhookVerifier is the interface for all verifiers
|
90
|
+
*/
|
91
|
+
export interface WebhookVerifier {
|
92
|
+
sign({ payload, secret, }: {
|
93
|
+
payload: string | Record<string, unknown>;
|
94
|
+
secret: string;
|
95
|
+
}): string;
|
96
|
+
verify({ payload, secret, signature, }: {
|
97
|
+
payload: string | Record<string, unknown>;
|
98
|
+
secret: string;
|
99
|
+
signature: string;
|
100
|
+
}): boolean | WebhookVerificationError;
|
101
|
+
type: SupportedVerifierTypes;
|
102
|
+
}
|
103
|
+
export {};
|
104
|
+
//# sourceMappingURL=common.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/common.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAE3E,eAAO,MAAM,cAAc;;;;;;;;;CAS1B,CAAA;AAED,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ,iBAAiB,GACjB,YAAY,GACZ,cAAc,GACd,kBAAkB,GAClB,oBAAoB,GACpB,uBAAuB,GACvB,WAAW,CAAA;AAEf,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,cAAc,CAAA;AAEhE,eAAO,MAAM,sBAAsB,QAAmC,CAAA;AAEtE,eAAO,MAAM,0BAA0B,mDACW,CAAA;AAElD,eAAO,MAAM,yBAAyB,2BAA2B,CAAA;AAIjE;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAe,CAAA;AAE7C;;;GAGG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B;;;SAGK;gBACO,OAAO,EAAE,MAAM;CAG5B;AAED;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,YAAY;IACxD;;;SAGK;gBACO,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAChD;;;SAGK;gBACO,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,oBAAoB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IACpD,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EACH,OAAO,EACP,MAAM,GACP,EAAE;QACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,MAAM,EAAE,MAAM,CAAA;KACf,GAAG,MAAM,CAAA;IACV,MAAM,CAAC,EACL,OAAO,EACP,MAAM,EACN,SAAS,GACV,EAAE;QACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,MAAM,EAAE,MAAM,CAAA;QACd,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,GAAG,wBAAwB,CAAA;IACtC,IAAI,EAAE,sBAAsB,CAAA;CAC7B"}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var common_exports = {};
|
30
|
+
__export(common_exports, {
|
31
|
+
DEFAULT_TOLERANCE: () => DEFAULT_TOLERANCE,
|
32
|
+
DEFAULT_WEBHOOK_SECRET: () => DEFAULT_WEBHOOK_SECRET,
|
33
|
+
VERIFICATION_ERROR_MESSAGE: () => VERIFICATION_ERROR_MESSAGE,
|
34
|
+
VERIFICATION_SIGN_MESSAGE: () => VERIFICATION_SIGN_MESSAGE,
|
35
|
+
WebhookSignError: () => WebhookSignError,
|
36
|
+
WebhookVerificationError: () => WebhookVerificationError,
|
37
|
+
verifierLookup: () => verifierLookup
|
38
|
+
});
|
39
|
+
module.exports = __toCommonJS(common_exports);
|
40
|
+
var import_base64Sha1Verifier = __toESM(require("./base64Sha1Verifier.js"), 1);
|
41
|
+
var import_base64Sha256Verifier = __toESM(require("./base64Sha256Verifier.js"), 1);
|
42
|
+
var import_jwtVerifier = __toESM(require("./jwtVerifier.js"), 1);
|
43
|
+
var import_secretKeyVerifier = __toESM(require("./secretKeyVerifier.js"), 1);
|
44
|
+
var import_sha1Verifier = __toESM(require("./sha1Verifier.js"), 1);
|
45
|
+
var import_sha256Verifier = __toESM(require("./sha256Verifier.js"), 1);
|
46
|
+
var import_skipVerifier = __toESM(require("./skipVerifier.js"), 1);
|
47
|
+
var import_timestampSchemeVerifier = __toESM(require("./timestampSchemeVerifier.js"), 1);
|
48
|
+
const verifierLookup = {
|
49
|
+
skipVerifier: import_skipVerifier.default,
|
50
|
+
secretKeyVerifier: import_secretKeyVerifier.default,
|
51
|
+
sha1Verifier: import_sha1Verifier.default,
|
52
|
+
sha256Verifier: import_sha256Verifier.default,
|
53
|
+
base64Sha1Verifier: import_base64Sha1Verifier.default,
|
54
|
+
base64Sha256Verifier: import_base64Sha256Verifier.default,
|
55
|
+
timestampSchemeVerifier: import_timestampSchemeVerifier.default,
|
56
|
+
jwtVerifier: import_jwtVerifier.default
|
57
|
+
};
|
58
|
+
const DEFAULT_WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
|
59
|
+
const VERIFICATION_ERROR_MESSAGE = "You don't have access to invoke this function.";
|
60
|
+
const VERIFICATION_SIGN_MESSAGE = "Unable to sign payload";
|
61
|
+
const FIVE_MINUTES = 5 * 6e4;
|
62
|
+
const DEFAULT_TOLERANCE = FIVE_MINUTES;
|
63
|
+
class WebhookError extends Error {
|
64
|
+
/**
|
65
|
+
* Create a WebhookError.
|
66
|
+
* @param {string} message - The error message
|
67
|
+
* */
|
68
|
+
constructor(message) {
|
69
|
+
super(message);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
class WebhookVerificationError extends WebhookError {
|
73
|
+
/**
|
74
|
+
* Create a WebhookVerificationError.
|
75
|
+
* @param {string} message - The error message
|
76
|
+
* */
|
77
|
+
constructor(message) {
|
78
|
+
super(message || VERIFICATION_ERROR_MESSAGE);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
class WebhookSignError extends WebhookError {
|
82
|
+
/**
|
83
|
+
* Create a WebhookSignError.
|
84
|
+
* @param {string} message - The error message
|
85
|
+
* */
|
86
|
+
constructor(message) {
|
87
|
+
super(message || VERIFICATION_SIGN_MESSAGE);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
91
|
+
0 && (module.exports = {
|
92
|
+
DEFAULT_TOLERANCE,
|
93
|
+
DEFAULT_WEBHOOK_SECRET,
|
94
|
+
VERIFICATION_ERROR_MESSAGE,
|
95
|
+
VERIFICATION_SIGN_MESSAGE,
|
96
|
+
WebhookSignError,
|
97
|
+
WebhookVerificationError,
|
98
|
+
verifierLookup
|
99
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { SupportedVerifierTypes, VerifyOptions, WebhookVerifier } from './common.js';
|
2
|
+
/**
|
3
|
+
* @param {SupportedVerifierTypes} type - What verification type methods used to sign and verify signatures
|
4
|
+
* @param {VerifyOptions} options - Options used to verify the signature based on verifiers requirements
|
5
|
+
*/
|
6
|
+
export declare const createVerifier: (type: SupportedVerifierTypes, options?: VerifyOptions) => WebhookVerifier;
|
7
|
+
export * from './common.js';
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACb,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB;;;GAGG;AACH,eAAO,MAAM,cAAc,SACnB,sBAAsB,YAClB,aAAa,KACtB,eAMF,CAAA;AAED,cAAc,aAAa,CAAA"}
|
@@ -0,0 +1,38 @@
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
20
|
+
var verifiers_exports = {};
|
21
|
+
__export(verifiers_exports, {
|
22
|
+
createVerifier: () => createVerifier
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(verifiers_exports);
|
25
|
+
var import_common = require("./common.js");
|
26
|
+
__reExport(verifiers_exports, require("./common.js"), module.exports);
|
27
|
+
const createVerifier = (type, options) => {
|
28
|
+
if (options) {
|
29
|
+
return import_common.verifierLookup[type](options);
|
30
|
+
} else {
|
31
|
+
return import_common.verifierLookup[type]();
|
32
|
+
}
|
33
|
+
};
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
35
|
+
0 && (module.exports = {
|
36
|
+
createVerifier,
|
37
|
+
...require("./common.js")
|
38
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common.js';
|
2
|
+
export interface JwtVerifier extends WebhookVerifier {
|
3
|
+
type: 'jwtVerifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, options, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
options: VerifyOptions | undefined;
|
15
|
+
}) => boolean;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* JWT Payload Verifier
|
19
|
+
*
|
20
|
+
* Based on Netlify's webhook payload verification
|
21
|
+
* @see: https://docs.netlify.com/site-deploys/notifications/#payload-signature
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare const jwtVerifier: (options?: VerifyOptions) => JwtVerifier;
|
25
|
+
export default jwtVerifier;
|
26
|
+
//# sourceMappingURL=jwtVerifier.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"jwtVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/jwtVerifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,IAAI,EAAE,aAAa,CAAA;CACpB;AA2BD;;;;GAIG;AACH,eAAO,MAAM,eAAe,6CAKzB;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,GAAG,SAAS,CAAA;CACnC,KAAG,OAmBH,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,aAAc,aAAa,KAAG,WAUrD,CAAA;AAED,eAAe,WAAW,CAAA"}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var jwtVerifier_exports = {};
|
30
|
+
__export(jwtVerifier_exports, {
|
31
|
+
default: () => jwtVerifier_default,
|
32
|
+
jwtVerifier: () => jwtVerifier,
|
33
|
+
verifySignature: () => verifySignature
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(jwtVerifier_exports);
|
36
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
37
|
+
var import_common = require("./common.js");
|
38
|
+
const createSignature = ({
|
39
|
+
payload,
|
40
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
41
|
+
options
|
42
|
+
}) => {
|
43
|
+
try {
|
44
|
+
const signOptions = options?.issuer ? { issuer: options?.issuer } : void 0;
|
45
|
+
return import_jsonwebtoken.default.sign(payload, secret, { ...signOptions });
|
46
|
+
} catch (error) {
|
47
|
+
throw new import_common.WebhookSignError(error.message);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
const verifySignature = ({
|
51
|
+
payload,
|
52
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
53
|
+
signature,
|
54
|
+
options
|
55
|
+
}) => {
|
56
|
+
try {
|
57
|
+
if (payload === void 0 || payload?.length === 0) {
|
58
|
+
console.warn("Missing payload");
|
59
|
+
}
|
60
|
+
if (options?.issuer) {
|
61
|
+
import_jsonwebtoken.default.verify(signature, secret, { issuer: options?.issuer });
|
62
|
+
} else {
|
63
|
+
import_jsonwebtoken.default.verify(signature, secret);
|
64
|
+
}
|
65
|
+
return true;
|
66
|
+
} catch {
|
67
|
+
throw new import_common.WebhookVerificationError();
|
68
|
+
}
|
69
|
+
};
|
70
|
+
const jwtVerifier = (options) => {
|
71
|
+
return {
|
72
|
+
sign: ({ payload, secret }) => {
|
73
|
+
return createSignature({ payload, secret, options });
|
74
|
+
},
|
75
|
+
verify: ({ payload, secret, signature }) => {
|
76
|
+
return verifySignature({ payload, secret, signature, options });
|
77
|
+
},
|
78
|
+
type: "jwtVerifier"
|
79
|
+
};
|
80
|
+
};
|
81
|
+
var jwtVerifier_default = jwtVerifier;
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
83
|
+
0 && (module.exports = {
|
84
|
+
jwtVerifier,
|
85
|
+
verifySignature
|
86
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common.js';
|
2
|
+
export interface SecretKeyVerifier extends WebhookVerifier {
|
3
|
+
type: 'secretKeyVerifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* Secret Key Verifier
|
8
|
+
*
|
9
|
+
* Use when the payload is not signed, but rather authorized via a known secret key
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
declare const secretKeyVerifier: (_options?: VerifyOptions) => SecretKeyVerifier;
|
13
|
+
export default secretKeyVerifier;
|
14
|
+
//# sourceMappingURL=secretKeyVerifier.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"secretKeyVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/secretKeyVerifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AAED;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,cAAe,aAAa,KAAG,iBAgBrD,CAAA;AAED,eAAe,iBAAiB,CAAA"}
|
@@ -0,0 +1,40 @@
|
|
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 secretKeyVerifier_exports = {};
|
20
|
+
__export(secretKeyVerifier_exports, {
|
21
|
+
default: () => secretKeyVerifier_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(secretKeyVerifier_exports);
|
24
|
+
var import_common = require("./common.js");
|
25
|
+
const secretKeyVerifier = (_options) => {
|
26
|
+
return {
|
27
|
+
sign: ({ secret }) => {
|
28
|
+
return secret;
|
29
|
+
},
|
30
|
+
verify: ({ signature, secret = import_common.DEFAULT_WEBHOOK_SECRET }) => {
|
31
|
+
const verified = signature === secret;
|
32
|
+
if (!verified) {
|
33
|
+
throw new import_common.WebhookVerificationError();
|
34
|
+
}
|
35
|
+
return verified;
|
36
|
+
},
|
37
|
+
type: "secretKeyVerifier"
|
38
|
+
};
|
39
|
+
};
|
40
|
+
var secretKeyVerifier_default = secretKeyVerifier;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common.js';
|
2
|
+
export interface Sha1Verifier extends WebhookVerifier {
|
3
|
+
type: 'sha1Verifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
}) => boolean;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* SHA1 HMAC Payload Verifier
|
18
|
+
*
|
19
|
+
* Based on Vercel's webhook payload verification
|
20
|
+
* @see https://vercel.com/docs/api#integrations/webhooks/securing-webhooks
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
declare const sha1Verifier: (_options?: VerifyOptions) => Sha1Verifier;
|
24
|
+
export default sha1Verifier;
|
25
|
+
//# sourceMappingURL=sha1Verifier.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sha1Verifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/sha1Verifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,cAAc,CAAA;CACrB;AAkCD;;;;GAIG;AACH,eAAO,MAAM,eAAe,oCAIzB;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OA+BH,CAAA;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,YAAY,cAAe,aAAa,KAAG,YAUhD,CAAA;AAED,eAAe,YAAY,CAAA"}
|
@@ -0,0 +1,85 @@
|
|
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 sha1Verifier_exports = {};
|
20
|
+
__export(sha1Verifier_exports, {
|
21
|
+
default: () => sha1Verifier_default,
|
22
|
+
verifySignature: () => verifySignature
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(sha1Verifier_exports);
|
25
|
+
var import_crypto = require("crypto");
|
26
|
+
var import_common = require("./common.js");
|
27
|
+
function toNormalizedJsonString(payload) {
|
28
|
+
return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
|
29
|
+
return s.substr(0, 3) + s.substr(3).toUpperCase();
|
30
|
+
});
|
31
|
+
}
|
32
|
+
const createSignature = ({
|
33
|
+
payload,
|
34
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET
|
35
|
+
}) => {
|
36
|
+
const algorithm = "sha1";
|
37
|
+
const hmac = (0, import_crypto.createHmac)(algorithm, secret);
|
38
|
+
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
39
|
+
const digest = Buffer.from(
|
40
|
+
algorithm + "=" + hmac.update(payload).digest("hex"),
|
41
|
+
"utf8"
|
42
|
+
);
|
43
|
+
return digest.toString();
|
44
|
+
};
|
45
|
+
const verifySignature = ({
|
46
|
+
payload,
|
47
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
48
|
+
signature
|
49
|
+
}) => {
|
50
|
+
try {
|
51
|
+
const algorithm = signature.split("=")[0];
|
52
|
+
const webhookSignature = Buffer.from(signature || "", "utf8");
|
53
|
+
const hmac = (0, import_crypto.createHmac)(algorithm, secret);
|
54
|
+
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
55
|
+
const digest = Buffer.from(
|
56
|
+
algorithm + "=" + hmac.update(payload).digest("hex"),
|
57
|
+
"utf8"
|
58
|
+
);
|
59
|
+
const verified = webhookSignature.length === digest.length && (0, import_crypto.timingSafeEqual)(digest, webhookSignature);
|
60
|
+
if (verified) {
|
61
|
+
return verified;
|
62
|
+
}
|
63
|
+
throw new import_common.WebhookVerificationError();
|
64
|
+
} catch (error) {
|
65
|
+
throw new import_common.WebhookVerificationError(
|
66
|
+
`${import_common.VERIFICATION_ERROR_MESSAGE}: ${error.message}`
|
67
|
+
);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
const sha1Verifier = (_options) => {
|
71
|
+
return {
|
72
|
+
sign: ({ payload, secret }) => {
|
73
|
+
return createSignature({ payload, secret });
|
74
|
+
},
|
75
|
+
verify: ({ payload, secret, signature }) => {
|
76
|
+
return verifySignature({ payload, secret, signature });
|
77
|
+
},
|
78
|
+
type: "sha1Verifier"
|
79
|
+
};
|
80
|
+
};
|
81
|
+
var sha1Verifier_default = sha1Verifier;
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
83
|
+
0 && (module.exports = {
|
84
|
+
verifySignature
|
85
|
+
});
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common.js';
|
2
|
+
export interface Sha256Verifier extends WebhookVerifier {
|
3
|
+
type: 'sha256Verifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
}) => boolean;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* SHA256 HMAC Payload Verifier
|
18
|
+
*
|
19
|
+
* Based on GitHub's webhook payload verification
|
20
|
+
* @see https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
declare const sha256Verifier: (_options?: VerifyOptions) => Sha256Verifier;
|
24
|
+
export default sha256Verifier;
|
25
|
+
//# sourceMappingURL=sha256Verifier.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sha256Verifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/sha256Verifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,IAAI,EAAE,gBAAgB,CAAA;CACvB;AAkCD;;;;GAIG;AACH,eAAO,MAAM,eAAe,oCAIzB;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OA+BH,CAAA;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,cAAc,cAAe,aAAa,KAAG,cAUlD,CAAA;AAED,eAAe,cAAc,CAAA"}
|