@metamask-previews/multichain-account-service 2.1.0-preview-f8faf75c → 2.1.0-preview-d41a7f35
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/CHANGELOG.md +0 -4
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +2 -2
- package/dist/MultichainAccountGroup.d.mts +2 -2
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService.cjs +1 -40
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +3 -19
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +3 -19
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +1 -40
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts +2 -2
- package/dist/MultichainAccountWallet.d.mts +2 -2
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs +0 -12
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +0 -8
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +0 -8
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs +0 -12
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +3 -13
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +3 -13
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +31 -1
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +3 -1
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +3 -1
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +31 -1
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +0 -4
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +0 -1
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +0 -1
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +0 -4
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +8 -64
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +0 -3
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +0 -3
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +8 -64
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +25 -3
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +25 -3
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +31 -1
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +1 -0
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +1 -0
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +31 -1
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/tests/accounts.cjs +1 -28
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +7 -11
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +7 -11
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +0 -25
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/providers.cjs +0 -1
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +0 -1
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +0 -1
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +0 -1
- package/dist/tests/providers.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -3,11 +3,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _SolAccountProvider_instances, _SolAccountProvider_client, _SolAccountProvider_getKeyringClientFromSnapId, _SolAccountProvider_createAccount;
|
|
7
13
|
import { assertIsBip44Account } from "@metamask/account-api";
|
|
8
14
|
import { SolScope } from "@metamask/keyring-api";
|
|
9
15
|
import { KeyringAccountEntropyTypeOption, SolAccountType } from "@metamask/keyring-api";
|
|
10
16
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
17
|
+
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
18
|
+
import { HandlerType } from "@metamask/snaps-utils";
|
|
11
19
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
12
20
|
import { withRetry, withTimeout } from "./utils.mjs";
|
|
13
21
|
export const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
|
|
@@ -25,6 +33,8 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
25
33
|
}) {
|
|
26
34
|
super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config);
|
|
27
35
|
_SolAccountProvider_instances.add(this);
|
|
36
|
+
_SolAccountProvider_client.set(this, void 0);
|
|
37
|
+
__classPrivateFieldSet(this, _SolAccountProvider_client, __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getKeyringClientFromSnapId).call(this, SolAccountProvider.SOLANA_SNAP_ID), "f");
|
|
28
38
|
}
|
|
29
39
|
getName() {
|
|
30
40
|
return SolAccountProvider.NAME;
|
|
@@ -45,7 +55,7 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
57
|
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
48
|
-
const discoveredAccounts = await withRetry(() => withTimeout(this.
|
|
58
|
+
const discoveredAccounts = await withRetry(() => withTimeout(__classPrivateFieldGet(this, _SolAccountProvider_client, "f").discoverAccounts([SolScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
49
59
|
maxAttempts: this.config.discovery.maxAttempts,
|
|
50
60
|
backOffMs: this.config.discovery.backOffMs,
|
|
51
61
|
});
|
|
@@ -60,7 +70,19 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
60
70
|
return createdAccounts;
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
|
-
|
|
73
|
+
_SolAccountProvider_client = new WeakMap(), _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getKeyringClientFromSnapId = function _SolAccountProvider_getKeyringClientFromSnapId(snapId) {
|
|
74
|
+
return new KeyringClient({
|
|
75
|
+
send: async (request) => {
|
|
76
|
+
const response = await this.messenger.call('SnapController:handleRequest', {
|
|
77
|
+
snapId: snapId,
|
|
78
|
+
origin: 'metamask',
|
|
79
|
+
handler: HandlerType.OnKeyringRequest,
|
|
80
|
+
request,
|
|
81
|
+
});
|
|
82
|
+
return response;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}, _SolAccountProvider_createAccount = async function _SolAccountProvider_createAccount({ entropySource, groupIndex, derivationPath, }) {
|
|
64
86
|
const createAccount = await this.getRestrictedSnapAccountCreator();
|
|
65
87
|
const account = await withTimeout(createAccount({ entropySource, derivationPath }), this.config.createAccounts.timeoutMs);
|
|
66
88
|
// Ensure entropy is present before type assertion validation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAqB,8BAA8B;AAEhF,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAGpD,OAAO,EACL,mBAAmB,EAEpB,kCAA8B;AAC/B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAKjD,M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D,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;IAEF,6DAA6D;IAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;QACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;QAC9C,EAAE,EAAE,aAAa;QACjB,UAAU;QACV,cAAc;KACf,CAAC;IAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA/EM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { SolScope } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport {\n SnapAccountProvider,\n type SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type SolAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana' as const;\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static NAME = SOL_ACCOUNT_PROVIDER_NAME;\n\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n },\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config);\n this.#client = this.#getKeyringClientFromSnapId(\n SolAccountProvider.SOLANA_SNAP_ID,\n );\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async #createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n derivationPath: string;\n }): Promise<Bip44Account<KeyringAccount>> {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n const account = await withTimeout(\n createAccount({ entropySource, derivationPath }),\n this.config.createAccounts.timeoutMs,\n );\n\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n return account;\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath,\n });\n\n return [account];\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n this.#client.discoverAccounts(\n [SolScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await Promise.all(\n discoveredAccounts.map((d) =>\n this.#createAccount({\n entropySource,\n groupIndex,\n derivationPath: d.derivationPath,\n }),\n ),\n );\n\n return createdAccounts;\n }\n}\n"]}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _TrxAccountProvider_instances, _TrxAccountProvider_client, _TrxAccountProvider_getKeyringClientFromSnapId;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.TrxAccountProvider = exports.TRX_ACCOUNT_PROVIDER_NAME = void 0;
|
|
4
16
|
const account_api_1 = require("@metamask/account-api");
|
|
5
17
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
6
18
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
19
|
+
const keyring_snap_client_1 = require("@metamask/keyring-snap-client");
|
|
20
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
21
|
const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
|
|
8
22
|
const utils_1 = require("./utils.cjs");
|
|
9
23
|
exports.TRX_ACCOUNT_PROVIDER_NAME = 'Tron';
|
|
@@ -20,6 +34,9 @@ class TrxAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
20
34
|
},
|
|
21
35
|
}) {
|
|
22
36
|
super(TrxAccountProvider.TRX_SNAP_ID, messenger, config);
|
|
37
|
+
_TrxAccountProvider_instances.add(this);
|
|
38
|
+
_TrxAccountProvider_client.set(this, void 0);
|
|
39
|
+
__classPrivateFieldSet(this, _TrxAccountProvider_client, __classPrivateFieldGet(this, _TrxAccountProvider_instances, "m", _TrxAccountProvider_getKeyringClientFromSnapId).call(this, TrxAccountProvider.TRX_SNAP_ID), "f");
|
|
23
40
|
}
|
|
24
41
|
getName() {
|
|
25
42
|
return TrxAccountProvider.NAME;
|
|
@@ -42,7 +59,7 @@ class TrxAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
42
59
|
});
|
|
43
60
|
}
|
|
44
61
|
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
45
|
-
const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(this.
|
|
62
|
+
const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(__classPrivateFieldGet(this, _TrxAccountProvider_client, "f").discoverAccounts([keyring_api_1.TrxScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
46
63
|
maxAttempts: this.config.discovery.maxAttempts,
|
|
47
64
|
backOffMs: this.config.discovery.backOffMs,
|
|
48
65
|
});
|
|
@@ -57,6 +74,19 @@ class TrxAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
57
74
|
}
|
|
58
75
|
}
|
|
59
76
|
exports.TrxAccountProvider = TrxAccountProvider;
|
|
77
|
+
_TrxAccountProvider_client = new WeakMap(), _TrxAccountProvider_instances = new WeakSet(), _TrxAccountProvider_getKeyringClientFromSnapId = function _TrxAccountProvider_getKeyringClientFromSnapId(snapId) {
|
|
78
|
+
return new keyring_snap_client_1.KeyringClient({
|
|
79
|
+
send: async (request) => {
|
|
80
|
+
const response = await this.messenger.call('SnapController:handleRequest', {
|
|
81
|
+
snapId: snapId,
|
|
82
|
+
origin: 'metamask',
|
|
83
|
+
handler: snaps_utils_1.HandlerType.OnKeyringRequest,
|
|
84
|
+
request,
|
|
85
|
+
});
|
|
86
|
+
return response;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
};
|
|
60
90
|
TrxAccountProvider.NAME = exports.TRX_ACCOUNT_PROVIDER_NAME;
|
|
61
91
|
TrxAccountProvider.TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap';
|
|
62
92
|
//# sourceMappingURL=TrxAccountProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAgF;AAEhF,uDAAiE;AACjE,qEAA4D;AAE5D,uEAA8D;AAE9D,uDAAoD;AAGpD,mEAG+B;AAC/B,uCAAiD;AAKpC,QAAA,yBAAyB,GAAG,MAAe,CAAC;AAEzD,MAAa,kBAAmB,SAAQ,yCAAmB;IAOzD,YACE,SAA4C,EAC5C,SAAmC;QACjC,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE;YACT,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,IAAI;SAChB;QACD,cAAc,EAAE;YACd,SAAS,EAAE,I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AO,CAAC,EAClB,aAAa,EACb,UAAU,CACX,EACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAChC,EACH;YACE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW;YAC9C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;SAC3C,CACF,CAAC;QAEF,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;YAC9B,OAAO,EAAE,CAAC;SACX;QAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YAChD,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;IACzB,CAAC;;AAjHH,gDAkHC;oMAnF6B,MAAc;IACxC,OAAO,IAAI,mCAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,yBAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AA7CM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { TrxAccountType, TrxScope } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport {\n SnapAccountProvider,\n type SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron' as const;\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n },\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config);\n this.#client = this.#getKeyringClientFromSnapId(\n TrxAccountProvider.TRX_SNAP_ID,\n );\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex: index,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n const account = await withTimeout(\n createAccount({\n entropySource,\n index,\n addressType: TrxAccountType.Eoa,\n scope: TrxScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n this.#client.discoverAccounts(\n [TrxScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await this.createAccounts({\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n }\n}\n"]}
|
|
@@ -7,6 +7,7 @@ import type { MultichainAccountServiceMessenger } from "../types.cjs";
|
|
|
7
7
|
export type TrxAccountProviderConfig = SnapAccountProviderConfig;
|
|
8
8
|
export declare const TRX_ACCOUNT_PROVIDER_NAME: "Tron";
|
|
9
9
|
export declare class TrxAccountProvider extends SnapAccountProvider {
|
|
10
|
+
#private;
|
|
10
11
|
static NAME: "Tron";
|
|
11
12
|
static TRX_SNAP_ID: SnapId;
|
|
12
13
|
constructor(messenger: MultichainAccountServiceMessenger, config?: TrxAccountProviderConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrxAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;
|
|
1
|
+
{"version":3,"file":"TrxAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAIlD,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC/B,kCAA8B;AAE/B,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,QAAkB,CAAC;AAEzD,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAA8C;gBAK9D,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAUP;IAQH,OAAO,IAAI,MAAM;IAqBjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,EAAE,KAAK,GAClB,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAmBrC,gBAAgB,CAAC,EACrB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA4B5C"}
|
|
@@ -7,6 +7,7 @@ import type { MultichainAccountServiceMessenger } from "../types.mjs";
|
|
|
7
7
|
export type TrxAccountProviderConfig = SnapAccountProviderConfig;
|
|
8
8
|
export declare const TRX_ACCOUNT_PROVIDER_NAME: "Tron";
|
|
9
9
|
export declare class TrxAccountProvider extends SnapAccountProvider {
|
|
10
|
+
#private;
|
|
10
11
|
static NAME: "Tron";
|
|
11
12
|
static TRX_SNAP_ID: SnapId;
|
|
12
13
|
constructor(messenger: MultichainAccountServiceMessenger, config?: TrxAccountProviderConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrxAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;
|
|
1
|
+
{"version":3,"file":"TrxAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAG7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAIlD,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC/B,kCAA8B;AAE/B,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,QAAkB,CAAC;AAEzD,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAA8C;gBAK9D,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAUP;IAQH,OAAO,IAAI,MAAM;IAqBjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,EAAE,KAAK,GAClB,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAmBrC,gBAAgB,CAAC,EACrB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CA4B5C"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _TrxAccountProvider_instances, _TrxAccountProvider_client, _TrxAccountProvider_getKeyringClientFromSnapId;
|
|
1
13
|
import { assertIsBip44Account } from "@metamask/account-api";
|
|
2
14
|
import { TrxAccountType, TrxScope } from "@metamask/keyring-api";
|
|
3
15
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
16
|
+
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
17
|
+
import { HandlerType } from "@metamask/snaps-utils";
|
|
4
18
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
5
19
|
import { withRetry, withTimeout } from "./utils.mjs";
|
|
6
20
|
export const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';
|
|
@@ -17,6 +31,9 @@ export class TrxAccountProvider extends SnapAccountProvider {
|
|
|
17
31
|
},
|
|
18
32
|
}) {
|
|
19
33
|
super(TrxAccountProvider.TRX_SNAP_ID, messenger, config);
|
|
34
|
+
_TrxAccountProvider_instances.add(this);
|
|
35
|
+
_TrxAccountProvider_client.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _TrxAccountProvider_client, __classPrivateFieldGet(this, _TrxAccountProvider_instances, "m", _TrxAccountProvider_getKeyringClientFromSnapId).call(this, TrxAccountProvider.TRX_SNAP_ID), "f");
|
|
20
37
|
}
|
|
21
38
|
getName() {
|
|
22
39
|
return TrxAccountProvider.NAME;
|
|
@@ -39,7 +56,7 @@ export class TrxAccountProvider extends SnapAccountProvider {
|
|
|
39
56
|
});
|
|
40
57
|
}
|
|
41
58
|
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
42
|
-
const discoveredAccounts = await withRetry(() => withTimeout(this.
|
|
59
|
+
const discoveredAccounts = await withRetry(() => withTimeout(__classPrivateFieldGet(this, _TrxAccountProvider_client, "f").discoverAccounts([TrxScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
43
60
|
maxAttempts: this.config.discovery.maxAttempts,
|
|
44
61
|
backOffMs: this.config.discovery.backOffMs,
|
|
45
62
|
});
|
|
@@ -53,6 +70,19 @@ export class TrxAccountProvider extends SnapAccountProvider {
|
|
|
53
70
|
return createdAccounts;
|
|
54
71
|
}
|
|
55
72
|
}
|
|
73
|
+
_TrxAccountProvider_client = new WeakMap(), _TrxAccountProvider_instances = new WeakSet(), _TrxAccountProvider_getKeyringClientFromSnapId = function _TrxAccountProvider_getKeyringClientFromSnapId(snapId) {
|
|
74
|
+
return new KeyringClient({
|
|
75
|
+
send: async (request) => {
|
|
76
|
+
const response = await this.messenger.call('SnapController:handleRequest', {
|
|
77
|
+
snapId: snapId,
|
|
78
|
+
origin: 'metamask',
|
|
79
|
+
handler: HandlerType.OnKeyringRequest,
|
|
80
|
+
request,
|
|
81
|
+
});
|
|
82
|
+
return response;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
};
|
|
56
86
|
TrxAccountProvider.NAME = TRX_ACCOUNT_PROVIDER_NAME;
|
|
57
87
|
TrxAccountProvider.TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap';
|
|
58
88
|
//# sourceMappingURL=TrxAccountProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrxAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAqB,8BAA8B;AAEhF,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AACjE,OAAO,EAAE,YAAY,EAAE,qCAAqC;
|
|
1
|
+
{"version":3,"file":"TrxAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAqB,8BAA8B;AAEhF,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AACjE,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAGpD,OAAO,EACL,mBAAmB,EAEpB,kCAA8B;AAC/B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAgB;AAKjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAe,CAAC;AAEzD,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAOzD,YACE,SAA4C,EAC5C,SAAmC;QACjC,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE;YACT,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,IAAI;SAChB;QACD,cAAc,EAAE;YACd,SAAS,EAAE,IAAI;SAChB;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AI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAChC,EACH;YACE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW;YAC9C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;SAC3C,CACF,CAAC;QAEF,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;YAC9B,OAAO,EAAE,CAAC;SACX;QAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YAChD,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;IACzB,CAAC;;oMAlF2B,MAAc;IACxC,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,8BAA8B,EAC9B;gBACE,MAAM,EAAE,MAAgB;gBACxB,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;gBACrC,OAAO;aACR,CACF,CAAC;YACF,OAAO,QAAgB,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AA7CM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","sourcesContent":["import { assertIsBip44Account, type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { TrxAccountType, TrxScope } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\n\nimport {\n SnapAccountProvider,\n type SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron' as const;\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n readonly #client: KeyringClient;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n },\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config);\n this.#client = this.#getKeyringClientFromSnapId(\n TrxAccountProvider.TRX_SNAP_ID,\n );\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n #getKeyringClientFromSnapId(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) => {\n const response = await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n },\n );\n return response as Json;\n },\n });\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex: index,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const createAccount = await this.getRestrictedSnapAccountCreator();\n\n const account = await withTimeout(\n createAccount({\n entropySource,\n index,\n addressType: TrxAccountType.Eoa,\n scope: TrxScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n return [account];\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n this.#client.discoverAccounts(\n [TrxScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (!discoveredAccounts.length) {\n return [];\n }\n\n const createdAccounts = await this.createAccounts({\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n }\n}\n"]}
|
package/dist/tests/accounts.cjs
CHANGED
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _MockAccountBuilder_account;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.mockAsInternalAccount = exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = exports.MOCK_WALLET_1_SOL_ACCOUNT = exports.MOCK_WALLET_1_EVM_ACCOUNT = exports.MOCK_WALLET_1_ENTROPY_SOURCE = exports.MockAccountBuilder = exports.
|
|
15
|
+
exports.mockAsInternalAccount = exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = exports.MOCK_WALLET_1_SOL_ACCOUNT = exports.MOCK_WALLET_1_EVM_ACCOUNT = exports.MOCK_WALLET_1_ENTROPY_SOURCE = exports.MockAccountBuilder = exports.MOCK_HARDWARE_ACCOUNT_1 = exports.MOCK_SNAP_ACCOUNT_4 = exports.MOCK_SNAP_ACCOUNT_3 = exports.MOCK_SNAP_ACCOUNT_2 = exports.MOCK_SNAP_ACCOUNT_1 = exports.MOCK_BTC_P2TR_ACCOUNT_1 = exports.MOCK_BTC_P2WPKH_ACCOUNT_1 = exports.MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1 = exports.MOCK_TRX_DISCOVERED_ACCOUNT_1 = exports.MOCK_SOL_DISCOVERED_ACCOUNT_1 = exports.MOCK_TRX_ACCOUNT_1 = exports.MOCK_SOL_ACCOUNT_1 = exports.MOCK_HD_ACCOUNT_2 = exports.MOCK_HD_ACCOUNT_1 = exports.MOCK_HD_KEYRING_2 = exports.MOCK_HD_KEYRING_1 = exports.MOCK_MNEMONIC = exports.MOCK_ENTROPY_SOURCE_2 = exports.MOCK_ENTROPY_SOURCE_1 = exports.MOCK_SNAP_2 = exports.MOCK_SNAP_1 = exports.ETH_EOA_METHODS = void 0;
|
|
16
16
|
const account_api_1 = require("@metamask/account-api");
|
|
17
17
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
18
18
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
@@ -248,23 +248,6 @@ exports.MOCK_HARDWARE_ACCOUNT_1 = {
|
|
|
248
248
|
lastSelected: 0,
|
|
249
249
|
},
|
|
250
250
|
};
|
|
251
|
-
function isInternalAccount(account) {
|
|
252
|
-
// Meant to be used for testing, so we keep this simple.
|
|
253
|
-
return Object.prototype.hasOwnProperty.call(account, 'metadata');
|
|
254
|
-
}
|
|
255
|
-
exports.isInternalAccount = isInternalAccount;
|
|
256
|
-
function asKeyringAccount(account) {
|
|
257
|
-
const { id, type, address, scopes, options, methods } = account;
|
|
258
|
-
return {
|
|
259
|
-
id,
|
|
260
|
-
type,
|
|
261
|
-
address,
|
|
262
|
-
scopes,
|
|
263
|
-
options,
|
|
264
|
-
methods,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
exports.asKeyringAccount = asKeyringAccount;
|
|
268
251
|
class MockAccountBuilder {
|
|
269
252
|
constructor(account) {
|
|
270
253
|
_MockAccountBuilder_account.set(this, void 0);
|
|
@@ -298,16 +281,6 @@ class MockAccountBuilder {
|
|
|
298
281
|
}
|
|
299
282
|
return this;
|
|
300
283
|
}
|
|
301
|
-
withSnapId(snapId) {
|
|
302
|
-
if (isInternalAccount(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
|
|
303
|
-
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").metadata.snap = {
|
|
304
|
-
enabled: true,
|
|
305
|
-
id: snapId,
|
|
306
|
-
name: `Name: ${snapId}`,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return this;
|
|
310
|
-
}
|
|
311
284
|
get() {
|
|
312
285
|
return __classPrivateFieldGet(this, _MockAccountBuilder_account, "f");
|
|
313
286
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,uDAAuD;AAMvD,uDAc+B;AAC/B,qEAA4D;AAG5D,+BAAkC;AAErB,QAAA,eAAe,GAAG;IAC7B,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAE5C,QAAA,aAAa,GACxB,sFAAsF,CAAC;AAE5E,Q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A4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AAET,SAAgB,qBAAqB,CACnC,OAAuB;IAEvB,OAAO;QACL,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,gBAAgB;YACtB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,OAAO,EAAE;gBACP,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF,CAAC;AACJ,CAAC;AAbD,sDAaC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\nimport type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type {\n DiscoveredAccount,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n TrxAccountType,\n TrxMethod,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { v4 as uuid } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_MNEMONIC =\n 'abandon ability able about above absent absorb abstract absurd abuse access accident';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_TRX_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [TrxMethod.SignMessageV2, TrxMethod.VerifyMessageV2],\n type: TrxAccountType.Eoa,\n scopes: [TrxScope.Mainnet],\n metadata: {\n name: 'Tron Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SOL_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [SolScope.Mainnet],\n derivationPath: `m/44'/501'/0'/0'`,\n};\n\nexport const MOCK_TRX_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [TrxScope.Mainnet],\n derivationPath: `m/44'/195'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [BtcScope.Mainnet],\n derivationPath: `m/44'/0'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: Object.values(BtcMethod),\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: Object.values(BtcMethod),\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport function isInternalAccount(\n account: KeyringAccount,\n): account is InternalAccount {\n // Meant to be used for testing, so we keep this simple.\n return Object.prototype.hasOwnProperty.call(account, 'metadata');\n}\n\nexport function asKeyringAccount<Account extends KeyringAccount>(\n account: Account,\n): KeyringAccount {\n const { id, type, address, scopes, options, methods } = account;\n\n return {\n id,\n type,\n address,\n scopes,\n options,\n methods,\n };\n}\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n withSnapId(snapId: SnapId) {\n if (isInternalAccount(this.#account)) {\n this.#account.metadata.snap = {\n enabled: true,\n id: snapId,\n name: `Name: ${snapId}`,\n };\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n\nexport function mockAsInternalAccount(\n account: KeyringAccount,\n): InternalAccount {\n return {\n ...account,\n metadata: {\n name: 'Mocked Account',\n importTime: Date.now(),\n keyring: {\n type: 'mock-keyring-type',\n },\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,uDAAuD;AAMvD,uDAc+B;AAC/B,qEAA4D;AAE5D,+BAAkC;AAErB,QAAA,eAAe,GAAG;IAC7B,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAE5C,QAAA,aAAa,GACxB,sFAAsF,CAAC;AAE5E,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,EAAE,EAAE,6BAAqB,EAAE,IAAI,EAAE,cAAc,EAAE;IAC7D,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,EAAE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,uBAAA,IAAI,mCAAS,CAAC,EAAE;YACjC,uBAAA,IAAI,mCAAS,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;SACvD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG;QACD,OAAO,uBAAA,IAAI,mCAAS,CAAC;IACvB,CAAC;CACF;AA9CD,gDA8CC;;AAEY,QAAA,4BAA4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AAET,SAAgB,qBAAqB,CACnC,OAAuB;IAEvB,OAAO;QACL,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,gBAAgB;YACtB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,OAAO,EAAE;gBACP,IAAI,EAAE,mBAAmB;aAC1B;SACF;KACF,CAAC;AACJ,CAAC;AAbD,sDAaC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\nimport type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type {\n DiscoveredAccount,\n EntropySourceId,\n KeyringAccount,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n TrxAccountType,\n TrxMethod,\n TrxScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { v4 as uuid } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_MNEMONIC =\n 'abandon ability able about above absent absorb abstract absurd abuse access accident';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_TRX_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [TrxMethod.SignMessageV2, TrxMethod.VerifyMessageV2],\n type: TrxAccountType.Eoa,\n scopes: [TrxScope.Mainnet],\n metadata: {\n name: 'Tron Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SOL_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [SolScope.Mainnet],\n derivationPath: `m/44'/501'/0'/0'`,\n};\n\nexport const MOCK_TRX_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [TrxScope.Mainnet],\n derivationPath: `m/44'/195'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1: DiscoveredAccount = {\n type: 'bip44',\n scopes: [BtcScope.Mainnet],\n derivationPath: `m/44'/0'/0'/0'`,\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: Object.values(BtcMethod),\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: Object.values(BtcMethod),\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: KeyringTypes.snap,\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n\nexport function mockAsInternalAccount(\n account: KeyringAccount,\n): InternalAccount {\n return {\n ...account,\n metadata: {\n name: 'Mocked Account',\n importTime: Date.now(),\n keyring: {\n type: 'mock-keyring-type',\n },\n },\n };\n}\n"]}
|
|
@@ -3,7 +3,6 @@ import type { DiscoveredAccount, EntropySourceId, KeyringAccount } from "@metama
|
|
|
3
3
|
import { EthMethod } from "@metamask/keyring-api";
|
|
4
4
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
5
5
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
|
-
import type { SnapId } from "@metamask/snaps-sdk";
|
|
7
6
|
export declare const ETH_EOA_METHODS: readonly [EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4];
|
|
8
7
|
export declare const MOCK_SNAP_1: {
|
|
9
8
|
id: string;
|
|
@@ -52,7 +51,7 @@ export declare const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount>;
|
|
|
52
51
|
export declare const MOCK_SNAP_ACCOUNT_1: Bip44Account<{
|
|
53
52
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
54
53
|
id: string;
|
|
55
|
-
options: Record<string, import("@metamask/
|
|
54
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
56
55
|
entropy?: {
|
|
57
56
|
type: "mnemonic";
|
|
58
57
|
id: string;
|
|
@@ -85,7 +84,7 @@ export declare const MOCK_SNAP_ACCOUNT_2: InternalAccount;
|
|
|
85
84
|
export declare const MOCK_SNAP_ACCOUNT_3: Bip44Account<{
|
|
86
85
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
87
86
|
id: string;
|
|
88
|
-
options: Record<string, import("@metamask/
|
|
87
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
89
88
|
entropy?: {
|
|
90
89
|
type: "mnemonic";
|
|
91
90
|
id: string;
|
|
@@ -117,7 +116,7 @@ export declare const MOCK_SNAP_ACCOUNT_3: Bip44Account<{
|
|
|
117
116
|
export declare const MOCK_SNAP_ACCOUNT_4: Bip44Account<{
|
|
118
117
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
119
118
|
id: string;
|
|
120
|
-
options: Record<string, import("@metamask/
|
|
119
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
121
120
|
entropy?: {
|
|
122
121
|
type: "mnemonic";
|
|
123
122
|
id: string;
|
|
@@ -147,8 +146,6 @@ export declare const MOCK_SNAP_ACCOUNT_4: Bip44Account<{
|
|
|
147
146
|
methods: string[];
|
|
148
147
|
}>;
|
|
149
148
|
export declare const MOCK_HARDWARE_ACCOUNT_1: InternalAccount;
|
|
150
|
-
export declare function isInternalAccount(account: KeyringAccount): account is InternalAccount;
|
|
151
|
-
export declare function asKeyringAccount<Account extends KeyringAccount>(account: Account): KeyringAccount;
|
|
152
149
|
export declare class MockAccountBuilder<Account extends KeyringAccount> {
|
|
153
150
|
#private;
|
|
154
151
|
constructor(account: Account);
|
|
@@ -158,14 +155,13 @@ export declare class MockAccountBuilder<Account extends KeyringAccount> {
|
|
|
158
155
|
withAddressSuffix(suffix: string): this;
|
|
159
156
|
withEntropySource(entropySource: EntropySourceId): this;
|
|
160
157
|
withGroupIndex(groupIndex: number): this;
|
|
161
|
-
withSnapId(snapId: SnapId): this;
|
|
162
158
|
get(): Account;
|
|
163
159
|
}
|
|
164
160
|
export declare const MOCK_WALLET_1_ENTROPY_SOURCE = "mock-keyring-id-1";
|
|
165
161
|
export declare const MOCK_WALLET_1_EVM_ACCOUNT: Bip44Account<{
|
|
166
162
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
167
163
|
id: string;
|
|
168
|
-
options: Record<string, import("@metamask/
|
|
164
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
169
165
|
entropy?: {
|
|
170
166
|
type: "mnemonic";
|
|
171
167
|
id: string;
|
|
@@ -197,7 +193,7 @@ export declare const MOCK_WALLET_1_EVM_ACCOUNT: Bip44Account<{
|
|
|
197
193
|
export declare const MOCK_WALLET_1_SOL_ACCOUNT: Bip44Account<{
|
|
198
194
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
199
195
|
id: string;
|
|
200
|
-
options: Record<string, import("@metamask/
|
|
196
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
201
197
|
entropy?: {
|
|
202
198
|
type: "mnemonic";
|
|
203
199
|
id: string;
|
|
@@ -229,7 +225,7 @@ export declare const MOCK_WALLET_1_SOL_ACCOUNT: Bip44Account<{
|
|
|
229
225
|
export declare const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT: Bip44Account<{
|
|
230
226
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
231
227
|
id: string;
|
|
232
|
-
options: Record<string, import("@metamask/
|
|
228
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
233
229
|
entropy?: {
|
|
234
230
|
type: "mnemonic";
|
|
235
231
|
id: string;
|
|
@@ -261,7 +257,7 @@ export declare const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT: Bip44Account<{
|
|
|
261
257
|
export declare const MOCK_WALLET_1_BTC_P2TR_ACCOUNT: Bip44Account<{
|
|
262
258
|
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
263
259
|
id: string;
|
|
264
|
-
options: Record<string, import("@metamask/
|
|
260
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
265
261
|
entropy?: {
|
|
266
262
|
type: "mnemonic";
|
|
267
263
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAKL,SAAS,EASV,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;
|
|
1
|
+
{"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAE1D,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAKL,SAAS,EASV,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,eAAO,MAAM,eAAe,+JAOlB,CAAC;AAIX,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAC;AAEF,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AAEzD,eAAO,MAAM,aAAa,yFAC8D,CAAC;AAEzF,eAAO,MAAM,iBAAiB;;;;;;;CAI7B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;CAI7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,eAAe,CAqB3D,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,eAAe,CAqB3D,CAAC;AAEF,eAAO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