@metamask-previews/notification-services-controller 0.0.0-preview-98d4c2a0 → 0.0.0-preview-23a96ae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/NotificationServicesController/NotificationServicesController.js +3 -3
  2. package/dist/NotificationServicesController/NotificationServicesController.mjs +2 -2
  3. package/dist/NotificationServicesController/index.js +4 -4
  4. package/dist/NotificationServicesController/index.mjs +3 -3
  5. package/dist/NotificationServicesController/services/onchain-notifications.js +2 -2
  6. package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -1
  7. package/dist/NotificationServicesPushController/NotificationServicesPushController.js +3 -3
  8. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +3 -3
  9. package/dist/NotificationServicesPushController/index.js +5 -5
  10. package/dist/NotificationServicesPushController/index.mjs +4 -4
  11. package/dist/NotificationServicesPushController/services/push/push-web.js +3 -3
  12. package/dist/NotificationServicesPushController/services/push/push-web.mjs +3 -3
  13. package/dist/NotificationServicesPushController/services/services.js +3 -3
  14. package/dist/NotificationServicesPushController/services/services.mjs +3 -3
  15. package/dist/NotificationServicesPushController/utils/get-notification-message.js +3 -3
  16. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +3 -3
  17. package/dist/NotificationServicesPushController/utils/index.js +3 -3
  18. package/dist/NotificationServicesPushController/utils/index.mjs +3 -3
  19. package/dist/{chunk-DNTK4U5M.js → chunk-53Y2GNFU.js} +1938 -899
  20. package/dist/chunk-53Y2GNFU.js.map +1 -0
  21. package/dist/{chunk-3F4M3OUO.mjs → chunk-6PPEQMF5.mjs} +2 -2
  22. package/dist/{chunk-XNBTOK6G.js → chunk-AXZU6W3P.js} +7 -7
  23. package/dist/{chunk-KTQP5UDT.mjs → chunk-F6TSWKZK.mjs} +1943 -904
  24. package/dist/chunk-F6TSWKZK.mjs.map +1 -0
  25. package/dist/chunk-G2ROCNJN.mjs +965 -0
  26. package/dist/chunk-G2ROCNJN.mjs.map +1 -0
  27. package/dist/{chunk-6B5FOWRH.js → chunk-G5RGQ3AG.js} +3 -3
  28. package/dist/{chunk-5OYPOYXZ.mjs → chunk-KKWCKF5W.mjs} +2 -2
  29. package/dist/chunk-ZDG7PIUJ.js +965 -0
  30. package/dist/chunk-ZDG7PIUJ.js.map +1 -0
  31. package/dist/index.js +5 -5
  32. package/dist/index.mjs +4 -4
  33. package/dist/tsconfig.build.tsbuildinfo +1 -1
  34. package/package.json +2 -4
  35. package/dist/chunk-DNTK4U5M.js.map +0 -1
  36. package/dist/chunk-KTQP5UDT.mjs.map +0 -1
  37. package/dist/chunk-UIRZIKC3.mjs +0 -187
  38. package/dist/chunk-UIRZIKC3.mjs.map +0 -1
  39. package/dist/chunk-VOZ7Y2OO.js +0 -187
  40. package/dist/chunk-VOZ7Y2OO.js.map +0 -1
  41. /package/dist/{chunk-3F4M3OUO.mjs.map → chunk-6PPEQMF5.mjs.map} +0 -0
  42. /package/dist/{chunk-XNBTOK6G.js.map → chunk-AXZU6W3P.js.map} +0 -0
  43. /package/dist/{chunk-6B5FOWRH.js.map → chunk-G5RGQ3AG.js.map} +0 -0
  44. /package/dist/{chunk-5OYPOYXZ.mjs.map → chunk-KKWCKF5W.mjs.map} +0 -0
@@ -1,30 +1,10 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunkUPVIT75Fjs = require('./chunk-UPVIT75F.js');
4
-
5
-
6
- var _chunk232HZSEVjs = require('./chunk-232HZSEV.js');
7
-
8
-
9
-
10
- var _chunkXNBTOK6Gjs = require('./chunk-XNBTOK6G.js');
11
-
12
-
13
- var _chunkZMNXLHACjs = require('./chunk-ZMNXLHAC.js');
14
-
15
-
16
-
17
-
18
- var _chunkVOZ7Y2OOjs = require('./chunk-VOZ7Y2OO.js');
19
3
 
20
4
 
21
5
  var _chunkPIZCE3JDjs = require('./chunk-PIZCE3JD.js');
22
6
 
23
7
 
24
- var _chunkCQ6CGSKZjs = require('./chunk-CQ6CGSKZ.js');
25
-
26
-
27
- var _chunkTLX5QQK5js = require('./chunk-TLX5QQK5.js');
28
8
 
29
9
 
30
10
 
