@metamask/multichain-account-service 11.1.0 → 13.0.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 +39 -1
- package/dist/MultichainAccountGroup.cjs +15 -2
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +11 -0
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts +11 -0
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs +15 -2
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +45 -21
- 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 +45 -21
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/analytics/traces.cjs +0 -1
- package/dist/analytics/traces.cjs.map +1 -1
- package/dist/analytics/traces.d.cts +0 -1
- package/dist/analytics/traces.d.cts.map +1 -1
- package/dist/analytics/traces.d.mts +0 -1
- package/dist/analytics/traces.d.mts.map +1 -1
- package/dist/analytics/traces.mjs +0 -1
- package/dist/analytics/traces.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +3 -45
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +3 -12
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +3 -12
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +4 -46
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +121 -82
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +59 -21
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +59 -21
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +123 -84
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapKeyringClient.cjs +35 -0
- package/dist/providers/SnapKeyringClient.cjs.map +1 -0
- package/dist/providers/SnapKeyringClient.d.cts +51 -0
- package/dist/providers/SnapKeyringClient.d.cts.map +1 -0
- package/dist/providers/SnapKeyringClient.d.mts +51 -0
- package/dist/providers/SnapKeyringClient.d.mts.map +1 -0
- package/dist/providers/SnapKeyringClient.mjs +31 -0
- package/dist/providers/SnapKeyringClient.mjs.map +1 -0
- package/dist/providers/SolAccountProvider.cjs +3 -45
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +3 -11
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +3 -11
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +4 -46
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +3 -44
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +3 -12
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +3 -12
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +4 -45
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/providers/XlmAccountProvider.cjs +3 -44
- package/dist/providers/XlmAccountProvider.cjs.map +1 -1
- package/dist/providers/XlmAccountProvider.d.cts +3 -12
- package/dist/providers/XlmAccountProvider.d.cts.map +1 -1
- package/dist/providers/XlmAccountProvider.d.mts +3 -12
- package/dist/providers/XlmAccountProvider.d.mts.map +1 -1
- package/dist/providers/XlmAccountProvider.mjs +4 -45
- package/dist/providers/XlmAccountProvider.mjs.map +1 -1
- package/dist/tests/messenger.cjs +1 -0
- package/dist/tests/messenger.cjs.map +1 -1
- package/dist/tests/messenger.d.cts.map +1 -1
- package/dist/tests/messenger.d.mts.map +1 -1
- package/dist/tests/messenger.mjs +1 -0
- package/dist/tests/messenger.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
3
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Transport used by both the v1 and v2 keyring clients. Matches the object the
|
|
6
|
+
* {@link KeyringClient} constructor expects.
|
|
7
|
+
*/
|
|
8
|
+
export type Sender = ConstructorParameters<typeof KeyringClient>[0];
|
|
9
|
+
type DiscoveredAccount = Awaited<ReturnType<KeyringClient['discoverAccounts']>>[number];
|
|
10
|
+
/**
|
|
11
|
+
* Thin abstraction over the v1 and v2 keyring RPC clients so that provider call
|
|
12
|
+
* sites (account re-sync and v1 discovery) don't have to branch on the keyring
|
|
13
|
+
* protocol version. The v1 and v2 clients expose different method names (e.g.
|
|
14
|
+
* v1 `listAccounts` vs v2 `getAccounts`), and v2 has no `discoverAccounts` — v2
|
|
15
|
+
* discovery flows through `createAccounts({ bip44:discover })` on the bridge
|
|
16
|
+
* keyring instead.
|
|
17
|
+
*/
|
|
18
|
+
export type SnapKeyringClient = {
|
|
19
|
+
/**
|
|
20
|
+
* Returns the accounts the Snap currently holds.
|
|
21
|
+
*/
|
|
22
|
+
getAccounts(): Promise<KeyringAccount[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Deletes an account by id from the Snap.
|
|
25
|
+
*
|
|
26
|
+
* @param id - The id of the account to delete.
|
|
27
|
+
*/
|
|
28
|
+
deleteAccount(id: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Discovers accounts for the given entropy source and group index.
|
|
31
|
+
*
|
|
32
|
+
* Only supported on the v1 client; the v2 client throws, since v2 discovery
|
|
33
|
+
* goes through `createAccounts({ bip44:discover })`.
|
|
34
|
+
*
|
|
35
|
+
* @param scopes - The scopes to discover accounts on.
|
|
36
|
+
* @param entropySource - The entropy source to discover accounts for.
|
|
37
|
+
* @param groupIndex - The group index to discover accounts for.
|
|
38
|
+
*/
|
|
39
|
+
discoverAccounts(scopes: CaipChainId[], entropySource: EntropySourceId, groupIndex: number): Promise<DiscoveredAccount[]>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Builds a version-agnostic {@link SnapKeyringClient} backed by either the v1
|
|
43
|
+
* or v2 keyring client, based on the Snap's declared capabilities.
|
|
44
|
+
*
|
|
45
|
+
* @param sender - The transport used to talk to the Snap.
|
|
46
|
+
* @param isV2 - Whether to back the client with the v2 keyring client.
|
|
47
|
+
* @returns A {@link SnapKeyringClient}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createSnapKeyringClient(sender: Sender, isV2: boolean): SnapKeyringClient;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=SnapKeyringClient.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapKeyringClient.d.cts","sourceRoot":"","sources":["../../src/providers/SnapKeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE,KAAK,iBAAiB,GAAG,OAAO,CAC9B,UAAU,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAC9C,CAAC,MAAM,CAAC,CAAC;AAEV;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEzC;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;;;;OASG;IACH,gBAAgB,CACd,MAAM,EAAE,WAAW,EAAE,EACrB,aAAa,EAAE,eAAe,EAC9B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CACjC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,iBAAiB,CAuBnB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
+
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
3
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Transport used by both the v1 and v2 keyring clients. Matches the object the
|
|
6
|
+
* {@link KeyringClient} constructor expects.
|
|
7
|
+
*/
|
|
8
|
+
export type Sender = ConstructorParameters<typeof KeyringClient>[0];
|
|
9
|
+
type DiscoveredAccount = Awaited<ReturnType<KeyringClient['discoverAccounts']>>[number];
|
|
10
|
+
/**
|
|
11
|
+
* Thin abstraction over the v1 and v2 keyring RPC clients so that provider call
|
|
12
|
+
* sites (account re-sync and v1 discovery) don't have to branch on the keyring
|
|
13
|
+
* protocol version. The v1 and v2 clients expose different method names (e.g.
|
|
14
|
+
* v1 `listAccounts` vs v2 `getAccounts`), and v2 has no `discoverAccounts` — v2
|
|
15
|
+
* discovery flows through `createAccounts({ bip44:discover })` on the bridge
|
|
16
|
+
* keyring instead.
|
|
17
|
+
*/
|
|
18
|
+
export type SnapKeyringClient = {
|
|
19
|
+
/**
|
|
20
|
+
* Returns the accounts the Snap currently holds.
|
|
21
|
+
*/
|
|
22
|
+
getAccounts(): Promise<KeyringAccount[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Deletes an account by id from the Snap.
|
|
25
|
+
*
|
|
26
|
+
* @param id - The id of the account to delete.
|
|
27
|
+
*/
|
|
28
|
+
deleteAccount(id: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Discovers accounts for the given entropy source and group index.
|
|
31
|
+
*
|
|
32
|
+
* Only supported on the v1 client; the v2 client throws, since v2 discovery
|
|
33
|
+
* goes through `createAccounts({ bip44:discover })`.
|
|
34
|
+
*
|
|
35
|
+
* @param scopes - The scopes to discover accounts on.
|
|
36
|
+
* @param entropySource - The entropy source to discover accounts for.
|
|
37
|
+
* @param groupIndex - The group index to discover accounts for.
|
|
38
|
+
*/
|
|
39
|
+
discoverAccounts(scopes: CaipChainId[], entropySource: EntropySourceId, groupIndex: number): Promise<DiscoveredAccount[]>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Builds a version-agnostic {@link SnapKeyringClient} backed by either the v1
|
|
43
|
+
* or v2 keyring client, based on the Snap's declared capabilities.
|
|
44
|
+
*
|
|
45
|
+
* @param sender - The transport used to talk to the Snap.
|
|
46
|
+
* @param isV2 - Whether to back the client with the v2 keyring client.
|
|
47
|
+
* @returns A {@link SnapKeyringClient}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createSnapKeyringClient(sender: Sender, isV2: boolean): SnapKeyringClient;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=SnapKeyringClient.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapKeyringClient.d.mts","sourceRoot":"","sources":["../../src/providers/SnapKeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAC7E,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE,KAAK,iBAAiB,GAAG,OAAO,CAC9B,UAAU,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAC9C,CAAC,MAAM,CAAC,CAAC;AAEV;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEzC;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;;;;OASG;IACH,gBAAgB,CACd,MAAM,EAAE,WAAW,EAAE,EACrB,aAAa,EAAE,eAAe,EAC9B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CACjC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,iBAAiB,CAuBnB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
2
|
+
import { KeyringClient as KeyringClientV2 } from "@metamask/keyring-snap-client/v2";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a version-agnostic {@link SnapKeyringClient} backed by either the v1
|
|
5
|
+
* or v2 keyring client, based on the Snap's declared capabilities.
|
|
6
|
+
*
|
|
7
|
+
* @param sender - The transport used to talk to the Snap.
|
|
8
|
+
* @param isV2 - Whether to back the client with the v2 keyring client.
|
|
9
|
+
* @returns A {@link SnapKeyringClient}.
|
|
10
|
+
*/
|
|
11
|
+
export function createSnapKeyringClient(sender, isV2) {
|
|
12
|
+
if (isV2) {
|
|
13
|
+
const client = new KeyringClientV2(sender);
|
|
14
|
+
return {
|
|
15
|
+
getAccounts: async () => client.getAccounts(),
|
|
16
|
+
deleteAccount: async (id) => client.deleteAccount(id),
|
|
17
|
+
discoverAccounts: async () => {
|
|
18
|
+
// v2 discovery is driven by `createAccounts({ bip44:discover })` through
|
|
19
|
+
// the bridge keyring, so the client is never used for discovery here.
|
|
20
|
+
throw new Error('discoverAccounts is not supported on the v2 keyring client');
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const client = new KeyringClient(sender);
|
|
25
|
+
return {
|
|
26
|
+
getAccounts: async () => client.listAccounts(),
|
|
27
|
+
deleteAccount: async (id) => client.deleteAccount(id),
|
|
28
|
+
discoverAccounts: async (scopes, entropySource, groupIndex) => client.discoverAccounts(scopes, entropySource, groupIndex),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=SnapKeyringClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapKeyringClient.mjs","sourceRoot":"","sources":["../../src/providers/SnapKeyringClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAC9D,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,yCAAyC;AAmDpF;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,IAAa;IAEb,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,OAAO;YACL,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE;YAC7C,aAAa,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACrD,gBAAgB,EAAE,KAAK,IAAkC,EAAE;gBACzD,yEAAyE;gBACzE,sEAAsE;gBACtE,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO;QACL,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE;QAC9C,aAAa,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACrD,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,EAAE,CAC5D,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport { KeyringClient as KeyringClientV2 } from '@metamask/keyring-snap-client/v2';\nimport type { CaipChainId } from '@metamask/utils';\n\n/**\n * Transport used by both the v1 and v2 keyring clients. Matches the object the\n * {@link KeyringClient} constructor expects.\n */\nexport type Sender = ConstructorParameters<typeof KeyringClient>[0];\n\ntype DiscoveredAccount = Awaited<\n ReturnType<KeyringClient['discoverAccounts']>\n>[number];\n\n/**\n * Thin abstraction over the v1 and v2 keyring RPC clients so that provider call\n * sites (account re-sync and v1 discovery) don't have to branch on the keyring\n * protocol version. The v1 and v2 clients expose different method names (e.g.\n * v1 `listAccounts` vs v2 `getAccounts`), and v2 has no `discoverAccounts` — v2\n * discovery flows through `createAccounts({ bip44:discover })` on the bridge\n * keyring instead.\n */\nexport type SnapKeyringClient = {\n /**\n * Returns the accounts the Snap currently holds.\n */\n getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Deletes an account by id from the Snap.\n *\n * @param id - The id of the account to delete.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Discovers accounts for the given entropy source and group index.\n *\n * Only supported on the v1 client; the v2 client throws, since v2 discovery\n * goes through `createAccounts({ bip44:discover })`.\n *\n * @param scopes - The scopes to discover accounts on.\n * @param entropySource - The entropy source to discover accounts for.\n * @param groupIndex - The group index to discover accounts for.\n */\n discoverAccounts(\n scopes: CaipChainId[],\n entropySource: EntropySourceId,\n groupIndex: number,\n ): Promise<DiscoveredAccount[]>;\n};\n\n/**\n * Builds a version-agnostic {@link SnapKeyringClient} backed by either the v1\n * or v2 keyring client, based on the Snap's declared capabilities.\n *\n * @param sender - The transport used to talk to the Snap.\n * @param isV2 - Whether to back the client with the v2 keyring client.\n * @returns A {@link SnapKeyringClient}.\n */\nexport function createSnapKeyringClient(\n sender: Sender,\n isV2: boolean,\n): SnapKeyringClient {\n if (isV2) {\n const client = new KeyringClientV2(sender);\n return {\n getAccounts: async () => client.getAccounts(),\n deleteAccount: async (id) => client.deleteAccount(id),\n discoverAccounts: async (): Promise<DiscoveredAccount[]> => {\n // v2 discovery is driven by `createAccounts({ bip44:discover })` through\n // the bridge keyring, so the client is never used for discovery here.\n throw new Error(\n 'discoverAccounts is not supported on the v2 keyring client',\n );\n },\n };\n }\n\n const client = new KeyringClient(sender);\n return {\n getAccounts: async () => client.listAccounts(),\n deleteAccount: async (id) => client.deleteAccount(id),\n discoverAccounts: async (scopes, entropySource, groupIndex) =>\n client.discoverAccounts(scopes, entropySource, groupIndex),\n };\n}\n"]}
|
|
@@ -11,9 +11,7 @@ const account_api_1 = require("@metamask/account-api");
|
|
|
11
11
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
12
12
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
13
13
|
const analytics_1 = require("../analytics/index.cjs");
|
|
14
|
-
const traces_1 = require("../analytics/traces.cjs");
|
|
15
14
|
const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
|
|
16
|
-
const utils_1 = require("./utils.cjs");
|
|
17
15
|
exports.SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
|
|
18
16
|
exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
19
17
|
maxConcurrency: 3,
|
|
@@ -24,7 +22,6 @@ exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
|
24
22
|
backOffMs: 1000,
|
|
25
23
|
},
|
|
26
24
|
createAccounts: {
|
|
27
|
-
batched: false, // For now, the Snap is not fully v2 compliant.
|
|
28
25
|
timeoutMs: 3000,
|
|
29
26
|
},
|
|
30
27
|
resyncAccounts: {
|
|
@@ -35,13 +32,9 @@ class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
35
32
|
constructor(messenger, config = exports.SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = analytics_1.traceFallback) {
|
|
36
33
|
super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);
|
|
37
34
|
_SolAccountProvider_instances.add(this);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
deriveIndex: true,
|
|
42
|
-
deriveIndexRange: true,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
35
|
+
// TODO: Remove once the Snap is fully v2 — discovery is then driven by the
|
|
36
|
+
// Snap's own supported scopes via `createAccounts({ bip44:discover })`.
|
|
37
|
+
this.v1DiscoveryScopes = [keyring_api_1.SolScope.Mainnet];
|
|
45
38
|
}
|
|
46
39
|
getName() {
|
|
47
40
|
return SolAccountProvider.NAME;
|
|
@@ -50,12 +43,6 @@ class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
50
43
|
return (account.type === keyring_api_1.SolAccountType.DataAccount &&
|
|
51
44
|
account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
|
|
52
45
|
}
|
|
53
|
-
async createAccountV1(keyring, { entropySource, groupIndex, }) {
|
|
54
|
-
return keyring.createAccount({
|
|
55
|
-
entropySource,
|
|
56
|
-
derivationPath: __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getDerivationPath).call(this, groupIndex),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
46
|
toBip44Account(account, { entropySource, groupIndex, }) {
|
|
60
47
|
// Ensure entropy is present before type assertion validation
|
|
61
48
|
account.options.entropy = {
|
|
@@ -67,35 +54,6 @@ class SolAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
67
54
|
(0, account_api_1.assertIsBip44Account)(account);
|
|
68
55
|
return account;
|
|
69
56
|
}
|
|
70
|
-
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
71
|
-
return this.withSnap(async ({ client, keyring }) => {
|
|
72
|
-
return await super.trace({
|
|
73
|
-
name: traces_1.TraceName.SnapDiscoverAccounts,
|
|
74
|
-
data: {
|
|
75
|
-
provider: this.getName(),
|
|
76
|
-
},
|
|
77
|
-
}, async () => {
|
|
78
|
-
if (!this.config.discovery.enabled) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(() => client.discoverAccounts([keyring_api_1.SolScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
82
|
-
maxAttempts: this.config.discovery.maxAttempts,
|
|
83
|
-
backOffMs: this.config.discovery.backOffMs,
|
|
84
|
-
});
|
|
85
|
-
if (!discoveredAccounts.length) {
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
// NOTE: We know the Solana Snap only return 1 account per group index during discovery. Also,
|
|
89
|
-
// we do not use the returned `derivationPath` on purpose. Instead we just create the account
|
|
90
|
-
// for this group index and that's all.
|
|
91
|
-
return await this.createBip44Accounts(keyring, {
|
|
92
|
-
type: keyring_api_1.AccountCreationType.Bip44DeriveIndex,
|
|
93
|
-
entropySource,
|
|
94
|
-
groupIndex,
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
57
|
}
|
|
100
58
|
exports.SolAccountProvider = SolAccountProvider;
|
|
101
59
|
_SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getDerivationPath = function _SolAccountProvider_getDerivationPath(groupIndex) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA6D;AAG7D,uDAI+B;AAE/B,qEAA4D;AAK5D,sDAA6C;AAE7C,mEAA4D;AAK/C,QAAA,yBAAyB,GAAG,QAAQ,CAAC;AAErC,QAAA,mCAAmC,GAA8B;IAC5E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;;QATrE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,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;IAMkB,cAAc,CAC/B,OAAuB,EACvB,EACE,aAAa,EACb,UAAU,GAC6C;QAEzD,6DAA6D;QAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,6CAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc,EAAE,uBAAA,IAAI,4EAAmB,MAAvB,IAAI,EAAoB,UAAU,CAAC;SACpD,CAAC;QAEF,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,OAAO,CAAC;IACjB,CAAC;;AAlDH,gDAmDC;sIAvBoB,UAAkB;IACnC,OAAO,cAAc,UAAU,MAAM,CAAC;AACxC,CAAC;AA7BM,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolScope,\n} from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } 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 { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\n\nexport type SolAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';\n\nexport const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static NAME = SOL_ACCOUNT_PROVIDER_NAME;\n\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [SolScope.Mainnet];\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\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 #getDerivationPath(groupIndex: number): string {\n return `m/44'/501'/${groupIndex}'/0'`;\n }\n\n protected override toBip44Account(\n account: KeyringAccount,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath: this.#getDerivationPath(groupIndex),\n };\n\n assertIsBip44Account(account);\n\n return account;\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Bip44Account } from "@metamask/account-api";
|
|
2
2
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
|
-
import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
|
|
5
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
7
7
|
import type { MultichainAccountServiceMessenger } from "../types.cjs";
|
|
8
8
|
import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
|
|
9
|
-
import type {
|
|
9
|
+
import type { SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
|
|
10
10
|
export type SolAccountProviderConfig = SnapAccountProviderConfig;
|
|
11
11
|
export declare const SOL_ACCOUNT_PROVIDER_NAME = "Solana";
|
|
12
12
|
export declare const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig;
|
|
@@ -14,21 +14,13 @@ export declare class SolAccountProvider extends SnapAccountProvider {
|
|
|
14
14
|
#private;
|
|
15
15
|
static NAME: string;
|
|
16
16
|
static SOLANA_SNAP_ID: SnapId;
|
|
17
|
-
readonly
|
|
17
|
+
protected readonly v1DiscoveryScopes: CaipChainId[];
|
|
18
18
|
constructor(messenger: MultichainAccountServiceMessenger, config?: SolAccountProviderConfig, trace?: TraceCallback);
|
|
19
19
|
getName(): string;
|
|
20
20
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
21
|
-
protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
|
|
22
|
-
entropySource: EntropySourceId;
|
|
23
|
-
groupIndex: number;
|
|
24
|
-
}): Promise<KeyringAccount>;
|
|
25
21
|
protected toBip44Account(account: KeyringAccount, { entropySource, groupIndex, }: {
|
|
26
22
|
entropySource: EntropySourceId;
|
|
27
23
|
groupIndex: number;
|
|
28
24
|
}): Bip44Account<KeyringAccount>;
|
|
29
|
-
discoverAccounts({ entropySource, groupIndex, }: {
|
|
30
|
-
entropySource: EntropySourceId;
|
|
31
|
-
groupIndex: number;
|
|
32
|
-
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
33
25
|
}
|
|
34
26
|
//# sourceMappingURL=SolAccountProvider.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.cts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAMhE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAGnD,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAClE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,kCAA8B;AAEvE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAElD,eAAO,MAAM,mCAAmC,EAAE,yBAcjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,cAAc,SAAgD;IAIrE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAsB;gBAGvE,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;cAWjD,cAAc,CAC/B,OAAO,EAAE,cAAc,EACvB,EACE,aAAa,EACb,UAAU,GACX,EAAE;QAAE,aAAa,EAAE,eAAe,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GACxD,YAAY,CAAC,cAAc,CAAC;CAahC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Bip44Account } from "@metamask/account-api";
|
|
2
2
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
3
3
|
import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
|
|
4
|
-
import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
|
|
5
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
7
7
|
import type { MultichainAccountServiceMessenger } from "../types.mjs";
|
|
8
8
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
9
|
-
import type {
|
|
9
|
+
import type { SnapAccountProviderConfig } from "./SnapAccountProvider.mjs";
|
|
10
10
|
export type SolAccountProviderConfig = SnapAccountProviderConfig;
|
|
11
11
|
export declare const SOL_ACCOUNT_PROVIDER_NAME = "Solana";
|
|
12
12
|
export declare const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig;
|
|
@@ -14,21 +14,13 @@ export declare class SolAccountProvider extends SnapAccountProvider {
|
|
|
14
14
|
#private;
|
|
15
15
|
static NAME: string;
|
|
16
16
|
static SOLANA_SNAP_ID: SnapId;
|
|
17
|
-
readonly
|
|
17
|
+
protected readonly v1DiscoveryScopes: CaipChainId[];
|
|
18
18
|
constructor(messenger: MultichainAccountServiceMessenger, config?: SolAccountProviderConfig, trace?: TraceCallback);
|
|
19
19
|
getName(): string;
|
|
20
20
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
21
|
-
protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
|
|
22
|
-
entropySource: EntropySourceId;
|
|
23
|
-
groupIndex: number;
|
|
24
|
-
}): Promise<KeyringAccount>;
|
|
25
21
|
protected toBip44Account(account: KeyringAccount, { entropySource, groupIndex, }: {
|
|
26
22
|
entropySource: EntropySourceId;
|
|
27
23
|
groupIndex: number;
|
|
28
24
|
}): Bip44Account<KeyringAccount>;
|
|
29
|
-
discoverAccounts({ entropySource, groupIndex, }: {
|
|
30
|
-
entropySource: EntropySourceId;
|
|
31
|
-
groupIndex: number;
|
|
32
|
-
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
33
25
|
}
|
|
34
26
|
//# sourceMappingURL=SolAccountProvider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.d.mts","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAMhE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAGnD,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAiB;AAClE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,kCAA8B;AAEvE,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAEjE,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAElD,eAAO,MAAM,mCAAmC,EAAE,yBAcjD,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,mBAAmB;;IACzD,MAAM,CAAC,IAAI,SAA6B;IAExC,MAAM,CAAC,cAAc,SAAgD;IAIrE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAsB;gBAGvE,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;cAWjD,cAAc,CAC/B,OAAO,EAAE,cAAc,EACvB,EACE,aAAa,EACb,UAAU,GACX,EAAE;QAAE,aAAa,EAAE,eAAe,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GACxD,YAAY,CAAC,cAAc,CAAC;CAahC"}
|
|
@@ -5,12 +5,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _SolAccountProvider_instances, _SolAccountProvider_getDerivationPath;
|
|
7
7
|
import { assertIsBip44Account } from "@metamask/account-api";
|
|
8
|
-
import {
|
|
8
|
+
import { KeyringAccountEntropyTypeOption, SolAccountType, SolScope } from "@metamask/keyring-api";
|
|
9
9
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
10
10
|
import { traceFallback } from "../analytics/index.mjs";
|
|
11
|
-
import { TraceName } from "../analytics/traces.mjs";
|
|
12
11
|
import { SnapAccountProvider } from "./SnapAccountProvider.mjs";
|
|
13
|
-
import { withRetry, withTimeout } from "./utils.mjs";
|
|
14
12
|
export const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';
|
|
15
13
|
export const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
16
14
|
maxConcurrency: 3,
|
|
@@ -21,7 +19,6 @@ export const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
|
21
19
|
backOffMs: 1000,
|
|
22
20
|
},
|
|
23
21
|
createAccounts: {
|
|
24
|
-
batched: false, // For now, the Snap is not fully v2 compliant.
|
|
25
22
|
timeoutMs: 3000,
|
|
26
23
|
},
|
|
27
24
|
resyncAccounts: {
|
|
@@ -32,13 +29,9 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
32
29
|
constructor(messenger, config = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = traceFallback) {
|
|
33
30
|
super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);
|
|
34
31
|
_SolAccountProvider_instances.add(this);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
deriveIndex: true,
|
|
39
|
-
deriveIndexRange: true,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
32
|
+
// TODO: Remove once the Snap is fully v2 — discovery is then driven by the
|
|
33
|
+
// Snap's own supported scopes via `createAccounts({ bip44:discover })`.
|
|
34
|
+
this.v1DiscoveryScopes = [SolScope.Mainnet];
|
|
42
35
|
}
|
|
43
36
|
getName() {
|
|
44
37
|
return SolAccountProvider.NAME;
|
|
@@ -47,12 +40,6 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
47
40
|
return (account.type === SolAccountType.DataAccount &&
|
|
48
41
|
account.metadata.keyring.type === KeyringTypes.snap);
|
|
49
42
|
}
|
|
50
|
-
async createAccountV1(keyring, { entropySource, groupIndex, }) {
|
|
51
|
-
return keyring.createAccount({
|
|
52
|
-
entropySource,
|
|
53
|
-
derivationPath: __classPrivateFieldGet(this, _SolAccountProvider_instances, "m", _SolAccountProvider_getDerivationPath).call(this, groupIndex),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
43
|
toBip44Account(account, { entropySource, groupIndex, }) {
|
|
57
44
|
// Ensure entropy is present before type assertion validation
|
|
58
45
|
account.options.entropy = {
|
|
@@ -64,35 +51,6 @@ export class SolAccountProvider extends SnapAccountProvider {
|
|
|
64
51
|
assertIsBip44Account(account);
|
|
65
52
|
return account;
|
|
66
53
|
}
|
|
67
|
-
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
68
|
-
return this.withSnap(async ({ client, keyring }) => {
|
|
69
|
-
return await super.trace({
|
|
70
|
-
name: TraceName.SnapDiscoverAccounts,
|
|
71
|
-
data: {
|
|
72
|
-
provider: this.getName(),
|
|
73
|
-
},
|
|
74
|
-
}, async () => {
|
|
75
|
-
if (!this.config.discovery.enabled) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const discoveredAccounts = await withRetry(() => withTimeout(() => client.discoverAccounts([SolScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
79
|
-
maxAttempts: this.config.discovery.maxAttempts,
|
|
80
|
-
backOffMs: this.config.discovery.backOffMs,
|
|
81
|
-
});
|
|
82
|
-
if (!discoveredAccounts.length) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
// NOTE: We know the Solana Snap only return 1 account per group index during discovery. Also,
|
|
86
|
-
// we do not use the returned `derivationPath` on purpose. Instead we just create the account
|
|
87
|
-
// for this group index and that's all.
|
|
88
|
-
return await this.createBip44Accounts(keyring, {
|
|
89
|
-
type: AccountCreationType.Bip44DeriveIndex,
|
|
90
|
-
entropySource,
|
|
91
|
-
groupIndex,
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
54
|
}
|
|
97
55
|
_SolAccountProvider_instances = new WeakSet(), _SolAccountProvider_getDerivationPath = function _SolAccountProvider_getDerivationPath(groupIndex) {
|
|
98
56
|
return `m/44'/501'/${groupIndex}'/0'`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"SolAccountProvider.mjs","sourceRoot":"","sources":["../../src/providers/SolAccountProvider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,8BAA8B;AAG7D,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACd,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,aAAa,EAAE,+BAAqB;AAE7C,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAK5D,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAElD,MAAM,CAAC,MAAM,mCAAmC,GAA8B;IAC5E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,mCAAmC,EACtE,QAAuB,aAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;;QATrE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,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;IAMkB,cAAc,CAC/B,OAAuB,EACvB,EACE,aAAa,EACb,UAAU,GAC6C;QAEzD,6DAA6D;QAC7D,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG;YACxB,IAAI,EAAE,+BAA+B,CAAC,QAAQ;YAC9C,EAAE,EAAE,aAAa;YACjB,UAAU;YACV,cAAc,EAAE,uBAAA,IAAI,4EAAmB,MAAvB,IAAI,EAAoB,UAAU,CAAC;SACpD,CAAC;QAEF,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,OAAO,CAAC;IACjB,CAAC;;sIAtBkB,UAAkB;IACnC,OAAO,cAAc,UAAU,MAAM,CAAC;AACxC,CAAC;AA7BM,uBAAI,GAAG,yBAAyB,AAA5B,CAA6B;AAEjC,iCAAc,GAAG,kCAA4C,AAA/C,CAAgD","sourcesContent":["import { assertIsBip44Account } from '@metamask/account-api';\nimport type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport {\n KeyringAccountEntropyTypeOption,\n SolAccountType,\n SolScope,\n} from '@metamask/keyring-api';\nimport type { EntropySourceId, KeyringAccount } 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 { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\n\nexport type SolAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const SOL_ACCOUNT_PROVIDER_NAME = 'Solana';\n\nexport const SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG: SnapAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class SolAccountProvider extends SnapAccountProvider {\n static NAME = SOL_ACCOUNT_PROVIDER_NAME;\n\n static SOLANA_SNAP_ID = 'npm:@metamask/solana-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [SolScope.Mainnet];\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: SolAccountProviderConfig = SOL_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(SolAccountProvider.SOLANA_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return SolAccountProvider.NAME;\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 #getDerivationPath(groupIndex: number): string {\n return `m/44'/501'/${groupIndex}'/0'`;\n }\n\n protected override toBip44Account(\n account: KeyringAccount,\n {\n entropySource,\n groupIndex,\n }: { entropySource: EntropySourceId; groupIndex: number },\n ): Bip44Account<KeyringAccount> {\n // Ensure entropy is present before type assertion validation\n account.options.entropy = {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: entropySource,\n groupIndex,\n derivationPath: this.#getDerivationPath(groupIndex),\n };\n\n assertIsBip44Account(account);\n\n return account;\n }\n}\n"]}
|
|
@@ -4,9 +4,7 @@ exports.TrxAccountProvider = exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = expor
|
|
|
4
4
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
5
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
6
6
|
const analytics_1 = require("../analytics/index.cjs");
|
|
7
|
-
const traces_1 = require("../analytics/traces.cjs");
|
|
8
7
|
const SnapAccountProvider_1 = require("./SnapAccountProvider.cjs");
|
|
9
|
-
const utils_1 = require("./utils.cjs");
|
|
10
8
|
exports.TRX_ACCOUNT_PROVIDER_NAME = 'Tron';
|
|
11
9
|
exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
12
10
|
maxConcurrency: 3,
|
|
@@ -17,7 +15,6 @@ exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
|
17
15
|
backOffMs: 1000,
|
|
18
16
|
},
|
|
19
17
|
createAccounts: {
|
|
20
|
-
batched: false, // For now, the Snap is not fully v2 compliant.
|
|
21
18
|
timeoutMs: 3000,
|
|
22
19
|
},
|
|
23
20
|
resyncAccounts: {
|
|
@@ -27,13 +24,9 @@ exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG = {
|
|
|
27
24
|
class TrxAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
28
25
|
constructor(messenger, config = exports.TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG, trace = analytics_1.traceFallback) {
|
|
29
26
|
super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
deriveIndex: true,
|
|
34
|
-
deriveIndexRange: true,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
27
|
+
// TODO: Remove once the Snap is fully v2 — discovery is then driven by the
|
|
28
|
+
// Snap's own supported scopes via `createAccounts({ bip44:discover })`.
|
|
29
|
+
this.v1DiscoveryScopes = [keyring_api_1.TrxScope.Mainnet];
|
|
37
30
|
}
|
|
38
31
|
getName() {
|
|
39
32
|
return TrxAccountProvider.NAME;
|
|
@@ -42,40 +35,6 @@ class TrxAccountProvider extends SnapAccountProvider_1.SnapAccountProvider {
|
|
|
42
35
|
return (account.type === keyring_api_1.TrxAccountType.Eoa &&
|
|
43
36
|
account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap);
|
|
44
37
|
}
|
|
45
|
-
createAccountV1(keyring, { entropySource, groupIndex, }) {
|
|
46
|
-
return keyring.createAccount({
|
|
47
|
-
entropySource,
|
|
48
|
-
index: groupIndex,
|
|
49
|
-
addressType: keyring_api_1.TrxAccountType.Eoa,
|
|
50
|
-
scope: keyring_api_1.TrxScope.Mainnet,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async discoverAccounts({ entropySource, groupIndex, }) {
|
|
54
|
-
return this.withSnap(async ({ client, keyring }) => {
|
|
55
|
-
return await super.trace({
|
|
56
|
-
name: traces_1.TraceName.SnapDiscoverAccounts,
|
|
57
|
-
data: {
|
|
58
|
-
provider: this.getName(),
|
|
59
|
-
},
|
|
60
|
-
}, async () => {
|
|
61
|
-
if (!this.config.discovery.enabled) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
const discoveredAccounts = await (0, utils_1.withRetry)(() => (0, utils_1.withTimeout)(() => client.discoverAccounts([keyring_api_1.TrxScope.Mainnet], entropySource, groupIndex), this.config.discovery.timeoutMs), {
|
|
65
|
-
maxAttempts: this.config.discovery.maxAttempts,
|
|
66
|
-
backOffMs: this.config.discovery.backOffMs,
|
|
67
|
-
});
|
|
68
|
-
if (!discoveredAccounts.length) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
return await this.createBip44Accounts(keyring, {
|
|
72
|
-
type: keyring_api_1.AccountCreationType.Bip44DeriveIndex,
|
|
73
|
-
entropySource,
|
|
74
|
-
groupIndex,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
38
|
}
|
|
80
39
|
exports.TrxAccountProvider = TrxAccountProvider;
|
|
81
40
|
TrxAccountProvider.NAME = exports.TRX_ACCOUNT_PROVIDER_NAME;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TrxAccountProvider.cjs","sourceRoot":"","sources":["../../src/providers/TrxAccountProvider.ts"],"names":[],"mappings":";;;AAEA,uDAAiE;AACjE,qEAA4D;AAK5D,sDAA6C;AAE7C,mEAA4D;AAK/C,QAAA,yBAAyB,GAAG,MAAM,CAAC;AAEnC,QAAA,mCAAmC,GAA6B;IAC3E,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,SAAS,EAAE,IAAI;KAChB;IACD,cAAc,EAAE;QACd,2BAA2B,EAAE,IAAI;KAClC;CACF,CAAC;AAEF,MAAa,kBAAmB,SAAQ,yCAAmB;IASzD,YACE,SAA4C,EAC5C,SAAmC,2CAAmC,EACtE,QAAuB,yBAAa;QAEpC,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QATlE,2EAA2E;QAC3E,wEAAwE;QACrD,sBAAiB,GAAkB,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;IAQzE,CAAC;IAED,OAAO;QACL,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,OAAsC;QACxD,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,4BAAc,CAAC,GAAG;YACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe,CAChE,CAAC;IACJ,CAAC;;AA1BH,gDA2BC;AA1BQ,uBAAI,GAAG,iCAAyB,AAA5B,CAA6B;AAEjC,8BAAW,GAAG,gCAA0C,AAA7C,CAA8C","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport { TrxAccountType, TrxScope } 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 { CaipChainId } from '@metamask/utils';\n\nimport { traceFallback } from '../analytics';\nimport type { MultichainAccountServiceMessenger } from '../types';\nimport { SnapAccountProvider } from './SnapAccountProvider';\nimport type { SnapAccountProviderConfig } from './SnapAccountProvider';\n\nexport type TrxAccountProviderConfig = SnapAccountProviderConfig;\n\nexport const TRX_ACCOUNT_PROVIDER_NAME = 'Tron';\n\nexport const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig = {\n maxConcurrency: 3,\n discovery: {\n enabled: true,\n timeoutMs: 2000,\n maxAttempts: 3,\n backOffMs: 1000,\n },\n createAccounts: {\n timeoutMs: 3000,\n },\n resyncAccounts: {\n autoRemoveExtraSnapAccounts: true,\n },\n};\n\nexport class TrxAccountProvider extends SnapAccountProvider {\n static NAME = TRX_ACCOUNT_PROVIDER_NAME;\n\n static TRX_SNAP_ID = 'npm:@metamask/tron-wallet-snap' as SnapId;\n\n // TODO: Remove once the Snap is fully v2 — discovery is then driven by the\n // Snap's own supported scopes via `createAccounts({ bip44:discover })`.\n protected readonly v1DiscoveryScopes: CaipChainId[] = [TrxScope.Mainnet];\n\n constructor(\n messenger: MultichainAccountServiceMessenger,\n config: TrxAccountProviderConfig = TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG,\n trace: TraceCallback = traceFallback,\n ) {\n super(TrxAccountProvider.TRX_SNAP_ID, messenger, config, trace);\n }\n\n getName(): string {\n return TrxAccountProvider.NAME;\n }\n\n isAccountCompatible(account: Bip44Account<InternalAccount>): boolean {\n return (\n account.type === TrxAccountType.Eoa &&\n account.metadata.keyring.type === (KeyringTypes.snap as string)\n );\n }\n}\n"]}
|
|
@@ -1,29 +1,20 @@
|
|
|
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";
|
|
4
|
-
import type { KeyringCapabilities } from "@metamask/keyring-api/v2";
|
|
5
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
4
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
5
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
7
6
|
import type { MultichainAccountServiceMessenger } from "../types.cjs";
|
|
8
7
|
import { SnapAccountProvider } from "./SnapAccountProvider.cjs";
|
|
9
|
-
import type {
|
|
8
|
+
import type { SnapAccountProviderConfig } from "./SnapAccountProvider.cjs";
|
|
10
9
|
export type TrxAccountProviderConfig = SnapAccountProviderConfig;
|
|
11
10
|
export declare const TRX_ACCOUNT_PROVIDER_NAME = "Tron";
|
|
12
11
|
export declare const TRX_ACCOUNT_PROVIDER_DEFAULT_CONFIG: TrxAccountProviderConfig;
|
|
13
12
|
export declare class TrxAccountProvider extends SnapAccountProvider {
|
|
14
13
|
static NAME: string;
|
|
15
14
|
static TRX_SNAP_ID: SnapId;
|
|
16
|
-
readonly
|
|
15
|
+
protected readonly v1DiscoveryScopes: CaipChainId[];
|
|
17
16
|
constructor(messenger: MultichainAccountServiceMessenger, config?: TrxAccountProviderConfig, trace?: TraceCallback);
|
|
18
17
|
getName(): string;
|
|
19
18
|
isAccountCompatible(account: Bip44Account<InternalAccount>): boolean;
|
|
20
|
-
protected createAccountV1(keyring: RestrictedSnapKeyring, { entropySource, groupIndex, }: {
|
|
21
|
-
entropySource: EntropySourceId;
|
|
22
|
-
groupIndex: number;
|
|
23
|
-
}): Promise<KeyringAccount>;
|
|
24
|
-
discoverAccounts({ entropySource, groupIndex, }: {
|
|
25
|
-
entropySource: EntropySourceId;
|
|
26
|
-
groupIndex: number;
|
|
27
|
-
}): Promise<Bip44Account<KeyringAccount>[]>;
|
|
28
19
|
}
|
|
29
20
|
//# sourceMappingURL=TrxAccountProvider.d.cts.map
|