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