@metamask-previews/account-api 0.2.0-e017e7a → 0.3.0-9522cc5
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 +14 -1
- package/dist/api/group.cjs +13 -1
- package/dist/api/group.cjs.map +1 -1
- package/dist/api/group.d.cts +15 -0
- package/dist/api/group.d.cts.map +1 -1
- package/dist/api/group.d.mts +15 -0
- package/dist/api/group.d.mts.map +1 -1
- package/dist/api/group.mjs +12 -0
- package/dist/api/group.mjs.map +1 -1
- package/dist/api/multichain/account.cjs +32 -15
- package/dist/api/multichain/account.cjs.map +1 -1
- package/dist/api/multichain/account.d.cts +7 -0
- package/dist/api/multichain/account.d.cts.map +1 -1
- package/dist/api/multichain/account.d.mts +7 -0
- package/dist/api/multichain/account.d.mts.map +1 -1
- package/dist/api/multichain/account.mjs +33 -16
- package/dist/api/multichain/account.mjs.map +1 -1
- package/dist/api/multichain/wallet.cjs +5 -5
- package/dist/api/multichain/wallet.cjs.map +1 -1
- package/dist/api/multichain/wallet.d.cts +5 -5
- package/dist/api/multichain/wallet.d.cts.map +1 -1
- package/dist/api/multichain/wallet.d.mts +5 -5
- package/dist/api/multichain/wallet.d.mts.map +1 -1
- package/dist/api/multichain/wallet.mjs +6 -6
- package/dist/api/multichain/wallet.mjs.map +1 -1
- package/dist/api/provider.cjs.map +1 -1
- package/dist/api/provider.d.cts +2 -3
- package/dist/api/provider.d.cts.map +1 -1
- package/dist/api/provider.d.mts +2 -3
- package/dist/api/provider.d.mts.map +1 -1
- package/dist/api/provider.mjs.map +1 -1
- package/dist/api/wallet.cjs +19 -17
- package/dist/api/wallet.cjs.map +1 -1
- package/dist/api/wallet.d.cts +15 -13
- package/dist/api/wallet.d.cts.map +1 -1
- package/dist/api/wallet.d.mts +15 -13
- package/dist/api/wallet.d.mts.map +1 -1
- package/dist/api/wallet.mjs +18 -16
- package/dist/api/wallet.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -78,12 +78,12 @@ class MultichainAccountWallet {
|
|
|
78
78
|
return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Gets the multichain account wallet
|
|
81
|
+
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
82
82
|
*
|
|
83
|
-
* @returns The multichain account wallet
|
|
83
|
+
* @returns The multichain account wallet type.
|
|
84
84
|
*/
|
|
85
|
-
get
|
|
86
|
-
return wallet_1.
|
|
85
|
+
get type() {
|
|
86
|
+
return wallet_1.AccountWalletType.Entropy;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Gets the multichain account wallet entropy source.
|
|
@@ -148,6 +148,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
|
|
|
148
148
|
* @returns The multichain account wallet ID.
|
|
149
149
|
*/
|
|
150
150
|
function toMultichainAccountWalletId(entropySource) {
|
|
151
|
-
return `${wallet_1.
|
|
151
|
+
return `${wallet_1.AccountWalletType.Entropy}:${entropySource}`;
|
|
152
152
|
}
|
|
153
153
|
//# sourceMappingURL=wallet.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuLA,kEAIC;AAtLD,2CAImB;AAGnB,wCAAmD;AAGnD,
|
|
1
|
+
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuLA,kEAIC;AAtLD,2CAImB;AAGnB,wCAAmD;AAGnD,0CAA8C;AAQ9C;;;GAGG;AACH,MAAa,uBAAuB;IAYlC,YAAY,EACV,SAAS,EACT,aAAa,GAId;QAdQ,8CAA+B;QAE/B,qDAAuC;QAEvC,yDAAgC;QAEhC,oDAAmD;QAS1D,uBAAA,IAAI,+BAAO,2BA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AKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,0BAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport {\n getGroupIndexFromMultichainAccountId,\n isMultichainAccountId,\n MultichainAccount,\n} from './account';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroupId } from '../group';\nimport { toDefaultAccountGroupId } from '../group';\nimport type { AccountProvider } from '../provider';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements AccountWallet<Account>\n{\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accounts: Map<number, MultichainAccount<Account>>;\n\n constructor({\n providers,\n entropySource,\n }: {\n providers: AccountProvider<Account>[];\n entropySource: EntropySourceId;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#accounts = new Map();\n\n // Initial synchronization.\n this.sync();\n }\n\n /**\n * Force wallet synchronization.\n *\n * This can be used if account providers got new accounts that the wallet\n * doesn't know about.\n */\n sync(): void {\n for (const provider of this.#providers) {\n for (const account of provider.getAccounts()) {\n const { entropy } = account.options;\n\n // Filter for this wallet only.\n if (entropy.id !== this.entropySource) {\n continue;\n }\n\n // This multichain account might exists already.\n let multichainAccount = this.#accounts.get(entropy.groupIndex);\n if (!multichainAccount) {\n multichainAccount = new MultichainAccount<Account>({\n groupIndex: entropy.groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n this.#accounts.set(entropy.groupIndex, multichainAccount);\n }\n }\n }\n\n // Now force-sync all remaining multichain accounts.\n for (const [groupIndex, multichainAccount] of this.#accounts.entries()) {\n multichainAccount.sync();\n\n // Clean up old multichain accounts.\n if (!multichainAccount.hasAccounts()) {\n this.#accounts.delete(groupIndex);\n }\n }\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accounts.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountId(id);\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccount<Account>[] {\n return this.getMultichainAccounts();\n }\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined {\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[] {\n return Array.from(this.#accounts.values()); // TODO: Prevent copy here.\n }\n}\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
|
|
@@ -4,11 +4,11 @@ import type { Bip44Account } from "../bip44.cjs";
|
|
|
4
4
|
import type { AccountGroupId } from "../group.cjs";
|
|
5
5
|
import type { AccountProvider } from "../provider.cjs";
|
|
6
6
|
import type { AccountWallet } from "../wallet.cjs";
|
|
7
|
-
import {
|
|
7
|
+
import { AccountWalletType } from "../wallet.cjs";
|
|
8
8
|
/**
|
|
9
9
|
* Multichain account wallet ID.
|
|
10
10
|
*/
|
|
11
|
-
export type MultichainAccountWalletId = `${
|
|
11
|
+
export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
|
|
12
12
|
/**
|
|
13
13
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
14
14
|
* group index).
|
|
@@ -33,11 +33,11 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
|
|
|
33
33
|
*/
|
|
34
34
|
get id(): MultichainAccountWalletId;
|
|
35
35
|
/**
|
|
36
|
-
* Gets the multichain account wallet
|
|
36
|
+
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
37
37
|
*
|
|
38
|
-
* @returns The multichain account wallet
|
|
38
|
+
* @returns The multichain account wallet type.
|
|
39
39
|
*/
|
|
40
|
-
get
|
|
40
|
+
get type(): AccountWalletType.Entropy;
|
|
41
41
|
/**
|
|
42
42
|
* Gets the multichain account wallet entropy source.
|
|
43
43
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,E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;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;IAgB3E;;;;OAIG;IACH,gBAAgB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAIhD;;;;;OAKG;IACH,oBAAoB,CAClB,UAAU,EAAE,MAAM,GACjB,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;IAIzC;;;;OAIG;IACH,qBAAqB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
|
|
@@ -4,11 +4,11 @@ import type { Bip44Account } from "../bip44.mjs";
|
|
|
4
4
|
import type { AccountGroupId } from "../group.mjs";
|
|
5
5
|
import type { AccountProvider } from "../provider.mjs";
|
|
6
6
|
import type { AccountWallet } from "../wallet.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { AccountWalletType } from "../wallet.mjs";
|
|
8
8
|
/**
|
|
9
9
|
* Multichain account wallet ID.
|
|
10
10
|
*/
|
|
11
|
-
export type MultichainAccountWalletId = `${
|
|
11
|
+
export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
|
|
12
12
|
/**
|
|
13
13
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
14
14
|
* group index).
|
|
@@ -33,11 +33,11 @@ export declare class MultichainAccountWallet<Account extends Bip44Account<Keyrin
|
|
|
33
33
|
*/
|
|
34
34
|
get id(): MultichainAccountWalletId;
|
|
35
35
|
/**
|
|
36
|
-
* Gets the multichain account wallet
|
|
36
|
+
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
37
37
|
*
|
|
38
|
-
* @returns The multichain account wallet
|
|
38
|
+
* @returns The multichain account wallet type.
|
|
39
39
|
*/
|
|
40
|
-
get
|
|
40
|
+
get type(): AccountWalletType.Entropy;
|
|
41
41
|
/**
|
|
42
42
|
* Gets the multichain account wallet entropy source.
|
|
43
43
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,EAGL,iBAAiB,EAClB,sBAAkB;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,EAGL,iBAAiB,EAClB,sBAAkB;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;;GAGG;AACH,qBAAa,uBAAuB,CAClC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,CAC5C,YAAW,aAAa,CAAC,OAAO,CAAC;;gBAUrB,EACV,SAAS,EACT,aAAa,GACd,EAAE;QACD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,aAAa,EAAE,eAAe,CAAC;KAChC;IAUD;;;;;OAKG;IACH,IAAI,IAAI,IAAI;IAmCZ;;;;OAIG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAElC;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAEpC;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,eAAe,CAEnC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;IAgB3E;;;;OAIG;IACH,gBAAgB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAIhD;;;;;OAKG;IACH,oBAAoB,CAClB,UAAU,EAAE,MAAM,GACjB,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS;IAIzC;;;;OAIG;IACH,qBAAqB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
|
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
var _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accounts;
|
|
13
13
|
import { getGroupIndexFromMultichainAccountId, isMultichainAccountId, MultichainAccount } from "./account.mjs";
|
|
14
14
|
import { toDefaultAccountGroupId } from "../group.mjs";
|
|
15
|
-
import {
|
|
15
|
+
import { AccountWalletType } from "../wallet.mjs";
|
|
16
16
|
/**
|
|
17
17
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
18
18
|
* group index).
|
|
@@ -74,12 +74,12 @@ export class MultichainAccountWallet {
|
|
|
74
74
|
return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* Gets the multichain account wallet
|
|
77
|
+
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
78
78
|
*
|
|
79
|
-
* @returns The multichain account wallet
|
|
79
|
+
* @returns The multichain account wallet type.
|
|
80
80
|
*/
|
|
81
|
-
get
|
|
82
|
-
return
|
|
81
|
+
get type() {
|
|
82
|
+
return AccountWalletType.Entropy;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Gets the multichain account wallet entropy source.
|
|
@@ -143,6 +143,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
|
|
|
143
143
|
* @returns The multichain account wallet ID.
|
|
144
144
|
*/
|
|
145
145
|
export function toMultichainAccountWalletId(entropySource) {
|
|
146
|
-
return `${
|
|
146
|
+
return `${AccountWalletType.Entropy}:${entropySource}`;
|
|
147
147
|
}
|
|
148
148
|
//# sourceMappingURL=wallet.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACrB,iBAAiB,EAClB,sBAAkB;AAGnB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACrB,iBAAiB,EAClB,sBAAkB;AAGnB,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAQ9C;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAYlC,YAAY,EACV,SAAS,EACT,aAAa,GAId;QAdQ,8CAA+B;QAE/B,qDAAuC;QAEvC,yDAAgC;QAEhC,oDAAmD;QAS1D,uBAAA,IAAI,+BAAO,2BAA2B,CAAC,aAAa,CAAC,MAAA,CAAC;QACtD,uBAAA,IAA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AAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport {\n getGroupIndexFromMultichainAccountId,\n isMultichainAccountId,\n MultichainAccount,\n} from './account';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroupId } from '../group';\nimport { toDefaultAccountGroupId } from '../group';\nimport type { AccountProvider } from '../provider';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport class MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> implements AccountWallet<Account>\n{\n readonly #id: MultichainAccountWalletId;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #entropySource: EntropySourceId;\n\n readonly #accounts: Map<number, MultichainAccount<Account>>;\n\n constructor({\n providers,\n entropySource,\n }: {\n providers: AccountProvider<Account>[];\n entropySource: EntropySourceId;\n }) {\n this.#id = toMultichainAccountWalletId(entropySource);\n this.#providers = providers;\n this.#entropySource = entropySource;\n this.#accounts = new Map();\n\n // Initial synchronization.\n this.sync();\n }\n\n /**\n * Force wallet synchronization.\n *\n * This can be used if account providers got new accounts that the wallet\n * doesn't know about.\n */\n sync(): void {\n for (const provider of this.#providers) {\n for (const account of provider.getAccounts()) {\n const { entropy } = account.options;\n\n // Filter for this wallet only.\n if (entropy.id !== this.entropySource) {\n continue;\n }\n\n // This multichain account might exists already.\n let multichainAccount = this.#accounts.get(entropy.groupIndex);\n if (!multichainAccount) {\n multichainAccount = new MultichainAccount<Account>({\n groupIndex: entropy.groupIndex,\n wallet: this,\n providers: this.#providers,\n });\n\n this.#accounts.set(entropy.groupIndex, multichainAccount);\n }\n }\n }\n\n // Now force-sync all remaining multichain accounts.\n for (const [groupIndex, multichainAccount] of this.#accounts.entries()) {\n multichainAccount.sync();\n\n // Clean up old multichain accounts.\n if (!multichainAccount.hasAccounts()) {\n this.#accounts.delete(groupIndex);\n }\n }\n }\n\n /**\n * Gets the multichain account wallet ID.\n *\n * @returns The multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n *\n * @returns The multichain account wallet type.\n */\n get type(): AccountWalletType.Entropy {\n return AccountWalletType.Entropy;\n }\n\n /**\n * Gets the multichain account wallet entropy source.\n *\n * @returns The multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId {\n return this.#entropySource;\n }\n\n /**\n * Gets multichain account for a given ID.\n * The default group ID will default to the multichain account with index 0.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined {\n // We consider the \"default case\" to be mapped to index 0.\n if (id === toDefaultAccountGroupId(this.id)) {\n return this.#accounts.get(0);\n }\n\n // If it is not a valid ID, we cannot extract the group index\n // from it, so we fail fast.\n if (!isMultichainAccountId(id)) {\n return undefined;\n }\n\n const groupIndex = getGroupIndexFromMultichainAccountId(id);\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.\n *\n * @returns The multichain accounts.\n */\n getAccountGroups(): MultichainAccount<Account>[] {\n return this.getMultichainAccounts();\n }\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccount(\n groupIndex: number,\n ): MultichainAccount<Account> | undefined {\n return this.#accounts.get(groupIndex);\n }\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccounts(): MultichainAccount<Account>[] {\n return Array.from(this.#accounts.values()); // TODO: Prevent copy here.\n }\n}\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @
|
|
1
|
+
{"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for a given entropy source and group index.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n};\n"]}
|
package/dist/api/provider.d.cts
CHANGED
|
@@ -6,10 +6,9 @@ export type AccountProvider<Account extends KeyringAccount> = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets an account for a given ID.
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
* @returns An account.
|
|
9
|
+
* @returns An account, or undefined if not found.
|
|
11
10
|
*/
|
|
12
|
-
getAccount: (id: Account['id']) => Account;
|
|
11
|
+
getAccount: (id: Account['id']) => Account | undefined;
|
|
13
12
|
/**
|
|
14
13
|
* Gets all accounts for a given entropy source and group index.
|
|
15
14
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D
|
|
1
|
+
{"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
|
package/dist/api/provider.d.mts
CHANGED
|
@@ -6,10 +6,9 @@ export type AccountProvider<Account extends KeyringAccount> = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets an account for a given ID.
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
* @returns An account.
|
|
9
|
+
* @returns An account, or undefined if not found.
|
|
11
10
|
*/
|
|
12
|
-
getAccount: (id: Account['id']) => Account;
|
|
11
|
+
getAccount: (id: Account['id']) => Account | undefined;
|
|
13
12
|
/**
|
|
14
13
|
* Gets all accounts for a given entropy source and group index.
|
|
15
14
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D
|
|
1
|
+
{"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;CAC9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.mjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @
|
|
1
|
+
{"version":3,"file":"provider.mjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for a given entropy source and group index.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n};\n"]}
|
package/dist/api/wallet.cjs
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AccountWalletType = void 0;
|
|
4
4
|
exports.toAccountWalletId = toAccountWalletId;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Wallet type.
|
|
7
|
+
*
|
|
8
|
+
* Each wallet types groups accounts using different criterias.
|
|
9
|
+
*/
|
|
10
|
+
var AccountWalletType;
|
|
11
|
+
(function (AccountWalletType) {
|
|
7
12
|
/**
|
|
8
|
-
*
|
|
9
|
-
* entropy source.
|
|
13
|
+
* Wallet grouping accounts based on their entropy source.
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
AccountWalletType["Entropy"] = "entropy";
|
|
12
16
|
/**
|
|
13
|
-
*
|
|
14
|
-
* keyring's type.
|
|
17
|
+
* Wallet grouping accounts based on their keyring's type.
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
AccountWalletType["Keyring"] = "keyring";
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
19
|
-
* account management Snap.
|
|
21
|
+
* Wallet grouping accounts associated with an account management Snap.
|
|
20
22
|
*/
|
|
21
|
-
|
|
22
|
-
})(
|
|
23
|
+
AccountWalletType["Snap"] = "snap";
|
|
24
|
+
})(AccountWalletType || (exports.AccountWalletType = AccountWalletType = {}));
|
|
23
25
|
/**
|
|
24
|
-
* Convert a unique ID to a wallet ID for a given
|
|
26
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
25
27
|
*
|
|
26
|
-
* @param
|
|
28
|
+
* @param type - A wallet type.
|
|
27
29
|
* @param id - A unique ID.
|
|
28
30
|
* @returns A wallet ID.
|
|
29
31
|
*/
|
|
30
|
-
function toAccountWalletId(
|
|
31
|
-
return `${
|
|
32
|
+
function toAccountWalletId(type, id) {
|
|
33
|
+
return `${type}:${id}`;
|
|
32
34
|
}
|
|
33
35
|
//# sourceMappingURL=wallet.cjs.map
|
package/dist/api/wallet.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;AAqEA,8CAKC;AArED;;;;GAIG;AACH,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,kCAAa,CAAA;AACf,CAAC,EAfW,iBAAiB,iCAAjB,iBAAiB,QAe5B;AAqCD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAuB,EACvB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountGroup, AccountGroupId } from './group';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /**\n * Wallet grouping accounts based on their entropy source.\n */\n Entropy = 'entropy',\n\n /**\n * Wallet grouping accounts based on their keyring's type.\n */\n Keyring = 'keyring',\n\n /**\n * Wallet grouping accounts associated with an account management Snap.\n */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId(\n type: AccountWalletType,\n id: string,\n): AccountWalletId {\n return `${type}:${id}`;\n}\n"]}
|
package/dist/api/wallet.d.cts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
2
|
import type { AccountGroup, AccountGroupId } from "./group.cjs";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Wallet type.
|
|
5
|
+
*
|
|
6
|
+
* Each wallet types groups accounts using different criterias.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AccountWalletType {
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
* entropy source.
|
|
10
|
+
* Wallet grouping accounts based on their entropy source.
|
|
7
11
|
*/
|
|
8
12
|
Entropy = "entropy",
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
11
|
-
* keyring's type.
|
|
14
|
+
* Wallet grouping accounts based on their keyring's type.
|
|
12
15
|
*/
|
|
13
16
|
Keyring = "keyring",
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
16
|
-
* account management Snap.
|
|
18
|
+
* Wallet grouping accounts associated with an account management Snap.
|
|
17
19
|
*/
|
|
18
20
|
Snap = "snap"
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Account wallet ID.
|
|
22
24
|
*/
|
|
23
|
-
export type AccountWalletId = `${
|
|
25
|
+
export type AccountWalletId = `${AccountWalletType}:${string}`;
|
|
24
26
|
/**
|
|
25
27
|
* Account wallet that can hold multiple account groups.
|
|
26
28
|
*/
|
|
@@ -30,9 +32,9 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
30
32
|
*/
|
|
31
33
|
get id(): AccountWalletId;
|
|
32
34
|
/**
|
|
33
|
-
* Account wallet
|
|
35
|
+
* Account wallet type.
|
|
34
36
|
*/
|
|
35
|
-
get
|
|
37
|
+
get type(): AccountWalletType;
|
|
36
38
|
/**
|
|
37
39
|
* Gets account group for a given ID.
|
|
38
40
|
*
|
|
@@ -48,11 +50,11 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
48
50
|
getAccountGroups(): AccountGroup<Account>[];
|
|
49
51
|
};
|
|
50
52
|
/**
|
|
51
|
-
* Convert a unique ID to a wallet ID for a given
|
|
53
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
52
54
|
*
|
|
53
|
-
* @param
|
|
55
|
+
* @param type - A wallet type.
|
|
54
56
|
* @param id - A unique ID.
|
|
55
57
|
* @returns A wallet ID.
|
|
56
58
|
*/
|
|
57
|
-
export declare function toAccountWalletId(
|
|
59
|
+
export declare function toAccountWalletId(type: AccountWalletType, id: string): AccountWalletId;
|
|
58
60
|
//# sourceMappingURL=wallet.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D,oBAAY,
|
|
1
|
+
{"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,cAAc,IAAI;IAC1D;;OAEG;IACH,IAAI,EAAE,IAAI,eAAe,CAAC;IAE1B;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC;IAE9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,MAAM,GACT,eAAe,CAEjB"}
|
package/dist/api/wallet.d.mts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
2
|
import type { AccountGroup, AccountGroupId } from "./group.mjs";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Wallet type.
|
|
5
|
+
*
|
|
6
|
+
* Each wallet types groups accounts using different criterias.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AccountWalletType {
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
* entropy source.
|
|
10
|
+
* Wallet grouping accounts based on their entropy source.
|
|
7
11
|
*/
|
|
8
12
|
Entropy = "entropy",
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
11
|
-
* keyring's type.
|
|
14
|
+
* Wallet grouping accounts based on their keyring's type.
|
|
12
15
|
*/
|
|
13
16
|
Keyring = "keyring",
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
16
|
-
* account management Snap.
|
|
18
|
+
* Wallet grouping accounts associated with an account management Snap.
|
|
17
19
|
*/
|
|
18
20
|
Snap = "snap"
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Account wallet ID.
|
|
22
24
|
*/
|
|
23
|
-
export type AccountWalletId = `${
|
|
25
|
+
export type AccountWalletId = `${AccountWalletType}:${string}`;
|
|
24
26
|
/**
|
|
25
27
|
* Account wallet that can hold multiple account groups.
|
|
26
28
|
*/
|
|
@@ -30,9 +32,9 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
30
32
|
*/
|
|
31
33
|
get id(): AccountWalletId;
|
|
32
34
|
/**
|
|
33
|
-
* Account wallet
|
|
35
|
+
* Account wallet type.
|
|
34
36
|
*/
|
|
35
|
-
get
|
|
37
|
+
get type(): AccountWalletType;
|
|
36
38
|
/**
|
|
37
39
|
* Gets account group for a given ID.
|
|
38
40
|
*
|
|
@@ -48,11 +50,11 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
48
50
|
getAccountGroups(): AccountGroup<Account>[];
|
|
49
51
|
};
|
|
50
52
|
/**
|
|
51
|
-
* Convert a unique ID to a wallet ID for a given
|
|
53
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
52
54
|
*
|
|
53
|
-
* @param
|
|
55
|
+
* @param type - A wallet type.
|
|
54
56
|
* @param id - A unique ID.
|
|
55
57
|
* @returns A wallet ID.
|
|
56
58
|
*/
|
|
57
|
-
export declare function toAccountWalletId(
|
|
59
|
+
export declare function toAccountWalletId(type: AccountWalletType, id: string): AccountWalletId;
|
|
58
60
|
//# sourceMappingURL=wallet.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D,oBAAY,
|
|
1
|
+
{"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAgB;AAE5D;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,cAAc,IAAI;IAC1D;;OAEG;IACH,IAAI,EAAE,IAAI,eAAe,CAAC;IAE1B;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC;IAE9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,MAAM,GACT,eAAe,CAEjB"}
|
package/dist/api/wallet.mjs
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Wallet type.
|
|
3
|
+
*
|
|
4
|
+
* Each wallet types groups accounts using different criterias.
|
|
5
|
+
*/
|
|
6
|
+
export var AccountWalletType;
|
|
7
|
+
(function (AccountWalletType) {
|
|
3
8
|
/**
|
|
4
|
-
*
|
|
5
|
-
* entropy source.
|
|
9
|
+
* Wallet grouping accounts based on their entropy source.
|
|
6
10
|
*/
|
|
7
|
-
|
|
11
|
+
AccountWalletType["Entropy"] = "entropy";
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
10
|
-
* keyring's type.
|
|
13
|
+
* Wallet grouping accounts based on their keyring's type.
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
AccountWalletType["Keyring"] = "keyring";
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
15
|
-
* account management Snap.
|
|
17
|
+
* Wallet grouping accounts associated with an account management Snap.
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
})(
|
|
19
|
+
AccountWalletType["Snap"] = "snap";
|
|
20
|
+
})(AccountWalletType || (AccountWalletType = {}));
|
|
19
21
|
/**
|
|
20
|
-
* Convert a unique ID to a wallet ID for a given
|
|
22
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
21
23
|
*
|
|
22
|
-
* @param
|
|
24
|
+
* @param type - A wallet type.
|
|
23
25
|
* @param id - A unique ID.
|
|
24
26
|
* @returns A wallet ID.
|
|
25
27
|
*/
|
|
26
|
-
export function toAccountWalletId(
|
|
27
|
-
return `${
|
|
28
|
+
export function toAccountWalletId(type, id) {
|
|
29
|
+
return `${type}:${id}`;
|
|
28
30
|
}
|
|
29
31
|
//# sourceMappingURL=wallet.mjs.map
|
package/dist/api/wallet.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,CAAN,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,kCAAa,CAAA;AACf,CAAC,EAfW,iBAAiB,KAAjB,iBAAiB,QAe5B;AAqCD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAuB,EACvB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountGroup, AccountGroupId } from './group';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /**\n * Wallet grouping accounts based on their entropy source.\n */\n Entropy = 'entropy',\n\n /**\n * Wallet grouping accounts based on their keyring's type.\n */\n Keyring = 'keyring',\n\n /**\n * Wallet grouping accounts associated with an account management Snap.\n */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId(\n type: AccountWalletType,\n id: string,\n): AccountWalletId {\n return `${type}:${id}`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/account-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-9522cc5",
|
|
4
4
|
"description": "MetaMask Account API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"metamask",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"test:watch": "jest --watch"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@metamask/keyring-api": "19.
|
|
49
|
+
"@metamask/keyring-api": "19.1.0",
|
|
50
50
|
"@metamask/keyring-utils": "3.1.0",
|
|
51
51
|
"@metamask/superstruct": "^3.1.0"
|
|
52
52
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@lavamoat/allow-scripts": "^3.2.1",
|
|
55
55
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
56
56
|
"@metamask/auto-changelog": "^3.4.4",
|
|
57
|
-
"@metamask/keyring-internal-api": "7.
|
|
57
|
+
"@metamask/keyring-internal-api": "7.1.0",
|
|
58
58
|
"@ts-bridge/cli": "^0.6.3",
|
|
59
59
|
"@types/jest": "^29.5.12",
|
|
60
60
|
"@types/node": "^20.12.12",
|