@metamask/account-api
Version:
MetaMask Account API
183 lines • 7.96 kB
JavaScript
// 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;
Object.defineProperty(exports, "__esModule", { value: true });
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_SOL_ACCOUNT_1 = exports.MOCK_HD_ACCOUNT_2 = exports.MOCK_HD_ACCOUNT_1 = void 0;
const keyring_api_1 = require("@metamask/keyring-api");
const uuid_1 = require("uuid");
const keyrings_1 = require("./keyrings.cjs");
const api_1 = require("../api/index.cjs");
const ETH_EOA_METHODS = [
keyring_api_1.EthMethod.PersonalSign,
keyring_api_1.EthMethod.Sign,
keyring_api_1.EthMethod.SignTransaction,
keyring_api_1.EthMethod.SignTypedDataV1,
keyring_api_1.EthMethod.SignTypedDataV3,
keyring_api_1.EthMethod.SignTypedDataV4,
];
const SOL_METHODS = Object.values(keyring_api_1.SolMethod);
exports.MOCK_HD_ACCOUNT_1 = {
id: 'mock-id-1',
address: '0x123',
options: {
entropy: {
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
id: keyrings_1.MOCK_ENTROPY_SOURCE_1,
groupIndex: 0,
derivationPath: '',
},
},
methods: [...ETH_EOA_METHODS],
type: keyring_api_1.EthAccountType.Eoa,
scopes: [keyring_api_1.EthScope.Eoa],
};
exports.MOCK_HD_ACCOUNT_2 = {
id: 'mock-id-2',
address: '0x456',
options: {
entropy: {
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
id: keyrings_1.MOCK_ENTROPY_SOURCE_2,
groupIndex: 0,
derivationPath: '',
},
},
methods: [...ETH_EOA_METHODS],
type: keyring_api_1.EthAccountType.Eoa,
scopes: [keyring_api_1.EthScope.Eoa],
};
exports.MOCK_SOL_ACCOUNT_1 = {
id: 'mock-snap-id-1',
address: 'aabbccdd',
options: {
entropy: {
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
// NOTE: shares entropy with MOCK_HD_ACCOUNT_2
id: keyrings_1.MOCK_ENTROPY_SOURCE_2,
groupIndex: 0,
derivationPath: '',
},
},
methods: SOL_METHODS,
type: keyring_api_1.SolAccountType.DataAccount,
scopes: [keyring_api_1.SolScope.Mainnet, keyring_api_1.SolScope.Testnet, keyring_api_1.SolScope.Devnet],
};
exports.MOCK_BTC_P2WPKH_ACCOUNT_1 = {
id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',
type: keyring_api_1.BtcAccountType.P2wpkh,
methods: Object.values(keyring_api_1.BtcMethod),
address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',
options: {
entropy: {
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
// NOTE: shares entropy with MOCK_HD_ACCOUNT_2
id: keyrings_1.MOCK_ENTROPY_SOURCE_2,
groupIndex: 0,
derivationPath: '',
},
},
scopes: [keyring_api_1.BtcScope.Mainnet],
};
exports.MOCK_BTC_P2TR_ACCOUNT_1 = {
id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',
type: keyring_api_1.BtcAccountType.P2tr,
methods: Object.values(keyring_api_1.BtcMethod),
address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',
options: {
entropy: {
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
// NOTE: shares entropy with MOCK_HD_ACCOUNT_2
id: keyrings_1.MOCK_ENTROPY_SOURCE_2,
groupIndex: 0,
derivationPath: '',
},
},
scopes: [keyring_api_1.BtcScope.Testnet],
};
exports.MOCK_SNAP_ACCOUNT_1 = exports.MOCK_SOL_ACCOUNT_1;
exports.MOCK_SNAP_ACCOUNT_2 = {
id: 'mock-snap-id-2',
address: '0x789',
options: {},
methods: [...ETH_EOA_METHODS],
type: keyring_api_1.EthAccountType.Eoa,
scopes: [keyring_api_1.EthScope.Eoa],
};
exports.MOCK_SNAP_ACCOUNT_3 = exports.MOCK_BTC_P2WPKH_ACCOUNT_1;
exports.MOCK_SNAP_ACCOUNT_4 = exports.MOCK_BTC_P2TR_ACCOUNT_1;
exports.MOCK_HARDWARE_ACCOUNT_1 = {
id: 'mock-hardware-id-1',
address: '0xABC',
options: {},
methods: [...ETH_EOA_METHODS],
type: keyring_api_1.EthAccountType.Eoa,
scopes: [keyring_api_1.EthScope.Eoa],
};
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 = (0, uuid_1.v4)();
return this;
}
withAddressSuffix(suffix) {
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address += suffix;
return this;
}
withEntropySource(entropySource) {
if ((0, api_1.isBip44Account)(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.id = entropySource;
}
return this;
}
withGroupIndex(groupIndex) {
if ((0, api_1.isBip44Account)(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.groupIndex = groupIndex;
}
return this;
}
get() {
return __classPrivateFieldGet(this, _MockAccountBuilder_account, "f");
}
}
exports.MockAccountBuilder = MockAccountBuilder;
_MockAccountBuilder_account = new WeakMap();
exports.MOCK_WALLET_1_ENTROPY_SOURCE = keyrings_1.MOCK_ENTROPY_SOURCE_1;
exports.MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(exports.MOCK_HD_ACCOUNT_1)
.withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
.withGroupIndex(0)
.get();
exports.MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(exports.MOCK_SOL_ACCOUNT_1)
.withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
.withGroupIndex(0)
.get();
exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(exports.MOCK_BTC_P2WPKH_ACCOUNT_1)
.withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
.withGroupIndex(0)
.get();
exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(exports.MOCK_BTC_P2TR_ACCOUNT_1)
.withEntropySource(exports.MOCK_WALLET_1_ENTROPY_SOURCE)
.withGroupIndex(0)
.get();
//# sourceMappingURL=accounts.cjs.map
;