@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
|
@@ -1,146 +1,7 @@
|
|
|
1
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 _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accounts;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MultichainAccountWallet = void 0;
|
|
16
3
|
exports.toMultichainAccountWalletId = toMultichainAccountWalletId;
|
|
17
|
-
const account_1 = require("./account.cjs");
|
|
18
|
-
const group_1 = require("../group.cjs");
|
|
19
4
|
const wallet_1 = require("../wallet.cjs");
|
|
20
|
-
/**
|
|
21
|
-
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
22
|
-
* group index).
|
|
23
|
-
*/
|
|
24
|
-
class MultichainAccountWallet {
|
|
25
|
-
constructor({ providers, entropySource, }) {
|
|
26
|
-
_MultichainAccountWallet_id.set(this, void 0);
|
|
27
|
-
_MultichainAccountWallet_providers.set(this, void 0);
|
|
28
|
-
_MultichainAccountWallet_entropySource.set(this, void 0);
|
|
29
|
-
_MultichainAccountWallet_accounts.set(this, void 0);
|
|
30
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
|
|
31
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
|
|
32
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
|
|
33
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_accounts, new Map(), "f");
|
|
34
|
-
// Initial synchronization.
|
|
35
|
-
this.sync();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Force wallet synchronization.
|
|
39
|
-
*
|
|
40
|
-
* This can be used if account providers got new accounts that the wallet
|
|
41
|
-
* doesn't know about.
|
|
42
|
-
*/
|
|
43
|
-
sync() {
|
|
44
|
-
for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
|
|
45
|
-
for (const account of provider.getAccounts()) {
|
|
46
|
-
const { entropy } = account.options;
|
|
47
|
-
// Filter for this wallet only.
|
|
48
|
-
if (entropy.id !== this.entropySource) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
// This multichain account might exists already.
|
|
52
|
-
let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(entropy.groupIndex);
|
|
53
|
-
if (!multichainAccount) {
|
|
54
|
-
multichainAccount = new account_1.MultichainAccount({
|
|
55
|
-
groupIndex: entropy.groupIndex,
|
|
56
|
-
wallet: this,
|
|
57
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
58
|
-
});
|
|
59
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").set(entropy.groupIndex, multichainAccount);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Now force-sync all remaining multichain accounts.
|
|
64
|
-
for (const [groupIndex, multichainAccount] of __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").entries()) {
|
|
65
|
-
multichainAccount.sync();
|
|
66
|
-
// Clean up old multichain accounts.
|
|
67
|
-
if (!multichainAccount.hasAccounts()) {
|
|
68
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").delete(groupIndex);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Gets the multichain account wallet ID.
|
|
74
|
-
*
|
|
75
|
-
* @returns The multichain account wallet ID.
|
|
76
|
-
*/
|
|
77
|
-
get id() {
|
|
78
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Gets the multichain account wallet category, which is always {@link AccountWalletCategory.Entropy}.
|
|
82
|
-
*
|
|
83
|
-
* @returns The multichain account wallet category.
|
|
84
|
-
*/
|
|
85
|
-
get category() {
|
|
86
|
-
return wallet_1.AccountWalletCategory.Entropy;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Gets the multichain account wallet entropy source.
|
|
90
|
-
*
|
|
91
|
-
* @returns The multichain account wallet entropy source.
|
|
92
|
-
*/
|
|
93
|
-
get entropySource() {
|
|
94
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets multichain account for a given ID.
|
|
98
|
-
* The default group ID will default to the multichain account with index 0.
|
|
99
|
-
*
|
|
100
|
-
* @param id - Account group ID.
|
|
101
|
-
* @returns Account group.
|
|
102
|
-
*/
|
|
103
|
-
getAccountGroup(id) {
|
|
104
|
-
// We consider the "default case" to be mapped to index 0.
|
|
105
|
-
if (id === (0, group_1.toDefaultAccountGroupId)(this.id)) {
|
|
106
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(0);
|
|
107
|
-
}
|
|
108
|
-
// If it is not a valid ID, we cannot extract the group index
|
|
109
|
-
// from it, so we fail fast.
|
|
110
|
-
if (!(0, account_1.isMultichainAccountId)(id)) {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
const groupIndex = (0, account_1.getGroupIndexFromMultichainAccountId)(id);
|
|
114
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
118
|
-
*
|
|
119
|
-
* @returns The multichain accounts.
|
|
120
|
-
*/
|
|
121
|
-
getAccountGroups() {
|
|
122
|
-
return this.getMultichainAccounts();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Gets multichain account for a given index.
|
|
126
|
-
*
|
|
127
|
-
* @param groupIndex - Multichain account index.
|
|
128
|
-
* @returns The multichain account associated with the given index.
|
|
129
|
-
*/
|
|
130
|
-
getMultichainAccount(groupIndex) {
|
|
131
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Gets all multichain accounts.
|
|
135
|
-
*
|
|
136
|
-
* @returns The multichain accounts.
|
|
137
|
-
*/
|
|
138
|
-
getMultichainAccounts() {
|
|
139
|
-
return Array.from(__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").values()); // TODO: Prevent copy here.
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.MultichainAccountWallet = MultichainAccountWallet;
|
|
143
|
-
_MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accounts = new WeakMap();
|
|
144
5
|
/**
|
|
145
6
|
* Gets the multichain account wallet ID from its entropy source.
|
|
146
7
|
*
|
|
@@ -148,6 +9,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
|
|
|
148
9
|
* @returns The multichain account wallet ID.
|
|
149
10
|
*/
|
|
150
11
|
function toMultichainAccountWalletId(entropySource) {
|
|
151
|
-
return `${wallet_1.
|
|
12
|
+
return `${wallet_1.AccountWalletType.Entropy}:${entropySource}`;
|
|
152
13
|
}
|
|
153
14
|
//# sourceMappingURL=wallet.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;AA8DA,kEAIC;AA1DD,0CAA8C;AAgD9C;;;;;GAKG;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 type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\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 type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\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 getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\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,77 +1,43 @@
|
|
|
1
1
|
import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import {
|
|
2
|
+
import type { MultichainAccountGroup } from "./group.cjs";
|
|
3
3
|
import type { Bip44Account } from "../bip44.cjs";
|
|
4
|
-
import type { AccountGroupId } from "../group.cjs";
|
|
5
|
-
import type { AccountProvider } from "../provider.cjs";
|
|
6
4
|
import type { AccountWallet } from "../wallet.cjs";
|
|
7
|
-
import {
|
|
5
|
+
import { AccountWalletType } from "../wallet.cjs";
|
|
8
6
|
/**
|
|
9
7
|
* Multichain account wallet ID.
|
|
10
8
|
*/
|
|
11
|
-
export type MultichainAccountWalletId = `${
|
|
9
|
+
export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
|
|
12
10
|
/**
|
|
13
11
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
14
12
|
* group index).
|
|
15
13
|
*/
|
|
16
|
-
export
|
|
17
|
-
#private;
|
|
18
|
-
constructor({ providers, entropySource, }: {
|
|
19
|
-
providers: AccountProvider<Account>[];
|
|
20
|
-
entropySource: EntropySourceId;
|
|
21
|
-
});
|
|
14
|
+
export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* This can be used if account providers got new accounts that the wallet
|
|
26
|
-
* doesn't know about.
|
|
27
|
-
*/
|
|
28
|
-
sync(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Gets the multichain account wallet ID.
|
|
31
|
-
*
|
|
32
|
-
* @returns The multichain account wallet ID.
|
|
16
|
+
* Multichain account wallet ID.
|
|
33
17
|
*/
|
|
34
18
|
get id(): MultichainAccountWalletId;
|
|
35
19
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @returns The multichain account wallet category.
|
|
20
|
+
* Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
39
21
|
*/
|
|
40
|
-
get
|
|
22
|
+
get type(): AccountWalletType.Entropy;
|
|
41
23
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @returns The multichain account wallet entropy source.
|
|
24
|
+
* Multichain account wallet entropy source.
|
|
45
25
|
*/
|
|
46
26
|
get entropySource(): EntropySourceId;
|
|
47
|
-
/**
|
|
48
|
-
* Gets multichain account for a given ID.
|
|
49
|
-
* The default group ID will default to the multichain account with index 0.
|
|
50
|
-
*
|
|
51
|
-
* @param id - Account group ID.
|
|
52
|
-
* @returns Account group.
|
|
53
|
-
*/
|
|
54
|
-
getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
57
|
-
*
|
|
58
|
-
* @returns The multichain accounts.
|
|
59
|
-
*/
|
|
60
|
-
getAccountGroups(): MultichainAccount<Account>[];
|
|
61
27
|
/**
|
|
62
28
|
* Gets multichain account for a given index.
|
|
63
29
|
*
|
|
64
30
|
* @param groupIndex - Multichain account index.
|
|
65
31
|
* @returns The multichain account associated with the given index.
|
|
66
32
|
*/
|
|
67
|
-
|
|
33
|
+
getMultichainAccountGroup(groupIndex: number): MultichainAccountGroup<Account> | undefined;
|
|
68
34
|
/**
|
|
69
35
|
* Gets all multichain accounts.
|
|
70
36
|
*
|
|
71
37
|
* @returns The multichain accounts.
|
|
72
38
|
*/
|
|
73
|
-
|
|
74
|
-
}
|
|
39
|
+
getMultichainAccountGroups(): MultichainAccountGroup<Account>[];
|
|
40
|
+
};
|
|
75
41
|
/**
|
|
76
42
|
* Gets the multichain account wallet ID from its entropy source.
|
|
77
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,EACpB,8BAA8B;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,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,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,aAAa,CAAC,OAAO,CAAC,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
|
|
@@ -1,77 +1,43 @@
|
|
|
1
1
|
import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import {
|
|
2
|
+
import type { MultichainAccountGroup } from "./group.mjs";
|
|
3
3
|
import type { Bip44Account } from "../bip44.mjs";
|
|
4
|
-
import type { AccountGroupId } from "../group.mjs";
|
|
5
|
-
import type { AccountProvider } from "../provider.mjs";
|
|
6
4
|
import type { AccountWallet } from "../wallet.mjs";
|
|
7
|
-
import {
|
|
5
|
+
import { AccountWalletType } from "../wallet.mjs";
|
|
8
6
|
/**
|
|
9
7
|
* Multichain account wallet ID.
|
|
10
8
|
*/
|
|
11
|
-
export type MultichainAccountWalletId = `${
|
|
9
|
+
export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
|
|
12
10
|
/**
|
|
13
11
|
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
14
12
|
* group index).
|
|
15
13
|
*/
|
|
16
|
-
export
|
|
17
|
-
#private;
|
|
18
|
-
constructor({ providers, entropySource, }: {
|
|
19
|
-
providers: AccountProvider<Account>[];
|
|
20
|
-
entropySource: EntropySourceId;
|
|
21
|
-
});
|
|
14
|
+
export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* This can be used if account providers got new accounts that the wallet
|
|
26
|
-
* doesn't know about.
|
|
27
|
-
*/
|
|
28
|
-
sync(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Gets the multichain account wallet ID.
|
|
31
|
-
*
|
|
32
|
-
* @returns The multichain account wallet ID.
|
|
16
|
+
* Multichain account wallet ID.
|
|
33
17
|
*/
|
|
34
18
|
get id(): MultichainAccountWalletId;
|
|
35
19
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @returns The multichain account wallet category.
|
|
20
|
+
* Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
|
|
39
21
|
*/
|
|
40
|
-
get
|
|
22
|
+
get type(): AccountWalletType.Entropy;
|
|
41
23
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @returns The multichain account wallet entropy source.
|
|
24
|
+
* Multichain account wallet entropy source.
|
|
45
25
|
*/
|
|
46
26
|
get entropySource(): EntropySourceId;
|
|
47
|
-
/**
|
|
48
|
-
* Gets multichain account for a given ID.
|
|
49
|
-
* The default group ID will default to the multichain account with index 0.
|
|
50
|
-
*
|
|
51
|
-
* @param id - Account group ID.
|
|
52
|
-
* @returns Account group.
|
|
53
|
-
*/
|
|
54
|
-
getAccountGroup(id: AccountGroupId): MultichainAccount<Account> | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
57
|
-
*
|
|
58
|
-
* @returns The multichain accounts.
|
|
59
|
-
*/
|
|
60
|
-
getAccountGroups(): MultichainAccount<Account>[];
|
|
61
27
|
/**
|
|
62
28
|
* Gets multichain account for a given index.
|
|
63
29
|
*
|
|
64
30
|
* @param groupIndex - Multichain account index.
|
|
65
31
|
* @returns The multichain account associated with the given index.
|
|
66
32
|
*/
|
|
67
|
-
|
|
33
|
+
getMultichainAccountGroup(groupIndex: number): MultichainAccountGroup<Account> | undefined;
|
|
68
34
|
/**
|
|
69
35
|
* Gets all multichain accounts.
|
|
70
36
|
*
|
|
71
37
|
* @returns The multichain accounts.
|
|
72
38
|
*/
|
|
73
|
-
|
|
74
|
-
}
|
|
39
|
+
getMultichainAccountGroups(): MultichainAccountGroup<Account>[];
|
|
40
|
+
};
|
|
75
41
|
/**
|
|
76
42
|
* Gets the multichain account wallet ID from its entropy source.
|
|
77
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,
|
|
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,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,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,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,aAAa,CAAC,OAAO,CAAC,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
|
|
@@ -1,141 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
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");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
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");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accounts;
|
|
13
|
-
import { getGroupIndexFromMultichainAccountId, isMultichainAccountId, MultichainAccount } from "./account.mjs";
|
|
14
|
-
import { toDefaultAccountGroupId } from "../group.mjs";
|
|
15
|
-
import { AccountWalletCategory } from "../wallet.mjs";
|
|
16
|
-
/**
|
|
17
|
-
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
|
|
18
|
-
* group index).
|
|
19
|
-
*/
|
|
20
|
-
export class MultichainAccountWallet {
|
|
21
|
-
constructor({ providers, entropySource, }) {
|
|
22
|
-
_MultichainAccountWallet_id.set(this, void 0);
|
|
23
|
-
_MultichainAccountWallet_providers.set(this, void 0);
|
|
24
|
-
_MultichainAccountWallet_entropySource.set(this, void 0);
|
|
25
|
-
_MultichainAccountWallet_accounts.set(this, void 0);
|
|
26
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_id, toMultichainAccountWalletId(entropySource), "f");
|
|
27
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_providers, providers, "f");
|
|
28
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
|
|
29
|
-
__classPrivateFieldSet(this, _MultichainAccountWallet_accounts, new Map(), "f");
|
|
30
|
-
// Initial synchronization.
|
|
31
|
-
this.sync();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Force wallet synchronization.
|
|
35
|
-
*
|
|
36
|
-
* This can be used if account providers got new accounts that the wallet
|
|
37
|
-
* doesn't know about.
|
|
38
|
-
*/
|
|
39
|
-
sync() {
|
|
40
|
-
for (const provider of __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")) {
|
|
41
|
-
for (const account of provider.getAccounts()) {
|
|
42
|
-
const { entropy } = account.options;
|
|
43
|
-
// Filter for this wallet only.
|
|
44
|
-
if (entropy.id !== this.entropySource) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
// This multichain account might exists already.
|
|
48
|
-
let multichainAccount = __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(entropy.groupIndex);
|
|
49
|
-
if (!multichainAccount) {
|
|
50
|
-
multichainAccount = new MultichainAccount({
|
|
51
|
-
groupIndex: entropy.groupIndex,
|
|
52
|
-
wallet: this,
|
|
53
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
54
|
-
});
|
|
55
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").set(entropy.groupIndex, multichainAccount);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Now force-sync all remaining multichain accounts.
|
|
60
|
-
for (const [groupIndex, multichainAccount] of __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").entries()) {
|
|
61
|
-
multichainAccount.sync();
|
|
62
|
-
// Clean up old multichain accounts.
|
|
63
|
-
if (!multichainAccount.hasAccounts()) {
|
|
64
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").delete(groupIndex);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Gets the multichain account wallet ID.
|
|
70
|
-
*
|
|
71
|
-
* @returns The multichain account wallet ID.
|
|
72
|
-
*/
|
|
73
|
-
get id() {
|
|
74
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_id, "f");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Gets the multichain account wallet category, which is always {@link AccountWalletCategory.Entropy}.
|
|
78
|
-
*
|
|
79
|
-
* @returns The multichain account wallet category.
|
|
80
|
-
*/
|
|
81
|
-
get category() {
|
|
82
|
-
return AccountWalletCategory.Entropy;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Gets the multichain account wallet entropy source.
|
|
86
|
-
*
|
|
87
|
-
* @returns The multichain account wallet entropy source.
|
|
88
|
-
*/
|
|
89
|
-
get entropySource() {
|
|
90
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Gets multichain account for a given ID.
|
|
94
|
-
* The default group ID will default to the multichain account with index 0.
|
|
95
|
-
*
|
|
96
|
-
* @param id - Account group ID.
|
|
97
|
-
* @returns Account group.
|
|
98
|
-
*/
|
|
99
|
-
getAccountGroup(id) {
|
|
100
|
-
// We consider the "default case" to be mapped to index 0.
|
|
101
|
-
if (id === toDefaultAccountGroupId(this.id)) {
|
|
102
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(0);
|
|
103
|
-
}
|
|
104
|
-
// If it is not a valid ID, we cannot extract the group index
|
|
105
|
-
// from it, so we fail fast.
|
|
106
|
-
if (!isMultichainAccountId(id)) {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
const groupIndex = getGroupIndexFromMultichainAccountId(id);
|
|
110
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Gets all multichain accounts. Similar to {@link MultichainAccountWallet.getMultichainAccounts}.
|
|
114
|
-
*
|
|
115
|
-
* @returns The multichain accounts.
|
|
116
|
-
*/
|
|
117
|
-
getAccountGroups() {
|
|
118
|
-
return this.getMultichainAccounts();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Gets multichain account for a given index.
|
|
122
|
-
*
|
|
123
|
-
* @param groupIndex - Multichain account index.
|
|
124
|
-
* @returns The multichain account associated with the given index.
|
|
125
|
-
*/
|
|
126
|
-
getMultichainAccount(groupIndex) {
|
|
127
|
-
return __classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").get(groupIndex);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Gets all multichain accounts.
|
|
131
|
-
*
|
|
132
|
-
* @returns The multichain accounts.
|
|
133
|
-
*/
|
|
134
|
-
getMultichainAccounts() {
|
|
135
|
-
return Array.from(__classPrivateFieldGet(this, _MultichainAccountWallet_accounts, "f").values()); // TODO: Prevent copy here.
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accounts = new WeakMap();
|
|
1
|
+
import { AccountWalletType } from "../wallet.mjs";
|
|
139
2
|
/**
|
|
140
3
|
* Gets the multichain account wallet ID from its entropy source.
|
|
141
4
|
*
|
|
@@ -143,6 +6,6 @@ _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers
|
|
|
143
6
|
* @returns The multichain account wallet ID.
|
|
144
7
|
*/
|
|
145
8
|
export function toMultichainAccountWalletId(entropySource) {
|
|
146
|
-
return `${
|
|
9
|
+
return `${AccountWalletType.Entropy}:${entropySource}`;
|
|
147
10
|
}
|
|
148
11
|
//# sourceMappingURL=wallet.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAgD9C;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\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 type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\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 getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\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"]}
|