UNPKG

@metamask/multichain-account-service

Version:
64 lines 3.24 kB
"use strict"; 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 _SolAccountProvider_instances, _SolAccountProvider_getDerivationPath; Object.defineProperty(exports, "__esModule", { value: true }); exports.SolAccountProvider = exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = exports.SOL_ACCOUNT_PROVIDER_NAME = void 0; const account_api_1 = require("@metamask/account-api"); const keyring_api_1 = require("@metamask/keyring-api"); const keyring_controller_1 = require("@metamask/keyring-controller"); const analytics_1 = require("../analytics/index.cjs"); const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs"); exports.SOL_ACCOUNT_PROVIDER_NAME = 'Solana'; exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = { maxConcurrency: 3, discovery: { enabled: true, timeoutMs: 2000, maxAttempts: 3, backOffMs: 1000, }, createAccounts: { timeoutMs: 3000, }, resyncAccounts: { autoRemoveExtraSnapAccounts: true, }, }; class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider { constructor(messenger, config = exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = analytics_1.traceFallback) { super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace); _SolAccountProvider_instances.add(this); // TODO: Remove once the Snap is fully v2 — discovery is then driven by the // Snap's own supported scopes via `createAccounts({ bip44:discover })`. this.v1DiscoveryScopes = [keyring_api_1.SolScope.Mainnet]; } getName() { return SolAccountProvider.NAME; } isAccountCompatible(account) { return (account.type === keyring_api_1.SolAccountType.DataAccount && account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap); } toBip44Account(account, { entropySource, groupIndex, }) { // Ensure entropy is present before type assertion validation account.options.entropy = { type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic, id: entropySource, groupIndex, derivationPath: __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getDerivationPath).call(this, groupIndex), }; (0, account_api_1.assertIsBip44Account)(account); return account; } } exports.SolAccountProvider = SolAccountProvider; _SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getDerivationPath = function _SolAccountProvider_getDerivationPath(groupIndex) { return `m/44'/501'/${groupIndex}'/0'`; }; SolAccountProvider.NAME = exports.SOL_ACCOUNT_PROVIDER_NAME; SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap'; //# sourceMappingURL=SolAccountProvider.cjs.map