@metamask-previews/account-api 0.2.0-e017e7a → 0.5.0-0e28ac0
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 +28 -1
- package/dist/api/group.cjs +13 -1
- package/dist/api/group.cjs.map +1 -1
- package/dist/api/group.d.cts +23 -3
- package/dist/api/group.d.cts.map +1 -1
- package/dist/api/group.d.mts +23 -3
- 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/group.cjs +42 -0
- package/dist/api/multichain/group.cjs.map +1 -0
- package/dist/api/multichain/group.d.cts +68 -0
- package/dist/api/multichain/group.d.cts.map +1 -0
- package/dist/api/multichain/group.d.mts +68 -0
- package/dist/api/multichain/group.d.mts.map +1 -0
- package/dist/api/multichain/group.mjs +37 -0
- package/dist/api/multichain/group.mjs.map +1 -0
- package/dist/api/multichain/index.cjs +1 -1
- package/dist/api/multichain/index.cjs.map +1 -1
- package/dist/api/multichain/index.d.cts +1 -1
- package/dist/api/multichain/index.d.cts.map +1 -1
- package/dist/api/multichain/index.d.mts +1 -1
- package/dist/api/multichain/index.d.mts.map +1 -1
- package/dist/api/multichain/index.mjs +1 -1
- package/dist/api/multichain/index.mjs.map +1 -1
- package/dist/api/multichain/wallet.cjs +1 -140
- package/dist/api/multichain/wallet.cjs.map +1 -1
- package/dist/api/multichain/wallet.d.cts +11 -45
- package/dist/api/multichain/wallet.d.cts.map +1 -1
- package/dist/api/multichain/wallet.d.mts +11 -45
- package/dist/api/multichain/wallet.d.mts.map +1 -1
- package/dist/api/multichain/wallet.mjs +2 -139
- 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 -23
- package/dist/api/wallet.cjs.map +1 -1
- package/dist/api/wallet.d.cts +20 -19
- package/dist/api/wallet.d.cts.map +1 -1
- package/dist/api/wallet.d.mts +20 -19
- package/dist/api/wallet.d.mts.map +1 -1
- package/dist/api/wallet.mjs +18 -22
- package/dist/api/wallet.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/api/multichain/account.cjs +0 -213
- package/dist/api/multichain/account.cjs.map +0 -1
- package/dist/api/multichain/account.d.cts +0 -103
- package/dist/api/multichain/account.d.cts.map +0 -1
- package/dist/api/multichain/account.d.mts +0 -103
- package/dist/api/multichain/account.d.mts.map +0 -1
- package/dist/api/multichain/account.mjs +0 -206
- package/dist/api/multichain/account.mjs.map +0 -1
package/dist/api/wallet.cjs
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
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
|
-
var AccountWalletCategory;
|
|
6
|
-
(function (AccountWalletCategory) {
|
|
7
|
-
/**
|
|
8
|
-
* Category for wallets that group accounts based on their
|
|
9
|
-
* entropy source.
|
|
10
|
-
*/
|
|
11
|
-
AccountWalletCategory["Entropy"] = "entropy";
|
|
12
|
-
/**
|
|
13
|
-
* Category for wallets that group accounts based on their
|
|
14
|
-
* keyring's type.
|
|
15
|
-
*/
|
|
16
|
-
AccountWalletCategory["Keyring"] = "keyring";
|
|
17
|
-
/**
|
|
18
|
-
* Category for wallets that group accounts associated with an
|
|
19
|
-
* account management Snap.
|
|
20
|
-
*/
|
|
21
|
-
AccountWalletCategory["Snap"] = "snap";
|
|
22
|
-
})(AccountWalletCategory || (exports.AccountWalletCategory = AccountWalletCategory = {}));
|
|
23
5
|
/**
|
|
24
|
-
*
|
|
6
|
+
* Wallet type.
|
|
25
7
|
*
|
|
26
|
-
*
|
|
8
|
+
* Each wallet types groups accounts using different criterias.
|
|
9
|
+
*/
|
|
10
|
+
var AccountWalletType;
|
|
11
|
+
(function (AccountWalletType) {
|
|
12
|
+
/** Wallet grouping accounts based on their entropy source. */
|
|
13
|
+
AccountWalletType["Entropy"] = "entropy";
|
|
14
|
+
/** Wallet grouping accounts based on their keyring's type. */
|
|
15
|
+
AccountWalletType["Keyring"] = "keyring";
|
|
16
|
+
/** Wallet grouping accounts associated with an account management Snap. */
|
|
17
|
+
AccountWalletType["Snap"] = "snap";
|
|
18
|
+
})(AccountWalletType || (exports.AccountWalletType = AccountWalletType = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
21
|
+
*
|
|
22
|
+
* @param type - A wallet type.
|
|
27
23
|
* @param id - A unique ID.
|
|
28
24
|
* @returns A wallet ID.
|
|
29
25
|
*/
|
|
30
|
-
function toAccountWalletId(
|
|
31
|
-
return `${
|
|
26
|
+
function toAccountWalletId(type, id) {
|
|
27
|
+
return `${type}:${id}`;
|
|
32
28
|
}
|
|
33
29
|
//# 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":";;;AAsEA,8CAKC;AAtED;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,kCAAa,CAAA;AACf,CAAC,EATW,iBAAiB,iCAAjB,iBAAiB,QAS5B;AA4CD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAgB,EAChB,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 /** Wallet grouping accounts based on their entropy source. */\n Entropy = 'entropy',\n\n /** Wallet grouping accounts based on their keyring's type. */\n Keyring = 'keyring',\n\n /** Wallet grouping accounts associated with an account management Snap. */\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 * Type utility to compute a constrained {@link AccountWalletId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountWalletIdOf<WalletType extends AccountWalletType> =\n `${WalletType}:${string}`;\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<WalletType extends AccountWalletType>(\n type: WalletType,\n id: string,\n): AccountWalletIdOf<WalletType> {\n return `${type}:${id}`;\n}\n"]}
|
package/dist/api/wallet.d.cts
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
2
|
import type { AccountGroup, AccountGroupId } from "./group.cjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Wallet type.
|
|
5
|
+
*
|
|
6
|
+
* Each wallet types groups accounts using different criterias.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AccountWalletType {
|
|
9
|
+
/** Wallet grouping accounts based on their entropy source. */
|
|
8
10
|
Entropy = "entropy",
|
|
9
|
-
/**
|
|
10
|
-
* Category for wallets that group accounts based on their
|
|
11
|
-
* keyring's type.
|
|
12
|
-
*/
|
|
11
|
+
/** Wallet grouping accounts based on their keyring's type. */
|
|
13
12
|
Keyring = "keyring",
|
|
14
|
-
/**
|
|
15
|
-
* Category for wallets that group accounts associated with an
|
|
16
|
-
* account management Snap.
|
|
17
|
-
*/
|
|
13
|
+
/** Wallet grouping accounts associated with an account management Snap. */
|
|
18
14
|
Snap = "snap"
|
|
19
15
|
}
|
|
20
16
|
/**
|
|
21
17
|
* Account wallet ID.
|
|
22
18
|
*/
|
|
23
|
-
export type AccountWalletId = `${
|
|
19
|
+
export type AccountWalletId = `${AccountWalletType}:${string}`;
|
|
24
20
|
/**
|
|
25
21
|
* Account wallet that can hold multiple account groups.
|
|
26
22
|
*/
|
|
@@ -30,9 +26,9 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
30
26
|
*/
|
|
31
27
|
get id(): AccountWalletId;
|
|
32
28
|
/**
|
|
33
|
-
* Account wallet
|
|
29
|
+
* Account wallet type.
|
|
34
30
|
*/
|
|
35
|
-
get
|
|
31
|
+
get type(): AccountWalletType;
|
|
36
32
|
/**
|
|
37
33
|
* Gets account group for a given ID.
|
|
38
34
|
*
|
|
@@ -48,11 +44,16 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
48
44
|
getAccountGroups(): AccountGroup<Account>[];
|
|
49
45
|
};
|
|
50
46
|
/**
|
|
51
|
-
*
|
|
47
|
+
* Type utility to compute a constrained {@link AccountWalletId} type given a
|
|
48
|
+
* specifc {@link AccountWalletType}.
|
|
49
|
+
*/
|
|
50
|
+
export type AccountWalletIdOf<WalletType extends AccountWalletType> = `${WalletType}:${string}`;
|
|
51
|
+
/**
|
|
52
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
52
53
|
*
|
|
53
|
-
* @param
|
|
54
|
+
* @param type - A wallet type.
|
|
54
55
|
* @param id - A unique ID.
|
|
55
56
|
* @returns A wallet ID.
|
|
56
57
|
*/
|
|
57
|
-
export declare function toAccountWalletId(
|
|
58
|
+
export declare function toAccountWalletId<WalletType extends AccountWalletType>(type: WalletType, id: string): AccountWalletIdOf<WalletType>;
|
|
58
59
|
//# 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,8DAA8D;IAC9D,OAAO,YAAY;IAEnB,8DAA8D;IAC9D,OAAO,YAAY;IAEnB,2EAA2E;IAC3E,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;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,UAAU,SAAS,iBAAiB,IAChE,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC;AAE5B;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,SAAS,iBAAiB,EACpE,IAAI,EAAE,UAAU,EAChB,EAAE,EAAE,MAAM,GACT,iBAAiB,CAAC,UAAU,CAAC,CAE/B"}
|
package/dist/api/wallet.d.mts
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import type { KeyringAccount } from "@metamask/keyring-api";
|
|
2
2
|
import type { AccountGroup, AccountGroupId } from "./group.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Wallet type.
|
|
5
|
+
*
|
|
6
|
+
* Each wallet types groups accounts using different criterias.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AccountWalletType {
|
|
9
|
+
/** Wallet grouping accounts based on their entropy source. */
|
|
8
10
|
Entropy = "entropy",
|
|
9
|
-
/**
|
|
10
|
-
* Category for wallets that group accounts based on their
|
|
11
|
-
* keyring's type.
|
|
12
|
-
*/
|
|
11
|
+
/** Wallet grouping accounts based on their keyring's type. */
|
|
13
12
|
Keyring = "keyring",
|
|
14
|
-
/**
|
|
15
|
-
* Category for wallets that group accounts associated with an
|
|
16
|
-
* account management Snap.
|
|
17
|
-
*/
|
|
13
|
+
/** Wallet grouping accounts associated with an account management Snap. */
|
|
18
14
|
Snap = "snap"
|
|
19
15
|
}
|
|
20
16
|
/**
|
|
21
17
|
* Account wallet ID.
|
|
22
18
|
*/
|
|
23
|
-
export type AccountWalletId = `${
|
|
19
|
+
export type AccountWalletId = `${AccountWalletType}:${string}`;
|
|
24
20
|
/**
|
|
25
21
|
* Account wallet that can hold multiple account groups.
|
|
26
22
|
*/
|
|
@@ -30,9 +26,9 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
30
26
|
*/
|
|
31
27
|
get id(): AccountWalletId;
|
|
32
28
|
/**
|
|
33
|
-
* Account wallet
|
|
29
|
+
* Account wallet type.
|
|
34
30
|
*/
|
|
35
|
-
get
|
|
31
|
+
get type(): AccountWalletType;
|
|
36
32
|
/**
|
|
37
33
|
* Gets account group for a given ID.
|
|
38
34
|
*
|
|
@@ -48,11 +44,16 @@ export type AccountWallet<Account extends KeyringAccount> = {
|
|
|
48
44
|
getAccountGroups(): AccountGroup<Account>[];
|
|
49
45
|
};
|
|
50
46
|
/**
|
|
51
|
-
*
|
|
47
|
+
* Type utility to compute a constrained {@link AccountWalletId} type given a
|
|
48
|
+
* specifc {@link AccountWalletType}.
|
|
49
|
+
*/
|
|
50
|
+
export type AccountWalletIdOf<WalletType extends AccountWalletType> = `${WalletType}:${string}`;
|
|
51
|
+
/**
|
|
52
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
52
53
|
*
|
|
53
|
-
* @param
|
|
54
|
+
* @param type - A wallet type.
|
|
54
55
|
* @param id - A unique ID.
|
|
55
56
|
* @returns A wallet ID.
|
|
56
57
|
*/
|
|
57
|
-
export declare function toAccountWalletId(
|
|
58
|
+
export declare function toAccountWalletId<WalletType extends AccountWalletType>(type: WalletType, id: string): AccountWalletIdOf<WalletType>;
|
|
58
59
|
//# 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,8DAA8D;IAC9D,OAAO,YAAY;IAEnB,8DAA8D;IAC9D,OAAO,YAAY;IAEnB,2EAA2E;IAC3E,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;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,UAAU,SAAS,iBAAiB,IAChE,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC;AAE5B;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,SAAS,iBAAiB,EACpE,IAAI,EAAE,UAAU,EAChB,EAAE,EAAE,MAAM,GACT,iBAAiB,CAAC,UAAU,CAAC,CAE/B"}
|
package/dist/api/wallet.mjs
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
export var AccountWalletCategory;
|
|
2
|
-
(function (AccountWalletCategory) {
|
|
3
|
-
/**
|
|
4
|
-
* Category for wallets that group accounts based on their
|
|
5
|
-
* entropy source.
|
|
6
|
-
*/
|
|
7
|
-
AccountWalletCategory["Entropy"] = "entropy";
|
|
8
|
-
/**
|
|
9
|
-
* Category for wallets that group accounts based on their
|
|
10
|
-
* keyring's type.
|
|
11
|
-
*/
|
|
12
|
-
AccountWalletCategory["Keyring"] = "keyring";
|
|
13
|
-
/**
|
|
14
|
-
* Category for wallets that group accounts associated with an
|
|
15
|
-
* account management Snap.
|
|
16
|
-
*/
|
|
17
|
-
AccountWalletCategory["Snap"] = "snap";
|
|
18
|
-
})(AccountWalletCategory || (AccountWalletCategory = {}));
|
|
19
1
|
/**
|
|
20
|
-
*
|
|
2
|
+
* Wallet type.
|
|
21
3
|
*
|
|
22
|
-
*
|
|
4
|
+
* Each wallet types groups accounts using different criterias.
|
|
5
|
+
*/
|
|
6
|
+
export var AccountWalletType;
|
|
7
|
+
(function (AccountWalletType) {
|
|
8
|
+
/** Wallet grouping accounts based on their entropy source. */
|
|
9
|
+
AccountWalletType["Entropy"] = "entropy";
|
|
10
|
+
/** Wallet grouping accounts based on their keyring's type. */
|
|
11
|
+
AccountWalletType["Keyring"] = "keyring";
|
|
12
|
+
/** Wallet grouping accounts associated with an account management Snap. */
|
|
13
|
+
AccountWalletType["Snap"] = "snap";
|
|
14
|
+
})(AccountWalletType || (AccountWalletType = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Convert a unique ID to a wallet ID for a given type.
|
|
17
|
+
*
|
|
18
|
+
* @param type - A wallet type.
|
|
23
19
|
* @param id - A unique ID.
|
|
24
20
|
* @returns A wallet ID.
|
|
25
21
|
*/
|
|
26
|
-
export function toAccountWalletId(
|
|
27
|
-
return `${
|
|
22
|
+
export function toAccountWalletId(type, id) {
|
|
23
|
+
return `${type}:${id}`;
|
|
28
24
|
}
|
|
29
25
|
//# 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,iBASX;AATD,WAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,kCAAa,CAAA;AACf,CAAC,EATW,iBAAiB,KAAjB,iBAAiB,QAS5B;AA4CD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAgB,EAChB,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 /** Wallet grouping accounts based on their entropy source. */\n Entropy = 'entropy',\n\n /** Wallet grouping accounts based on their keyring's type. */\n Keyring = 'keyring',\n\n /** Wallet grouping accounts associated with an account management Snap. */\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 * Type utility to compute a constrained {@link AccountWalletId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountWalletIdOf<WalletType extends AccountWalletType> =\n `${WalletType}:${string}`;\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<WalletType extends AccountWalletType>(\n type: WalletType,\n id: string,\n): AccountWalletIdOf<WalletType> {\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.5.0-0e28ac0",
|
|
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",
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _MultichainAccount_id, _MultichainAccount_wallet, _MultichainAccount_index, _MultichainAccount_providers, _MultichainAccount_accounts, _MultichainAccount_reverse;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MultichainAccount = void 0;
|
|
16
|
-
exports.toMultichainAccountId = toMultichainAccountId;
|
|
17
|
-
exports.isMultichainAccountId = isMultichainAccountId;
|
|
18
|
-
exports.getGroupIndexFromMultichainAccountId = getGroupIndexFromMultichainAccountId;
|
|
19
|
-
const keyring_utils_1 = require("@metamask/keyring-utils");
|
|
20
|
-
const wallet_1 = require("../wallet.cjs");
|
|
21
|
-
const MULTICHAIN_ACCOUNT_ID_REGEX = new RegExp(`^${wallet_1.AccountWalletCategory.Entropy}:.*/(?<groupIndex>\\d+)$`, 'u');
|
|
22
|
-
/**
|
|
23
|
-
* A multichain account that holds multiple accounts.
|
|
24
|
-
*/
|
|
25
|
-
class MultichainAccount {
|
|
26
|
-
constructor({ groupIndex, wallet, providers, }) {
|
|
27
|
-
_MultichainAccount_id.set(this, void 0);
|
|
28
|
-
_MultichainAccount_wallet.set(this, void 0);
|
|
29
|
-
_MultichainAccount_index.set(this, void 0);
|
|
30
|
-
_MultichainAccount_providers.set(this, void 0);
|
|
31
|
-
_MultichainAccount_accounts.set(this, void 0);
|
|
32
|
-
_MultichainAccount_reverse.set(this, void 0);
|
|
33
|
-
__classPrivateFieldSet(this, _MultichainAccount_id, toMultichainAccountId(wallet.id, groupIndex), "f");
|
|
34
|
-
__classPrivateFieldSet(this, _MultichainAccount_index, groupIndex, "f");
|
|
35
|
-
__classPrivateFieldSet(this, _MultichainAccount_wallet, wallet, "f");
|
|
36
|
-
__classPrivateFieldSet(this, _MultichainAccount_providers, providers, "f");
|
|
37
|
-
__classPrivateFieldSet(this, _MultichainAccount_accounts, new Map(), "f");
|
|
38
|
-
__classPrivateFieldSet(this, _MultichainAccount_reverse, new Map(), "f");
|
|
39
|
-
this.sync();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Force multichain account synchronization.
|
|
43
|
-
*
|
|
44
|
-
* This can be used if account providers got new accounts that the multichain
|
|
45
|
-
* account doesn't know about.
|
|
46
|
-
*/
|
|
47
|
-
sync() {
|
|
48
|
-
// Clear reverse mapping and re-construct it entirely based on the refreshed
|
|
49
|
-
// list of accounts from each providers.
|
|
50
|
-
__classPrivateFieldGet(this, _MultichainAccount_reverse, "f").clear();
|
|
51
|
-
for (const provider of __classPrivateFieldGet(this, _MultichainAccount_providers, "f")) {
|
|
52
|
-
// Filter account only for that index.
|
|
53
|
-
const accounts = [];
|
|
54
|
-
for (const account of provider.getAccounts()) {
|
|
55
|
-
if (account.options.entropy.id === this.wallet.entropySource &&
|
|
56
|
-
account.options.entropy.groupIndex === this.index) {
|
|
57
|
-
// We only use IDs to always fetch the latest version of accounts.
|
|
58
|
-
accounts.push(account.id);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
__classPrivateFieldGet(this, _MultichainAccount_accounts, "f").set(provider, accounts);
|
|
62
|
-
// Reverse-mapping for fast indexing.
|
|
63
|
-
for (const id of accounts) {
|
|
64
|
-
__classPrivateFieldGet(this, _MultichainAccount_reverse, "f").set(id, provider);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Gets the multichain account ID.
|
|
70
|
-
*
|
|
71
|
-
* @returns The multichain account ID.
|
|
72
|
-
*/
|
|
73
|
-
get id() {
|
|
74
|
-
return __classPrivateFieldGet(this, _MultichainAccount_id, "f");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Gets the multichain account's wallet reference (parent).
|
|
78
|
-
*
|
|
79
|
-
* @returns The multichain account's wallet.
|
|
80
|
-
*/
|
|
81
|
-
get wallet() {
|
|
82
|
-
return __classPrivateFieldGet(this, _MultichainAccount_wallet, "f");
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Gets the multichain account group index.
|
|
86
|
-
*
|
|
87
|
-
* @returns The multichain account group index.
|
|
88
|
-
*/
|
|
89
|
-
get index() {
|
|
90
|
-
return __classPrivateFieldGet(this, _MultichainAccount_index, "f");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Checks if there's any underlying accounts for this multichain accounts.
|
|
94
|
-
*
|
|
95
|
-
* @returns True if there's any underlying accounts, false otherwise.
|
|
96
|
-
*/
|
|
97
|
-
hasAccounts() {
|
|
98
|
-
// If there's anything in the reverse-map, it means we have some accounts.
|
|
99
|
-
return __classPrivateFieldGet(this, _MultichainAccount_reverse, "f").size > 0;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Gets the accounts for this multichain account.
|
|
103
|
-
*
|
|
104
|
-
* @returns The accounts.
|
|
105
|
-
*/
|
|
106
|
-
getAccounts() {
|
|
107
|
-
let allAccounts = [];
|
|
108
|
-
for (const [provider, accounts] of __classPrivateFieldGet(this, _MultichainAccount_accounts, "f").entries()) {
|
|
109
|
-
allAccounts = allAccounts.concat(accounts.map((id) => provider.getAccount(id)));
|
|
110
|
-
}
|
|
111
|
-
return allAccounts;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Gets the account for a given account ID.
|
|
115
|
-
*
|
|
116
|
-
* @param id - Account ID.
|
|
117
|
-
* @returns The account or undefined if not found.
|
|
118
|
-
*/
|
|
119
|
-
getAccount(id) {
|
|
120
|
-
const provider = __classPrivateFieldGet(this, _MultichainAccount_reverse, "f").get(id);
|
|
121
|
-
// If there's nothing in the map, it means we tried to get an account
|
|
122
|
-
// that does not belong to this multichain account.
|
|
123
|
-
if (!provider) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return provider.getAccount(id);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Query an account matching the selector.
|
|
130
|
-
*
|
|
131
|
-
* @param selector - Query selector.
|
|
132
|
-
* @returns The account matching the selector or undefined if not matching.
|
|
133
|
-
* @throws If multiple accounts match the selector.
|
|
134
|
-
*/
|
|
135
|
-
get(selector) {
|
|
136
|
-
const accounts = this.select(selector);
|
|
137
|
-
if (accounts.length > 1) {
|
|
138
|
-
throw new Error(`Too many account candidates, expected 1, got: ${accounts.length}`);
|
|
139
|
-
}
|
|
140
|
-
if (accounts.length === 0) {
|
|
141
|
-
return undefined;
|
|
142
|
-
}
|
|
143
|
-
return accounts[0]; // This is safe, see checks above.
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Query accounts matching the selector.
|
|
147
|
-
*
|
|
148
|
-
* @param selector - Query selector.
|
|
149
|
-
* @returns The accounts matching the selector.
|
|
150
|
-
*/
|
|
151
|
-
select(selector) {
|
|
152
|
-
return this.getAccounts().filter((account) => {
|
|
153
|
-
let selected = true;
|
|
154
|
-
if (selector.id) {
|
|
155
|
-
selected && (selected = account.id === selector.id);
|
|
156
|
-
}
|
|
157
|
-
if (selector.address) {
|
|
158
|
-
selected && (selected = account.address === selector.address);
|
|
159
|
-
}
|
|
160
|
-
if (selector.type) {
|
|
161
|
-
selected && (selected = account.type === selector.type);
|
|
162
|
-
}
|
|
163
|
-
if (selector.methods !== undefined) {
|
|
164
|
-
selected && (selected = selector.methods.some((method) => account.methods.includes(method)));
|
|
165
|
-
}
|
|
166
|
-
if (selector.scopes !== undefined) {
|
|
167
|
-
selected && (selected = selector.scopes.some((scope) => {
|
|
168
|
-
return (
|
|
169
|
-
// This will cover specific EVM EOA scopes as well.
|
|
170
|
-
(0, keyring_utils_1.isScopeEqualToAny)(scope, account.scopes));
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
return selected;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.MultichainAccount = MultichainAccount;
|
|
178
|
-
_MultichainAccount_id = new WeakMap(), _MultichainAccount_wallet = new WeakMap(), _MultichainAccount_index = new WeakMap(), _MultichainAccount_providers = new WeakMap(), _MultichainAccount_accounts = new WeakMap(), _MultichainAccount_reverse = new WeakMap();
|
|
179
|
-
/**
|
|
180
|
-
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
181
|
-
*
|
|
182
|
-
* @param walletId - Multichain account wallet ID.
|
|
183
|
-
* @param groupIndex - Index of that multichain account.
|
|
184
|
-
* @returns The multichain account ID.
|
|
185
|
-
*/
|
|
186
|
-
function toMultichainAccountId(walletId, groupIndex) {
|
|
187
|
-
return `${walletId}/${groupIndex}`;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Checks if the given value is {@link MultichainAccountId}.
|
|
191
|
-
*
|
|
192
|
-
* @param value - The value to check.
|
|
193
|
-
* @returns Whether the value is a {@link MultichainAccountId}.
|
|
194
|
-
*/
|
|
195
|
-
function isMultichainAccountId(value) {
|
|
196
|
-
return MULTICHAIN_ACCOUNT_ID_REGEX.test(value);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Gets the multichain account index from an account group ID.
|
|
200
|
-
*
|
|
201
|
-
* @param id - Multichain account ID.
|
|
202
|
-
* @returns The multichain account index if extractable, undefined otherwise.
|
|
203
|
-
*/
|
|
204
|
-
function getGroupIndexFromMultichainAccountId(id) {
|
|
205
|
-
const matched = id.match(MULTICHAIN_ACCOUNT_ID_REGEX);
|
|
206
|
-
if (matched?.groups?.groupIndex === undefined) {
|
|
207
|
-
// Unable to extract group index, even though, type wise, this should not
|
|
208
|
-
// be possible!
|
|
209
|
-
throw new Error('Unable to extract group index');
|
|
210
|
-
}
|
|
211
|
-
return Number(matched.groups.groupIndex);
|
|
212
|
-
}
|
|
213
|
-
//# sourceMappingURL=account.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account.cjs","sourceRoot":"","sources":["../../../src/api/multichain/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuOA,sDAKC;AAQD,sDAIC;AAQD,oFAWC;AA1QD,2DAA4D;AAU5D,0CAAkD;AAElD,MAAM,2BAA2B,GAAG,IAAI,MAAM,CAC5C,IAAI,8BAAqB,CAAC,OAAO,0BAA0B,EAC3D,GAAG,CACJ,CAAC;AAOF;;GAEG;AACH,MAAa,iBAAiB;IAe5B,YAAY,EACV,UAAU,EACV,MAAM,EACN,SAAS,GAKV;QApBQ,wCAAyB;QAEzB,4CAA0C;QAE1C,2CAAe;QAEf,+CAAuC;QAEvC,8CAA0D;QAE1D,6CAAuD;QAW9D,uBAAA,IAAI,yBAAO,qBAAqB,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,MAAA,CAAC;QACxD,uBAAA,IAAI,4BAAU,UAAU,MAAA,CAAC;QACzB,uBAAA,IAAI,6BAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,+BAAa,IAAI,GAAG,EAAE,MAAA,CAAC;QAC3B,uBAAA,IAAI,8BAAY,IAAI,GAAG,EAAE,MAAA,CAAC;QAE1B,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAI;QACF,4EAA4E;QAC5E,wCAAwC;QACxC,uBAAA,IAAI,kCAAS,CAAC,KAAK,EAAE,CAAC;QAEtB,KAAK,MAAM,QAAQ,IAAI,uBAAA,IAAI,oCAAW,EAAE,CAAC;YACvC,sCAAsC;YACtC,MAAM,QAAQ,GAAG,EAAE,CAAC;YACpB,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,WAAW,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AAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { type KeyringAccount } from '@metamask/keyring-api';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\n\nimport type {\n MultichainAccountWallet,\n MultichainAccountWalletId,\n} from './wallet';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroup } from '../group';\nimport type { AccountProvider } from '../provider';\nimport type { AccountSelector } from '../selector';\nimport { AccountWalletCategory } from '../wallet';\n\nconst MULTICHAIN_ACCOUNT_ID_REGEX = new RegExp(\n `^${AccountWalletCategory.Entropy}:.*/(?<groupIndex>\\\\d+)$`,\n 'u',\n);\n\n/**\n * Multichain account ID.\n */\nexport type MultichainAccountId = `${MultichainAccountWalletId}/${number}`; // Use number for the account group index.\n\n/**\n * A multichain account that holds multiple accounts.\n */\nexport class MultichainAccount<Account extends Bip44Account<KeyringAccount>>\n implements AccountGroup<Account>\n{\n readonly #id: MultichainAccountId;\n\n readonly #wallet: MultichainAccountWallet<Account>;\n\n readonly #index: number;\n\n readonly #providers: AccountProvider<Account>[];\n\n readonly #accounts: Map<AccountProvider<Account>, Account['id'][]>;\n\n readonly #reverse: Map<Account['id'], AccountProvider<Account>>;\n\n constructor({\n groupIndex,\n wallet,\n providers,\n }: {\n groupIndex: number;\n wallet: MultichainAccountWallet<Account>;\n providers: AccountProvider<Account>[];\n }) {\n this.#id = toMultichainAccountId(wallet.id, groupIndex);\n this.#index = groupIndex;\n this.#wallet = wallet;\n this.#providers = providers;\n this.#accounts = new Map();\n this.#reverse = new Map();\n\n this.sync();\n }\n\n /**\n * Force multichain account synchronization.\n *\n * This can be used if account providers got new accounts that the multichain\n * account doesn't know about.\n */\n sync(): void {\n // Clear reverse mapping and re-construct it entirely based on the refreshed\n // list of accounts from each providers.\n this.#reverse.clear();\n\n for (const provider of this.#providers) {\n // Filter account only for that index.\n const accounts = [];\n for (const account of provider.getAccounts()) {\n if (\n account.options.entropy.id === this.wallet.entropySource &&\n account.options.entropy.groupIndex === this.index\n ) {\n // We only use IDs to always fetch the latest version of accounts.\n accounts.push(account.id);\n }\n }\n this.#accounts.set(provider, accounts);\n\n // Reverse-mapping for fast indexing.\n for (const id of accounts) {\n this.#reverse.set(id, provider);\n }\n }\n }\n\n /**\n * Gets the multichain account ID.\n *\n * @returns The multichain account ID.\n */\n get id(): MultichainAccountId {\n return this.#id;\n }\n\n /**\n * Gets the multichain account's wallet reference (parent).\n *\n * @returns The multichain account's wallet.\n */\n get wallet(): MultichainAccountWallet<Account> {\n return this.#wallet;\n }\n\n /**\n * Gets the multichain account group index.\n *\n * @returns The multichain account group index.\n */\n get index(): number {\n return this.#index;\n }\n\n /**\n * Checks if there's any underlying accounts for this multichain accounts.\n *\n * @returns True if there's any underlying accounts, false otherwise.\n */\n hasAccounts(): boolean {\n // If there's anything in the reverse-map, it means we have some accounts.\n return this.#reverse.size > 0;\n }\n\n /**\n * Gets the accounts for this multichain account.\n *\n * @returns The accounts.\n */\n getAccounts(): Account[] {\n let allAccounts: Account[] = [];\n\n for (const [provider, accounts] of this.#accounts.entries()) {\n allAccounts = allAccounts.concat(\n accounts.map((id) => provider.getAccount(id)),\n );\n }\n\n return allAccounts;\n }\n\n /**\n * Gets the account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The account or undefined if not found.\n */\n getAccount(id: Account['id']): Account | undefined {\n const provider = this.#reverse.get(id);\n\n // If there's nothing in the map, it means we tried to get an account\n // that does not belong to this multichain account.\n if (!provider) {\n return undefined;\n }\n return provider.getAccount(id);\n }\n\n /**\n * Query an account matching the selector.\n *\n * @param selector - Query selector.\n * @returns The account matching the selector or undefined if not matching.\n * @throws If multiple accounts match the selector.\n */\n get(selector: AccountSelector<Account>): Account | undefined {\n const accounts = this.select(selector);\n\n if (accounts.length > 1) {\n throw new Error(\n `Too many account candidates, expected 1, got: ${accounts.length}`,\n );\n }\n\n if (accounts.length === 0) {\n return undefined;\n }\n\n return accounts[0]; // This is safe, see checks above.\n }\n\n /**\n * Query accounts matching the selector.\n *\n * @param selector - Query selector.\n * @returns The accounts matching the selector.\n */\n select(selector: AccountSelector<Account>): Account[] {\n return this.getAccounts().filter((account) => {\n let selected = true;\n\n if (selector.id) {\n selected &&= account.id === selector.id;\n }\n if (selector.address) {\n selected &&= account.address === selector.address;\n }\n if (selector.type) {\n selected &&= account.type === selector.type;\n }\n if (selector.methods !== undefined) {\n selected &&= selector.methods.some((method) =>\n account.methods.includes(method),\n );\n }\n if (selector.scopes !== undefined) {\n selected &&= selector.scopes.some((scope) => {\n return (\n // This will cover specific EVM EOA scopes as well.\n isScopeEqualToAny(scope, account.scopes)\n );\n });\n }\n\n return selected;\n });\n }\n}\n\n/**\n * Gets the multichain account ID from its multichain account wallet ID and its index.\n *\n * @param walletId - Multichain account wallet ID.\n * @param groupIndex - Index of that multichain account.\n * @returns The multichain account ID.\n */\nexport function toMultichainAccountId(\n walletId: MultichainAccountWalletId,\n groupIndex: number,\n): MultichainAccountId {\n return `${walletId}/${groupIndex}`;\n}\n\n/**\n * Checks if the given value is {@link MultichainAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MultichainAccountId}.\n */\nexport function isMultichainAccountId(\n value: string,\n): value is MultichainAccountId {\n return MULTICHAIN_ACCOUNT_ID_REGEX.test(value);\n}\n\n/**\n * Gets the multichain account index from an account group ID.\n *\n * @param id - Multichain account ID.\n * @returns The multichain account index if extractable, undefined otherwise.\n */\nexport function getGroupIndexFromMultichainAccountId(\n id: MultichainAccountId,\n): number {\n const matched = id.match(MULTICHAIN_ACCOUNT_ID_REGEX);\n if (matched?.groups?.groupIndex === undefined) {\n // Unable to extract group index, even though, type wise, this should not\n // be possible!\n throw new Error('Unable to extract group index');\n }\n\n return Number(matched.groups.groupIndex);\n}\n"]}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import type { MultichainAccountWallet, MultichainAccountWalletId } from "./wallet.cjs";
|
|
3
|
-
import type { Bip44Account } from "../bip44.cjs";
|
|
4
|
-
import type { AccountGroup } from "../group.cjs";
|
|
5
|
-
import type { AccountProvider } from "../provider.cjs";
|
|
6
|
-
import type { AccountSelector } from "../selector.cjs";
|
|
7
|
-
/**
|
|
8
|
-
* Multichain account ID.
|
|
9
|
-
*/
|
|
10
|
-
export type MultichainAccountId = `${MultichainAccountWalletId}/${number}`;
|
|
11
|
-
/**
|
|
12
|
-
* A multichain account that holds multiple accounts.
|
|
13
|
-
*/
|
|
14
|
-
export declare class MultichainAccount<Account extends Bip44Account<KeyringAccount>> implements AccountGroup<Account> {
|
|
15
|
-
#private;
|
|
16
|
-
constructor({ groupIndex, wallet, providers, }: {
|
|
17
|
-
groupIndex: number;
|
|
18
|
-
wallet: MultichainAccountWallet<Account>;
|
|
19
|
-
providers: AccountProvider<Account>[];
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Force multichain account synchronization.
|
|
23
|
-
*
|
|
24
|
-
* This can be used if account providers got new accounts that the multichain
|
|
25
|
-
* account doesn't know about.
|
|
26
|
-
*/
|
|
27
|
-
sync(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Gets the multichain account ID.
|
|
30
|
-
*
|
|
31
|
-
* @returns The multichain account ID.
|
|
32
|
-
*/
|
|
33
|
-
get id(): MultichainAccountId;
|
|
34
|
-
/**
|
|
35
|
-
* Gets the multichain account's wallet reference (parent).
|
|
36
|
-
*
|
|
37
|
-
* @returns The multichain account's wallet.
|
|
38
|
-
*/
|
|
39
|
-
get wallet(): MultichainAccountWallet<Account>;
|
|
40
|
-
/**
|
|
41
|
-
* Gets the multichain account group index.
|
|
42
|
-
*
|
|
43
|
-
* @returns The multichain account group index.
|
|
44
|
-
*/
|
|
45
|
-
get index(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Checks if there's any underlying accounts for this multichain accounts.
|
|
48
|
-
*
|
|
49
|
-
* @returns True if there's any underlying accounts, false otherwise.
|
|
50
|
-
*/
|
|
51
|
-
hasAccounts(): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Gets the accounts for this multichain account.
|
|
54
|
-
*
|
|
55
|
-
* @returns The accounts.
|
|
56
|
-
*/
|
|
57
|
-
getAccounts(): Account[];
|
|
58
|
-
/**
|
|
59
|
-
* Gets the account for a given account ID.
|
|
60
|
-
*
|
|
61
|
-
* @param id - Account ID.
|
|
62
|
-
* @returns The account or undefined if not found.
|
|
63
|
-
*/
|
|
64
|
-
getAccount(id: Account['id']): Account | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* Query an account matching the selector.
|
|
67
|
-
*
|
|
68
|
-
* @param selector - Query selector.
|
|
69
|
-
* @returns The account matching the selector or undefined if not matching.
|
|
70
|
-
* @throws If multiple accounts match the selector.
|
|
71
|
-
*/
|
|
72
|
-
get(selector: AccountSelector<Account>): Account | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Query accounts matching the selector.
|
|
75
|
-
*
|
|
76
|
-
* @param selector - Query selector.
|
|
77
|
-
* @returns The accounts matching the selector.
|
|
78
|
-
*/
|
|
79
|
-
select(selector: AccountSelector<Account>): Account[];
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the multichain account ID from its multichain account wallet ID and its index.
|
|
83
|
-
*
|
|
84
|
-
* @param walletId - Multichain account wallet ID.
|
|
85
|
-
* @param groupIndex - Index of that multichain account.
|
|
86
|
-
* @returns The multichain account ID.
|
|
87
|
-
*/
|
|
88
|
-
export declare function toMultichainAccountId(walletId: MultichainAccountWalletId, groupIndex: number): MultichainAccountId;
|
|
89
|
-
/**
|
|
90
|
-
* Checks if the given value is {@link MultichainAccountId}.
|
|
91
|
-
*
|
|
92
|
-
* @param value - The value to check.
|
|
93
|
-
* @returns Whether the value is a {@link MultichainAccountId}.
|
|
94
|
-
*/
|
|
95
|
-
export declare function isMultichainAccountId(value: string): value is MultichainAccountId;
|
|
96
|
-
/**
|
|
97
|
-
* Gets the multichain account index from an account group ID.
|
|
98
|
-
*
|
|
99
|
-
* @param id - Multichain account ID.
|
|
100
|
-
* @returns The multichain account index if extractable, undefined otherwise.
|
|
101
|
-
*/
|
|
102
|
-
export declare function getGroupIndexFromMultichainAccountId(id: MultichainAccountId): number;
|
|
103
|
-
//# sourceMappingURL=account.d.cts.map
|