UNPKG

@metamask/account-api

Version:
179 lines 6.94 kB
// istanbul ignore file 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 { BtcAccountType, BtcMethod, BtcScope, EthAccountType, EthMethod, EthScope, KeyringAccountEntropyTypeOption, SolAccountType, SolMethod, SolScope } from "@metamask/keyring-api"; import { v4 as uuid } from "uuid"; import { MOCK_ENTROPY_SOURCE_1, MOCK_ENTROPY_SOURCE_2 } from "./keyrings.mjs"; import { isBip44Account } from "../api/index.mjs"; 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_HD_ACCOUNT_1 = { id: 'mock-id-1', address: '0x123', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, id: MOCK_ENTROPY_SOURCE_1, groupIndex: 0, derivationPath: '', }, }, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], }; export const MOCK_HD_ACCOUNT_2 = { id: 'mock-id-2', address: '0x456', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, id: MOCK_ENTROPY_SOURCE_2, groupIndex: 0, derivationPath: '', }, }, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, scopes: [EthScope.Eoa], }; 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_ENTROPY_SOURCE_2, groupIndex: 0, derivationPath: '', }, }, methods: SOL_METHODS, type: SolAccountType.DataAccount, scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet], }; export const MOCK_BTC_P2WPKH_ACCOUNT_1 = { id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db', type: BtcAccountType.P2wpkh, methods: Object.values(BtcMethod), address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, // NOTE: shares entropy with MOCK_HD_ACCOUNT_2 id: MOCK_ENTROPY_SOURCE_2, groupIndex: 0, derivationPath: '', }, }, scopes: [BtcScope.Mainnet], }; export const MOCK_BTC_P2TR_ACCOUNT_1 = { id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb', type: BtcAccountType.P2tr, methods: Object.values(BtcMethod), address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh', options: { entropy: { type: KeyringAccountEntropyTypeOption.Mnemonic, // NOTE: shares entropy with MOCK_HD_ACCOUNT_2 id: MOCK_ENTROPY_SOURCE_2, groupIndex: 0, derivationPath: '', }, }, scopes: [BtcScope.Testnet], }; 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], }; 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], }; 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(); //# sourceMappingURL=accounts.mjs.map