@dodopayments/convex 0.2.7 → 0.2.8

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/index.cjs CHANGED
@@ -417,8 +417,8 @@ function convexOrUndefinedToJson(value) {
417
417
  return convexOrUndefinedToJsonInternal(value, value, "");
418
418
  }
419
419
 
420
- var __defProp$3 = Object.defineProperty;
421
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
420
+ var __defProp$4 = Object.defineProperty;
421
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
422
422
  var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
423
423
  var _a, _b;
424
424
  const IDENTIFYING_FIELD = Symbol.for("ConvexError");
@@ -533,8 +533,8 @@ function setupActionCalls(requestId) {
533
533
  };
534
534
  }
535
535
 
536
- var __defProp$2 = Object.defineProperty;
537
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
536
+ var __defProp$3 = Object.defineProperty;
537
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
538
538
  var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
539
539
  class FilterExpression {
540
540
  /**
@@ -556,8 +556,8 @@ function validateArg(arg, idx, method, argName) {
556
556
  }
557
557
  }
558
558
 
559
- var __defProp$1 = Object.defineProperty;
560
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
559
+ var __defProp$2 = Object.defineProperty;
560
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
561
561
  var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
562
562
  function setupActionVectorSearch(requestId) {
563
563
  return async (tableName, indexName, query) => {
@@ -834,8 +834,8 @@ const httpActionGeneric = (func) => {
834
834
  return q;
835
835
  };
836
836
 
837
- var __defProp = Object.defineProperty;
838
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
837
+ var __defProp$1 = Object.defineProperty;
838
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
839
839
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
840
840
  class InstalledComponent {
841
841
  constructor(definition, name) {
@@ -5308,857 +5308,824 @@ var WebhookPayloadSchema = discriminatedUnionType("type", [
5308
5308
  LicenseKeyCreatedPayloadSchema
5309
5309
  ]);
5310
5310
 
5311
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5312
-
5313
- var dist = {};
5314
-
5315
- var timing_safe_equal = {};
5316
-
5317
- Object.defineProperty(timing_safe_equal, "__esModule", { value: true });
5318
- timing_safe_equal.timingSafeEqual = void 0;
5311
+ // src/webhook/vendor/timing_safe_equal.ts
5319
5312
  function assert(expr, msg = "") {
5320
- if (!expr) {
5321
- throw new Error(msg);
5322
- }
5313
+ if (!expr) {
5314
+ throw new Error(msg);
5315
+ }
5323
5316
  }
5324
5317
  function timingSafeEqual(a, b) {
5325
- if (a.byteLength !== b.byteLength) {
5326
- return false;
5327
- }
5328
- if (!(a instanceof DataView)) {
5329
- a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
5330
- }
5331
- if (!(b instanceof DataView)) {
5332
- b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
5333
- }
5334
- assert(a instanceof DataView);
5335
- assert(b instanceof DataView);
5336
- const length = a.byteLength;
5337
- let out = 0;
5338
- let i = -1;
5339
- while (++i < length) {
5340
- out |= a.getUint8(i) ^ b.getUint8(i);
5341
- }
5342
- return out === 0;
5318
+ if (a.byteLength !== b.byteLength) {
5319
+ return false;
5320
+ }
5321
+ if (!(a instanceof DataView)) {
5322
+ a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
5323
+ }
5324
+ if (!(b instanceof DataView)) {
5325
+ b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
5326
+ }
5327
+ assert(a instanceof DataView);
5328
+ assert(b instanceof DataView);
5329
+ const length = a.byteLength;
5330
+ let out = 0;
5331
+ let i = -1;
5332
+ while (++i < length) {
5333
+ out |= a.getUint8(i) ^ b.getUint8(i);
5334
+ }
5335
+ return out === 0;
5343
5336
  }
5344
- timing_safe_equal.timingSafeEqual = timingSafeEqual;
5345
5337
 
5346
- var base64$1 = {};
5338
+ var __create = Object.create;
5339
+ var __defProp = Object.defineProperty;
5340
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5341
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5342
+ var __getProtoOf = Object.getPrototypeOf;
5343
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5344
+ var __commonJS = (cb, mod) => function __require2() {
5345
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
5346
+ };
5347
+ var __copyProps = (to, from, except, desc) => {
5348
+ if (from && typeof from === "object" || typeof from === "function") {
5349
+ for (let key of __getOwnPropNames(from))
5350
+ if (!__hasOwnProp.call(to, key) && key !== except)
5351
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
5352
+ }
5353
+ return to;
5354
+ };
5355
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
5356
+ // If the importer is in node compatibility mode or this is not an ESM
5357
+ // file that has been converted to a CommonJS file using a Babel-
5358
+ // compatible transform (i.e. "__esModule" has not been set), then set
5359
+ // "default" to the CommonJS "module.exports" for node compatibility.
5360
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
5361
+ mod
5362
+ ));
5347
5363
 
5348
- // Copyright (C) 2016 Dmitry Chestnykh
5349
- // MIT License. See LICENSE file for details.
5350
- var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
5351
- var extendStatics = function (d, b) {
5352
- extendStatics = Object.setPrototypeOf ||
5353
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5354
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5364
+ // ../../node_modules/@stablelib/base64/lib/base64.js
5365
+ var require_base64 = __commonJS({
5366
+ "../../node_modules/@stablelib/base64/lib/base64.js"(exports) {
5367
+ var __extends = exports && exports.__extends || /* @__PURE__ */ function() {
5368
+ var extendStatics = function(d, b) {
5369
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
5370
+ d2.__proto__ = b2;
5371
+ } || function(d2, b2) {
5372
+ for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
5373
+ };
5355
5374
  return extendStatics(d, b);
5356
- };
5357
- return function (d, b) {
5375
+ };
5376
+ return function(d, b) {
5358
5377
  extendStatics(d, b);
5359
- function __() { this.constructor = d; }
5378
+ function __() {
5379
+ this.constructor = d;
5380
+ }
5360
5381
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5361
- };
5362
- })();
5363
- Object.defineProperty(base64$1, "__esModule", { value: true });
5364
- /**
5365
- * Package base64 implements Base64 encoding and decoding.
5366
- */
5367
- // Invalid character used in decoding to indicate
5368
- // that the character to decode is out of range of
5369
- // alphabet and cannot be decoded.
5370
- var INVALID_BYTE = 256;
5371
- /**
5372
- * Implements standard Base64 encoding.
5373
- *
5374
- * Operates in constant time.
5375
- */
5376
- var Coder = /** @class */ (function () {
5377
- // TODO(dchest): methods to encode chunk-by-chunk.
5378
- function Coder(_paddingCharacter) {
5379
- if (_paddingCharacter === void 0) { _paddingCharacter = "="; }
5380
- this._paddingCharacter = _paddingCharacter;
5381
- }
5382
- Coder.prototype.encodedLength = function (length) {
5383
- if (!this._paddingCharacter) {
5382
+ };
5383
+ }();
5384
+ Object.defineProperty(exports, "__esModule", { value: true });
5385
+ var INVALID_BYTE = 256;
5386
+ var Coder = (
5387
+ /** @class */
5388
+ function() {
5389
+ function Coder2(_paddingCharacter) {
5390
+ if (_paddingCharacter === void 0) {
5391
+ _paddingCharacter = "=";
5392
+ }
5393
+ this._paddingCharacter = _paddingCharacter;
5394
+ }
5395
+ Coder2.prototype.encodedLength = function(length) {
5396
+ if (!this._paddingCharacter) {
5384
5397
  return (length * 8 + 5) / 6 | 0;
5385
- }
5386
- return (length + 2) / 3 * 4 | 0;
5387
- };
5388
- Coder.prototype.encode = function (data) {
5389
- var out = "";
5390
- var i = 0;
5391
- for (; i < data.length - 2; i += 3) {
5392
- var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
5393
- out += this._encodeByte((c >>> 3 * 6) & 63);
5394
- out += this._encodeByte((c >>> 2 * 6) & 63);
5395
- out += this._encodeByte((c >>> 1 * 6) & 63);
5396
- out += this._encodeByte((c >>> 0 * 6) & 63);
5397
- }
5398
- var left = data.length - i;
5399
- if (left > 0) {
5400
- var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0);
5401
- out += this._encodeByte((c >>> 3 * 6) & 63);
5402
- out += this._encodeByte((c >>> 2 * 6) & 63);
5398
+ }
5399
+ return (length + 2) / 3 * 4 | 0;
5400
+ };
5401
+ Coder2.prototype.encode = function(data) {
5402
+ var out = "";
5403
+ var i = 0;
5404
+ for (; i < data.length - 2; i += 3) {
5405
+ var c = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
5406
+ out += this._encodeByte(c >>> 3 * 6 & 63);
5407
+ out += this._encodeByte(c >>> 2 * 6 & 63);
5408
+ out += this._encodeByte(c >>> 1 * 6 & 63);
5409
+ out += this._encodeByte(c >>> 0 * 6 & 63);
5410
+ }
5411
+ var left = data.length - i;
5412
+ if (left > 0) {
5413
+ var c = data[i] << 16 | (left === 2 ? data[i + 1] << 8 : 0);
5414
+ out += this._encodeByte(c >>> 3 * 6 & 63);
5415
+ out += this._encodeByte(c >>> 2 * 6 & 63);
5403
5416
  if (left === 2) {
5404
- out += this._encodeByte((c >>> 1 * 6) & 63);
5405
- }
5406
- else {
5407
- out += this._paddingCharacter || "";
5417
+ out += this._encodeByte(c >>> 1 * 6 & 63);
5418
+ } else {
5419
+ out += this._paddingCharacter || "";
5408
5420
  }
5409
5421
  out += this._paddingCharacter || "";
5410
- }
5411
- return out;
5412
- };
5413
- Coder.prototype.maxDecodedLength = function (length) {
5414
- if (!this._paddingCharacter) {
5422
+ }
5423
+ return out;
5424
+ };
5425
+ Coder2.prototype.maxDecodedLength = function(length) {
5426
+ if (!this._paddingCharacter) {
5415
5427
  return (length * 6 + 7) / 8 | 0;
5416
- }
5417
- return length / 4 * 3 | 0;
5418
- };
5419
- Coder.prototype.decodedLength = function (s) {
5420
- return this.maxDecodedLength(s.length - this._getPaddingLength(s));
5421
- };
5422
- Coder.prototype.decode = function (s) {
5423
- if (s.length === 0) {
5428
+ }
5429
+ return length / 4 * 3 | 0;
5430
+ };
5431
+ Coder2.prototype.decodedLength = function(s) {
5432
+ return this.maxDecodedLength(s.length - this._getPaddingLength(s));
5433
+ };
5434
+ Coder2.prototype.decode = function(s) {
5435
+ if (s.length === 0) {
5424
5436
  return new Uint8Array(0);
5425
- }
5426
- var paddingLength = this._getPaddingLength(s);
5427
- var length = s.length - paddingLength;
5428
- var out = new Uint8Array(this.maxDecodedLength(length));
5429
- var op = 0;
5430
- var i = 0;
5431
- var haveBad = 0;
5432
- var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
5433
- for (; i < length - 4; i += 4) {
5437
+ }
5438
+ var paddingLength = this._getPaddingLength(s);
5439
+ var length = s.length - paddingLength;
5440
+ var out = new Uint8Array(this.maxDecodedLength(length));
5441
+ var op = 0;
5442
+ var i = 0;
5443
+ var haveBad = 0;
5444
+ var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
5445
+ for (; i < length - 4; i += 4) {
5434
5446
  v0 = this._decodeChar(s.charCodeAt(i + 0));
5435
5447
  v1 = this._decodeChar(s.charCodeAt(i + 1));
5436
5448
  v2 = this._decodeChar(s.charCodeAt(i + 2));
5437
5449
  v3 = this._decodeChar(s.charCodeAt(i + 3));
5438
- out[op++] = (v0 << 2) | (v1 >>> 4);
5439
- out[op++] = (v1 << 4) | (v2 >>> 2);
5440
- out[op++] = (v2 << 6) | v3;
5450
+ out[op++] = v0 << 2 | v1 >>> 4;
5451
+ out[op++] = v1 << 4 | v2 >>> 2;
5452
+ out[op++] = v2 << 6 | v3;
5441
5453
  haveBad |= v0 & INVALID_BYTE;
5442
5454
  haveBad |= v1 & INVALID_BYTE;
5443
5455
  haveBad |= v2 & INVALID_BYTE;
5444
5456
  haveBad |= v3 & INVALID_BYTE;
5445
- }
5446
- if (i < length - 1) {
5457
+ }
5458
+ if (i < length - 1) {
5447
5459
  v0 = this._decodeChar(s.charCodeAt(i));
5448
5460
  v1 = this._decodeChar(s.charCodeAt(i + 1));
5449
- out[op++] = (v0 << 2) | (v1 >>> 4);
5461
+ out[op++] = v0 << 2 | v1 >>> 4;
5450
5462
  haveBad |= v0 & INVALID_BYTE;
5451
5463
  haveBad |= v1 & INVALID_BYTE;
5452
- }
5453
- if (i < length - 2) {
5464
+ }
5465
+ if (i < length - 2) {
5454
5466
  v2 = this._decodeChar(s.charCodeAt(i + 2));
5455
- out[op++] = (v1 << 4) | (v2 >>> 2);
5467
+ out[op++] = v1 << 4 | v2 >>> 2;
5456
5468
  haveBad |= v2 & INVALID_BYTE;
5457
- }
5458
- if (i < length - 3) {
5469
+ }
5470
+ if (i < length - 3) {
5459
5471
  v3 = this._decodeChar(s.charCodeAt(i + 3));
5460
- out[op++] = (v2 << 6) | v3;
5472
+ out[op++] = v2 << 6 | v3;
5461
5473
  haveBad |= v3 & INVALID_BYTE;
5462
- }
5463
- if (haveBad !== 0) {
5474
+ }
5475
+ if (haveBad !== 0) {
5464
5476
  throw new Error("Base64Coder: incorrect characters for decoding");
5465
- }
5466
- return out;
5467
- };
5468
- // Standard encoding have the following encoded/decoded ranges,
5469
- // which we need to convert between.
5470
- //
5471
- // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + /
5472
- // Index: 0 - 25 26 - 51 52 - 61 62 63
5473
- // ASCII: 65 - 90 97 - 122 48 - 57 43 47
5474
- //
5475
- // Encode 6 bits in b into a new character.
5476
- Coder.prototype._encodeByte = function (b) {
5477
- // Encoding uses constant time operations as follows:
5478
- //
5479
- // 1. Define comparison of A with B using (A - B) >>> 8:
5480
- // if A > B, then result is positive integer
5481
- // if A <= B, then result is 0
5482
- //
5483
- // 2. Define selection of C or 0 using bitwise AND: X & C:
5484
- // if X == 0, then result is 0
5485
- // if X != 0, then result is C
5486
- //
5487
- // 3. Start with the smallest comparison (b >= 0), which is always
5488
- // true, so set the result to the starting ASCII value (65).
5489
- //
5490
- // 4. Continue comparing b to higher ASCII values, and selecting
5491
- // zero if comparison isn't true, otherwise selecting a value
5492
- // to add to result, which:
5493
- //
5494
- // a) undoes the previous addition
5495
- // b) provides new value to add
5496
- //
5497
- var result = b;
5498
- // b >= 0
5499
- result += 65;
5500
- // b > 25
5501
- result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
5502
- // b > 51
5503
- result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
5504
- // b > 61
5505
- result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43);
5506
- // b > 62
5507
- result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47);
5508
- return String.fromCharCode(result);
5509
- };
5510
- // Decode a character code into a byte.
5511
- // Must return 256 if character is out of alphabet range.
5512
- Coder.prototype._decodeChar = function (c) {
5513
- // Decoding works similar to encoding: using the same comparison
5514
- // function, but now it works on ranges: result is always incremented
5515
- // by value, but this value becomes zero if the range is not
5516
- // satisfied.
5517
- //
5518
- // Decoding starts with invalid value, 256, which is then
5519
- // subtracted when the range is satisfied. If none of the ranges
5520
- // apply, the function returns 256, which is then checked by
5521
- // the caller to throw error.
5522
- var result = INVALID_BYTE; // start with invalid character
5523
- // c == 43 (c > 42 and c < 44)
5524
- result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62);
5525
- // c == 47 (c > 46 and c < 48)
5526
- result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63);
5527
- // c > 47 and c < 58
5528
- result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
5529
- // c > 64 and c < 91
5530
- result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
5531
- // c > 96 and c < 123
5532
- result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
5533
- return result;
5534
- };
5535
- Coder.prototype._getPaddingLength = function (s) {
5536
- var paddingLength = 0;
5537
- if (this._paddingCharacter) {
5477
+ }
5478
+ return out;
5479
+ };
5480
+ Coder2.prototype._encodeByte = function(b) {
5481
+ var result = b;
5482
+ result += 65;
5483
+ result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
5484
+ result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
5485
+ result += 61 - b >>> 8 & 52 - 48 - 62 + 43;
5486
+ result += 62 - b >>> 8 & 62 - 43 - 63 + 47;
5487
+ return String.fromCharCode(result);
5488
+ };
5489
+ Coder2.prototype._decodeChar = function(c) {
5490
+ var result = INVALID_BYTE;
5491
+ result += (42 - c & c - 44) >>> 8 & -INVALID_BYTE + c - 43 + 62;
5492
+ result += (46 - c & c - 48) >>> 8 & -INVALID_BYTE + c - 47 + 63;
5493
+ result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
5494
+ result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
5495
+ result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
5496
+ return result;
5497
+ };
5498
+ Coder2.prototype._getPaddingLength = function(s) {
5499
+ var paddingLength = 0;
5500
+ if (this._paddingCharacter) {
5538
5501
  for (var i = s.length - 1; i >= 0; i--) {
5539
- if (s[i] !== this._paddingCharacter) {
5540
- break;
5541
- }
5542
- paddingLength++;
5502
+ if (s[i] !== this._paddingCharacter) {
5503
+ break;
5504
+ }
5505
+ paddingLength++;
5543
5506
  }
5544
5507
  if (s.length < 4 || paddingLength > 2) {
5545
- throw new Error("Base64Coder: incorrect padding");
5508
+ throw new Error("Base64Coder: incorrect padding");
5546
5509
  }
5547
- }
5548
- return paddingLength;
5510
+ }
5511
+ return paddingLength;
5512
+ };
5513
+ return Coder2;
5514
+ }()
5515
+ );
5516
+ exports.Coder = Coder;
5517
+ var stdCoder = new Coder();
5518
+ function encode2(data) {
5519
+ return stdCoder.encode(data);
5520
+ }
5521
+ exports.encode = encode2;
5522
+ function decode2(s) {
5523
+ return stdCoder.decode(s);
5524
+ }
5525
+ exports.decode = decode2;
5526
+ var URLSafeCoder = (
5527
+ /** @class */
5528
+ function(_super) {
5529
+ __extends(URLSafeCoder2, _super);
5530
+ function URLSafeCoder2() {
5531
+ return _super !== null && _super.apply(this, arguments) || this;
5532
+ }
5533
+ URLSafeCoder2.prototype._encodeByte = function(b) {
5534
+ var result = b;
5535
+ result += 65;
5536
+ result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
5537
+ result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
5538
+ result += 61 - b >>> 8 & 52 - 48 - 62 + 45;
5539
+ result += 62 - b >>> 8 & 62 - 45 - 63 + 95;
5540
+ return String.fromCharCode(result);
5541
+ };
5542
+ URLSafeCoder2.prototype._decodeChar = function(c) {
5543
+ var result = INVALID_BYTE;
5544
+ result += (44 - c & c - 46) >>> 8 & -INVALID_BYTE + c - 45 + 62;
5545
+ result += (94 - c & c - 96) >>> 8 & -INVALID_BYTE + c - 95 + 63;
5546
+ result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
5547
+ result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
5548
+ result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
5549
+ return result;
5550
+ };
5551
+ return URLSafeCoder2;
5552
+ }(Coder)
5553
+ );
5554
+ exports.URLSafeCoder = URLSafeCoder;
5555
+ var urlSafeCoder = new URLSafeCoder();
5556
+ function encodeURLSafe(data) {
5557
+ return urlSafeCoder.encode(data);
5558
+ }
5559
+ exports.encodeURLSafe = encodeURLSafe;
5560
+ function decodeURLSafe(s) {
5561
+ return urlSafeCoder.decode(s);
5562
+ }
5563
+ exports.decodeURLSafe = decodeURLSafe;
5564
+ exports.encodedLength = function(length) {
5565
+ return stdCoder.encodedLength(length);
5549
5566
  };
