@metamask-previews/multichain-account-service 0.3.0-preview-bf50b46b → 0.3.0-preview-e4e5ca5c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +3 -3
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts +3 -3
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService.cjs +28 -1
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +33 -8
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +33 -8
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +28 -1
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +115 -13
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts +22 -1
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts +22 -1
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs +115 -13
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/providers/BaseAccountProvider.cjs +30 -1
- package/dist/providers/BaseAccountProvider.cjs.map +1 -1
- package/dist/providers/BaseAccountProvider.d.cts +32 -5
- package/dist/providers/BaseAccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseAccountProvider.d.mts +32 -5
- package/dist/providers/BaseAccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseAccountProvider.mjs +27 -0
- package/dist/providers/BaseAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +35 -0
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +66 -0
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +66 -0
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +36 -1
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +41 -0
- package/dist/providers/SnapAccountProvider.cjs.map +1 -0
- package/dist/providers/SnapAccountProvider.d.cts +34 -0
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -0
- package/dist/providers/SnapAccountProvider.d.mts +34 -0
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -0
- package/dist/providers/SnapAccountProvider.mjs +37 -0
- package/dist/providers/SnapAccountProvider.mjs.map +1 -0
- package/dist/providers/SolAccountProvider.cjs +31 -1
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +14 -3
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +14 -3
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +33 -3
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/index.cjs +22 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +5 -0
- package/dist/providers/index.d.cts.map +1 -0
- package/dist/providers/index.d.mts +5 -0
- package/dist/providers/index.d.mts.map +1 -0
- package/dist/providers/index.mjs +6 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/tests/accounts.cjs +9 -0
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +27 -55
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +27 -55
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +9 -0
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +9 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +9 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -4
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
import { EthAccountType } from "@metamask/keyring-api";
|
|
2
2
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
3
|
-
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
3
|
+
import { assertIsBip44Account, BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Asserts an internal account exists.
|
|
6
|
+
*
|
|
7
|
+
* @param account - The internal account to check.
|
|
8
|
+
* @throws An error if the internal account does not exist.
|
|
9
|
+
*/
|
|
10
|
+
function assertInternalAccountExists(account) {
|
|
11
|
+
if (!account) {
|
|
12
|
+
throw new Error('Internal account does not exist');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
4
15
|
export class EvmAccountProvider extends BaseAccountProvider {
|
|
5
16
|
isAccountCompatible(account) {
|
|
6
17
|
return (account.type === EthAccountType.Eoa &&
|
|
7
18
|
account.metadata.keyring.type === KeyringTypes.hd);
|
|
8
19
|
}
|
|
20
|
+
async createAccounts({ entropySource, groupIndex, }) {
|
|
21
|
+
const [address] = await this.withKeyring({ id: entropySource }, async ({ keyring }) => {
|
|
22
|
+
const accounts = await keyring.getAccounts();
|
|
23
|
+
if (groupIndex < accounts.length) {
|
|
24
|
+
// Nothing new to create, we just re-use the existing accounts here,
|
|
25
|
+
return [accounts[groupIndex]];
|
|
26
|
+
}
|
|
27
|
+
// For now, we don't allow for gap, so if we need to create a new
|
|
28
|
+
// account, this has to be the next one.
|
|
29
|
+
if (groupIndex !== accounts.length) {
|
|
30
|
+
throw new Error('Trying to create too many accounts');
|
|
31
|
+
}
|
|
32
|
+
// Create next account (and returns their addresses).
|
|
33
|
+
return await keyring.addAccounts(1);
|
|
34
|
+
});
|
|
35
|
+
const account = this.messenger.call('AccountsController:getAccountByAddress', address);
|
|
36
|
+
// We MUST have the associated internal account.
|
|
37
|
+
assertInternalAccountExists(account);
|
|
38
|
+
assertIsBip44Account(account);
|
|
39
|
+
return [account];
|
|
40
|
+
}
|
|
41
|
+
async discoverAndCreateAccounts(_) {
|
|
42
|
+
return []; // TODO: Implement account discovery.
|
|
43
|
+
}
|
|
9
44
|
}
|
|
10
45
|
//# sourceMappingURL=EvmAccountProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EvmAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/EvmAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAO5D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACpB,kCAA8B;AAE/B;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAoC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;AACH,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IACzD,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAC9D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,CAAC,WAAW,CACtC,EAAE,EAAE,EAAE,aAAa,EAAE,EACrB,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACpB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAI,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE;gBAChC,oEAAoE;gBACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;aAC/B;YAED,iEAAiE;YACjE,wCAAwC;YACxC,IAAI,UAAU,KAAK,QAAQ,CAAC,MAAM,EAAE;gBAClC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;aACvD;YAED,qDAAqD;YACrD,OAAO,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,CACF,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACjC,wCAAwC,EACxC,OAAO,CACR,CAAC;QAEF,gDAAgD;QAChD,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACrC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;CACF","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n EthKeyring,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport type { Hex } from '@metamask/utils';\n\nimport {\n assertIsBip44Account,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\n/**\n * Asserts an internal account exists.\n *\n * @param account - The internal account to check.\n * @throws An error if the internal account does not exist.\n */\nfunction assertInternalAccountExists(\n account: InternalAccount | undefined,\n): asserts account is InternalAccount {\n if (!account) {\n throw new Error('Internal account does not exist');\n }\n}\n\nexport class EvmAccountProvider extends BaseAccountProvider {\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === EthAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.hd as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n const [address] = await this.withKeyring<EthKeyring, Hex[]>(\n { id: entropySource },\n async ({ keyring }) => {\n const accounts = await keyring.getAccounts();\n if (groupIndex < accounts.length) {\n // Nothing new to create, we just re-use the existing accounts here,\n return [accounts[groupIndex]];\n }\n\n // For now, we don't allow for gap, so if we need to create a new\n // account, this has to be the next one.\n if (groupIndex !== accounts.length) {\n throw new Error('Trying to create too many accounts');\n }\n\n // Create next account (and returns their addresses).\n return await keyring.addAccounts(1);\n },\n );\n\n const account = this.messenger.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n\n // We MUST have the associated internal account.\n assertInternalAccountExists(account);\n assertIsBip44Account(account);\n\n return [account];\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnapAccountProvider = void 0;
|
|
4
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
5
|
+
const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
|
|
6
|
+
class SnapAccountProvider extends BaseAccountProvider_1.BaseAccountProvider {
|
|
7
|
+
constructor(snapId, messenger) {
|
|
8
|
+
super(messenger);
|
|
9
|
+
this.snapId = snapId;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Execute the operation to create accounts.
|
|
13
|
+
*
|
|
14
|
+
* All accounts have to be BIP-44 compatible, otherwise this method will throw.
|
|
15
|
+
*
|
|
16
|
+
* @param createAccounts - Callback to create all accounts for this provider. The first
|
|
17
|
+
* argument of this callback is a function that can be used to create Snap account on
|
|
18
|
+
* the associated Snap of this provider. It will automatically skips any account
|
|
19
|
+
* creation confirmations if possible.
|
|
20
|
+
* @throws If any of the created accounts are not BIP-44 compatible.
|
|
21
|
+
* @returns The list of created accounts.
|
|
22
|
+
*/
|
|
23
|
+
async withCreateAccount(createAccounts) {
|
|
24
|
+
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
25
|
+
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
26
|
+
// without triggering UI confirmation.
|
|
27
|
+
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
28
|
+
// account will get created and persisted properly with the Snap account creation
|
|
29
|
+
// flow "asynchronously" (with `notify:accountCreated`).
|
|
30
|
+
const createAccount = await this.withKeyring({ type: keyring_controller_1.KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
31
|
+
const accounts = await createAccounts((options) => createAccount(this.snapId, options, {
|
|
32
|
+
displayAccountNameSuggestion: false,
|
|
33
|
+
displayConfirmation: false,
|
|
34
|
+
setSelectedAccount: false,
|
|
35
|
+
}));
|
|
36
|
+
(0, BaseAccountProvider_1.assertAreBip44Accounts)(accounts);
|
|
37
|
+
return accounts;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.SnapAccountProvider = SnapAccountProvider;
|
|
41
|
+
//# sourceMappingURL=SnapAccountProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":";;;AAGA,qEAA4D;AAK5D,mEAG+B;AAM/B,MAAsB,mBAAoB,SAAQ,yCAAmB;IAGnE,YAAY,MAAc,EAAE,SAA4C;QACtE,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;OAWG;IACO,KAAK,CAAC,iBAAiB,CAC/B,cAE8B;QAE9B,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,iCAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAChD,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YAClC,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CACH,CAAC;QAEF,IAAA,4CAAsB,EAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;CAaF;AA/DD,kDA+DC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport {\n assertAreBip44Accounts,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\nexport type RestrictedSnapKeyringCreateAccount = (\n options: Record<string, Json>,\n) => Promise<KeyringAccount>;\n\nexport abstract class SnapAccountProvider extends BaseAccountProvider {\n readonly snapId: SnapId;\n\n constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger) {\n super(messenger);\n\n this.snapId = snapId;\n }\n\n /**\n * Execute the operation to create accounts.\n *\n * All accounts have to be BIP-44 compatible, otherwise this method will throw.\n *\n * @param createAccounts - Callback to create all accounts for this provider. The first\n * argument of this callback is a function that can be used to create Snap account on\n * the associated Snap of this provider. It will automatically skips any account\n * creation confirmations if possible.\n * @throws If any of the created accounts are not BIP-44 compatible.\n * @returns The list of created accounts.\n */\n protected async withCreateAccount(\n createAccounts: (\n createAccount: RestrictedSnapKeyringCreateAccount,\n ) => Promise<KeyringAccount[]>,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n const accounts = await createAccounts((options) =>\n createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n }),\n );\n\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Bip44Account } from "@metamask/account-api";
|
|
2
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
+
import type { Json, SnapId } from "@metamask/snaps-sdk";
|
|
5
|
+
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
|
+
import { BaseAccountProvider } from "./BaseAccountProvider.cjs";
|
|
7
|
+
export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
|
|
8
|
+
export declare abstract class SnapAccountProvider extends BaseAccountProvider {
|
|
9
|
+
readonly snapId: SnapId;
|
|
10
|
+
constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger);
|
|
11
|
+
/**
|
|
12
|
+
* Execute the operation to create accounts.
|
|
13
|
+
*
|
|
14
|
+
* All accounts have to be BIP-44 compatible, otherwise this method will throw.
|
|
15
|
+
*
|
|
16
|
+
* @param createAccounts - Callback to create all accounts for this provider. The first
|
|
17
|
+
* argument of this callback is a function that can be used to create Snap account on
|
|
18
|
+
* the associated Snap of this provider. It will automatically skips any account
|
|
19
|
+
* creation confirmations if possible.
|
|
20
|
+
* @throws If any of the created accounts are not BIP-44 compatible.
|
|
21
|
+
* @returns The list of created accounts.
|
|
22
|
+
*/
|
|
23
|
+
protected withCreateAccount(createAccounts: (createAccount: RestrictedSnapKeyringCreateAccount) => Promise<KeyringAccount[]>): Promise<Bip44Account<KeyringAccount>[]>;
|
|
24
|
+
abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
25
|
+
abstract createAccounts(options: {
|
|
26
|
+
entropySource: EntropySourceId;
|
|
27
|
+
groupIndex: number;
|
|
28
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
29
|
+
abstract discoverAndCreateAccounts(options: {
|
|
30
|
+
entropySource: EntropySourceId;
|
|
31
|
+
groupIndex: number;
|
|
32
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=SnapAccountProvider.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"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amask/account-api";
|
|
2
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
+
import type { Json, SnapId } from "@metamask/snaps-sdk";
|
|
5
|
+
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
|
+
import { BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
7
|
+
export type RestrictedSnapKeyringCreateAccount = (options: Record<string, Json>) => Promise<KeyringAccount>;
|
|
8
|
+
export declare abstract class SnapAccountProvider extends BaseAccountProvider {
|
|
9
|
+
readonly snapId: SnapId;
|
|
10
|
+
constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger);
|
|
11
|
+
/**
|
|
12
|
+
* Execute the operation to create accounts.
|
|
13
|
+
*
|
|
14
|
+
* All accounts have to be BIP-44 compatible, otherwise this method will throw.
|
|
15
|
+
*
|
|
16
|
+
* @param createAccounts - Callback to create all accounts for this provider. The first
|
|
17
|
+
* argument of this callback is a function that can be used to create Snap account on
|
|
18
|
+
* the associated Snap of this provider. It will automatically skips any account
|
|
19
|
+
* creation confirmations if possible.
|
|
20
|
+
* @throws If any of the created accounts are not BIP-44 compatible.
|
|
21
|
+
* @returns The list of created accounts.
|
|
22
|
+
*/
|
|
23
|
+
protected withCreateAccount(createAccounts: (createAccount: RestrictedSnapKeyringCreateAccount) => Promise<KeyringAccount[]>): Promise<Bip44Account<KeyringAccount>[]>;
|
|
24
|
+
abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
25
|
+
abstract createAccounts(options: {
|
|
26
|
+
entropySource: EntropySourceId;
|
|
27
|
+
groupIndex: number;
|
|
28
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
29
|
+
abstract discoverAndCreateAccounts(options: {
|
|
30
|
+
entropySource: EntropySourceId;
|
|
31
|
+
groupIndex: number;
|
|
32
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
33
|
+
}
|
|
34
|
+
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E,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAC5C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
2
|
+
import { assertAreBip44Accounts, BaseAccountProvider } from "./BaseAccountProvider.mjs";
|
|
3
|
+
export class SnapAccountProvider extends BaseAccountProvider {
|
|
4
|
+
constructor(snapId, messenger) {
|
|
5
|
+
super(messenger);
|
|
6
|
+
this.snapId = snapId;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Execute the operation to create accounts.
|
|
10
|
+
*
|
|
11
|
+
* All accounts have to be BIP-44 compatible, otherwise this method will throw.
|
|
12
|
+
*
|
|
13
|
+
* @param createAccounts - Callback to create all accounts for this provider. The first
|
|
14
|
+
* argument of this callback is a function that can be used to create Snap account on
|
|
15
|
+
* the associated Snap of this provider. It will automatically skips any account
|
|
16
|
+
* creation confirmations if possible.
|
|
17
|
+
* @throws If any of the created accounts are not BIP-44 compatible.
|
|
18
|
+
* @returns The list of created accounts.
|
|
19
|
+
*/
|
|
20
|
+
async withCreateAccount(createAccounts) {
|
|
21
|
+
// NOTE: We're not supposed to make the keyring instance escape `withKeyring` but
|
|
22
|
+
// we have to use the `SnapKeyring` instance to be able to create Solana account
|
|
23
|
+
// without triggering UI confirmation.
|
|
24
|
+
// Also, creating account that way won't invalidate the Snap keyring state. The
|
|
25
|
+
// account will get created and persisted properly with the Snap account creation
|
|
26
|
+
// flow "asynchronously" (with `notify:accountCreated`).
|
|
27
|
+
const createAccount = await this.withKeyring({ type: KeyringTypes.snap }, async ({ keyring }) => keyring.createAccount.bind(keyring));
|
|
28
|
+
const accounts = await createAccounts((options) => createAccount(this.snapId, options, {
|
|
29
|
+
displayAccountNameSuggestion: false,
|
|
30
|
+
displayConfirmation: false,
|
|
31
|
+
setSelectedAccount: false,
|
|
32
|
+
}));
|
|
33
|
+
assertAreBip44Accounts(accounts);
|
|
34
|
+
return accounts;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=SnapAccountProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SnapAccountProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACpB,kCAA8B;AAM/B,MAAM,OAAgB,mBAAoB,SAAQ,mBAAmB;IAGnE,YAAY,MAAc,EAAE,SAA4C;QACtE,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;OAWG;IACO,KAAK,CAAC,iBAAiB,CAC/B,cAE8B;QAE9B,iFAAiF;QACjF,gFAAgF;QAChF,sCAAsC;QACtC,+EAA+E;QAC/E,iFAAiF;QACjF,wDAAwD;QACxD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAG1C,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACnD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CACpC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAChD,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YAClC,4BAA4B,EAAE,KAAK;YACnC,mBAAmB,EAAE,KAAK;YAC1B,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CACH,CAAC;QAEF,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;CAaF","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Json, SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport {\n assertAreBip44Accounts,\n BaseAccountProvider,\n} from './BaseAccountProvider';\n\nexport type RestrictedSnapKeyringCreateAccount = (\n options: Record<string, Json>,\n) => Promise<KeyringAccount>;\n\nexport abstract class SnapAccountProvider extends BaseAccountProvider {\n readonly snapId: SnapId;\n\n constructor(snapId: SnapId, messenger: MultichainAccountServiceMessenger) {\n super(messenger);\n\n this.snapId = snapId;\n }\n\n /**\n * Execute the operation to create accounts.\n *\n * All accounts have to be BIP-44 compatible, otherwise this method will throw.\n *\n * @param createAccounts - Callback to create all accounts for this provider. The first\n * argument of this callback is a function that can be used to create Snap account on\n * the associated Snap of this provider. It will automatically skips any account\n * creation confirmations if possible.\n * @throws If any of the created accounts are not BIP-44 compatible.\n * @returns The list of created accounts.\n */\n protected async withCreateAccount(\n createAccounts: (\n createAccount: RestrictedSnapKeyringCreateAccount,\n ) => Promise<KeyringAccount[]>,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n // NOTE: We're not supposed to make the keyring instance escape `withKeyring` but\n // we have to use the `SnapKeyring` instance to be able to create Solana account\n // without triggering UI confirmation.\n // Also, creating account that way won't invalidate the Snap keyring state. The\n // account will get created and persisted properly with the Snap account creation\n // flow \"asynchronously\" (with `notify:accountCreated`).\n const createAccount = await this.withKeyring<\n SnapKeyring,\n SnapKeyring['createAccount']\n >({ type: KeyringTypes.snap }, async ({ keyring }) =>\n keyring.createAccount.bind(keyring),\n );\n\n const accounts = await createAccounts((options) =>\n createAccount(this.snapId, options, {\n displayAccountNameSuggestion: false,\n displayConfirmation: false,\n setSelectedAccount: false,\n }),\n );\n\n assertAreBip44Accounts(accounts);\n\n return accounts;\n }\n\n abstract isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;\n\n abstract createAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n\n abstract discoverAndCreateAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]>;\n}\n"]}
|
|
@@ -4,11 +4,41 @@ exports.SolAccountProvider = void 0;
|
|
|
4
4
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
5
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
6
6
|
const BaseAccountProvider_1 = require("./BaseAccountProvider.cjs");
|
|
7
|
-
|
|
7
|
+
const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
|
|
8
|
+
class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
9
|
+
constructor(messenger) {
|
|
10
|
+
super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
|
|
11
|
+
}
|
|
8
12
|
isAccountCompatible(account) {
|
|
9
13
|
return (account.type === keyring_api_1.SolAccountType.DataAccount &&
|
|
10
14
|
account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
|
|
11
15
|
}
|
|
16
|
+
async createAccounts({ entropySource, groupIndex, }) {
|
|
17
|
+
return this.withCreateAccount(async (createAccount) => {
|
|
18
|
+
// Create account without any confirmation nor selecting it.
|
|
19
|
+
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
20
|
+
// type once ready.
|
|
21
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
22
|
+
const account = await createAccount({
|
|
23
|
+
entropySource,
|
|
24
|
+
derivationPath,
|
|
25
|
+
});
|
|
26
|
+
// Solana Snap does not use BIP-44 typed options for the moment
|
|
27
|
+
// so we "inject" them (the `AccountsController` does a similar thing
|
|
28
|
+
// for the moment).
|
|
29
|
+
account.options.entropy = {
|
|
30
|
+
type: keyring_api_1.KeyringAccountEntropyTypeOption.Mnemonic,
|
|
31
|
+
id: entropySource,
|
|
32
|
+
groupIndex,
|
|
33
|
+
derivationPath,
|
|
34
|
+
};
|
|
35
|
+
(0, BaseAccountProvider_1.assertIsBip44Account)(account);
|
|
36
|
+
return [account];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async discoverAndCreateAccounts(_) {
|
|
40
|
+
return []; // TODO: Implement account discovery.
|
|
41
|
+
}
|
|
12
42
|
}
|
|
13
43
|
exports.SolAccountProvider = SolAccountProvider;
|
|
14
44
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAG+B;AAC/B,qEAA4D;AAK5D,mEAA6D;AAC7D,mEAA4D;AAE5D,MAAa,kBAAmB,SAAQ,yCAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;YACpD,4DAA4D;YAC5D,uFAAuF;YACvF,mBAAmB;YACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;YACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;gBAClC,aAAa;gBACb,cAAc;aACf,CAAC,CAAC;YAEH,+DAA+D;YAC/D,qEAAqE;YACrE,mBAAmB;YACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;gBACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,aAAa;gBACjB,UAAU;gBACV,cAAc;aACf,CAAC;YAEF,IAAA,0CAAoB,EAAC,OAAO,CAAC,CAAC;YAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AApDH,gDAqDC;AApDQ,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertIsBip44Account } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withCreateAccount(async (createAccount) => {\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n\n return [account];\n });\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Bip44Account } from "@metamask/account-api";
|
|
2
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
4
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
|
+
import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
|
|
7
|
+
export declare class SolAccountProvider extends SnapAccountProvider {
|
|
6
8
|
static SOLANA_SNAP_ID: SnapId;
|
|
9
|
+
constructor(messenger: MultichainAccountServiceMessenger);
|
|
7
10
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
11
|
+
createAccounts({ entropySource, groupIndex, }: {
|
|
12
|
+
entropySource: EntropySourceId;
|
|
13
|
+
groupIndex: number;
|
|
14
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
15
|
+
discoverAndCreateAccounts(_: {
|
|
16
|
+
entropySource: EntropySourceId;
|
|
17
|
+
groupIndex: number;
|
|
18
|
+
}): Promise<never[]>;
|
|
8
19
|
}
|
|
9
20
|
//# sourceMappingURL=SolAccountProvider.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAM7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAGnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;gBAEzD,SAAS,EAAE,iCAAiC;IAIxD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IA2BrC,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Bip44Account } from "@metamask/account-api";
|
|
2
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
4
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import type { MultichainAccountServiceMessenger } from "src/types";
|
|
6
|
+
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
7
|
+
export declare class SolAccountProvider extends SnapAccountProvider {
|
|
6
8
|
static SOLANA_SNAP_ID: SnapId;
|
|
9
|
+
constructor(messenger: MultichainAccountServiceMessenger);
|
|
7
10
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
11
|
+
createAccounts({ entropySource, groupIndex, }: {
|
|
12
|
+
entropySource: EntropySourceId;
|
|
13
|
+
groupIndex: number;
|
|
14
|
+
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
15
|
+
discoverAndCreateAccounts(_: {
|
|
16
|
+
entropySource: EntropySourceId;
|
|
17
|
+
groupIndex: number;
|
|
18
|
+
}): Promise<never[]>;
|
|
8
19
|
}
|
|
9
20
|
//# sourceMappingURL=SolAccountProvider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAM7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,iCAAiC,EAAE,kBAAkB;AAGnE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,qBAAa,kBAAmB,SAAQ,mBAAmB;IACzD,MAAM,CAAC,cAAc,SAAgD;gBAEzD,SAAS,EAAE,iCAAiC;IAIxD,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAO9D,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IA2BrC,yBAAyB,CAAC,CAAC,EAAE;QACjC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB;CAGF"}
|
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
import { SolAccountType } from "@metamask/keyring-api";
|
|
1
|
+
import { KeyringAccountEntropyTypeOption, SolAccountType } from "@metamask/keyring-api";
|
|
2
2
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { assertIsBip44Account } from "./BaseAccountProvider.mjs";
|
|
4
|
+
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
5
|
+
export class SolAccountProvider extends SnapAccountProvider {
|
|
6
|
+
constructor(messenger) {
|
|
7
|
+
super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
|
|
8
|
+
}
|
|
5
9
|
isAccountCompatible(account) {
|
|
6
10
|
return (account.type === SolAccountType.DataAccount &&
|
|
7
11
|
account.metadata.keyring.type === KeyringTypes.snap);
|
|
8
12
|
}
|
|
13
|
+
async createAccounts({ entropySource, groupIndex, }) {
|
|
14
|
+
return this.withCreateAccount(async (createAccount) => {
|
|
15
|
+
// Create account without any confirmation nor selecting it.
|
|
16
|
+
// TODO: Use the new keyring API `createAccounts` method with the "bip-44:derive-index"
|
|
17
|
+
// type once ready.
|
|
18
|
+
const derivationPath = `m/44'/501'/${groupIndex}'/0'`;
|
|
19
|
+
const account = await createAccount({
|
|
20
|
+
entropySource,
|
|
21
|
+
derivationPath,
|
|
22
|
+
});
|
|
23
|
+
// Solana Snap does not use BIP-44 typed options for the moment
|
|
24
|
+
// so we "inject" them (the `AccountsController` does a similar thing
|
|
25
|
+
// for the moment).
|
|
26
|
+
account.options.entropy = {
|
|
27
|
+
type: KeyringAccountEntropyTypeOption.Mnemonic,
|
|
28
|
+
id: entropySource,
|
|
29
|
+
groupIndex,
|
|
30
|
+
derivationPath,
|
|
31
|
+
};
|
|
32
|
+
assertIsBip44Account(account);
|
|
33
|
+
return [account];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async discoverAndCreateAccounts(_) {
|
|
37
|
+
return []; // TODO: Implement account discovery.
|
|
38
|
+
}
|
|
9
39
|
}
|
|
10
40
|
SolAccountProvider.SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap';
|
|
11
41
|
//# sourceMappingURL=SolAccountProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACf,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,oBAAoB,EAAE,kCAA8B;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAE5D,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IAGzD,YAAY,SAA4C;QACtD,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW;YAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EACnB,aAAa,EACb,UAAU,GAIX;QACC,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;YACpD,4DAA4D;YAC5D,uFAAuF;YACvF,mBAAmB;YACnB,MAAM,cAAc,GAAG,cAAc,UAAU,MAAM,CAAC;YACtD,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;gBAClC,aAAa;gBACb,cAAc;aACf,CAAC,CAAC;YAEH,+DAA+D;YAC/D,qEAAqE;YACrE,mBAAmB;YACnB,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;gBACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,aAAa;gBACjB,UAAU;gBACV,cAAc;aACf,CAAC;YAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAE9B,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,CAG/B;QACC,OAAO,EAAE,CAAC,CAAC,qCAAqC;IAClD,CAAC;;AAnDM,iCAAc,GAAG,kCAA4C,CAAC","sourcesContent":["import { type Bip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { MultichainAccountServiceMessenger } from 'src/types';\n\nimport { assertIsBip44Account } from './BaseAccountProvider';\nimport { SnapAccountProvider } from './SnapAccountProvider';\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger);\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === SolAccountType.DataAccount &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n\n async createAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withCreateAccount(async (createAccount) => {\n // Create account without any confirmation nor selecting it.\n // TODO: Use the new keyring API `createAccounts` method with the \"bip-44:derive-index\"\n // type once ready.\n const derivationPath = `m/44'/501'/${groupIndex}'/0'`;\n const account = await createAccount({\n entropySource,\n derivationPath,\n });\n\n // Solana Snap does not use BIP-44 typed options for the moment\n // so we \"inject\" them (the `AccountsController` does a similar thing\n // for the moment).\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath,\n };\n\n assertIsBip44Account(account);\n\n return [account];\n });\n }\n\n async discoverAndCreateAccounts(_: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) {\n return []; // TODO: Implement account discovery.\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./BaseAccountProvider.cjs"), exports);
|
|
18
|
+
__exportStar(require("./SnapAccountProvider.cjs"), exports);
|
|
19
|
+
// Concrete providers:
|
|
20
|
+
__exportStar(require("./SolAccountProvider.cjs"), exports);
|
|
21
|
+
__exportStar(require("./EvmAccountProvider.cjs"), exports);
|
|
22
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC;AACtC,4DAAsC;AAEtC,sBAAsB;AACtB,2DAAqC;AACrC,2DAAqC","sourcesContent":["export * from './BaseAccountProvider';\nexport * from './SnapAccountProvider';\n\n// Concrete providers:\nexport * from './SolAccountProvider';\nexport * from './EvmAccountProvider';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,0CAAsC;AACtC,0CAAsC;AAGtC,yCAAqC;AACrC,yCAAqC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,0CAAsC;AACtC,0CAAsC;AAGtC,yCAAqC;AACrC,yCAAqC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,0CAAsC;AACtC,0CAAsC;AAEtC,sBAAsB;AACtB,yCAAqC;AACrC,yCAAqC","sourcesContent":["export * from './BaseAccountProvider';\nexport * from './SnapAccountProvider';\n\n// Concrete providers:\nexport * from './SolAccountProvider';\nexport * from './EvmAccountProvider';\n"]}
|
package/dist/tests/accounts.cjs
CHANGED
|
@@ -16,6 +16,7 @@ exports.MOCK_WALLET_1_BTC_P2TR_ACCOUNT = exports.MOCK_WALLET_1_BTC_P2WPKH_ACCOUN
|
|
|
16
16
|
const account_api_1 = require("@metamask/account-api");
|
|
17
17
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
18
18
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
19
|
+
const uuid_1 = require("uuid");
|
|
19
20
|
const ETH_EOA_METHODS = [
|
|
20
21
|
keyring_api_1.EthMethod.PersonalSign,
|
|
21
22
|
keyring_api_1.EthMethod.Sign,
|
|
@@ -221,6 +222,14 @@ class MockAccountBuilder {
|
|
|
221
222
|
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = id;
|
|
222
223
|
return this;
|
|
223
224
|
}
|
|
225
|
+
withUuid() {
|
|
226
|
+
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").id = (0, uuid_1.v4)();
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
withAddressSuffix(suffix) {
|
|
230
|
+
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").address += suffix;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
224
233
|
withEntropySource(entropySource) {
|
|
225
234
|
if ((0, account_api_1.isBip44Account)(__classPrivateFieldGet(this, _MockAccountBuilder_account, "f"))) {
|
|
226
235
|
__classPrivateFieldGet(this, _MockAccountBuilder_account, "f").options.entropy.id = entropySource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAuD;AAEvD,uDAW+B;AAC/B,qEAA4D;AAG5D,MAAM,eAAe,GAAG;IACtB,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,E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AC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nconst ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: InternalAccount = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: InternalAccount = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: InternalAccount = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: InternalAccount = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: [BtcMethod.SendBitcoin],\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: InternalAccount = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: [BtcMethod.SendBitcoin],\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport class MockAccountBuilder {\n readonly #account: InternalAccount;\n\n constructor(account: InternalAccount) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from(account: InternalAccount): MockAccountBuilder {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n"]}
|
|
1
|
+
{"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../src/tests/accounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAAuD;AAEvD,uDAW+B;AAC/B,qEAA4D;AAE5D,+BAAkC;AAElC,MAAM,eAAe,GAAG;IACtB,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAS,CAAC,CAAC;AAEhC,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,YAAY,EAAE,aAAa;KAC5B;CACF,CAAC;AAEW,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAE5C,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ,EAAE,EAAE,EAAE,EAAE,6BAAqB,EAAE,IAAI,EAAE,cAAc,EAAE;IAC7D,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,iCAAY,CAAC,EAAE;IACrB,QAAQ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,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,aAAa,CAAC;SAClD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc,CAAC,UAAkB;QAC/B,IAAI,IAAA,4BAAc,EAAC,uBAAA,IAAI,mCAAS,CAAC,EAAE;YACjC,uBAAA,IAAI,mCAAS,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;SACvD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG;QACD,OAAO,uBAAA,IAAI,mCAAS,CAAC;IACvB,CAAC;CACF;AA9CD,gDA8CC;;AAEY,QAAA,4BAA4B,GAAG,6BAAqB,CAAC;AAErD,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,yBAAiB,CAClB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,yBAAyB,GAAG,kBAAkB,CAAC,IAAI,CAC9D,0BAAkB,CACnB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CACrE,iCAAyB,CAC1B;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC;AACI,QAAA,8BAA8B,GAAG,kBAAkB,CAAC,IAAI,CACnE,+BAAuB,CACxB;KACE,iBAAiB,CAAC,oCAA4B,CAAC;KAC/C,cAAc,CAAC,CAAC,CAAC;KACjB,GAAG,EAAE,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport { isBip44Account } from '@metamask/account-api';\nimport type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n BtcScope,\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolMethod,\n SolScope,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { v4 as uuid } from 'uuid';\n\nconst ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nconst SOL_METHODS = Object.values(SolMethod);\n\nexport const MOCK_SNAP_1 = {\n id: 'local:mock-snap-id-1',\n name: 'Mock Snap 1',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 1',\n },\n};\n\nexport const MOCK_SNAP_2 = {\n id: 'local:mock-snap-id-2',\n name: 'Mock Snap 2',\n enabled: true,\n manifest: {\n proposedName: 'Mock Snap 2',\n },\n};\n\nexport const MOCK_ENTROPY_SOURCE_1 = 'mock-keyring-id-1';\nexport const MOCK_ENTROPY_SOURCE_2 = 'mock-keyring-id-2';\n\nexport const MOCK_HD_KEYRING_1 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_1, name: 'HD Keyring 1' },\n accounts: ['0x123'],\n};\n\nexport const MOCK_HD_KEYRING_2 = {\n type: KeyringTypes.hd,\n metadata: { id: MOCK_ENTROPY_SOURCE_2, name: 'HD Keyring 2' },\n accounts: ['0x456'],\n};\n\nexport const MOCK_HD_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-id-1',\n address: '0x123',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_1.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 1',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_HD_ACCOUNT_2: Bip44Account<InternalAccount> = {\n id: 'mock-id-2',\n address: '0x456',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Account 2',\n keyring: { type: KeyringTypes.hd },\n importTime: 0,\n lastSelected: 0,\n nameLastUpdatedAt: 0,\n },\n};\n\nexport const MOCK_SOL_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'mock-snap-id-1',\n address: 'aabbccdd',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n methods: SOL_METHODS,\n type: SolAccountType.DataAccount,\n scopes: [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet],\n metadata: {\n name: 'Solana Account 1',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_1,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'b0f030d8-e101-4b5a-a3dd-13f8ca8ec1db',\n type: BtcAccountType.P2wpkh,\n methods: [BtcMethod.SendBitcoin],\n address: 'bc1qx8ls07cy8j8nrluy2u0xwn7gh8fxg0rg4s8zze',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Mainnet],\n metadata: {\n name: 'Bitcoin Native Segwit Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {\n id: 'a20c2e1a-6ff6-40ba-b8e0-ccdb6f9933bb',\n type: BtcAccountType.P2tr,\n methods: [BtcMethod.SendBitcoin],\n address: 'tb1p5cyxnuxmeuwuvkwfem96lxx9wex9kkf4mt9ll6q60jfsnrzqg4sszkqjnh',\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n // NOTE: shares entropy with MOCK_HD_ACCOUNT_2\n id: MOCK_HD_KEYRING_2.metadata.id,\n groupIndex: 0,\n derivationPath: '',\n },\n },\n scopes: [BtcScope.Testnet],\n metadata: {\n name: 'Bitcoin Taproot Account 1',\n importTime: 0,\n keyring: {\n type: 'Snap keyring',\n },\n snap: {\n id: 'mock-btc-snap-id',\n enabled: true,\n name: 'Mock Bitcoin Snap',\n },\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_1 = MOCK_SOL_ACCOUNT_1;\n\nexport const MOCK_SNAP_ACCOUNT_2: InternalAccount = {\n id: 'mock-snap-id-2',\n address: '0x789',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Snap Acc 2',\n keyring: { type: KeyringTypes.snap },\n snap: MOCK_SNAP_2,\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport const MOCK_SNAP_ACCOUNT_3 = MOCK_BTC_P2WPKH_ACCOUNT_1;\nexport const MOCK_SNAP_ACCOUNT_4 = MOCK_BTC_P2TR_ACCOUNT_1;\n\nexport const MOCK_HARDWARE_ACCOUNT_1: InternalAccount = {\n id: 'mock-hardware-id-1',\n address: '0xABC',\n options: {},\n methods: [...ETH_EOA_METHODS],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: 'Hardware Acc 1',\n keyring: { type: KeyringTypes.ledger },\n importTime: 0,\n lastSelected: 0,\n },\n};\n\nexport class MockAccountBuilder<Account extends KeyringAccount> {\n readonly #account: Account;\n\n constructor(account: Account) {\n // Make a deep-copy to avoid mutating the same ref.\n this.#account = JSON.parse(JSON.stringify(account));\n }\n\n static from<Account extends KeyringAccount>(\n account: Account,\n ): MockAccountBuilder<Account> {\n return new MockAccountBuilder(account);\n }\n\n withId(id: InternalAccount['id']) {\n this.#account.id = id;\n return this;\n }\n\n withUuid() {\n this.#account.id = uuid();\n return this;\n }\n\n withAddressSuffix(suffix: string) {\n this.#account.address += suffix;\n return this;\n }\n\n withEntropySource(entropySource: EntropySourceId) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.id = entropySource;\n }\n return this;\n }\n\n withGroupIndex(groupIndex: number) {\n if (isBip44Account(this.#account)) {\n this.#account.options.entropy.groupIndex = groupIndex;\n }\n return this;\n }\n\n get() {\n return this.#account;\n }\n}\n\nexport const MOCK_WALLET_1_ENTROPY_SOURCE = MOCK_ENTROPY_SOURCE_1;\n\nexport const MOCK_WALLET_1_EVM_ACCOUNT = MockAccountBuilder.from(\n MOCK_HD_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_SOL_ACCOUNT = MockAccountBuilder.from(\n MOCK_SOL_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2WPKH_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2WPKH_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\nexport const MOCK_WALLET_1_BTC_P2TR_ACCOUNT = MockAccountBuilder.from(\n MOCK_BTC_P2TR_ACCOUNT_1,\n)\n .withEntropySource(MOCK_WALLET_1_ENTROPY_SOURCE)\n .withGroupIndex(0)\n .get();\n"]}
|