@metamask/multichain-account-service
Version:
Service to manage multichain accounts
60 lines • 2.92 kB
JavaScript
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;
import { assertIsBip44Account } from "@metamask/account-api";
import { KeyringAccountEntropyTypeOption, SolAccountType, SolScope } from "@metamask/keyring-api";
import { KeyringTypes } from "@metamask/keyring-controller";
import { traceFallback } from "../analytics/index.mjs";
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
export const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
export const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
maxConcurrency: 3,
discovery: {
enabled: true,
timeoutMs: 2000,
maxAttempts: 3,
backOffMs: 1000,
},
createAccounts: {
timeoutMs: 3000,
},
resyncAccounts: {
autoRemoveExtraSnapAccounts: true,
},
};
export class SolAccountProvider extends SnapAccountProvider {
constructor(messenger, config = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = 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 = [SolScope.Mainnet];
}
getName() {
return SolAccountProvider.NAME;
}
isAccountCompatible(account) {
return (account.type === SolAccountType.DataAccount &&
account.metadata.keyring.type === KeyringTypes.snap);
}
toBip44Account(account, { entropySource, groupIndex, }) {
// Ensure entropy is present before type assertion validation
account.options.entropy = {
type: KeyringAccountEntropyTypeOption.Mnemonic,
id: entropySource,
groupIndex,
derivationPath: __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getDerivationPath).call(this, groupIndex),
};
assertIsBip44Account(account);
return account;
}
}
_SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getDerivationPath = function _SolAccountProvider_getDerivationPath(groupIndex) {
return `m/44'/501'/${groupIndex}'/0'`;
};
SolAccountProvider.NAME = SOL_ACCOUNT_PROVIDER_NAME;
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
//# sourceMappingURL=SolAccountProvider.mjs.map