@metamask/multichain-account-service
Version:
Service to manage multichain accounts
23 lines • 1.21 kB
JavaScript
import { KeyringTypes } from "@metamask/keyring-controller";
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
export class SnapAccountProvider extends BaseAccountProvider {
constructor(snapId, messenger) {
super(messenger);
this.snapId = snapId;
}
async getRestrictedSnapAccountCreator() {
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
// we have to use the `SnapKeyring` instance to be able to create Solana account
// without triggering UI confirmation.
// Also, creating account that way won't invalidate the Snap keyring state. The
// account will get created and persisted properly with the Snap account creation
// flow "asynchronously" (with `notify:accountCreated`).
const createAccount = await this.withKeyring({ type: KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
return (options) => createAccount(this.snapId, options, {
displayAccountNameSuggestion: false,
displayConfirmation: false,
setSelectedAccount: false,
});
}
}
//# sourceMappingURL=SnapAccountProvider.mjs.map