5550
- return Coder;
5551
- }());
5552
- base64$1.Coder = Coder;
5553
- var stdCoder = new Coder();
5554
- function encode(data) {
5555
- return stdCoder.encode(data);
5556
- }
5557
- base64$1.encode = encode;
5558
- function decode(s) {
5559
- return stdCoder.decode(s);
5560
- }
5561
- base64$1.decode = decode;
5562
- /**
5563
- * Implements URL-safe Base64 encoding.
5564
- * (Same as Base64, but '+' is replaced with '-', and '/' with '_').
5565
- *
5566
- * Operates in constant time.
5567
- */
5568
- var URLSafeCoder = /** @class */ (function (_super) {
5569
- __extends(URLSafeCoder, _super);
5570
- function URLSafeCoder() {
5571
- return _super !== null && _super.apply(this, arguments) || this;
5572
- }
5573
- // URL-safe encoding have the following encoded/decoded ranges:
5574
- //
5575
- // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _
5576
- // Index: 0 - 25 26 - 51 52 - 61 62 63
5577
- // ASCII: 65 - 90 97 - 122 48 - 57 45 95
5578
- //
5579
- URLSafeCoder.prototype._encodeByte = function (b) {
5580
- var result = b;
5581
- // b >= 0
5582
- result += 65;
5583
- // b > 25
5584
- result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
5585
- // b > 51
5586
- result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
5587
- // b > 61
5588
- result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45);
5589
- // b > 62
5590
- result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95);
5591
- return String.fromCharCode(result);
5567
+ exports.maxDecodedLength = function(length) {
5568
+ return stdCoder.maxDecodedLength(length);
5592
5569
  };
5593
- URLSafeCoder.prototype._decodeChar = function (c) {
5594
- var result = INVALID_BYTE;
5595
- // c == 45 (c > 44 and c < 46)
5596
- result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62);
5597
- // c == 95 (c > 94 and c < 96)
5598
- result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63);
5599
- // c > 47 and c < 58
5600
- result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
5601
- // c > 64 and c < 91
5602
- result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
5603
- // c > 96 and c < 123
5604
- result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
5605
- return result;
5570
+ exports.decodedLength = function(s) {
5571
+ return stdCoder.decodedLength(s);
5606
5572
  };
