UNPKG

@metamask/multichain-account-service

Version:
276 lines 9.39 kB
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); 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"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); 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"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _MockAccountBuilder_account; import { isBip44Account } from "@metamask/account-api"; import { BtcAccountType, BtcMethod, BtcScope, EthAccountType, EthMethod, EthScope, KeyringAccountEntropyTypeOption, SolAccountType, SolMethod, SolScope } from "@metamask/keyring-api"; import { KeyringTypes } from "@metamask/keyring-controller"; import { v4 as uuid } from "uuid"; const ETH_EOA_METHODS = [ EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4, ]; const SOL_METHODS = Object.values(SolMethod); export const MOCK_SNAP_1 = { id: 'local:mock-snap-id-1', name: 'Mock Snap 1', enabled: true, manifest: { proposedName: 'Mock Snap 1', }, }; export const MOCK_SNAP_2 = { id: 'local:mock-snap-id-2', name: 'Mock Snap 2', enabled: true, manifest: { proposedName: 'Mock Snap 2', }, }; export const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1'; export const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2'; export const MOCK_HD_KEYRING_1 = { type: KeyringTypes.hd, metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' }, accounts: ['0x123'], }; export const MOCK_HD_KEYRING_2 = { type: KeyringTypes.hd, metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' }, accounts: ['0x456'], }; export const MOCK_HD_ACCOUNT_1 = { id: 'mock-id-1', address: '0x123', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, id: MOCK_HD_KEYRING_1.metadata.id, groupIndex: 0, derivationPath: '', }, }, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], metadata: { name: 'Account 1', keyring: { type: KeyringTypes.hd }, importTime: 0, lastSelected: 0, nameLastUpdatedAt: 0, }, }; export const MOCK_HD_ACCOUNT_2 = { id: 'mock-id-2', address: '0x456', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, id: MOCK_HD_KEYRING_2.metadata.id, groupIndex: 0, derivationPath: '', }, }, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], metadata: { name: 'Account 2', keyring: { type: KeyringTypes.hd }, importTime: 0, lastSelected: 0, nameLastUpdatedAt: 0, }, }; export const MOCK_SOL_ACCOUNT_1 = { id: 'mock-snap-id-1', address: 'aabbccdd', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, // NOTE: shares entropy with MOCK_HD_ACCOUNT_2 id: MOCK_HD_KEYRING_2.metadata.id, groupIndex: 0, derivationPath: '', }, }, methods: SOL_METHODS, type: SolAccountType.DataAccount, scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet], metadata: { name: 'Solana Account 1', keyring: { type: KeyringTypes.snap }, snap: MOCK_SNAP_1, importTime: 0, lastSelected: 0, }, }; export const MOCK_BTC_P2WPKH_ACCOUNT_1 = { id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db', type: BtcAccountType.P2wpkh, methods: [BtcMethod.SendBitcoin], address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, // NOTE: shares entropy with MOCK_HD_ACCOUNT_2 id: MOCK_HD_KEYRING_2.metadata.id, groupIndex: 0, derivationPath: '', }, }, scopes: [BtcScope.Mainnet], metadata: { name: 'Bitcoin Native Segwit Account 1', importTime: 0, keyring: { type: 'Snap keyring', }, snap: { id: 'mock-btc-snap-id', enabled: true, name: 'Mock Bitcoin Snap', }, }, }; export const MOCK_BTC_P2TR_ACCOUNT_1 = { id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb', type: BtcAccountType.P2tr, methods: [BtcMethod.SendBitcoin], address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, // NOTE: shares entropy with MOCK_HD_ACCOUNT_2 id: MOCK_HD_KEYRING_2.metadata.id, groupIndex: 0, derivationPath: '', }, }, scopes: [BtcScope.Testnet], metadata: { name: 'Bitcoin Taproot Account 1', importTime: 0, keyring: { type: 'Snap keyring', }, snap: { id: 'mock-btc-snap-id', enabled: true, name: 'Mock Bitcoin Snap', }, }, }; export const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1; export const MOCK_SNAP_ACCOUNT_2 = { id: 'mock-snap-id-2', address: '0x789', options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], metadata: { name: 'Snap Acc 2', keyring: { type: KeyringTypes.snap }, snap: MOCK_SNAP_2, importTime: 0, lastSelected: 0, }, }; export const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1; export const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1; export const MOCK_HARDWARE_ACCOUNT_1 = { id: 'mock-hardware-id-1', address: '0xABC', options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], metadata: { name: 'Hardware Acc 1', keyring: { type: KeyringTypes.ledger }, importTime: 0, lastSelected: 0, }, }; export class MockAccountBuilder { constructor(account) { _MockAccountBuilder_account.set(this, void 0); // Make a deep-copy to avoid mutating the same ref. __classPrivateFieldSet(this, _MockAccountBuilder_account, JSON.parse(JSON.stringify(account)), "f"); } static from(account) { return new MockAccountBuilder(account); } withId(id) { __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = id; return this; } withUuid() { __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = uuid(); return this; } withAddressSuffix(suffix) { __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address += suffix; return this; } withEntropySource(entropySource) { if (isBip44Account(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) { __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.id = entropySource; } return this; } withGroupIndex(groupIndex) { if (isBip44Account(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) { __classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.groupIndex = groupIndex; } return this; } get() { return __classPrivateFieldGet(this, _MockAccountBuilder_account, "f"); } } _MockAccountBuilder_account = new WeakMap(); export const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1; export const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(MOCK_HD_ACCOUNT_1) .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE) .withGroupIndex(0) .get(); export const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(MOCK_SOL_ACCOUNT_1) .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE) .withGroupIndex(0) .get(); export const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(MOCK_BTC_P2WPKH_ACCOUNT_1) .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE) .withGroupIndex(0) .get(); export const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(MOCK_BTC_P2TR_ACCOUNT_1) .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE) .withGroupIndex(0) .get(); export function mockAsInternalAccount(account) { return { ...account, metadata: { name: 'Mocked Account', importTime: Date.now(), keyring: { type: 'mock-keyring-type', }, }, }; } //# sourceMappingURL=accounts.mjs.map