@metamask-previews/notification-services-controller 0.0.0-preview-98d4c2a0 → 0.0.0-preview-e751859
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NotificationServicesController/NotificationServicesController.js +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.mjs +2 -2
- package/dist/NotificationServicesController/index.js +4 -4
- package/dist/NotificationServicesController/index.mjs +3 -3
- package/dist/NotificationServicesController/services/onchain-notifications.js +2 -2
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.js +3 -3
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +3 -3
- package/dist/NotificationServicesPushController/index.js +5 -5
- package/dist/NotificationServicesPushController/index.mjs +4 -4
- package/dist/NotificationServicesPushController/services/push/push-web.js +3 -3
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +3 -3
- package/dist/NotificationServicesPushController/services/services.js +3 -3
- package/dist/NotificationServicesPushController/services/services.mjs +3 -3
- package/dist/NotificationServicesPushController/utils/get-notification-message.js +3 -3
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +3 -3
- package/dist/NotificationServicesPushController/utils/index.js +3 -3
- package/dist/NotificationServicesPushController/utils/index.mjs +3 -3
- package/dist/chunk-3M76IZD5.js +965 -0
- package/dist/chunk-3M76IZD5.js.map +1 -0
- package/dist/{chunk-DNTK4U5M.js → chunk-3O5NGZWB.js} +2266 -892
- package/dist/chunk-3O5NGZWB.js.map +1 -0
- package/dist/{chunk-5OYPOYXZ.mjs → chunk-4QS664EH.mjs} +2 -2
- package/dist/{chunk-KTQP5UDT.mjs → chunk-IG3CMJBW.mjs} +2272 -898
- package/dist/chunk-IG3CMJBW.mjs.map +1 -0
- package/dist/{chunk-XNBTOK6G.js → chunk-LJ533Y4L.js} +7 -7
- package/dist/{chunk-3F4M3OUO.mjs → chunk-VNTBP7AI.mjs} +2 -2
- package/dist/{chunk-6B5FOWRH.js → chunk-WYAE7RGD.js} +3 -3
- package/dist/chunk-Y7CUC6PM.mjs +965 -0
- package/dist/chunk-Y7CUC6PM.mjs.map +1 -0
- package/dist/index.js +5 -5
- package/dist/index.mjs +4 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/dist/chunk-DNTK4U5M.js.map +0 -1
- package/dist/chunk-KTQP5UDT.mjs.map +0 -1
- package/dist/chunk-UIRZIKC3.mjs +0 -187
- package/dist/chunk-UIRZIKC3.mjs.map +0 -1
- package/dist/chunk-VOZ7Y2OO.js +0 -187
- package/dist/chunk-VOZ7Y2OO.js.map +0 -1
- /package/dist/{chunk-5OYPOYXZ.mjs.map → chunk-4QS664EH.mjs.map} +0 -0
- /package/dist/{chunk-XNBTOK6G.js.map → chunk-LJ533Y4L.js.map} +0 -0
- /package/dist/{chunk-3F4M3OUO.mjs.map → chunk-VNTBP7AI.mjs.map} +0 -0
- /package/dist/{chunk-6B5FOWRH.js.map → chunk-WYAE7RGD.js.map} +0 -0
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
types_exports
|
|
6
|
-
} from "./chunk-B4ECJJ5C.mjs";
|
|
7
|
-
import {
|
|
8
|
-
NotificationServicesController,
|
|
9
|
-
defaultState
|
|
10
|
-
} from "./chunk-5OYPOYXZ.mjs";
|
|
11
|
-
import {
|
|
12
|
-
FEATURE_ANNOUNCEMENT_API
|
|
13
|
-
} from "./chunk-EQWVJX6K.mjs";
|
|
14
|
-
import {
|
|
15
|
-
NOTIFICATION_API_LIST_ENDPOINT,
|
|
16
|
-
NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
|
|
17
|
-
TRIGGER_API_BATCH_ENDPOINT
|
|
18
|
-
} from "./chunk-UIRZIKC3.mjs";
|
|
19
|
-
import {
|
|
20
|
-
initializeUserStorage
|
|
2
|
+
makeApiCall,
|
|
3
|
+
toggleUserStorageTriggerStatus,
|
|
4
|
+
traverseUserStorageTriggers
|
|
21
5
|
} from "./chunk-SMKJEA45.mjs";
|
|
22
|
-
import {
|
|
23
|
-
constants_exports
|
|
24
|
-
} from "./chunk-VE4DTN4R.mjs";
|
|
25
|
-
import {
|
|
26
|
-
USER_STORAGE_VERSION_KEY
|
|
27
|
-
} from "./chunk-6ZDVTRRT.mjs";
|
|
28
6
|
import {
|
|
29
7
|
__commonJS,
|
|
30
8
|
__export,
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateMethod,
|
|
31
12
|
__require,
|
|
32
13
|
__toESM
|
|
33
14
|
} from "./chunk-26CCETCM.mjs";
|
|
@@ -169,12 +150,12 @@ var require_common = __commonJS({
|
|
|
169
150
|
createDebug.skips = [];
|
|
170
151
|
createDebug.formatters = {};
|
|
171
152
|
function selectColor(namespace) {
|
|
172
|
-
let
|
|
153
|
+
let hash2 = 0;
|
|
173
154
|
for (let i = 0; i < namespace.length; i++) {
|
|
174
|
-
|
|
175
|
-
|
|
155
|
+
hash2 = (hash2 << 5) - hash2 + namespace.charCodeAt(i);
|
|
156
|
+
hash2 |= 0;
|
|
176
157
|
}
|
|
177
|
-
return createDebug.colors[Math.abs(
|
|
158
|
+
return createDebug.colors[Math.abs(hash2) % createDebug.colors.length];
|
|
178
159
|
}
|
|
179
160
|
createDebug.selectColor = selectColor;
|
|
180
161
|
function createDebug(namespace) {
|
|
@@ -578,15 +559,15 @@ var require_common2 = __commonJS({
|
|
|
578
559
|
function stringifyRequest(options, body) {
|
|
579
560
|
const { method = "GET", path = "", port } = options;
|
|
580
561
|
const origin = normalizeOrigin(options.proto, options.hostname, port);
|
|
581
|
-
const
|
|
562
|
+
const log3 = {
|
|
582
563
|
method,
|
|
583
564
|
url: `${origin}${path}`,
|
|
584
565
|
headers: options.headers
|
|
585
566
|
};
|
|
586
567
|
if (body) {
|
|
587
|
-
|
|
568
|
+
log3.body = body;
|
|
588
569
|
}
|
|
589
|
-
return JSON.stringify(
|
|
570
|
+
return JSON.stringify(log3, null, 2);
|
|
590
571
|
}
|
|
591
572
|
function isContentEncoded(headers) {
|
|
592
573
|
const contentEncoding2 = headers["content-encoding"];
|
|
@@ -1691,7 +1672,7 @@ var require_interceptor = __commonJS({
|
|
|
1691
1672
|
"use strict";
|
|
1692
1673
|
var stringify = require_stringify();
|
|
1693
1674
|
var querystring = __require("querystring");
|
|
1694
|
-
var { URL, URLSearchParams } = __require("url");
|
|
1675
|
+
var { URL: URL2, URLSearchParams } = __require("url");
|
|
1695
1676
|
var common = require_common2();
|
|
1696
1677
|
var { remove } = require_intercept();
|
|
1697
1678
|
var matchBody = require_match_body();
|
|
@@ -1745,7 +1726,7 @@ var require_interceptor = __commonJS({
|
|
|
1745
1726
|
this.delayConnectionInMs = 0;
|
|
1746
1727
|
this.optional = false;
|
|
1747
1728
|
if (uriIsStr && uri.includes("?")) {
|
|
1748
|
-
const parsedURL = new
|
|
1729
|
+
const parsedURL = new URL2(this.path, "http://localhost");
|
|
1749
1730
|
this.path = parsedURL.pathname;
|
|
1750
1731
|
this.query(parsedURL.searchParams);
|
|
1751
1732
|
this._key = `${this.method} ${scope.basePath}${this.path}`;
|
|
@@ -2742,18 +2723,18 @@ var require_scope = __commonJS({
|
|
|
2742
2723
|
var debug = require_browser()("nock.scope");
|
|
2743
2724
|
var { EventEmitter } = __require("events");
|
|
2744
2725
|
var Interceptor = require_interceptor();
|
|
2745
|
-
var { URL, Url: LegacyUrl } = url;
|
|
2726
|
+
var { URL: URL2, Url: LegacyUrl } = url;
|
|
2746
2727
|
var fs;
|
|
2747
2728
|
try {
|
|
2748
2729
|
fs = __require("fs");
|
|
2749
2730
|
} catch (err) {
|
|
2750
2731
|
}
|
|
2751
2732
|
function normalizeUrl(u) {
|
|
2752
|
-
if (!(u instanceof
|
|
2733
|
+
if (!(u instanceof URL2)) {
|
|
2753
2734
|
if (u instanceof LegacyUrl) {
|
|
2754
|
-
return normalizeUrl(new
|
|
2735
|
+
return normalizeUrl(new URL2(url.format(u)));
|
|
2755
2736
|
}
|
|
2756
|
-
return normalizeUrl(new
|
|
2737
|
+
return normalizeUrl(new URL2(u));
|
|
2757
2738
|
}
|
|
2758
2739
|
if (!/https?:/.test(u.protocol)) {
|
|
2759
2740
|
throw new TypeError(
|
|
@@ -3299,13 +3280,13 @@ var require_back = __commonJS({
|
|
|
3299
3280
|
lockdown
|
|
3300
3281
|
// use recorded nocks, disables all http calls even when not nocked, doesnt record
|
|
3301
3282
|
};
|
|
3302
|
-
Back.setMode = function(
|
|
3303
|
-
if (!(
|
|
3304
|
-
throw new Error(`Unknown mode: ${
|
|
3283
|
+
Back.setMode = function(mode2) {
|
|
3284
|
+
if (!(mode2 in Modes)) {
|
|
3285
|
+
throw new Error(`Unknown mode: ${mode2}`);
|
|
3305
3286
|
}
|
|
3306
|
-
Back.currentMode =
|
|
3287
|
+
Back.currentMode = mode2;
|
|
3307
3288
|
debug("New nock back mode:", Back.currentMode);
|
|
3308
|
-
_mode = Modes[
|
|
3289
|
+
_mode = Modes[mode2];
|
|
3309
3290
|
_mode.setup();
|
|
3310
3291
|
};
|
|
3311
3292
|
Back.fixtures = null;
|
|
@@ -3365,936 +3346,2329 @@ var require_nock = __commonJS({
|
|
|
3365
3346
|
}
|
|
3366
3347
|
});
|
|
3367
3348
|
|
|
3368
|
-
// src/
|
|
3369
|
-
var
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3349
|
+
// ../profile-sync-controller/src/sdk/env.ts
|
|
3350
|
+
var ENV_URLS = {
|
|
3351
|
+
dev: {
|
|
3352
|
+
authApiUrl: "https://authentication.dev-api.cx.metamask.io",
|
|
3353
|
+
oidcApiUrl: "https://oidc.dev-api.cx.metamask.io",
|
|
3354
|
+
userStorageApiUrl: "https://user-storage.dev-api.cx.metamask.io"
|
|
3355
|
+
},
|
|
3356
|
+
uat: {
|
|
3357
|
+
authApiUrl: "https://authentication.uat-api.cx.metamask.io",
|
|
3358
|
+
oidcApiUrl: "https://oidc.uat-api.cx.metamask.io",
|
|
3359
|
+
userStorageApiUrl: "https://user-storage.uat-api.cx.metamask.io"
|
|
3360
|
+
},
|
|
3361
|
+
prd: {
|
|
3362
|
+
authApiUrl: "https://authentication.api.cx.metamask.io",
|
|
3363
|
+
oidcApiUrl: "https://oidc.api.cx.metamask.io",
|
|
3364
|
+
userStorageApiUrl: "https://user-storage.api.cx.metamask.io"
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
3367
|
+
function getEnvUrls(env) {
|
|
3368
|
+
if (!ENV_URLS[env]) {
|
|
3369
|
+
throw new Error("invalid environment configuration");
|
|
3370
|
+
}
|
|
3371
|
+
return ENV_URLS[env];
|
|
3372
|
+
}
|
|
3378
3373
|
|
|
3379
|
-
//
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
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
|
-
});
|
|
3374
|
+
// ../../node_modules/@noble/ciphers/esm/_assert.js
|
|
3375
|
+
function isBytes(a) {
|
|
3376
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
3377
|
+
}
|
|
3378
|
+
function bytes(b, ...lengths) {
|
|
3379
|
+
if (!isBytes(b))
|
|
3380
|
+
throw new Error("Uint8Array expected");
|
|
3381
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
3382
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
3383
|
+
}
|
|
3384
|
+
function exists(instance, checkFinished = true) {
|
|
3385
|
+
if (instance.destroyed)
|
|
3386
|
+
throw new Error("Hash instance has been destroyed");
|
|
3387
|
+
if (checkFinished && instance.finished)
|
|
3388
|
+
throw new Error("Hash#digest() has already been called");
|
|
3389
|
+
}
|
|
3390
|
+
function output(out, instance) {
|
|
3391
|
+
bytes(out);
|
|
3392
|
+
const min = instance.outputLen;
|
|
3393
|
+
if (out.length < min) {
|
|
3394
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3419
3397
|
|
|
3420
|
-
//
|
|
3421
|
-
|
|
3398
|
+
// ../../node_modules/@noble/ciphers/esm/utils.js
|
|
3399
|
+
var u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3400
|
+
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
3401
|
+
var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3402
|
+
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
3403
|
+
if (!isLE)
|
|
3404
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
3405
|
+
function utf8ToBytes(str) {
|
|
3406
|
+
if (typeof str !== "string")
|
|
3407
|
+
throw new Error(`string expected, got ${typeof str}`);
|
|
3408
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
3409
|
+
}
|
|
3410
|
+
function toBytes(data) {
|
|
3411
|
+
if (typeof data === "string")
|
|
3412
|
+
data = utf8ToBytes(data);
|
|
3413
|
+
else if (isBytes(data))
|
|
3414
|
+
data = data.slice();
|
|
3415
|
+
else
|
|
3416
|
+
throw new Error(`Uint8Array expected, got ${typeof data}`);
|
|
3417
|
+
return data;
|
|
3418
|
+
}
|
|
3419
|
+
function equalBytes(a, b) {
|
|
3420
|
+
if (a.length !== b.length)
|
|
3421
|
+
return false;
|
|
3422
|
+
let diff = 0;
|
|
3423
|
+
for (let i = 0; i < a.length; i++)
|
|
3424
|
+
diff |= a[i] ^ b[i];
|
|
3425
|
+
return diff === 0;
|
|
3426
|
+
}
|
|
3427
|
+
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, c) => {
|
|
3428
|
+
Object.assign(c, params);
|
|
3429
|
+
return c;
|
|
3430
|
+
};
|
|
3431
|
+
function setBigUint64(view, byteOffset, value, isLE3) {
|
|
3432
|
+
if (typeof view.setBigUint64 === "function")
|
|
3433
|
+
return view.setBigUint64(byteOffset, value, isLE3);
|
|
3434
|
+
const _32n = BigInt(32);
|
|
3435
|
+
const _u32_max = BigInt(4294967295);
|
|
3436
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
3437
|
+
const wl = Number(value & _u32_max);
|
|
3438
|
+
const h = isLE3 ? 4 : 0;
|
|
3439
|
+
const l = isLE3 ? 0 : 4;
|
|
3440
|
+
view.setUint32(byteOffset + h, wh, isLE3);
|
|
3441
|
+
view.setUint32(byteOffset + l, wl, isLE3);
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
// ../../node_modules/@noble/ciphers/esm/_polyval.js
|
|
3445
|
+
var BLOCK_SIZE = 16;
|
|
3446
|
+
var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
3447
|
+
var ZEROS32 = u32(ZEROS16);
|
|
3448
|
+
var POLY = 225;
|
|
3449
|
+
var mul2 = (s0, s1, s2, s3) => {
|
|
3450
|
+
const hiBit = s3 & 1;
|
|
3422
3451
|
return {
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
}
|
|
3490
|
-
],
|
|
3491
|
-
nodeType: "document"
|
|
3492
|
-
},
|
|
3493
|
-
link: {
|
|
3494
|
-
sys: {
|
|
3495
|
-
type: "Link",
|
|
3496
|
-
linkType: "Entry",
|
|
3497
|
-
id: "62xKYM2ydo4F1mS5q97K5q"
|
|
3498
|
-
}
|
|
3499
|
-
}
|
|
3452
|
+
s3: s2 << 31 | s3 >>> 1,
|
|
3453
|
+
s2: s1 << 31 | s2 >>> 1,
|
|
3454
|
+
s1: s0 << 31 | s1 >>> 1,
|
|
3455
|
+
s0: s0 >>> 1 ^ POLY << 24 & -(hiBit & 1)
|
|
3456
|
+
// reduce % poly
|
|
3457
|
+
};
|
|
3458
|
+
};
|
|
3459
|
+
var swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
|
|
3460
|
+
function _toGHASHKey(k) {
|
|
3461
|
+
k.reverse();
|
|
3462
|
+
const hiBit = k[15] & 1;
|
|
3463
|
+
let carry = 0;
|
|
3464
|
+
for (let i = 0; i < k.length; i++) {
|
|
3465
|
+
const t = k[i];
|
|
3466
|
+
k[i] = t >>> 1 | carry;
|
|
3467
|
+
carry = (t & 1) << 7;
|
|
3468
|
+
}
|
|
3469
|
+
k[0] ^= -hiBit & 225;
|
|
3470
|
+
return k;
|
|
3471
|
+
}
|
|
3472
|
+
var estimateWindow = (bytes3) => {
|
|
3473
|
+
if (bytes3 > 64 * 1024)
|
|
3474
|
+
return 8;
|
|
3475
|
+
if (bytes3 > 1024)
|
|
3476
|
+
return 4;
|
|
3477
|
+
return 2;
|
|
3478
|
+
};
|
|
3479
|
+
var GHASH = class {
|
|
3480
|
+
// We select bits per window adaptively based on expectedLength
|
|
3481
|
+
constructor(key, expectedLength) {
|
|
3482
|
+
this.blockLen = BLOCK_SIZE;
|
|
3483
|
+
this.outputLen = BLOCK_SIZE;
|
|
3484
|
+
this.s0 = 0;
|
|
3485
|
+
this.s1 = 0;
|
|
3486
|
+
this.s2 = 0;
|
|
3487
|
+
this.s3 = 0;
|
|
3488
|
+
this.finished = false;
|
|
3489
|
+
key = toBytes(key);
|
|
3490
|
+
bytes(key, 16);
|
|
3491
|
+
const kView = createView(key);
|
|
3492
|
+
let k0 = kView.getUint32(0, false);
|
|
3493
|
+
let k1 = kView.getUint32(4, false);
|
|
3494
|
+
let k2 = kView.getUint32(8, false);
|
|
3495
|
+
let k3 = kView.getUint32(12, false);
|
|
3496
|
+
const doubles = [];
|
|
3497
|
+
for (let i = 0; i < 128; i++) {
|
|
3498
|
+
doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) });
|
|
3499
|
+
({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul2(k0, k1, k2, k3));
|
|
3500
|
+
}
|
|
3501
|
+
const W = estimateWindow(expectedLength || 1024);
|
|
3502
|
+
if (![1, 2, 4, 8].includes(W))
|
|
3503
|
+
throw new Error(`ghash: wrong window size=${W}, should be 2, 4 or 8`);
|
|
3504
|
+
this.W = W;
|
|
3505
|
+
const bits = 128;
|
|
3506
|
+
const windows = bits / W;
|
|
3507
|
+
const windowSize = this.windowSize = 2 ** W;
|
|
3508
|
+
const items = [];
|
|
3509
|
+
for (let w = 0; w < windows; w++) {
|
|
3510
|
+
for (let byte = 0; byte < windowSize; byte++) {
|
|
3511
|
+
let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
|
3512
|
+
for (let j = 0; j < W; j++) {
|
|
3513
|
+
const bit = byte >>> W - j - 1 & 1;
|
|
3514
|
+
if (!bit)
|
|
3515
|
+
continue;
|
|
3516
|
+
const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W * w + j];
|
|
3517
|
+
s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
|
|
3500
3518
|
}
|
|
3519
|
+
items.push({ s0, s1, s2, s3 });
|
|
3501
3520
|
}
|
|
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
3521
|
}
|
|
3590
|
-
|
|
3591
|
-
}
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
extensionLink: {
|
|
3608
|
-
extensionLinkText: "Try now",
|
|
3609
|
-
extensionLinkRoute: "home.html"
|
|
3522
|
+
this.t = items;
|
|
3523
|
+
}
|
|
3524
|
+
_updateBlock(s0, s1, s2, s3) {
|
|
3525
|
+
s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
|
|
3526
|
+
const { W, t, windowSize } = this;
|
|
3527
|
+
let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
|
|
3528
|
+
const mask = (1 << W) - 1;
|
|
3529
|
+
let w = 0;
|
|
3530
|
+
for (const num of [s0, s1, s2, s3]) {
|
|
3531
|
+
for (let bytePos = 0; bytePos < 4; bytePos++) {
|
|
3532
|
+
const byte = num >>> 8 * bytePos & 255;
|
|
3533
|
+
for (let bitPos = 8 / W - 1; bitPos >= 0; bitPos--) {
|
|
3534
|
+
const bit = byte >>> W * bitPos & mask;
|
|
3535
|
+
const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
|
|
3536
|
+
o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
|
|
3537
|
+
w += 1;
|
|
3538
|
+
}
|
|
3610
3539
|
}
|
|
3611
3540
|
}
|
|
3612
|
-
|
|
3541
|
+
this.s0 = o0;
|
|
3542
|
+
this.s1 = o1;
|
|
3543
|
+
this.s2 = o2;
|
|
3544
|
+
this.s3 = o3;
|
|
3545
|
+
}
|
|
3546
|
+
update(data) {
|
|
3547
|
+
data = toBytes(data);
|
|
3548
|
+
exists(this);
|
|
3549
|
+
const b32 = u32(data);
|
|
3550
|
+
const blocks = Math.floor(data.length / BLOCK_SIZE);
|
|
3551
|
+
const left = data.length % BLOCK_SIZE;
|
|
3552
|
+
for (let i = 0; i < blocks; i++) {
|
|
3553
|
+
this._updateBlock(b32[i * 4 + 0], b32[i * 4 + 1], b32[i * 4 + 2], b32[i * 4 + 3]);
|
|
3554
|
+
}
|
|
3555
|
+
if (left) {
|
|
3556
|
+
ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
|
|
3557
|
+
this._updateBlock(ZEROS32[0], ZEROS32[1], ZEROS32[2], ZEROS32[3]);
|
|
3558
|
+
ZEROS32.fill(0);
|
|
3559
|
+
}
|
|
3560
|
+
return this;
|
|
3561
|
+
}
|
|
3562
|
+
destroy() {
|
|
3563
|
+
const { t } = this;
|
|
3564
|
+
for (const elm of t) {
|
|
3565
|
+
elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
digestInto(out) {
|
|
3569
|
+
exists(this);
|
|
3570
|
+
output(out, this);
|
|
3571
|
+
this.finished = true;
|
|
3572
|
+
const { s0, s1, s2, s3 } = this;
|
|
3573
|
+
const o32 = u32(out);
|
|
3574
|
+
o32[0] = s0;
|
|
3575
|
+
o32[1] = s1;
|
|
3576
|
+
o32[2] = s2;
|
|
3577
|
+
o32[3] = s3;
|
|
3578
|
+
return out;
|
|
3579
|
+
}
|
|
3580
|
+
digest() {
|
|
3581
|
+
const res = new Uint8Array(BLOCK_SIZE);
|
|
3582
|
+
this.digestInto(res);
|
|
3583
|
+
this.destroy();
|
|
3584
|
+
return res;
|
|
3585
|
+
}
|
|
3586
|
+
};
|
|
3587
|
+
var Polyval = class extends GHASH {
|
|
3588
|
+
constructor(key, expectedLength) {
|
|
3589
|
+
key = toBytes(key);
|
|
3590
|
+
const ghKey = _toGHASHKey(key.slice());
|
|
3591
|
+
super(ghKey, expectedLength);
|
|
3592
|
+
ghKey.fill(0);
|
|
3593
|
+
}
|
|
3594
|
+
update(data) {
|
|
3595
|
+
data = toBytes(data);
|
|
3596
|
+
exists(this);
|
|
3597
|
+
const b32 = u32(data);
|
|
3598
|
+
const left = data.length % BLOCK_SIZE;
|
|
3599
|
+
const blocks = Math.floor(data.length / BLOCK_SIZE);
|
|
3600
|
+
for (let i = 0; i < blocks; i++) {
|
|
3601
|
+
this._updateBlock(swapLE(b32[i * 4 + 3]), swapLE(b32[i * 4 + 2]), swapLE(b32[i * 4 + 1]), swapLE(b32[i * 4 + 0]));
|
|
3602
|
+
}
|
|
3603
|
+
if (left) {
|
|
3604
|
+
ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
|
|
3605
|
+
this._updateBlock(swapLE(ZEROS32[3]), swapLE(ZEROS32[2]), swapLE(ZEROS32[1]), swapLE(ZEROS32[0]));
|
|
3606
|
+
ZEROS32.fill(0);
|
|
3607
|
+
}
|
|
3608
|
+
return this;
|
|
3609
|
+
}
|
|
3610
|
+
digestInto(out) {
|
|
3611
|
+
exists(this);
|
|
3612
|
+
output(out, this);
|
|
3613
|
+
this.finished = true;
|
|
3614
|
+
const { s0, s1, s2, s3 } = this;
|
|
3615
|
+
const o32 = u32(out);
|
|
3616
|
+
o32[0] = s0;
|
|
3617
|
+
o32[1] = s1;
|
|
3618
|
+
o32[2] = s2;
|
|
3619
|
+
o32[3] = s3;
|
|
3620
|
+
return out.reverse();
|
|
3621
|
+
}
|
|
3622
|
+
};
|
|
3623
|
+
function wrapConstructorWithKey(hashCons) {
|
|
3624
|
+
const hashC = (msg, key) => hashCons(key, msg.length).update(toBytes(msg)).digest();
|
|
3625
|
+
const tmp = hashCons(new Uint8Array(16), 0);
|
|
3626
|
+
hashC.outputLen = tmp.outputLen;
|
|
3627
|
+
hashC.blockLen = tmp.blockLen;
|
|
3628
|
+
hashC.create = (key, expectedLength) => hashCons(key, expectedLength);
|
|
3629
|
+
return hashC;
|
|
3613
3630
|
}
|
|
3631
|
+
var ghash = wrapConstructorWithKey((key, expectedLength) => new GHASH(key, expectedLength));
|
|
3632
|
+
var polyval = wrapConstructorWithKey((key, expectedLength) => new Polyval(key, expectedLength));
|
|
3614
3633
|
|
|
3615
|
-
//
|
|
3616
|
-
|
|
3617
|
-
|
|
3634
|
+
// ../../node_modules/@noble/ciphers/esm/aes.js
|
|
3635
|
+
var BLOCK_SIZE2 = 16;
|
|
3636
|
+
var BLOCK_SIZE32 = 4;
|
|
3637
|
+
var EMPTY_BLOCK = new Uint8Array(BLOCK_SIZE2);
|
|
3638
|
+
var POLY2 = 283;
|
|
3639
|
+
function mul22(n) {
|
|
3640
|
+
return n << 1 ^ POLY2 & -(n >> 7);
|
|
3641
|
+
}
|
|
3642
|
+
function mul(a, b) {
|
|
3643
|
+
let res = 0;
|
|
3644
|
+
for (; b > 0; b >>= 1) {
|
|
3645
|
+
res ^= a & -(b & 1);
|
|
3646
|
+
a = mul22(a);
|
|
3647
|
+
}
|
|
3648
|
+
return res;
|
|
3649
|
+
}
|
|
3650
|
+
var sbox = /* @__PURE__ */ (() => {
|
|
3651
|
+
let t = new Uint8Array(256);
|
|
3652
|
+
for (let i = 0, x = 1; i < 256; i++, x ^= mul22(x))
|
|
3653
|
+
t[i] = x;
|
|
3654
|
+
const box = new Uint8Array(256);
|
|
3655
|
+
box[0] = 99;
|
|
3656
|
+
for (let i = 0; i < 255; i++) {
|
|
3657
|
+
let x = t[255 - i];
|
|
3658
|
+
x |= x << 8;
|
|
3659
|
+
box[t[i]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
|
|
3660
|
+
}
|
|
3661
|
+
return box;
|
|
3662
|
+
})();
|
|
3663
|
+
var invSbox = /* @__PURE__ */ sbox.map((_, j) => sbox.indexOf(j));
|
|
3664
|
+
var rotr32_8 = (n) => n << 24 | n >>> 8;
|
|
3665
|
+
var rotl32_8 = (n) => n << 8 | n >>> 24;
|
|
3666
|
+
function genTtable(sbox2, fn) {
|
|
3667
|
+
if (sbox2.length !== 256)
|
|
3668
|
+
throw new Error("Wrong sbox length");
|
|
3669
|
+
const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
|
|
3670
|
+
const T1 = T0.map(rotl32_8);
|
|
3671
|
+
const T2 = T1.map(rotl32_8);
|
|
3672
|
+
const T3 = T2.map(rotl32_8);
|
|
3673
|
+
const T01 = new Uint32Array(256 * 256);
|
|
3674
|
+
const T23 = new Uint32Array(256 * 256);
|
|
3675
|
+
const sbox22 = new Uint16Array(256 * 256);
|
|
3676
|
+
for (let i = 0; i < 256; i++) {
|
|
3677
|
+
for (let j = 0; j < 256; j++) {
|
|
3678
|
+
const idx = i * 256 + j;
|
|
3679
|
+
T01[idx] = T0[i] ^ T1[j];
|
|
3680
|
+
T23[idx] = T2[i] ^ T3[j];
|
|
3681
|
+
sbox22[idx] = sbox2[i] << 8 | sbox2[j];
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
|
|
3685
|
+
}
|
|
3686
|
+
var tableEncoding = /* @__PURE__ */ genTtable(sbox, (s) => mul(s, 3) << 24 | s << 16 | s << 8 | mul(s, 2));
|
|
3687
|
+
var tableDecoding = /* @__PURE__ */ genTtable(invSbox, (s) => mul(s, 11) << 24 | mul(s, 13) << 16 | mul(s, 9) << 8 | mul(s, 14));
|
|
3688
|
+
var xPowers = /* @__PURE__ */ (() => {
|
|
3689
|
+
const p = new Uint8Array(16);
|
|
3690
|
+
for (let i = 0, x = 1; i < 16; i++, x = mul22(x))
|
|
3691
|
+
p[i] = x;
|
|
3692
|
+
return p;
|
|
3693
|
+
})();
|
|
3694
|
+
function expandKeyLE(key) {
|
|
3695
|
+
bytes(key);
|
|
3696
|
+
const len = key.length;
|
|
3697
|
+
if (![16, 24, 32].includes(len))
|
|
3698
|
+
throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${len}`);
|
|
3699
|
+
const { sbox2 } = tableEncoding;
|
|
3700
|
+
const k32 = u32(key);
|
|
3701
|
+
const Nk = k32.length;
|
|
3702
|
+
const subByte = (n) => applySbox(sbox2, n, n, n, n);
|
|
3703
|
+
const xk = new Uint32Array(len + 28);
|
|
3704
|
+
xk.set(k32);
|
|
3705
|
+
for (let i = Nk; i < xk.length; i++) {
|
|
3706
|
+
let t = xk[i - 1];
|
|
3707
|
+
if (i % Nk === 0)
|
|
3708
|
+
t = subByte(rotr32_8(t)) ^ xPowers[i / Nk - 1];
|
|
3709
|
+
else if (Nk > 6 && i % Nk === 4)
|
|
3710
|
+
t = subByte(t);
|
|
3711
|
+
xk[i] = xk[i - Nk] ^ t;
|
|
3712
|
+
}
|
|
3713
|
+
return xk;
|
|
3714
|
+
}
|
|
3715
|
+
function expandKeyDecLE(key) {
|
|
3716
|
+
const encKey = expandKeyLE(key);
|
|
3717
|
+
const xk = encKey.slice();
|
|
3718
|
+
const Nk = encKey.length;
|
|
3719
|
+
const { sbox2 } = tableEncoding;
|
|
3720
|
+
const { T0, T1, T2, T3 } = tableDecoding;
|
|
3721
|
+
for (let i = 0; i < Nk; i += 4) {
|
|
3722
|
+
for (let j = 0; j < 4; j++)
|
|
3723
|
+
xk[i + j] = encKey[Nk - i - 4 + j];
|
|
3724
|
+
}
|
|
3725
|
+
encKey.fill(0);
|
|
3726
|
+
for (let i = 4; i < Nk - 4; i++) {
|
|
3727
|
+
const x = xk[i];
|
|
3728
|
+
const w = applySbox(sbox2, x, x, x, x);
|
|
3729
|
+
xk[i] = T0[w & 255] ^ T1[w >>> 8 & 255] ^ T2[w >>> 16 & 255] ^ T3[w >>> 24];
|
|
3730
|
+
}
|
|
3731
|
+
return xk;
|
|
3732
|
+
}
|
|
3733
|
+
function apply0123(T01, T23, s0, s1, s2, s3) {
|
|
3734
|
+
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
3735
|
+
}
|
|
3736
|
+
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
3737
|
+
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
3738
|
+
}
|
|
3739
|
+
function encrypt(xk, s0, s1, s2, s3) {
|
|
3740
|
+
const { sbox2, T01, T23 } = tableEncoding;
|
|
3741
|
+
let k = 0;
|
|
3742
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
3743
|
+
const rounds = xk.length / 4 - 2;
|
|
3744
|
+
for (let i = 0; i < rounds; i++) {
|
|
3745
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
3746
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
3747
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
3748
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
3749
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
3750
|
+
}
|
|
3751
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
|
|
3752
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
|
|
3753
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
|
|
3754
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
|
|
3755
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
3756
|
+
}
|
|
3757
|
+
function decrypt(xk, s0, s1, s2, s3) {
|
|
3758
|
+
const { sbox2, T01, T23 } = tableDecoding;
|
|
3759
|
+
let k = 0;
|
|
3760
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
3761
|
+
const rounds = xk.length / 4 - 2;
|
|
3762
|
+
for (let i = 0; i < rounds; i++) {
|
|
3763
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s3, s2, s1);
|
|
3764
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s0, s3, s2);
|
|
3765
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s1, s0, s3);
|
|
3766
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s2, s1, s0);
|
|
3767
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
3768
|
+
}
|
|
3769
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s3, s2, s1);
|
|
3770
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s0, s3, s2);
|
|
3771
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s1, s0, s3);
|
|
3772
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s2, s1, s0);
|
|
3773
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
3774
|
+
}
|
|
3775
|
+
function getDst(len, dst) {
|
|
3776
|
+
if (!dst)
|
|
3777
|
+
return new Uint8Array(len);
|
|
3778
|
+
bytes(dst);
|
|
3779
|
+
if (dst.length < len)
|
|
3780
|
+
throw new Error(`aes: wrong destination length, expected at least ${len}, got: ${dst.length}`);
|
|
3781
|
+
return dst;
|
|
3782
|
+
}
|
|
3783
|
+
function ctrCounter(xk, nonce, src, dst) {
|
|
3784
|
+
bytes(nonce, BLOCK_SIZE2);
|
|
3785
|
+
bytes(src);
|
|
3786
|
+
const srcLen = src.length;
|
|
3787
|
+
dst = getDst(srcLen, dst);
|
|
3788
|
+
const ctr4 = nonce;
|
|
3789
|
+
const c32 = u32(ctr4);
|
|
3790
|
+
let { s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]);
|
|
3791
|
+
const src32 = u32(src);
|
|
3792
|
+
const dst32 = u32(dst);
|
|
3793
|
+
for (let i = 0; i + 4 <= src32.length; i += 4) {
|
|
3794
|
+
dst32[i + 0] = src32[i + 0] ^ s0;
|
|
3795
|
+
dst32[i + 1] = src32[i + 1] ^ s1;
|
|
3796
|
+
dst32[i + 2] = src32[i + 2] ^ s2;
|
|
3797
|
+
dst32[i + 3] = src32[i + 3] ^ s3;
|
|
3798
|
+
let carry = 1;
|
|
3799
|
+
for (let i2 = ctr4.length - 1; i2 >= 0; i2--) {
|
|
3800
|
+
carry = carry + (ctr4[i2] & 255) | 0;
|
|
3801
|
+
ctr4[i2] = carry & 255;
|
|
3802
|
+
carry >>>= 8;
|
|
3803
|
+
}
|
|
3804
|
+
({ s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]));
|
|
3805
|
+
}
|
|
3806
|
+
const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
|
|
3807
|
+
if (start < srcLen) {
|
|
3808
|
+
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
3809
|
+
const buf = u8(b32);
|
|
3810
|
+
for (let i = start, pos = 0; i < srcLen; i++, pos++)
|
|
3811
|
+
dst[i] = src[i] ^ buf[pos];
|
|
3812
|
+
}
|
|
3813
|
+
return dst;
|
|
3814
|
+
}
|
|
3815
|
+
function ctr32(xk, isLE3, nonce, src, dst) {
|
|
3816
|
+
bytes(nonce, BLOCK_SIZE2);
|
|
3817
|
+
bytes(src);
|
|
3818
|
+
dst = getDst(src.length, dst);
|
|
3819
|
+
const ctr4 = nonce;
|
|
3820
|
+
const c32 = u32(ctr4);
|
|
3821
|
+
const view = createView(ctr4);
|
|
3822
|
+
const src32 = u32(src);
|
|
3823
|
+
const dst32 = u32(dst);
|
|
3824
|
+
const ctrPos = isLE3 ? 0 : 12;
|
|
3825
|
+
const srcLen = src.length;
|
|
3826
|
+
let ctrNum = view.getUint32(ctrPos, isLE3);
|
|
3827
|
+
let { s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]);
|
|
3828
|
+
for (let i = 0; i + 4 <= src32.length; i += 4) {
|
|
3829
|
+
dst32[i + 0] = src32[i + 0] ^ s0;
|
|
3830
|
+
dst32[i + 1] = src32[i + 1] ^ s1;
|
|
3831
|
+
dst32[i + 2] = src32[i + 2] ^ s2;
|
|
3832
|
+
dst32[i + 3] = src32[i + 3] ^ s3;
|
|
3833
|
+
ctrNum = ctrNum + 1 >>> 0;
|
|
3834
|
+
view.setUint32(ctrPos, ctrNum, isLE3);
|
|
3835
|
+
({ s0, s1, s2, s3 } = encrypt(xk, c32[0], c32[1], c32[2], c32[3]));
|
|
3836
|
+
}
|
|
3837
|
+
const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
|
|
3838
|
+
if (start < srcLen) {
|
|
3839
|
+
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
3840
|
+
const buf = u8(b32);
|
|
3841
|
+
for (let i = start, pos = 0; i < srcLen; i++, pos++)
|
|
3842
|
+
dst[i] = src[i] ^ buf[pos];
|
|
3843
|
+
}
|
|
3844
|
+
return dst;
|
|
3845
|
+
}
|
|
3846
|
+
var ctr = wrapCipher({ blockSize: 16, nonceLength: 16 }, function ctr2(key, nonce) {
|
|
3847
|
+
bytes(key);
|
|
3848
|
+
bytes(nonce, BLOCK_SIZE2);
|
|
3849
|
+
function processCtr(buf, dst) {
|
|
3850
|
+
const xk = expandKeyLE(key);
|
|
3851
|
+
const n = nonce.slice();
|
|
3852
|
+
const out = ctrCounter(xk, n, buf, dst);
|
|
3853
|
+
xk.fill(0);
|
|
3854
|
+
n.fill(0);
|
|
3855
|
+
return out;
|
|
3856
|
+
}
|
|
3618
3857
|
return {
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
chainId: "1",
|
|
3622
|
-
kind: "eth_sent",
|
|
3623
|
-
enabled: true,
|
|
3624
|
-
...override
|
|
3858
|
+
encrypt: (plaintext, dst) => processCtr(plaintext, dst),
|
|
3859
|
+
decrypt: (ciphertext, dst) => processCtr(ciphertext, dst)
|
|
3625
3860
|
};
|
|
3861
|
+
});
|
|
3862
|
+
function validateBlockDecrypt(data) {
|
|
3863
|
+
bytes(data);
|
|
3864
|
+
if (data.length % BLOCK_SIZE2 !== 0) {
|
|
3865
|
+
throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE2}`);
|
|
3866
|
+
}
|
|
3626
3867
|
}
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3868
|
+
function validateBlockEncrypt(plaintext, pcks5, dst) {
|
|
3869
|
+
let outLen = plaintext.length;
|
|
3870
|
+
const remaining = outLen % BLOCK_SIZE2;
|
|
3871
|
+
if (!pcks5 && remaining !== 0)
|
|
3872
|
+
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
3873
|
+
const b = u32(plaintext);
|
|
3874
|
+
if (pcks5) {
|
|
3875
|
+
let left = BLOCK_SIZE2 - remaining;
|
|
3876
|
+
if (!left)
|
|
3877
|
+
left = BLOCK_SIZE2;
|
|
3878
|
+
outLen = outLen + left;
|
|
3879
|
+
}
|
|
3880
|
+
const out = getDst(outLen, dst);
|
|
3881
|
+
const o = u32(out);
|
|
3882
|
+
return { b, o, out };
|
|
3883
|
+
}
|
|
3884
|
+
function validatePCKS(data, pcks5) {
|
|
3885
|
+
if (!pcks5)
|
|
3886
|
+
return data;
|
|
3887
|
+
const len = data.length;
|
|
3888
|
+
if (!len)
|
|
3889
|
+
throw new Error(`aes/pcks5: empty ciphertext not allowed`);
|
|
3890
|
+
const lastByte = data[len - 1];
|
|
3891
|
+
if (lastByte <= 0 || lastByte > 16)
|
|
3892
|
+
throw new Error(`aes/pcks5: wrong padding byte: ${lastByte}`);
|
|
3893
|
+
const out = data.subarray(0, -lastByte);
|
|
3894
|
+
for (let i = 0; i < lastByte; i++)
|
|
3895
|
+
if (data[len - i - 1] !== lastByte)
|
|
3896
|
+
throw new Error(`aes/pcks5: wrong padding`);
|
|
3897
|
+
return out;
|
|
3898
|
+
}
|
|
3899
|
+
function padPCKS(left) {
|
|
3900
|
+
const tmp = new Uint8Array(16);
|
|
3901
|
+
const tmp32 = u32(tmp);
|
|
3902
|
+
tmp.set(left);
|
|
3903
|
+
const paddingByte = BLOCK_SIZE2 - left.length;
|
|
3904
|
+
for (let i = BLOCK_SIZE2 - paddingByte; i < BLOCK_SIZE2; i++)
|
|
3905
|
+
tmp[i] = paddingByte;
|
|
3906
|
+
return tmp32;
|
|
3907
|
+
}
|
|
3908
|
+
var ecb = wrapCipher({ blockSize: 16 }, function ecb2(key, opts = {}) {
|
|
3909
|
+
bytes(key);
|
|
3910
|
+
const pcks5 = !opts.disablePadding;
|
|
3632
3911
|
return {
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
},
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3912
|
+
encrypt: (plaintext, dst) => {
|
|
3913
|
+
bytes(plaintext);
|
|
3914
|
+
const { b, o, out: _out } = validateBlockEncrypt(plaintext, pcks5, dst);
|
|
3915
|
+
const xk = expandKeyLE(key);
|
|
3916
|
+
let i = 0;
|
|
3917
|
+
for (; i + 4 <= b.length; ) {
|
|
3918
|
+
const { s0, s1, s2, s3 } = encrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
|
|
3919
|
+
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
3920
|
+
}
|
|
3921
|
+
if (pcks5) {
|
|
3922
|
+
const tmp32 = padPCKS(plaintext.subarray(i * 4));
|
|
3923
|
+
const { s0, s1, s2, s3 } = encrypt(xk, tmp32[0], tmp32[1], tmp32[2], tmp32[3]);
|
|
3924
|
+
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
3925
|
+
}
|
|
3926
|
+
xk.fill(0);
|
|
3927
|
+
return _out;
|
|
3645
3928
|
},
|
|
3646
|
-
|
|
3929
|
+
decrypt: (ciphertext, dst) => {
|
|
3930
|
+
validateBlockDecrypt(ciphertext);
|
|
3931
|
+
const xk = expandKeyDecLE(key);
|
|
3932
|
+
const out = getDst(ciphertext.length, dst);
|
|
3933
|
+
const b = u32(ciphertext);
|
|
3934
|
+
const o = u32(out);
|
|
3935
|
+
for (let i = 0; i + 4 <= b.length; ) {
|
|
3936
|
+
const { s0, s1, s2, s3 } = decrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
|
|
3937
|
+
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
3938
|
+
}
|
|
3939
|
+
xk.fill(0);
|
|
3940
|
+
return validatePCKS(out, pcks5);
|
|
3941
|
+
}
|
|
3647
3942
|
};
|
|
3648
|
-
}
|
|
3649
|
-
function
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3943
|
+
});
|
|
3944
|
+
var cbc = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cbc2(key, iv, opts = {}) {
|
|
3945
|
+
bytes(key);
|
|
3946
|
+
bytes(iv, 16);
|
|
3947
|
+
const pcks5 = !opts.disablePadding;
|
|
3948
|
+
return {
|
|
3949
|
+
encrypt: (plaintext, dst) => {
|
|
3950
|
+
const xk = expandKeyLE(key);
|
|
3951
|
+
const { b, o, out: _out } = validateBlockEncrypt(plaintext, pcks5, dst);
|
|
3952
|
+
const n32 = u32(iv);
|
|
3953
|
+
let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
|
|
3954
|
+
let i = 0;
|
|
3955
|
+
for (; i + 4 <= b.length; ) {
|
|
3956
|
+
s0 ^= b[i + 0], s1 ^= b[i + 1], s2 ^= b[i + 2], s3 ^= b[i + 3];
|
|
3957
|
+
({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
|
|
3958
|
+
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
3959
|
+
}
|
|
3960
|
+
if (pcks5) {
|
|
3961
|
+
const tmp32 = padPCKS(plaintext.subarray(i * 4));
|
|
3962
|
+
s0 ^= tmp32[0], s1 ^= tmp32[1], s2 ^= tmp32[2], s3 ^= tmp32[3];
|
|
3963
|
+
({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
|
|
3964
|
+
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
3965
|
+
}
|
|
3966
|
+
xk.fill(0);
|
|
3967
|
+
return _out;
|
|
3968
|
+
},
|
|
3969
|
+
decrypt: (ciphertext, dst) => {
|
|
3970
|
+
validateBlockDecrypt(ciphertext);
|
|
3971
|
+
const xk = expandKeyDecLE(key);
|
|
3972
|
+
const n32 = u32(iv);
|
|
3973
|
+
const out = getDst(ciphertext.length, dst);
|
|
3974
|
+
const b = u32(ciphertext);
|
|
3975
|
+
const o = u32(out);
|
|
3976
|
+
let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
|
|
3977
|
+
for (let i = 0; i + 4 <= b.length; ) {
|
|
3978
|
+
const ps0 = s0, ps1 = s1, ps2 = s2, ps3 = s3;
|
|
3979
|
+
s0 = b[i + 0], s1 = b[i + 1], s2 = b[i + 2], s3 = b[i + 3];
|
|
3980
|
+
const { s0: o0, s1: o1, s2: o2, s3: o3 } = decrypt(xk, s0, s1, s2, s3);
|
|
3981
|
+
o[i++] = o0 ^ ps0, o[i++] = o1 ^ ps1, o[i++] = o2 ^ ps2, o[i++] = o3 ^ ps3;
|
|
3982
|
+
}
|
|
3983
|
+
xk.fill(0);
|
|
3984
|
+
return validatePCKS(out, pcks5);
|
|
3654
3985
|
}
|
|
3655
3986
|
};
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3987
|
+
});
|
|
3988
|
+
var cfb = wrapCipher({ blockSize: 16, nonceLength: 16 }, function cfb2(key, iv) {
|
|
3989
|
+
bytes(key);
|
|
3990
|
+
bytes(iv, 16);
|
|
3991
|
+
function processCfb(src, isEncrypt, dst) {
|
|
3992
|
+
const xk = expandKeyLE(key);
|
|
3993
|
+
const srcLen = src.length;
|
|
3994
|
+
dst = getDst(srcLen, dst);
|
|
3995
|
+
const src32 = u32(src);
|
|
3996
|
+
const dst32 = u32(dst);
|
|
3997
|
+
const next32 = isEncrypt ? dst32 : src32;
|
|
3998
|
+
const n32 = u32(iv);
|
|
3999
|
+
let s0 = n32[0], s1 = n32[1], s2 = n32[2], s3 = n32[3];
|
|
4000
|
+
for (let i = 0; i + 4 <= src32.length; ) {
|
|
4001
|
+
const { s0: e0, s1: e1, s2: e2, s3: e3 } = encrypt(xk, s0, s1, s2, s3);
|
|
4002
|
+
dst32[i + 0] = src32[i + 0] ^ e0;
|
|
4003
|
+
dst32[i + 1] = src32[i + 1] ^ e1;
|
|
4004
|
+
dst32[i + 2] = src32[i + 2] ^ e2;
|
|
4005
|
+
dst32[i + 3] = src32[i + 3] ^ e3;
|
|
4006
|
+
s0 = next32[i++], s1 = next32[i++], s2 = next32[i++], s3 = next32[i++];
|
|
3668
4007
|
}
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
function createMockFullUserStorage(props = {}) {
|
|
3677
|
-
return initializeUserStorage(
|
|
3678
|
-
[{ address: props.address ?? MOCK_USER_STORAGE_ACCOUNT }],
|
|
3679
|
-
props.triggersEnabled ?? true
|
|
3680
|
-
);
|
|
3681
|
-
}
|
|
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
|
-
}
|
|
4008
|
+
const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
|
|
4009
|
+
if (start < srcLen) {
|
|
4010
|
+
({ s0, s1, s2, s3 } = encrypt(xk, s0, s1, s2, s3));
|
|
4011
|
+
const buf = u8(new Uint32Array([s0, s1, s2, s3]));
|
|
4012
|
+
for (let i = start, pos = 0; i < srcLen; i++, pos++)
|
|
4013
|
+
dst[i] = src[i] ^ buf[pos];
|
|
4014
|
+
buf.fill(0);
|
|
3708
4015
|
}
|
|
4016
|
+
xk.fill(0);
|
|
4017
|
+
return dst;
|
|
4018
|
+
}
|
|
4019
|
+
return {
|
|
4020
|
+
encrypt: (plaintext, dst) => processCfb(plaintext, true, dst),
|
|
4021
|
+
decrypt: (ciphertext, dst) => processCfb(ciphertext, false, dst)
|
|
3709
4022
|
};
|
|
3710
|
-
|
|
4023
|
+
});
|
|
4024
|
+
function computeTag(fn, isLE3, key, data, AAD) {
|
|
4025
|
+
const h = fn.create(key, data.length + (AAD?.length || 0));
|
|
4026
|
+
if (AAD)
|
|
4027
|
+
h.update(AAD);
|
|
4028
|
+
h.update(data);
|
|
4029
|
+
const num = new Uint8Array(16);
|
|
4030
|
+
const view = createView(num);
|
|
4031
|
+
if (AAD)
|
|
4032
|
+
setBigUint64(view, 0, BigInt(AAD.length * 8), isLE3);
|
|
4033
|
+
setBigUint64(view, 8, BigInt(data.length * 8), isLE3);
|
|
4034
|
+
h.update(num);
|
|
4035
|
+
return h.digest();
|
|
3711
4036
|
}
|
|
3712
|
-
function
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
4037
|
+
var gcm = wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16 }, function gcm2(key, nonce, AAD) {
|
|
4038
|
+
bytes(nonce);
|
|
4039
|
+
if (nonce.length === 0)
|
|
4040
|
+
throw new Error("aes/gcm: empty nonce");
|
|
4041
|
+
const tagLength = 16;
|
|
4042
|
+
function _computeTag(authKey, tagMask, data) {
|
|
4043
|
+
const tag = computeTag(ghash, false, authKey, data, AAD);
|
|
4044
|
+
for (let i = 0; i < tagMask.length; i++)
|
|
4045
|
+
tag[i] ^= tagMask[i];
|
|
4046
|
+
return tag;
|
|
4047
|
+
}
|
|
4048
|
+
function deriveKeys() {
|
|
4049
|
+
const xk = expandKeyLE(key);
|
|
4050
|
+
const authKey = EMPTY_BLOCK.slice();
|
|
4051
|
+
const counter = EMPTY_BLOCK.slice();
|
|
4052
|
+
ctr32(xk, false, counter, counter, authKey);
|
|
4053
|
+
if (nonce.length === 12) {
|
|
4054
|
+
counter.set(nonce);
|
|
4055
|
+
} else {
|
|
4056
|
+
const nonceLen = EMPTY_BLOCK.slice();
|
|
4057
|
+
const view = createView(nonceLen);
|
|
4058
|
+
setBigUint64(view, 8, BigInt(nonce.length * 8), false);
|
|
4059
|
+
ghash.create(authKey).update(nonce).update(nonceLen).digestInto(counter);
|
|
4060
|
+
}
|
|
4061
|
+
const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
|
|
4062
|
+
return { xk, authKey, counter, tagMask };
|
|
4063
|
+
}
|
|
4064
|
+
return {
|
|
4065
|
+
encrypt: (plaintext) => {
|
|
4066
|
+
bytes(plaintext);
|
|
4067
|
+
const { xk, authKey, counter, tagMask } = deriveKeys();
|
|
4068
|
+
const out = new Uint8Array(plaintext.length + tagLength);
|
|
4069
|
+
ctr32(xk, false, counter, plaintext, out);
|
|
4070
|
+
const tag = _computeTag(authKey, tagMask, out.subarray(0, out.length - tagLength));
|
|
4071
|
+
out.set(tag, plaintext.length);
|
|
4072
|
+
xk.fill(0);
|
|
4073
|
+
return out;
|
|
4074
|
+
},
|
|
4075
|
+
decrypt: (ciphertext) => {
|
|
4076
|
+
bytes(ciphertext);
|
|
4077
|
+
if (ciphertext.length < tagLength)
|
|
4078
|
+
throw new Error(`aes/gcm: ciphertext less than tagLen (${tagLength})`);
|
|
4079
|
+
const { xk, authKey, counter, tagMask } = deriveKeys();
|
|
4080
|
+
const data = ciphertext.subarray(0, -tagLength);
|
|
4081
|
+
const passedTag = ciphertext.subarray(-tagLength);
|
|
4082
|
+
const tag = _computeTag(authKey, tagMask, data);
|
|
4083
|
+
if (!equalBytes(tag, passedTag))
|
|
4084
|
+
throw new Error("aes/gcm: invalid ghash tag");
|
|
4085
|
+
const out = ctr32(xk, false, counter, data);
|
|
4086
|
+
authKey.fill(0);
|
|
4087
|
+
tagMask.fill(0);
|
|
4088
|
+
xk.fill(0);
|
|
4089
|
+
return out;
|
|
4090
|
+
}
|
|
4091
|
+
};
|
|
4092
|
+
});
|
|
4093
|
+
var limit = (name, min, max) => (value) => {
|
|
4094
|
+
if (!Number.isSafeInteger(value) || min > value || value > max)
|
|
4095
|
+
throw new Error(`${name}: invalid value=${value}, must be [${min}..${max}]`);
|
|
4096
|
+
};
|
|
4097
|
+
var siv = wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16 }, function siv2(key, nonce, AAD) {
|
|
4098
|
+
const tagLength = 16;
|
|
4099
|
+
const AAD_LIMIT = limit("AAD", 0, 2 ** 36);
|
|
4100
|
+
const PLAIN_LIMIT = limit("plaintext", 0, 2 ** 36);
|
|
4101
|
+
const NONCE_LIMIT = limit("nonce", 12, 12);
|
|
4102
|
+
const CIPHER_LIMIT = limit("ciphertext", 16, 2 ** 36 + 16);
|
|
4103
|
+
bytes(nonce);
|
|
4104
|
+
NONCE_LIMIT(nonce.length);
|
|
4105
|
+
if (AAD) {
|
|
4106
|
+
bytes(AAD);
|
|
4107
|
+
AAD_LIMIT(AAD.length);
|
|
4108
|
+
}
|
|
4109
|
+
function deriveKeys() {
|
|
4110
|
+
const len = key.length;
|
|
4111
|
+
if (len !== 16 && len !== 24 && len !== 32)
|
|
4112
|
+
throw new Error(`key length must be 16, 24 or 32 bytes, got: ${len} bytes`);
|
|
4113
|
+
const xk = expandKeyLE(key);
|
|
4114
|
+
const encKey = new Uint8Array(len);
|
|
4115
|
+
const authKey = new Uint8Array(16);
|
|
4116
|
+
const n32 = u32(nonce);
|
|
4117
|
+
let s0 = 0, s1 = n32[0], s2 = n32[1], s3 = n32[2];
|
|
4118
|
+
let counter = 0;
|
|
4119
|
+
for (const derivedKey of [authKey, encKey].map(u32)) {
|
|
4120
|
+
const d32 = u32(derivedKey);
|
|
4121
|
+
for (let i = 0; i < d32.length; i += 2) {
|
|
4122
|
+
const { s0: o0, s1: o1 } = encrypt(xk, s0, s1, s2, s3);
|
|
4123
|
+
d32[i + 0] = o0;
|
|
4124
|
+
d32[i + 1] = o1;
|
|
4125
|
+
s0 = ++counter;
|
|
3735
4126
|
}
|
|
3736
4127
|
}
|
|
4128
|
+
xk.fill(0);
|
|
4129
|
+
return { authKey, encKey: expandKeyLE(encKey) };
|
|
4130
|
+
}
|
|
4131
|
+
function _computeTag(encKey, authKey, data) {
|
|
4132
|
+
const tag = computeTag(polyval, true, authKey, data, AAD);
|
|
4133
|
+
for (let i = 0; i < 12; i++)
|
|
4134
|
+
tag[i] ^= nonce[i];
|
|
4135
|
+
tag[15] &= 127;
|
|
4136
|
+
const t32 = u32(tag);
|
|
4137
|
+
let s0 = t32[0], s1 = t32[1], s2 = t32[2], s3 = t32[3];
|
|
4138
|
+
({ s0, s1, s2, s3 } = encrypt(encKey, s0, s1, s2, s3));
|
|
4139
|
+
t32[0] = s0, t32[1] = s1, t32[2] = s2, t32[3] = s3;
|
|
4140
|
+
return tag;
|
|
4141
|
+
}
|
|
4142
|
+
function processSiv(encKey, tag, input) {
|
|
4143
|
+
let block = tag.slice();
|
|
4144
|
+
block[15] |= 128;
|
|
4145
|
+
return ctr32(encKey, true, block, input);
|
|
4146
|
+
}
|
|
4147
|
+
return {
|
|
4148
|
+
encrypt: (plaintext) => {
|
|
4149
|
+
bytes(plaintext);
|
|
4150
|
+
PLAIN_LIMIT(plaintext.length);
|
|
4151
|
+
const { encKey, authKey } = deriveKeys();
|
|
4152
|
+
const tag = _computeTag(encKey, authKey, plaintext);
|
|
4153
|
+
const out = new Uint8Array(plaintext.length + tagLength);
|
|
4154
|
+
out.set(tag, plaintext.length);
|
|
4155
|
+
out.set(processSiv(encKey, tag, plaintext));
|
|
4156
|
+
encKey.fill(0);
|
|
4157
|
+
authKey.fill(0);
|
|
4158
|
+
return out;
|
|
4159
|
+
},
|
|
4160
|
+
decrypt: (ciphertext) => {
|
|
4161
|
+
bytes(ciphertext);
|
|
4162
|
+
CIPHER_LIMIT(ciphertext.length);
|
|
4163
|
+
const tag = ciphertext.subarray(-tagLength);
|
|
4164
|
+
const { encKey, authKey } = deriveKeys();
|
|
4165
|
+
const plaintext = processSiv(encKey, tag, ciphertext.subarray(0, -tagLength));
|
|
4166
|
+
const expectedTag = _computeTag(encKey, authKey, plaintext);
|
|
4167
|
+
encKey.fill(0);
|
|
4168
|
+
authKey.fill(0);
|
|
4169
|
+
if (!equalBytes(tag, expectedTag))
|
|
4170
|
+
throw new Error("invalid polyval tag");
|
|
4171
|
+
return plaintext;
|
|
4172
|
+
}
|
|
3737
4173
|
};
|
|
3738
|
-
|
|
4174
|
+
});
|
|
4175
|
+
|
|
4176
|
+
// ../../node_modules/@noble/ciphers/esm/crypto.js
|
|
4177
|
+
var cr = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
4178
|
+
function randomBytes(bytesLength = 32) {
|
|
4179
|
+
if (cr && typeof cr.getRandomValues === "function")
|
|
4180
|
+
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
4181
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
4182
|
+
}
|
|
4183
|
+
function getWebcryptoSubtle() {
|
|
4184
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null)
|
|
4185
|
+
return cr.subtle;
|
|
4186
|
+
throw new Error("crypto.subtle must be defined");
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
// ../../node_modules/@noble/ciphers/esm/webcrypto.js
|
|
4190
|
+
var utils = {
|
|
4191
|
+
async encrypt(key, keyParams, cryptParams, plaintext) {
|
|
4192
|
+
const cr2 = getWebcryptoSubtle();
|
|
4193
|
+
const iKey = await cr2.importKey("raw", key, keyParams, true, ["encrypt"]);
|
|
4194
|
+
const ciphertext = await cr2.encrypt(cryptParams, iKey, plaintext);
|
|
4195
|
+
return new Uint8Array(ciphertext);
|
|
4196
|
+
},
|
|
4197
|
+
async decrypt(key, keyParams, cryptParams, ciphertext) {
|
|
4198
|
+
const cr2 = getWebcryptoSubtle();
|
|
4199
|
+
const iKey = await cr2.importKey("raw", key, keyParams, true, ["decrypt"]);
|
|
4200
|
+
const plaintext = await cr2.decrypt(cryptParams, iKey, ciphertext);
|
|
4201
|
+
return new Uint8Array(plaintext);
|
|
4202
|
+
}
|
|
4203
|
+
};
|
|
4204
|
+
var mode = {
|
|
4205
|
+
CBC: "AES-CBC",
|
|
4206
|
+
CTR: "AES-CTR",
|
|
4207
|
+
GCM: "AES-GCM"
|
|
4208
|
+
};
|
|
4209
|
+
function getCryptParams(algo, nonce, AAD) {
|
|
4210
|
+
if (algo === mode.CBC)
|
|
4211
|
+
return { name: mode.CBC, iv: nonce };
|
|
4212
|
+
if (algo === mode.CTR)
|
|
4213
|
+
return { name: mode.CTR, counter: nonce, length: 64 };
|
|
4214
|
+
if (algo === mode.GCM)
|
|
4215
|
+
return { name: mode.GCM, iv: nonce, additionalData: AAD };
|
|
4216
|
+
throw new Error("unknown aes block mode");
|
|
3739
4217
|
}
|
|
3740
|
-
function
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
address: "0x881D40237659C251811CEC9c364ef91dC08D300C",
|
|
3752
|
-
data: {
|
|
3753
|
-
kind: "erc20_sent",
|
|
3754
|
-
network_fee: {
|
|
3755
|
-
gas_price: "207806259583",
|
|
3756
|
-
native_token_price_in_usd: "0.83"
|
|
4218
|
+
function generate(algo) {
|
|
4219
|
+
return (key, nonce, AAD) => {
|
|
4220
|
+
bytes(key);
|
|
4221
|
+
bytes(nonce);
|
|
4222
|
+
const keyParams = { name: algo, length: key.length * 8 };
|
|
4223
|
+
const cryptParams = getCryptParams(algo, nonce, AAD);
|
|
4224
|
+
return {
|
|
4225
|
+
// keyLength,
|
|
4226
|
+
encrypt(plaintext) {
|
|
4227
|
+
bytes(plaintext);
|
|
4228
|
+
return utils.encrypt(key, keyParams, cryptParams, plaintext);
|
|
3757
4229
|
},
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
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"
|
|
4230
|
+
decrypt(ciphertext) {
|
|
4231
|
+
bytes(ciphertext);
|
|
4232
|
+
return utils.decrypt(key, keyParams, cryptParams, ciphertext);
|
|
3768
4233
|
}
|
|
3769
|
-
}
|
|
4234
|
+
};
|
|
3770
4235
|
};
|
|
3771
|
-
return mockNotification;
|
|
3772
4236
|
}
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
4237
|
+
var cbc3 = generate(mode.CBC);
|
|
4238
|
+
var ctr3 = generate(mode.CTR);
|
|
4239
|
+
var gcm3 = generate(mode.GCM);
|
|
4240
|
+
|
|
4241
|
+
// ../../node_modules/@noble/hashes/esm/_assert.js
|
|
4242
|
+
function number2(n) {
|
|
4243
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
4244
|
+
throw new Error(`positive integer expected, not ${n}`);
|
|
4245
|
+
}
|
|
4246
|
+
function isBytes2(a) {
|
|
4247
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
4248
|
+
}
|
|
4249
|
+
function bytes2(b, ...lengths) {
|
|
4250
|
+
if (!isBytes2(b))
|
|
4251
|
+
throw new Error("Uint8Array expected");
|
|
4252
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
4253
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
4254
|
+
}
|
|
4255
|
+
function hash(h) {
|
|
4256
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
4257
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
4258
|
+
number2(h.outputLen);
|
|
4259
|
+
number2(h.blockLen);
|
|
4260
|
+
}
|
|
4261
|
+
function exists2(instance, checkFinished = true) {
|
|
4262
|
+
if (instance.destroyed)
|
|
4263
|
+
throw new Error("Hash instance has been destroyed");
|
|
4264
|
+
if (checkFinished && instance.finished)
|
|
4265
|
+
throw new Error("Hash#digest() has already been called");
|
|
4266
|
+
}
|
|
4267
|
+
function output2(out, instance) {
|
|
4268
|
+
bytes2(out);
|
|
4269
|
+
const min = instance.outputLen;
|
|
4270
|
+
if (out.length < min) {
|
|
4271
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
|
|
4275
|
+
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
4276
|
+
var u322 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
4277
|
+
var createView2 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
4278
|
+
var rotr = (word, shift) => word << 32 - shift | word >>> shift;
|
|
4279
|
+
var rotl = (word, shift) => word << shift | word >>> 32 - shift >>> 0;
|
|
4280
|
+
var isLE2 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
4281
|
+
var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
4282
|
+
function byteSwap32(arr) {
|
|
4283
|
+
for (let i = 0; i < arr.length; i++) {
|
|
4284
|
+
arr[i] = byteSwap(arr[i]);
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
4288
|
+
function bytesToHex(bytes3) {
|
|
4289
|
+
bytes2(bytes3);
|
|
4290
|
+
let hex = "";
|
|
4291
|
+
for (let i = 0; i < bytes3.length; i++) {
|
|
4292
|
+
hex += hexes[bytes3[i]];
|
|
4293
|
+
}
|
|
4294
|
+
return hex;
|
|
4295
|
+
}
|
|
4296
|
+
function utf8ToBytes2(str) {
|
|
4297
|
+
if (typeof str !== "string")
|
|
4298
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
4299
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
4300
|
+
}
|
|
4301
|
+
function toBytes2(data) {
|
|
4302
|
+
if (typeof data === "string")
|
|
4303
|
+
data = utf8ToBytes2(data);
|
|
4304
|
+
bytes2(data);
|
|
4305
|
+
return data;
|
|
4306
|
+
}
|
|
4307
|
+
function concatBytes(...arrays) {
|
|
4308
|
+
let sum = 0;
|
|
4309
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
4310
|
+
const a = arrays[i];
|
|
4311
|
+
bytes2(a);
|
|
4312
|
+
sum += a.length;
|
|
4313
|
+
}
|
|
4314
|
+
const res = new Uint8Array(sum);
|
|
4315
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
4316
|
+
const a = arrays[i];
|
|
4317
|
+
res.set(a, pad);
|
|
4318
|
+
pad += a.length;
|
|
4319
|
+
}
|
|
4320
|
+
return res;
|
|
4321
|
+
}
|
|
4322
|
+
var Hash = class {
|
|
4323
|
+
// Safe version that clones internal state
|
|
4324
|
+
clone() {
|
|
4325
|
+
return this._cloneInto();
|
|
4326
|
+
}
|
|
4327
|
+
};
|
|
4328
|
+
var toStr = {}.toString;
|
|
4329
|
+
function checkOpts(defaults, opts) {
|
|
4330
|
+
if (opts !== void 0 && toStr.call(opts) !== "[object Object]")
|
|
4331
|
+
throw new Error("Options should be object or undefined");
|
|
4332
|
+
const merged = Object.assign(defaults, opts);
|
|
4333
|
+
return merged;
|
|
4334
|
+
}
|
|
4335
|
+
function wrapConstructor(hashCons) {
|
|
4336
|
+
const hashC = (msg) => hashCons().update(toBytes2(msg)).digest();
|
|
4337
|
+
const tmp = hashCons();
|
|
4338
|
+
hashC.outputLen = tmp.outputLen;
|
|
4339
|
+
hashC.blockLen = tmp.blockLen;
|
|
4340
|
+
hashC.create = () => hashCons();
|
|
4341
|
+
return hashC;
|
|
4342
|
+
}
|
|
4343
|
+
|
|
4344
|
+
// ../../node_modules/@noble/hashes/esm/hmac.js
|
|
4345
|
+
var HMAC = class extends Hash {
|
|
4346
|
+
constructor(hash2, _key) {
|
|
4347
|
+
super();
|
|
4348
|
+
this.finished = false;
|
|
4349
|
+
this.destroyed = false;
|
|
4350
|
+
hash(hash2);
|
|
4351
|
+
const key = toBytes2(_key);
|
|
4352
|
+
this.iHash = hash2.create();
|
|
4353
|
+
if (typeof this.iHash.update !== "function")
|
|
4354
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
4355
|
+
this.blockLen = this.iHash.blockLen;
|
|
4356
|
+
this.outputLen = this.iHash.outputLen;
|
|
4357
|
+
const blockLen = this.blockLen;
|
|
4358
|
+
const pad = new Uint8Array(blockLen);
|
|
4359
|
+
pad.set(key.length > blockLen ? hash2.create().update(key).digest() : key);
|
|
4360
|
+
for (let i = 0; i < pad.length; i++)
|
|
4361
|
+
pad[i] ^= 54;
|
|
4362
|
+
this.iHash.update(pad);
|
|
4363
|
+
this.oHash = hash2.create();
|
|
4364
|
+
for (let i = 0; i < pad.length; i++)
|
|
4365
|
+
pad[i] ^= 54 ^ 92;
|
|
4366
|
+
this.oHash.update(pad);
|
|
4367
|
+
pad.fill(0);
|
|
4368
|
+
}
|
|
4369
|
+
update(buf) {
|
|
4370
|
+
exists2(this);
|
|
4371
|
+
this.iHash.update(buf);
|
|
4372
|
+
return this;
|
|
4373
|
+
}
|
|
4374
|
+
digestInto(out) {
|
|
4375
|
+
exists2(this);
|
|
4376
|
+
bytes2(out, this.outputLen);
|
|
4377
|
+
this.finished = true;
|
|
4378
|
+
this.iHash.digestInto(out);
|
|
4379
|
+
this.oHash.update(out);
|
|
4380
|
+
this.oHash.digestInto(out);
|
|
4381
|
+
this.destroy();
|
|
4382
|
+
}
|
|
4383
|
+
digest() {
|
|
4384
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
4385
|
+
this.digestInto(out);
|
|
4386
|
+
return out;
|
|
4387
|
+
}
|
|
4388
|
+
_cloneInto(to) {
|
|
4389
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
4390
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
4391
|
+
to = to;
|
|
4392
|
+
to.finished = finished;
|
|
4393
|
+
to.destroyed = destroyed;
|
|
4394
|
+
to.blockLen = blockLen;
|
|
4395
|
+
to.outputLen = outputLen;
|
|
4396
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
4397
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
4398
|
+
return to;
|
|
4399
|
+
}
|
|
4400
|
+
destroy() {
|
|
4401
|
+
this.destroyed = true;
|
|
4402
|
+
this.oHash.destroy();
|
|
4403
|
+
this.iHash.destroy();
|
|
4404
|
+
}
|
|
4405
|
+
};
|
|
4406
|
+
var hmac = (hash2, key, message) => new HMAC(hash2, key).update(message).digest();
|
|
4407
|
+
hmac.create = (hash2, key) => new HMAC(hash2, key);
|
|
4408
|
+
|
|
4409
|
+
// ../../node_modules/@noble/hashes/esm/pbkdf2.js
|
|
4410
|
+
function pbkdf2Init(hash2, _password, _salt, _opts) {
|
|
4411
|
+
hash(hash2);
|
|
4412
|
+
const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
|
|
4413
|
+
const { c, dkLen, asyncTick } = opts;
|
|
4414
|
+
number2(c);
|
|
4415
|
+
number2(dkLen);
|
|
4416
|
+
number2(asyncTick);
|
|
4417
|
+
if (c < 1)
|
|
4418
|
+
throw new Error("PBKDF2: iterations (c) should be >= 1");
|
|
4419
|
+
const password = toBytes2(_password);
|
|
4420
|
+
const salt = toBytes2(_salt);
|
|
4421
|
+
const DK = new Uint8Array(dkLen);
|
|
4422
|
+
const PRF = hmac.create(hash2, password);
|
|
4423
|
+
const PRFSalt = PRF._cloneInto().update(salt);
|
|
4424
|
+
return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
|
|
4425
|
+
}
|
|
4426
|
+
function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
|
|
4427
|
+
PRF.destroy();
|
|
4428
|
+
PRFSalt.destroy();
|
|
4429
|
+
if (prfW)
|
|
4430
|
+
prfW.destroy();
|
|
4431
|
+
u.fill(0);
|
|
4432
|
+
return DK;
|
|
4433
|
+
}
|
|
4434
|
+
function pbkdf2(hash2, password, salt, opts) {
|
|
4435
|
+
const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash2, password, salt, opts);
|
|
4436
|
+
let prfW;
|
|
4437
|
+
const arr = new Uint8Array(4);
|
|
4438
|
+
const view = createView2(arr);
|
|
4439
|
+
const u = new Uint8Array(PRF.outputLen);
|
|
4440
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
4441
|
+
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
4442
|
+
view.setInt32(0, ti, false);
|
|
4443
|
+
(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
|
|
4444
|
+
Ti.set(u.subarray(0, Ti.length));
|
|
4445
|
+
for (let ui = 1; ui < c; ui++) {
|
|
4446
|
+
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
4447
|
+
for (let i = 0; i < Ti.length; i++)
|
|
4448
|
+
Ti[i] ^= u[i];
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
// ../../node_modules/@noble/hashes/esm/_md.js
|
|
4455
|
+
function setBigUint642(view, byteOffset, value, isLE3) {
|
|
4456
|
+
if (typeof view.setBigUint64 === "function")
|
|
4457
|
+
return view.setBigUint64(byteOffset, value, isLE3);
|
|
4458
|
+
const _32n = BigInt(32);
|
|
4459
|
+
const _u32_max = BigInt(4294967295);
|
|
4460
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
4461
|
+
const wl = Number(value & _u32_max);
|
|
4462
|
+
const h = isLE3 ? 4 : 0;
|
|
4463
|
+
const l = isLE3 ? 0 : 4;
|
|
4464
|
+
view.setUint32(byteOffset + h, wh, isLE3);
|
|
4465
|
+
view.setUint32(byteOffset + l, wl, isLE3);
|
|
4466
|
+
}
|
|
4467
|
+
var Chi = (a, b, c) => a & b ^ ~a & c;
|
|
4468
|
+
var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
|
|
4469
|
+
var HashMD = class extends Hash {
|
|
4470
|
+
constructor(blockLen, outputLen, padOffset, isLE3) {
|
|
4471
|
+
super();
|
|
4472
|
+
this.blockLen = blockLen;
|
|
4473
|
+
this.outputLen = outputLen;
|
|
4474
|
+
this.padOffset = padOffset;
|
|
4475
|
+
this.isLE = isLE3;
|
|
4476
|
+
this.finished = false;
|
|
4477
|
+
this.length = 0;
|
|
4478
|
+
this.pos = 0;
|
|
4479
|
+
this.destroyed = false;
|
|
4480
|
+
this.buffer = new Uint8Array(blockLen);
|
|
4481
|
+
this.view = createView2(this.buffer);
|
|
4482
|
+
}
|
|
4483
|
+
update(data) {
|
|
4484
|
+
exists2(this);
|
|
4485
|
+
const { view, buffer, blockLen } = this;
|
|
4486
|
+
data = toBytes2(data);
|
|
4487
|
+
const len = data.length;
|
|
4488
|
+
for (let pos = 0; pos < len; ) {
|
|
4489
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
4490
|
+
if (take === blockLen) {
|
|
4491
|
+
const dataView = createView2(data);
|
|
4492
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
4493
|
+
this.process(dataView, pos);
|
|
4494
|
+
continue;
|
|
4495
|
+
}
|
|
4496
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
4497
|
+
this.pos += take;
|
|
4498
|
+
pos += take;
|
|
4499
|
+
if (this.pos === blockLen) {
|
|
4500
|
+
this.process(view, 0);
|
|
4501
|
+
this.pos = 0;
|
|
3801
4502
|
}
|
|
3802
4503
|
}
|
|
4504
|
+
this.length += data.length;
|
|
4505
|
+
this.roundClean();
|
|
4506
|
+
return this;
|
|
4507
|
+
}
|
|
4508
|
+
digestInto(out) {
|
|
4509
|
+
exists2(this);
|
|
4510
|
+
output2(out, this);
|
|
4511
|
+
this.finished = true;
|
|
4512
|
+
const { buffer, view, blockLen, isLE: isLE3 } = this;
|
|
4513
|
+
let { pos } = this;
|
|
4514
|
+
buffer[pos++] = 128;
|
|
4515
|
+
this.buffer.subarray(pos).fill(0);
|
|
4516
|
+
if (this.padOffset > blockLen - pos) {
|
|
4517
|
+
this.process(view, 0);
|
|
4518
|
+
pos = 0;
|
|
4519
|
+
}
|
|
4520
|
+
for (let i = pos; i < blockLen; i++)
|
|
4521
|
+
buffer[i] = 0;
|
|
4522
|
+
setBigUint642(view, blockLen - 8, BigInt(this.length * 8), isLE3);
|
|
4523
|
+
this.process(view, 0);
|
|
4524
|
+
const oview = createView2(out);
|
|
4525
|
+
const len = this.outputLen;
|
|
4526
|
+
if (len % 4)
|
|
4527
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
4528
|
+
const outLen = len / 4;
|
|
4529
|
+
const state = this.get();
|
|
4530
|
+
if (outLen > state.length)
|
|
4531
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
4532
|
+
for (let i = 0; i < outLen; i++)
|
|
4533
|
+
oview.setUint32(4 * i, state[i], isLE3);
|
|
4534
|
+
}
|
|
4535
|
+
digest() {
|
|
4536
|
+
const { buffer, outputLen } = this;
|
|
4537
|
+
this.digestInto(buffer);
|
|
4538
|
+
const res = buffer.slice(0, outputLen);
|
|
4539
|
+
this.destroy();
|
|
4540
|
+
return res;
|
|
4541
|
+
}
|
|
4542
|
+
_cloneInto(to) {
|
|
4543
|
+
to || (to = new this.constructor());
|
|
4544
|
+
to.set(...this.get());
|
|
4545
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
4546
|
+
to.length = length;
|
|
4547
|
+
to.pos = pos;
|
|
4548
|
+
to.finished = finished;
|
|
4549
|
+
to.destroyed = destroyed;
|
|
4550
|
+
if (length % blockLen)
|
|
4551
|
+
to.buffer.set(buffer);
|
|
4552
|
+
return to;
|
|
4553
|
+
}
|
|
4554
|
+
};
|
|
4555
|
+
|
|
4556
|
+
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
4557
|
+
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
4558
|
+
1116352408,
|
|
4559
|
+
1899447441,
|
|
4560
|
+
3049323471,
|
|
4561
|
+
3921009573,
|
|
4562
|
+
961987163,
|
|
4563
|
+
1508970993,
|
|
4564
|
+
2453635748,
|
|
4565
|
+
2870763221,
|
|
4566
|
+
3624381080,
|
|
4567
|
+
310598401,
|
|
4568
|
+
607225278,
|
|
4569
|
+
1426881987,
|
|
4570
|
+
1925078388,
|
|
4571
|
+
2162078206,
|
|
4572
|
+
2614888103,
|
|
4573
|
+
3248222580,
|
|
4574
|
+
3835390401,
|
|
4575
|
+
4022224774,
|
|
4576
|
+
264347078,
|
|
4577
|
+
604807628,
|
|
4578
|
+
770255983,
|
|
4579
|
+
1249150122,
|
|
4580
|
+
1555081692,
|
|
4581
|
+
1996064986,
|
|
4582
|
+
2554220882,
|
|
4583
|
+
2821834349,
|
|
4584
|
+
2952996808,
|
|
4585
|
+
3210313671,
|
|
4586
|
+
3336571891,
|
|
4587
|
+
3584528711,
|
|
4588
|
+
113926993,
|
|
4589
|
+
338241895,
|
|
4590
|
+
666307205,
|
|
4591
|
+
773529912,
|
|
4592
|
+
1294757372,
|
|
4593
|
+
1396182291,
|
|
4594
|
+
1695183700,
|
|
4595
|
+
1986661051,
|
|
4596
|
+
2177026350,
|
|
4597
|
+
2456956037,
|
|
4598
|
+
2730485921,
|
|
4599
|
+
2820302411,
|
|
4600
|
+
3259730800,
|
|
4601
|
+
3345764771,
|
|
4602
|
+
3516065817,
|
|
4603
|
+
3600352804,
|
|
4604
|
+
4094571909,
|
|
4605
|
+
275423344,
|
|
4606
|
+
430227734,
|
|
4607
|
+
506948616,
|
|
4608
|
+
659060556,
|
|
4609
|
+
883997877,
|
|
4610
|
+
958139571,
|
|
4611
|
+
1322822218,
|
|
4612
|
+
1537002063,
|
|
4613
|
+
1747873779,
|
|
4614
|
+
1955562222,
|
|
4615
|
+
2024104815,
|
|
4616
|
+
2227730452,
|
|
4617
|
+
2361852424,
|
|
4618
|
+
2428436474,
|
|
4619
|
+
2756734187,
|
|
4620
|
+
3204031479,
|
|
4621
|
+
3329325298
|
|
4622
|
+
]);
|
|
4623
|
+
var SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
4624
|
+
1779033703,
|
|
4625
|
+
3144134277,
|
|
4626
|
+
1013904242,
|
|
4627
|
+
2773480762,
|
|
4628
|
+
1359893119,
|
|
4629
|
+
2600822924,
|
|
4630
|
+
528734635,
|
|
4631
|
+
1541459225
|
|
4632
|
+
]);
|
|
4633
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
4634
|
+
var SHA256 = class extends HashMD {
|
|
4635
|
+
constructor() {
|
|
4636
|
+
super(64, 32, 8, false);
|
|
4637
|
+
this.A = SHA256_IV[0] | 0;
|
|
4638
|
+
this.B = SHA256_IV[1] | 0;
|
|
4639
|
+
this.C = SHA256_IV[2] | 0;
|
|
4640
|
+
this.D = SHA256_IV[3] | 0;
|
|
4641
|
+
this.E = SHA256_IV[4] | 0;
|
|
4642
|
+
this.F = SHA256_IV[5] | 0;
|
|
4643
|
+
this.G = SHA256_IV[6] | 0;
|
|
4644
|
+
this.H = SHA256_IV[7] | 0;
|
|
4645
|
+
}
|
|
4646
|
+
get() {
|
|
4647
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
4648
|
+
return [A, B, C, D, E, F, G, H];
|
|
4649
|
+
}
|
|
4650
|
+
// prettier-ignore
|
|
4651
|
+
set(A, B, C, D, E, F, G, H) {
|
|
4652
|
+
this.A = A | 0;
|
|
4653
|
+
this.B = B | 0;
|
|
4654
|
+
this.C = C | 0;
|
|
4655
|
+
this.D = D | 0;
|
|
4656
|
+
this.E = E | 0;
|
|
4657
|
+
this.F = F | 0;
|
|
4658
|
+
this.G = G | 0;
|
|
4659
|
+
this.H = H | 0;
|
|
4660
|
+
}
|
|
4661
|
+
process(view, offset) {
|
|
4662
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
4663
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
4664
|
+
for (let i = 16; i < 64; i++) {
|
|
4665
|
+
const W15 = SHA256_W[i - 15];
|
|
4666
|
+
const W2 = SHA256_W[i - 2];
|
|
4667
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
4668
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
4669
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
4670
|
+
}
|
|
4671
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
4672
|
+
for (let i = 0; i < 64; i++) {
|
|
4673
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
4674
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
4675
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
4676
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
4677
|
+
H = G;
|
|
4678
|
+
G = F;
|
|
4679
|
+
F = E;
|
|
4680
|
+
E = D + T1 | 0;
|
|
4681
|
+
D = C;
|
|
4682
|
+
C = B;
|
|
4683
|
+
B = A;
|
|
4684
|
+
A = T1 + T2 | 0;
|
|
4685
|
+
}
|
|
4686
|
+
A = A + this.A | 0;
|
|
4687
|
+
B = B + this.B | 0;
|
|
4688
|
+
C = C + this.C | 0;
|
|
4689
|
+
D = D + this.D | 0;
|
|
4690
|
+
E = E + this.E | 0;
|
|
4691
|
+
F = F + this.F | 0;
|
|
4692
|
+
G = G + this.G | 0;
|
|
4693
|
+
H = H + this.H | 0;
|
|
4694
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
4695
|
+
}
|
|
4696
|
+
roundClean() {
|
|
4697
|
+
SHA256_W.fill(0);
|
|
4698
|
+
}
|
|
4699
|
+
destroy() {
|
|
4700
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
4701
|
+
this.buffer.fill(0);
|
|
4702
|
+
}
|
|
4703
|
+
};
|
|
4704
|
+
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
4705
|
+
|
|
4706
|
+
// ../../node_modules/@metamask/snaps-utils/dist/chunk-5R7UF7KM.mjs
|
|
4707
|
+
var HandlerType = /* @__PURE__ */ ((HandlerType2) => {
|
|
4708
|
+
HandlerType2["OnRpcRequest"] = "onRpcRequest";
|
|
4709
|
+
HandlerType2["OnSignature"] = "onSignature";
|
|
4710
|
+
HandlerType2["OnTransaction"] = "onTransaction";
|
|
4711
|
+
HandlerType2["OnCronjob"] = "onCronjob";
|
|
4712
|
+
HandlerType2["OnInstall"] = "onInstall";
|
|
4713
|
+
HandlerType2["OnUpdate"] = "onUpdate";
|
|
4714
|
+
HandlerType2["OnNameLookup"] = "onNameLookup";
|
|
4715
|
+
HandlerType2["OnKeyringRequest"] = "onKeyringRequest";
|
|
4716
|
+
HandlerType2["OnHomePage"] = "onHomePage";
|
|
4717
|
+
HandlerType2["OnUserInput"] = "onUserInput";
|
|
4718
|
+
return HandlerType2;
|
|
4719
|
+
})(HandlerType || {});
|
|
4720
|
+
var SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
4721
|
+
|
|
4722
|
+
// ../profile-sync-controller/src/controllers/authentication/auth-snap-requests.ts
|
|
4723
|
+
var snapId = "npm:@metamask/message-signing-snap";
|
|
4724
|
+
function createSnapSignMessageRequest(message) {
|
|
4725
|
+
return {
|
|
4726
|
+
snapId,
|
|
4727
|
+
origin: "",
|
|
4728
|
+
handler: HandlerType.OnRpcRequest,
|
|
4729
|
+
request: {
|
|
4730
|
+
method: "signMessage",
|
|
4731
|
+
params: { message }
|
|
4732
|
+
}
|
|
3803
4733
|
};
|
|
3804
|
-
return mockNotification;
|
|
3805
4734
|
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
4735
|
+
|
|
4736
|
+
// ../profile-sync-controller/src/controllers/user-storage/index.ts
|
|
4737
|
+
var user_storage_exports = {};
|
|
4738
|
+
__export(user_storage_exports, {
|
|
4739
|
+
Controller: () => UserStorageController,
|
|
4740
|
+
Encryption: () => encryption_default,
|
|
4741
|
+
Mocks: () => fixtures_exports,
|
|
4742
|
+
createSHA256Hash: () => createSHA256Hash
|
|
4743
|
+
});
|
|
4744
|
+
|
|
4745
|
+
// ../profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
|
|
4746
|
+
import { BaseController } from "@metamask/base-controller";
|
|
4747
|
+
|
|
4748
|
+
// ../../node_modules/@noble/hashes/esm/scrypt.js
|
|
4749
|
+
function XorAndSalsa(prev, pi, input, ii, out, oi) {
|
|
4750
|
+
let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++];
|
|
4751
|
+
let y02 = prev[pi++] ^ input[ii++], y03 = prev[pi++] ^ input[ii++];
|
|
4752
|
+
let y04 = prev[pi++] ^ input[ii++], y05 = prev[pi++] ^ input[ii++];
|
|
4753
|
+
let y06 = prev[pi++] ^ input[ii++], y07 = prev[pi++] ^ input[ii++];
|
|
4754
|
+
let y08 = prev[pi++] ^ input[ii++], y09 = prev[pi++] ^ input[ii++];
|
|
4755
|
+
let y10 = prev[pi++] ^ input[ii++], y11 = prev[pi++] ^ input[ii++];
|
|
4756
|
+
let y12 = prev[pi++] ^ input[ii++], y13 = prev[pi++] ^ input[ii++];
|
|
4757
|
+
let y14 = prev[pi++] ^ input[ii++], y15 = prev[pi++] ^ input[ii++];
|
|
4758
|
+
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;
|
|
4759
|
+
for (let i = 0; i < 8; i += 2) {
|
|
4760
|
+
x04 ^= rotl(x00 + x12 | 0, 7);
|
|
4761
|
+
x08 ^= rotl(x04 + x00 | 0, 9);
|
|
4762
|
+
x12 ^= rotl(x08 + x04 | 0, 13);
|
|
4763
|
+
x00 ^= rotl(x12 + x08 | 0, 18);
|
|
4764
|
+
x09 ^= rotl(x05 + x01 | 0, 7);
|
|
4765
|
+
x13 ^= rotl(x09 + x05 | 0, 9);
|
|
4766
|
+
x01 ^= rotl(x13 + x09 | 0, 13);
|
|
4767
|
+
x05 ^= rotl(x01 + x13 | 0, 18);
|
|
4768
|
+
x14 ^= rotl(x10 + x06 | 0, 7);
|
|
4769
|
+
x02 ^= rotl(x14 + x10 | 0, 9);
|
|
4770
|
+
x06 ^= rotl(x02 + x14 | 0, 13);
|
|
4771
|
+
x10 ^= rotl(x06 + x02 | 0, 18);
|
|
4772
|
+
x03 ^= rotl(x15 + x11 | 0, 7);
|
|
4773
|
+
x07 ^= rotl(x03 + x15 | 0, 9);
|
|
4774
|
+
x11 ^= rotl(x07 + x03 | 0, 13);
|
|
4775
|
+
x15 ^= rotl(x11 + x07 | 0, 18);
|
|
4776
|
+
x01 ^= rotl(x00 + x03 | 0, 7);
|
|
4777
|
+
x02 ^= rotl(x01 + x00 | 0, 9);
|
|
4778
|
+
x03 ^= rotl(x02 + x01 | 0, 13);
|
|
4779
|
+
x00 ^= rotl(x03 + x02 | 0, 18);
|
|
4780
|
+
x06 ^= rotl(x05 + x04 | 0, 7);
|
|
4781
|
+
x07 ^= rotl(x06 + x05 | 0, 9);
|
|
4782
|
+
x04 ^= rotl(x07 + x06 | 0, 13);
|
|
4783
|
+
x05 ^= rotl(x04 + x07 | 0, 18);
|
|
4784
|
+
x11 ^= rotl(x10 + x09 | 0, 7);
|
|
4785
|
+
x08 ^= rotl(x11 + x10 | 0, 9);
|
|
4786
|
+
x09 ^= rotl(x08 + x11 | 0, 13);
|
|
4787
|
+
x10 ^= rotl(x09 + x08 | 0, 18);
|
|
4788
|
+
x12 ^= rotl(x15 + x14 | 0, 7);
|
|
4789
|
+
x13 ^= rotl(x12 + x15 | 0, 9);
|
|
4790
|
+
x14 ^= rotl(x13 + x12 | 0, 13);
|
|
4791
|
+
x15 ^= rotl(x14 + x13 | 0, 18);
|
|
4792
|
+
}
|
|
4793
|
+
out[oi++] = y00 + x00 | 0;
|
|
4794
|
+
out[oi++] = y01 + x01 | 0;
|
|
4795
|
+
out[oi++] = y02 + x02 | 0;
|
|
4796
|
+
out[oi++] = y03 + x03 | 0;
|
|
4797
|
+
out[oi++] = y04 + x04 | 0;
|
|
4798
|
+
out[oi++] = y05 + x05 | 0;
|
|
4799
|
+
out[oi++] = y06 + x06 | 0;
|
|
4800
|
+
out[oi++] = y07 + x07 | 0;
|
|
4801
|
+
out[oi++] = y08 + x08 | 0;
|
|
4802
|
+
out[oi++] = y09 + x09 | 0;
|
|
4803
|
+
out[oi++] = y10 + x10 | 0;
|
|
4804
|
+
out[oi++] = y11 + x11 | 0;
|
|
4805
|
+
out[oi++] = y12 + x12 | 0;
|
|
4806
|
+
out[oi++] = y13 + x13 | 0;
|
|
4807
|
+
out[oi++] = y14 + x14 | 0;
|
|
4808
|
+
out[oi++] = y15 + x15 | 0;
|
|
4809
|
+
}
|
|
4810
|
+
function BlockMix(input, ii, out, oi, r) {
|
|
4811
|
+
let head = oi + 0;
|
|
4812
|
+
let tail = oi + 16 * r;
|
|
4813
|
+
for (let i = 0; i < 16; i++)
|
|
4814
|
+
out[tail + i] = input[ii + (2 * r - 1) * 16 + i];
|
|
4815
|
+
for (let i = 0; i < r; i++, head += 16, ii += 16) {
|
|
4816
|
+
XorAndSalsa(out, tail, input, ii, out, head);
|
|
4817
|
+
if (i > 0)
|
|
4818
|
+
tail += 16;
|
|
4819
|
+
XorAndSalsa(out, head, input, ii += 16, out, tail);
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
function scryptInit(password, salt, _opts) {
|
|
4823
|
+
const opts = checkOpts({
|
|
4824
|
+
dkLen: 32,
|
|
4825
|
+
asyncTick: 10,
|
|
4826
|
+
maxmem: 1024 ** 3 + 1024
|
|
4827
|
+
}, _opts);
|
|
4828
|
+
const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts;
|
|
4829
|
+
number2(N);
|
|
4830
|
+
number2(r);
|
|
4831
|
+
number2(p);
|
|
4832
|
+
number2(dkLen);
|
|
4833
|
+
number2(asyncTick);
|
|
4834
|
+
number2(maxmem);
|
|
4835
|
+
if (onProgress !== void 0 && typeof onProgress !== "function")
|
|
4836
|
+
throw new Error("progressCb should be function");
|
|
4837
|
+
const blockSize = 128 * r;
|
|
4838
|
+
const blockSize32 = blockSize / 4;
|
|
4839
|
+
if (N <= 1 || (N & N - 1) !== 0 || N >= 2 ** (blockSize / 8) || N > 2 ** 32) {
|
|
4840
|
+
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");
|
|
4841
|
+
}
|
|
4842
|
+
if (p < 0 || p > (2 ** 32 - 1) * 32 / blockSize) {
|
|
4843
|
+
throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
|
|
4844
|
+
}
|
|
4845
|
+
if (dkLen < 0 || dkLen > (2 ** 32 - 1) * 32) {
|
|
4846
|
+
throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
|
|
4847
|
+
}
|
|
4848
|
+
const memUsed = blockSize * (N + p);
|
|
4849
|
+
if (memUsed > maxmem) {
|
|
4850
|
+
throw new Error(`Scrypt: parameters too large, ${memUsed} (128 * r * (N + p)) > ${maxmem} (maxmem)`);
|
|
4851
|
+
}
|
|
4852
|
+
const B = pbkdf2(sha256, password, salt, { c: 1, dkLen: blockSize * p });
|
|
4853
|
+
const B32 = u322(B);
|
|
4854
|
+
const V = u322(new Uint8Array(blockSize * N));
|
|
4855
|
+
const tmp = u322(new Uint8Array(blockSize));
|
|
4856
|
+
let blockMixCb = () => {
|
|
3838
4857
|
};
|
|
3839
|
-
|
|
4858
|
+
if (onProgress) {
|
|
4859
|
+
const totalBlockMix = 2 * N * p;
|
|
4860
|
+
const callbackPer = Math.max(Math.floor(totalBlockMix / 1e4), 1);
|
|
4861
|
+
let blockMixCnt = 0;
|
|
4862
|
+
blockMixCb = () => {
|
|
4863
|
+
blockMixCnt++;
|
|
4864
|
+
if (onProgress && (!(blockMixCnt % callbackPer) || blockMixCnt === totalBlockMix))
|
|
4865
|
+
onProgress(blockMixCnt / totalBlockMix);
|
|
4866
|
+
};
|
|
4867
|
+
}
|
|
4868
|
+
return { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick };
|
|
3840
4869
|
}
|
|
3841
|
-
function
|
|
3842
|
-
const
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
4870
|
+
function scryptOutput(password, dkLen, B, V, tmp) {
|
|
4871
|
+
const res = pbkdf2(sha256, password, B, { c: 1, dkLen });
|
|
4872
|
+
B.fill(0);
|
|
4873
|
+
V.fill(0);
|
|
4874
|
+
tmp.fill(0);
|
|
4875
|
+
return res;
|
|
4876
|
+
}
|
|
4877
|
+
function scrypt(password, salt, opts) {
|
|
4878
|
+
const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb } = scryptInit(password, salt, opts);
|
|
4879
|
+
if (!isLE2)
|
|
4880
|
+
byteSwap32(B32);
|
|
4881
|
+
for (let pi = 0; pi < p; pi++) {
|
|
4882
|
+
const Pi = blockSize32 * pi;
|
|
4883
|
+
for (let i = 0; i < blockSize32; i++)
|
|
4884
|
+
V[i] = B32[Pi + i];
|
|
4885
|
+
for (let i = 0, pos = 0; i < N - 1; i++) {
|
|
4886
|
+
BlockMix(V, pos, V, pos += blockSize32, r);
|
|
4887
|
+
blockMixCb();
|
|
4888
|
+
}
|
|
4889
|
+
BlockMix(V, (N - 1) * blockSize32, B32, Pi, r);
|
|
4890
|
+
blockMixCb();
|
|
4891
|
+
for (let i = 0; i < N; i++) {
|
|
4892
|
+
const j = B32[Pi + blockSize32 - 16] % N;
|
|
4893
|
+
for (let k = 0; k < blockSize32; k++)
|
|
4894
|
+
tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k];
|
|
4895
|
+
BlockMix(tmp, 0, B32, Pi, r);
|
|
4896
|
+
blockMixCb();
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
if (!isLE2)
|
|
4900
|
+
byteSwap32(B32);
|
|
4901
|
+
return scryptOutput(password, dkLen, B, V, tmp);
|
|
4902
|
+
}
|
|
4903
|
+
|
|
4904
|
+
// ../profile-sync-controller/src/controllers/user-storage/encryption/utils.ts
|
|
4905
|
+
var byteArrayToBase64 = (byteArray) => {
|
|
4906
|
+
return Buffer.from(byteArray).toString("base64");
|
|
4907
|
+
};
|
|
4908
|
+
var base64ToByteArray = (base64) => {
|
|
4909
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
4910
|
+
};
|
|
4911
|
+
var bytesToUtf8 = (byteArray) => {
|
|
4912
|
+
const decoder = new TextDecoder("utf-8");
|
|
4913
|
+
return decoder.decode(byteArray);
|
|
4914
|
+
};
|
|
4915
|
+
|
|
4916
|
+
// ../profile-sync-controller/src/controllers/user-storage/encryption/cache.ts
|
|
4917
|
+
var MAX_PASSWORD_CACHES = 3;
|
|
4918
|
+
var MAX_SALT_CACHES = 10;
|
|
4919
|
+
var inMemCachedKDF = {};
|
|
4920
|
+
var getPasswordCache = (hashedPassword) => {
|
|
4921
|
+
inMemCachedKDF[hashedPassword] ?? (inMemCachedKDF[hashedPassword] = /* @__PURE__ */ new Map());
|
|
4922
|
+
return inMemCachedKDF[hashedPassword];
|
|
4923
|
+
};
|
|
4924
|
+
function getCachedKeyBySalt(hashedPassword, salt) {
|
|
4925
|
+
const cache = getPasswordCache(hashedPassword);
|
|
4926
|
+
const base64Salt = byteArrayToBase64(salt);
|
|
4927
|
+
const cachedKey = cache.get(base64Salt);
|
|
4928
|
+
if (!cachedKey) {
|
|
4929
|
+
return void 0;
|
|
4930
|
+
}
|
|
4931
|
+
return {
|
|
4932
|
+
salt,
|
|
4933
|
+
base64Salt,
|
|
4934
|
+
key: cachedKey
|
|
3873
4935
|
};
|
|
3874
|
-
return mockNotification;
|
|
3875
4936
|
}
|
|
3876
|
-
function
|
|
3877
|
-
const
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
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
|
|
4937
|
+
function getAnyCachedKey(hashedPassword) {
|
|
4938
|
+
const cache = getPasswordCache(hashedPassword);
|
|
4939
|
+
const cachedEntry = cache.entries().next().value;
|
|
4940
|
+
if (!cachedEntry) {
|
|
4941
|
+
return void 0;
|
|
4942
|
+
}
|
|
4943
|
+
const base64Salt = cachedEntry[0];
|
|
4944
|
+
const bytesSalt = base64ToByteArray(base64Salt);
|
|
4945
|
+
return {
|
|
4946
|
+
salt: bytesSalt,
|
|
4947
|
+
base64Salt,
|
|
4948
|
+
key: cachedEntry[1]
|
|
3908
4949
|
};
|
|
3909
|
-
return mockNotification;
|
|
3910
4950
|
}
|
|
3911
|
-
function
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
4951
|
+
function setCachedKey(hashedPassword, salt, key) {
|
|
4952
|
+
if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {
|
|
4953
|
+
inMemCachedKDF = {};
|
|
4954
|
+
}
|
|
4955
|
+
const cache = getPasswordCache(hashedPassword);
|
|
4956
|
+
const base64Salt = byteArrayToBase64(salt);
|
|
4957
|
+
if (cache.size > MAX_SALT_CACHES) {
|
|
4958
|
+
cache.clear();
|
|
4959
|
+
}
|
|
4960
|
+
cache.set(base64Salt, key);
|
|
4961
|
+
}
|
|
4962
|
+
|
|
4963
|
+
// ../profile-sync-controller/src/controllers/user-storage/encryption/encryption.ts
|
|
4964
|
+
var ALGORITHM_NONCE_SIZE = 12;
|
|
4965
|
+
var ALGORITHM_KEY_SIZE = 16;
|
|
4966
|
+
var SCRYPT_SALT_SIZE = 16;
|
|
4967
|
+
var SCRYPT_N = 2 ** 17;
|
|
4968
|
+
var SCRYPT_r = 8;
|
|
4969
|
+
var SCRYPT_p = 1;
|
|
4970
|
+
var _encryptStringV1, encryptStringV1_fn, _decryptStringV1, decryptStringV1_fn, _encrypt, encrypt_fn, _decrypt, decrypt_fn, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn;
|
|
4971
|
+
var EncryptorDecryptor = class {
|
|
4972
|
+
constructor() {
|
|
4973
|
+
__privateAdd(this, _encryptStringV1);
|
|
4974
|
+
__privateAdd(this, _decryptStringV1);
|
|
4975
|
+
__privateAdd(this, _encrypt);
|
|
4976
|
+
__privateAdd(this, _decrypt);
|
|
4977
|
+
__privateAdd(this, _getOrGenerateScryptKey);
|
|
4978
|
+
}
|
|
4979
|
+
encryptString(plaintext, password) {
|
|
4980
|
+
try {
|
|
4981
|
+
return __privateMethod(this, _encryptStringV1, encryptStringV1_fn).call(this, plaintext, password);
|
|
4982
|
+
} catch (e) {
|
|
4983
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
4984
|
+
throw new Error(`Unable to encrypt string - ${errorMessage}`);
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
decryptString(encryptedDataStr, password) {
|
|
4988
|
+
try {
|
|
4989
|
+
const encryptedData = JSON.parse(encryptedDataStr);
|
|
4990
|
+
if (encryptedData.v === "1") {
|
|
4991
|
+
if (encryptedData.t === "scrypt") {
|
|
4992
|
+
return __privateMethod(this, _decryptStringV1, decryptStringV1_fn).call(this, encryptedData, password);
|
|
3930
4993
|
}
|
|
3931
|
-
},
|
|
3932
|
-
from: "0x0000000000000000000000000000000000000000",
|
|
3933
|
-
kind: "erc1155_received",
|
|
3934
|
-
network_fee: {
|
|
3935
|
-
gas_price: "33571446596",
|
|
3936
|
-
native_token_price_in_usd: "2038.88"
|
|
3937
4994
|
}
|
|
4995
|
+
throw new Error(
|
|
4996
|
+
`Unsupported encrypted data payload - ${encryptedDataStr}`
|
|
4997
|
+
);
|
|
4998
|
+
} catch (e) {
|
|
4999
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5000
|
+
throw new Error(`Unable to decrypt string - ${errorMessage}`);
|
|
5001
|
+
}
|
|
5002
|
+
}
|
|
5003
|
+
};
|
|
5004
|
+
_encryptStringV1 = new WeakSet();
|
|
5005
|
+
encryptStringV1_fn = function(plaintext, password) {
|
|
5006
|
+
const { key, salt } = __privateMethod(this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
|
|
5007
|
+
N: SCRYPT_N,
|
|
5008
|
+
r: SCRYPT_r,
|
|
5009
|
+
p: SCRYPT_p,
|
|
5010
|
+
dkLen: ALGORITHM_KEY_SIZE
|
|
5011
|
+
});
|
|
5012
|
+
const plaintextRaw = utf8ToBytes2(plaintext);
|
|
5013
|
+
const ciphertextAndNonceAndSalt = concatBytes(
|
|
5014
|
+
salt,
|
|
5015
|
+
__privateMethod(this, _encrypt, encrypt_fn).call(this, plaintextRaw, key)
|
|
5016
|
+
);
|
|
5017
|
+
const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);
|
|
5018
|
+
const encryptedPayload = {
|
|
5019
|
+
v: "1",
|
|
5020
|
+
t: "scrypt",
|
|
5021
|
+
d: encryptedData,
|
|
5022
|
+
o: {
|
|
5023
|
+
N: SCRYPT_N,
|
|
5024
|
+
r: SCRYPT_r,
|
|
5025
|
+
p: SCRYPT_p,
|
|
5026
|
+
dkLen: ALGORITHM_KEY_SIZE
|
|
3938
5027
|
},
|
|
3939
|
-
|
|
3940
|
-
trigger_id: "710c8abb-43a9-42a5-9d86-9dd258726c82",
|
|
3941
|
-
tx_hash: "0x03381aba290facbaf71c123e263c8dc3dd550aac00ef589cce395182eaeff76f",
|
|
3942
|
-
unread: true
|
|
5028
|
+
saltLen: SCRYPT_SALT_SIZE
|
|
3943
5029
|
};
|
|
3944
|
-
return
|
|
3945
|
-
}
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
5030
|
+
return JSON.stringify(encryptedPayload);
|
|
5031
|
+
};
|
|
5032
|
+
_decryptStringV1 = new WeakSet();
|
|
5033
|
+
decryptStringV1_fn = function(data, password) {
|
|
5034
|
+
const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
|
|
5035
|
+
const ciphertextAndNonceAndSalt = base64ToByteArray(
|
|
5036
|
+
base64CiphertextAndNonceAndSalt
|
|
5037
|
+
);
|
|
5038
|
+
const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
|
|
5039
|
+
const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(
|
|
5040
|
+
saltLen,
|
|
5041
|
+
ciphertextAndNonceAndSalt.length
|
|
5042
|
+
);
|
|
5043
|
+
const { key } = __privateMethod(this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
|
|
5044
|
+
N: o.N,
|
|
5045
|
+
r: o.r,
|
|
5046
|
+
p: o.p,
|
|
5047
|
+
dkLen: o.dkLen
|
|
5048
|
+
}, salt);
|
|
5049
|
+
return bytesToUtf8(__privateMethod(this, _decrypt, decrypt_fn).call(this, ciphertextAndNonce, key));
|
|
5050
|
+
};
|
|
5051
|
+
_encrypt = new WeakSet();
|
|
5052
|
+
encrypt_fn = function(plaintext, key) {
|
|
5053
|
+
const nonce = randomBytes(ALGORITHM_NONCE_SIZE);
|
|
5054
|
+
const ciphertext = gcm(key, nonce).encrypt(plaintext);
|
|
5055
|
+
return concatBytes(nonce, ciphertext);
|
|
5056
|
+
};
|
|
5057
|
+
_decrypt = new WeakSet();
|
|
5058
|
+
decrypt_fn = function(ciphertextAndNonce, key) {
|
|
5059
|
+
const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
|
|
5060
|
+
const ciphertext = ciphertextAndNonce.slice(
|
|
5061
|
+
ALGORITHM_NONCE_SIZE,
|
|
5062
|
+
ciphertextAndNonce.length
|
|
5063
|
+
);
|
|
5064
|
+
return gcm(key, nonce).decrypt(ciphertext);
|
|
5065
|
+
};
|
|
5066
|
+
_getOrGenerateScryptKey = new WeakSet();
|
|
5067
|
+
getOrGenerateScryptKey_fn = function(password, o, salt) {
|
|
5068
|
+
const hashedPassword = createSHA256Hash(password);
|
|
5069
|
+
const cachedKey = salt ? getCachedKeyBySalt(hashedPassword, salt) : getAnyCachedKey(hashedPassword);
|
|
5070
|
+
if (cachedKey) {
|
|
5071
|
+
return {
|
|
5072
|
+
key: cachedKey.key,
|
|
5073
|
+
salt: cachedKey.salt
|
|
5074
|
+
};
|
|
5075
|
+
}
|
|
5076
|
+
const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);
|
|
5077
|
+
const newKey = scrypt(password, newSalt, {
|
|
5078
|
+
N: o.N,
|
|
5079
|
+
r: o.r,
|
|
5080
|
+
p: o.p,
|
|
5081
|
+
dkLen: o.dkLen
|
|
5082
|
+
});
|
|
5083
|
+
setCachedKey(hashedPassword, newSalt, newKey);
|
|
5084
|
+
return {
|
|
5085
|
+
key: newKey,
|
|
5086
|
+
salt: newSalt
|
|
3984
5087
|
};
|
|
3985
|
-
|
|
5088
|
+
};
|
|
5089
|
+
var encryption = new EncryptorDecryptor();
|
|
5090
|
+
var encryption_default = encryption;
|
|
5091
|
+
function createSHA256Hash(data) {
|
|
5092
|
+
const hashedData = sha256(data);
|
|
5093
|
+
return bytesToHex(hashedData);
|
|
3986
5094
|
}
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
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;
|
|
5095
|
+
|
|
5096
|
+
// ../profile-sync-controller/src/controllers/user-storage/encryption/index.ts
|
|
5097
|
+
var encryption_default2 = encryption_default;
|
|
5098
|
+
|
|
5099
|
+
// ../profile-sync-controller/src/controllers/user-storage/services.ts
|
|
5100
|
+
import log from "loglevel";
|
|
5101
|
+
|
|
5102
|
+
// ../profile-sync-controller/src/controllers/user-storage/schema.ts
|
|
5103
|
+
var USER_STORAGE_ENTRIES = {
|
|
5104
|
+
notificationSettings: {
|
|
5105
|
+
path: "notifications",
|
|
5106
|
+
entryName: "notificationSettings"
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
function createEntryPath(entryKey, storageKey) {
|
|
5110
|
+
const entry = USER_STORAGE_ENTRIES[entryKey];
|
|
5111
|
+
if (!entry) {
|
|
5112
|
+
throw new Error(`user-storage - invalid entry provided: ${entryKey}`);
|
|
5113
|
+
}
|
|
5114
|
+
const hashedKey = createSHA256Hash(entry.entryName + storageKey);
|
|
5115
|
+
return `/${entry.path}/${hashedKey}`;
|
|
4026
5116
|
}
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
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"
|
|
5117
|
+
|
|
5118
|
+
// ../profile-sync-controller/src/controllers/user-storage/services.ts
|
|
5119
|
+
var ENV_URLS2 = getEnvUrls("prd" /* PRD */);
|
|
5120
|
+
var USER_STORAGE_API = ENV_URLS2.userStorageApiUrl;
|
|
5121
|
+
var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
|
|
5122
|
+
async function getUserStorage(opts) {
|
|
5123
|
+
try {
|
|
5124
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
5125
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
5126
|
+
const userStorageResponse = await fetch(url.toString(), {
|
|
5127
|
+
headers: {
|
|
5128
|
+
"Content-Type": "application/json",
|
|
5129
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
4058
5130
|
}
|
|
5131
|
+
});
|
|
5132
|
+
if (userStorageResponse.status === 404) {
|
|
5133
|
+
return null;
|
|
5134
|
+
}
|
|
5135
|
+
if (userStorageResponse.status !== 200) {
|
|
5136
|
+
throw new Error("Unable to get User Storage");
|
|
5137
|
+
}
|
|
5138
|
+
const userStorage = await userStorageResponse.json();
|
|
5139
|
+
const encryptedData = userStorage?.Data ?? null;
|
|
5140
|
+
if (!encryptedData) {
|
|
5141
|
+
return null;
|
|
5142
|
+
}
|
|
5143
|
+
const decryptedData = encryption_default2.decryptString(
|
|
5144
|
+
encryptedData,
|
|
5145
|
+
opts.storageKey
|
|
5146
|
+
);
|
|
5147
|
+
return decryptedData;
|
|
5148
|
+
} catch (e) {
|
|
5149
|
+
log.error("Failed to get user storage", e);
|
|
5150
|
+
return null;
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
async function upsertUserStorage(data, opts) {
|
|
5154
|
+
const encryptedData = encryption_default2.encryptString(data, opts.storageKey);
|
|
5155
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
5156
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
5157
|
+
const res = await fetch(url.toString(), {
|
|
5158
|
+
method: "PUT",
|
|
5159
|
+
headers: {
|
|
5160
|
+
"Content-Type": "application/json",
|
|
5161
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
4059
5162
|
},
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
}
|
|
4065
|
-
return mockNotification;
|
|
5163
|
+
body: JSON.stringify({ data: encryptedData })
|
|
5164
|
+
});
|
|
5165
|
+
if (!res.ok) {
|
|
5166
|
+
throw new Error("user-storage - unable to upsert data");
|
|
5167
|
+
}
|
|
4066
5168
|
}
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
5169
|
+
|
|
5170
|
+
// ../profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
|
|
5171
|
+
var controllerName = "UserStorageController";
|
|
5172
|
+
var defaultState = {
|
|
5173
|
+
isProfileSyncingEnabled: true,
|
|
5174
|
+
isProfileSyncingUpdateLoading: false
|
|
5175
|
+
};
|
|
5176
|
+
var metadata = {
|
|
5177
|
+
isProfileSyncingEnabled: {
|
|
5178
|
+
persist: true,
|
|
5179
|
+
anonymous: true
|
|
5180
|
+
},
|
|
5181
|
+
isProfileSyncingUpdateLoading: {
|
|
5182
|
+
persist: false,
|
|
5183
|
+
anonymous: false
|
|
5184
|
+
}
|
|
5185
|
+
};
|
|
5186
|
+
var _auth, _notificationServices, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
5187
|
+
var UserStorageController = class extends BaseController {
|
|
5188
|
+
constructor(params) {
|
|
5189
|
+
super({
|
|
5190
|
+
messenger: params.messenger,
|
|
5191
|
+
metadata,
|
|
5192
|
+
name: controllerName,
|
|
5193
|
+
state: { ...defaultState, ...params.state }
|
|
5194
|
+
});
|
|
5195
|
+
/**
|
|
5196
|
+
* Constructor helper for registering this controller's messaging system
|
|
5197
|
+
* actions.
|
|
5198
|
+
*/
|
|
5199
|
+
__privateAdd(this, _registerMessageHandlers);
|
|
5200
|
+
__privateAdd(this, _assertProfileSyncingEnabled);
|
|
5201
|
+
/**
|
|
5202
|
+
* Utility to get the bearer token and storage key
|
|
5203
|
+
*/
|
|
5204
|
+
__privateAdd(this, _getStorageKeyAndBearerToken);
|
|
5205
|
+
/**
|
|
5206
|
+
* Rather than storing the storage key, we can compute the storage key when needed.
|
|
5207
|
+
*
|
|
5208
|
+
* @returns the storage key
|
|
5209
|
+
*/
|
|
5210
|
+
__privateAdd(this, _createStorageKey);
|
|
5211
|
+
/**
|
|
5212
|
+
* Signs a specific message using an underlying auth snap.
|
|
5213
|
+
*
|
|
5214
|
+
* @param message - A specific tagged message to sign.
|
|
5215
|
+
* @returns A Signature created by the snap.
|
|
5216
|
+
*/
|
|
5217
|
+
__privateAdd(this, _snapSignMessage);
|
|
5218
|
+
__privateAdd(this, _setIsProfileSyncingUpdateLoading);
|
|
5219
|
+
__privateAdd(this, _auth, {
|
|
5220
|
+
getBearerToken: async () => {
|
|
5221
|
+
return await this.messagingSystem.call(
|
|
5222
|
+
"AuthenticationController:getBearerToken"
|
|
5223
|
+
);
|
|
4085
5224
|
},
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
symbol: "STETH",
|
|
4092
|
-
address: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
4093
|
-
decimals: "18"
|
|
5225
|
+
getProfileId: async () => {
|
|
5226
|
+
const sessionProfile = await this.messagingSystem.call(
|
|
5227
|
+
"AuthenticationController:getSessionProfile"
|
|
5228
|
+
);
|
|
5229
|
+
return sessionProfile?.profileId;
|
|
4094
5230
|
},
|
|
4095
|
-
|
|
4096
|
-
|
|
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;
|
|
4106
|
-
}
|
|
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"
|
|
5231
|
+
isAuthEnabled: () => {
|
|
5232
|
+
return this.messagingSystem.call("AuthenticationController:isSignedIn");
|
|
4125
5233
|
},
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
symbol: "ETH",
|
|
4131
|
-
address: "0x0000000000000000000000000000000000000000",
|
|
4132
|
-
decimals: "18",
|
|
4133
|
-
name: "Ethereum"
|
|
5234
|
+
signIn: async () => {
|
|
5235
|
+
return await this.messagingSystem.call(
|
|
5236
|
+
"AuthenticationController:performSignIn"
|
|
5237
|
+
);
|
|
4134
5238
|
},
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
5239
|
+
signOut: async () => {
|
|
5240
|
+
return this.messagingSystem.call(
|
|
5241
|
+
"AuthenticationController:performSignOut"
|
|
5242
|
+
);
|
|
4138
5243
|
}
|
|
4139
|
-
}
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
return mockNotification;
|
|
4146
|
-
}
|
|
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"
|
|
5244
|
+
});
|
|
5245
|
+
__privateAdd(this, _notificationServices, {
|
|
5246
|
+
disableNotificationServices: async () => {
|
|
5247
|
+
return await this.messagingSystem.call(
|
|
5248
|
+
"NotificationServicesController:disableNotificationServices"
|
|
5249
|
+
);
|
|
4174
5250
|
},
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
5251
|
+
selectIsNotificationServicesEnabled: async () => {
|
|
5252
|
+
return this.messagingSystem.call(
|
|
5253
|
+
"NotificationServicesController:selectIsNotificationServicesEnabled"
|
|
5254
|
+
);
|
|
4178
5255
|
}
|
|
4179
|
-
}
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
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"
|
|
5256
|
+
});
|
|
5257
|
+
this.getMetaMetricsState = params.getMetaMetricsState;
|
|
5258
|
+
__privateMethod(this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
5259
|
+
}
|
|
5260
|
+
async enableProfileSyncing() {
|
|
5261
|
+
try {
|
|
5262
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
5263
|
+
const authEnabled = __privateGet(this, _auth).isAuthEnabled();
|
|
5264
|
+
if (!authEnabled) {
|
|
5265
|
+
await __privateGet(this, _auth).signIn();
|
|
4206
5266
|
}
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
5267
|
+
this.update((state) => {
|
|
5268
|
+
state.isProfileSyncingEnabled = true;
|
|
5269
|
+
});
|
|
5270
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5271
|
+
} catch (e) {
|
|
5272
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5273
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5274
|
+
throw new Error(
|
|
5275
|
+
`${controllerName} - failed to enable profile syncing - ${errorMessage}`
|
|
5276
|
+
);
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
async setIsProfileSyncingEnabled(isProfileSyncingEnabled) {
|
|
5280
|
+
this.update((state) => {
|
|
5281
|
+
state.isProfileSyncingEnabled = isProfileSyncingEnabled;
|
|
5282
|
+
});
|
|
5283
|
+
}
|
|
5284
|
+
async disableProfileSyncing() {
|
|
5285
|
+
const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;
|
|
5286
|
+
if (isAlreadyDisabled) {
|
|
5287
|
+
return;
|
|
5288
|
+
}
|
|
5289
|
+
try {
|
|
5290
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
5291
|
+
const isNotificationServicesEnabled = await __privateGet(this, _notificationServices).selectIsNotificationServicesEnabled();
|
|
5292
|
+
if (isNotificationServicesEnabled) {
|
|
5293
|
+
await __privateGet(this, _notificationServices).disableNotificationServices();
|
|
5294
|
+
}
|
|
5295
|
+
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
5296
|
+
if (!isMetaMetricsParticipation) {
|
|
5297
|
+
this.messagingSystem.call("AuthenticationController:performSignOut");
|
|
5298
|
+
}
|
|
5299
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5300
|
+
this.update((state) => {
|
|
5301
|
+
state.isProfileSyncingEnabled = false;
|
|
5302
|
+
});
|
|
5303
|
+
} catch (e) {
|
|
5304
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5305
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5306
|
+
throw new Error(
|
|
5307
|
+
`${controllerName} - failed to disable profile syncing - ${errorMessage}`
|
|
5308
|
+
);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
/**
|
|
5312
|
+
* Allows retrieval of stored data. Data stored is string formatted.
|
|
5313
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
5314
|
+
*
|
|
5315
|
+
* @param entryKey - entry key that matches schema
|
|
5316
|
+
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
5317
|
+
*/
|
|
5318
|
+
async performGetStorage(entryKey) {
|
|
5319
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5320
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
5321
|
+
const result = await getUserStorage({
|
|
5322
|
+
entryKey,
|
|
5323
|
+
bearerToken,
|
|
5324
|
+
storageKey
|
|
5325
|
+
});
|
|
5326
|
+
return result;
|
|
5327
|
+
}
|
|
5328
|
+
/**
|
|
5329
|
+
* Allows storage of user data. Data stored must be string formatted.
|
|
5330
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
5331
|
+
*
|
|
5332
|
+
* @param entryKey - entry key that matches schema
|
|
5333
|
+
* @param value - The string data you want to store.
|
|
5334
|
+
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
5335
|
+
*/
|
|
5336
|
+
async performSetStorage(entryKey, value) {
|
|
5337
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5338
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
5339
|
+
await upsertUserStorage(value, {
|
|
5340
|
+
entryKey,
|
|
5341
|
+
bearerToken,
|
|
5342
|
+
storageKey
|
|
5343
|
+
});
|
|
5344
|
+
}
|
|
5345
|
+
/**
|
|
5346
|
+
* Retrieves the storage key, for internal use only!
|
|
5347
|
+
*
|
|
5348
|
+
* @returns the storage key
|
|
5349
|
+
*/
|
|
5350
|
+
async getStorageKey() {
|
|
5351
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5352
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
5353
|
+
return storageKey;
|
|
5354
|
+
}
|
|
4231
5355
|
};
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
5356
|
+
_auth = new WeakMap();
|
|
5357
|
+
_notificationServices = new WeakMap();
|
|
5358
|
+
_registerMessageHandlers = new WeakSet();
|
|
5359
|
+
registerMessageHandlers_fn = function() {
|
|
5360
|
+
this.messagingSystem.registerActionHandler(
|
|
5361
|
+
"UserStorageController:performGetStorage",
|
|
5362
|
+
this.performGetStorage.bind(this)
|
|
5363
|
+
);
|
|
5364
|
+
this.messagingSystem.registerActionHandler(
|
|
5365
|
+
"UserStorageController:performSetStorage",
|
|
5366
|
+
this.performSetStorage.bind(this)
|
|
5367
|
+
);
|
|
5368
|
+
this.messagingSystem.registerActionHandler(
|
|
5369
|
+
"UserStorageController:getStorageKey",
|
|
5370
|
+
this.getStorageKey.bind(this)
|
|
5371
|
+
);
|
|
5372
|
+
this.messagingSystem.registerActionHandler(
|
|
5373
|
+
"UserStorageController:enableProfileSyncing",
|
|
5374
|
+
this.enableProfileSyncing.bind(this)
|
|
5375
|
+
);
|
|
5376
|
+
this.messagingSystem.registerActionHandler(
|
|
5377
|
+
"UserStorageController:disableProfileSyncing",
|
|
5378
|
+
this.disableProfileSyncing.bind(this)
|
|
5379
|
+
);
|
|
4238
5380
|
};
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
5381
|
+
_assertProfileSyncingEnabled = new WeakSet();
|
|
5382
|
+
assertProfileSyncingEnabled_fn = function() {
|
|
5383
|
+
if (!this.state.isProfileSyncingEnabled) {
|
|
5384
|
+
throw new Error(
|
|
5385
|
+
`${controllerName}: Unable to call method, user is not authenticated`
|
|
5386
|
+
);
|
|
5387
|
+
}
|
|
4245
5388
|
};
|
|
4246
|
-
|
|
4247
|
-
|
|
5389
|
+
_getStorageKeyAndBearerToken = new WeakSet();
|
|
5390
|
+
getStorageKeyAndBearerToken_fn = async function() {
|
|
5391
|
+
const bearerToken = await __privateGet(this, _auth).getBearerToken();
|
|
5392
|
+
if (!bearerToken) {
|
|
5393
|
+
throw new Error("UserStorageController - unable to get bearer token");
|
|
5394
|
+
}
|
|
5395
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
5396
|
+
return { bearerToken, storageKey };
|
|
5397
|
+
};
|
|
5398
|
+
_createStorageKey = new WeakSet();
|
|
5399
|
+
createStorageKey_fn = async function() {
|
|
5400
|
+
const id = await __privateGet(this, _auth).getProfileId();
|
|
5401
|
+
if (!id) {
|
|
5402
|
+
throw new Error("UserStorageController - unable to create storage key");
|
|
5403
|
+
}
|
|
5404
|
+
const storageKeySignature = await __privateMethod(this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
|
|
5405
|
+
const storageKey = createSHA256Hash(storageKeySignature);
|
|
5406
|
+
return storageKey;
|
|
5407
|
+
};
|
|
5408
|
+
_snapSignMessage = new WeakSet();
|
|
5409
|
+
snapSignMessage_fn = function(message) {
|
|
5410
|
+
return this.messagingSystem.call(
|
|
5411
|
+
"SnapController:handleRequest",
|
|
5412
|
+
createSnapSignMessageRequest(message)
|
|
5413
|
+
);
|
|
5414
|
+
};
|
|
5415
|
+
_setIsProfileSyncingUpdateLoading = new WeakSet();
|
|
5416
|
+
setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
|
|
5417
|
+
this.update((state) => {
|
|
5418
|
+
state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;
|
|
5419
|
+
});
|
|
5420
|
+
};
|
|
5421
|
+
|
|
5422
|
+
// ../profile-sync-controller/src/controllers/user-storage/__fixtures__/index.ts
|
|
5423
|
+
var fixtures_exports = {};
|
|
5424
|
+
__export(fixtures_exports, {
|
|
5425
|
+
MOCK_ENCRYPTED_STORAGE_DATA: () => MOCK_ENCRYPTED_STORAGE_DATA,
|
|
5426
|
+
MOCK_STORAGE_DATA: () => MOCK_STORAGE_DATA,
|
|
5427
|
+
MOCK_STORAGE_KEY: () => MOCK_STORAGE_KEY,
|
|
5428
|
+
MOCK_STORAGE_KEY_SIGNATURE: () => MOCK_STORAGE_KEY_SIGNATURE,
|
|
5429
|
+
MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT: () => MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
|
|
5430
|
+
getMockUserStorageGetResponse: () => getMockUserStorageGetResponse,
|
|
5431
|
+
getMockUserStoragePutResponse: () => getMockUserStoragePutResponse,
|
|
5432
|
+
mockEndpointGetUserStorage: () => mockEndpointGetUserStorage,
|
|
5433
|
+
mockEndpointUpsertUserStorage: () => mockEndpointUpsertUserStorage
|
|
5434
|
+
});
|
|
5435
|
+
|
|
5436
|
+
// ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockStorage.ts
|
|
5437
|
+
var MOCK_STORAGE_KEY_SIGNATURE = "mockStorageKey";
|
|
5438
|
+
var MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);
|
|
5439
|
+
var MOCK_STORAGE_DATA = JSON.stringify({ hello: "world" });
|
|
5440
|
+
var MOCK_ENCRYPTED_STORAGE_DATA = encryption_default2.encryptString(
|
|
5441
|
+
MOCK_STORAGE_DATA,
|
|
5442
|
+
MOCK_STORAGE_KEY
|
|
5443
|
+
);
|
|
5444
|
+
|
|
5445
|
+
// ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts
|
|
5446
|
+
var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(
|
|
5447
|
+
"notificationSettings",
|
|
5448
|
+
MOCK_STORAGE_KEY
|
|
5449
|
+
)}`;
|
|
5450
|
+
var MOCK_GET_USER_STORAGE_RESPONSE = {
|
|
5451
|
+
HashedKey: "HASHED_KEY",
|
|
5452
|
+
Data: MOCK_ENCRYPTED_STORAGE_DATA
|
|
5453
|
+
};
|
|
5454
|
+
var getMockUserStorageGetResponse = () => {
|
|
4248
5455
|
return {
|
|
4249
|
-
url:
|
|
4250
|
-
requestMethod: "
|
|
4251
|
-
response:
|
|
5456
|
+
url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
|
|
5457
|
+
requestMethod: "GET",
|
|
5458
|
+
response: MOCK_GET_USER_STORAGE_RESPONSE
|
|
4252
5459
|
};
|
|
4253
5460
|
};
|
|
4254
|
-
var
|
|
5461
|
+
var getMockUserStoragePutResponse = () => {
|
|
4255
5462
|
return {
|
|
4256
|
-
url:
|
|
4257
|
-
requestMethod: "
|
|
5463
|
+
url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
|
|
5464
|
+
requestMethod: "PUT",
|
|
4258
5465
|
response: null
|
|
4259
5466
|
};
|
|
4260
5467
|
};
|
|
4261
5468
|
|
|
4262
|
-
// src/
|
|
5469
|
+
// ../profile-sync-controller/src/controllers/user-storage/__fixtures__/mockServices.ts
|
|
4263
5470
|
var import_nock = __toESM(require_nock());
|
|
4264
|
-
var
|
|
4265
|
-
const mockResponse =
|
|
4266
|
-
const reply = mockReply ?? {
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
};
|
|
4270
|
-
|
|
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);
|
|
5471
|
+
var mockEndpointGetUserStorage = (mockReply) => {
|
|
5472
|
+
const mockResponse = getMockUserStorageGetResponse();
|
|
5473
|
+
const reply = mockReply ?? {
|
|
5474
|
+
status: 200,
|
|
5475
|
+
body: mockResponse.response
|
|
5476
|
+
};
|
|
5477
|
+
const mockEndpoint = (0, import_nock.default)(mockResponse.url).get("").reply(reply.status, reply.body);
|
|
4286
5478
|
return mockEndpoint;
|
|
4287
5479
|
};
|
|
4288
|
-
var
|
|
4289
|
-
const mockResponse =
|
|
4290
|
-
const
|
|
4291
|
-
const mockEndpoint = (0, import_nock.default)(mockResponse.url).post("").reply(reply.status, reply.body);
|
|
5480
|
+
var mockEndpointUpsertUserStorage = (mockReply) => {
|
|
5481
|
+
const mockResponse = getMockUserStoragePutResponse();
|
|
5482
|
+
const mockEndpoint = (0, import_nock.default)(mockResponse.url).put("").reply(mockReply?.status ?? 204);
|
|
4292
5483
|
return mockEndpoint;
|
|
4293
5484
|
};
|
|
4294
5485
|
|
|
5486
|
+
// src/NotificationServicesController/services/onchain-notifications.ts
|
|
5487
|
+
import log2 from "loglevel";
|
|
5488
|
+
var TRIGGER_API = "https://trigger.api.cx.metamask.io";
|
|
5489
|
+
var NOTIFICATION_API = "https://notification.api.cx.metamask.io";
|
|
5490
|
+
var TRIGGER_API_BATCH_ENDPOINT = `${TRIGGER_API}/api/v1/triggers/batch`;
|
|
5491
|
+
var NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v1/notifications`;
|
|
5492
|
+
var NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY = (page) => `${NOTIFICATION_API_LIST_ENDPOINT}?page=${page}&per_page=100`;
|
|
5493
|
+
var NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/api/v1/notifications/mark-as-read`;
|
|
5494
|
+
async function createOnChainTriggers(userStorage, storageKey, bearerToken, triggers) {
|
|
5495
|
+
const triggersToCreate = triggers.map((t) => ({
|
|
5496
|
+
id: t.id,
|
|
5497
|
+
token: user_storage_exports.createSHA256Hash(t.id + storageKey),
|
|
5498
|
+
config: {
|
|
5499
|
+
kind: t.kind,
|
|
5500
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5501
|
+
chain_id: Number(t.chainId),
|
|
5502
|
+
address: t.address
|
|
5503
|
+
}
|
|
5504
|
+
}));
|
|
5505
|
+
if (triggersToCreate.length === 0) {
|
|
5506
|
+
return;
|
|
5507
|
+
}
|
|
5508
|
+
const response = await makeApiCall(
|
|
5509
|
+
bearerToken,
|
|
5510
|
+
TRIGGER_API_BATCH_ENDPOINT,
|
|
5511
|
+
"POST",
|
|
5512
|
+
triggersToCreate
|
|
5513
|
+
);
|
|
5514
|
+
if (!response.ok) {
|
|
5515
|
+
const errorData = await response.json().catch(() => void 0);
|
|
5516
|
+
log2.error("Error creating triggers:", errorData);
|
|
5517
|
+
throw new Error("OnChain Notifications - unable to create triggers");
|
|
5518
|
+
}
|
|
5519
|
+
for (const trigger of triggersToCreate) {
|
|
5520
|
+
toggleUserStorageTriggerStatus(
|
|
5521
|
+
userStorage,
|
|
5522
|
+
trigger.config.address,
|
|
5523
|
+
String(trigger.config.chain_id),
|
|
5524
|
+
trigger.id,
|
|
5525
|
+
true
|
|
5526
|
+
);
|
|
5527
|
+
}
|
|
5528
|
+
}
|
|
5529
|
+
async function deleteOnChainTriggers(userStorage, storageKey, bearerToken, uuids) {
|
|
5530
|
+
const triggersToDelete = uuids.map((uuid) => ({
|
|
5531
|
+
id: uuid,
|
|
5532
|
+
token: user_storage_exports.createSHA256Hash(uuid + storageKey)
|
|
5533
|
+
}));
|
|
5534
|
+
try {
|
|
5535
|
+
const response = await makeApiCall(
|
|
5536
|
+
bearerToken,
|
|
5537
|
+
TRIGGER_API_BATCH_ENDPOINT,
|
|
5538
|
+
"DELETE",
|
|
5539
|
+
triggersToDelete
|
|
5540
|
+
);
|
|
5541
|
+
if (!response.ok) {
|
|
5542
|
+
throw new Error(
|
|
5543
|
+
`Failed to delete on-chain notifications for uuids ${uuids.join(", ")}`
|
|
5544
|
+
);
|
|
5545
|
+
}
|
|
5546
|
+
for (const uuid of uuids) {
|
|
5547
|
+
for (const address in userStorage) {
|
|
5548
|
+
if (address in userStorage) {
|
|
5549
|
+
for (const chainId in userStorage[address]) {
|
|
5550
|
+
if (userStorage?.[address]?.[chainId]?.[uuid]) {
|
|
5551
|
+
delete userStorage[address][chainId][uuid];
|
|
5552
|
+
}
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5555
|
+
}
|
|
5556
|
+
}
|
|
5557
|
+
const isEmpty = (obj = {}) => Object.keys(obj).length === 0;
|
|
5558
|
+
for (const address in userStorage) {
|
|
5559
|
+
if (address in userStorage) {
|
|
5560
|
+
for (const chainId in userStorage[address]) {
|
|
5561
|
+
if (isEmpty(userStorage?.[address]?.[chainId])) {
|
|
5562
|
+
delete userStorage[address][chainId];
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
if (isEmpty(userStorage?.[address])) {
|
|
5566
|
+
delete userStorage[address];
|
|
5567
|
+
}
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
} catch (err) {
|
|
5571
|
+
log2.error(
|
|
5572
|
+
`Error deleting on-chain notifications for uuids ${uuids.join(", ")}:`,
|
|
5573
|
+
err
|
|
5574
|
+
);
|
|
5575
|
+
throw err;
|
|
5576
|
+
}
|
|
5577
|
+
return userStorage;
|
|
5578
|
+
}
|
|
5579
|
+
async function getOnChainNotifications(userStorage, bearerToken) {
|
|
5580
|
+
const triggerIds = traverseUserStorageTriggers(userStorage, {
|
|
5581
|
+
mapTrigger: (t) => {
|
|
5582
|
+
if (!t.enabled) {
|
|
5583
|
+
return void 0;
|
|
5584
|
+
}
|
|
5585
|
+
return t.id;
|
|
5586
|
+
}
|
|
5587
|
+
});
|
|
5588
|
+
if (triggerIds.length === 0) {
|
|
5589
|
+
return [];
|
|
5590
|
+
}
|
|
5591
|
+
const onChainNotifications = [];
|
|
5592
|
+
const PAGE_LIMIT = 2;
|
|
5593
|
+
for (let page = 1; page <= PAGE_LIMIT; page++) {
|
|
5594
|
+
try {
|
|
5595
|
+
const response = await makeApiCall(
|
|
5596
|
+
bearerToken,
|
|
5597
|
+
NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY(page),
|
|
5598
|
+
"POST",
|
|
5599
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5600
|
+
{ trigger_ids: triggerIds }
|
|
5601
|
+
);
|
|
5602
|
+
const notifications = await response.json();
|
|
5603
|
+
const transformedNotifications = notifications.map(
|
|
5604
|
+
(n) => {
|
|
5605
|
+
if (!n.data?.kind) {
|
|
5606
|
+
return void 0;
|
|
5607
|
+
}
|
|
5608
|
+
return {
|
|
5609
|
+
...n,
|
|
5610
|
+
type: n.data.kind
|
|
5611
|
+
};
|
|
5612
|
+
}
|
|
5613
|
+
).filter((n) => Boolean(n));
|
|
5614
|
+
onChainNotifications.push(...transformedNotifications);
|
|
5615
|
+
if (notifications.length < 100) {
|
|
5616
|
+
page = PAGE_LIMIT + 1;
|
|
5617
|
+
break;
|
|
5618
|
+
}
|
|
5619
|
+
} catch (err) {
|
|
5620
|
+
log2.error(
|
|
5621
|
+
`Error fetching on-chain notifications for trigger IDs ${triggerIds.join(
|
|
5622
|
+
", "
|
|
5623
|
+
)}:`,
|
|
5624
|
+
err
|
|
5625
|
+
);
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
return onChainNotifications;
|
|
5629
|
+
}
|
|
5630
|
+
async function markNotificationsAsRead(bearerToken, notificationIds) {
|
|
5631
|
+
if (notificationIds.length === 0) {
|
|
5632
|
+
return;
|
|
5633
|
+
}
|
|
5634
|
+
try {
|
|
5635
|
+
const response = await makeApiCall(
|
|
5636
|
+
bearerToken,
|
|
5637
|
+
NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
|
|
5638
|
+
"POST",
|
|
5639
|
+
{ ids: notificationIds }
|
|
5640
|
+
);
|
|
5641
|
+
if (response.status !== 200) {
|
|
5642
|
+
const errorData = await response.json().catch(() => void 0);
|
|
5643
|
+
throw new Error(
|
|
5644
|
+
`Error marking notifications as read: ${errorData?.message}`
|
|
5645
|
+
);
|
|
5646
|
+
}
|
|
5647
|
+
} catch (err) {
|
|
5648
|
+
log2.error("Error marking notifications as read:", err);
|
|
5649
|
+
throw err;
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5652
|
+
|
|
4295
5653
|
export {
|
|
4296
5654
|
require_nock,
|
|
4297
|
-
|
|
4298
|
-
|
|
5655
|
+
TRIGGER_API,
|
|
5656
|
+
NOTIFICATION_API,
|
|
5657
|
+
TRIGGER_API_BATCH_ENDPOINT,
|
|
5658
|
+
NOTIFICATION_API_LIST_ENDPOINT,
|
|
5659
|
+
NOTIFICATION_API_LIST_ENDPOINT_PAGE_QUERY,
|
|
5660
|
+
NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
|
|
5661
|
+
createOnChainTriggers,
|
|
5662
|
+
deleteOnChainTriggers,
|
|
5663
|
+
getOnChainNotifications,
|
|
5664
|
+
markNotificationsAsRead
|
|
4299
5665
|
};
|
|
4300
|
-
|
|
5666
|
+
/*! Bundled license information:
|
|
5667
|
+
|
|
5668
|
+
@noble/ciphers/esm/utils.js:
|
|
5669
|
+
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
5670
|
+
|
|
5671
|
+
@noble/hashes/esm/utils.js:
|
|
5672
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
5673
|
+
*/
|
|
5674
|
+
//# sourceMappingURL=chunk-IG3CMJBW.mjs.map
|