5607
- return URLSafeCoder;
5608
- }(Coder));
5609
- base64$1.URLSafeCoder = URLSafeCoder;
5610
- var urlSafeCoder = new URLSafeCoder();
5611
- function encodeURLSafe(data) {
5612
- return urlSafeCoder.encode(data);
5613
- }
5614
- base64$1.encodeURLSafe = encodeURLSafe;
5615
- function decodeURLSafe(s) {
5616
- return urlSafeCoder.decode(s);
5617
- }
5618
- base64$1.decodeURLSafe = decodeURLSafe;
5619
- base64$1.encodedLength = function (length) {
5620
- return stdCoder.encodedLength(length);
5621
- };
5622
- base64$1.maxDecodedLength = function (length) {
5623
- return stdCoder.maxDecodedLength(length);
5624
- };
5625
- base64$1.decodedLength = function (s) {
5626
- return stdCoder.decodedLength(s);
5627
- };
5628
-
5629
- var sha256$1 = {exports: {}};
5630
-
5631
- (function (module) {
5632
- (function (root, factory) {
5633
- // Hack to make all exports of this module sha256 function object properties.
5634
- var exports = {};
5635
- factory(exports);
5636
- var sha256 = exports["default"];
5637
- for (var k in exports) {
5638
- sha256[k] = exports[k];
5639
- }
5640
-
5641
- {
5642
- module.exports = sha256;
5643
- }
5644
- })(commonjsGlobal, function(exports) {
5645
- exports.__esModule = true;
5646
- // SHA-256 (+ HMAC and PBKDF2) for JavaScript.
5647
- //
5648
- // Written in 2014-2016 by Dmitry Chestnykh.
5649
- // Public domain, no warranty.
5650
- //
5651
- // Functions (accept and return Uint8Arrays):
5652
- //
5653
- // sha256(message) -> hash
5654
- // sha256.hmac(key, message) -> mac
5655
- // sha256.pbkdf2(password, salt, rounds, dkLen) -> dk
5656
- //
5657
- // Classes:
5658
- //
5659
- // new sha256.Hash()
5660
- // new sha256.HMAC(key)
5661
- //
5662
- exports.digestLength = 32;
5663
- exports.blockSize = 64;
5664
- // SHA-256 constants
5665
- var K = new Uint32Array([
5666
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
5667
- 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
5668
- 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
5669
- 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
5670
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
5671
- 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
5672
- 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
5673
- 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
5674
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
5675
- 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
5676
- 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
5677
- 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
5678
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
5679
- ]);
5680
- function hashBlocks(w, v, p, pos, len) {
5681
- var a, b, c, d, e, f, g, h, u, i, j, t1, t2;
5682
- while (len >= 64) {
5683
- a = v[0];
5684
- b = v[1];
5685
- c = v[2];
5686
- d = v[3];
5687
- e = v[4];
5688
- f = v[5];
5689
- g = v[6];
5690
- h = v[7];
5691
- for (i = 0; i < 16; i++) {
5692
- j = pos + i * 4;
5693
- w[i] = (((p[j] & 0xff) << 24) | ((p[j + 1] & 0xff) << 16) |
5694
- ((p[j + 2] & 0xff) << 8) | (p[j + 3] & 0xff));
5695
- }
5696
- for (i = 16; i < 64; i++) {
5697
- u = w[i - 2];
5698
- t1 = (u >>> 17 | u << (32 - 17)) ^ (u >>> 19 | u << (32 - 19)) ^ (u >>> 10);
5699
- u = w[i - 15];
5700
- t2 = (u >>> 7 | u << (32 - 7)) ^ (u >>> 18 | u << (32 - 18)) ^ (u >>> 3);
5701
- w[i] = (t1 + w[i - 7] | 0) + (t2 + w[i - 16] | 0);
5702
- }
5703
- for (i = 0; i < 64; i++) {
5704
- t1 = (((((e >>> 6 | e << (32 - 6)) ^ (e >>> 11 | e << (32 - 11)) ^
5705
- (e >>> 25 | e << (32 - 25))) + ((e & f) ^ (~e & g))) | 0) +
5706
- ((h + ((K[i] + w[i]) | 0)) | 0)) | 0;
5707
- t2 = (((a >>> 2 | a << (32 - 2)) ^ (a >>> 13 | a << (32 - 13)) ^
5708
- (a >>> 22 | a << (32 - 22))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
5709
- h = g;
5710
- g = f;
5711
- f = e;
5712
- e = (d + t1) | 0;
5713
- d = c;
5714
- c = b;
5715
- b = a;
5716
- a = (t1 + t2) | 0;
5717
- }
5718
- v[0] += a;
5719
- v[1] += b;
5720
- v[2] += c;
5721
- v[3] += d;
5722
- v[4] += e;
5723
- v[5] += f;
5724
- v[6] += g;
5725
- v[7] += h;
5726
- pos += 64;
5727
- len -= 64;
5728
- }
5729
- return pos;
5730
- }
5731
- // Hash implements SHA256 hash algorithm.
5732
- var Hash = /** @class */ (function () {
5733
- function Hash() {
5734
- this.digestLength = exports.digestLength;
5735
- this.blockSize = exports.blockSize;
5736
- // Note: Int32Array is used instead of Uint32Array for performance reasons.
5737
- this.state = new Int32Array(8); // hash state
5738
- this.temp = new Int32Array(64); // temporary state
5739
- this.buffer = new Uint8Array(128); // buffer for data to hash
5740
- this.bufferLength = 0; // number of bytes in buffer
5741
- this.bytesHashed = 0; // number of total bytes hashed
5742
- this.finished = false; // indicates whether the hash was finalized
5743
- this.reset();
5744
- }
5745
- // Resets hash state making it possible
5746
- // to re-use this instance to hash other data.
5747
- Hash.prototype.reset = function () {
5748
- this.state[0] = 0x6a09e667;
5749
- this.state[1] = 0xbb67ae85;
5750
- this.state[2] = 0x3c6ef372;
5751
- this.state[3] = 0xa54ff53a;
5752
- this.state[4] = 0x510e527f;
5753
- this.state[5] = 0x9b05688c;
5754
- this.state[6] = 0x1f83d9ab;
5755
- this.state[7] = 0x5be0cd19;
5756
- this.bufferLength = 0;
5757
- this.bytesHashed = 0;
5758
- this.finished = false;
5759
- return this;
5760
- };
5761
- // Cleans internal buffers and re-initializes hash state.
5762
- Hash.prototype.clean = function () {
5763
- for (var i = 0; i < this.buffer.length; i++) {
5764
- this.buffer[i] = 0;
5765
- }
5766
- for (var i = 0; i < this.temp.length; i++) {
5767
- this.temp[i] = 0;
5768
- }
5769
- this.reset();
5770
- };
5771
- // Updates hash state with the given data.
5772
- //
5773
- // Optionally, length of the data can be specified to hash
5774
- // fewer bytes than data.length.
5775
- //
5776
- // Throws error when trying to update already finalized hash:
5777
- // instance must be reset to use it again.
5778
- Hash.prototype.update = function (data, dataLength) {
5779
- if (dataLength === void 0) { dataLength = data.length; }
5780
- if (this.finished) {
5781
- throw new Error("SHA256: can't update because hash was finished.");
5782
- }
5783
- var dataPos = 0;
5784
- this.bytesHashed += dataLength;
5785
- if (this.bufferLength > 0) {
5786
- while (this.bufferLength < 64 && dataLength > 0) {
5787
- this.buffer[this.bufferLength++] = data[dataPos++];
5788
- dataLength--;
5789
- }
5790
- if (this.bufferLength === 64) {
5791
- hashBlocks(this.temp, this.state, this.buffer, 0, 64);
5792
- this.bufferLength = 0;
5793
- }
5794
- }
5795
- if (dataLength >= 64) {
5796
- dataPos = hashBlocks(this.temp, this.state, data, dataPos, dataLength);
5797
- dataLength %= 64;
5798
- }
5799
- while (dataLength > 0) {
5800
- this.buffer[this.bufferLength++] = data[dataPos++];
5801
- dataLength--;
5802
- }
5803
- return this;
5804
- };
5805
- // Finalizes hash state and puts hash into out.
5806
- //
5807
- // If hash was already finalized, puts the same value.
5808
- Hash.prototype.finish = function (out) {
5809
- if (!this.finished) {
5810
- var bytesHashed = this.bytesHashed;
5811
- var left = this.bufferLength;
5812
- var bitLenHi = (bytesHashed / 0x20000000) | 0;
5813
- var bitLenLo = bytesHashed << 3;
5814
- var padLength = (bytesHashed % 64 < 56) ? 64 : 128;
5815
- this.buffer[left] = 0x80;
5816
- for (var i = left + 1; i < padLength - 8; i++) {
5817
- this.buffer[i] = 0;
5818
- }
5819
- this.buffer[padLength - 8] = (bitLenHi >>> 24) & 0xff;
5820
- this.buffer[padLength - 7] = (bitLenHi >>> 16) & 0xff;
5821
- this.buffer[padLength - 6] = (bitLenHi >>> 8) & 0xff;
5822
- this.buffer[padLength - 5] = (bitLenHi >>> 0) & 0xff;
5823
- this.buffer[padLength - 4] = (bitLenLo >>> 24) & 0xff;
5824
- this.buffer[padLength - 3] = (bitLenLo >>> 16) & 0xff;
5825
- this.buffer[padLength - 2] = (bitLenLo >>> 8) & 0xff;
5826
- this.buffer[padLength - 1] = (bitLenLo >>> 0) & 0xff;
5827
- hashBlocks(this.temp, this.state, this.buffer, 0, padLength);
5828
- this.finished = true;
5829
- }
5830
- for (var i = 0; i < 8; i++) {
5831
- out[i * 4 + 0] = (this.state[i] >>> 24) & 0xff;
5832
- out[i * 4 + 1] = (this.state[i] >>> 16) & 0xff;
5833
- out[i * 4 + 2] = (this.state[i] >>> 8) & 0xff;
5834
- out[i * 4 + 3] = (this.state[i] >>> 0) & 0xff;
5835
- }
5836
- return this;
5837
- };
5838
- // Returns the final hash digest.
5839
- Hash.prototype.digest = function () {
5840
- var out = new Uint8Array(this.digestLength);
5841
- this.finish(out);
5842
- return out;
5843
- };
5844
- // Internal function for use in HMAC for optimization.
5845
- Hash.prototype._saveState = function (out) {
5846
- for (var i = 0; i < this.state.length; i++) {
5847
- out[i] = this.state[i];
5848
- }
5849
- };
5850
- // Internal function for use in HMAC for optimization.
5851
- Hash.prototype._restoreState = function (from, bytesHashed) {
5852
- for (var i = 0; i < this.state.length; i++) {
5853
- this.state[i] = from[i];
5854
- }
5855
- this.bytesHashed = bytesHashed;
5856
- this.finished = false;
5857
- this.bufferLength = 0;
5858
- };
5859
- return Hash;
5860
- }());
5861
- exports.Hash = Hash;
5862
- // HMAC implements HMAC-SHA256 message authentication algorithm.
5863
- var HMAC = /** @class */ (function () {
5864
- function HMAC(key) {
5865
- this.inner = new Hash();
5866
- this.outer = new Hash();
5867
- this.blockSize = this.inner.blockSize;
5868
- this.digestLength = this.inner.digestLength;
5869
- var pad = new Uint8Array(this.blockSize);
5870
- if (key.length > this.blockSize) {
5871
- (new Hash()).update(key).finish(pad).clean();
5872
- }
5873
- else {
5874
- for (var i = 0; i < key.length; i++) {
5875
- pad[i] = key[i];
5876
- }
5877
- }
5878
- for (var i = 0; i < pad.length; i++) {
5879
- pad[i] ^= 0x36;
5880
- }
5881
- this.inner.update(pad);
5882
- for (var i = 0; i < pad.length; i++) {
5883
- pad[i] ^= 0x36 ^ 0x5c;
5884
- }
5885
- this.outer.update(pad);
5886
- this.istate = new Uint32Array(8);
5887
- this.ostate = new Uint32Array(8);
5888
- this.inner._saveState(this.istate);
5889
- this.outer._saveState(this.ostate);
5890
- for (var i = 0; i < pad.length; i++) {
5891
- pad[i] = 0;
5892
- }
5893
- }
5894
- // Returns HMAC state to the state initialized with key
5895
- // to make it possible to run HMAC over the other data with the same
5896
- // key without creating a new instance.
5897
- HMAC.prototype.reset = function () {
5898
- this.inner._restoreState(this.istate, this.inner.blockSize);
5899
- this.outer._restoreState(this.ostate, this.outer.blockSize);
5900
- return this;
5901
- };
5902
- // Cleans HMAC state.
5903
- HMAC.prototype.clean = function () {
5904
- for (var i = 0; i < this.istate.length; i++) {
5905
- this.ostate[i] = this.istate[i] = 0;
5906
- }
5907
- this.inner.clean();
5908
- this.outer.clean();
5909
- };
5910
- // Updates state with provided data.
5911
- HMAC.prototype.update = function (data) {
5912
- this.inner.update(data);
5913
- return this;
5914
- };
5915
- // Finalizes HMAC and puts the result in out.
5916
- HMAC.prototype.finish = function (out) {
5917
- if (this.outer.finished) {
5918
- this.outer.finish(out);
5919
- }
5920
- else {
5921
- this.inner.finish(out);
5922
- this.outer.update(out, this.digestLength).finish(out);
5923
- }
5924
- return this;
5925
- };
5926
- // Returns message authentication code.
5927
- HMAC.prototype.digest = function () {
5928
- var out = new Uint8Array(this.digestLength);
5929
- this.finish(out);
5930
- return out;
5931
- };
5932
- return HMAC;
5933
- }());
5934
- exports.HMAC = HMAC;
5935
- // Returns SHA256 hash of data.
5936
- function hash(data) {
5937
- var h = (new Hash()).update(data);
5938
- var digest = h.digest();
5939
- h.clean();
5940
- return digest;
5941
- }
5942
- exports.hash = hash;
5943
- // Function hash is both available as module.hash and as default export.
5944
- exports["default"] = hash;
5945
- // Returns HMAC-SHA256 of data under the key.
5946
- function hmac(key, data) {
5947
- var h = (new HMAC(key)).update(data);
5948
- var digest = h.digest();
5949
- h.clean();
5950
- return digest;
5951
- }
5952
- exports.hmac = hmac;
5953
- // Fills hkdf buffer like this:
5954
- // T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
5955
- function fillBuffer(buffer, hmac, info, counter) {
5956
- // Counter is a byte value: check if it overflowed.
5957
- var num = counter[0];
5958
- if (num === 0) {
5959
- throw new Error("hkdf: cannot expand more");
5960
- }
5961
- // Prepare HMAC instance for new data with old key.
5962
- hmac.reset();
5963
- // Hash in previous output if it was generated
5964
- // (i.e. counter is greater than 1).
5965
- if (num > 1) {
5966
- hmac.update(buffer);
5967
- }
5968
- // Hash in info if it exists.
5969
- if (info) {
5970
- hmac.update(info);
5971
- }
5972
- // Hash in the counter.
5973
- hmac.update(counter);
5974
- // Output result to buffer and clean HMAC instance.
5975
- hmac.finish(buffer);
5976
- // Increment counter inside typed array, this works properly.
5977
- counter[0]++;
5978
- }
5979
- var hkdfSalt = new Uint8Array(exports.digestLength); // Filled with zeroes.
5980
- function hkdf(key, salt, info, length) {
5981
- if (salt === void 0) { salt = hkdfSalt; }
5982
- if (length === void 0) { length = 32; }
5983
- var counter = new Uint8Array([1]);
5984
- // HKDF-Extract uses salt as HMAC key, and key as data.
5985
- var okm = hmac(salt, key);
5986
- // Initialize HMAC for expanding with extracted key.
5987
- // Ensure no collisions with `hmac` function.
5988
- var hmac_ = new HMAC(okm);
5989
- // Allocate buffer.
5990
- var buffer = new Uint8Array(hmac_.digestLength);
5991
- var bufpos = buffer.length;
5992
- var out = new Uint8Array(length);
5993
- for (var i = 0; i < length; i++) {
5994
- if (bufpos === buffer.length) {
5995
- fillBuffer(buffer, hmac_, info, counter);
5996
- bufpos = 0;
5997
- }
5998
- out[i] = buffer[bufpos++];
5999
- }
6000
- hmac_.clean();
6001
- buffer.fill(0);
6002
- counter.fill(0);
6003
- return out;
6004
- }
6005
- exports.hkdf = hkdf;
6006
- // Derives a key from password and salt using PBKDF2-HMAC-SHA256
6007
- // with the given number of iterations.
6008
- //
6009
- // The number of bytes returned is equal to dkLen.
6010
- //
6011
- // (For better security, avoid dkLen greater than hash length - 32 bytes).
6012
- function pbkdf2(password, salt, iterations, dkLen) {
6013
- var prf = new HMAC(password);
6014
- var len = prf.digestLength;
6015
- var ctr = new Uint8Array(4);
6016
- var t = new Uint8Array(len);
6017
- var u = new Uint8Array(len);
6018
- var dk = new Uint8Array(dkLen);
6019
- for (var i = 0; i * len < dkLen; i++) {
6020
- var c = i + 1;
6021
- ctr[0] = (c >>> 24) & 0xff;
6022
- ctr[1] = (c >>> 16) & 0xff;
6023
- ctr[2] = (c >>> 8) & 0xff;
6024
- ctr[3] = (c >>> 0) & 0xff;
6025
- prf.reset();
6026
- prf.update(salt);
6027
- prf.update(ctr);
6028
- prf.finish(u);
6029
- for (var j = 0; j < len; j++) {
6030
- t[j] = u[j];
6031
- }
6032
- for (var j = 2; j <= iterations; j++) {
6033
- prf.reset();
6034
- prf.update(u).finish(u);
6035
- for (var k = 0; k < len; k++) {
6036
- t[k] ^= u[k];
6037
- }
6038
- }
6039
- for (var j = 0; j < len && i * len + j < dkLen; j++) {
6040
- dk[i * len + j] = t[j];
6041
- }
6042
- }
6043
- for (var i = 0; i < len; i++) {
6044
- t[i] = u[i] = 0;
6045
- }
6046
- for (var i = 0; i < 4; i++) {
6047
- ctr[i] = 0;
6048
- }
6049
- prf.clean();
6050
- return dk;
6051
- }
6052
- exports.pbkdf2 = pbkdf2;
6053
- });
6054
- } (sha256$1));
5573
+ }
5574
+ });
6055
5575
 
