pkg-sdk-test 0.0.17 → 0.0.19

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.
Files changed (63) hide show
  1. package/dist/cjs/BaseClient.js +2 -2
  2. package/dist/cjs/api/resources/payments/client/requests/CryptopayCreatePaymentRequest.d.ts +1 -1
  3. package/dist/cjs/api/types/CryptopayPaymentResponse.d.ts +1 -1
  4. package/dist/cjs/api/types/WebhookPaymentEvent.d.ts +26 -0
  5. package/dist/cjs/api/types/WebhookPaymentEvent.js +12 -0
  6. package/dist/cjs/api/types/WebhookStaticDepositEvent.d.ts +29 -0
  7. package/dist/cjs/api/types/WebhookStaticDepositEvent.js +11 -0
  8. package/dist/cjs/api/types/index.d.ts +2 -0
  9. package/dist/cjs/api/types/index.js +2 -0
  10. package/dist/cjs/core/index.d.ts +1 -0
  11. package/dist/cjs/core/index.js +1 -0
  12. package/dist/cjs/core/webhooks/computeHmacSignature.d.ts +9 -0
  13. package/dist/cjs/core/webhooks/computeHmacSignature.js +84 -0
  14. package/dist/cjs/core/webhooks/fetchJwks.d.ts +15 -0
  15. package/dist/cjs/core/webhooks/fetchJwks.js +156 -0
  16. package/dist/cjs/core/webhooks/index.d.ts +8 -0
  17. package/dist/cjs/core/webhooks/index.js +11 -0
  18. package/dist/cjs/core/webhooks/timingSafeEqual.d.ts +1 -0
  19. package/dist/cjs/core/webhooks/timingSafeEqual.js +85 -0
  20. package/dist/cjs/core/webhooks/types.d.ts +1 -0
  21. package/dist/cjs/core/webhooks/types.js +2 -0
  22. package/dist/cjs/core/webhooks/verifyAsymmetricSignature.d.ts +10 -0
  23. package/dist/cjs/core/webhooks/verifyAsymmetricSignature.js +210 -0
  24. package/dist/cjs/index.d.ts +1 -0
  25. package/dist/cjs/index.js +2 -1
  26. package/dist/cjs/version.d.ts +1 -1
  27. package/dist/cjs/version.js +1 -1
  28. package/dist/cjs/webhooks/WebhooksHelper.d.ts +9 -0
  29. package/dist/cjs/webhooks/WebhooksHelper.js +87 -0
  30. package/dist/cjs/webhooks/index.d.ts +1 -0
  31. package/dist/cjs/webhooks/index.js +5 -0
  32. package/dist/esm/BaseClient.mjs +2 -2
  33. package/dist/esm/api/resources/payments/client/requests/CryptopayCreatePaymentRequest.d.mts +1 -1
  34. package/dist/esm/api/types/CryptopayPaymentResponse.d.mts +1 -1
  35. package/dist/esm/api/types/WebhookPaymentEvent.d.mts +26 -0
  36. package/dist/esm/api/types/WebhookPaymentEvent.mjs +9 -0
  37. package/dist/esm/api/types/WebhookStaticDepositEvent.d.mts +29 -0
  38. package/dist/esm/api/types/WebhookStaticDepositEvent.mjs +8 -0
  39. package/dist/esm/api/types/index.d.mts +2 -0
  40. package/dist/esm/api/types/index.mjs +2 -0
  41. package/dist/esm/core/index.d.mts +1 -0
  42. package/dist/esm/core/index.mjs +1 -0
  43. package/dist/esm/core/webhooks/computeHmacSignature.d.mts +9 -0
  44. package/dist/esm/core/webhooks/computeHmacSignature.mjs +48 -0
  45. package/dist/esm/core/webhooks/fetchJwks.d.mts +15 -0
  46. package/dist/esm/core/webhooks/fetchJwks.mjs +153 -0
  47. package/dist/esm/core/webhooks/index.d.mts +8 -0
  48. package/dist/esm/core/webhooks/index.mjs +4 -0
  49. package/dist/esm/core/webhooks/timingSafeEqual.d.mts +1 -0
  50. package/dist/esm/core/webhooks/timingSafeEqual.mjs +49 -0
  51. package/dist/esm/core/webhooks/types.d.mts +1 -0
  52. package/dist/esm/core/webhooks/types.mjs +1 -0
  53. package/dist/esm/core/webhooks/verifyAsymmetricSignature.d.mts +10 -0
  54. package/dist/esm/core/webhooks/verifyAsymmetricSignature.mjs +174 -0
  55. package/dist/esm/index.d.mts +1 -0
  56. package/dist/esm/index.mjs +1 -0
  57. package/dist/esm/version.d.mts +1 -1
  58. package/dist/esm/version.mjs +1 -1
  59. package/dist/esm/webhooks/WebhooksHelper.d.mts +9 -0
  60. package/dist/esm/webhooks/WebhooksHelper.mjs +50 -0
  61. package/dist/esm/webhooks/index.d.mts +1 -0
  62. package/dist/esm/webhooks/index.mjs +1 -0
  63. package/package.json +1 -1
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "pkg-sdk-test",
46
- "X-Fern-SDK-Version": "0.0.17",
47
- "User-Agent": "pkg-sdk-test/0.0.17",
46
+ "X-Fern-SDK-Version": "0.0.19",
47
+ "User-Agent": "pkg-sdk-test/0.0.19",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -11,7 +11,7 @@ export interface CryptopayCreatePaymentRequest {
11
11
  isTest?: boolean;
12
12
  metadata?: Record<string, unknown>;
13
13
  paymentWindowSeconds?: number;
14
- redirect?: SuwardSDK.CryptopayRedirectConfigDto;
14
+ redirectConfig?: SuwardSDK.CryptopayRedirectConfigDto;
15
15
  underpaymentTolerance?: string;
16
16
  webhookUrl?: string;
17
17
  }
