@metamask-previews/money-account-controller 0.0.0-preview-373edc9
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 +10 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/MoneyAccountController.cjs +213 -0
- package/dist/MoneyAccountController.cjs.map +1 -0
- package/dist/MoneyAccountController.d.cts +72 -0
- package/dist/MoneyAccountController.d.cts.map +1 -0
- package/dist/MoneyAccountController.d.mts +72 -0
- package/dist/MoneyAccountController.d.mts.map +1 -0
- package/dist/MoneyAccountController.mjs +208 -0
- package/dist/MoneyAccountController.mjs.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +5 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/money-account-controller-method-action-types.cjs +3 -0
- package/dist/money-account-controller-method-action-types.cjs.map +1 -0
- package/dist/money-account-controller-method-action-types.d.cts +15 -0
- package/dist/money-account-controller-method-action-types.d.cts.map +1 -0
- package/dist/money-account-controller-method-action-types.d.mts +15 -0
- package/dist/money-account-controller-method-action-types.d.mts.map +1 -0
- package/dist/money-account-controller-method-action-types.mjs +2 -0
- package/dist/money-account-controller-method-action-types.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +9 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +9 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +15 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +10 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +10 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +11 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +78 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
[Unreleased]: https://github.com/MetaMask/core/
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@metamask/money-account-controller`
|
|
2
|
+
|
|
3
|
+
MetaMask Money account controller.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/money-account-controller`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/money-account-controller`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
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");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _MoneyAccountController_instances, _MoneyAccountController_getOrCreateMoneyAccountFromKeyring, _MoneyAccountController_createMoneyKeyring, _MoneyAccountController_getPrimaryEntropySource, _MoneyAccountController_assertIsUnlocked;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MoneyAccountController = exports.getDefaultMoneyAccountControllerState = exports.controllerName = void 0;
|
|
10
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
11
|
+
const eth_money_keyring_1 = require("@metamask/eth-money-keyring");
|
|
12
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
13
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
14
|
+
const uuid_1 = require("uuid");
|
|
15
|
+
const logger_1 = require("./logger.cjs");
|
|
16
|
+
const utils_1 = require("./utils.cjs");
|
|
17
|
+
exports.controllerName = 'MoneyAccountController';
|
|
18
|
+
const moneyAccountControllerMetadata = {
|
|
19
|
+
moneyAccounts: {
|
|
20
|
+
includeInDebugSnapshot: false,
|
|
21
|
+
includeInStateLogs: true,
|
|
22
|
+
persist: true,
|
|
23
|
+
usedInUi: true,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
function getDefaultMoneyAccountControllerState() {
|
|
27
|
+
return {
|
|
28
|
+
moneyAccounts: {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.getDefaultMoneyAccountControllerState = getDefaultMoneyAccountControllerState;
|
|
32
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
33
|
+
'createMoneyAccount',
|
|
34
|
+
'getMoneyAccount',
|
|
35
|
+
'clearState',
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Controller for managing money accounts.
|
|
39
|
+
*/
|
|
40
|
+
class MoneyAccountController extends base_controller_1.BaseController {
|
|
41
|
+
/**
|
|
42
|
+
* Constructor for the MoneyAccountController.
|
|
43
|
+
*
|
|
44
|
+
* @param options - The options for constructing the controller.
|
|
45
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
46
|
+
* @param options.state - The initial state of the controller. If not provided, the default state will be used.
|
|
47
|
+
*/
|
|
48
|
+
constructor({ messenger, state, }) {
|
|
49
|
+
super({
|
|
50
|
+
messenger,
|
|
51
|
+
metadata: moneyAccountControllerMetadata,
|
|
52
|
+
name: exports.controllerName,
|
|
53
|
+
state: {
|
|
54
|
+
...getDefaultMoneyAccountControllerState(),
|
|
55
|
+
...state,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
_MoneyAccountController_instances.add(this);
|
|
59
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initializes the controller by creating a money account for the primary
|
|
63
|
+
* entropy source if one does not already exist.
|
|
64
|
+
*/
|
|
65
|
+
async init() {
|
|
66
|
+
__classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_assertIsUnlocked).call(this);
|
|
67
|
+
const primaryEntropySource = __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getPrimaryEntropySource).call(this);
|
|
68
|
+
if (primaryEntropySource) {
|
|
69
|
+
(0, logger_1.projectLogger)('Initializing money account for primary entropy source: %s', primaryEntropySource);
|
|
70
|
+
await this.createMoneyAccount(primaryEntropySource);
|
|
71
|
+
(0, logger_1.projectLogger)('Money account initialized');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a money account for the given entropy source. If an account
|
|
76
|
+
* already exists for that entropy source, it is returned as-is (idempotent).
|
|
77
|
+
*
|
|
78
|
+
* @param entropySource - The entropy source ID to create the money account for.
|
|
79
|
+
* @returns The money account.
|
|
80
|
+
*/
|
|
81
|
+
async createMoneyAccount(entropySource) {
|
|
82
|
+
__classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_assertIsUnlocked).call(this);
|
|
83
|
+
// Idempotent: return existing account if already in state.
|
|
84
|
+
const existingAccount = this.getMoneyAccount({ entropySource });
|
|
85
|
+
if (existingAccount) {
|
|
86
|
+
(0, logger_1.projectLogger)(`Money account already exists for entropy source: ${entropySource}, address: ${existingAccount.address}`);
|
|
87
|
+
return existingAccount;
|
|
88
|
+
}
|
|
89
|
+
// Try to find an existing `MoneyKeyring` for this entropy source and get its address.
|
|
90
|
+
// If no such keyring exists, create one and add an account to get the address.
|
|
91
|
+
let address;
|
|
92
|
+
try {
|
|
93
|
+
address = await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getOrCreateMoneyAccountFromKeyring).call(this, entropySource);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Forward any unexpected errors, but if the error is that
|
|
97
|
+
// the keyring wasn't found, we'll create it below.
|
|
98
|
+
if (!(0, keyring_controller_1.isKeyringNotFoundError)(error)) {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
(0, logger_1.projectLogger)(`No money keyring found for entropy source: ${entropySource}, creating one`);
|
|
102
|
+
// Create the keyring right away by providing a `numberOfAccounts` of 1, which will create
|
|
103
|
+
// the first account and allow us to get the address without having to use `withKeyring` again.
|
|
104
|
+
await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_createMoneyKeyring).call(this, entropySource);
|
|
105
|
+
// Now we can get the address from the newly created keyring.
|
|
106
|
+
address = await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getOrCreateMoneyAccountFromKeyring).call(this, entropySource);
|
|
107
|
+
}
|
|
108
|
+
(0, logger_1.projectLogger)(`Creating money account for address: ${address}`);
|
|
109
|
+
const account = {
|
|
110
|
+
id: (0, uuid_1.v4)(),
|
|
111
|
+
type: keyring_api_1.EthAccountType.Eoa,
|
|
112
|
+
address,
|
|
113
|
+
scopes: [keyring_api_1.EthScope.Eoa],
|
|
114
|
+
options: {
|
|
115
|
+
entropy: {
|
|
116
|
+
type: 'mnemonic',
|
|
117
|
+
id: entropySource,
|
|
118
|
+
groupIndex: 0,
|
|
119
|
+
derivationPath: eth_money_keyring_1.MONEY_DERIVATION_PATH,
|
|
120
|
+
},
|
|
121
|
+
exportable: false,
|
|
122
|
+
},
|
|
123
|
+
methods: [
|
|
124
|
+
keyring_api_1.EthMethod.SignTransaction,
|
|
125
|
+
keyring_api_1.EthMethod.PersonalSign,
|
|
126
|
+
keyring_api_1.EthMethod.Sign,
|
|
127
|
+
keyring_api_1.EthMethod.SignTypedDataV1,
|
|
128
|
+
keyring_api_1.EthMethod.SignTypedDataV3,
|
|
129
|
+
keyring_api_1.EthMethod.SignTypedDataV4,
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
// Store the account in state.
|
|
133
|
+
this.update((state) => {
|
|
134
|
+
state.moneyAccounts[account.id] = account;
|
|
135
|
+
});
|
|
136
|
+
(0, logger_1.projectLogger)(`Money account created: ${account.address} (${account.id})`);
|
|
137
|
+
return account;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets a money account by its associated entropy source ID. If no ID is
|
|
141
|
+
* provided, the primary entropy source will be used.
|
|
142
|
+
*
|
|
143
|
+
* @param selector - Selector options for getting the money account.
|
|
144
|
+
* @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.
|
|
145
|
+
* @returns The money account, or `undefined` if no account exists for the given entropy source.
|
|
146
|
+
*/
|
|
147
|
+
getMoneyAccount(selector = {}) {
|
|
148
|
+
const entropySource = selector.entropySource ?? __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getPrimaryEntropySource).call(this);
|
|
149
|
+
if (entropySource === undefined) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
// We should never have more than one money account per entropy source, but if we
|
|
153
|
+
// do, just return the first one we find.
|
|
154
|
+
return Object.values(this.state.moneyAccounts).find((account) => account.options.entropy.id === entropySource);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resets the controller state to its default, removing all money accounts.
|
|
158
|
+
*
|
|
159
|
+
* Intended for use during a full app reset (e.g. when the user wipes all
|
|
160
|
+
* wallet data). Does not interact with the keyring — the caller is
|
|
161
|
+
* responsible for ensuring the associated keyring state is also cleared.
|
|
162
|
+
*/
|
|
163
|
+
clearState() {
|
|
164
|
+
this.update((state) => {
|
|
165
|
+
state.moneyAccounts = {};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.MoneyAccountController = MoneyAccountController;
|
|
170
|
+
_MoneyAccountController_instances = new WeakSet(), _MoneyAccountController_getOrCreateMoneyAccountFromKeyring =
|
|
171
|
+
/**
|
|
172
|
+
* Gets or creates a money account with its associated entropy source ID. It relies on
|
|
173
|
+
* the `MoneyKeyring` keyring instance to get the address, so if no account exists
|
|
174
|
+
* on the keyring yet, it will be created and then the address will be returned.
|
|
175
|
+
*
|
|
176
|
+
* @param entropySource - The entropy source ID to get the money account address for.
|
|
177
|
+
* @returns The money account address.
|
|
178
|
+
*/
|
|
179
|
+
async function _MoneyAccountController_getOrCreateMoneyAccountFromKeyring(entropySource) {
|
|
180
|
+
// Filter to find a specific `MoneyKeyring` for the given entropy source.
|
|
181
|
+
const isMoneyKeyringForEntropySource = (keyring) => (0, utils_1.isMoneyKeyring)(keyring) && keyring.entropySource === entropySource;
|
|
182
|
+
const result = await this.messenger.call('KeyringController:withKeyring', {
|
|
183
|
+
filter: isMoneyKeyringForEntropySource,
|
|
184
|
+
}, async ({ keyring }) => {
|
|
185
|
+
// We're adding this logic to be defensive against the possibility of a money keyring
|
|
186
|
+
// existing without any accounts, which shouldn't normally happen but we want to be
|
|
187
|
+
// sure we can handle it if it does.
|
|
188
|
+
// If there are no accounts, we'll add one and then get the address.
|
|
189
|
+
const accounts = await keyring.getAccounts();
|
|
190
|
+
if (accounts.length === 0) {
|
|
191
|
+
await keyring.addAccounts(1);
|
|
192
|
+
}
|
|
193
|
+
// We have the guarantee that there is at least one account after the above code, so
|
|
194
|
+
// we can safely destructure the first address.
|
|
195
|
+
const [moneyAddress] = await keyring.getAccounts();
|
|
196
|
+
return moneyAddress;
|
|
197
|
+
});
|
|
198
|
+
return result;
|
|
199
|
+
}, _MoneyAccountController_createMoneyKeyring = function _MoneyAccountController_createMoneyKeyring(entropySource) {
|
|
200
|
+
return this.messenger.call('KeyringController:addNewKeyring', keyring_controller_1.KeyringTypes.money, {
|
|
201
|
+
entropySource,
|
|
202
|
+
});
|
|
203
|
+
}, _MoneyAccountController_getPrimaryEntropySource = function _MoneyAccountController_getPrimaryEntropySource() {
|
|
204
|
+
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
205
|
+
const primaryHdKeyring = keyrings.find((keyring) => keyring.type === 'HD Key Tree');
|
|
206
|
+
return primaryHdKeyring?.metadata.id;
|
|
207
|
+
}, _MoneyAccountController_assertIsUnlocked = function _MoneyAccountController_assertIsUnlocked() {
|
|
208
|
+
const { isUnlocked } = this.messenger.call('KeyringController:getState');
|
|
209
|
+
if (!isUnlocked) {
|
|
210
|
+
throw new Error('Cannot create a money account while the keyring is locked');
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
//# sourceMappingURL=MoneyAccountController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyAccountController.cjs","sourceRoot":"","sources":["../src/MoneyAccountController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAK3D,mEAAoE;AACpE,uDAA4E;AAQ5E,qEAGsC;AAItC,+BAAkC;AAElC,yCAAgD;AAGhD,uCAAyC;AAE5B,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAQvD,MAAM,8BAA8B,GAAG;IACrC,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD,SAAgB,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC;AAJD,sFAIC;AAED,MAAM,yBAAyB,GAAG;IAChC,oBAAoB;IACpB,iBAAiB;IACjB,YAAY;CACJ,CAAC;AAgCX;;GAEG;AACH,MAAa,sBAAuB,SAAQ,gCAI3C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gB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CAAC;IACtB,CAAC,CACF,CAAC;IAEF,OAAO,MAAa,CAAC;AACvB,CAAC,mGAYC,aAA8B;IAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CACxB,iCAAiC,EACjC,iCAAY,CAAC,KAAK,EAClB;QACE,aAAa;KACiB,CACjC,CAAC;AACJ,CAAC;IAQC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACvE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,aAAa,CAC5C,CAAC;IACF,OAAO,gBAAgB,EAAE,QAAQ,CAAC,EAAE,CAAC;AACvC,CAAC;IAMC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACzE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MoneyKeyring,\n MoneyKeyringSerializedState,\n} from '@metamask/eth-money-keyring';\nimport { MONEY_DERIVATION_PATH } from '@metamask/eth-money-keyring';\nimport { EthAccountType, EthMethod, EthScope } from '@metamask/keyring-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerGetStateAction,\n KeyringControllerWithKeyringAction,\n KeyringMetadata,\n} from '@metamask/keyring-controller';\nimport {\n isKeyringNotFoundError,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport { EthKeyring } from '@metamask/keyring-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { Hex } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { projectLogger as log } from './logger';\nimport type { MoneyAccountControllerMethodActions } from './money-account-controller-method-action-types';\nimport type { MoneyAccount } from './types';\nimport { isMoneyKeyring } from './utils';\n\nexport const controllerName = 'MoneyAccountController';\n\nexport type MoneyAccountControllerState = {\n moneyAccounts: {\n [id: MoneyAccount['id']]: MoneyAccount;\n };\n};\n\nconst moneyAccountControllerMetadata = {\n moneyAccounts: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<MoneyAccountControllerState>;\n\nexport function getDefaultMoneyAccountControllerState(): MoneyAccountControllerState {\n return {\n moneyAccounts: {},\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'createMoneyAccount',\n 'getMoneyAccount',\n 'clearState',\n] as const;\n\nexport type MoneyAccountControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountControllerState\n>;\n\nexport type MoneyAccountControllerActions =\n | MoneyAccountControllerGetStateAction\n | MoneyAccountControllerMethodActions;\n\ntype AllowedActions =\n | KeyringControllerGetStateAction\n | KeyringControllerAddNewKeyringAction\n | KeyringControllerWithKeyringAction;\n\nexport type MoneyAccountControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n MoneyAccountControllerState\n>;\n\nexport type MoneyAccountControllerEvents =\n MoneyAccountControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountControllerActions | AllowedActions,\n MoneyAccountControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller for managing money accounts.\n */\nexport class MoneyAccountController extends BaseController<\n typeof controllerName,\n MoneyAccountControllerState,\n MoneyAccountControllerMessenger\n> {\n /**\n * Constructor for the MoneyAccountController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n * @param options.state - The initial state of the controller. If not provided, the default state will be used.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: MoneyAccountControllerMessenger;\n state?: Partial<MoneyAccountControllerState>;\n }) {\n super({\n messenger,\n metadata: moneyAccountControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultMoneyAccountControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the controller by creating a money account for the primary\n * entropy source if one does not already exist.\n */\n async init(): Promise<void> {\n this.#assertIsUnlocked();\n\n const primaryEntropySource = this.#getPrimaryEntropySource();\n if (primaryEntropySource) {\n log(\n 'Initializing money account for primary entropy source: %s',\n primaryEntropySource,\n );\n await this.createMoneyAccount(primaryEntropySource);\n log('Money account initialized');\n }\n }\n\n /**\n * Creates a money account for the given entropy source. If an account\n * already exists for that entropy source, it is returned as-is (idempotent).\n *\n * @param entropySource - The entropy source ID to create the money account for.\n * @returns The money account.\n */\n async createMoneyAccount(\n entropySource: EntropySourceId,\n ): Promise<MoneyAccount> {\n this.#assertIsUnlocked();\n\n // Idempotent: return existing account if already in state.\n const existingAccount = this.getMoneyAccount({ entropySource });\n if (existingAccount) {\n log(\n `Money account already exists for entropy source: ${entropySource}, address: ${existingAccount.address}`,\n );\n return existingAccount;\n }\n\n // Try to find an existing `MoneyKeyring` for this entropy source and get its address.\n // If no such keyring exists, create one and add an account to get the address.\n let address: Hex;\n try {\n address = await this.#getOrCreateMoneyAccountFromKeyring(entropySource);\n } catch (error) {\n // Forward any unexpected errors, but if the error is that\n // the keyring wasn't found, we'll create it below.\n if (!isKeyringNotFoundError(error)) {\n throw error;\n }\n\n log(\n `No money keyring found for entropy source: ${entropySource}, creating one`,\n );\n // Create the keyring right away by providing a `numberOfAccounts` of 1, which will create\n // the first account and allow us to get the address without having to use `withKeyring` again.\n await this.#createMoneyKeyring(entropySource);\n\n // Now we can get the address from the newly created keyring.\n address = await this.#getOrCreateMoneyAccountFromKeyring(entropySource);\n }\n\n log(`Creating money account for address: ${address}`);\n const account: MoneyAccount = {\n id: uuid(),\n type: EthAccountType.Eoa,\n address,\n scopes: [EthScope.Eoa],\n options: {\n entropy: {\n type: 'mnemonic',\n id: entropySource,\n groupIndex: 0,\n derivationPath: MONEY_DERIVATION_PATH,\n },\n exportable: false,\n },\n methods: [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n };\n\n // Store the account in state.\n this.update((state) => {\n state.moneyAccounts[account.id] = account;\n });\n\n log(`Money account created: ${account.address} (${account.id})`);\n return account;\n }\n\n /**\n * Gets a money account by its associated entropy source ID. If no ID is\n * provided, the primary entropy source will be used.\n *\n * @param selector - Selector options for getting the money account.\n * @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.\n * @returns The money account, or `undefined` if no account exists for the given entropy source.\n */\n getMoneyAccount(\n selector: { entropySource?: EntropySourceId } = {},\n ): MoneyAccount | undefined {\n const entropySource =\n selector.entropySource ?? this.#getPrimaryEntropySource();\n if (entropySource === undefined) {\n return undefined;\n }\n\n // We should never have more than one money account per entropy source, but if we\n // do, just return the first one we find.\n return Object.values(this.state.moneyAccounts).find(\n (account) => account.options.entropy.id === entropySource,\n );\n }\n\n /**\n * Resets the controller state to its default, removing all money accounts.\n *\n * Intended for use during a full app reset (e.g. when the user wipes all\n * wallet data). Does not interact with the keyring — the caller is\n * responsible for ensuring the associated keyring state is also cleared.\n */\n clearState(): void {\n this.update((state) => {\n state.moneyAccounts = {};\n });\n }\n\n /**\n * Gets or creates a money account with its associated entropy source ID. It relies on\n * the `MoneyKeyring` keyring instance to get the address, so if no account exists\n * on the keyring yet, it will be created and then the address will be returned.\n *\n * @param entropySource - The entropy source ID to get the money account address for.\n * @returns The money account address.\n */\n async #getOrCreateMoneyAccountFromKeyring(\n entropySource: EntropySourceId,\n ): Promise<Hex> {\n // Filter to find a specific `MoneyKeyring` for the given entropy source.\n const isMoneyKeyringForEntropySource = (\n keyring: EthKeyring,\n ): keyring is MoneyKeyring =>\n isMoneyKeyring(keyring) && keyring.entropySource === entropySource;\n\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n {\n filter: isMoneyKeyringForEntropySource,\n },\n async ({ keyring }) => {\n // We're adding this logic to be defensive against the possibility of a money keyring\n // existing without any accounts, which shouldn't normally happen but we want to be\n // sure we can handle it if it does.\n // If there are no accounts, we'll add one and then get the address.\n const accounts = await keyring.getAccounts();\n if (accounts.length === 0) {\n await keyring.addAccounts(1);\n }\n\n // We have the guarantee that there is at least one account after the above code, so\n // we can safely destructure the first address.\n const [moneyAddress] = await keyring.getAccounts();\n return moneyAddress;\n },\n );\n\n return result as Hex;\n }\n\n /**\n * Adds a new money keyring for the given entropy source and returns its metadata.\n *\n * NOTE: This function won't check if a money keyring for the given entropy source already\n * exists!\n *\n * @param entropySource - The entropy source ID to create the money keyring for.\n * @returns The metadata of the newly created money keyring.\n */\n #createMoneyKeyring(\n entropySource: EntropySourceId,\n ): Promise<KeyringMetadata> {\n return this.messenger.call(\n 'KeyringController:addNewKeyring',\n KeyringTypes.money,\n {\n entropySource,\n } as MoneyKeyringSerializedState,\n );\n }\n\n /**\n * Gets the primary entropy source ID.\n *\n * @returns The primary entropy source ID, or `undefined` if no HD keyring exists.\n */\n #getPrimaryEntropySource(): EntropySourceId | undefined {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n const primaryHdKeyring = keyrings.find(\n (keyring) => keyring.type === 'HD Key Tree',\n );\n return primaryHdKeyring?.metadata.id;\n }\n\n /**\n * Throws if the keyring is currently locked.\n */\n #assertIsUnlocked(): void {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n if (!isUnlocked) {\n throw new Error(\n 'Cannot create a money account while the keyring is locked',\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import { BaseController } from "@metamask/base-controller";
|
|
3
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
4
|
+
import type { KeyringControllerAddNewKeyringAction, KeyringControllerGetStateAction, KeyringControllerWithKeyringAction } from "@metamask/keyring-controller";
|
|
5
|
+
import type { Messenger } from "@metamask/messenger";
|
|
6
|
+
import type { MoneyAccountControllerMethodActions } from "./money-account-controller-method-action-types.cjs";
|
|
7
|
+
import type { MoneyAccount } from "./types.cjs";
|
|
8
|
+
export declare const controllerName = "MoneyAccountController";
|
|
9
|
+
export type MoneyAccountControllerState = {
|
|
10
|
+
moneyAccounts: {
|
|
11
|
+
[id: MoneyAccount['id']]: MoneyAccount;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function getDefaultMoneyAccountControllerState(): MoneyAccountControllerState;
|
|
15
|
+
export type MoneyAccountControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountControllerState>;
|
|
16
|
+
export type MoneyAccountControllerActions = MoneyAccountControllerGetStateAction | MoneyAccountControllerMethodActions;
|
|
17
|
+
type AllowedActions = KeyringControllerGetStateAction | KeyringControllerAddNewKeyringAction | KeyringControllerWithKeyringAction;
|
|
18
|
+
export type MoneyAccountControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, MoneyAccountControllerState>;
|
|
19
|
+
export type MoneyAccountControllerEvents = MoneyAccountControllerStateChangeEvent;
|
|
20
|
+
type AllowedEvents = never;
|
|
21
|
+
export type MoneyAccountControllerMessenger = Messenger<typeof controllerName, MoneyAccountControllerActions | AllowedActions, MoneyAccountControllerEvents | AllowedEvents>;
|
|
22
|
+
/**
|
|
23
|
+
* Controller for managing money accounts.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MoneyAccountController extends BaseController<typeof controllerName, MoneyAccountControllerState, MoneyAccountControllerMessenger> {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor for the MoneyAccountController.
|
|
29
|
+
*
|
|
30
|
+
* @param options - The options for constructing the controller.
|
|
31
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
32
|
+
* @param options.state - The initial state of the controller. If not provided, the default state will be used.
|
|
33
|
+
*/
|
|
34
|
+
constructor({ messenger, state, }: {
|
|
35
|
+
messenger: MoneyAccountControllerMessenger;
|
|
36
|
+
state?: Partial<MoneyAccountControllerState>;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the controller by creating a money account for the primary
|
|
40
|
+
* entropy source if one does not already exist.
|
|
41
|
+
*/
|
|
42
|
+
init(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a money account for the given entropy source. If an account
|
|
45
|
+
* already exists for that entropy source, it is returned as-is (idempotent).
|
|
46
|
+
*
|
|
47
|
+
* @param entropySource - The entropy source ID to create the money account for.
|
|
48
|
+
* @returns The money account.
|
|
49
|
+
*/
|
|
50
|
+
createMoneyAccount(entropySource: EntropySourceId): Promise<MoneyAccount>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets a money account by its associated entropy source ID. If no ID is
|
|
53
|
+
* provided, the primary entropy source will be used.
|
|
54
|
+
*
|
|
55
|
+
* @param selector - Selector options for getting the money account.
|
|
56
|
+
* @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.
|
|
57
|
+
* @returns The money account, or `undefined` if no account exists for the given entropy source.
|
|
58
|
+
*/
|
|
59
|
+
getMoneyAccount(selector?: {
|
|
60
|
+
entropySource?: EntropySourceId;
|
|
61
|
+
}): MoneyAccount | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Resets the controller state to its default, removing all money accounts.
|
|
64
|
+
*
|
|
65
|
+
* Intended for use during a full app reset (e.g. when the user wipes all
|
|
66
|
+
* wallet data). Does not interact with the keyring — the caller is
|
|
67
|
+
* responsible for ensuring the associated keyring state is also cleared.
|
|
68
|
+
*/
|
|
69
|
+
clearState(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=MoneyAccountController.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G;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,KAAK,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;KAC9C;IAiBD;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;;;;;OAMG;IACG,kBAAkB,CACtB,aAAa,EAAE,eAAe,GAC7B,OAAO,CAAC,YAAY,CAAC;IAqExB;;;;;;;OAOG;IACH,eAAe,CACb,QAAQ,GAAE;QAAE,aAAa,CAAC,EAAE,eAAe,CAAA;KAAO,GACjD,YAAY,GAAG,SAAS;IAc3B;;;;;;OAMG;IACH,UAAU,IAAI,IAAI;CA6FnB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import { BaseController } from "@metamask/base-controller";
|
|
3
|
+
import type { EntropySourceId } from "@metamask/keyring-api";
|
|
4
|
+
import type { KeyringControllerAddNewKeyringAction, KeyringControllerGetStateAction, KeyringControllerWithKeyringAction } from "@metamask/keyring-controller";
|
|
5
|
+
import type { Messenger } from "@metamask/messenger";
|
|
6
|
+
import type { MoneyAccountControllerMethodActions } from "./money-account-controller-method-action-types.mjs";
|
|
7
|
+
import type { MoneyAccount } from "./types.mjs";
|
|
8
|
+
export declare const controllerName = "MoneyAccountController";
|
|
9
|
+
export type MoneyAccountControllerState = {
|
|
10
|
+
moneyAccounts: {
|
|
11
|
+
[id: MoneyAccount['id']]: MoneyAccount;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function getDefaultMoneyAccountControllerState(): MoneyAccountControllerState;
|
|
15
|
+
export type MoneyAccountControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountControllerState>;
|
|
16
|
+
export type MoneyAccountControllerActions = MoneyAccountControllerGetStateAction | MoneyAccountControllerMethodActions;
|
|
17
|
+
type AllowedActions = KeyringControllerGetStateAction | KeyringControllerAddNewKeyringAction | KeyringControllerWithKeyringAction;
|
|
18
|
+
export type MoneyAccountControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, MoneyAccountControllerState>;
|
|
19
|
+
export type MoneyAccountControllerEvents = MoneyAccountControllerStateChangeEvent;
|
|
20
|
+
type AllowedEvents = never;
|
|
21
|
+
export type MoneyAccountControllerMessenger = Messenger<typeof controllerName, MoneyAccountControllerActions | AllowedActions, MoneyAccountControllerEvents | AllowedEvents>;
|
|
22
|
+
/**
|
|
23
|
+
* Controller for managing money accounts.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MoneyAccountController extends BaseController<typeof controllerName, MoneyAccountControllerState, MoneyAccountControllerMessenger> {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor for the MoneyAccountController.
|
|
29
|
+
*
|
|
30
|
+
* @param options - The options for constructing the controller.
|
|
31
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
32
|
+
* @param options.state - The initial state of the controller. If not provided, the default state will be used.
|
|
33
|
+
*/
|
|
34
|
+
constructor({ messenger, state, }: {
|
|
35
|
+
messenger: MoneyAccountControllerMessenger;
|
|
36
|
+
state?: Partial<MoneyAccountControllerState>;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the controller by creating a money account for the primary
|
|
40
|
+
* entropy source if one does not already exist.
|
|
41
|
+
*/
|
|
42
|
+
init(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a money account for the given entropy source. If an account
|
|
45
|
+
* already exists for that entropy source, it is returned as-is (idempotent).
|
|
46
|
+
*
|
|
47
|
+
* @param entropySource - The entropy source ID to create the money account for.
|
|
48
|
+
* @returns The money account.
|
|
49
|
+
*/
|
|
50
|
+
createMoneyAccount(entropySource: EntropySourceId): Promise<MoneyAccount>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets a money account by its associated entropy source ID. If no ID is
|
|
53
|
+
* provided, the primary entropy source will be used.
|
|
54
|
+
*
|
|
55
|
+
* @param selector - Selector options for getting the money account.
|
|
56
|
+
* @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.
|
|
57
|
+
* @returns The money account, or `undefined` if no account exists for the given entropy source.
|
|
58
|
+
*/
|
|
59
|
+
getMoneyAccount(selector?: {
|
|
60
|
+
entropySource?: EntropySourceId;
|
|
61
|
+
}): MoneyAccount | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Resets the controller state to its default, removing all money accounts.
|
|
64
|
+
*
|
|
65
|
+
* Intended for use during a full app reset (e.g. when the user wipes all
|
|
66
|
+
* wallet data). Does not interact with the keyring — the caller is
|
|
67
|
+
* responsible for ensuring the associated keyring state is also cleared.
|
|
68
|
+
*/
|
|
69
|
+
clearState(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=MoneyAccountController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyAccountController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAO3D,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EACV,oCAAoC,EACpC,+BAA+B,EAC/B,kCAAkC,EAEnC,qCAAqC;AAMtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAKrD,OAAO,KAAK,EAAE,mCAAmC,EAAE,2DAAuD;AAC1G,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAG5C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,E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1,208 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _MoneyAccountController_instances, _MoneyAccountController_getOrCreateMoneyAccountFromKeyring, _MoneyAccountController_createMoneyKeyring, _MoneyAccountController_getPrimaryEntropySource, _MoneyAccountController_assertIsUnlocked;
|
|
7
|
+
import { BaseController } from "@metamask/base-controller";
|
|
8
|
+
import { MONEY_DERIVATION_PATH } from "@metamask/eth-money-keyring";
|
|
9
|
+
import { EthAccountType, EthMethod, EthScope } from "@metamask/keyring-api";
|
|
10
|
+
import { isKeyringNotFoundError, KeyringTypes } from "@metamask/keyring-controller";
|
|
11
|
+
import { v4 as uuid } from "uuid";
|
|
12
|
+
import { projectLogger as log } from "./logger.mjs";
|
|
13
|
+
import { isMoneyKeyring } from "./utils.mjs";
|
|
14
|
+
export const controllerName = 'MoneyAccountController';
|
|
15
|
+
const moneyAccountControllerMetadata = {
|
|
16
|
+
moneyAccounts: {
|
|
17
|
+
includeInDebugSnapshot: false,
|
|
18
|
+
includeInStateLogs: true,
|
|
19
|
+
persist: true,
|
|
20
|
+
usedInUi: true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export function getDefaultMoneyAccountControllerState() {
|
|
24
|
+
return {
|
|
25
|
+
moneyAccounts: {},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
29
|
+
'createMoneyAccount',
|
|
30
|
+
'getMoneyAccount',
|
|
31
|
+
'clearState',
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Controller for managing money accounts.
|
|
35
|
+
*/
|
|
36
|
+
export class MoneyAccountController extends BaseController {
|
|
37
|
+
/**
|
|
38
|
+
* Constructor for the MoneyAccountController.
|
|
39
|
+
*
|
|
40
|
+
* @param options - The options for constructing the controller.
|
|
41
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
42
|
+
* @param options.state - The initial state of the controller. If not provided, the default state will be used.
|
|
43
|
+
*/
|
|
44
|
+
constructor({ messenger, state, }) {
|
|
45
|
+
super({
|
|
46
|
+
messenger,
|
|
47
|
+
metadata: moneyAccountControllerMetadata,
|
|
48
|
+
name: controllerName,
|
|
49
|
+
state: {
|
|
50
|
+
...getDefaultMoneyAccountControllerState(),
|
|
51
|
+
...state,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
_MoneyAccountController_instances.add(this);
|
|
55
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initializes the controller by creating a money account for the primary
|
|
59
|
+
* entropy source if one does not already exist.
|
|
60
|
+
*/
|
|
61
|
+
async init() {
|
|
62
|
+
__classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_assertIsUnlocked).call(this);
|
|
63
|
+
const primaryEntropySource = __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getPrimaryEntropySource).call(this);
|
|
64
|
+
if (primaryEntropySource) {
|
|
65
|
+
log('Initializing money account for primary entropy source: %s', primaryEntropySource);
|
|
66
|
+
await this.createMoneyAccount(primaryEntropySource);
|
|
67
|
+
log('Money account initialized');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a money account for the given entropy source. If an account
|
|
72
|
+
* already exists for that entropy source, it is returned as-is (idempotent).
|
|
73
|
+
*
|
|
74
|
+
* @param entropySource - The entropy source ID to create the money account for.
|
|
75
|
+
* @returns The money account.
|
|
76
|
+
*/
|
|
77
|
+
async createMoneyAccount(entropySource) {
|
|
78
|
+
__classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_assertIsUnlocked).call(this);
|
|
79
|
+
// Idempotent: return existing account if already in state.
|
|
80
|
+
const existingAccount = this.getMoneyAccount({ entropySource });
|
|
81
|
+
if (existingAccount) {
|
|
82
|
+
log(`Money account already exists for entropy source: ${entropySource}, address: ${existingAccount.address}`);
|
|
83
|
+
return existingAccount;
|
|
84
|
+
}
|
|
85
|
+
// Try to find an existing `MoneyKeyring` for this entropy source and get its address.
|
|
86
|
+
// If no such keyring exists, create one and add an account to get the address.
|
|
87
|
+
let address;
|
|
88
|
+
try {
|
|
89
|
+
address = await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getOrCreateMoneyAccountFromKeyring).call(this, entropySource);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
// Forward any unexpected errors, but if the error is that
|
|
93
|
+
// the keyring wasn't found, we'll create it below.
|
|
94
|
+
if (!isKeyringNotFoundError(error)) {
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
log(`No money keyring found for entropy source: ${entropySource}, creating one`);
|
|
98
|
+
// Create the keyring right away by providing a `numberOfAccounts` of 1, which will create
|
|
99
|
+
// the first account and allow us to get the address without having to use `withKeyring` again.
|
|
100
|
+
await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_createMoneyKeyring).call(this, entropySource);
|
|
101
|
+
// Now we can get the address from the newly created keyring.
|
|
102
|
+
address = await __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getOrCreateMoneyAccountFromKeyring).call(this, entropySource);
|
|
103
|
+
}
|
|
104
|
+
log(`Creating money account for address: ${address}`);
|
|
105
|
+
const account = {
|
|
106
|
+
id: uuid(),
|
|
107
|
+
type: EthAccountType.Eoa,
|
|
108
|
+
address,
|
|
109
|
+
scopes: [EthScope.Eoa],
|
|
110
|
+
options: {
|
|
111
|
+
entropy: {
|
|
112
|
+
type: 'mnemonic',
|
|
113
|
+
id: entropySource,
|
|
114
|
+
groupIndex: 0,
|
|
115
|
+
derivationPath: MONEY_DERIVATION_PATH,
|
|
116
|
+
},
|
|
117
|
+
exportable: false,
|
|
118
|
+
},
|
|
119
|
+
methods: [
|
|
120
|
+
EthMethod.SignTransaction,
|
|
121
|
+
EthMethod.PersonalSign,
|
|
122
|
+
EthMethod.Sign,
|
|
123
|
+
EthMethod.SignTypedDataV1,
|
|
124
|
+
EthMethod.SignTypedDataV3,
|
|
125
|
+
EthMethod.SignTypedDataV4,
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
// Store the account in state.
|
|
129
|
+
this.update((state) => {
|
|
130
|
+
state.moneyAccounts[account.id] = account;
|
|
131
|
+
});
|
|
132
|
+
log(`Money account created: ${account.address} (${account.id})`);
|
|
133
|
+
return account;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets a money account by its associated entropy source ID. If no ID is
|
|
137
|
+
* provided, the primary entropy source will be used.
|
|
138
|
+
*
|
|
139
|
+
* @param selector - Selector options for getting the money account.
|
|
140
|
+
* @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.
|
|
141
|
+
* @returns The money account, or `undefined` if no account exists for the given entropy source.
|
|
142
|
+
*/
|
|
143
|
+
getMoneyAccount(selector = {}) {
|
|
144
|
+
const entropySource = selector.entropySource ?? __classPrivateFieldGet(this, _MoneyAccountController_instances, "m", _MoneyAccountController_getPrimaryEntropySource).call(this);
|
|
145
|
+
if (entropySource === undefined) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
// We should never have more than one money account per entropy source, but if we
|
|
149
|
+
// do, just return the first one we find.
|
|
150
|
+
return Object.values(this.state.moneyAccounts).find((account) => account.options.entropy.id === entropySource);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Resets the controller state to its default, removing all money accounts.
|
|
154
|
+
*
|
|
155
|
+
* Intended for use during a full app reset (e.g. when the user wipes all
|
|
156
|
+
* wallet data). Does not interact with the keyring — the caller is
|
|
157
|
+
* responsible for ensuring the associated keyring state is also cleared.
|
|
158
|
+
*/
|
|
159
|
+
clearState() {
|
|
160
|
+
this.update((state) => {
|
|
161
|
+
state.moneyAccounts = {};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
_MoneyAccountController_instances = new WeakSet(), _MoneyAccountController_getOrCreateMoneyAccountFromKeyring =
|
|
166
|
+
/**
|
|
167
|
+
* Gets or creates a money account with its associated entropy source ID. It relies on
|
|
168
|
+
* the `MoneyKeyring` keyring instance to get the address, so if no account exists
|
|
169
|
+
* on the keyring yet, it will be created and then the address will be returned.
|
|
170
|
+
*
|
|
171
|
+
* @param entropySource - The entropy source ID to get the money account address for.
|
|
172
|
+
* @returns The money account address.
|
|
173
|
+
*/
|
|
174
|
+
async function _MoneyAccountController_getOrCreateMoneyAccountFromKeyring(entropySource) {
|
|
175
|
+
// Filter to find a specific `MoneyKeyring` for the given entropy source.
|
|
176
|
+
const isMoneyKeyringForEntropySource = (keyring) => isMoneyKeyring(keyring) && keyring.entropySource === entropySource;
|
|
177
|
+
const result = await this.messenger.call('KeyringController:withKeyring', {
|
|
178
|
+
filter: isMoneyKeyringForEntropySource,
|
|
179
|
+
}, async ({ keyring }) => {
|
|
180
|
+
// We're adding this logic to be defensive against the possibility of a money keyring
|
|
181
|
+
// existing without any accounts, which shouldn't normally happen but we want to be
|
|
182
|
+
// sure we can handle it if it does.
|
|
183
|
+
// If there are no accounts, we'll add one and then get the address.
|
|
184
|
+
const accounts = await keyring.getAccounts();
|
|
185
|
+
if (accounts.length === 0) {
|
|
186
|
+
await keyring.addAccounts(1);
|
|
187
|
+
}
|
|
188
|
+
// We have the guarantee that there is at least one account after the above code, so
|
|
189
|
+
// we can safely destructure the first address.
|
|
190
|
+
const [moneyAddress] = await keyring.getAccounts();
|
|
191
|
+
return moneyAddress;
|
|
192
|
+
});
|
|
193
|
+
return result;
|
|
194
|
+
}, _MoneyAccountController_createMoneyKeyring = function _MoneyAccountController_createMoneyKeyring(entropySource) {
|
|
195
|
+
return this.messenger.call('KeyringController:addNewKeyring', KeyringTypes.money, {
|
|
196
|
+
entropySource,
|
|
197
|
+
});
|
|
198
|
+
}, _MoneyAccountController_getPrimaryEntropySource = function _MoneyAccountController_getPrimaryEntropySource() {
|
|
199
|
+
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
200
|
+
const primaryHdKeyring = keyrings.find((keyring) => keyring.type === 'HD Key Tree');
|
|
201
|
+
return primaryHdKeyring?.metadata.id;
|
|
202
|
+
}, _MoneyAccountController_assertIsUnlocked = function _MoneyAccountController_assertIsUnlocked() {
|
|
203
|
+
const { isUnlocked } = this.messenger.call('KeyringController:getState');
|
|
204
|
+
if (!isUnlocked) {
|
|
205
|
+
throw new Error('Cannot create a money account while the keyring is locked');
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=MoneyAccountController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyAccountController.mjs","sourceRoot":"","sources":["../src/MoneyAccountController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AACpE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,8BAA8B;AAQ5E,OAAO,EACL,sBAAsB,EACtB,YAAY,EACb,qCAAqC;AAItC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,qBAAiB;AAGhD,OAAO,EAAE,cAAc,EAAE,oBAAgB;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAQvD,MAAM,8BAA8B,GAAG;IACrC,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAA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AAO,EAAE,EAAE,EAAE;QACpB,qFAAqF;QACrF,mFAAmF;QACnF,oCAAoC;QACpC,oEAAoE;QACpE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QAC7C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QAED,oFAAoF;QACpF,+CAA+C;QAC/C,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACnD,OAAO,YAAY,CAAC;IACtB,CAAC,CACF,CAAC;IAEF,OAAO,MAAa,CAAC;AACvB,CAAC,mGAYC,aAA8B;IAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CACxB,iCAAiC,EACjC,YAAY,CAAC,KAAK,EAClB;QACE,aAAa;KACiB,CACjC,CAAC;AACJ,CAAC;IAQC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACvE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,aAAa,CAC5C,CAAC;IACF,OAAO,gBAAgB,EAAE,QAAQ,CAAC,EAAE,CAAC;AACvC,CAAC;IAMC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACzE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MoneyKeyring,\n MoneyKeyringSerializedState,\n} from '@metamask/eth-money-keyring';\nimport { MONEY_DERIVATION_PATH } from '@metamask/eth-money-keyring';\nimport { EthAccountType, EthMethod, EthScope } from '@metamask/keyring-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type {\n KeyringControllerAddNewKeyringAction,\n KeyringControllerGetStateAction,\n KeyringControllerWithKeyringAction,\n KeyringMetadata,\n} from '@metamask/keyring-controller';\nimport {\n isKeyringNotFoundError,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport { EthKeyring } from '@metamask/keyring-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { Hex } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { projectLogger as log } from './logger';\nimport type { MoneyAccountControllerMethodActions } from './money-account-controller-method-action-types';\nimport type { MoneyAccount } from './types';\nimport { isMoneyKeyring } from './utils';\n\nexport const controllerName = 'MoneyAccountController';\n\nexport type MoneyAccountControllerState = {\n moneyAccounts: {\n [id: MoneyAccount['id']]: MoneyAccount;\n };\n};\n\nconst moneyAccountControllerMetadata = {\n moneyAccounts: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<MoneyAccountControllerState>;\n\nexport function getDefaultMoneyAccountControllerState(): MoneyAccountControllerState {\n return {\n moneyAccounts: {},\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'createMoneyAccount',\n 'getMoneyAccount',\n 'clearState',\n] as const;\n\nexport type MoneyAccountControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountControllerState\n>;\n\nexport type MoneyAccountControllerActions =\n | MoneyAccountControllerGetStateAction\n | MoneyAccountControllerMethodActions;\n\ntype AllowedActions =\n | KeyringControllerGetStateAction\n | KeyringControllerAddNewKeyringAction\n | KeyringControllerWithKeyringAction;\n\nexport type MoneyAccountControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n MoneyAccountControllerState\n>;\n\nexport type MoneyAccountControllerEvents =\n MoneyAccountControllerStateChangeEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountControllerActions | AllowedActions,\n MoneyAccountControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller for managing money accounts.\n */\nexport class MoneyAccountController extends BaseController<\n typeof controllerName,\n MoneyAccountControllerState,\n MoneyAccountControllerMessenger\n> {\n /**\n * Constructor for the MoneyAccountController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n * @param options.state - The initial state of the controller. If not provided, the default state will be used.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: MoneyAccountControllerMessenger;\n state?: Partial<MoneyAccountControllerState>;\n }) {\n super({\n messenger,\n metadata: moneyAccountControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultMoneyAccountControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the controller by creating a money account for the primary\n * entropy source if one does not already exist.\n */\n async init(): Promise<void> {\n this.#assertIsUnlocked();\n\n const primaryEntropySource = this.#getPrimaryEntropySource();\n if (primaryEntropySource) {\n log(\n 'Initializing money account for primary entropy source: %s',\n primaryEntropySource,\n );\n await this.createMoneyAccount(primaryEntropySource);\n log('Money account initialized');\n }\n }\n\n /**\n * Creates a money account for the given entropy source. If an account\n * already exists for that entropy source, it is returned as-is (idempotent).\n *\n * @param entropySource - The entropy source ID to create the money account for.\n * @returns The money account.\n */\n async createMoneyAccount(\n entropySource: EntropySourceId,\n ): Promise<MoneyAccount> {\n this.#assertIsUnlocked();\n\n // Idempotent: return existing account if already in state.\n const existingAccount = this.getMoneyAccount({ entropySource });\n if (existingAccount) {\n log(\n `Money account already exists for entropy source: ${entropySource}, address: ${existingAccount.address}`,\n );\n return existingAccount;\n }\n\n // Try to find an existing `MoneyKeyring` for this entropy source and get its address.\n // If no such keyring exists, create one and add an account to get the address.\n let address: Hex;\n try {\n address = await this.#getOrCreateMoneyAccountFromKeyring(entropySource);\n } catch (error) {\n // Forward any unexpected errors, but if the error is that\n // the keyring wasn't found, we'll create it below.\n if (!isKeyringNotFoundError(error)) {\n throw error;\n }\n\n log(\n `No money keyring found for entropy source: ${entropySource}, creating one`,\n );\n // Create the keyring right away by providing a `numberOfAccounts` of 1, which will create\n // the first account and allow us to get the address without having to use `withKeyring` again.\n await this.#createMoneyKeyring(entropySource);\n\n // Now we can get the address from the newly created keyring.\n address = await this.#getOrCreateMoneyAccountFromKeyring(entropySource);\n }\n\n log(`Creating money account for address: ${address}`);\n const account: MoneyAccount = {\n id: uuid(),\n type: EthAccountType.Eoa,\n address,\n scopes: [EthScope.Eoa],\n options: {\n entropy: {\n type: 'mnemonic',\n id: entropySource,\n groupIndex: 0,\n derivationPath: MONEY_DERIVATION_PATH,\n },\n exportable: false,\n },\n methods: [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n };\n\n // Store the account in state.\n this.update((state) => {\n state.moneyAccounts[account.id] = account;\n });\n\n log(`Money account created: ${account.address} (${account.id})`);\n return account;\n }\n\n /**\n * Gets a money account by its associated entropy source ID. If no ID is\n * provided, the primary entropy source will be used.\n *\n * @param selector - Selector options for getting the money account.\n * @param selector.entropySource - The entropy source ID to get the money account for. If not provided, the primary entropy source will be used.\n * @returns The money account, or `undefined` if no account exists for the given entropy source.\n */\n getMoneyAccount(\n selector: { entropySource?: EntropySourceId } = {},\n ): MoneyAccount | undefined {\n const entropySource =\n selector.entropySource ?? this.#getPrimaryEntropySource();\n if (entropySource === undefined) {\n return undefined;\n }\n\n // We should never have more than one money account per entropy source, but if we\n // do, just return the first one we find.\n return Object.values(this.state.moneyAccounts).find(\n (account) => account.options.entropy.id === entropySource,\n );\n }\n\n /**\n * Resets the controller state to its default, removing all money accounts.\n *\n * Intended for use during a full app reset (e.g. when the user wipes all\n * wallet data). Does not interact with the keyring — the caller is\n * responsible for ensuring the associated keyring state is also cleared.\n */\n clearState(): void {\n this.update((state) => {\n state.moneyAccounts = {};\n });\n }\n\n /**\n * Gets or creates a money account with its associated entropy source ID. It relies on\n * the `MoneyKeyring` keyring instance to get the address, so if no account exists\n * on the keyring yet, it will be created and then the address will be returned.\n *\n * @param entropySource - The entropy source ID to get the money account address for.\n * @returns The money account address.\n */\n async #getOrCreateMoneyAccountFromKeyring(\n entropySource: EntropySourceId,\n ): Promise<Hex> {\n // Filter to find a specific `MoneyKeyring` for the given entropy source.\n const isMoneyKeyringForEntropySource = (\n keyring: EthKeyring,\n ): keyring is MoneyKeyring =>\n isMoneyKeyring(keyring) && keyring.entropySource === entropySource;\n\n const result = await this.messenger.call(\n 'KeyringController:withKeyring',\n {\n filter: isMoneyKeyringForEntropySource,\n },\n async ({ keyring }) => {\n // We're adding this logic to be defensive against the possibility of a money keyring\n // existing without any accounts, which shouldn't normally happen but we want to be\n // sure we can handle it if it does.\n // If there are no accounts, we'll add one and then get the address.\n const accounts = await keyring.getAccounts();\n if (accounts.length === 0) {\n await keyring.addAccounts(1);\n }\n\n // We have the guarantee that there is at least one account after the above code, so\n // we can safely destructure the first address.\n const [moneyAddress] = await keyring.getAccounts();\n return moneyAddress;\n },\n );\n\n return result as Hex;\n }\n\n /**\n * Adds a new money keyring for the given entropy source and returns its metadata.\n *\n * NOTE: This function won't check if a money keyring for the given entropy source already\n * exists!\n *\n * @param entropySource - The entropy source ID to create the money keyring for.\n * @returns The metadata of the newly created money keyring.\n */\n #createMoneyKeyring(\n entropySource: EntropySourceId,\n ): Promise<KeyringMetadata> {\n return this.messenger.call(\n 'KeyringController:addNewKeyring',\n KeyringTypes.money,\n {\n entropySource,\n } as MoneyKeyringSerializedState,\n );\n }\n\n /**\n * Gets the primary entropy source ID.\n *\n * @returns The primary entropy source ID, or `undefined` if no HD keyring exists.\n */\n #getPrimaryEntropySource(): EntropySourceId | undefined {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n const primaryHdKeyring = keyrings.find(\n (keyring) => keyring.type === 'HD Key Tree',\n );\n return primaryHdKeyring?.metadata.id;\n }\n\n /**\n * Throws if the keyring is currently locked.\n */\n #assertIsUnlocked(): void {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n if (!isUnlocked) {\n throw new Error(\n 'Cannot create a money account while the keyring is locked',\n );\n }\n }\n}\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultMoneyAccountControllerState = exports.controllerName = exports.MoneyAccountController = exports.isMoneyKeyring = void 0;
|
|
4
|
+
var utils_1 = require("./utils.cjs");
|
|
5
|
+
Object.defineProperty(exports, "isMoneyKeyring", { enumerable: true, get: function () { return utils_1.isMoneyKeyring; } });
|
|
6
|
+
var MoneyAccountController_1 = require("./MoneyAccountController.cjs");
|
|
7
|
+
Object.defineProperty(exports, "MoneyAccountController", { enumerable: true, get: function () { return MoneyAccountController_1.MoneyAccountController; } });
|
|
8
|
+
Object.defineProperty(exports, "controllerName", { enumerable: true, get: function () { return MoneyAccountController_1.controllerName; } });
|
|
9
|
+
Object.defineProperty(exports, "getDefaultMoneyAccountControllerState", { enumerable: true, get: function () { return MoneyAccountController_1.getDefaultMoneyAccountControllerState; } });
|
|
10
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qCAAyC;AAAhC,uGAAA,cAAc,OAAA;AACvB,uEAIkC;AAHhC,gIAAA,sBAAsB,OAAA;AACtB,wHAAA,cAAc,OAAA;AACd,+IAAA,qCAAqC,OAAA","sourcesContent":["export type { MoneyAccount } from './types';\nexport { isMoneyKeyring } from './utils';\nexport {\n MoneyAccountController,\n controllerName,\n getDefaultMoneyAccountControllerState,\n} from './MoneyAccountController';\nexport type {\n MoneyAccountControllerState,\n MoneyAccountControllerGetStateAction,\n MoneyAccountControllerActions,\n MoneyAccountControllerStateChangeEvent,\n MoneyAccountControllerEvents,\n MoneyAccountControllerMessenger,\n} from './MoneyAccountController';\nexport type {\n MoneyAccountControllerCreateMoneyAccountAction,\n MoneyAccountControllerGetMoneyAccountAction,\n} from './money-account-controller-method-action-types';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { MoneyAccount } from "./types.cjs";
|
|
2
|
+
export { isMoneyKeyring } from "./utils.cjs";
|
|
3
|
+
export { MoneyAccountController, controllerName, getDefaultMoneyAccountControllerState, } from "./MoneyAccountController.cjs";
|
|
4
|
+
export type { MoneyAccountControllerState, MoneyAccountControllerGetStateAction, MoneyAccountControllerActions, MoneyAccountControllerStateChangeEvent, MoneyAccountControllerEvents, MoneyAccountControllerMessenger, } from "./MoneyAccountController.cjs";
|
|
5
|
+
export type { MoneyAccountControllerCreateMoneyAccountAction, MoneyAccountControllerGetMoneyAccountAction, } from "./money-account-controller-method-action-types.cjs";
|
|
6
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,oBAAgB;AAC5C,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EACV,8CAA8C,EAC9C,2CAA2C,GAC5C,2DAAuD"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { MoneyAccount } from "./types.mjs";
|
|
2
|
+
export { isMoneyKeyring } from "./utils.mjs";
|
|
3
|
+
export { MoneyAccountController, controllerName, getDefaultMoneyAccountControllerState, } from "./MoneyAccountController.mjs";
|
|
4
|
+
export type { MoneyAccountControllerState, MoneyAccountControllerGetStateAction, MoneyAccountControllerActions, MoneyAccountControllerStateChangeEvent, MoneyAccountControllerEvents, MoneyAccountControllerMessenger, } from "./MoneyAccountController.mjs";
|
|
5
|
+
export type { MoneyAccountControllerCreateMoneyAccountAction, MoneyAccountControllerGetMoneyAccountAction, } from "./money-account-controller-method-action-types.mjs";
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,oBAAgB;AAC5C,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EACV,8CAA8C,EAC9C,2CAA2C,GAC5C,2DAAuD"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,qCAAqC,EACtC,qCAAiC","sourcesContent":["export type { MoneyAccount } from './types';\nexport { isMoneyKeyring } from './utils';\nexport {\n MoneyAccountController,\n controllerName,\n getDefaultMoneyAccountControllerState,\n} from './MoneyAccountController';\nexport type {\n MoneyAccountControllerState,\n MoneyAccountControllerGetStateAction,\n MoneyAccountControllerActions,\n MoneyAccountControllerStateChangeEvent,\n MoneyAccountControllerEvents,\n MoneyAccountControllerMessenger,\n} from './MoneyAccountController';\nexport type {\n MoneyAccountControllerCreateMoneyAccountAction,\n MoneyAccountControllerGetMoneyAccountAction,\n} from './money-account-controller-method-action-types';\n"]}
|
package/dist/logger.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createModuleLogger = exports.projectLogger = void 0;
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
7
|
+
exports.projectLogger = (0, utils_1.createProjectLogger)('money-account-controller');
|
|
8
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;AAE1B,2CAA0E;AAIjE,mGAJqB,0BAAkB,OAIrB;AAFd,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,0BAA0B,CAAC,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('money-account-controller');\n\nexport { createModuleLogger };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAAkD,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAAkD,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('money-account-controller');\n\nexport { createModuleLogger };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-controller-method-action-types.cjs","sourceRoot":"","sources":["../src/money-account-controller-method-action-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MoneyAccountController } from './MoneyAccountController';\n\nexport type MoneyAccountControllerCreateMoneyAccountAction = {\n type: `MoneyAccountController:createMoneyAccount`;\n handler: MoneyAccountController['createMoneyAccount'];\n};\n\nexport type MoneyAccountControllerGetMoneyAccountAction = {\n type: `MoneyAccountController:getMoneyAccount`;\n handler: MoneyAccountController['getMoneyAccount'];\n};\n\nexport type MoneyAccountControllerClearStateAction = {\n type: `MoneyAccountController:clearState`;\n handler: MoneyAccountController['clearState'];\n};\n\nexport type MoneyAccountControllerMethodActions =\n | MoneyAccountControllerCreateMoneyAccountAction\n | MoneyAccountControllerGetMoneyAccountAction\n | MoneyAccountControllerClearStateAction;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MoneyAccountController } from "./MoneyAccountController.cjs";
|
|
2
|
+
export type MoneyAccountControllerCreateMoneyAccountAction = {
|
|
3
|
+
type: `MoneyAccountController:createMoneyAccount`;
|
|
4
|
+
handler: MoneyAccountController['createMoneyAccount'];
|
|
5
|
+
};
|
|
6
|
+
export type MoneyAccountControllerGetMoneyAccountAction = {
|
|
7
|
+
type: `MoneyAccountController:getMoneyAccount`;
|
|
8
|
+
handler: MoneyAccountController['getMoneyAccount'];
|
|
9
|
+
};
|
|
10
|
+
export type MoneyAccountControllerClearStateAction = {
|
|
11
|
+
type: `MoneyAccountController:clearState`;
|
|
12
|
+
handler: MoneyAccountController['clearState'];
|
|
13
|
+
};
|
|
14
|
+
export type MoneyAccountControllerMethodActions = MoneyAccountControllerCreateMoneyAccountAction | MoneyAccountControllerGetMoneyAccountAction | MoneyAccountControllerClearStateAction;
|
|
15
|
+
//# sourceMappingURL=money-account-controller-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-controller-method-action-types.d.cts","sourceRoot":"","sources":["../src/money-account-controller-method-action-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AAEvE,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAC3C,8CAA8C,GAC9C,2CAA2C,GAC3C,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MoneyAccountController } from "./MoneyAccountController.mjs";
|
|
2
|
+
export type MoneyAccountControllerCreateMoneyAccountAction = {
|
|
3
|
+
type: `MoneyAccountController:createMoneyAccount`;
|
|
4
|
+
handler: MoneyAccountController['createMoneyAccount'];
|
|
5
|
+
};
|
|
6
|
+
export type MoneyAccountControllerGetMoneyAccountAction = {
|
|
7
|
+
type: `MoneyAccountController:getMoneyAccount`;
|
|
8
|
+
handler: MoneyAccountController['getMoneyAccount'];
|
|
9
|
+
};
|
|
10
|
+
export type MoneyAccountControllerClearStateAction = {
|
|
11
|
+
type: `MoneyAccountController:clearState`;
|
|
12
|
+
handler: MoneyAccountController['clearState'];
|
|
13
|
+
};
|
|
14
|
+
export type MoneyAccountControllerMethodActions = MoneyAccountControllerCreateMoneyAccountAction | MoneyAccountControllerGetMoneyAccountAction | MoneyAccountControllerClearStateAction;
|
|
15
|
+
//# sourceMappingURL=money-account-controller-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-controller-method-action-types.d.mts","sourceRoot":"","sources":["../src/money-account-controller-method-action-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AAEvE,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAC3C,8CAA8C,GAC9C,2CAA2C,GAC3C,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-account-controller-method-action-types.mjs","sourceRoot":"","sources":["../src/money-account-controller-method-action-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MoneyAccountController } from './MoneyAccountController';\n\nexport type MoneyAccountControllerCreateMoneyAccountAction = {\n type: `MoneyAccountController:createMoneyAccount`;\n handler: MoneyAccountController['createMoneyAccount'];\n};\n\nexport type MoneyAccountControllerGetMoneyAccountAction = {\n type: `MoneyAccountController:getMoneyAccount`;\n handler: MoneyAccountController['getMoneyAccount'];\n};\n\nexport type MoneyAccountControllerClearStateAction = {\n type: `MoneyAccountController:clearState`;\n handler: MoneyAccountController['clearState'];\n};\n\nexport type MoneyAccountControllerMethodActions =\n | MoneyAccountControllerCreateMoneyAccountAction\n | MoneyAccountControllerGetMoneyAccountAction\n | MoneyAccountControllerClearStateAction;\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n KeyringAccount,\n KeyringAccountEntropyMnemonicOptions,\n} from '@metamask/keyring-api';\n\n/** A money account represents an account managed by the MoneyAccountController. */\nexport type MoneyAccount = Omit<KeyringAccount, 'options'> & {\n // We use stricter options for money accounts. They can be seen as BIP-44 accounts\n // and we make them non-exportable too.\n options: {\n entropy: KeyringAccountEntropyMnemonicOptions;\n exportable: false;\n };\n};\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringAccountEntropyMnemonicOptions } from "@metamask/keyring-api";
|
|
2
|
+
/** A money account represents an account managed by the MoneyAccountController. */
|
|
3
|
+
export type MoneyAccount = Omit<KeyringAccount, 'options'> & {
|
|
4
|
+
options: {
|
|
5
|
+
entropy: KeyringAccountEntropyMnemonicOptions;
|
|
6
|
+
exportable: false;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oCAAoC,EACrC,8BAA8B;AAE/B,mFAAmF;AACnF,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG;IAG3D,OAAO,EAAE;QACP,OAAO,EAAE,oCAAoC,CAAC;QAC9C,UAAU,EAAE,KAAK,CAAC;KACnB,CAAC;CACH,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringAccountEntropyMnemonicOptions } from "@metamask/keyring-api";
|
|
2
|
+
/** A money account represents an account managed by the MoneyAccountController. */
|
|
3
|
+
export type MoneyAccount = Omit<KeyringAccount, 'options'> & {
|
|
4
|
+
options: {
|
|
5
|
+
entropy: KeyringAccountEntropyMnemonicOptions;
|
|
6
|
+
exportable: false;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oCAAoC,EACrC,8BAA8B;AAE/B,mFAAmF;AACnF,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG;IAG3D,OAAO,EAAE;QACP,OAAO,EAAE,oCAAoC,CAAC;QAC9C,UAAU,EAAE,KAAK,CAAC;KACnB,CAAC;CACH,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n KeyringAccount,\n KeyringAccountEntropyMnemonicOptions,\n} from '@metamask/keyring-api';\n\n/** A money account represents an account managed by the MoneyAccountController. */\nexport type MoneyAccount = Omit<KeyringAccount, 'options'> & {\n // We use stricter options for money accounts. They can be seen as BIP-44 accounts\n // and we make them non-exportable too.\n options: {\n entropy: KeyringAccountEntropyMnemonicOptions;\n exportable: false;\n };\n};\n"]}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMoneyKeyring = void 0;
|
|
4
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
5
|
+
/**
|
|
6
|
+
* Returns `true` if the given keyring is a {@link MoneyKeyring}.
|
|
7
|
+
*
|
|
8
|
+
* @param keyring - The keyring to check.
|
|
9
|
+
* @returns Whether the keyring is a `MoneyKeyring`.
|
|
10
|
+
*/
|
|
11
|
+
function isMoneyKeyring(keyring) {
|
|
12
|
+
return keyring.type === keyring_controller_1.KeyringTypes.money;
|
|
13
|
+
}
|
|
14
|
+
exports.isMoneyKeyring = isMoneyKeyring;
|
|
15
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,qEAA4D;AAG5D;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAAmB;IAChD,OAAO,OAAO,CAAC,IAAI,KAAK,iCAAY,CAAC,KAAK,CAAC;AAC7C,CAAC;AAFD,wCAEC","sourcesContent":["import type { MoneyKeyring } from '@metamask/eth-money-keyring';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport { EthKeyring } from '@metamask/keyring-utils';\n\n/**\n * Returns `true` if the given keyring is a {@link MoneyKeyring}.\n *\n * @param keyring - The keyring to check.\n * @returns Whether the keyring is a `MoneyKeyring`.\n */\nexport function isMoneyKeyring(keyring: EthKeyring): keyring is MoneyKeyring {\n return keyring.type === KeyringTypes.money;\n}\n"]}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MoneyKeyring } from "@metamask/eth-money-keyring";
|
|
2
|
+
import { EthKeyring } from "@metamask/keyring-utils";
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the given keyring is a {@link MoneyKeyring}.
|
|
5
|
+
*
|
|
6
|
+
* @param keyring - The keyring to check.
|
|
7
|
+
* @returns Whether the keyring is a `MoneyKeyring`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isMoneyKeyring(keyring: EthKeyring): keyring is MoneyKeyring;
|
|
10
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,oCAAoC;AAEhE,OAAO,EAAE,UAAU,EAAE,gCAAgC;AAErD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,YAAY,CAE3E"}
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MoneyKeyring } from "@metamask/eth-money-keyring";
|
|
2
|
+
import { EthKeyring } from "@metamask/keyring-utils";
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the given keyring is a {@link MoneyKeyring}.
|
|
5
|
+
*
|
|
6
|
+
* @param keyring - The keyring to check.
|
|
7
|
+
* @returns Whether the keyring is a `MoneyKeyring`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isMoneyKeyring(keyring: EthKeyring): keyring is MoneyKeyring;
|
|
10
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,oCAAoC;AAEhE,OAAO,EAAE,UAAU,EAAE,gCAAgC;AAErD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,YAAY,CAE3E"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the given keyring is a {@link MoneyKeyring}.
|
|
4
|
+
*
|
|
5
|
+
* @param keyring - The keyring to check.
|
|
6
|
+
* @returns Whether the keyring is a `MoneyKeyring`.
|
|
7
|
+
*/
|
|
8
|
+
export function isMoneyKeyring(keyring) {
|
|
9
|
+
return keyring.type === KeyringTypes.money;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAmB;IAChD,OAAO,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,KAAK,CAAC;AAC7C,CAAC","sourcesContent":["import type { MoneyKeyring } from '@metamask/eth-money-keyring';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport { EthKeyring } from '@metamask/keyring-utils';\n\n/**\n * Returns `true` if the given keyring is a {@link MoneyKeyring}.\n *\n * @param keyring - The keyring to check.\n * @returns Whether the keyring is a `MoneyKeyring`.\n */\nexport function isMoneyKeyring(keyring: EthKeyring): keyring is MoneyKeyring {\n return keyring.type === KeyringTypes.money;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/money-account-controller",
|
|
3
|
+
"version": "0.0.0-preview-373edc9",
|
|
4
|
+
"description": "MetaMask Money account controller",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/money-account-controller#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
40
|
+
"build:docs": "typedoc",
|
|
41
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/money-account-controller",
|
|
42
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/money-account-controller",
|
|
43
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
46
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
47
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
51
|
+
"@metamask/keyring-utils": "^3.2.0",
|
|
52
|
+
"@metamask/utils": "^11.9.0",
|
|
53
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
"deepmerge": "^4.2.2",
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"ts-jest": "^29.2.5",
|
|
58
|
+
"typedoc": "^0.25.13",
|
|
59
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
60
|
+
"typescript": "~5.3.3"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": "^18.18 || >=20"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public",
|
|
67
|
+
"registry": "https://registry.npmjs.org/"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@metamask/account-api": "^1.0.0",
|
|
71
|
+
"@metamask/base-controller": "^9.0.1",
|
|
72
|
+
"@metamask/eth-money-keyring": "^2.0.0",
|
|
73
|
+
"@metamask/keyring-api": "^21.6.0",
|
|
74
|
+
"@metamask/keyring-controller": "^25.1.1",
|
|
75
|
+
"@metamask/messenger": "^1.0.0",
|
|
76
|
+
"uuid": "^8.3.2"
|
|
77
|
+
}
|
|
78
|
+
}
|