6056
- var sha256Exports = sha256$1.exports;
5576
+ // ../../node_modules/fast-sha256/sha256.js
5577
+ var require_sha256 = __commonJS({
5578
+ "../../node_modules/fast-sha256/sha256.js"(exports, module) {
5579
+ (function(root, factory) {
5580
+ var exports2 = {};
5581
+ factory(exports2);
5582
+ var sha2562 = exports2["default"];
5583
+ for (var k in exports2) {
5584
+ sha2562[k] = exports2[k];
5585
+ }
5586
+ if (typeof module === "object" && typeof module.exports === "object") {
5587
+ module.exports = sha2562;
5588
+ } else if (typeof define === "function" && define.amd) {
5589
+ define(function() {
5590
+ return sha2562;
5591
+ });
5592
+ } else {
5593
+ root.sha256 = sha2562;
5594
+ }
5595
+ })(exports, function(exports2) {
5596
+ exports2.__esModule = true;
5597
+ exports2.digestLength = 32;
5598
+ exports2.blockSize = 64;
5599
+ var K = new Uint32Array([
5600
+ 1116352408,
5601
+ 1899447441,
5602
+ 3049323471,
5603
+ 3921009573,
5604
+ 961987163,
5605
+ 1508970993,
5606
+ 2453635748,
5607
+ 2870763221,
5608
+ 3624381080,
5609
+ 310598401,
5610
+ 607225278,
5611
+ 1426881987,
5612
+ 1925078388,
5613
+ 2162078206,
5614
+ 2614888103,
5615
+ 3248222580,
5616
+ 3835390401,
5617
+ 4022224774,
5618
+ 264347078,
5619
+ 604807628,
5620
+ 770255983,
5621
+ 1249150122,
5622
+ 1555081692,
5623
+ 1996064986,
5624
+ 2554220882,
5625
+ 2821834349,
5626
+ 2952996808,
5627
+ 3210313671,
5628
+ 3336571891,
5629
+ 3584528711,
5630
+ 113926993,
5631
+ 338241895,
5632
+ 666307205,
5633
+ 773529912,
5634
+ 1294757372,
5635
+ 1396182291,
5636
+ 1695183700,
5637
+ 1986661051,
5638
+ 2177026350,
5639
+ 2456956037,
5640
+ 2730485921,
5641
+ 2820302411,
5642
+ 3259730800,
5643
+ 3345764771,
5644
+ 3516065817,
5645
+ 3600352804,
5646
+ 4094571909,
5647
+ 275423344,
5648
+ 430227734,
5649
+ 506948616,
5650
+ 659060556,
5651
+ 883997877,
5652
+ 958139571,
5653
+ 1322822218,
5654
+ 1537002063,
5655
+ 1747873779,
5656
+ 1955562222,
5657
+ 2024104815,
5658
+ 2227730452,
5659
+ 2361852424,
5660
+ 2428436474,
5661
+ 2756734187,
5662
+ 3204031479,
5663
+ 3329325298
5664
+ ]);
5665
+ function hashBlocks(w, v, p, pos, len) {
5666
+ var a, b, c, d, e, f, g, h, u, i, j, t1, t2;
5667
+ while (len >= 64) {
5668
+ a = v[0];
5669
+ b = v[1];
5670
+ c = v[2];
5671
+ d = v[3];
5672
+ e = v[4];
5673
+ f = v[5];
5674
+ g = v[6];
5675
+ h = v[7];
5676
+ for (i = 0; i < 16; i++) {
5677
+ j = pos + i * 4;
5678
+ w[i] = (p[j] & 255) << 24 | (p[j + 1] & 255) << 16 | (p[j + 2] & 255) << 8 | p[j + 3] & 255;
5679
+ }
5680
+ for (i = 16; i < 64; i++) {
5681
+ u = w[i - 2];
5682
+ t1 = (u >>> 17 | u << 32 - 17) ^ (u >>> 19 | u << 32 - 19) ^ u >>> 10;
5683
+ u = w[i - 15];
5684
+ t2 = (u >>> 7 | u << 32 - 7) ^ (u >>> 18 | u << 32 - 18) ^ u >>> 3;
5685
+ w[i] = (t1 + w[i - 7] | 0) + (t2 + w[i - 16] | 0);
5686
+ }
5687
+ for (i = 0; i < 64; i++) {
5688
+ t1 = (((e >>> 6 | e << 32 - 6) ^ (e >>> 11 | e << 32 - 11) ^ (e >>> 25 | e << 32 - 25)) + (e & f ^ ~e & g) | 0) + (h + (K[i] + w[i] | 0) | 0) | 0;
5689
+ t2 = ((a >>> 2 | a << 32 - 2) ^ (a >>> 13 | a << 32 - 13) ^ (a >>> 22 | a << 32 - 22)) + (a & b ^ a & c ^ b & c) | 0;
5690
+ h = g;
5691
+ g = f;
5692
+ f = e;
5693
+ e = d + t1 | 0;
5694
+ d = c;
5695
+ c = b;
5696
+ b = a;
5697
+ a = t1 + t2 | 0;
5698
+ }
5699
+ v[0] += a;
5700
+ v[1] += b;
5701
+ v[2] += c;
5702
+ v[3] += d;
5703
+ v[4] += e;
5704
+ v[5] += f;
5705
+ v[6] += g;
5706
+ v[7] += h;
5707
+ pos += 64;
5708
+ len -= 64;
5709
+ }
5710
+ return pos;
5711
+ }
5712
+ var Hash = (
5713
+ /** @class */
5714
+ function() {
5715
+ function Hash2() {
5716
+ this.digestLength = exports2.digestLength;
5717
+ this.blockSize = exports2.blockSize;
5718
+ this.state = new Int32Array(8);
5719
+ this.temp = new Int32Array(64);
5720
+ this.buffer = new Uint8Array(128);
5721
+ this.bufferLength = 0;
5722
+ this.bytesHashed = 0;
5723
+ this.finished = false;
5724
+ this.reset();
5725
+ }
5726
+ Hash2.prototype.reset = function() {
5727
+ this.state[0] = 1779033703;
5728
+ this.state[1] = 3144134277;
5729
+ this.state[2] = 1013904242;
5730
+ this.state[3] = 2773480762;
5731
+ this.state[4] = 1359893119;
5732
+ this.state[5] = 2600822924;
5733
+ this.state[6] = 528734635;
5734
+ this.state[7] = 1541459225;
5735
+ this.bufferLength = 0;
5736
+ this.bytesHashed = 0;
5737
+ this.finished = false;
5738
+ return this;
5739
+ };
5740
+ Hash2.prototype.clean = function() {
5741
+ for (var i = 0; i < this.buffer.length; i++) {
5742
+ this.buffer[i] = 0;
5743
+ }
5744
+ for (var i = 0; i < this.temp.length; i++) {
5745
+ this.temp[i] = 0;
5746
+ }
5747
+ this.reset();
5748
+ };
5749
+ Hash2.prototype.update = function(data, dataLength) {
5750
+ if (dataLength === void 0) {
5751
+ dataLength = data.length;
5752
+ }
5753
+ if (this.finished) {
5754
+ throw new Error("SHA256: can't update because hash was finished.");
5755
+ }
5756
+ var dataPos = 0;
5757
+ this.bytesHashed += dataLength;
5758
+ if (this.bufferLength > 0) {
5759
+ while (this.bufferLength < 64 && dataLength > 0) {
5760
+ this.buffer[this.bufferLength++] = data[dataPos++];
5761
+ dataLength--;
5762
+ }
5763
+ if (this.bufferLength === 64) {
5764
+ hashBlocks(this.temp, this.state, this.buffer, 0, 64);
5765
+ this.bufferLength = 0;
5766
+ }
5767
+ }
5768
+ if (dataLength >= 64) {
5769
+ dataPos = hashBlocks(this.temp, this.state, data, dataPos, dataLength);
5770
+ dataLength %= 64;
5771
+ }
5772
+ while (dataLength > 0) {
5773
+ this.buffer[this.bufferLength++] = data[dataPos++];
5774
+ dataLength--;
5775
+ }
5776
+ return this;
5777
+ };
5778
+ Hash2.prototype.finish = function(out) {
5779
+ if (!this.finished) {
5780
+ var bytesHashed = this.bytesHashed;
5781
+ var left = this.bufferLength;
5782
+ var bitLenHi = bytesHashed / 536870912 | 0;
5783
+ var bitLenLo = bytesHashed << 3;
5784
+ var padLength = bytesHashed % 64 < 56 ? 64 : 128;
5785
+ this.buffer[left] = 128;
5786
+ for (var i = left + 1; i < padLength - 8; i++) {
5787
+ this.buffer[i] = 0;
5788
+ }
5789
+ this.buffer[padLength - 8] = bitLenHi >>> 24 & 255;
5790
+ this.buffer[padLength - 7] = bitLenHi >>> 16 & 255;
5791
+ this.buffer[padLength - 6] = bitLenHi >>> 8 & 255;
5792
+ this.buffer[padLength - 5] = bitLenHi >>> 0 & 255;
5793
+ this.buffer[padLength - 4] = bitLenLo >>> 24 & 255;
5794
+ this.buffer[padLength - 3] = bitLenLo >>> 16 & 255;
5795
+ this.buffer[padLength - 2] = bitLenLo >>> 8 & 255;
5796
+ this.buffer[padLength - 1] = bitLenLo >>> 0 & 255;
5797
+ hashBlocks(this.temp, this.state, this.buffer, 0, padLength);
5798
+ this.finished = true;
5799
+ }
5800
+ for (var i = 0; i < 8; i++) {
5801
+ out[i * 4 + 0] = this.state[i] >>> 24 & 255;
5802
+ out[i * 4 + 1] = this.state[i] >>> 16 & 255;
5803
+ out[i * 4 + 2] = this.state[i] >>> 8 & 255;
5804
+ out[i * 4 + 3] = this.state[i] >>> 0 & 255;
5805
+ }
5806
+ return this;
5807
+ };
5808
+ Hash2.prototype.digest = function() {
5809
+ var out = new Uint8Array(this.digestLength);
5810
+ this.finish(out);
5811
+ return out;
5812
+ };
5813
+ Hash2.prototype._saveState = function(out) {
5814
+ for (var i = 0; i < this.state.length; i++) {
5815
+ out[i] = this.state[i];
5816
+ }
5817
+ };
5818
+ Hash2.prototype._restoreState = function(from, bytesHashed) {
5819
+ for (var i = 0; i < this.state.length; i++) {
5820
+ this.state[i] = from[i];
5821
+ }
5822
+ this.bytesHashed = bytesHashed;
5823
+ this.finished = false;
5824
+ this.bufferLength = 0;
5825
+ };
5826
+ return Hash2;
5827
+ }()
5828
+ );
5829
+ exports2.Hash = Hash;
5830
+ var HMAC = (
5831
+ /** @class */
5832
+ function() {
5833
+ function HMAC2(key) {
5834
+ this.inner = new Hash();
5835
+ this.outer = new Hash();
5836
+ this.blockSize = this.inner.blockSize;
5837
+ this.digestLength = this.inner.digestLength;
5838
+ var pad = new Uint8Array(this.blockSize);
5839
+ if (key.length > this.blockSize) {
5840
+ new Hash().update(key).finish(pad).clean();
5841
+ } else {
5842
+ for (var i = 0; i < key.length; i++) {
5843
+ pad[i] = key[i];
5844
+ }
5845
+ }
5846
+ for (var i = 0; i < pad.length; i++) {
5847
+ pad[i] ^= 54;
5848
+ }
5849
+ this.inner.update(pad);
5850
+ for (var i = 0; i < pad.length; i++) {
5851
+ pad[i] ^= 54 ^ 92;
5852
+ }
5853
+ this.outer.update(pad);
5854
+ this.istate = new Uint32Array(8);
5855
+ this.ostate = new Uint32Array(8);
5856
+ this.inner._saveState(this.istate);
5857
+ this.outer._saveState(this.ostate);
5858
+ for (var i = 0; i < pad.length; i++) {
5859
+ pad[i] = 0;
5860
+ }
5861
+ }
5862
+ HMAC2.prototype.reset = function() {
5863
+ this.inner._restoreState(this.istate, this.inner.blockSize);
5864
+ this.outer._restoreState(this.ostate, this.outer.blockSize);
5865
+ return this;
5866
+ };
5867
+ HMAC2.prototype.clean = function() {
5868
+ for (var i = 0; i < this.istate.length; i++) {
5869
+ this.ostate[i] = this.istate[i] = 0;
5870
+ }
5871
+ this.inner.clean();
5872
+ this.outer.clean();
5873
+ };
5874
+ HMAC2.prototype.update = function(data) {
5875
+ this.inner.update(data);
5876
+ return this;
5877
+ };
5878
+ HMAC2.prototype.finish = function(out) {
5879
+ if (this.outer.finished) {
5880
+ this.outer.finish(out);
5881
+ } else {
5882
+ this.inner.finish(out);
5883
+ this.outer.update(out, this.digestLength).finish(out);
5884
+ }
5885
+ return this;
5886
+ };
5887
+ HMAC2.prototype.digest = function() {
5888
+ var out = new Uint8Array(this.digestLength);
5889
+ this.finish(out);
5890
+ return out;
5891
+ };
5892
+ return HMAC2;
5893
+ }()
5894
+ );
5895
+ exports2.HMAC = HMAC;
5896
+ function hash(data) {
5897
+ var h = new Hash().update(data);
5898
+ var digest = h.digest();
5899
+ h.clean();
5900
+ return digest;
5901
+ }
5902
+ exports2.hash = hash;
5903
+ exports2["default"] = hash;
5904
+ function hmac2(key, data) {
5905
+ var h = new HMAC(key).update(data);
5906
+ var digest = h.digest();
5907
+ h.clean();
5908
+ return digest;
5909
+ }
5910
+ exports2.hmac = hmac2;
5911
+ function fillBuffer(buffer, hmac3, info, counter) {
5912
+ var num = counter[0];
5913
+ if (num === 0) {
5914
+ throw new Error("hkdf: cannot expand more");
5915
+ }
5916
+ hmac3.reset();
5917
+ if (num > 1) {
5918
+ hmac3.update(buffer);
5919
+ }
5920
+ if (info) {
5921
+ hmac3.update(info);
5922
+ }
5923
+ hmac3.update(counter);
5924
+ hmac3.finish(buffer);
5925
+ counter[0]++;
5926
+ }
5927
+ var hkdfSalt = new Uint8Array(exports2.digestLength);
5928
+ function hkdf(key, salt, info, length) {
5929
+ if (salt === void 0) {
5930
+ salt = hkdfSalt;
5931
+ }
5932
+ if (length === void 0) {
5933
+ length = 32;
5934
+ }
5935
+ var counter = new Uint8Array([1]);
5936
+ var okm = hmac2(salt, key);
5937
+ var hmac_ = new HMAC(okm);
5938
+ var buffer = new Uint8Array(hmac_.digestLength);
5939
+ var bufpos = buffer.length;
5940
+ var out = new Uint8Array(length);
5941
+ for (var i = 0; i < length; i++) {
5942
+ if (bufpos === buffer.length) {
5943
+ fillBuffer(buffer, hmac_, info, counter);
5944
+ bufpos = 0;
5945
+ }
5946
+ out[i] = buffer[bufpos++];
5947
+ }
5948
+ hmac_.clean();
5949
+ buffer.fill(0);
5950
+ counter.fill(0);
5951
+ return out;
5952
+ }
5953
+ exports2.hkdf = hkdf;
5954
+ function pbkdf2(password, salt, iterations, dkLen) {
5955
+ var prf = new HMAC(password);
5956
+ var len = prf.digestLength;
5957
+ var ctr = new Uint8Array(4);
5958
+ var t = new Uint8Array(len);
5959
+ var u = new Uint8Array(len);
5960
+ var dk = new Uint8Array(dkLen);
5961
+ for (var i = 0; i * len < dkLen; i++) {
5962
+ var c = i + 1;
5963
+ ctr[0] = c >>> 24 & 255;
5964
+ ctr[1] = c >>> 16 & 255;
5965
+ ctr[2] = c >>> 8 & 255;
5966
+ ctr[3] = c >>> 0 & 255;
5967
+ prf.reset();
5968
+ prf.update(salt);
5969
+ prf.update(ctr);
5970
+ prf.finish(u);
5971
+ for (var j = 0; j < len; j++) {
5972
+ t[j] = u[j];
5973
+ }
5974
+ for (var j = 2; j <= iterations; j++) {
5975
+ prf.reset();
5976
+ prf.update(u).finish(u);
5977
+ for (var k = 0; k < len; k++) {
5978
+ t[k] ^= u[k];
5979
+ }
5980
+ }
5981
+ for (var j = 0; j < len && i * len + j < dkLen; j++) {
5982
+ dk[i * len + j] = t[j];
5983
+ }
5984
+ }
5985
+ for (var i = 0; i < len; i++) {
5986
+ t[i] = u[i] = 0;
5987
+ }
5988
+ for (var i = 0; i < 4; i++) {
5989
+ ctr[i] = 0;
5990
+ }
5991
+ prf.clean();
5992
+ return dk;
5993
+ }
5994
+ exports2.pbkdf2 = pbkdf2;
5995
+ });
5996
+ }
5997
+ });
6057
5998
 
