@metamask/multichain-account-service
Version:
Service to manage multichain accounts
41 lines • 1.82 kB
JavaScript
import { KeyringAccountEntropyTypeOption, SolAccountType } from "@metamask/keyring-api";
import { KeyringTypes } from "@metamask/keyring-controller";
import { assertAreBip44Accounts } from "./BaseAccountProvider.mjs";
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
export class SolAccountProvider extends SnapAccountProvider {
constructor(messenger) {
super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
}
isAccountCompatible(account) {
return (account.type === SolAccountType.DataAccount &&
account.metadata.keyring.type === KeyringTypes.snap);
}
async createAccounts({ entropySource, groupIndex, }) {
const createAccount = await this.getRestrictedSnapAccountCreator();
// Create account without any confirmation nor selecting it.
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
// type once ready.
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
const account = await createAccount({
entropySource,
derivationPath,
});
// Solana Snap does not use BIP-44 typed options for the moment
// so we "inject" them (the `AccountsController` does a similar thing
// for the moment).
account.options.entropy = {
type: KeyringAccountEntropyTypeOption.Mnemonic,
id: entropySource,
groupIndex,
derivationPath,
};
const accounts = [account];
assertAreBip44Accounts(accounts);
return accounts;
}
async discoverAndCreateAccounts(_) {
return []; // TODO: Implement account discovery.
}
}
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
//# sourceMappingURL=SolAccountProvider.mjs.map