@@ -18,7 +18,7 @@ export interface CryptopayPaymentResponse {
18
18
  networkFee?: string | undefined;
19
19
  paymentWindowSeconds?: number | undefined;
20
20
  projectId?: string | undefined;
21
- redirect?: SuwardSDK.CryptopayRedirectConfigDto | undefined;
21
+ redirectConfig?: SuwardSDK.CryptopayRedirectConfigDto | undefined;
22
22
  status?: SuwardSDK.CryptopayPaymentStatusEnum | undefined;
23
23
  subStatus?: SuwardSDK.CryptopayPaymentSubStatusEnum | undefined;
24
24
  transactions?: SuwardSDK.CryptopayTransactionResponse[] | undefined;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Webhook body for a payment lifecycle transition. Signed over the raw body with the project's Ed25519 key; verify with project.webhookPublicKey. `createdAt` is the signed, trusted timestamp.
3
+ */
4
+ export interface WebhookPaymentEvent {
5
+ type: WebhookPaymentEvent.Type;
6
+ eventId: string;
7
+ /** Event creation time, unix milliseconds. */
8
+ createdAt: number;
9
+ paymentId: string;
10
+ projectId: string;
11
+ externalId?: string | undefined;
12
+ status: string;
13
+ subStatus: string;
14
+ amount: string;
15
+ amountReceived: string;
16
+ amountConfirmed: string;
17
+ assetId?: number | undefined;
18
+ }
19
+ export declare namespace WebhookPaymentEvent {
20
+ const Type: {
21
+ readonly PaymentAccepted: "payment.accepted";
22
+ readonly PaymentSuccess: "payment.success";
23
+ readonly PaymentFailed: "payment.failed";
24
+ };
25
+ type Type = (typeof Type)[keyof typeof Type];
26
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.WebhookPaymentEvent = void 0;
5
+ var WebhookPaymentEvent;
6
+ (function (WebhookPaymentEvent) {
7
+ WebhookPaymentEvent.Type = {
8
+ PaymentAccepted: "payment.accepted",
9
+ PaymentSuccess: "payment.success",
10
+ PaymentFailed: "payment.failed",
11
+ };
12
+ })(WebhookPaymentEvent || (exports.WebhookPaymentEvent = WebhookPaymentEvent = {}));
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Webhook body for a static-wallet deposit transition. Signed over the raw body with the project's Ed25519 key; verify with project.webhookPublicKey. `createdAt` is the signed, trusted timestamp.
3
+ */
4
+ export interface WebhookStaticDepositEvent {
5
+ type: WebhookStaticDepositEvent.Type;
6
+ eventId: string;
7
+ /** Event creation time, unix milliseconds. */
8
+ createdAt: number;
9
+ staticWalletId: string;
10
+ depositId: string;
11
+ projectId: string;
12
+ externalId?: string | undefined;
13
+ address: string;
14
+ txHash: string;
15
+ transferIndex: string;
16
+ assetId: number;
17
+ amount: string;
18
+ netAmount: string;
19
+ fee: string;
20
+ networkFee: string;
21
+ status: string;
22
+ }
23
+ export declare namespace WebhookStaticDepositEvent {
24
+ const Type: {
25
+ readonly StaticDepositAccepted: "static_deposit.accepted";
26
+ readonly StaticDepositSuccess: "static_deposit.success";
27
+ };
28
+ type Type = (typeof Type)[keyof typeof Type];
29
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.WebhookStaticDepositEvent = void 0;
5
+ var WebhookStaticDepositEvent;
6
+ (function (WebhookStaticDepositEvent) {
7
+ WebhookStaticDepositEvent.Type = {
8
+ StaticDepositAccepted: "static_deposit.accepted",
9
+ StaticDepositSuccess: "static_deposit.success",
10
+ };
11
+ })(WebhookStaticDepositEvent || (exports.WebhookStaticDepositEvent = WebhookStaticDepositEvent = {}));
@@ -12,3 +12,5 @@ export * from "./CryptopayRedirectConfigDto.js";
12
12
  export * from "./CryptopayStaticDepositResponse.js";
13
13
  export * from "./CryptopayStaticWalletResponse.js";
14
14
  export * from "./CryptopayTransactionResponse.js";
15
+ export * from "./WebhookPaymentEvent.js";
16
+ export * from "./WebhookStaticDepositEvent.js";
@@ -28,3 +28,5 @@ __exportStar(require("./CryptopayRedirectConfigDto.js"), exports);
28
28
  __exportStar(require("./CryptopayStaticDepositResponse.js"), exports);
29
29
  __exportStar(require("./CryptopayStaticWalletResponse.js"), exports);
30
30
  __exportStar(require("./CryptopayTransactionResponse.js"), exports);
31
+ __exportStar(require("./WebhookPaymentEvent.js"), exports);
32
+ __exportStar(require("./WebhookStaticDepositEvent.js"), exports);
@@ -4,3 +4,4 @@ export * from "./fetcher/index.js";
4
4
  export * as logging from "./logging/index.js";
5
5
  export * from "./runtime/index.js";
6
6
  export * as url from "./url/index.js";
7
+ export * from "./webhooks/index.js";
@@ -43,3 +43,4 @@ __exportStar(require("./fetcher/index.js"), exports);
43
43
  exports.logging = __importStar(require("./logging/index.js"));
44
44
  __exportStar(require("./runtime/index.js"), exports);
45
45
  exports.url = __importStar(require("./url/index.js"));
46
+ __exportStar(require("./webhooks/index.js"), exports);
@@ -0,0 +1,9 @@
1
+ import type { SignatureEncoding } from "./types.js";
2
+ export type HmacAlgorithm = "sha256" | "sha1" | "sha384" | "sha512";
3
+ export interface ComputeHmacSignatureArgs {
4
+ payload: string;
5
+ secret: string;
6
+ algorithm: HmacAlgorithm;
7
+ encoding: SignatureEncoding;
8
+ }
9
+ export declare function computeHmacSignature(args: ComputeHmacSignatureArgs): Promise<string>;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.computeHmacSignature = computeHmacSignature;
46
+ const index_js_1 = require("../runtime/index.js");
47
+ function hmacAlgorithmToSubtleName(algorithm) {
48
+ switch (algorithm) {
49
+ case "sha1":
50
+ return "SHA-1";
51
+ case "sha256":
52
+ return "SHA-256";
53
+ case "sha384":
54
+ return "SHA-384";
55
+ case "sha512":
56
+ return "SHA-512";
57
+ }
58
+ }
59
+ function computeHmacSignature(args) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ if (index_js_1.RUNTIME.type === "node") {
62
+ const crypto = yield Promise.resolve().then(() => __importStar(require("crypto")));
63
+ const hmac = crypto.createHmac(args.algorithm, args.secret);
64
+ hmac.update(args.payload);
65
+ return hmac.digest(args.encoding);
66
+ }
67
+ const subtle = globalThis.crypto.subtle;
68
+ const enc = new TextEncoder();
69
+ const keyMaterial = yield subtle.importKey("raw", enc.encode(args.secret), { name: "HMAC", hash: hmacAlgorithmToSubtleName(args.algorithm) }, false, ["sign"]);
70
+ const signatureBuffer = yield subtle.sign("HMAC", keyMaterial, enc.encode(args.payload));
71
+ const bytes = new Uint8Array(signatureBuffer);
72
+ if (args.encoding === "hex") {
73
+ return Array.from(bytes)
74
+ .map((b) => b.toString(16).padStart(2, "0"))
75
+ .join("");
76
+ }
77
+ // base64
78
+ let binary = "";
79
+ for (const byte of bytes) {
80
+ binary += String.fromCharCode(byte);
81
+ }
82
+ return btoa(binary);
83
+ });
84
+ }
@@ -0,0 +1,15 @@
1
+ export interface FetchJwksArgs {
2
+ url: string;
3
+ keyId?: string;
4
+ }
5
+ /**
6
+ * Fetches a public key from a JWKS endpoint and returns it as a PEM string.
7
+ *
8
+ * Only RSA keys (reconstructed from `n`/`e`) and keys with an `x5c` certificate chain are supported.
9
+ * EC (kty: "EC") and OKP (kty: "OKP") keys are **not** supported and will throw an error.
10
+ *
11
+ * @throws {Error} If the JWKS endpoint returns a non-OK response.
12
+ * @throws {Error} If no key matching `keyId` is found (after one cache-busting retry).
13
+ * @throws {Error} If the selected key has an unsupported type (e.g. EC or OKP).
14
+ */
15
+ export declare function fetchJwks(args: FetchJwksArgs): Promise<string>;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fetchJwks = fetchJwks;
13
+ const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
14
+ const CACHE_MAX_SIZE = 50;
15
+ const cache = new Map();
16
+ function base64UrlToBase64(base64url) {
17
+ let base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
18
+ while (base64.length % 4 !== 0) {
19
+ base64 += "=";
20
+ }
21
+ return base64;
22
+ }
23
+ function jwkToPem(jwk) {
24
+ if (jwk.x5c != null && jwk.x5c.length > 0) {
25
+ const cert = jwk.x5c[0];
26
+ return `-----BEGIN CERTIFICATE-----\n${cert}\n-----END CERTIFICATE-----`;
27
+ }
28
+ if (jwk.kty === "RSA" && jwk.n != null && jwk.e != null) {
29
+ return constructRsaPem(jwk.n, jwk.e);
30
+ }
31
+ throw new Error(`Unsupported JWK key type for PEM conversion: ${jwk.kty}`);
32
+ }
33
+ function base64UrlToBytes(base64url) {
34
+ const binary = atob(base64UrlToBase64(base64url));
35
+ const bytes = new Uint8Array(binary.length);
36
+ for (let i = 0; i < binary.length; i++) {
37
+ bytes[i] = binary.charCodeAt(i);
38
+ }
39
+ return bytes;
40
+ }
41
+ function concatBytes(arrays) {
42
+ const total = arrays.reduce((sum, a) => sum + a.length, 0);
43
+ const result = new Uint8Array(total);
44
+ let offset = 0;
45
+ for (const array of arrays) {
46
+ result.set(array, offset);
47
+ offset += array.length;
48
+ }
49
+ return result;
50
+ }
51
+ function constructRsaPem(nBase64Url, eBase64Url) {
52
+ const nBytes = base64UrlToBytes(nBase64Url);
53
+ const eBytes = base64UrlToBytes(eBase64Url);
54
+ // ASN.1 DER encoding of RSA public key
55
+ const nEncoded = asn1Integer(nBytes);
56
+ const eEncoded = asn1Integer(eBytes);
57
+ const sequence = asn1Sequence(concatBytes([nEncoded, eEncoded]));
58
+ const bitString = asn1BitString(sequence);
59
+ const algorithmIdentifier = asn1Sequence(new Uint8Array([
60
+ // OID for rsaEncryption (1.2.840.113549.1.1.1)
61
+ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
62
+ // NULL
63
+ 0x05, 0x00,
64
+ ]));
65
+ const spki = asn1Sequence(concatBytes([algorithmIdentifier, bitString]));
66
+ let binary = "";
67
+ for (const byte of spki) {
68
+ binary += String.fromCharCode(byte);
69
+ }
70
+ const base64 = btoa(binary);
71
+ const lines = [];
72
+ for (let i = 0; i < base64.length; i += 64) {
73
+ lines.push(base64.substring(i, i + 64));
74
+ }
75
+ return `-----BEGIN PUBLIC KEY-----\n${lines.join("\n")}\n-----END PUBLIC KEY-----`;
76
+ }
77
+ function asn1Length(length) {
78
+ if (length < 0x80) {
79
+ return new Uint8Array([length]);
80
+ }
81
+ const bytes = [];
82
+ let temp = length;
83
+ while (temp > 0) {
84
+ bytes.unshift(temp & 0xff);
85
+ temp >>= 8;
86
+ }
87
+ return new Uint8Array([0x80 | bytes.length, ...bytes]);
88
+ }
89
+ function asn1Integer(bytes) {
90
+ // Add leading zero if high bit is set (to ensure positive integer)
91
+ const needsPadding = bytes[0] >= 0x80;
92
+ const content = needsPadding ? concatBytes([new Uint8Array([0x00]), bytes]) : bytes;
93
+ return concatBytes([new Uint8Array([0x02]), asn1Length(content.length), content]);
94
+ }
95
+ function asn1Sequence(content) {
96
+ return concatBytes([new Uint8Array([0x30]), asn1Length(content.length), content]);
97
+ }
98
+ function asn1BitString(content) {
99
+ // Prepend a zero byte for unused bits
100
+ return concatBytes([new Uint8Array([0x03]), asn1Length(content.length + 1), new Uint8Array([0x00]), content]);
101
+ }
102
+ function fetchKeys(url) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const cached = cache.get(url);
105
+ if (cached != null && Date.now() - cached.fetchedAt < CACHE_TTL_MS) {
106
+ return cached.keys;
107
+ }
108
+ const response = yield fetch(url);
109
+ if (!response.ok) {
110
+ throw new Error(`Failed to fetch JWKS from ${url}: ${response.status} ${response.statusText}`);
111
+ }
112
+ const jwks = (yield response.json());
113
+ if (cache.size >= CACHE_MAX_SIZE) {
114
+ for (const key of cache.keys()) {
115
+ cache.delete(key);
116
+ break;
117
+ }
118
+ }
119
+ cache.set(url, { keys: jwks.keys, fetchedAt: Date.now() });
120
+ return jwks.keys;
121
+ });
122
+ }
123
+ /**
124
+ * Fetches a public key from a JWKS endpoint and returns it as a PEM string.
125
+ *
126
+ * Only RSA keys (reconstructed from `n`/`e`) and keys with an `x5c` certificate chain are supported.
127
+ * EC (kty: "EC") and OKP (kty: "OKP") keys are **not** supported and will throw an error.
128
+ *
129
+ * @throws {Error} If the JWKS endpoint returns a non-OK response.
130
+ * @throws {Error} If no key matching `keyId` is found (after one cache-busting retry).
131
+ * @throws {Error} If the selected key has an unsupported type (e.g. EC or OKP).
132
+ */
133
+ function fetchJwks(args) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const keys = yield fetchKeys(args.url);
136
+ let selectedKey;
137
+ if (args.keyId != null) {
138
+ selectedKey = keys.find((k) => k.kid === args.keyId);
139
+ if (selectedKey == null) {
140
+ // Invalidate cache and retry once
141
+ cache.delete(args.url);
142
+ const refreshedKeys = yield fetchKeys(args.url);
143
+ selectedKey = refreshedKeys.find((k) => k.kid === args.keyId);
144
+ }
145
+ }
146
+ else {
147
+ selectedKey = keys[0];
148
+ }
149
+ if (selectedKey == null) {
150
+ throw new Error(args.keyId != null
151
+ ? `No key found with kid "${args.keyId}" in JWKS at ${args.url}`
152
+ : `No keys found in JWKS at ${args.url}`);
153
+ }
154
+ return jwkToPem(selectedKey);
155
+ });
156
+ }
@@ -0,0 +1,8 @@
1
+ export type { ComputeHmacSignatureArgs, HmacAlgorithm } from "./computeHmacSignature.js";
2
+ export { computeHmacSignature } from "./computeHmacSignature.js";
3
+ export type { FetchJwksArgs } from "./fetchJwks.js";
4
+ export { fetchJwks } from "./fetchJwks.js";
5
+ export { timingSafeEqual } from "./timingSafeEqual.js";
6
+ export type { SignatureEncoding } from "./types.js";
7
+ export type { AsymmetricAlgorithm, VerifyAsymmetricSignatureArgs } from "./verifyAsymmetricSignature.js";
8
+ export { verifyAsymmetricSignature } from "./verifyAsymmetricSignature.js";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyAsymmetricSignature = exports.timingSafeEqual = exports.fetchJwks = exports.computeHmacSignature = void 0;
4
+ var computeHmacSignature_js_1 = require("./computeHmacSignature.js");
5
+ Object.defineProperty(exports, "computeHmacSignature", { enumerable: true, get: function () { return computeHmacSignature_js_1.computeHmacSignature; } });
6
+ var fetchJwks_js_1 = require("./fetchJwks.js");
7
+ Object.defineProperty(exports, "fetchJwks", { enumerable: true, get: function () { return fetchJwks_js_1.fetchJwks; } });
8
+ var timingSafeEqual_js_1 = require("./timingSafeEqual.js");
9
+ Object.defineProperty(exports, "timingSafeEqual", { enumerable: true, get: function () { return timingSafeEqual_js_1.timingSafeEqual; } });
10
+ var verifyAsymmetricSignature_js_1 = require("./verifyAsymmetricSignature.js");
11
+ Object.defineProperty(exports, "verifyAsymmetricSignature", { enumerable: true, get: function () { return verifyAsymmetricSignature_js_1.verifyAsymmetricSignature; } });
@@ -0,0 +1 @@
1
+ export declare function timingSafeEqual(a: string, b: string): Promise<boolean>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.timingSafeEqual = timingSafeEqual;
46
+ const index_js_1 = require("../runtime/index.js");
47
+ function timingSafeEqual(a, b) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ var _a;
50
+ if (index_js_1.RUNTIME.type === "node") {
51
+ const crypto = yield Promise.resolve().then(() => __importStar(require("crypto")));
52
+ const bufA = Buffer.from(a);
53
+ const bufB = Buffer.from(b);
54
+ if (bufA.length !== bufB.length) {
55
+ // Still perform comparison to avoid leaking length via timing
56
+ const dummy = Buffer.alloc(bufA.length);
57
+ crypto.timingSafeEqual(bufA, dummy);
58
+ return false;
59
+ }
60
+ return crypto.timingSafeEqual(bufA, bufB);
61
+ }
62
+ // Fallback: constant-time XOR comparison using Uint8Array
63
+ const enc = new TextEncoder();
64
+ const bytesA = enc.encode(a);
65
+ const bytesB = enc.encode(b);
66
+ if (bytesA.length !== bytesB.length) {
67
+ // XOR each byte of bytesA against bytesB[0] (a runtime value) so the
68
+ // loop cannot be trivially folded to a constant by the engine. This is
69
+ // best-effort timing-stability: JS has no guarantee, but we avoid an
70
+ // obvious early-exit that would trivially leak length via timing.
71
+ const pivot = (_a = bytesB[0]) !== null && _a !== void 0 ? _a : 0;
72
+ let sink = 0;
73
+ for (let i = 0; i < bytesA.length; i++) {
74
+ sink |= bytesA[i] ^ pivot;
75
+ }
76
+ void sink;
77
+ return false;
78
+ }
79
+ let result = 0;
80
+ for (let i = 0; i < bytesA.length; i++) {
81
+ result |= bytesA[i] ^ bytesB[i];
82
+ }
83
+ return result === 0;
84
+ });
85
+ }
@@ -0,0 +1 @@
1
+ export type SignatureEncoding = "base64" | "hex";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import type { SignatureEncoding } from "./types.js";
2
+ export type AsymmetricAlgorithm = "RSA_SHA256" | "RSA_SHA384" | "RSA_SHA512" | "ECDSA_SHA256" | "ECDSA_SHA384" | "ECDSA_SHA512" | "ED25519";
3
+ export interface VerifyAsymmetricSignatureArgs {
4
+ payload: string;
5
+ signature: string;
6
+ publicKey: string;
7
+ algorithm: AsymmetricAlgorithm;
8
+ encoding: SignatureEncoding;
9
+ }
10
+ export declare function verifyAsymmetricSignature(args: VerifyAsymmetricSignatureArgs): Promise<boolean>;