6058
- Object.defineProperty(dist, "__esModule", { value: true });
6059
- var Webhook_1 = dist.Webhook = WebhookVerificationError_1 = dist.WebhookVerificationError = void 0;
6060
- const timing_safe_equal_1 = timing_safe_equal;
6061
- const base64 = base64$1;
6062
- const sha256 = sha256Exports;
6063
- const WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
6064
- class ExtendableError extends Error {
6065
- constructor(message) {
6066
- super(message);
6067
- Object.setPrototypeOf(this, ExtendableError.prototype);
6068
- this.name = "ExtendableError";
6069
- this.stack = new Error(message).stack;
5999
+ // src/webhook/vendor/standardwebhook.ts
6000
+ var base64 = __toESM(require_base64());
6001
+ var sha256 = __toESM(require_sha256());
6002
+ var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
6003
+ var ExtendableError = class _ExtendableError extends Error {
6004
+ constructor(message) {
6005
+ super(message);
6006
+ Object.setPrototypeOf(this, _ExtendableError.prototype);
6007
+ this.name = "ExtendableError";
6008
+ this.stack = new Error(message).stack;
6009
+ }
6010
+ };
6011
+ var WebhookVerificationError = class _WebhookVerificationError extends ExtendableError {
6012
+ constructor(message) {
6013
+ super(message);
6014
+ Object.setPrototypeOf(this, _WebhookVerificationError.prototype);
6015
+ this.name = "WebhookVerificationError";
6016
+ }
6017
+ };
6018
+ var Webhook = class _Webhook {
6019
+ static prefix = "whsec_";
6020
+ key;
6021
+ constructor(secret, options) {
6022
+ if (!secret) {
6023
+ throw new Error("Secret can't be empty.");
6024
+ }
6025
+ if ((options == null ? void 0 : options.format) === "raw") {
6026
+ if (secret instanceof Uint8Array) {
6027
+ this.key = secret;
6028
+ } else {
6029
+ this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0));
6030
+ }
6031
+ } else {
6032
+ if (typeof secret !== "string") {
6033
+ throw new Error("Expected secret to be of type string");
6034
+ }
6035
+ if (secret.startsWith(_Webhook.prefix)) {
6036
+ secret = secret.substring(_Webhook.prefix.length);
6037
+ }
6038
+ this.key = base64.decode(secret);
6070
6039
  }
6071
- }
6072
- class WebhookVerificationError extends ExtendableError {
6073
- constructor(message) {
6074
- super(message);
6075
- Object.setPrototypeOf(this, WebhookVerificationError.prototype);
6076
- this.name = "WebhookVerificationError";
6040
+ }
6041
+ verify(payload, headers_) {
6042
+ const headers = {};
6043
+ for (const key of Object.keys(headers_)) {
6044
+ headers[key.toLowerCase()] = headers_[key];
6045
+ }
6046
+ const msgId = headers["webhook-id"];
6047
+ const msgSignature = headers["webhook-signature"];
6048
+ const msgTimestamp = headers["webhook-timestamp"];
6049
+ if (!msgSignature || !msgId || !msgTimestamp) {
6050
+ throw new WebhookVerificationError("Missing required headers");
6051
+ }
6052
+ const timestamp = this.verifyTimestamp(msgTimestamp);
6053
+ const computedSignature = this.sign(msgId, timestamp, payload);
6054
+ const expectedSignature = computedSignature.split(",")[1];
6055
+ const passedSignatures = msgSignature.split(" ");
6056
+ const encoder = new globalThis.TextEncoder();
6057
+ for (const versionedSignature of passedSignatures) {
6058
+ const [version, signature] = versionedSignature.split(",");
6059
+ if (version !== "v1") {
6060
+ continue;
6061
+ }
6062
+ if (timingSafeEqual(
6063
+ encoder.encode(signature),
6064
+ encoder.encode(expectedSignature)
6065
+ )) {
6066
+ return JSON.parse(payload.toString());
6067
+ }
6077
6068
  }
6078
- }
6079
- var WebhookVerificationError_1 = dist.WebhookVerificationError = WebhookVerificationError;
6080
- class Webhook {
6081
- constructor(secret, options) {
6082
- if (!secret) {
6083
- throw new Error("Secret can't be empty.");
6084
- }
6085
- if ((options === null || options === void 0 ? void 0 : options.format) === "raw") {
6086
- if (secret instanceof Uint8Array) {
6087
- this.key = secret;
6088
- }
6089
- else {
6090
- this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0));
6091
- }
6092
- }
6093
- else {
6094
- if (typeof secret !== "string") {
6095
- throw new Error("Expected secret to be of type string");
6096
- }
6097
- if (secret.startsWith(Webhook.prefix)) {
6098
- secret = secret.substring(Webhook.prefix.length);
6099
- }
6100
- this.key = base64.decode(secret);
6101
- }
6069
+ throw new WebhookVerificationError("No matching signature found");
6070
+ }
6071
+ sign(msgId, timestamp, payload) {
6072
+ if (typeof payload === "string") ; else if (payload.constructor.name === "Buffer") {
6073
+ payload = payload.toString();
6074
+ } else {
6075
+ throw new Error("Expected payload to be of type string or Buffer.");
6102
6076
  }
6103
- verify(payload, headers_) {
6104
- const headers = {};
6105
- for (const key of Object.keys(headers_)) {
6106
- headers[key.toLowerCase()] = headers_[key];
6107
- }
6108
- const msgId = headers["webhook-id"];
6109
- const msgSignature = headers["webhook-signature"];
6110
- const msgTimestamp = headers["webhook-timestamp"];
6111
- if (!msgSignature || !msgId || !msgTimestamp) {
6112
- throw new WebhookVerificationError("Missing required headers");
6113
- }
6114
- const timestamp = this.verifyTimestamp(msgTimestamp);
6115
- const computedSignature = this.sign(msgId, timestamp, payload);
6116
- const expectedSignature = computedSignature.split(",")[1];
6117
- const passedSignatures = msgSignature.split(" ");
6118
- const encoder = new globalThis.TextEncoder();
6119
- for (const versionedSignature of passedSignatures) {
6120
- const [version, signature] = versionedSignature.split(",");
6121
- if (version !== "v1") {
6122
- continue;
6123
- }
6124
- if ((0, timing_safe_equal_1.timingSafeEqual)(encoder.encode(signature), encoder.encode(expectedSignature))) {
6125
- return JSON.parse(payload.toString());
6126
- }
6127
- }
6128
- throw new WebhookVerificationError("No matching signature found");
6077
+ const encoder = new TextEncoder();
6078
+ const timestampNumber = Math.floor(timestamp.getTime() / 1e3);
6079
+ const toSign = encoder.encode(`${msgId}.${timestampNumber}.${payload}`);
6080
+ const expectedSignature = base64.encode(sha256.hmac(this.key, toSign));
6081
+ return `v1,${expectedSignature}`;
6082
+ }
6083
+ verifyTimestamp(timestampHeader) {
6084
+ const now = Math.floor(Date.now() / 1e3);
6085
+ const timestamp = parseInt(timestampHeader, 10);
6086
+ if (isNaN(timestamp)) {
6087
+ throw new WebhookVerificationError("Invalid Signature Headers");
6129
6088
  }
6130
- sign(msgId, timestamp, payload) {
6131
- if (typeof payload === "string") ;
6132
- else if (payload.constructor.name === "Buffer") {
6133
- payload = payload.toString();
6134
- }
6135
- else {
6136
- throw new Error("Expected payload to be of type string or Buffer.");
6137
- }
6138
- const encoder = new TextEncoder();
6139
- const timestampNumber = Math.floor(timestamp.getTime() / 1000);
6140
- const toSign = encoder.encode(`${msgId}.${timestampNumber}.${payload}`);
6141
- const expectedSignature = base64.encode(sha256.hmac(this.key, toSign));
6142
- return `v1,${expectedSignature}`;
6089
+ if (now - timestamp > WEBHOOK_TOLERANCE_IN_SECONDS) {
6090
+ throw new WebhookVerificationError("Message timestamp too old");
6143
6091
  }
6144
- verifyTimestamp(timestampHeader) {
6145
- const now = Math.floor(Date.now() / 1000);
6146
- const timestamp = parseInt(timestampHeader, 10);
6147
- if (isNaN(timestamp)) {
6148
- throw new WebhookVerificationError("Invalid Signature Headers");
6149
- }
6150
- if (now - timestamp > WEBHOOK_TOLERANCE_IN_SECONDS) {
6151
- throw new WebhookVerificationError("Message timestamp too old");
6152
- }
6153
- if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
6154
- throw new WebhookVerificationError("Message timestamp too new");
6155
- }
6156
- return new Date(timestamp * 1000);
6092
+ if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
6093
+ throw new WebhookVerificationError("Message timestamp too new");
6157
6094
  }
6158
- }
6159
- Webhook_1 = dist.Webhook = Webhook;
6160
- Webhook.prefix = "whsec_";
6095
+ return new Date(timestamp * 1e3);
6096
+ }
6097
+ };
6098
+ /**
6099
+ * The MIT License
6100
+ *
6101
+ * Copyright (c) 2023 Svix (https://www.svix.com)
6102
+ *
6103
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6104
+ * of this software and associated documentation files (the "Software"), to deal
6105
+ * in the Software without restriction, including without limitation the rights
6106
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6107
+ * copies of the Software, and to permit persons to whom the Software is
6108
+ * furnished to do so, subject to the following conditions:
6109
+ *
6110
+ * The above copyright notice and this permission notice shall be included in
6111
+ * all copies or substantial portions of the Software.
6112
+ *
6113
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6114
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6115
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6116
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6117
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6118
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
6119
+ * THE SOFTWARE.
6120
+ *
6121
+ * @fileoverview Server-only webhook verification implementation.
6122
+ * @description Vendored from standardwebhooks package to avoid bundling issues.
6123
+ * Uses Node.js crypto module - DO NOT import in client/browser code.
6124
+ * @license MIT
6125
+ * @internal
6126
+ */
6161
6127
 
6128
+ // src/webhook/webhook.ts
6162
6129
  async function handleWebhookPayload(payload, config, context) {
6163
6130
  const callHandler = (handler, payload2) => {
6164
6131
  if (!handler) return;
@@ -6245,11 +6212,11 @@ var verifyWebhookPayload = async ({
6245
6212
  headers,
6246
6213
  body
6247
6214
  }) => {
6248
- const standardWebhook = new Webhook_1(webhookKey);
6215
+ const standardWebhook = new Webhook(webhookKey);
6249
6216
  try {
6250
6217
  standardWebhook.verify(body, headers);
6251
6218
  } catch (e) {
6252
- if (e instanceof WebhookVerificationError_1) {
6219
+ if (e instanceof WebhookVerificationError) {
6253
6220
  throw new Error(e.message);
6254
6221
  }
6255
6222
  throw e;