@@ -169,12 +149,12 @@ var require_common = _chunkV46WVGWNjs.__commonJS.call(void 0, {
169
149
  createDebug.skips = [];
170
150
  createDebug.formatters = {};
171
151
  function selectColor(namespace) {
172
- let hash = 0;
152
+ let hash2 = 0;
173
153
  for (let i = 0; i < namespace.length; i++) {
174
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
175
- hash |= 0;
154
+ hash2 = (hash2 << 5) - hash2 + namespace.charCodeAt(i);
155
+ hash2 |= 0;
176
156
  }
177
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
157
+ return createDebug.colors[Math.abs(hash2) % createDebug.colors.length];
178
158
  }
179
159
  createDebug.selectColor = selectColor;
180
160
  function createDebug(namespace) {
@@ -578,15 +558,15 @@ var require_common2 = _chunkV46WVGWNjs.__commonJS.call(void 0, {
578
558
  function stringifyRequest(options, body) {
579
559
  const { method = "GET", path = "", port } = options;
580
560
  const origin = normalizeOrigin(options.proto, options.hostname, port);
581
- const log = {
561
+ const log3 = {
582
562
  method,
583
563
  url: `${origin}${path}`,
584
564
  headers: options.headers
585
565
  };
586
566
  if (body) {
587
- log.body = body;
567
+ log3.body = body;
588
568
  }
589
- return JSON.stringify(log, null, 2);
569
+ return JSON.stringify(log3, null, 2);
590
570
  }
591
571
  function isContentEncoded(headers) {
592
572
  const contentEncoding2 = headers["content-encoding"];
@@ -1691,7 +1671,7 @@ var require_interceptor = _chunkV46WVGWNjs.__commonJS.call(void 0, {
1691
1671
  "use strict";
1692
1672
  var stringify = require_stringify();
1693
1673
  var querystring = _chunkV46WVGWNjs.__require.call(void 0, "querystring");
1694
- var { URL, URLSearchParams } = _chunkV46WVGWNjs.__require.call(void 0, "url");
1674
+ var { URL: URL2, URLSearchParams } = _chunkV46WVGWNjs.__require.call(void 0, "url");
1695
1675
  var common = require_common2();
1696
1676
  var { remove } = require_intercept();
1697
1677
  var matchBody = require_match_body();
@@ -1745,7 +1725,7 @@ var require_interceptor = _chunkV46WVGWNjs.__commonJS.call(void 0, {
1745
1725
  this.delayConnectionInMs = 0;
1746
1726
  this.optional = false;
1747
1727
  if (uriIsStr && uri.includes("?")) {
1748
- const parsedURL = new URL(this.path, "http://localhost");
1728
+ const parsedURL = new URL2(this.path, "http://localhost");
1749
1729
  this.path = parsedURL.pathname;
1750
1730
  this.query(parsedURL.searchParams);
1751
1731
  this._key = `${this.method} ${scope.basePath}${this.path}`;
@@ -2742,18 +2722,18 @@ var require_scope = _chunkV46WVGWNjs.__commonJS.call(void 0, {
2742
2722
  var debug = require_browser()("nock.scope");
2743
2723
  var { EventEmitter } = _chunkV46WVGWNjs.__require.call(void 0, "events");
2744
2724
  var Interceptor = require_interceptor();
2745
- var { URL, Url: LegacyUrl } = url;
2725
+ var { URL: URL2, Url: LegacyUrl } = url;
2746
2726
  var fs;
2747
2727
  try {
2748
2728
  fs = _chunkV46WVGWNjs.__require.call(void 0, "fs");
2749
2729
  } catch (err) {
2750
2730
  }
2751
2731
  function normalizeUrl(u) {
2752
- if (!(u instanceof URL)) {
2732
+ if (!(u instanceof URL2)) {
2753
2733
  if (u instanceof LegacyUrl) {
2754
- return normalizeUrl(new URL(url.format(u)));
2734
+ return normalizeUrl(new URL2(url.format(u)));
2755
2735
  }
2756
- return normalizeUrl(new URL(u));
2736
+ return normalizeUrl(new URL2(u));
2757
2737
  }
2758
2738
  if (!/https?:/.test(u.protocol)) {
2759
2739
  throw new TypeError(
@@ -3299,13 +3279,13 @@ var require_back = _chunkV46WVGWNjs.__commonJS.call(void 0, {
3299
3279
  lockdown
3300
3280
  // use recorded nocks, disables all http calls even when not nocked, doesnt record
3301
3281
  };
3302
- Back.setMode = function(mode) {
3303
- if (!(mode in Modes)) {
3304
- throw new Error(`Unknown mode: ${mode}`);
3282
+ Back.setMode = function(mode2) {
3283
+ if (!(mode2 in Modes)) {
3284
+ throw new Error(`Unknown mode: ${mode2}`);
3305
3285
  }
3306
- Back.currentMode = mode;
3286
+ Back.currentMode = mode2;
3307
3287
  debug("New nock back mode:", Back.currentMode);
3308
- _mode = Modes[mode];
3288
+ _mode = Modes[mode2];
3309
3289
  _mode.setup();
3310
3290
  };
3311
3291
  Back.fixtures = null;
@@ -3365,936 +3345,1995 @@ var require_nock = _chunkV46WVGWNjs.__commonJS.call(void 0, {
3365
3345
  }
3366
3346
  });
3367
3347
 
3368
- // src/NotificationServicesController/index.ts
3369
- var NotificationServicesController_exports = {};
3370
- _chunkV46WVGWNjs.__export.call(void 0, NotificationServicesController_exports, {
3371
- Constants: () => _chunkCQ6CGSKZjs.constants_exports,
3372
- Mocks: () => fixtures_exports,
3373
- NotificationServicesController: () => _chunkXNBTOK6Gjs.NotificationServicesController,
3374
- Processors: () => _chunkUPVIT75Fjs.processors_exports,
3375
- Types: () => _chunk232HZSEVjs.types_exports,
3376
- defaultState: () => _chunkXNBTOK6Gjs.defaultState
3377
- });
3348
+ // ../profile-sync-controller/src/sdk/env.ts
3349
+ var ENV_URLS = {
3350
+ dev: {
3351
+ authApiUrl: "https://authentication.dev-api.cx.metamask.io",
3352
+ oidcApiUrl: "https://oidc.dev-api.cx.metamask.io",
3353
+ userStorageApiUrl: "https://user-storage.dev-api.cx.metamask.io"
3354
+ },
3355
+ uat: {
3356
+ authApiUrl: "https://authentication.uat-api.cx.metamask.io",
3357
+ oidcApiUrl: "https://oidc.uat-api.cx.metamask.io",
3358
+ userStorageApiUrl: "https://user-storage.uat-api.cx.metamask.io"
3359
+ },
3360
+ prd: {
3361
+ authApiUrl: "https://authentication.api.cx.metamask.io",
3362
+ oidcApiUrl: "https://oidc.api.cx.metamask.io",
3363
+ userStorageApiUrl: "https://user-storage.api.cx.metamask.io"
3364
+ }
3365
+ };
3366
+ function getEnvUrls(env) {
3367
+ if (!ENV_URLS[env]) {
3368
+ throw new Error("invalid environment configuration");
3369
+ }
3370
+ return ENV_URLS[env];
3371
+ }
3378
3372
 
3379
- // src/NotificationServicesController/__fixtures__/index.ts
3380
- var fixtures_exports = {};
3381
- _chunkV46WVGWNjs.__export.call(void 0, fixtures_exports, {
3382
- CONTENTFUL_RESPONSE: () => CONTENTFUL_RESPONSE,
3383
- MOCK_RAW_ON_CHAIN_NOTIFICATIONS: () => MOCK_RAW_ON_CHAIN_NOTIFICATIONS,
3384
- MOCK_USER_STORAGE_ACCOUNT: () => MOCK_USER_STORAGE_ACCOUNT,
3385
- MOCK_USER_STORAGE_CHAIN: () => MOCK_USER_STORAGE_CHAIN,
3386
- createMockFeatureAnnouncementAPIResult: () => createMockFeatureAnnouncementAPIResult,
3387
- createMockFeatureAnnouncementRaw: () => createMockFeatureAnnouncementRaw,
3388
- createMockFullUserStorage: () => createMockFullUserStorage,
3389
- createMockNotificationERC1155Received: () => createMockNotificationERC1155Received,
3390
- createMockNotificationERC1155Sent: () => createMockNotificationERC1155Sent,
3391
- createMockNotificationERC20Received: () => createMockNotificationERC20Received,
3392
- createMockNotificationERC20Sent: () => createMockNotificationERC20Sent,
3393
- createMockNotificationERC721Received: () => createMockNotificationERC721Received,
3394
- createMockNotificationERC721Sent: () => createMockNotificationERC721Sent,
3395
- createMockNotificationEthReceived: () => createMockNotificationEthReceived,
3396
- createMockNotificationEthSent: () => createMockNotificationEthSent,
3397
- createMockNotificationLidoReadyToBeWithdrawn: () => createMockNotificationLidoReadyToBeWithdrawn,
3398
- createMockNotificationLidoStakeCompleted: () => createMockNotificationLidoStakeCompleted,
3399
- createMockNotificationLidoWithdrawalCompleted: () => createMockNotificationLidoWithdrawalCompleted,
3400
- createMockNotificationLidoWithdrawalRequested: () => createMockNotificationLidoWithdrawalRequested,
3401
- createMockNotificationMetaMaskSwapsCompleted: () => createMockNotificationMetaMaskSwapsCompleted,
3402
- createMockNotificationRocketPoolStakeCompleted: () => createMockNotificationRocketPoolStakeCompleted,
3403
- createMockNotificationRocketPoolUnStakeCompleted: () => createMockNotificationRocketPoolUnStakeCompleted,
3404
- createMockNotificationTrigger: () => createMockNotificationTrigger,
3405
- createMockRawOnChainNotifications: () => createMockRawOnChainNotifications,
3406
- createMockUserStorage: () => createMockUserStorage,
3407
- createMockUserStorageWithTriggers: () => createMockUserStorageWithTriggers,
3408
- getMockBatchCreateTriggersResponse: () => getMockBatchCreateTriggersResponse,
3409
- getMockBatchDeleteTriggersResponse: () => getMockBatchDeleteTriggersResponse,
3410
- getMockFeatureAnnouncementResponse: () => getMockFeatureAnnouncementResponse,
3411
- getMockListNotificationsResponse: () => getMockListNotificationsResponse,
3412
- getMockMarkNotificationsAsReadResponse: () => getMockMarkNotificationsAsReadResponse,
3413
- mockBatchCreateTriggers: () => mockBatchCreateTriggers,
3414
- mockBatchDeleteTriggers: () => mockBatchDeleteTriggers,
3415
- mockFetchFeatureAnnouncementNotifications: () => mockFetchFeatureAnnouncementNotifications,
3416
- mockListNotifications: () => mockListNotifications,
3417
- mockMarkNotificationsAsRead: () => mockMarkNotificationsAsRead
3418
- });
3373
+ // ../../node_modules/@noble/ciphers/esm/_assert.js
3374
+ function isBytes(a) {
3375
+ return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
3376
+ }
3377
+ function bytes(b, ...lengths) {
3378
+ if (!isBytes(b))
3379
+ throw new Error("Uint8Array expected");
3380
+ if (lengths.length > 0 && !lengths.includes(b.length))
3381
+ throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
3382
+ }
3383
+ function exists(instance, checkFinished = true) {
3384
+ if (instance.destroyed)
3385
+ throw new Error("Hash instance has been destroyed");
3386
+ if (checkFinished && instance.finished)
3387
+ throw new Error("Hash#digest() has already been called");
3388
+ }
3389
+ function output(out, instance) {
3390
+ bytes(out);
3391
+ const min = instance.outputLen;
3392
+ if (out.length < min) {
3393
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
3394
+ }
3395
+ }
3396
+
3397
+ // ../../node_modules/@noble/ciphers/esm/utils.js
3398
+ var u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
3399
+ var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
3400
+ var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
3401
+ var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
3402
+ if (!isLE)
3403
+ throw new Error("Non little-endian hardware is not supported");
3404
+ function utf8ToBytes(str) {
3405
+ if (typeof str !== "string")
3406
+ throw new Error(`string expected, got ${typeof str}`);
3407
+ return new Uint8Array(new TextEncoder().encode(str));
3408
+ }
3409
+ function toBytes(data) {
3410
+ if (typeof data === "string")
3411
+ data = utf8ToBytes(data);
3412
+ else if (isBytes(data))
3413
+ data = data.slice();
3414
+ else
3415
+ throw new Error(`Uint8Array expected, got ${typeof data}`);
3416
+ return data;
3417
+ }
3418
+ function equalBytes(a, b) {
3419
+ if (a.length !== b.length)
3420
+ return false;
3421
+ let diff = 0;
3422
+ for (let i = 0; i < a.length; i++)
3423
+ diff |= a[i] ^ b[i];
3424
+ return diff === 0;
3425
+ }
3426
+ var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, c) => {
3427
+ Object.assign(c, params);
3428
+ return c;
3429
+ };
3430
+ function setBigUint64(view, byteOffset, value, isLE3) {
3431
+ if (typeof view.setBigUint64 === "function")
3432
+ return view.setBigUint64(byteOffset, value, isLE3);
3433
+ const _32n = BigInt(32);
3434
+ const _u32_max = BigInt(4294967295);
3435
+ const wh = Number(value >> _32n & _u32_max);
3436
+ const wl = Number(value & _u32_max);
3437
+ const h = isLE3 ? 4 : 0;
3438
+ const l = isLE3 ? 0 : 4;
3439
+ view.setUint32(byteOffset + h, wh, isLE3);
3440
+ view.setUint32(byteOffset + l, wl, isLE3);
3441
+ }
3419
3442
 
3420
- // src/NotificationServicesController/__fixtures__/mock-feature-announcements.ts
3421
- function createMockFeatureAnnouncementAPIResult() {
3443
+ // ../../node_modules/@noble/ciphers/esm/_polyval.js
3444
+ var BLOCK_SIZE = 16;
3445
+ var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
3446
+ var ZEROS32 = u32(ZEROS16);
3447
+ var POLY = 225;
3448
+ var mul2 = (s0, s1, s2, s3) => {
3449
+ const hiBit = s3 & 1;
3422
3450
  return {
3423
- sys: {
3424
- type: "Array"
3425
- },
3426
- total: 17,
3427
- skip: 0,
3428
- limit: 1,
3429
- items: [
3430
- {
3431
- metadata: {
3432
- tags: []
3433
- },
3434
- sys: {
3435
- space: {
3436
- sys: {
3437
- type: "Link",
3438
- linkType: "Space",
3439
- id: "jdkgyfmyd9sw"
3440
- }
3441
- },
3442
- id: "1ABRmHaNCgmxROKXXLXsMu",
3443
- type: "Entry",
3444
- createdAt: "2024-04-09T13:24:01.872Z",
3445
- updatedAt: "2024-04-09T13:24:01.872Z",
3446
- environment: {
3447
- sys: {
3448
- id: "master",
3449
- type: "Link",
3450
- linkType: "Environment"
3451
- }
3452
- },
3453
- revision: 1,
3454
- contentType: {
3455
- sys: {
3456
- type: "Link",
3457
- linkType: "ContentType",
3458
- id: "productAnnouncement"
3459
- }
3460
- },
3461
- locale: "en-US"
3462
- },
3463
- fields: {
3464
- title: "Don\u2019t miss out on airdrops and new NFT mints!",
3465
- id: "dont-miss-out-on-airdrops-and-new-nft-mints",
3466
- category: "ANNOUNCEMENT",
3467
- shortDescription: "Check your airdrop eligibility and see trending NFT drops. Head over to the Explore tab to get started. ",
3468
- image: {
3469
- sys: {
3470
- type: "Link",
3471
- linkType: "Asset",
3472
- id: "5jqq8sFeLc6XEoeWlpI3aB"
3473
- }
3474
- },
3475
- longDescription: {
3476
- data: {},
3477
- content: [
3478
- {
3479
- data: {},
3480
- content: [
3481
- {
3482
- data: {},
3483
- marks: [],
3484
- value: "You can now verify if any of your connected addresses are eligible for airdrops and other ERC-20 claims in a secure and convenient way. We\u2019ve also added trending NFT mints based on creators you\u2019ve minted from before or other tokens you hold. Head over to the Explore tab to get started. \n",
3485
- nodeType: "text"
3486
- }
3487
- ],
3488
- nodeType: "paragraph"
3489
- }
3490
- ],
3491
- nodeType: "document"
3492
- },
3493
- link: {
3494
- sys: {
3495
- type: "Link",
3496
- linkType: "Entry",
3497
- id: "62xKYM2ydo4F1mS5q97K5q"
3498
- }
3499
- }
3451
+ s3: s2 << 31 | s3 >>> 1,
3452
+ s2: s1 << 31 | s2 >>> 1,
3453
+ s1: s0 << 31 | s1 >>> 1,
3454
+ s0: s0 >>> 1 ^ POLY << 24 & -(hiBit & 1)
3455
+ // reduce % poly
3456
+ };
3457
+ };
3458
+ var swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
3459
+ function _toGHASHKey(k) {
3460
+ k.reverse();
3461
+ const hiBit = k[15] & 1;
3462
+ let carry = 0;
3463
+ for (let i = 0; i < k.length; i++) {
3464
+ const t = k[i];
3465
+ k[i] = t >>> 1 | carry;
3466
+ carry = (t & 1) << 7;
3467
+ }
3468
+ k[0] ^= -hiBit & 225;
3469
+ return k;
3470
+ }
3471
+ var estimateWindow = (bytes3) => {
3472
+ if (bytes3 > 64 * 1024)
3473
+ return 8;
3474
+ if (bytes3 > 1024)
3475
+ return 4;
3476
+ return 2;
3477
+ };
3478
+ var GHASH = class {
3479
+ // We select bits per window adaptively based on expectedLength
3480
+ constructor(key, expectedLength) {
3481
+ this.blockLen = BLOCK_SIZE;
3482
+ this.outputLen = BLOCK_SIZE;
3483
+ this.s0 = 0;
3484
+ this.s1 = 0;
3485
+ this.s2 = 0;
3486
+ this.s3 = 0;
3487
+ this.finished = false;
3488
+ key = toBytes(key);
3489
+ bytes(key, 16);
3490
+ const kView = createView(key);
3491
+ let k0 = kView.getUint32(0, false);
3492
+ let k1 = kView.getUint32(4, false);
3493
+ let k2 = kView.getUint32(8, false);
3494
+ let k3 = kView.getUint32(12, false);
3495
+ const doubles = [];
3496
+ for (let i = 0; i < 128; i++) {
3497
+ doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) });
3498
+ ({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul2(k0, k1, k2, k3));
3499
+ }
3500
+ const W = estimateWindow(expectedLength || 1024);
3501
+ if (![1, 2, 4, 8].includes(W))
3502
+ throw new Error(`ghash: wrong window size=${W}, should be 2, 4 or 8`);
3503
+ this.W = W;
3504
+ const bits = 128;
3505
+ const windows = bits / W;
3506
+ const windowSize = this.windowSize = 2 ** W;
3507
+ const items = [];
3508
+ for (let w = 0; w < windows; w++) {
3509
+ for (let byte = 0; byte < windowSize; byte++) {
3510
+ let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
3511
+ for (let j = 0; j < W; j++) {
3512
+ const bit = byte >>> W - j - 1 & 1;
3513
+ if (!bit)
3514
+ continue;
3515
+ const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W * w + j];
3516
+ s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
3500
3517
  }
3518
+ items.push({ s0, s1, s2, s3 });
3501
3519
  }
3502
- ],
3503
- includes: {
3504
- Entry: [
3505
- {
3506
- metadata: {
3507
- tags: []
3508
- },
3509
- sys: {
3510
- space: {
3511
- sys: {
3512
- type: "Link",
3513
- linkType: "Space",
3514
- id: "jdkgyfmyd9sw"
3515
- }
3516
- },
3517
- id: "62xKYM2ydo4F1mS5q97K5q",
3518
- type: "Entry",
3519
- createdAt: "2024-04-09T13:23:03.636Z",
3520
- updatedAt: "2024-04-09T13:23:03.636Z",
3521
- environment: {
3522
- sys: {
3523
- id: "master",
3524
- type: "Link",
3525
- linkType: "Environment"
3526
- }
3527
- },
3528
- revision: 1,
3529
- contentType: {
3530
- sys: {
3531
- type: "Link",
3532
- linkType: "ContentType",
3533
- id: "link"
3534
- }
3535
- },
3536
- locale: "en-US"
3537
- },
3538
- fields: {
3539
- extensionLinkText: "Try now",
3540
- extensionLinkRoute: "home.html"
3541
- }
3542
- }
3543
- ],
3544
- Asset: [
3545
- {
3546
- metadata: {
3547
- tags: []
3548
- },
3549
- sys: {
3550
- space: {
3551
- sys: {
3552
- type: "Link",
3553
- linkType: "Space",
3554
- id: "jdkgyfmyd9sw"
3555
- }
3556
- },
3557
- id: "5jqq8sFeLc6XEoeWlpI3aB",
3558
- type: "Asset",
3559
- createdAt: "2024-04-09T13:23:13.327Z",
3560
- updatedAt: "2024-04-09T13:23:13.327Z",
3561
- environment: {
3562
- sys: {
3563
- id: "master",
3564
- type: "Link",
3565
- linkType: "Environment"
3566
- }
3567
- },
3568
- revision: 1,
3569
- locale: "en-US"
3570
- },
3571
- fields: {
3572
- title: "PDAPP notification image Airdrops & NFT mints",
3573
- description: "",
3574
- file: {
3575
- url: "//images.ctfassets.net/jdkgyfmyd9sw/5jqq8sFeLc6XEoeWlpI3aB/73ee0f1afa9916c3a7538b0bbee09c26/PDAPP_notification_image_Airdrops___NFT_mints.png",
3576
- details: {
3577
- size: 797731,
3578
- image: {
3579
- width: 2880,
3580
- height: 1921
3581
- }
3582
- },
3583
- fileName: "PDAPP notification image_Airdrops & NFT mints.png",
3584
- contentType: "image/png"
3585
- }
3586
- }
3587
- }
3588
- ]
3589
3520
  }
3590
- };
3591
- }
3592
- function createMockFeatureAnnouncementRaw() {
3593
- return {
3594
- type: "features_announcement" /* FEATURES_ANNOUNCEMENT */,
3595
- createdAt: "2999-04-09T13:24:01.872Z",
3596
- data: {
3597
- id: "dont-miss-out-on-airdrops-and-new-nft-mints",
3598
- category: "ANNOUNCEMENT",
3599
- title: "Don\u2019t miss out on airdrops and new NFT mints!",
3600
- longDescription: `<p>You can now verify if any of your connected addresses are eligible for airdrops and other ERC-20 claims in a secure and convenient way. We\u2019ve also added trending NFT mints based on creators you\u2019ve minted from before or other tokens you hold. Head over to the Explore tab to get started.</p>`,
3601
- shortDescription: "Check your airdrop eligibility and see trending NFT drops. Head over to the Explore tab to get started.",
3602
- image: {
3603
- title: "PDAPP notification image Airdrops & NFT mints",
3604
- description: "",
3605
- url: "//images.ctfassets.net/jdkgyfmyd9sw/5jqq8sFeLc6XEoeWlpI3aB/73ee0f1afa9916c3a7538b0bbee09c26/PDAPP_notification_image_Airdrops___NFT_mints.png"
3606
- },
3607
- extensionLink: {
3608
- extensionLinkText: "Try now",
3609
- extensionLinkRoute: "home.html"
3521
+ this.t = items;
3522
+ }
3523
+ _updateBlock(s0, s1, s2, s3) {
3524
+ s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
3525
+ const { W, t, windowSize } = this;
3526
+ let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
3527
+ const mask = (1 << W) - 1;
3528
+ let w = 0;
3529
+ for (const num of [s0, s1, s2, s3]) {
3530
+ for (let bytePos = 0; bytePos < 4; bytePos++) {
3531
+ const byte = num >>> 8 * bytePos & 255;
3532
+ for (let bitPos = 8 / W - 1; bitPos >= 0; bitPos--) {
3533
+ const bit = byte >>> W * bitPos & mask;
3534
+ const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
3535
+ o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
3536
+ w += 1;
3537
+ }
3610
3538
  }
3611
3539
  }
3612
- };
3540
+ this.s0 = o0;
3541
+ this.s1 = o1;
3542
+ this.s2 = o2;
3543
+ this.s3 = o3;
3544
+ }
3545
+ update(data) {
3546
+ data = toBytes(data);
3547
+ exists(this);
3548
+ const b32 = u32(data);
3549
+ const blocks = Math.floor(data.length / BLOCK_SIZE);
3550
+ const left = data.length % BLOCK_SIZE;
3551
+ for (let i = 0; i < blocks; i++) {
3552
+ this._updateBlock(b32[i * 4 + 0], b32[i * 4 + 1], b32[i * 4 + 2], b32[i * 4 + 3]);
3553
+ }
3554
+ if (left) {
3555
+ ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
3556
+ this._updateBlock(ZEROS32[0], ZEROS32[1], ZEROS32[2], ZEROS32[3]);
3557
+ ZEROS32.fill(0);
3558
+ }
3559
+ return this;
3560
+ }
3561
+ destroy() {
3562
+ const { t } = this;
3563
+ for (const elm of t) {
3564
+ elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
3565
+ }
3566
+ }
3567
+ digestInto(out) {
3568
+ exists(this);
3569
+ output(out, this);
3570
+ this.finished = true;
3571
+ const { s0, s1, s2, s3 } = this;
3572
+ const o32 = u32(out);
3573
+ o32[0] = s0;
3574
+ o32[1] = s1;
3575
+ o32[2] = s2;
3576
+ o32[3] = s3;
3577
+ return out;
3578
+ }
3579
+ digest() {
3580
+ const res = new Uint8Array(BLOCK_SIZE);
3581
+ this.digestInto(res);
3582
+ this.destroy();
3583
+ return res;
3584
+ }
3585
+ };
3586
+ var Polyval = class extends GHASH {
3587
+ constructor(key, expectedLength) {
3588
+ key = toBytes(key);
3589
+ const ghKey = _toGHASHKey(key.slice());
3590
+ super(ghKey, expectedLength);
3591
+ ghKey.fill(0);
3592
+ }
3593
+ update(data) {
3594
+ data = toBytes(data);
3595
+ exists(this);
3596
+ const b32 = u32(data);
3597
+ const left = data.length % BLOCK_SIZE;
3598
+ const blocks = Math.floor(data.length / BLOCK_SIZE);
3599
+ for (let i = 0; i < blocks; i++) {
3600
+ this._updateBlock(swapLE(b32[i * 4 + 3]), swapLE(b32[i * 4 + 2]), swapLE(b32[i * 4 + 1]), swapLE(b32[i * 4 + 0]));
3601
+ }
3602
+ if (left) {
3603
+ ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
3604
+ this._updateBlock(swapLE(ZEROS32[3]), swapLE(ZEROS32[2]), swapLE(ZEROS32[1]), swapLE(ZEROS32[0]));
3605
+ ZEROS32.fill(0);
3606
+ }
3607
+ return this;
3608
+ }
3609
+ digestInto(out) {
3610
+ exists(this);
3611
+ output(out, this);
3612
+ this.finished = true;
3613
+ const { s0, s1, s2, s3 } = this;
3614
+ const o32 = u32(out);
3615
+ o32[0] = s0;
3616
+ o32[1] = s1;
3617
+ o32[2] = s2;
3618
+ o32[3] = s3;
3619
+ return out.reverse();
3620
+ }
3621
+ };
3622
+ function wrapConstructorWithKey(hashCons) {
3623
+ const hashC = (msg, key) => hashCons(key, msg.length).update(toBytes(msg)).digest();
3624
+ const tmp = hashCons(new Uint8Array(16), 0);
3625
+ hashC.outputLen = tmp.outputLen;
3626
+ hashC.blockLen = tmp.blockLen;
3627
+ hashC.create = (key, expectedLength) => hashCons(key, expectedLength);
3628
+ return hashC;
3613
3629
  }
3630
+ var ghash = wrapConstructorWithKey((key, expectedLength) => new GHASH(key, expectedLength));
3631
+ var polyval = wrapConstructorWithKey((key, expectedLength) => new Polyval(key, expectedLength));
3614
3632
 
3615
- // src/NotificationServicesController/__fixtures__/mock-notification-trigger.ts
3616
- var _uuid = require('uuid');
3617
- function createMockNotificationTrigger(override) {
3618
- return {
3619
- id: _uuid.v4.call(void 0, ),
3620
- address: "0xFAKE_ADDRESS",
3621
- chainId: "1",
3622
- kind: "eth_sent",
3623
- enabled: true,
3624
- ...override
3625
- };
3633
+ // ../../node_modules/@noble/ciphers/esm/aes.js
3634
+ var BLOCK_SIZE2 = 16;
3635
+ var BLOCK_SIZE32 = 4;
3636
+ var EMPTY_BLOCK = new Uint8Array(BLOCK_SIZE2);
3637
+ var POLY2 = 283;
3638
+ function mul22(n) {
3639
+ return n << 1 ^ POLY2 & -(n >> 7);
3626
3640
  }
3627
-
3628
- // src/NotificationServicesController/__fixtures__/mock-notification-user-storage.ts
3629
- var MOCK_USER_STORAGE_ACCOUNT = "0x0000000000000000000000000000000000000000";
3630
- var MOCK_USER_STORAGE_CHAIN = "1";
3631
- function createMockUserStorage(override) {
3632
- return {
3633
- [_chunkTLX5QQK5js.USER_STORAGE_VERSION_KEY]: "1",
3634
- [MOCK_USER_STORAGE_ACCOUNT]: {
3635
- [MOCK_USER_STORAGE_CHAIN]: {
3636
- "111-111-111-111": {
3637
- k: "erc20_received" /* ERC20_RECEIVED */,
3638
- e: true
3639
- },
3640
- "222-222-222-222": {
3641
- k: "erc20_sent" /* ERC20_SENT */,
3642
- e: true
3643
- }
3644
- }
3645
- },
3646
- ...override
3647
- };
3641
+ function mul(a, b) {
3642
+ let res = 0;
3643
+ for (; b > 0; b >>= 1) {
3644
+ res ^= a & -(b & 1);
3645
+ a = mul22(a);
3646
+ }
3647
+ return res;
3648
3648
  }
3649
- function createMockUserStorageWithTriggers(triggers) {
3650
- const userStorage = {
3651
- [_chunkTLX5QQK5js.USER_STORAGE_VERSION_KEY]: "1",
3652
- [MOCK_USER_STORAGE_ACCOUNT]: {
3653
- [MOCK_USER_STORAGE_CHAIN]: {}
3654
- }
3655
- };
3656
- triggers.forEach((t) => {
3657
- let tId;
3658
- let e;
3659
- let k;
3660
- if (typeof t === "string") {
3661
- tId = t;
3662
- e = true;
3663
- k = "erc20_received" /* ERC20_RECEIVED */;
3664
- } else {
3665
- tId = t.id;
3666
- e = t.e;
3667
- k = t.k ?? "erc20_received" /* ERC20_RECEIVED */;
3649
+ var sbox = /* @__PURE__ */ (() => {
3650
+ let t = new Uint8Array(256);
3651
+ for (let i = 0, x = 1; i < 256; i++, x ^= mul22(x))
3652
+ t[i] = x;
3653
+ const box = new Uint8Array(256);
3654
+ box[0] = 99;
3655
+ for (let i = 0; i < 255; i++) {
3656
+ let x = t[255 - i];
3657
+ x |= x << 8;
3658
+ box[t[i]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
3659
+ }
3660
+ return box;
3661
+ })();
3662
+ var invSbox = /* @__PURE__ */ sbox.map((_, j) => sbox.indexOf(j));
3663
+ var rotr32_8 = (n) => n << 24 | n >>> 8;
3664
+ var rotl32_8 = (n) => n << 8 | n >>> 24;
3665
+ function genTtable(sbox2, fn) {
3666
+ if (sbox2.length !== 256)
3667
+ throw new Error("Wrong sbox length");
3668
+ const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
3669
+ const T1 = T0.map(rotl32_8);
3670
+ const T2 = T1.map(rotl32_8);
3671
+ const T3 = T2.map(rotl32_8);
3672
+ const T01 = new Uint32Array(256 * 256);
3673
+ const T23 = new Uint32Array(256 * 256);
3674
+ const sbox22 = new Uint16Array(256 * 256);
3675
+ for (let i = 0; i < 256; i++) {
3676
+ for (let j = 0; j < 256; j++) {
3677
+ const idx = i * 256 + j;
3678
+ T01[idx] = T0[i] ^ T1[j];
3679
+ T23[idx] = T2[i] ^ T3[j];
3680
+ sbox22[idx] = sbox2[i] << 8 | sbox2[j];
3668
3681
  }
3669
- userStorage[MOCK_USER_STORAGE_ACCOUNT][MOCK_USER_STORAGE_CHAIN][tId] = {
3670
- k,
3671
- e
3672
- };
3673
- });
3674
- return userStorage;
3682
+ }
3683
+ return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
3675
3684
  }
3676
- function createMockFullUserStorage(props = {}) {
3677
- return _chunkPIZCE3JDjs.initializeUserStorage.call(void 0,
3678
- [{ address: props.address ?? MOCK_USER_STORAGE_ACCOUNT }],
3679
- props.triggersEnabled ?? true
3680
- );
3685
+ var tableEncoding = /* @__PURE__ */ genTtable(sbox, (s) => mul(s, 3) << 24 | s << 16 | s << 8 | mul(s, 2));
3686
+ var tableDecoding = /* @__PURE__ */ genTtable(invSbox, (s) => mul(s, 11) << 24 | mul(s, 13) << 16 | mul(s, 9) << 8 | mul(s, 14));
3687
+ var xPowers = /* @__PURE__ */ (() => {
3688
+ const p = new Uint8Array(16);
3689
+ for (let i = 0, x = 1; i < 16; i++, x = mul22(x))
3690
+ p[i] = x;
3691
+ return p;
3692
+ })();
3693
+ function expandKeyLE(key) {
3694
+ bytes(key);
3695
+ const len = key.length;
3696
+ if (![16, 24, 32].includes(len))
3697
+ throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${len}`);
3698
+ const { sbox2 } = tableEncoding;
3699
+ const k32 = u32(key);
3700
+ const Nk = k32.length;
3701
+ const subByte = (n) => applySbox(sbox2, n, n, n, n);
3702
+ const xk = new Uint32Array(len + 28);
3703
+ xk.set(k32);
3704
+ for (let i = Nk; i < xk.length; i++) {
3705
+ let t = xk[i - 1];
3706
+ if (i % Nk === 0)
3707
+ t = subByte(rotr32_8(t)) ^ xPowers[i / Nk - 1];
3708
+ else if (Nk > 6 && i % Nk === 4)
3709
+ t = subByte(t);
3710
+ xk[i] = xk[i - Nk] ^ t;
3711
+ }
3712
+ return xk;
3681
3713
  }
3682
-
3683
- // src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts
3684
- function createMockNotificationEthSent() {
3685
- const mockNotification = {
3686
- type: "eth_sent" /* ETH_SENT */,
3687
- id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3688
- trigger_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3689
- chain_id: 1,
3690
- block_number: 17485840,
3691
- block_timestamp: "2022-03-01T00:00:00Z",
3692
- tx_hash: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3693
- unread: true,
3694
- created_at: "2022-03-01T00:00:00Z",
3695
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3696
- data: {
3697
- kind: "eth_sent",
3698
- network_fee: {
3699
- gas_price: "207806259583",
3700
- native_token_price_in_usd: "0.83"
3701
- },
3702
- from: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3703
- to: "0x881D40237659C251811CEC9c364ef91dC08D300D",
3704
- amount: {
3705
- usd: "670.64",
3706
- eth: "0.005"
3707
- }
3714
+ function expandKeyDecLE(key) {
3715
+ const encKey = expandKeyLE(key);
3716
+ const xk = encKey.slice();
3717
+ const Nk = encKey.length;
3718
+ const { sbox2 } = tableEncoding;
3719
+ const { T0, T1, T2, T3 } = tableDecoding;
3720
+ for (let i = 0; i < Nk; i += 4) {
3721
+ for (let j = 0; j < 4; j++)
3722
+ xk[i + j] = encKey[Nk - i - 4 + j];
3723
+ }
3724
+ encKey.fill(0);
3725
+ for (let i = 4; i < Nk - 4; i++) {
3726
+ const x = xk[i];
3727
+ const w = applySbox(sbox2, x, x, x, x);
3728
+ xk[i] = T0[w & 255] ^ T1[w >>> 8 & 255] ^ T2[w >>> 16 & 255] ^ T3[w >>> 24];
3729
+ }
3730
+ return xk;
3731
+ }
3732
+ function apply0123(T01, T23, s0, s1, s2, s3) {
3733
+ return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
3734
+ }
3735
+ function applySbox(sbox2, s0, s1, s2, s3) {
3736
+ return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
3737
+ }
3738
+ function encrypt(xk, s0, s1, s2, s3) {
3739
+ const { sbox2, T01, T23 } = tableEncoding;
3740
+ let k = 0;
3741
+ s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
3742
+ const rounds = xk.length / 4 - 2;
3743
+ for (let i = 0; i < rounds; i++) {
3744
+ const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
3745
+ const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
3746
+ const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
3747
+ const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
3748
+ s0 = t02, s1 = t12, s2 = t22, s3 = t32;
3749
+ }
3750
+ const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
3751
+ const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
3752
+ const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
3753
+ const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
3754
+ return { s0: t0, s1: t1, s2: t2, s3: t3 };
3755
+ }
3756
+ function decrypt(xk, s0, s1, s2, s3) {
3757
+ const { sbox2, T01, T23 } = tableDecoding;
3758
+ let k = 0;
3759
+ s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
3760
+ const rounds = xk.length / 4 - 2;
3761
+ for (let i = 0; i < rounds; i++) {
3762
+ const t02 = xk[k++] ^ apply0123(T01, T23, s0, s3, s2, s1);
3763
+ const t12 = xk[k++] ^ apply0123(T01, T23, s1, s0, s3, s2);
3764
+ const t22 = xk[k++] ^ apply0123(T01, T23, s2, s1, s0, s3);
3765
+ const t32 = xk[k++] ^ apply0123(T01, T23, s3, s2, s1, s0);
3766
+ s0 = t02, s1 = t12, s2 = t22, s3 = t32;
3767
+ }
3768
+ const t0 = xk[k++] ^ applySbox(sbox2, s0, s3, s2, s1);
3769
+ const t1 = xk[k++] ^ applySbox(sbox2, s1, s0, s3, s2);
3770
+ const t2 = xk[k++] ^ applySbox(sbox2, s2, s1, s0, s3);
3771
+ const t3 = xk[k++] ^ applySbox(sbox2, s3, s2, s1, s0);
3772
+ return { s0: t0, s1: t1, s2: t2, s3: t3 };
3773
+ }
3774
+ function getDst(len, dst) {
3775
+ if (!dst)
3776
+ return new Uint8Array(len);
3777
+ bytes(dst);
3778
+ if (dst.length < len)
3779
+ throw new Error(`aes: wrong destination length, expected at least ${len}, got: ${dst.length}`);
3780
+ return dst;
3781
+ }
3782
+ function ctrCounter(xk, nonce, src, dst) {
3783
+ bytes(nonce, BLOCK_SIZE2);
3784
+ bytes(src);
3785
+ const srcLen = src.length;
3786
+ dst = getDst(srcLen, dst);
3787
+ const ctr4 = nonce;
3788
+ const c32 = u32(ctr4);
3789
+ let { s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]);
3790
+ const src32 = u32(src);
3791
+ const dst32 = u32(dst);
3792
+ for (let i = 0; i + 4 <= src32.length; i += 4) {
3793
+ dst32[i + 0] = src32[i + 0] ^ s0;
3794
+ dst32[i + 1] = src32[i + 1] ^ s1;
3795
+ dst32[i + 2] = src32[i + 2] ^ s2;
3796
+ dst32[i + 3] = src32[i + 3] ^ s3;
3797
+ let carry = 1;
3798
+ for (let i2 = ctr4.length - 1; i2 >= 0; i2--) {
3799
+ carry = carry + (ctr4[i2] & 255) | 0;
3800
+ ctr4[i2] = carry & 255;
3801
+ carry >>>= 8;
3708
3802
  }
3803
+ ({ s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]));
3804
+ }
3805
+ const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
3806
+ if (start < srcLen) {
3807
+ const b32 = new Uint32Array([s0, s1, s2, s3]);
3808
+ const buf = u8(b32);
3809
+ for (let i = start, pos = 0; i < srcLen; i++, pos++)
3810
+ dst[i] = src[i] ^ buf[pos];
3811
+ }
3812
+ return dst;
3813
+ }
3814
+ function ctr32(xk, isLE3, nonce, src, dst) {
3815
+ bytes(nonce, BLOCK_SIZE2);
3816
+ bytes(src);
3817
+ dst = getDst(src.length, dst);
3818
+ const ctr4 = nonce;
3819
+ const c32 = u32(ctr4);
3820
+ const view = createView(ctr4);
3821
+ const src32 = u32(src);
3822
+ const dst32 = u32(dst);
3823
+ const ctrPos = isLE3 ? 0 : 12;
3824
+ const srcLen = src.length;
3825
+ let ctrNum = view.getUint32(ctrPos, isLE3);
3826
+ let { s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]);
3827
+ for (let i = 0; i + 4 <= src32.length; i += 4) {
3828
+ dst32[i + 0] = src32[i + 0] ^ s0;
3829
+ dst32[i + 1] = src32[i + 1] ^ s1;
3830
+ dst32[i + 2] = src32[i + 2] ^ s2;
3831
+ dst32[i + 3] = src32[i + 3] ^ s3;
3832
+ ctrNum = ctrNum + 1 >>> 0;
3833
+ view.setUint32(ctrPos, ctrNum, isLE3);
3834
+ ({ s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]));
3835
+ }
3836
+ const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
3837
+ if (start < srcLen) {
3838
+ const b32 = new Uint32Array([s0, s1, s2, s3]);
3839
+ const buf = u8(b32);
3840
+ for (let i = start, pos = 0; i < srcLen; i++, pos++)
3841
+ dst[i] = src[i] ^ buf[pos];
3842
+ }
3843
+ return dst;
3844
+ }
3845
+ var ctr = wrapCipher({ blockSize: 16, nonceLength: 16 }, function ctr2(key, nonce) {
3846
+ bytes(key);
3847
+ bytes(nonce, BLOCK_SIZE2);
3848
+ function processCtr(buf, dst) {
3849
+ const xk = expandKeyLE(key);
3850
+ const n = nonce.slice();
3851
+ const out = ctrCounter(xk, n, buf, dst);
3852
+ xk.fill(0);
3853
+ n.fill(0);
3854
+ return out;
3855
+ }
3856
+ return {
3857
+ encrypt: (plaintext, dst) => processCtr(plaintext, dst),
3858
+ decrypt: (ciphertext, dst) => processCtr(ciphertext, dst)
3709
3859
  };
3710
- return mockNotification;
3860
+ });
3861
+ function validateBlockDecrypt(data) {
3862
+ bytes(data);
3863
+ if (data.length % BLOCK_SIZE2 !== 0) {
3864
+ throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE2}`);
3865
+ }
3711
3866
  }
3712
- function createMockNotificationEthReceived() {
3713
- const mockNotification = {
3714
- type: "eth_received" /* ETH_RECEIVED */,
3715
- id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3716
- trigger_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3717
- chain_id: 1,
3718
- block_number: 17485840,
3719
- block_timestamp: "2022-03-01T00:00:00Z",
3720
- tx_hash: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3721
- unread: true,
3722
- created_at: "2022-03-01T00:00:00Z",
3723
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3724
- data: {
3725
- kind: "eth_received",
3726
- network_fee: {
3727
- gas_price: "207806259583",
3728
- native_token_price_in_usd: "0.83"
3729
- },
3730
- from: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3731
- to: "0x881D40237659C251811CEC9c364ef91dC08D300D",
3732
- amount: {
3733
- usd: "670.64",
3734
- eth: "808.000000000000000000"
3735
- }
3867
+ function validateBlockEncrypt(plaintext, pcks5, dst) {
3868
+ let outLen = plaintext.length;
3869
+ const remaining = outLen % BLOCK_SIZE2;
3870
+ if (!pcks5 && remaining !== 0)
3871
+ throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
3872
+ const b = u32(plaintext);
3873
+ if (pcks5) {
3874
+ let left = BLOCK_SIZE2 - remaining;
3875
+ if (!left)
3876
+ left = BLOCK_SIZE2;
3877
+ outLen = outLen + left;
3878
+ }
3879
+ const out = getDst(outLen, dst);
3880
+ const o = u32(out);
3881
+ return { b, o, out };
3882
+ }
3883
+ function validatePCKS(data, pcks5) {
3884
+ if (!pcks5)
3885
+ return data;
3886
+ const len = data.length;
3887
+ if (!len)
3888
+ throw new Error(`aes/pcks5: empty ciphertext not allowed`);
3889
+ const lastByte = data[len - 1];
3890
+ if (lastByte <= 0 || lastByte > 16)
3891
+ throw new Error(`aes/pcks5: wrong padding byte: ${lastByte}`);
3892
+ const out = data.subarray(0, -lastByte);
3893
+ for (let i = 0; i < lastByte; i++)
3894
+ if (data[len - i - 1] !== lastByte)
3895
+ throw new Error(`aes/pcks5: wrong padding`);
3896
+ return out;
3897
+ }
3898
+ function padPCKS(left) {
3899
+ const tmp = new Uint8Array(16);
3900
+ const tmp32 = u32(tmp);
3901
+ tmp.set(left);
3902
+ const paddingByte = BLOCK_SIZE2 - left.length;
3903
+ for (let i = BLOCK_SIZE2 - paddingByte; i < BLOCK_SIZE2; i++)
3904
+ tmp[i] = paddingByte;
3905
+ return tmp32;
3906
+ }
3907
+ var ecb = wrapCipher({ blockSize: 16 }, function ecb2(key, opts = {}) {
3908
+ bytes(key);
3909
+ const pcks5 = !opts.disablePadding;
3910
+ return {
3911
+ encrypt: (plaintext, dst) => {
3912
+ bytes(plaintext);
3913
+ const { b, o, out: _out } = validateBlockEncrypt(plaintext, pcks5, dst);
3914
+ const xk = expandKeyLE(key);
3915
+ let i = 0;
3916
+ for (; i + 4 <= b.length; ) {
3917
+ const { s0, s1, s2, s3 } = encrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
3918
+ o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
3919
+ }
3920
+ if (pcks5) {
3921
+ const tmp32 = padPCKS(plaintext.subarray(i * 4));
3922
+ const { s0, s1, s2, s3 } = encrypt(xk, tmp32[0], tmp32[1], tmp32[2], tmp32[3]);
3923
+ o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
3924
+ }
3925
+ xk.fill(0);
3926
+ return _out;
3927
+ },
3928
+ decrypt: (ciphertext, dst) => {
3929
+ validateBlockDecrypt(ciphertext);
3930
+ const xk = expandKeyDecLE(key);
3931
+ const out = getDst(ciphertext.length, dst);
3932
+ const b = u32(ciphertext);
3933
+ const o = u32(out);
3934
+ for (let i = 0; i + 4 <= b.length; ) {
3935
+ const { s0, s1, s2, s3 } = decrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
3936
+ o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
3937
+ }
3938
+ xk.fill(0);
3939
+ return validatePCKS(out, pcks5);
3736
3940
  }
3737
3941
  };
3738
- return mockNotification;
3739
- }
3740
- function createMockNotificationERC20Sent() {
3741
- const mockNotification = {
3742
- type: "erc20_sent" /* ERC20_SENT */,
3743
- id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3744
- trigger_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3745
- chain_id: 1,
3746
- block_number: 17485840,
3747
- block_timestamp: "2022-03-01T00:00:00Z",
3748
- tx_hash: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3749
- unread: true,
3750
- created_at: "2022-03-01T00:00:00Z",
3751
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3752
- data: {
3753
- kind: "erc20_sent",
3754
- network_fee: {
3755
- gas_price: "207806259583",
3756
- native_token_price_in_usd: "0.83"
3757
- },
3758
- to: "0xecc19e177d24551aa7ed6bc6fe566eca726cc8a9",
3759
- from: "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
3760
- token: {
3761
- usd: "1.00",
3762
- name: "USDC",
3763
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/usdc.svg",
3764
- amount: "4956250000",
3765
- symbol: "USDC",
3766
- address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
3767
- decimals: "6"
3768
- }
3942
+ });
3943
+ var cbc = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cbc2(key, iv, opts = {}) {
3944
+ bytes(key);
3945
+ bytes(iv, 16);
3946
+ const pcks5 = !opts.disablePadding;
3947
+ return {
3948
+ encrypt: (plaintext, dst) => {
3949
+ const xk = expandKeyLE(key);
3950
+ const { b, o, out: _out } = validateBlockEncrypt(plaintext, pcks5, dst);
3951
+ const n32 = u32(iv);
3952
+ let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
3953
+ let i = 0;
3954
+ for (; i + 4 <= b.length; ) {
3955
+ s0 ^= b[i + 0], s1 ^= b[i + 1], s2 ^= b[i + 2], s3 ^= b[i + 3];
3956
+ ({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
3957
+ o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
3958
+ }
3959
+ if (pcks5) {
3960
+ const tmp32 = padPCKS(plaintext.subarray(i * 4));
3961
+ s0 ^= tmp32[0], s1 ^= tmp32[1], s2 ^= tmp32[2], s3 ^= tmp32[3];
3962
+ ({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
3963
+ o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
3964
+ }
3965
+ xk.fill(0);
3966
+ return _out;
3967
+ },
3968
+ decrypt: (ciphertext, dst) => {
3969
+ validateBlockDecrypt(ciphertext);
3970
+ const xk = expandKeyDecLE(key);
3971
+ const n32 = u32(iv);
3972
+ const out = getDst(ciphertext.length, dst);
3973
+ const b = u32(ciphertext);
3974
+ const o = u32(out);
3975
+ let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
3976
+ for (let i = 0; i + 4 <= b.length; ) {
3977
+ const ps0 = s0, ps1 = s1, ps2 = s2, ps3 = s3;
3978
+ s0 = b[i + 0], s1 = b[i + 1], s2 = b[i + 2], s3 = b[i + 3];
3979
+ const { s0: o0, s1: o1, s2: o2, s3: o3 } = decrypt(xk, s0, s1, s2, s3);
3980
+ o[i++] = o0 ^ ps0, o[i++] = o1 ^ ps1, o[i++] = o2 ^ ps2, o[i++] = o3 ^ ps3;
3981
+ }
3982
+ xk.fill(0);
3983
+ return validatePCKS(out, pcks5);
3769
3984
  }
3770
3985
  };
3771
- return mockNotification;
3772
- }
3773
- function createMockNotificationERC20Received() {
3774
- const mockNotification = {
3775
- type: "erc20_received" /* ERC20_RECEIVED */,
3776
- id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3777
- trigger_id: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
3778
- chain_id: 1,
3779
- block_number: 17485840,
3780
- block_timestamp: "2022-03-01T00:00:00Z",
3781
- tx_hash: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3782
- unread: true,
3783
- created_at: "2022-03-01T00:00:00Z",
3784
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3785
- data: {
3786
- kind: "erc20_received",
3787
- network_fee: {
3788
- gas_price: "207806259583",
3789
- native_token_price_in_usd: "0.83"
3790
- },
3791
- to: "0xeae7380dd4cef6fbd1144f49e4d1e6964258a4f4",
3792
- from: "0x51c72848c68a965f66fa7a88855f9f7784502a7f",
3793
- token: {
3794
- usd: "0.00",
3795
- name: "SHIBA INU",
3796
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/shib.svg",
3797
- amount: "8382798736999999457296646144",
3798
- symbol: "SHIB",
3799
- address: "0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce",
3800
- decimals: "18"
3801
- }
3986
+ });
3987
+ var cfb = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cfb2(key, iv) {
3988
+ bytes(key);
3989
+ bytes(iv, 16);
3990
+ function processCfb(src, isEncrypt, dst) {
3991
+ const xk = expandKeyLE(key);
3992
+ const srcLen = src.length;
3993
+ dst = getDst(srcLen, dst);
3994
+ const src32 = u32(src);
3995
+ const dst32 = u32(dst);
3996
+ const next32 = isEncrypt ? dst32 : src32;
3997
+ const n32 = u32(iv);
3998
+ let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
3999
+ for (let i = 0; i + 4 <= src32.length; ) {
4000
+ const { s0: e0, s1: e1, s2: e2, s3: e3 } = encrypt(xk, s0, s1, s2, s3);
4001
+ dst32[i + 0] = src32[i + 0] ^ e0;
4002
+ dst32[i + 1] = src32[i + 1] ^ e1;
4003
+ dst32[i + 2] = src32[i + 2] ^ e2;
4004
+ dst32[i + 3] = src32[i + 3] ^ e3;
4005
+ s0 = next32[i++], s1 = next32[i++], s2 = next32[i++], s3 = next32[i++];
4006
+ }
4007
+ const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
4008
+ if (start < srcLen) {
4009
+ ({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
4010
+ const buf = u8(new Uint32Array([s0, s1, s2, s3]));
4011
+ for (let i = start, pos = 0; i < srcLen; i++, pos++)
4012
+ dst[i] = src[i] ^ buf[pos];
4013
+ buf.fill(0);
3802
4014
  }
4015
+ xk.fill(0);
4016
+ return dst;
4017
+ }
4018
+ return {
4019
+ encrypt: (plaintext, dst) => processCfb(plaintext, true, dst),
4020
+ decrypt: (ciphertext, dst) => processCfb(ciphertext, false, dst)
3803
4021
  };
3804
- return mockNotification;
4022
+ });
4023
+ function computeTag(fn, isLE3, key, data, AAD) {
4024
+ const h = fn.create(key, data.length + (AAD?.length || 0));
4025
+ if (AAD)
4026
+ h.update(AAD);
4027
+ h.update(data);
4028
+ const num = new Uint8Array(16);
4029
+ const view = createView(num);
4030
+ if (AAD)
4031
+ setBigUint64(view, 0, BigInt(AAD.length * 8), isLE3);
4032
+ setBigUint64(view, 8, BigInt(data.length * 8), isLE3);
4033
+ h.update(num);
4034
+ return h.digest();
3805
4035
  }
3806
- function createMockNotificationERC721Sent() {
3807
- const mockNotification = {
3808
- type: "erc721_sent" /* ERC721_SENT */,
3809
- block_number: 18576643,
3810
- block_timestamp: "1700043467",
3811
- chain_id: 1,
3812
- created_at: "2023-11-15T11:08:17.895407Z",
3813
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3814
- data: {
3815
- to: "0xf47f628fe3bd2595e9ab384bfffc3859b448e451",
3816
- nft: {
3817
- name: "Captainz #8680",
3818
- image: "https://i.seadn.io/s/raw/files/ae0fc06714ff7fb40217340d8a242c0e.gif?w=500&auto=format",
3819
- token_id: "8680",
3820
- collection: {
3821
- name: "The Captainz",
3822
- image: "https://i.seadn.io/gcs/files/6df4d75778066bce740050615bc84e21.png?w=500&auto=format",
3823
- symbol: "Captainz",
3824
- address: "0x769272677fab02575e84945f03eca517acc544cc"
3825
- }
3826
- },
3827
- from: "0x24a0bb54b7e7a8e406e9b28058a9fd6c49e6df4f",
3828
- kind: "erc721_sent",
3829
- network_fee: {
3830
- gas_price: "24550653274",
3831
- native_token_price_in_usd: "1986.61"
3832
- }
4036
+ var gcm = wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16 }, function gcm2(key, nonce, AAD) {
4037
+ bytes(nonce);
4038
+ if (nonce.length === 0)
4039
+ throw new Error("aes/gcm: empty nonce");
4040
+ const tagLength = 16;
4041
+ function _computeTag(authKey, tagMask, data) {
4042
+ const tag = computeTag(ghash, false, authKey, data, AAD);
4043
+ for (let i = 0; i < tagMask.length; i++)
4044
+ tag[i] ^= tagMask[i];
4045
+ return tag;
4046
+ }
4047
+ function deriveKeys() {
4048
+ const xk = expandKeyLE(key);
4049
+ const authKey = EMPTY_BLOCK.slice();
4050
+ const counter = EMPTY_BLOCK.slice();
4051
+ ctr32(xk, false, counter, counter, authKey);
4052
+ if (nonce.length === 12) {
4053
+ counter.set(nonce);
4054
+ } else {
4055
+ const nonceLen = EMPTY_BLOCK.slice();
4056
+ const view = createView(nonceLen);
4057
+ setBigUint64(view, 8, BigInt(nonce.length * 8), false);
4058
+ ghash.create(authKey).update(nonce).update(nonceLen).digestInto(counter);
4059
+ }
4060
+ const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
4061
+ return { xk, authKey, counter, tagMask };
4062
+ }
4063
+ return {
4064
+ encrypt: (plaintext) => {
4065
+ bytes(plaintext);
4066
+ const { xk, authKey, counter, tagMask } = deriveKeys();
4067
+ const out = new Uint8Array(plaintext.length + tagLength);
4068
+ ctr32(xk, false, counter, plaintext, out);
4069
+ const tag = _computeTag(authKey, tagMask, out.subarray(0, out.length - tagLength));
4070
+ out.set(tag, plaintext.length);
4071
+ xk.fill(0);
4072
+ return out;
3833
4073
  },
3834
- id: "a4193058-9814-537e-9df4-79dcac727fb6",
3835
- trigger_id: "028485be-b994-422b-a93b-03fcc01ab715",
3836
- tx_hash: "0x0833c69fb41cf972a0f031fceca242939bc3fcf82b964b74606649abcad371bd",
3837
- unread: true
4074
+ decrypt: (ciphertext) => {
4075
+ bytes(ciphertext);
4076
+ if (ciphertext.length < tagLength)
4077
+ throw new Error(`aes/gcm: ciphertext less than tagLen (${tagLength})`);
4078
+ const { xk, authKey, counter, tagMask } = deriveKeys();
4079
+ const data = ciphertext.subarray(0, -tagLength);
4080
+ const passedTag = ciphertext.subarray(-tagLength);
4081
+ const tag = _computeTag(authKey, tagMask, data);
4082
+ if (!equalBytes(tag, passedTag))
4083
+ throw new Error("aes/gcm: invalid ghash tag");
4084
+ const out = ctr32(xk, false, counter, data);
4085
+ authKey.fill(0);
4086
+ tagMask.fill(0);
4087
+ xk.fill(0);
4088
+ return out;
4089
+ }
3838
4090
  };
3839
- return mockNotification;
3840
- }
3841
- function createMockNotificationERC721Received() {
3842
- const mockNotification = {
3843
- type: "erc721_received" /* ERC721_RECEIVED */,
3844
- block_number: 18571446,
3845
- block_timestamp: "1699980623",
3846
- chain_id: 1,
3847
- created_at: "2023-11-14T17:40:52.319281Z",
3848
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3849
- data: {
3850
- to: "0xba7f3daa8adfdad686574406ab9bd5d2f0a49d2e",
3851
- nft: {
3852
- name: "The Plague #2722",
3853
- image: "https://i.seadn.io/s/raw/files/a96f90ec8ebf55a2300c66a0c46d6a16.png?w=500&auto=format",
3854
- token_id: "2722",
3855
- collection: {
3856
- name: "The Plague NFT",
3857
- image: "https://i.seadn.io/gcs/files/4577987a5ca45ca5118b2e31559ee4d1.jpg?w=500&auto=format",
3858
- symbol: "FROG",
3859
- address: "0xc379e535caff250a01caa6c3724ed1359fe5c29b"
3860
- }
3861
- },
3862
- from: "0x24a0bb54b7e7a8e406e9b28058a9fd6c49e6df4f",
3863
- kind: "erc721_received",
3864
- network_fee: {
3865
- gas_price: "53701898538",
3866
- native_token_price_in_usd: "2047.01"
4091
+ });
4092
+ var limit = (name, min, max) => (value) => {
4093
+ if (!Number.isSafeInteger(value) || min > value || value > max)
4094
+ throw new Error(`${name}: invalid value=${value}, must be [${min}..${max}]`);
4095
+ };
4096
+ var siv = wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16 }, function siv2(key, nonce, AAD) {
4097
+ const tagLength = 16;
4098
+ const AAD_LIMIT = limit("AAD", 0, 2 ** 36);
4099
+ const PLAIN_LIMIT = limit("plaintext", 0, 2 ** 36);
4100
+ const NONCE_LIMIT = limit("nonce", 12, 12);
4101
+ const CIPHER_LIMIT = limit("ciphertext", 16, 2 ** 36 + 16);
4102
+ bytes(nonce);
4103
+ NONCE_LIMIT(nonce.length);
4104
+ if (AAD) {
4105
+ bytes(AAD);
4106
+ AAD_LIMIT(AAD.length);
4107
+ }
4108
+ function deriveKeys() {
4109
+ const len = key.length;
4110
+ if (len !== 16 && len !== 24 && len !== 32)
4111
+ throw new Error(`key length must be 16, 24 or 32 bytes, got: ${len} bytes`);
4112
+ const xk = expandKeyLE(key);
4113
+ const encKey = new Uint8Array(len);
4114
+ const authKey = new Uint8Array(16);
4115
+ const n32 = u32(nonce);
4116
+ let s0 = 0, s1 = n32[0], s2 = n32[1], s3 = n32[2];
4117
+ let counter = 0;
4118
+ for (const derivedKey of [authKey, encKey].map(u32)) {
4119
+ const d32 = u32(derivedKey);
4120
+ for (let i = 0; i < d32.length; i += 2) {
4121
+ const { s0: o0, s1: o1 } = encrypt(xk, s0, s1, s2, s3);
4122
+ d32[i + 0] = o0;
4123
+ d32[i + 1] = o1;
4124
+ s0 = ++counter;
3867
4125
  }
4126
+ }
4127
+ xk.fill(0);
4128
+ return { authKey, encKey: expandKeyLE(encKey) };
4129
+ }
4130
+ function _computeTag(encKey, authKey, data) {
4131
+ const tag = computeTag(polyval, true, authKey, data, AAD);
4132
+ for (let i = 0; i < 12; i++)
4133
+ tag[i] ^= nonce[i];
4134
+ tag[15] &= 127;
4135
+ const t32 = u32(tag);
4136
+ let s0 = t32[0], s1 = t32[1], s2 = t32[2], s3 = t32[3];
4137
+ ({ s0, s1, s2, s3 } = encrypt(encKey, s0, s1, s2, s3));
4138
+ t32[0] = s0, t32[1] = s1, t32[2] = s2, t32[3] = s3;
4139
+ return tag;
4140
+ }
4141
+ function processSiv(encKey, tag, input) {
4142
+ let block = tag.slice();
4143
+ block[15] |= 128;
4144
+ return ctr32(encKey, true, block, input);
4145
+ }
4146
+ return {
4147
+ encrypt: (plaintext) => {
4148
+ bytes(plaintext);
4149
+ PLAIN_LIMIT(plaintext.length);
4150
+ const { encKey, authKey } = deriveKeys();
4151
+ const tag = _computeTag(encKey, authKey, plaintext);
4152
+ const out = new Uint8Array(plaintext.length + tagLength);
4153
+ out.set(tag, plaintext.length);
4154
+ out.set(processSiv(encKey, tag, plaintext));
4155
+ encKey.fill(0);
4156
+ authKey.fill(0);
4157
+ return out;
3868
4158
  },
3869
- id: "00a79d24-befa-57ed-a55a-9eb8696e1654",
3870
- trigger_id: "d24ac26a-8579-49ec-9947-d04d63592ebd",
3871
- tx_hash: "0xe554c9e29e6eeca8ba94da4d047334ba08b8eb9ca3b801dd69cec08dfdd4ae43",
3872
- unread: true
4159
+ decrypt: (ciphertext) => {
4160
+ bytes(ciphertext);
4161
+ CIPHER_LIMIT(ciphertext.length);
4162
+ const tag = ciphertext.subarray(-tagLength);
4163
+ const { encKey, authKey } = deriveKeys();
4164
+ const plaintext = processSiv(encKey, tag, ciphertext.subarray(0, -tagLength));
4165
+ const expectedTag = _computeTag(encKey, authKey, plaintext);
4166
+ encKey.fill(0);
4167
+ authKey.fill(0);
4168
+ if (!equalBytes(tag, expectedTag))
4169
+ throw new Error("invalid polyval tag");
4170
+ return plaintext;
4171
+ }
3873
4172
  };
3874
- return mockNotification;
4173
+ });
4174
+
4175
+ // ../../node_modules/@noble/ciphers/esm/crypto.js
4176
+ var cr = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
4177
+ function randomBytes(bytesLength = 32) {
4178
+ if (cr && typeof cr.getRandomValues === "function")
4179
+ return cr.getRandomValues(new Uint8Array(bytesLength));
4180
+ throw new Error("crypto.getRandomValues must be defined");
3875
4181
  }
3876
- function createMockNotificationERC1155Sent() {
3877
- const mockNotification = {
3878
- type: "erc1155_sent" /* ERC1155_SENT */,
3879
- block_number: 18615206,
3880
- block_timestamp: "1700510003",
3881
- chain_id: 1,
3882
- created_at: "2023-11-20T20:44:10.110706Z",
3883
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3884
- data: {
3885
- to: "0x15bd77ccacf2da39b84f0c31fee2e451225bb190",
3886
- nft: {
3887
- name: "IlluminatiNFT DAO",
3888
- image: "https://i.seadn.io/gcs/files/79a77cb37c7b2f1069f752645d29fea7.jpg?w=500&auto=format",
3889
- token_id: "1",
3890
- collection: {
3891
- name: "IlluminatiNFT DAO",
3892
- image: "https://i.seadn.io/gae/LTKz3om2eCQfn3M6PkqEmY7KhLtdMCOm0QVch2318KJq7-KyToCH7NBTMo4UuJ0AZI-oaBh1HcgrAEIEWYbXY3uMcYpuGXunaXEh?w=500&auto=format",
3893
- symbol: "TRUTH",
3894
- address: "0xe25f0fe686477f9df3c2876c4902d3b85f75f33a"
3895
- }
3896
- },
3897
- from: "0x0000000000000000000000000000000000000000",
3898
- kind: "erc1155_sent",
3899
- network_fee: {
3900
- gas_price: "33571446596",
3901
- native_token_price_in_usd: "2038.88"
3902
- }
3903
- },
3904
- id: "a09ff9d1-623a-52ab-a3d4-c7c8c9a58362",
3905
- trigger_id: "e2130f7d-78b8-4c34-999a-3f3d3bb5b03c",
3906
- tx_hash: "0x03381aba290facbaf71c123e263c8dc3dd550aac00ef589cce395182eaeff76f",
3907
- unread: true
3908
- };
3909
- return mockNotification;
4182
+ function getWebcryptoSubtle() {
4183
+ if (cr && typeof cr.subtle === "object" && cr.subtle != null)
4184
+ return cr.subtle;
4185
+ throw new Error("crypto.subtle must be defined");
3910
4186
  }
3911
- function createMockNotificationERC1155Received() {
3912
- const mockNotification = {
3913
- type: "erc1155_received" /* ERC1155_RECEIVED */,
3914
- block_number: 18615206,
3915
- block_timestamp: "1700510003",
3916
- chain_id: 1,
3917
- created_at: "2023-11-20T20:44:10.110706Z",
3918
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3919
- data: {
3920
- to: "0x15bd77ccacf2da39b84f0c31fee2e451225bb190",
3921
- nft: {
3922
- name: "IlluminatiNFT DAO",
3923
- image: "https://i.seadn.io/gcs/files/79a77cb37c7b2f1069f752645d29fea7.jpg?w=500&auto=format",
3924
- token_id: "1",
3925
- collection: {
3926
- name: "IlluminatiNFT DAO",
3927
- image: "https://i.seadn.io/gae/LTKz3om2eCQfn3M6PkqEmY7KhLtdMCOm0QVch2318KJq7-KyToCH7NBTMo4UuJ0AZI-oaBh1HcgrAEIEWYbXY3uMcYpuGXunaXEh?w=500&auto=format",
3928
- symbol: "TRUTH",
3929
- address: "0xe25f0fe686477f9df3c2876c4902d3b85f75f33a"
3930
- }
3931
- },
3932
- from: "0x0000000000000000000000000000000000000000",
3933
- kind: "erc1155_received",
3934
- network_fee: {
3935
- gas_price: "33571446596",
3936
- native_token_price_in_usd: "2038.88"
3937
- }
3938
- },
3939
- id: "b6b93c84-e8dc-54ed-9396-7ea50474843a",
3940
- trigger_id: "710c8abb-43a9-42a5-9d86-9dd258726c82",
3941
- tx_hash: "0x03381aba290facbaf71c123e263c8dc3dd550aac00ef589cce395182eaeff76f",
3942
- unread: true
3943
- };
3944
- return mockNotification;
4187
+
4188
+ // ../../node_modules/@noble/ciphers/esm/webcrypto.js
4189
+ var utils = {
4190
+ async encrypt(key, keyParams, cryptParams, plaintext) {
4191
+ const cr2 = getWebcryptoSubtle();
4192
+ const iKey = await cr2.importKey("raw", key, keyParams, true, ["encrypt"]);
4193
+ const ciphertext = await cr2.encrypt(cryptParams, iKey, plaintext);
4194
+ return new Uint8Array(ciphertext);
4195
+ },
4196
+ async decrypt(key, keyParams, cryptParams, ciphertext) {
4197
+ const cr2 = getWebcryptoSubtle();
4198
+ const iKey = await cr2.importKey("raw", key, keyParams, true, ["decrypt"]);
4199
+ const plaintext = await cr2.decrypt(cryptParams, iKey, ciphertext);
4200
+ return new Uint8Array(plaintext);
4201
+ }
4202
+ };
4203
+ var mode = {
4204
+ CBC: "AES-CBC",
4205
+ CTR: "AES-CTR",
4206
+ GCM: "AES-GCM"
4207
+ };
4208
+ function getCryptParams(algo, nonce, AAD) {
4209
+ if (algo === mode.CBC)
4210
+ return { name: mode.CBC, iv: nonce };
4211
+ if (algo === mode.CTR)
4212
+ return { name: mode.CTR, counter: nonce, length: 64 };
4213
+ if (algo === mode.GCM)
4214
+ return { name: mode.GCM, iv: nonce, additionalData: AAD };
4215
+ throw new Error("unknown aes block mode");
3945
4216
  }
3946
- function createMockNotificationMetaMaskSwapsCompleted() {
3947
- const mockNotification = {
3948
- type: "metamask_swap_completed" /* METAMASK_SWAP_COMPLETED */,
3949
- block_number: 18377666,
3950
- block_timestamp: "1697637275",
3951
- chain_id: 1,
3952
- created_at: "2023-10-18T13:58:49.854596Z",
3953
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3954
- data: {
3955
- kind: "metamask_swap_completed",
3956
- rate: "1558.27",
3957
- token_in: {
3958
- usd: "1576.73",
3959
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
3960
- amount: "9000000000000000",
3961
- symbol: "ETH",
3962
- address: "0x0000000000000000000000000000000000000000",
3963
- decimals: "18",
3964
- name: "Ethereum"
4217
+ function generate(algo) {
4218
+ return (key, nonce, AAD) => {
4219
+ bytes(key);
4220
+ bytes(nonce);
4221
+ const keyParams = { name: algo, length: key.length * 8 };
4222
+ const cryptParams = getCryptParams(algo, nonce, AAD);
4223
+ return {
4224
+ // keyLength,
4225
+ encrypt(plaintext) {
4226
+ bytes(plaintext);
4227
+ return utils.encrypt(key, keyParams, cryptParams, plaintext);
3965
4228
  },
3966
- token_out: {
3967
- usd: "1.00",
3968
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/usdt.svg",
3969
- amount: "14024419",
3970
- symbol: "USDT",
3971
- address: "0xdac17f958d2ee523a2206206994597c13d831ec7",
3972
- decimals: "6",
3973
- name: "USDT"
3974
- },
3975
- network_fee: {
3976
- gas_price: "15406129273",
3977
- native_token_price_in_usd: "1576.73"
4229
+ decrypt(ciphertext) {
4230
+ bytes(ciphertext);
4231
+ return utils.decrypt(key, keyParams, cryptParams, ciphertext);
3978
4232
  }
3979
- },
3980
- id: "7ddfe6a1-ac52-5ffe-aa40-f04242db4b8b",
3981
- trigger_id: "d2eaa2eb-2e6e-4fd5-8763-b70ea571b46c",
3982
- tx_hash: "0xf69074290f3aa11bce567aabc9ca0df7a12559dfae1b80ba1a124e9dfe19ecc5",
3983
- unread: true
4233
+ };
3984
4234
  };
3985
- return mockNotification;
3986
4235
  }
3987
- function createMockNotificationRocketPoolStakeCompleted() {
3988
- const mockNotification = {
3989
- type: "rocketpool_stake_completed" /* ROCKETPOOL_STAKE_COMPLETED */,
3990
- block_number: 18585057,
3991
- block_timestamp: "1700145059",
3992
- chain_id: 1,
3993
- created_at: "2023-11-20T12:02:48.796824Z",
3994
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
3995
- data: {
3996
- kind: "rocketpool_stake_completed",
3997
- stake_in: {
3998
- usd: "2031.86",
3999
- name: "Ethereum",
4000
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4001
- amount: "190690478063438272",
4002
- symbol: "ETH",
4003
- address: "0x0000000000000000000000000000000000000000",
4004
- decimals: "18"
4005
- },
4006
- stake_out: {
4007
- usd: "2226.49",
4008
- name: "Rocket Pool ETH",
4009
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/rETH.svg",
4010
- amount: "175024360778165879",
4011
- symbol: "RETH",
4012
- address: "0xae78736Cd615f374D3085123A210448E74Fc6393",
4013
- decimals: "18"
4014
- },
4015
- network_fee: {
4016
- gas_price: "36000000000",
4017
- native_token_price_in_usd: "2031.86"
4018
- }
4019
- },
4020
- id: "c2a2f225-b2fb-5d6c-ba56-e27a5c71ffb9",
4021
- trigger_id: "5110ff97-acff-40c0-83b4-11d487b8c7b0",
4022
- tx_hash: "0xcfc0693bf47995907b0f46ef0644cf16dd9a0de797099b2e00fd481e1b2117d3",
4023
- unread: true
4024
- };
4025
- return mockNotification;
4236
+ var cbc3 = generate(mode.CBC);
4237
+ var ctr3 = generate(mode.CTR);
4238
+ var gcm3 = generate(mode.GCM);
4239
+
4240
+ // ../../node_modules/@noble/hashes/esm/_assert.js
4241
+ function number2(n) {
4242
+ if (!Number.isSafeInteger(n) || n < 0)
4243
+ throw new Error(`positive integer expected, not ${n}`);
4026
4244
  }
4027
- function createMockNotificationRocketPoolUnStakeCompleted() {
4028
- const mockNotification = {
4029
- type: "rocketpool_unstake_completed" /* ROCKETPOOL_UNSTAKE_COMPLETED */,
4030
- block_number: 18384336,
4031
- block_timestamp: "1697718011",
4032
- chain_id: 1,
4033
- created_at: "2023-10-19T13:11:10.623042Z",
4034
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
4035
- data: {
4036
- kind: "rocketpool_unstake_completed",
4037
- stake_in: {
4038
- usd: "1686.34",
4039
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/rETH.svg",
4040
- amount: "66608041413696770",
4041
- symbol: "RETH",
4042
- address: "0xae78736Cd615f374D3085123A210448E74Fc6393",
4043
- decimals: "18",
4044
- name: "Rocketpool Eth"
4045
- },
4046
- stake_out: {
4047
- usd: "1553.75",
4048
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4049
- amount: "72387843427700824",
4050
- symbol: "ETH",
4051
- address: "0x0000000000000000000000000000000000000000",
4052
- decimals: "18",
4053
- name: "Ethereum"
4054
- },
4055
- network_fee: {
4056
- gas_price: "5656322987",
4057
- native_token_price_in_usd: "1553.75"
4058
- }
4059
- },
4060
- id: "d8c246e7-a0a4-5f1d-b079-2b1707665fbc",
4061
- trigger_id: "291ec897-f569-4837-b6c0-21001b198dff",
4062
- tx_hash: "0xc7972a7e409abfc62590ec90e633acd70b9b74e76ad02305be8bf133a0e22d5f",
4063
- unread: true
4064
- };
4065
- return mockNotification;
4245
+ function isBytes2(a) {
4246
+ return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
4066
4247
  }
4067
- function createMockNotificationLidoStakeCompleted() {
4068
- const mockNotification = {
4069
- type: "lido_stake_completed" /* LIDO_STAKE_COMPLETED */,
4070
- block_number: 18487118,
4071
- block_timestamp: "1698961091",
4072
- chain_id: 1,
4073
- created_at: "2023-11-02T22:28:49.970865Z",
4074
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
4075
- data: {
4076
- kind: "lido_stake_completed",
4077
- stake_in: {
4078
- usd: "1806.33",
4079
- name: "Ethereum",
4080
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4081
- amount: "330303634023928032",
4082
- symbol: "ETH",
4083
- address: "0x0000000000000000000000000000000000000000",
4084
- decimals: "18"
4085
- },
4086
- stake_out: {
4087
- usd: "1801.30",
4088
- name: "Liquid staked Ether 2.0",
4089
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/stETH.svg",
4090
- amount: "330303634023928032",
4091
- symbol: "STETH",
4092
- address: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
4093
- decimals: "18"
4094
- },
4095
- network_fee: {
4096
- gas_price: "26536359866",
4097
- native_token_price_in_usd: "1806.33"
4098
- }
4099
- },
4100
- id: "9d9b1467-b3ee-5492-8ca2-22382657b690",
4101
- trigger_id: "ec10d66a-f78f-461f-83c9-609aada8cc50",
4102
- tx_hash: "0x8cc0fa805f7c3b1743b14f3b91c6b824113b094f26d4ccaf6a71ad8547ce6a0f",
4103
- unread: true
4104
- };
4105
- return mockNotification;
4248
+ function bytes2(b, ...lengths) {
4249
+ if (!isBytes2(b))
4250
+ throw new Error("Uint8Array expected");
4251
+ if (lengths.length > 0 && !lengths.includes(b.length))
4252
+ throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
4106
4253
  }
4107
- function createMockNotificationLidoWithdrawalRequested() {
4108
- const mockNotification = {
4109
- type: "lido_withdrawal_requested" /* LIDO_WITHDRAWAL_REQUESTED */,
4110
- block_number: 18377760,
4111
- block_timestamp: "1697638415",
4112
- chain_id: 1,
4113
- created_at: "2023-10-18T15:04:02.482526Z",
4114
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
4115
- data: {
4116
- kind: "lido_withdrawal_requested",
4117
- stake_in: {
4118
- usd: "1568.54",
4119
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/stETH.svg",
4120
- amount: "97180668792218669859",
4121
- symbol: "STETH",
4122
- address: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
4123
- decimals: "18",
4124
- name: "Staked Eth"
4125
- },
4126
- stake_out: {
4127
- usd: "1576.73",
4128
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4129
- amount: "97180668792218669859",
4130
- symbol: "ETH",
4131
- address: "0x0000000000000000000000000000000000000000",
4132
- decimals: "18",
4133
- name: "Ethereum"
4134
- },
4135
- network_fee: {
4136
- gas_price: "11658906980",
4137
- native_token_price_in_usd: "1576.73"
4138
- }
4139
- },
4140
- id: "29ddc718-78c6-5f91-936f-2bef13a605f0",
4141
- trigger_id: "ef003925-3379-4ba7-9e2d-8218690cadc8",
4142
- tx_hash: "0x58b5f82e084cb750ea174e02b20fbdfd2ba8d78053deac787f34fc38e5d427aa",
4143
- unread: true
4144
- };
4145
- return mockNotification;
4254
+ function hash(h) {
4255
+ if (typeof h !== "function" || typeof h.create !== "function")
4256
+ throw new Error("Hash should be wrapped by utils.wrapConstructor");
4257
+ number2(h.outputLen);
4258
+ number2(h.blockLen);
4146
4259
  }
4147
- function createMockNotificationLidoWithdrawalCompleted() {
4148
- const mockNotification = {
4149
- type: "lido_withdrawal_completed" /* LIDO_WITHDRAWAL_COMPLETED */,
4150
- block_number: 18378208,
4151
- block_timestamp: "1697643851",
4152
- chain_id: 1,
4153
- created_at: "2023-10-18T16:35:03.147606Z",
4154
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
4155
- data: {
4156
- kind: "lido_withdrawal_completed",
4157
- stake_in: {
4158
- usd: "1570.23",
4159
- image: "https://raw.githubusercontent.com/MetaMask/contract-metadata/master/images/stETH.svg",
4160
- amount: "35081997661451346",
4161
- symbol: "STETH",
4162
- address: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
4163
- decimals: "18",
4164
- name: "Staked Eth"
4165
- },
4166
- stake_out: {
4167
- usd: "1571.74",
4168
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4169
- amount: "35081997661451346",
4170
- symbol: "ETH",
4171
- address: "0x0000000000000000000000000000000000000000",
4172
- decimals: "18",
4173
- name: "Ethereum"
4174
- },
4175
- network_fee: {
4176
- gas_price: "12699495150",
4177
- native_token_price_in_usd: "1571.74"
4178
- }
4179
- },
4180
- id: "f4ef0b7f-5612-537f-9144-0b5c63ae5391",
4181
- trigger_id: "d73df14d-ce73-4f38-bad3-ab028154042c",
4182
- tx_hash: "0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657",
4183
- unread: true
4184
- };
4185
- return mockNotification;
4260
+ function exists2(instance, checkFinished = true) {
4261
+ if (instance.destroyed)
4262
+ throw new Error("Hash instance has been destroyed");
4263
+ if (checkFinished && instance.finished)
4264
+ throw new Error("Hash#digest() has already been called");
4265
+ }
4266
+ function output2(out, instance) {
4267
+ bytes2(out);
4268
+ const min = instance.outputLen;
4269
+ if (out.length < min) {
4270
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
4271
+ }
4272
+ }
4273
+
4274
+ // ../../node_modules/@noble/hashes/esm/utils.js
4275
+ var u322 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
4276
+ var createView2 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
4277
+ var rotr = (word, shift) => word << 32 - shift | word >>> shift;
4278
+ var rotl = (word, shift) => word << shift | word >>> 32 - shift >>> 0;
4279
+ var isLE2 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
4280
+ var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
4281
+ function byteSwap32(arr) {
4282
+ for (let i = 0; i < arr.length; i++) {
4283
+ arr[i] = byteSwap(arr[i]);
4284
+ }
4285
+ }
4286
+ var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
4287
+ function bytesToHex(bytes3) {
4288
+ bytes2(bytes3);
4289
+ let hex = "";
4290
+ for (let i = 0; i < bytes3.length; i++) {
4291
+ hex += hexes[bytes3[i]];
4292
+ }
4293
+ return hex;
4294
+ }
4295
+ function utf8ToBytes2(str) {
4296
+ if (typeof str !== "string")
4297
+ throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
4298
+ return new Uint8Array(new TextEncoder().encode(str));
4299
+ }
4300
+ function toBytes2(data) {
4301
+ if (typeof data === "string")
4302
+ data = utf8ToBytes2(data);
4303
+ bytes2(data);
4304
+ return data;
4305
+ }
4306
+ function concatBytes(...arrays) {
4307
+ let sum = 0;
4308
+ for (let i = 0; i < arrays.length; i++) {
4309
+ const a = arrays[i];
4310
+ bytes2(a);
4311
+ sum += a.length;
4312
+ }
4313
+ const res = new Uint8Array(sum);
4314
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
4315
+ const a = arrays[i];
4316
+ res.set(a, pad);
4317
+ pad += a.length;
4318
+ }
4319
+ return res;
4320
+ }
4321
+ var Hash = class {
4322
+ // Safe version that clones internal state
4323
+ clone() {
4324
+ return this._cloneInto();
4325
+ }
4326
+ };
4327
+ var toStr = {}.toString;
4328
+ function checkOpts(defaults, opts) {
4329
+ if (opts !== void 0 && toStr.call(opts) !== "[object Object]")
4330
+ throw new Error("Options should be object or undefined");
4331
+ const merged = Object.assign(defaults, opts);
4332
+ return merged;
4333
+ }
4334
+ function wrapConstructor(hashCons) {
4335
+ const hashC = (msg) => hashCons().update(toBytes2(msg)).digest();
4336
+ const tmp = hashCons();
4337
+ hashC.outputLen = tmp.outputLen;
4338
+ hashC.blockLen = tmp.blockLen;
4339
+ hashC.create = () => hashCons();
4340
+ return hashC;
4341
+ }
4342
+
4343
+ // ../../node_modules/@noble/hashes/esm/hmac.js
4344
+ var HMAC = class extends Hash {
4345
+ constructor(hash2, _key) {
4346
+ super();
4347
+ this.finished = false;
4348
+ this.destroyed = false;
4349
+ hash(hash2);
4350
+ const key = toBytes2(_key);
4351
+ this.iHash = hash2.create();
4352
+ if (typeof this.iHash.update !== "function")
4353
+ throw new Error("Expected instance of class which extends utils.Hash");
4354
+ this.blockLen = this.iHash.blockLen;
4355
+ this.outputLen = this.iHash.outputLen;
4356
+ const blockLen = this.blockLen;
4357
+ const pad = new Uint8Array(blockLen);
4358
+ pad.set(key.length > blockLen ? hash2.create().update(key).digest() : key);
4359
+ for (let i = 0; i < pad.length; i++)
4360
+ pad[i] ^= 54;
4361
+ this.iHash.update(pad);
4362
+ this.oHash = hash2.create();
4363
+ for (let i = 0; i < pad.length; i++)
4364
+ pad[i] ^= 54 ^ 92;
4365
+ this.oHash.update(pad);
4366
+ pad.fill(0);
4367
+ }
4368
+ update(buf) {
4369
+ exists2(this);
4370
+ this.iHash.update(buf);
4371
+ return this;
4372
+ }
4373
+ digestInto(out) {
4374
+ exists2(this);
4375
+ bytes2(out, this.outputLen);
4376
+ this.finished = true;
4377
+ this.iHash.digestInto(out);
4378
+ this.oHash.update(out);
4379
+ this.oHash.digestInto(out);
4380
+ this.destroy();
4381
+ }
4382
+ digest() {
4383
+ const out = new Uint8Array(this.oHash.outputLen);
4384
+ this.digestInto(out);
4385
+ return out;
4386
+ }
4387
+ _cloneInto(to) {
4388
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
4389
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
4390
+ to = to;
4391
+ to.finished = finished;
4392
+ to.destroyed = destroyed;
4393
+ to.blockLen = blockLen;
4394
+ to.outputLen = outputLen;
4395
+ to.oHash = oHash._cloneInto(to.oHash);
4396
+ to.iHash = iHash._cloneInto(to.iHash);
4397
+ return to;
4398
+ }
4399
+ destroy() {
4400
+ this.destroyed = true;
4401
+ this.oHash.destroy();
4402
+ this.iHash.destroy();
4403
+ }
4404
+ };
4405
+ var hmac = (hash2, key, message) => new HMAC(hash2, key).update(message).digest();
4406
+ hmac.create = (hash2, key) => new HMAC(hash2, key);
4407
+
4408
+ // ../../node_modules/@noble/hashes/esm/pbkdf2.js
4409
+ function pbkdf2Init(hash2, _password, _salt, _opts) {
4410
+ hash(hash2);
4411
+ const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
4412
+ const { c, dkLen, asyncTick } = opts;
4413
+ number2(c);
4414
+ number2(dkLen);
4415
+ number2(asyncTick);
4416
+ if (c < 1)
4417
+ throw new Error("PBKDF2: iterations (c) should be >= 1");
4418
+ const password = toBytes2(_password);
4419
+ const salt = toBytes2(_salt);
4420
+ const DK = new Uint8Array(dkLen);
4421
+ const PRF = hmac.create(hash2, password);
4422
+ const PRFSalt = PRF._cloneInto().update(salt);
4423
+ return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
4424
+ }
4425
+ function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
4426
+ PRF.destroy();
4427
+ PRFSalt.destroy();
4428
+ if (prfW)
4429
+ prfW.destroy();
4430
+ u.fill(0);
4431
+ return DK;
4432
+ }
4433
+ function pbkdf2(hash2, password, salt, opts) {
4434
+ const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash2, password, salt, opts);
4435
+ let prfW;
4436
+ const arr = new Uint8Array(4);
4437
+ const view = createView2(arr);
4438
+ const u = new Uint8Array(PRF.outputLen);
4439
+ for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
4440
+ const Ti = DK.subarray(pos, pos + PRF.outputLen);
4441
+ view.setInt32(0, ti, false);
4442
+ (prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
4443
+ Ti.set(u.subarray(0, Ti.length));
4444
+ for (let ui = 1; ui < c; ui++) {
4445
+ PRF._cloneInto(prfW).update(u).digestInto(u);
4446
+ for (let i = 0; i < Ti.length; i++)
4447
+ Ti[i] ^= u[i];
4448
+ }
4449
+ }
4450
+ return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
4186
4451
  }
4187
- function createMockNotificationLidoReadyToBeWithdrawn() {
4188
- const mockNotification = {
4189
- type: "lido_stake_ready_to_be_withdrawn" /* LIDO_STAKE_READY_TO_BE_WITHDRAWN */,
4190
- block_number: 18378208,
4191
- block_timestamp: "1697643851",
4192
- chain_id: 1,
4193
- created_at: "2023-10-18T16:35:03.147606Z",
4194
- address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
4195
- data: {
4196
- kind: "lido_stake_ready_to_be_withdrawn",
4197
- request_id: "123456789",
4198
- staked_eth: {
4199
- address: "0x881D40237659C251811CEC9c364ef91dC08D300F",
4200
- symbol: "ETH",
4201
- name: "Ethereum",
4202
- amount: "2.5",
4203
- decimals: "18",
4204
- image: "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
4205
- usd: "10000.00"
4452
+
4453
+ // ../../node_modules/@noble/hashes/esm/_md.js
4454
+ function setBigUint642(view, byteOffset, value, isLE3) {
4455
+ if (typeof view.setBigUint64 === "function")
4456
+ return view.setBigUint64(byteOffset, value, isLE3);
4457
+ const _32n = BigInt(32);
4458
+ const _u32_max = BigInt(4294967295);
4459
+ const wh = Number(value >> _32n & _u32_max);
4460
+ const wl = Number(value & _u32_max);
4461
+ const h = isLE3 ? 4 : 0;
4462
+ const l = isLE3 ? 0 : 4;
4463
+ view.setUint32(byteOffset + h, wh, isLE3);
4464
+ view.setUint32(byteOffset + l, wl, isLE3);
4465
+ }
4466
+ var Chi = (a, b, c) => a & b ^ ~a & c;
4467
+ var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
4468
+ var HashMD = class extends Hash {
4469
+ constructor(blockLen, outputLen, padOffset, isLE3) {
4470
+ super();
4471
+ this.blockLen = blockLen;
4472
+ this.outputLen = outputLen;
4473
+ this.padOffset = padOffset;
4474
+ this.isLE = isLE3;
4475
+ this.finished = false;
4476
+ this.length = 0;
4477
+ this.pos = 0;
4478
+ this.destroyed = false;
4479
+ this.buffer = new Uint8Array(blockLen);
4480
+ this.view = createView2(this.buffer);
4481
+ }
4482
+ update(data) {
4483
+ exists2(this);
4484
+ const { view, buffer, blockLen } = this;
4485
+ data = toBytes2(data);
4486
+ const len = data.length;
4487
+ for (let pos = 0; pos < len; ) {
4488
+ const take = Math.min(blockLen - this.pos, len - pos);
4489
+ if (take === blockLen) {
4490
+ const dataView = createView2(data);
4491
+ for (; blockLen <= len - pos; pos += blockLen)
4492
+ this.process(dataView, pos);
4493
+ continue;
4494
+ }
4495
+ buffer.set(data.subarray(pos, pos + take), this.pos);
4496
+ this.pos += take;
4497
+ pos += take;
4498
+ if (this.pos === blockLen) {
4499
+ this.process(view, 0);
4500
+ this.pos = 0;
4206
4501
  }
4207
- },
4208
- id: "f4ef0b7f-5612-537f-9144-0b5c63ae5391",
4209
- trigger_id: "d73df14d-ce73-4f38-bad3-ab028154042c",
4210
- tx_hash: "0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657",
4211
- unread: true
4502
+ }
4503
+ this.length += data.length;
4504
+ this.roundClean();
4505
+ return this;
4506
+ }
4507
+ digestInto(out) {
4508
+ exists2(this);
4509
+ output2(out, this);
4510
+ this.finished = true;
4511
+ const { buffer, view, blockLen, isLE: isLE3 } = this;
4512
+ let { pos } = this;
4513
+ buffer[pos++] = 128;
4514
+ this.buffer.subarray(pos).fill(0);
4515
+ if (this.padOffset > blockLen - pos) {
4516
+ this.process(view, 0);
4517
+ pos = 0;
4518
+ }
4519
+ for (let i = pos; i < blockLen; i++)
4520
+ buffer[i] = 0;
4521
+ setBigUint642(view, blockLen - 8, BigInt(this.length * 8), isLE3);
4522
+ this.process(view, 0);
4523
+ const oview = createView2(out);
4524
+ const len = this.outputLen;
4525
+ if (len % 4)
4526
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
4527
+ const outLen = len / 4;
4528
+ const state = this.get();
4529
+ if (outLen > state.length)
4530
+ throw new Error("_sha2: outputLen bigger than state");
4531
+ for (let i = 0; i < outLen; i++)
4532
+ oview.setUint32(4 * i, state[i], isLE3);
4533
+ }
4534
+ digest() {
4535
+ const { buffer, outputLen } = this;
4536
+ this.digestInto(buffer);
4537
+ const res = buffer.slice(0, outputLen);
4538
+ this.destroy();
4539
+ return res;
4540
+ }
4541
+ _cloneInto(to) {
4542
+ to || (to = new this.constructor());
4543
+ to.set(...this.get());
4544
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
4545
+ to.length = length;
4546
+ to.pos = pos;
4547
+ to.finished = finished;
4548
+ to.destroyed = destroyed;
4549
+ if (length % blockLen)
4550
+ to.buffer.set(buffer);
4551
+ return to;
4552
+ }
4553
+ };
4554
+
4555
+ // ../../node_modules/@noble/hashes/esm/sha256.js
4556
+ var SHA256_K = /* @__PURE__ */ new Uint32Array([
4557
+ 1116352408,
4558
+ 1899447441,
4559
+ 3049323471,
4560
+ 3921009573,
4561
+ 961987163,
4562
+ 1508970993,
4563
+ 2453635748,
4564
+ 2870763221,
4565
+ 3624381080,
4566
+ 310598401,
4567
+ 607225278,
4568
+ 1426881987,
4569
+ 1925078388,
4570
+ 2162078206,
4571
+ 2614888103,
4572
+ 3248222580,
4573
+ 3835390401,
4574
+ 4022224774,
4575
+ 264347078,
4576
+ 604807628,
4577
+ 770255983,
4578
+ 1249150122,
4579
+ 1555081692,
4580
+ 1996064986,
4581
+ 2554220882,
4582
+ 2821834349,
4583
+ 2952996808,
4584
+ 3210313671,
4585
+ 3336571891,
4586
+ 3584528711,
4587
+ 113926993,
4588
+ 338241895,
4589
+ 666307205,
4590
+ 773529912,
4591
+ 1294757372,
4592
+ 1396182291,
4593
+ 1695183700,
4594
+ 1986661051,
4595
+ 2177026350,
4596
+ 2456956037,
4597
+ 2730485921,
4598
+ 2820302411,
4599
+ 3259730800,
4600
+ 3345764771,
4601
+ 3516065817,
4602
+ 3600352804,
4603
+ 4094571909,
4604
+ 275423344,
4605
+ 430227734,
4606
+ 506948616,
4607
+ 659060556,
4608
+ 883997877,
4609
+ 958139571,
4610
+ 1322822218,
4611
+ 1537002063,
4612
+ 1747873779,
4613
+ 1955562222,
4614
+ 2024104815,
4615
+ 2227730452,
4616
+ 2361852424,
4617
+ 2428436474,
4618
+ 2756734187,
4619
+ 3204031479,
4620
+ 3329325298
4621
+ ]);
4622
+ var SHA256_IV = /* @__PURE__ */ new Uint32Array([
4623
+ 1779033703,
4624
+ 3144134277,
4625
+ 1013904242,
4626
+ 2773480762,
4627
+ 1359893119,
4628
+ 2600822924,
4629
+ 528734635,
4630
+ 1541459225
4631
+ ]);
4632
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
4633
+ var SHA256 = class extends HashMD {
4634
+ constructor() {
4635
+ super(64, 32, 8, false);
4636
+ this.A = SHA256_IV[0] | 0;
4637
+ this.B = SHA256_IV[1] | 0;
4638
+ this.C = SHA256_IV[2] | 0;
4639
+ this.D = SHA256_IV[3] | 0;
4640
+ this.E = SHA256_IV[4] | 0;
4641
+ this.F = SHA256_IV[5] | 0;
4642
+ this.G = SHA256_IV[6] | 0;
4643
+ this.H = SHA256_IV[7] | 0;
4644
+ }
4645
+ get() {
4646
+ const { A, B, C, D, E, F, G, H } = this;
4647
+ return [A, B, C, D, E, F, G, H];
4648
+ }
4649
+ // prettier-ignore
4650
+ set(A, B, C, D, E, F, G, H) {
4651
+ this.A = A | 0;
4652
+ this.B = B | 0;
4653
+ this.C = C | 0;
4654
+ this.D = D | 0;
4655
+ this.E = E | 0;
4656
+ this.F = F | 0;
4657
+ this.G = G | 0;
4658
+ this.H = H | 0;
4659
+ }
4660
+ process(view, offset) {
4661
+ for (let i = 0; i < 16; i++, offset += 4)
4662
+ SHA256_W[i] = view.getUint32(offset, false);
4663
+ for (let i = 16; i < 64; i++) {
4664
+ const W15 = SHA256_W[i - 15];
4665
+ const W2 = SHA256_W[i - 2];
4666
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
4667
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
4668
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
4669
+ }
4670
+ let { A, B, C, D, E, F, G, H } = this;
4671
+ for (let i = 0; i < 64; i++) {
4672
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
4673
+ const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
4674
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
4675
+ const T2 = sigma0 + Maj(A, B, C) | 0;
4676
+ H = G;
4677
+ G = F;
4678
+ F = E;
4679
+ E = D + T1 | 0;
4680
+ D = C;
4681
+ C = B;
4682
+ B = A;
4683
+ A = T1 + T2 | 0;
4684
+ }
4685
+ A = A + this.A | 0;
4686
+ B = B + this.B | 0;
4687
+ C = C + this.C | 0;
4688
+ D = D + this.D | 0;
4689
+ E = E + this.E | 0;
4690
+ F = F + this.F | 0;
4691
+ G = G + this.G | 0;
4692
+ H = H + this.H | 0;
4693
+ this.set(A, B, C, D, E, F, G, H);
4694
+ }
4695
+ roundClean() {
4696
+ SHA256_W.fill(0);
4697
+ }
4698
+ destroy() {
4699
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
4700
+ this.buffer.fill(0);
4701
+ }
4702
+ };
4703
+ var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
4704
+
4705
+ // ../profile-sync-controller/src/controllers/user-storage/index.ts
4706
+ var user_storage_exports = {};
4707
+ _chunkV46WVGWNjs.__export.call(void 0, user_storage_exports, {
4708
+ Mocks: () => fixtures_exports,
4709
+ createSHA256Hash: () => createSHA256Hash
4710
+ });
4711
+
4712
+ // ../../node_modules/@noble/hashes/esm/scrypt.js
4713
+ function XorAndSalsa(prev, pi, input, ii, out, oi) {
4714
+ let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++];
4715
+ let y02 = prev[pi++] ^ input[ii++], y03 = prev[pi++] ^ input[ii++];
4716
+ let y04 = prev[pi++] ^ input[ii++], y05 = prev[pi++] ^ input[ii++];
4717
+ let y06 = prev[pi++] ^ input[ii++], y07 = prev[pi++] ^ input[ii++];
4718
+ let y08 = prev[pi++] ^ input[ii++], y09 = prev[pi++] ^ input[ii++];
4719
+ let y10 = prev[pi++] ^ input[ii++], y11 = prev[pi++] ^ input[ii++];
4720
+ let y12 = prev[pi++] ^ input[ii++], y13 = prev[pi++] ^ input[ii++];
4721
+ let y14 = prev[pi++] ^ input[ii++], y15 = prev[pi++] ^ input[ii++];
4722
+ let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
4723
+ for (let i = 0; i < 8; i += 2) {
4724
+ x04 ^= rotl(x00 + x12 | 0, 7);
4725
+ x08 ^= rotl(x04 + x00 | 0, 9);
4726
+ x12 ^= rotl(x08 + x04 | 0, 13);
4727
+ x00 ^= rotl(x12 + x08 | 0, 18);
4728
+ x09 ^= rotl(x05 + x01 | 0, 7);
4729
+ x13 ^= rotl(x09 + x05 | 0, 9);
4730
+ x01 ^= rotl(x13 + x09 | 0, 13);
4731
+ x05 ^= rotl(x01 + x13 | 0, 18);
4732
+ x14 ^= rotl(x10 + x06 | 0, 7);
4733
+ x02 ^= rotl(x14 + x10 | 0, 9);
4734
+ x06 ^= rotl(x02 + x14 | 0, 13);
4735
+ x10 ^= rotl(x06 + x02 | 0, 18);
4736
+ x03 ^= rotl(x15 + x11 | 0, 7);
4737
+ x07 ^= rotl(x03 + x15 | 0, 9);
4738
+ x11 ^= rotl(x07 + x03 | 0, 13);
4739
+ x15 ^= rotl(x11 + x07 | 0, 18);
4740
+ x01 ^= rotl(x00 + x03 | 0, 7);
4741
+ x02 ^= rotl(x01 + x00 | 0, 9);
4742
+ x03 ^= rotl(x02 + x01 | 0, 13);
4743
+ x00 ^= rotl(x03 + x02 | 0, 18);
4744
+ x06 ^= rotl(x05 + x04 | 0, 7);
4745
+ x07 ^= rotl(x06 + x05 | 0, 9);
4746
+ x04 ^= rotl(x07 + x06 | 0, 13);
4747
+ x05 ^= rotl(x04 + x07 | 0, 18);
4748
+ x11 ^= rotl(x10 + x09 | 0, 7);
4749
+ x08 ^= rotl(x11 + x10 | 0, 9);
4750
+ x09 ^= rotl(x08 + x11 | 0, 13);
4751
+ x10 ^= rotl(x09 + x08 | 0, 18);
4752
+ x12 ^= rotl(x15 + x14 | 0, 7);
4753
+ x13 ^= rotl(x12 + x15 | 0, 9);
4754
+ x14 ^= rotl(x13 + x12 | 0, 13);
4755
+ x15 ^= rotl(x14 + x13 | 0, 18);
4756
+ }
4757
+ out[oi++] = y00 + x00 | 0;
4758
+ out[oi++] = y01 + x01 | 0;
4759
+ out[oi++] = y02 + x02 | 0;
4760
+ out[oi++] = y03 + x03 | 0;
4761
+ out[oi++] = y04 + x04 | 0;
4762
+ out[oi++] = y05 + x05 | 0;
4763
+ out[oi++] = y06 + x06 | 0;
4764
+ out[oi++] = y07 + x07 | 0;
4765
+ out[oi++] = y08 + x08 | 0;
4766
+ out[oi++] = y09 + x09 | 0;
4767
+ out[oi++] = y10 + x10 | 0;
4768
+ out[oi++] = y11 + x11 | 0;
4769
+ out[oi++] = y12 + x12 | 0;
4770
+ out[oi++] = y13 + x13 | 0;
4771
+ out[oi++] = y14 + x14 | 0;
4772
+ out[oi++] = y15 + x15 | 0;
4773
+ }
4774
+ function BlockMix(input, ii, out, oi, r) {
4775
+ let head = oi + 0;
4776
+ let tail = oi + 16 * r;
4777
+ for (let i = 0; i < 16; i++)
4778
+ out[tail + i] = input[ii + (2 * r - 1) * 16 + i];
4779
+ for (let i = 0; i < r; i++, head += 16, ii += 16) {
4780
+ XorAndSalsa(out, tail, input, ii, out, head);
4781
+ if (i > 0)
4782
+ tail += 16;
4783
+ XorAndSalsa(out, head, input, ii += 16, out, tail);
4784
+ }
4785
+ }
4786
+ function scryptInit(password, salt, _opts) {
4787
+ const opts = checkOpts({
4788
+ dkLen: 32,
4789
+ asyncTick: 10,
4790
+ maxmem: 1024 ** 3 + 1024
4791
+ }, _opts);
4792
+ const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts;
4793
+ number2(N);
4794
+ number2(r);
4795
+ number2(p);
4796
+ number2(dkLen);
4797
+ number2(asyncTick);
4798
+ number2(maxmem);
4799
+ if (onProgress !== void 0 && typeof onProgress !== "function")
4800
+ throw new Error("progressCb should be function");
4801
+ const blockSize = 128 * r;
4802
+ const blockSize32 = blockSize / 4;
4803
+ if (N <= 1 || (N & N - 1) !== 0 || N >= 2 ** (blockSize / 8) || N > 2 ** 32) {
4804
+ throw new Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");
4805
+ }
4806
+ if (p < 0 || p > (2 ** 32 - 1) * 32 / blockSize) {
4807
+ throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
4808
+ }
4809
+ if (dkLen < 0 || dkLen > (2 ** 32 - 1) * 32) {
4810
+ throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
4811
+ }
4812
+ const memUsed = blockSize * (N + p);
4813
+ if (memUsed > maxmem) {
4814
+ throw new Error(`Scrypt: parameters too large, ${memUsed} (128 * r * (N + p)) > ${maxmem} (maxmem)`);
4815
+ }
4816
+ const B = pbkdf2(sha256, password, salt, { c: 1, dkLen: blockSize * p });
4817
+ const B32 = u322(B);
4818
+ const V = u322(new Uint8Array(blockSize * N));
4819
+ const tmp = u322(new Uint8Array(blockSize));
4820
+ let blockMixCb = () => {
4212
4821
  };
4213
- return mockNotification;
4822
+ if (onProgress) {
4823
+ const totalBlockMix = 2 * N * p;
4824
+ const callbackPer = Math.max(Math.floor(totalBlockMix / 1e4), 1);
4825
+ let blockMixCnt = 0;
4826
+ blockMixCb = () => {
4827
+ blockMixCnt++;
4828
+ if (onProgress && (!(blockMixCnt % callbackPer) || blockMixCnt === totalBlockMix))
4829
+ onProgress(blockMixCnt / totalBlockMix);
4830
+ };
4831
+ }
4832
+ return { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick };
4214
4833
  }
4215
- function createMockRawOnChainNotifications() {
4216
- return [1, 2, 3].map((id) => {
4217
- const notification = createMockNotificationEthSent();
4218
- notification.id += `-${id}`;
4219
- return notification;
4220
- });
4834
+ function scryptOutput(password, dkLen, B, V, tmp) {
4835
+ const res = pbkdf2(sha256, password, B, { c: 1, dkLen });
4836
+ B.fill(0);
4837
+ V.fill(0);
4838
+ tmp.fill(0);
4839
+ return res;
4221
4840
  }
4841
+ function scrypt(password, salt, opts) {
4842
+ const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb } = scryptInit(password, salt, opts);
4843
+ if (!isLE2)
4844
+ byteSwap32(B32);
4845
+ for (let pi = 0; pi < p; pi++) {
4846
+ const Pi = blockSize32 * pi;
4847
+ for (let i = 0; i < blockSize32; i++)
4848
+ V[i] = B32[Pi + i];
4849
+ for (let i = 0, pos = 0; i < N - 1; i++) {
4850
+ BlockMix(V, pos, V, pos += blockSize32, r);
4851
+ blockMixCb();
4852
+ }
4853
+ BlockMix(V, (N - 1) * blockSize32, B32, Pi, r);
4854
+ blockMixCb();
4855
+ for (let i = 0; i < N; i++) {
4856
+ const j = B32[Pi + blockSize32 - 16] % N;
4857
+ for (let k = 0; k < blockSize32; k++)
4858
+ tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k];
4859
+ BlockMix(tmp, 0, B32, Pi, r);
4860
+ blockMixCb();
4861
+ }
4862
+ }
4863
+ if (!isLE2)
4864
+ byteSwap32(B32);
4865
+ return scryptOutput(password, dkLen, B, V, tmp);
4866
+ }
4867
+
4868
+ // ../profile-sync-controller/src/controllers/user-storage/encryption/utils.ts
4869
+ var byteArrayToBase64 = (byteArray) => {
4870
+ return Buffer.from(byteArray).toString("base64");
4871
+ };
4872
+ var base64ToByteArray = (base64) => {
4873
+ return new Uint8Array(Buffer.from(base64, "base64"));
4874
+ };
4875
+ var bytesToUtf8 = (byteArray) => {
4876
+ const decoder = new TextDecoder("utf-8");
4877
+ return decoder.decode(byteArray);
4878
+ };
4222
4879
 
4223
- // src/NotificationServicesController/__fixtures__/mockResponses.ts
4224
- var CONTENTFUL_RESPONSE = createMockFeatureAnnouncementAPIResult();
4225
- var getMockFeatureAnnouncementResponse = () => {
4880
+ // ../profile-sync-controller/src/controllers/user-storage/encryption/cache.ts
4881
+ var MAX_PASSWORD_CACHES = 3;
4882
+ var MAX_SALT_CACHES = 10;
4883
+ var inMemCachedKDF = {};
4884
+ var getPasswordCache = (hashedPassword) => {
4885
+ inMemCachedKDF[hashedPassword] ?? (inMemCachedKDF[hashedPassword] = /* @__PURE__ */ new Map());
4886
+ return inMemCachedKDF[hashedPassword];
4887
+ };
4888
+ function getCachedKeyBySalt(hashedPassword, salt) {
4889
+ const cache = getPasswordCache(hashedPassword);
4890
+ const base64Salt = byteArrayToBase64(salt);
4891
+ const cachedKey = cache.get(base64Salt);
4892
+ if (!cachedKey) {
4893
+ return void 0;
4894
+ }
4226
4895
  return {
4227
- url: _chunkZMNXLHACjs.FEATURE_ANNOUNCEMENT_API,
4228
- requestMethod: "GET",
4229
- response: CONTENTFUL_RESPONSE
4896
+ salt,
4897
+ base64Salt,
4898
+ key: cachedKey
4230
4899
  };
4231
- };
4232
- var getMockBatchCreateTriggersResponse = () => {
4900
+ }
4901
+ function getAnyCachedKey(hashedPassword) {
4902
+ const cache = getPasswordCache(hashedPassword);
4903
+ const cachedEntry = cache.entries().next().value;
4904
+ if (!cachedEntry) {
4905
+ return void 0;
4906
+ }
4907
+ const base64Salt = cachedEntry[0];
4908
+ const bytesSalt = base64ToByteArray(base64Salt);
4233
4909
  return {
4234
- url: _chunkVOZ7Y2OOjs.TRIGGER_API_BATCH_ENDPOINT,
4235
- requestMethod: "POST",
4236
- response: null
4910
+ salt: bytesSalt,
4911
+ base64Salt,
4912
+ key: cachedEntry[1]
4913
+ };
4914
+ }
4915
+ function setCachedKey(hashedPassword, salt, key) {
4916
+ if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {
4917
+ inMemCachedKDF = {};
4918
+ }
4919
+ const cache = getPasswordCache(hashedPassword);
4920
+ const base64Salt = byteArrayToBase64(salt);
4921
+ if (cache.size > MAX_SALT_CACHES) {
4922
+ cache.clear();
4923
+ }
4924
+ cache.set(base64Salt, key);
4925
+ }
4926
+
4927
+ // ../profile-sync-controller/src/controllers/user-storage/encryption/encryption.ts
4928
+ var ALGORITHM_NONCE_SIZE = 12;
4929
+ var ALGORITHM_KEY_SIZE = 16;
4930
+ var SCRYPT_SALT_SIZE = 16;
4931
+ var SCRYPT_N = 2 ** 17;
4932
+ var SCRYPT_r = 8;
4933
+ var SCRYPT_p = 1;
4934
+ var _encryptStringV1, encryptStringV1_fn, _decryptStringV1, decryptStringV1_fn, _encrypt, encrypt_fn, _decrypt, decrypt_fn, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn;
4935
+ var EncryptorDecryptor = class {
4936
+ constructor() {
4937
+ _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _encryptStringV1);
4938
+ _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _decryptStringV1);
4939
+ _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _encrypt);
4940
+ _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _decrypt);
4941
+ _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _getOrGenerateScryptKey);
4942
+ }
4943
+ encryptString(plaintext, password) {
4944
+ try {
4945
+ return _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _encryptStringV1, encryptStringV1_fn).call(this, plaintext, password);
4946
+ } catch (e) {
4947
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
4948
+ throw new Error(`Unable to encrypt string - ${errorMessage}`);
4949
+ }
4950
+ }
4951
+ decryptString(encryptedDataStr, password) {
4952
+ try {
4953
+ const encryptedData = JSON.parse(encryptedDataStr);
4954
+ if (encryptedData.v === "1") {
4955
+ if (encryptedData.t === "scrypt") {
4956
+ return _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _decryptStringV1, decryptStringV1_fn).call(this, encryptedData, password);
4957
+ }
4958
+ }
4959
+ throw new Error(
4960
+ `Unsupported encrypted data payload - ${encryptedDataStr}`
4961
+ );
4962
+ } catch (e) {
4963
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
4964
+ throw new Error(`Unable to decrypt string - ${errorMessage}`);
4965
+ }
4966
+ }
4967
+ };
4968
+ _encryptStringV1 = new WeakSet();
4969
+ encryptStringV1_fn = function(plaintext, password) {
4970
+ const { key, salt } = _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
4971
+ N: SCRYPT_N,
4972
+ r: SCRYPT_r,
4973
+ p: SCRYPT_p,
4974
+ dkLen: ALGORITHM_KEY_SIZE
4975
+ });
4976
+ const plaintextRaw = utf8ToBytes2(plaintext);
4977
+ const ciphertextAndNonceAndSalt = concatBytes(
4978
+ salt,
4979
+ _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _encrypt, encrypt_fn).call(this, plaintextRaw, key)
4980
+ );
4981
+ const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);
4982
+ const encryptedPayload = {
4983
+ v: "1",
4984
+ t: "scrypt",
4985
+ d: encryptedData,
4986
+ o: {
4987
+ N: SCRYPT_N,
4988
+ r: SCRYPT_r,
4989
+ p: SCRYPT_p,
4990
+ dkLen: ALGORITHM_KEY_SIZE
4991
+ },
4992
+ saltLen: SCRYPT_SALT_SIZE
4237
4993
  };
4994
+ return JSON.stringify(encryptedPayload);
4995
+ };
4996
+ _decryptStringV1 = new WeakSet();
4997
+ decryptStringV1_fn = function(data, password) {
4998
+ const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
4999
+ const ciphertextAndNonceAndSalt = base64ToByteArray(
5000
+ base64CiphertextAndNonceAndSalt
5001
+ );
5002
+ const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
5003
+ const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(
5004
+ saltLen,
5005
+ ciphertextAndNonceAndSalt.length
5006
+ );
5007
+ const { key } = _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
5008
+ N: o.N,
5009
+ r: o.r,
5010
+ p: o.p,
5011
+ dkLen: o.dkLen
5012
+ }, salt);
5013
+ return bytesToUtf8(_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _decrypt, decrypt_fn).call(this, ciphertextAndNonce, key));
5014
+ };
5015
+ _encrypt = new WeakSet();
5016
+ encrypt_fn = function(plaintext, key) {
5017
+ const nonce = randomBytes(ALGORITHM_NONCE_SIZE);
5018
+ const ciphertext = gcm(key, nonce).encrypt(plaintext);
5019
+ return concatBytes(nonce, ciphertext);
5020
+ };
5021
+ _decrypt = new WeakSet();
5022
+ decrypt_fn = function(ciphertextAndNonce, key) {
5023
+ const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
5024
+ const ciphertext = ciphertextAndNonce.slice(
5025
+ ALGORITHM_NONCE_SIZE,
5026
+ ciphertextAndNonce.length
5027
+ );
5028
+ return gcm(key, nonce).decrypt(ciphertext);
4238
5029
  };
4239
- var getMockBatchDeleteTriggersResponse = () => {
5030
+ _getOrGenerateScryptKey = new WeakSet();
5031
+ getOrGenerateScryptKey_fn = function(password, o, salt) {
5032
+ const hashedPassword = createSHA256Hash(password);
5033
+ const cachedKey = salt ? getCachedKeyBySalt(hashedPassword, salt) : getAnyCachedKey(hashedPassword);
5034
+ if (cachedKey) {
5035
+ return {
5036
+ key: cachedKey.key,
5037
+ salt: cachedKey.salt
5038
+ };
5039
+ }
5040
+ const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);
5041
+ const newKey = scrypt(password, newSalt, {
5042
+ N: o.N,
5043
+ r: o.r,
5044
+ p: o.p,
5045
+ dkLen: o.dkLen
5046
+ });
5047
+ setCachedKey(hashedPassword, newSalt, newKey);
4240
5048
  return {
4241
- url: _chunkVOZ7Y2OOjs.TRIGGER_API_BATCH_ENDPOINT,
4242
- requestMethod: "DELETE",
4243
- response: null
5049
+ key: newKey,
5050
+ salt: newSalt
4244
5051
  };
4245
5052
  };
4246
- var MOCK_RAW_ON_CHAIN_NOTIFICATIONS = createMockRawOnChainNotifications();
4247
- var getMockListNotificationsResponse = () => {
5053
+ var encryption = new EncryptorDecryptor();
5054
+ var encryption_default = encryption;
5055
+ function createSHA256Hash(data) {
5056
+ const hashedData = sha256(data);
5057
+ return bytesToHex(hashedData);
5058
+ }
5059
+
5060
+ // ../profile-sync-controller/src/controllers/user-storage/encryption/index.ts
5061
+ var encryption_default2 = encryption_default;
5062
+
5063
+ // ../profile-sync-controller/src/controllers/user-storage/services.ts
5064
+ var _loglevel = require('loglevel'); var _loglevel2 = _interopRequireDefault(_loglevel);
5065
+
5066
+ // ../profile-sync-controller/src/controllers/user-storage/schema.ts
5067
+ var USER_STORAGE_ENTRIES = {
5068
+ notificationSettings: {
5069
+ path: "notifications",
5070
+ entryName: "notificationSettings"
5071
+ }
5072
+ };
5073
+ function createEntryPath(entryKey, storageKey) {
5074
+ const entry = USER_STORAGE_ENTRIES[entryKey];
5075
+ if (!entry) {
5076
+ throw new Error(`user-storage - invalid entry provided: ${entryKey}`);
5077
+ }
5078
+ const hashedKey = createSHA256Hash(entry.entryName + storageKey);
5079
+ return `/${entry.path}/${hashedKey}`;
5080
+ }
5081
+
5082
+ // ../profile-sync-controller/src/controllers/user-storage/services.ts
5083
+ var ENV_URLS2 = getEnvUrls("prd" /* PRD */);
5084
+ var USER_STORAGE_API = ENV_URLS2.userStorageApiUrl;
5085
+ var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
5086
+
5087
+ // ../profile-sync-controller/src/controllers/user-storage/__fixtures__/index.ts
5088
+ var fixtures_exports = {};
5089
+ _chunkV46WVGWNjs.__export.call(void 0, fixtures_exports, {
5090
+ MOCK_ENCRYPTED_STORAGE_DATA: () => MOCK_ENCRYPTED_STORAGE_DATA,
5091
+ MOCK_STORAGE_DATA: () => MOCK_STORAGE_DATA,
5092
+ MOCK_STORAGE_KEY: () => MOCK_STORAGE_KEY,
5093
+ MOCK_STORAGE_KEY_SIGNATURE: () => MOCK_STORAGE_KEY_SIGNATURE,
5094
+ MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT: () => MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
5095
+ getMockUserStorageGetResponse: () => getMockUserStorageGetResponse,
5096
+ getMockUserStoragePutResponse: () => getMockUserStoragePutResponse,
5097
+ mockEndpointGetUserStorage: () => mockEndpointGetUserStorage,
5098
+ mockEndpointUpsertUserStorage: () => mockEndpointUpsertUserStorage
5099
+ });
5100
+
5101
+ // ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockStorage.ts
5102
+ var MOCK_STORAGE_KEY_SIGNATURE = "mockStorageKey";
5103
+ var MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);
5104
+ var MOCK_STORAGE_DATA = JSON.stringify({ hello: "world" });
5105
+ var MOCK_ENCRYPTED_STORAGE_DATA = encryption_default2.encryptString(
5106
+ MOCK_STORAGE_DATA,
5107
+ MOCK_STORAGE_KEY
5108
+ );
5109
+
5110
+ // ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts
5111
+ var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(
5112
+ "notificationSettings",
5113
+ MOCK_STORAGE_KEY
5114
+ )}`;
5115
+ var MOCK_GET_USER_STORAGE_RESPONSE = {
5116
+ HashedKey: "HASHED_KEY",
5117
+ Data: MOCK_ENCRYPTED_STORAGE_DATA
5118
+ };
5119
+ var getMockUserStorageGetResponse = () => {
4248
5120
  return {
4249
- url: _chunkVOZ7Y2OOjs.NOTIFICATION_API_LIST_ENDPOINT,
4250
- requestMethod: "POST",
4251
- response: MOCK_RAW_ON_CHAIN_NOTIFICATIONS
5121
+ url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
5122
+ requestMethod: "GET",
5123
+ response: MOCK_GET_USER_STORAGE_RESPONSE
4252
5124
  };
4253
5125
  };
4254
- var getMockMarkNotificationsAsReadResponse = () => {
5126
+ var getMockUserStoragePutResponse = () => {
4255
5127
  return {
4256
- url: _chunkVOZ7Y2OOjs.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
4257
- requestMethod: "POST",
5128
+ url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
5129
+ requestMethod: "PUT",
4258
5130
  response: null
4259
5131
  };
4260
5132
  };
4261
5133
 
4262
- // src/NotificationServicesController/__fixtures__/mockServices.ts
5134
+ // ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockServices.ts
4263
5135
  var import_nock = _chunkV46WVGWNjs.__toESM.call(void 0, require_nock());
4264
- var mockFetchFeatureAnnouncementNotifications = (mockReply) => {
4265
- const mockResponse = getMockFeatureAnnouncementResponse();
4266
- const reply = mockReply ?? { status: 200, body: mockResponse.response };
4267
- const mockEndpoint = (0, import_nock.default)(mockResponse.url).get("").query(true).reply(reply.status, reply.body);
4268
- return mockEndpoint;
4269
- };
4270
- var mockBatchCreateTriggers = (mockReply) => {
4271
- const mockResponse = getMockBatchCreateTriggersResponse();
4272
- const reply = mockReply ?? { status: 204 };
4273
- const mockEndpoint = (0, import_nock.default)(mockResponse.url).post("").reply(reply.status, reply.body);
4274
- return mockEndpoint;
4275
- };
4276
- var mockBatchDeleteTriggers = (mockReply) => {
4277
- const mockResponse = getMockBatchDeleteTriggersResponse();
4278
- const reply = mockReply ?? { status: 204 };
4279
- const mockEndpoint = (0, import_nock.default)(mockResponse.url).delete("").reply(reply.status, reply.body);
4280
- return mockEndpoint;
4281
- };
4282
- var mockListNotifications = (mockReply) => {
4283
- const mockResponse = getMockListNotificationsResponse();
4284
- const reply = mockReply ?? { status: 200, body: mockResponse.response };
4285
- const mockEndpoint = (0, import_nock.default)(mockResponse.url).post("").query(true).reply(reply.status, reply.body);
5136
+ var mockEndpointGetUserStorage = (mockReply) => {
5137
+ const mockResponse = getMockUserStorageGetResponse();
5138
+ const reply = mockReply ?? {
5139
+ status: 200,
5140
+ body: mockResponse.response
5141
+ };
5142
+ const mockEndpoint = (0, import_nock.default)(mockResponse.url).get("").reply(reply.status, reply.body);
4286
5143
  return mockEndpoint;
4287
5144
  };
4288
- var mockMarkNotificationsAsRead = (mockReply) => {
4289
- const mockResponse = getMockMarkNotificationsAsReadResponse();
4290
- const reply = mockReply ?? { status: 200 };
4291
- const mockEndpoint = (0, import_nock.default)(mockResponse.url).post("").reply(reply.status, reply.body);
5145
+ var mockEndpointUpsertUserStorage = (mockReply) => {
5146
+ const mockResponse = getMockUserStoragePutResponse();
5147
+ const mockEndpoint = (0, import_nock.default)(mockResponse.url).put("").reply(mockReply?.status ?? 204);
4292
5148
  return mockEndpoint;
4293
5149
  };
4294
5150
 
5151
+ // src/NotificationServicesController/services/onchain-notifications.ts
5152
+
5153
+ var TRIGGER_API = "https://trigger.api.cx.metamask.io";
5154
+ var NOTIFICATION_API = "https://notification.api.cx.metamask.io";
5155
+ var TRIGGER_API_BATCH_ENDPOINT = `${TRIGGER_API}/api/v1/triggers/batch`;
5156
+ var NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v1/notifications`;
5157
+ var NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY = (page) => `${NOTIFICATION_API_LIST_ENDPOINT}?page=${page}&per_page=100`;
5158
+ var NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/api/v1/notifications/mark-as-read`;
5159
+ async function createOnChainTriggers(userStorage, storageKey, bearerToken, triggers) {
5160
+ const triggersToCreate = triggers.map((t) => ({
5161
+ id: t.id,
5162
+ token: user_storage_exports.createSHA256Hash(t.id + storageKey),
5163
+ config: {
5164
+ kind: t.kind,
5165
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5166
+ chain_id: Number(t.chainId),
5167
+ address: t.address
5168
+ }
5169
+ }));
5170
+ if (triggersToCreate.length === 0) {
5171
+ return;
5172
+ }
5173
+ const response = await _chunkPIZCE3JDjs.makeApiCall.call(void 0,
5174
+ bearerToken,
5175
+ TRIGGER_API_BATCH_ENDPOINT,
5176
+ "POST",
5177
+ triggersToCreate
5178
+ );
5179
+ if (!response.ok) {
5180
+ const errorData = await response.json().catch(() => void 0);
5181
+ _loglevel2.default.error("Error creating triggers:", errorData);
5182
+ throw new Error("OnChain Notifications - unable to create triggers");
5183
+ }
5184
+ for (const trigger of triggersToCreate) {
5185
+ _chunkPIZCE3JDjs.toggleUserStorageTriggerStatus.call(void 0,
5186
+ userStorage,
5187
+ trigger.config.address,
5188
+ String(trigger.config.chain_id),
5189
+ trigger.id,
5190
+ true
5191
+ );
5192
+ }
5193
+ }
5194
+ async function deleteOnChainTriggers(userStorage, storageKey, bearerToken, uuids) {
5195
+ const triggersToDelete = uuids.map((uuid) => ({
5196
+ id: uuid,
5197
+ token: user_storage_exports.createSHA256Hash(uuid + storageKey)
5198
+ }));
5199
+ try {
5200
+ const response = await _chunkPIZCE3JDjs.makeApiCall.call(void 0,
5201
+ bearerToken,
5202
+ TRIGGER_API_BATCH_ENDPOINT,
5203
+ "DELETE",
5204
+ triggersToDelete
5205
+ );
5206
+ if (!response.ok) {
5207
+ throw new Error(
5208
+ `Failed to delete on-chain notifications for uuids ${uuids.join(", ")}`
5209
+ );
5210
+ }
5211
+ for (const uuid of uuids) {
5212
+ for (const address in userStorage) {
5213
+ if (address in userStorage) {
5214
+ for (const chainId in userStorage[address]) {
5215
+ if (userStorage?.[address]?.[chainId]?.[uuid]) {
5216
+ delete userStorage[address][chainId][uuid];
5217
+ }
5218
+ }
5219
+ }
5220
+ }
5221
+ }
5222
+ const isEmpty = (obj = {}) => Object.keys(obj).length === 0;
5223
+ for (const address in userStorage) {
5224
+ if (address in userStorage) {
5225
+ for (const chainId in userStorage[address]) {
5226
+ if (isEmpty(userStorage?.[address]?.[chainId])) {
5227
+ delete userStorage[address][chainId];
5228
+ }
5229
+ }
5230
+ if (isEmpty(userStorage?.[address])) {
5231
+ delete userStorage[address];
5232
+ }
5233
+ }
5234
+ }
5235
+ } catch (err) {
5236
+ _loglevel2.default.error(
5237
+ `Error deleting on-chain notifications for uuids ${uuids.join(", ")}:`,
5238
+ err
5239
+ );
5240
+ throw err;
5241
+ }
5242
+ return userStorage;
5243
+ }
5244
+ async function getOnChainNotifications(userStorage, bearerToken) {
5245
+ const triggerIds = _chunkPIZCE3JDjs.traverseUserStorageTriggers.call(void 0, userStorage, {
5246
+ mapTrigger: (t) => {
5247
+ if (!t.enabled) {
5248
+ return void 0;
5249
+ }
5250
+ return t.id;
5251
+ }
5252
+ });
5253
+ if (triggerIds.length === 0) {
5254
+ return [];
5255
+ }
5256
+ const onChainNotifications = [];
5257
+ const PAGE_LIMIT = 2;
5258
+ for (let page = 1; page <= PAGE_LIMIT; page++) {
5259
+ try {
5260
+ const response = await _chunkPIZCE3JDjs.makeApiCall.call(void 0,
5261
+ bearerToken,
5262
+ NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY(page),
5263
+ "POST",
5264
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5265
+ { trigger_ids: triggerIds }
5266
+ );
5267
+ const notifications = await response.json();
5268
+ const transformedNotifications = notifications.map(
5269
+ (n) => {
5270
+ if (!n.data?.kind) {
5271
+ return void 0;
5272
+ }
5273
+ return {
5274
+ ...n,
5275
+ type: n.data.kind
5276
+ };
5277
+ }
5278
+ ).filter((n) => Boolean(n));
5279
+ onChainNotifications.push(...transformedNotifications);
5280
+ if (notifications.length < 100) {
5281
+ page = PAGE_LIMIT + 1;
5282
+ break;
5283
+ }
5284
+ } catch (err) {
5285
+ _loglevel2.default.error(
5286
+ `Error fetching on-chain notifications for trigger IDs ${triggerIds.join(
5287
+ ", "
5288
+ )}:`,
5289
+ err
5290
+ );
5291
+ }
5292
+ }
5293
+ return onChainNotifications;
5294
+ }
5295
+ async function markNotificationsAsRead(bearerToken, notificationIds) {
5296
+ if (notificationIds.length === 0) {
5297
+ return;
5298
+ }
5299
+ try {
5300
+ const response = await _chunkPIZCE3JDjs.makeApiCall.call(void 0,
5301
+ bearerToken,
5302
+ NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
5303
+ "POST",
5304
+ { ids: notificationIds }
5305
+ );
5306
+ if (response.status !== 200) {
5307
+ const errorData = await response.json().catch(() => void 0);
5308
+ throw new Error(
5309
+ `Error marking notifications as read: ${errorData?.message}`
5310
+ );
5311
+ }
5312
+ } catch (err) {
5313
+ _loglevel2.default.error("Error marking notifications as read:", err);
5314
+ throw err;
5315
+ }
5316
+ }
5317
+
5318
+
5319
+
5320
+
5321
+
5322
+
5323
+
5324
+
5325
+
5326
+
5327
+
4295
5328
 
4296
5329
 
5330
+ exports.require_nock = require_nock; exports.TRIGGER_API = TRIGGER_API; exports.NOTIFICATION_API = NOTIFICATION_API; exports.TRIGGER_API_BATCH_ENDPOINT = TRIGGER_API_BATCH_ENDPOINT; exports.NOTIFICATION_API_LIST_ENDPOINT = NOTIFICATION_API_LIST_ENDPOINT; exports.NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY = NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY; exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT; exports.createOnChainTriggers = createOnChainTriggers; exports.deleteOnChainTriggers = deleteOnChainTriggers; exports.getOnChainNotifications = getOnChainNotifications; exports.markNotificationsAsRead = markNotificationsAsRead;
5331
+ /*! Bundled license information:
4297
5332
 
5333
+ @noble/ciphers/esm/utils.js:
5334
+ (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
4298
5335
 
4299
- exports.require_nock = require_nock; exports.fixtures_exports = fixtures_exports; exports.NotificationServicesController_exports = NotificationServicesController_exports;
4300
- //# sourceMappingURL=chunk-DNTK4U5M.js.map
5336
+ @noble/hashes/esm/utils.js:
5337
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
5338
+ */
5339
+ //# sourceMappingURL=chunk-53Y2GNFU.js.map