@metamask/multichain-account-service 6.0.0 → 7.1.0
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 +29 -1
- package/dist/MultichainAccountService-method-action-types.cjs +7 -0
- package/dist/MultichainAccountService-method-action-types.cjs.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.cts +164 -0
- package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.mts +164 -0
- package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.mjs +6 -0
- package/dist/MultichainAccountService-method-action-types.mjs.map +1 -0
- package/dist/MultichainAccountService.cjs +22 -15
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +7 -1
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +7 -1
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +22 -15
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +4 -0
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs +4 -0
- package/dist/MultichainAccountWallet.mjs.map +1 -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.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs +3 -2
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +3 -7
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +3 -7
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs +3 -2
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs +2 -0
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +19 -5
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +19 -5
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs +2 -0
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +11 -1
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +3 -5
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +3 -5
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +12 -2
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +12 -4
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts +4 -8
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts +4 -8
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +13 -5
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +3 -1
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +2 -5
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +2 -5
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +3 -1
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +13 -4
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +3 -5
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +3 -5
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +12 -3
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +12 -2
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +3 -5
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +3 -5
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +13 -3
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.cjs +8 -7
- package/dist/snaps/SnapPlatformWatcher.cjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts +7 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts +7 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.mjs +8 -7
- package/dist/snaps/SnapPlatformWatcher.mjs.map +1 -1
- package/dist/tests/accounts.d.cts +21 -7
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +21 -7
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/providers.cjs +12 -0
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +2 -1
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +2 -1
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +12 -0
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -54
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -54
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +14 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountProviderWrapper.d.mts","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AccountProviderWrapper.d.mts","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,wBAAwB;IAClE,OAAO,CAAC,SAAS,CAAiB;IAElC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;gBAGlD,SAAS,EAAE,iCAAiC,EAC5C,QAAQ,EAAE,wBAAwB;IAM3B,OAAO,IAAI,MAAM;IAI1B,IAAI,YAAY,IAAI,mBAAmB,CAEtC;IAED;;;;;OAKG;IACM,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI;IAInE;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACY,cAAc,CAC3B,QAAQ,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,GACxC,OAAO,CAAC,IAAI,CAAC;IAOhB;;;;OAIG;IACM,WAAW,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE;IAOvC,aAAa,CAAC,OAAO,EAAE;QACpC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;IAOjD;;;;;;OAMG;IACM,UAAU,CACjB,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GACrC,YAAY,CAAC,cAAc,CAAC;IAO/B;;;;;;OAMG;IACH,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO;IAInE;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAO1C;;;;;;;OAOG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAC9B,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;CAM5C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,sBAAsB,CAEpC"}
|
|
@@ -12,6 +12,9 @@ export class AccountProviderWrapper extends BaseBip44AccountProvider {
|
|
|
12
12
|
getName() {
|
|
13
13
|
return this.provider.getName();
|
|
14
14
|
}
|
|
15
|
+
get capabilities() {
|
|
16
|
+
return this.provider.capabilities;
|
|
17
|
+
}
|
|
15
18
|
/**
|
|
16
19
|
* Forward initialization to the wrapped provider to ensure both
|
|
17
20
|
* instances share the same visible account IDs.
|
|
@@ -87,8 +90,6 @@ export class AccountProviderWrapper extends BaseBip44AccountProvider {
|
|
|
87
90
|
* Implement abstract method: Create accounts, returns empty array when disabled.
|
|
88
91
|
*
|
|
89
92
|
* @param options - Account creation options.
|
|
90
|
-
* @param options.entropySource - The entropy source to use.
|
|
91
|
-
* @param options.groupIndex - The group index to use.
|
|
92
93
|
* @returns Promise resolving to created accounts, or empty array if disabled.
|
|
93
94
|
*/
|
|
94
95
|
async createAccounts(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountProviderWrapper.mjs","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccountProviderWrapper.mjs","sourceRoot":"","sources":["../../src/providers/AccountProviderWrapper.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AAGtE;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,wBAAwB;IAKlE,YACE,SAA4C,EAC5C,QAAkC;QAElC,KAAK,CAAC,SAAS,CAAC,CAAC;QARX,cAAS,GAAY,IAAI,CAAC;QAShC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEQ,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACM,IAAI,CAAC,QAA8C;QAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,OAAgB;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,UAAU;QACR,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACM,KAAK,CAAC,cAAc,CAC3B,QAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,C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;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AACpD,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { BaseBip44AccountProvider } from './BaseBip44AccountProvider';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * A simple wrapper that adds disable functionality to any BaseBip44AccountProvider.\n * When disabled, the provider will not create new accounts and return empty results.\n */\nexport class AccountProviderWrapper extends BaseBip44AccountProvider {\n private isEnabled: boolean = true;\n\n private readonly provider: BaseBip44AccountProvider;\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n provider: BaseBip44AccountProvider,\n ) {\n super(messenger);\n this.provider = provider;\n }\n\n override getName(): string {\n return this.provider.getName();\n }\n\n get capabilities(): KeyringCapabilities {\n return this.provider.capabilities;\n }\n\n /**\n * Forward initialization to the wrapped provider to ensure both\n * instances share the same visible account IDs.\n *\n * @param accounts - Account IDs to initialize with.\n */\n override init(accounts: Bip44Account<KeyringAccount>['id'][]): void {\n this.provider.init(accounts);\n }\n\n /**\n * Set the enabled state for this provider.\n *\n * @param enabled - Whether the provider should be enabled.\n */\n setEnabled(enabled: boolean): void {\n this.isEnabled = enabled;\n }\n\n isDisabled(): boolean {\n return !this.isEnabled;\n }\n\n /**\n * Override resyncAccounts to not execute it when disabled.\n *\n * @param accounts - List of local accounts.\n */\n override async resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void> {\n if (!this.isEnabled) {\n return;\n }\n await this.provider.resyncAccounts(accounts);\n }\n\n /**\n * Override getAccounts to return empty array when disabled.\n *\n * @returns Array of accounts, or empty array if disabled.\n */\n override getAccounts(): Bip44Account<KeyringAccount>[] {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.getAccounts();\n }\n\n override async alignAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>['id'][]> {\n if (this.isDisabled()) {\n return [];\n }\n return await this.provider.alignAccounts(options);\n }\n\n /**\n * Override getAccount to throw when disabled.\n *\n * @param id - The account ID to retrieve.\n * @returns The account with the specified ID.\n * @throws When disabled or account not found.\n */\n override getAccount(\n id: Bip44Account<KeyringAccount>['id'],\n ): Bip44Account<KeyringAccount> {\n if (!this.isEnabled) {\n throw new Error('Provider is disabled');\n }\n return this.provider.getAccount(id);\n }\n\n /**\n * Implement abstract method: Check if account is compatible.\n * Delegates directly to wrapped provider - no runtime checks needed!\n *\n * @param account - The account to check.\n * @returns True if the account is compatible.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean {\n return this.provider.isAccountCompatible(account);\n }\n\n /**\n * Implement abstract method: Create accounts, returns empty array when disabled.\n *\n * @param options - Account creation options.\n * @returns Promise resolving to created accounts, or empty array if disabled.\n */\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.createAccounts(options);\n }\n\n /**\n * Implement abstract method: Discover and create accounts, returns empty array when disabled.\n *\n * @param options - Account discovery options.\n * @param options.entropySource - The entropy source to use.\n * @param options.groupIndex - The group index to use.\n * @returns Promise resolving to discovered accounts, or empty array if disabled.\n */\n async discoverAccounts(options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n if (!this.isEnabled) {\n return [];\n }\n return this.provider.discoverAccounts(options);\n }\n}\n\n/**\n * Simple type guard to check if a provider is wrapped.\n *\n * @param provider - The provider to check.\n * @returns True if the provider is an AccountProviderWrapper.\n */\nexport function isAccountProviderWrapper(\n provider: unknown,\n): provider is AccountProviderWrapper {\n return provider instanceof AccountProviderWrapper;\n}\n"]}
|
|
@@ -8,6 +8,7 @@ var _BaseBip44AccountProvider_instances, _BaseBip44AccountProvider_getAccountIds
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.BaseBip44AccountProvider = exports.assertAreBip44Accounts = exports.assertIsBip44Account = void 0;
|
|
10
10
|
const account_api_1 = require("@metamask/account-api");
|
|
11
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
11
12
|
/**
|
|
12
13
|
* Asserts a keyring account is BIP-44 compatible.
|
|
13
14
|
*
|
|
@@ -84,6 +85,7 @@ class BaseBip44AccountProvider {
|
|
|
84
85
|
}
|
|
85
86
|
async alignAccounts({ entropySource, groupIndex, }) {
|
|
86
87
|
const accounts = await this.createAccounts({
|
|
88
|
+
type: keyring_api_1.AccountCreationType.Bip44DeriveIndex,
|
|
87
89
|
entropySource,
|
|
88
90
|
groupIndex,
|
|
89
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;
|
|
1
|
+
{"version":3,"file":"BaseBip44AccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAAuD;AAEvD,uDAA4D;AAe5D;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAND,oDAMC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA0B;IAE1B,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACzC,CAAC;AAJD,wDAIC;AA8DD,MAAsB,wBAAwB;IAQ5C,YAAY,SAA4C;;QAF9C,aAAQ,GAA4C,IAAI,GAAG,EAAE,CAAC;QAGtE,IA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C,cAAc,CAAC;YACzC,IAAI,EAAE,iCAAmB,CAAC,gBAAgB;YAC1C,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;CAqBF;AAjID,4DAiIC;;IAlGG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Align the accounts with the given entropy source and group index.\n *\n * @param options - The options for aligning the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @returns The already and newly aligned accounts IDs.\n */\n alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]>;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\n }\n\n protected async withKeyring<SelectedKeyring, CallbackResult = void>(\n selector: KeyringSelector,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n async alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]> {\n const accounts = await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n const accountIds = accounts.map((account) => account.id);\n return accountIds;\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccountProvider, Bip44Account } from "@metamask/account-api";
|
|
2
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
3
3
|
import type { KeyringMetadata, KeyringSelector } from "@metamask/keyring-controller";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "../types.cjs";
|
|
@@ -18,6 +18,12 @@ export declare function assertIsBip44Account(account: KeyringAccount): asserts a
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function assertAreBip44Accounts(accounts: KeyringAccount[]): asserts accounts is Bip44Account<KeyringAccount>[];
|
|
20
20
|
export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> = AccountProvider<Account> & {
|
|
21
|
+
/**
|
|
22
|
+
* Provider capabilities, including supported scopes and BIP-44 options.
|
|
23
|
+
*
|
|
24
|
+
* @returns The provider capabilities.
|
|
25
|
+
*/
|
|
26
|
+
get capabilities(): KeyringCapabilities;
|
|
21
27
|
/**
|
|
22
28
|
* Get the name of the provider.
|
|
23
29
|
*
|
|
@@ -46,6 +52,16 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
|
|
|
46
52
|
entropySource: EntropySourceId;
|
|
47
53
|
groupIndex: number;
|
|
48
54
|
}): Promise<Account['id'][]>;
|
|
55
|
+
/**
|
|
56
|
+
* Create accounts for the provider.
|
|
57
|
+
*
|
|
58
|
+
* @param options - The options for creating the accounts.
|
|
59
|
+
* @param options.entropySource - The entropy source.
|
|
60
|
+
* @param options.groupIndex - The group index.
|
|
61
|
+
* @param options.type - The type of account creation.
|
|
62
|
+
* @returns The created accounts.
|
|
63
|
+
*/
|
|
64
|
+
createAccounts(options: CreateAccountOptions): Promise<Account[]>;
|
|
49
65
|
/**
|
|
50
66
|
* Re-synchronize MetaMask accounts and the providers accounts if needed.
|
|
51
67
|
*
|
|
@@ -90,13 +106,11 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
|
|
|
90
106
|
entropySource: EntropySourceId;
|
|
91
107
|
groupIndex: number;
|
|
92
108
|
}): Promise<Account['id'][]>;
|
|
109
|
+
abstract get capabilities(): KeyringCapabilities;
|
|
93
110
|
abstract getName(): string;
|
|
94
111
|
abstract resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
|
|
95
112
|
abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
|
|
96
|
-
abstract createAccounts(
|
|
97
|
-
entropySource: EntropySourceId;
|
|
98
|
-
groupIndex: number;
|
|
99
|
-
}): Promise<Account[]>;
|
|
113
|
+
abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;
|
|
100
114
|
abstract discoverAccounts({ entropySource, groupIndex, }: {
|
|
101
115
|
entropySource: EntropySourceId;
|
|
102
116
|
groupIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseBip44AccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"BaseBip44AccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,8BAA8B;AAE3E,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAC/B,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAChB,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE;;;;;GAKG;AACH,wBAAgB,oBA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,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CACvB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccountProvider, Bip44Account } from "@metamask/account-api";
|
|
2
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
3
3
|
import type { KeyringMetadata, KeyringSelector } from "@metamask/keyring-controller";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { MultichainAccountServiceMessenger } from "../types.mjs";
|
|
@@ -18,6 +18,12 @@ export declare function assertIsBip44Account(account: KeyringAccount): asserts a
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function assertAreBip44Accounts(accounts: KeyringAccount[]): asserts accounts is Bip44Account<KeyringAccount>[];
|
|
20
20
|
export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>> = AccountProvider<Account> & {
|
|
21
|
+
/**
|
|
22
|
+
* Provider capabilities, including supported scopes and BIP-44 options.
|
|
23
|
+
*
|
|
24
|
+
* @returns The provider capabilities.
|
|
25
|
+
*/
|
|
26
|
+
get capabilities(): KeyringCapabilities;
|
|
21
27
|
/**
|
|
22
28
|
* Get the name of the provider.
|
|
23
29
|
*
|
|
@@ -46,6 +52,16 @@ export type Bip44AccountProvider<Account extends Bip44Account<KeyringAccount> =
|
|
|
46
52
|
entropySource: EntropySourceId;
|
|
47
53
|
groupIndex: number;
|
|
48
54
|
}): Promise<Account['id'][]>;
|
|
55
|
+
/**
|
|
56
|
+
* Create accounts for the provider.
|
|
57
|
+
*
|
|
58
|
+
* @param options - The options for creating the accounts.
|
|
59
|
+
* @param options.entropySource - The entropy source.
|
|
60
|
+
* @param options.groupIndex - The group index.
|
|
61
|
+
* @param options.type - The type of account creation.
|
|
62
|
+
* @returns The created accounts.
|
|
63
|
+
*/
|
|
64
|
+
createAccounts(options: CreateAccountOptions): Promise<Account[]>;
|
|
49
65
|
/**
|
|
50
66
|
* Re-synchronize MetaMask accounts and the providers accounts if needed.
|
|
51
67
|
*
|
|
@@ -90,13 +106,11 @@ export declare abstract class BaseBip44AccountProvider<Account extends Bip44Acco
|
|
|
90
106
|
entropySource: EntropySourceId;
|
|
91
107
|
groupIndex: number;
|
|
92
108
|
}): Promise<Account['id'][]>;
|
|
109
|
+
abstract get capabilities(): KeyringCapabilities;
|
|
93
110
|
abstract getName(): string;
|
|
94
111
|
abstract resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;
|
|
95
112
|
abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;
|
|
96
|
-
abstract createAccounts(
|
|
97
|
-
entropySource: EntropySourceId;
|
|
98
|
-
groupIndex: number;
|
|
99
|
-
}): Promise<Account[]>;
|
|
113
|
+
abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;
|
|
100
114
|
abstract discoverAccounts({ entropySource, groupIndex, }: {
|
|
101
115
|
entropySource: EntropySourceId;
|
|
102
116
|
groupIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseBip44AccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"BaseBip44AccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,8BAA8B;AAE3E,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAC/B,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAChB,qCAAqC;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,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAE1E,QAAQ,CAAC,gBAAgB,CAAC,EACxB,aAAa,EACb,UAAU,GACX,EAAE;QACD,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CACvB"}
|
|
@@ -5,6 +5,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _BaseBip44AccountProvider_instances, _BaseBip44AccountProvider_getAccountIds;
|
|
7
7
|
import { isBip44Account } from "@metamask/account-api";
|
|
8
|
+
import { AccountCreationType } from "@metamask/keyring-api";
|
|
8
9
|
/**
|
|
9
10
|
* Asserts a keyring account is BIP-44 compatible.
|
|
10
11
|
*
|
|
@@ -79,6 +80,7 @@ export class BaseBip44AccountProvider {
|
|
|
79
80
|
}
|
|
80
81
|
async alignAccounts({ entropySource, groupIndex, }) {
|
|
81
82
|
const accounts = await this.createAccounts({
|
|
83
|
+
type: AccountCreationType.Bip44DeriveIndex,
|
|
82
84
|
entropySource,
|
|
83
85
|
groupIndex,
|
|
84
86
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseBip44AccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"BaseBip44AccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BaseBip44AccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,mBAAmB,EAAE,8BAA8B;AAe5D;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAuB;IAEvB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC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C,IAAI,CACtC,+BAA+B,EAC/B,QAAQ,EACR,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,OAAO,EAAE,OAA0B;YACnC,QAAQ;SACT,CAAC,CACL,CAAC;QAEF,OAAO,MAAwB,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAClB,aAAa,EACb,UAAU,GAIX;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YACzC,IAAI,EAAE,mBAAmB,CAAC,gBAAgB;YAC1C,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;CAqBF;;IAlGG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { isBip44Account } from '@metamask/account-api';\nimport type { AccountProvider, Bip44Account } from '@metamask/account-api';\nimport { AccountCreationType } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport type {\n KeyringMetadata,\n KeyringSelector,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { MultichainAccountServiceMessenger } from '../types';\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account(\n account: KeyringAccount,\n): asserts account is Bip44Account<KeyringAccount> {\n if (!isBip44Account(account)) {\n throw new Error('Created account is not BIP-44 compatible');\n }\n}\n\n/**\n * Asserts that a list of keyring accounts are all BIP-44 compatible.\n *\n * @param accounts - Keyring accounts to check.\n * @throws If any of the keyring account is not compatible.\n */\nexport function assertAreBip44Accounts(\n accounts: KeyringAccount[],\n): asserts accounts is Bip44Account<KeyringAccount>[] {\n accounts.forEach(assertIsBip44Account);\n}\n\nexport type Bip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> = AccountProvider<Account> & {\n /**\n * Provider capabilities, including supported scopes and BIP-44 options.\n *\n * @returns The provider capabilities.\n */\n get capabilities(): KeyringCapabilities;\n /**\n * Get the name of the provider.\n *\n * @returns The name of the provider.\n */\n getName(): string;\n /**\n * Initialize the provider with the given accounts.\n *\n * @param accounts - The accounts to initialize the provider with.\n */\n init(accounts: Bip44Account<KeyringAccount>['id'][]): void;\n /**\n * Check if the account is compatible with the provider.\n */\n isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n /**\n * Align the accounts with the given entropy source and group index.\n *\n * @param options - The options for aligning the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @returns The already and newly aligned accounts IDs.\n */\n alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]>;\n /**\n * Create accounts for the provider.\n *\n * @param options - The options for creating the accounts.\n * @param options.entropySource - The entropy source.\n * @param options.groupIndex - The group index.\n * @param options.type - The type of account creation.\n * @returns The created accounts.\n */\n createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n /**\n * Re-synchronize MetaMask accounts and the providers accounts if needed.\n *\n * NOTE: This is mostly required if one of the providers (keyrings or Snaps)\n * have different sets of accounts. This method would ensure that both are\n * in-sync and use the same accounts (and same IDs).\n */\n resyncAccounts(accounts: Bip44Account<InternalAccount>[]): Promise<void>;\n};\n\nexport abstract class BaseBip44AccountProvider<\n Account extends Bip44Account<KeyringAccount> = Bip44Account<KeyringAccount>,\n> implements Bip44AccountProvider\n{\n protected readonly messenger: MultichainAccountServiceMessenger;\n\n protected accounts: Set<Bip44Account<KeyringAccount>['id']> = new Set();\n\n constructor(messenger: MultichainAccountServiceMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Add accounts to the provider.\n *\n * Note: There's an implicit assumption that the accounts are BIP-44 compatible.\n *\n * @param accounts - The accounts to add.\n */\n init(accounts: Account['id'][]): void {\n for (const account of accounts) {\n this.accounts.add(account);\n }\n }\n\n /**\n * Get the accounts list for the provider.\n *\n * @returns The accounts list.\n */\n #getAccountIds(): Account['id'][] {\n return [...this.accounts];\n }\n\n /**\n * Get the accounts list for the provider from the AccountsController.\n *\n * @returns The accounts list.\n */\n getAccounts(): Account[] {\n const accountsIds = this.#getAccountIds();\n const internalAccounts = this.messenger.call(\n 'AccountsController:getAccounts',\n accountsIds,\n );\n // we cast here because we know that the accounts are BIP-44 compatible\n return internalAccounts as unknown as Account[];\n }\n\n /**\n * Get the account for the provider.\n *\n * @param id - The account ID.\n * @returns The account.\n * @throws If the account is not found.\n */\n getAccount(id: Account['id']): Account {\n const hasAccount = this.accounts.has(id);\n\n if (!hasAccount) {\n throw new Error(`Unable to find account: ${id}`);\n }\n\n // We need to upcast here since InternalAccounts are not always BIP-44 compatible\n // but we know that the account is BIP-44 compatible here so it is safe to do so\n return this.messenger.call(\n 'AccountsController:getAccount',\n id,\n ) as unknown as Account;\n }\n\n protected async withKeyring<SelectedKeyring, CallbackResult = void>(\n selector: KeyringSelector,\n operation: ({\n keyring,\n metadata,\n }: {\n keyring: SelectedKeyring;\n metadata: KeyringMetadata;\n }) => Promise<CallbackResult>,\n ): Promise<CallbackResult> {\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n selector,\n ({ keyring, metadata }) =>\n operation({\n keyring: keyring as SelectedKeyring,\n metadata,\n }),\n );\n\n return result as CallbackResult;\n }\n\n async alignAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account['id'][]> {\n const accounts = await this.createAccounts({\n type: AccountCreationType.Bip44DeriveIndex,\n entropySource,\n groupIndex,\n });\n const accountIds = accounts.map((account) => account.id);\n return accountIds;\n }\n\n abstract get capabilities(): KeyringCapabilities;\n\n abstract getName(): string;\n\n abstract resyncAccounts(\n accounts: Bip44Account<InternalAccount>[],\n ): Promise<void>;\n\n abstract isAccountCompatible(account: Bip44Account<KeyringAccount>): boolean;\n\n abstract createAccounts(options: CreateAccountOptions): Promise<Account[]>;\n\n abstract discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Account[]>;\n}\n"]}
|
|
@@ -30,6 +30,12 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
30
30
|
constructor(messenger, config = exports.BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = analytics_1.traceFallback) {
|
|
31
31
|
super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);
|
|
32
32
|
_BtcAccountProvider_instances.add(this);
|
|
33
|
+
this.capabilities = {
|
|
34
|
+
scopes: [keyring_api_1.BtcScope.Mainnet, keyring_api_1.BtcScope.Testnet],
|
|
35
|
+
bip44: {
|
|
36
|
+
deriveIndex: true,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
33
39
|
}
|
|
34
40
|
getName() {
|
|
35
41
|
return BtcAccountProvider.NAME;
|
|
@@ -38,7 +44,11 @@ class BtcAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
38
44
|
return (account.type === keyring_api_1.BtcAccountType.P2wpkh &&
|
|
39
45
|
Object.values(keyring_api_1.BtcAccountType).includes(account.type));
|
|
40
46
|
}
|
|
41
|
-
async createAccounts(
|
|
47
|
+
async createAccounts(options) {
|
|
48
|
+
(0, keyring_api_1.assertCreateAccountOptionIsSupported)(options, [
|
|
49
|
+
`${keyring_api_1.AccountCreationType.Bip44DeriveIndex}`,
|
|
50
|
+
]);
|
|
51
|
+
const { entropySource, groupIndex } = options;
|
|
42
52
|
return this.withSnap(async ({ keyring }) => {
|
|
43
53
|
return __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, { keyring, entropySource, groupIndex });
|
|
44
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;
|
|
1
|
+
{"version":3,"file":"BtcAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;AAS7D,uDAK+B;AAI/B,mEAA4D;AAK5D,uCAAiD;AACjD,sDAA6C;AAC7C,oDAAgD;AAKnC,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEtC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IAYzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;;QAZzD,iBAAY,GAAwB;YAC3C,MAAM,EAAE,CAAC,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,OAAO,CAAC;YAC5C,KAAK,EAAE;gBACL,WAAW,EAAE,IAAI;aAClB;SACF,CAAC;IAQF,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,MAAM;YACtC,MAAM,CAAC,MAAM,CAAS,4BAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,I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AC,SAAS,CAAC,SAAS;iBAC3C,CACF,CAAC;gBAEF,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;oBAClC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAC/B,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,MAAM,eAAe,GAAG,MAAM,uBAAA,IAAI,yEAAgB,MAApB,IAAI,EAAiB;oBACjD,OAAO;oBACP,aAAa;oBACb,UAAU;iBACX,CAAC,CAAC;gBAEH,OAAO,eAAe,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AA5HH,gDA6HC;oFA9FC,KAAK,6CAAiB,EACpB,OAAO,EACP,aAAa,EACb,UAAU,EAAE,KAAK,GAKlB;IACC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;QACxC,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAW,EAC/B,OAAO,CAAC,aAAa,CAAC;YACpB,aAAa;YACb,KAAK;YACL,WAAW,EAAE,4BAAc,CAAC,MAAM;YAClC,KAAK,EAAE,sBAAQ,CAAC,OAAO;SACxB,CAAC,EACF,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;QAEF,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAtDM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n this.accounts.add(account.id);\n return [account];\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n ]);\n\n const { entropySource, groupIndex } = options;\n\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Bip44Account } from "@metamask/account-api";
|
|
2
2
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
3
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
|
+
import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
6
|
import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
|
|
@@ -13,13 +13,11 @@ export declare class BtcAccountProvider extends SnapAccountProvider {
|
|
|
13
13
|
#private;
|
|
14
14
|
static NAME: string;
|
|
15
15
|
static BTC_SNAP_ID: SnapId;
|
|
16
|
+
readonly capabilities: KeyringCapabilities;
|
|
16
17
|
constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
|
|
17
18
|
getName(): string;
|
|
18
19
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
19
|
-
createAccounts(
|
|
20
|
-
entropySource: EntropySourceId;
|
|
21
|
-
groupIndex: number;
|
|
22
|
-
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
20
|
+
createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
|
|
23
21
|
discoverAccounts({ entropySource, groupIndex, }: {
|
|
24
22
|
entropySource: EntropySourceId;
|
|
25
23
|
groupIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"BtcAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAO/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAEV,yBAAyB,EAC1B,kCAA8B;AAI/B,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAWjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;IAEnE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAKxC;gBAGA,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAA8D,EACtE,KAAK,GAAE,aAA6B;IAKtC,OAAO,IAAI,MAAM;IAIjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAiC9D,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAYpC,gBAAgB,CAAC,EACrB,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;CAgD5C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Bip44Account } from "@metamask/account-api";
|
|
2
2
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
3
|
-
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
3
|
+
import type { CreateAccountOptions, EntropySourceId, KeyringAccount, KeyringCapabilities } from "@metamask/keyring-api";
|
|
4
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
5
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
6
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
@@ -13,13 +13,11 @@ export declare class BtcAccountProvider extends SnapAccountProvider {
|
|
|
13
13
|
#private;
|
|
14
14
|
static NAME: string;
|
|
15
15
|
static BTC_SNAP_ID: SnapId;
|
|
16
|
+
readonly capabilities: KeyringCapabilities;
|
|
16
17
|
constructor(messenger: MultichainAccountServiceMessenger, config?: BtcAccountProviderConfig, trace?: TraceCallback);
|
|
17
18
|
getName(): string;
|
|
18
19
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
19
|
-
createAccounts(
|
|
20
|
-
entropySource: EntropySourceId;
|
|
21
|
-
groupIndex: number;
|
|
22
|
-
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
20
|
+
createAccounts(options: CreateAccountOptions): Promise<Bip44Account<KeyringAccount>[]>;
|
|
23
21
|
discoverAccounts({ entropySource, groupIndex, }: {
|
|
24
22
|
entropySource: EntropySourceId;
|
|
25
23
|
groupIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"BtcAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,8BAA8B;AAO/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAEV,yBAAyB,EAC1B,kCAA8B;AAI/B,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAElE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,eAAO,MAAM,mCAAmC,EAAE,wBAWjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,WAAW,SAAiD;IAEnE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAKxC;gBAGA,SAAS,EAAE,iCAAiC,EAC5C,MAAM,GAAE,wBAA8D,EACtE,KAAK,GAAE,aAA6B;IAKtC,OAAO,IAAI,MAAM;IAIjB,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,OAAO;IAiC9D,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAYpC,gBAAgB,CAAC,EACrB,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;CAgD5C"}
|
|
@@ -5,7 +5,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _BtcAccountProvider_instances, _BtcAccountProvider_createAccounts;
|
|
7
7
|
import { assertIsBip44Account } from "@metamask/account-api";
|
|
8
|
-
import { BtcAccountType, BtcScope } from "@metamask/keyring-api";
|
|
8
|
+
import { AccountCreationType, assertCreateAccountOptionIsSupported, BtcAccountType, BtcScope } from "@metamask/keyring-api";
|
|
9
9
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
10
10
|
import { withRetry, withTimeout } from "./utils.mjs";
|
|
11
11
|
import { traceFallback } from "../analytics/index.mjs";
|
|
@@ -27,6 +27,12 @@ export class BtcAccountProvider extends SnapAccountProvider {
|
|
|
27
27
|
constructor(messenger, config = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = traceFallback) {
|
|
28
28
|
super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);
|
|
29
29
|
_BtcAccountProvider_instances.add(this);
|
|
30
|
+
this.capabilities = {
|
|
31
|
+
scopes: [BtcScope.Mainnet, BtcScope.Testnet],
|
|
32
|
+
bip44: {
|
|
33
|
+
deriveIndex: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
30
36
|
}
|
|
31
37
|
getName() {
|
|
32
38
|
return BtcAccountProvider.NAME;
|
|
@@ -35,7 +41,11 @@ export class BtcAccountProvider extends SnapAccountProvider {
|
|
|
35
41
|
return (account.type === BtcAccountType.P2wpkh &&
|
|
36
42
|
Object.values(BtcAccountType).includes(account.type));
|
|
37
43
|
}
|
|
38
|
-
async createAccounts(
|
|
44
|
+
async createAccounts(options) {
|
|
45
|
+
assertCreateAccountOptionIsSupported(options, [
|
|
46
|
+
`${AccountCreationType.Bip44DeriveIndex}`,
|
|
47
|
+
]);
|
|
48
|
+
const { entropySource, groupIndex } = options;
|
|
39
49
|
return this.withSnap(async ({ keyring }) => {
|
|
40
50
|
return __classPrivateFieldGet(this, _BtcAccountProvider_instances, "m", _BtcAccountProvider_createAccounts).call(this, { keyring, entropySource, groupIndex });
|
|
41
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/BtcAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"BtcAccountProvider.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3C,CACF,CAAC;gBAEF,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;oBAClC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAC/B,CAAC;oBACD,OAAO,EAAE,CAAC;gBACZ,CAAC;gBAED,MAAM,eAAe,GAAG,MAAM,uBAAA,IAAI,yEAAgB,MAApB,IAAI,EAAiB;oBACjD,OAAO;oBACP,aAAa;oBACb,UAAU;iBACX,CAAC,CAAC;gBAEH,OAAO,eAAe,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;oFA7FD,KAAK,6CAAiB,EACpB,OAAO,EACP,aAAa,EACb,UAAU,EAAE,KAAK,GAKlB;IACC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;QACxC,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,OAAO,CAAC,aAAa,CAAC;YACpB,aAAa;YACb,KAAK;YACL,WAAW,EAAE,cAAc,CAAC,MAAM;YAClC,KAAK,EAAE,QAAQ,CAAC,OAAO;SACxB,CAAC,EACF,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CACrC,CAAC;QAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAtDM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,mCAA6C,AAAhD,CAAiD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n CreateAccountOptions,\n EntropySourceId,\n KeyringAccount,\n KeyringCapabilities,\n} from '@metamask/keyring-api';\nimport {\n AccountCreationType,\n assertCreateAccountOptionIsSupported,\n BtcAccountType,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type {\n RestrictedSnapKeyring,\n SnapAccountProviderConfig,\n} from './SnapAccountProvider';\nimport { withRetry, withTimeout } from './utils';\nimport { traceFallback } from '../analytics';\nimport { TraceName } from '../constants/traces';\nimport type { MultichainAccountServiceMessenger } from '../types';\n\nexport type BtcAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin';\n\nexport const BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG: BtcAccountProviderConfig = {\n maxConcurrency: 3,\n createAccounts: {\n timeoutMs: 3000,\n },\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n};\n\nexport class BtcAccountProvider extends SnapAccountProvider {\n static NAME = BTC_ACCOUNT_PROVIDER_NAME;\n\n static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;\n\n readonly capabilities: KeyringCapabilities = {\n scopes: [BtcScope.Mainnet, BtcScope.Testnet],\n bip44: {\n deriveIndex: true,\n },\n };\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: BtcAccountProviderConfig = BTC_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(BtcAccountProvider.BTC_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return BtcAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === BtcAccountType.P2wpkh &&\n Object.values<string>(BtcAccountType).includes(account.type)\n );\n }\n\n async #createAccounts({\n keyring,\n entropySource,\n groupIndex: index,\n }: {\n keyring: RestrictedSnapKeyring;\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withMaxConcurrency(async () => {\n const account = await withTimeout(\n keyring.createAccount({\n entropySource,\n index,\n addressType: BtcAccountType.P2wpkh,\n scope: BtcScope.Mainnet,\n }),\n this.config.createAccounts.timeoutMs,\n );\n\n assertIsBip44Account(account);\n this.accounts.add(account.id);\n return [account];\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n assertCreateAccountOptionIsSupported(options, [\n `${AccountCreationType.Bip44DeriveIndex}`,\n ]);\n\n const { entropySource, groupIndex } = options;\n\n return this.withSnap(async ({ keyring }) => {\n return this.#createAccounts({ keyring, entropySource, groupIndex });\n });\n }\n\n async discoverAccounts({\n entropySource,\n groupIndex,\n }: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withSnap(async ({ client, keyring }) => {\n return await super.trace(\n {\n name: TraceName.SnapDiscoverAccounts,\n data: {\n provider: this.getName(),\n },\n },\n async () => {\n if (!this.config.discovery.enabled) {\n return [];\n }\n\n const discoveredAccounts = await withRetry(\n () =>\n withTimeout(\n client.discoverAccounts(\n [BtcScope.Mainnet],\n entropySource,\n groupIndex,\n ),\n this.config.discovery.timeoutMs,\n ),\n {\n maxAttempts: this.config.discovery.maxAttempts,\n backOffMs: this.config.discovery.backOffMs,\n },\n );\n\n if (\n !Array.isArray(discoveredAccounts) ||\n discoveredAccounts.length === 0\n ) {\n return [];\n }\n\n const createdAccounts = await this.#createAccounts({\n keyring,\n entropySource,\n groupIndex,\n });\n\n return createdAccounts;\n },\n );\n });\n }\n}\n"]}
|
|
@@ -49,6 +49,12 @@ class EvmAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountProv
|
|
|
49
49
|
_EvmAccountProvider_instances.add(this);
|
|
50
50
|
_EvmAccountProvider_config.set(this, void 0);
|
|
51
51
|
_EvmAccountProvider_trace.set(this, void 0);
|
|
52
|
+
this.capabilities = {
|
|
53
|
+
scopes: [keyring_api_1.EthScope.Eoa],
|
|
54
|
+
bip44: {
|
|
55
|
+
deriveIndex: true,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
52
58
|
__classPrivateFieldSet(this, _EvmAccountProvider_config, {
|
|
53
59
|
...config,
|
|
54
60
|
discovery: {
|
|
@@ -78,12 +84,14 @@ class EvmAccountProvider extends BaseBip44AccountProvider_1.BaseBip44AccountProv
|
|
|
78
84
|
/**
|
|
79
85
|
* Create accounts for the EVM provider.
|
|
80
86
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @param opts.entropySource - The entropy source to use for the creation of the accounts.
|
|
83
|
-
* @param opts.groupIndex - The index of the group to create the accounts for.
|
|
87
|
+
* @param options - The options for the creation of the accounts.
|
|
84
88
|
* @returns The accounts for the EVM provider.
|
|
85
89
|
*/
|
|
86
|
-
async createAccounts(
|
|
90
|
+
async createAccounts(options) {
|
|
91
|
+
(0, keyring_api_1.assertCreateAccountOptionIsSupported)(options, [
|
|
92
|
+
`${keyring_api_1.AccountCreationType.Bip44DeriveIndex}`,
|
|
93
|
+
]);
|
|
94
|
+
const { entropySource, groupIndex } = options;
|
|
87
95
|
const [address] = await __classPrivateFieldGet(this, _EvmAccountProvider_instances, "m", _EvmAccountProvider_createAccount).call(this, {
|
|
88
96
|
entropySource,
|
|
89
97
|
groupIndex,
|