@tetherto/wdk-wallet 1.0.0-beta.10 → 1.0.0-beta.11
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/index.js +7 -2
- package/package.json +6 -2
- package/src/errors.js +13 -0
- package/src/signer.js +62 -0
- package/src/wallet-manager.js +130 -20
- package/types/index.d.ts +2 -1
- package/types/src/errors.d.ts +8 -0
- package/types/src/signer.d.ts +34 -0
- package/types/src/wallet-manager.d.ts +95 -15
package/index.js
CHANGED
|
@@ -25,8 +25,13 @@
|
|
|
25
25
|
|
|
26
26
|
export { default } from './src/wallet-manager.js'
|
|
27
27
|
|
|
28
|
-
export {
|
|
28
|
+
export {
|
|
29
|
+
default as WalletAccountReadOnly,
|
|
30
|
+
IWalletAccountReadOnly
|
|
31
|
+
} from './src/wallet-account-read-only.js'
|
|
29
32
|
|
|
30
33
|
export { IWalletAccount } from './src/wallet-account.js'
|
|
31
34
|
|
|
32
|
-
export { NotImplementedError } from './src/errors.js'
|
|
35
|
+
export { NotImplementedError, SignerError } from './src/errors.js'
|
|
36
|
+
|
|
37
|
+
export { ISigner } from './src/signer.js'
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "A simple package to manage BIP-32 wallets.",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wdk",
|
|
7
|
+
"wallet",
|
|
8
|
+
"bip-32"
|
|
9
|
+
],
|
|
6
10
|
"author": "Tether",
|
|
7
11
|
"license": "Apache-2.0",
|
|
8
12
|
"repository": {
|
package/src/errors.js
CHANGED
|
@@ -25,3 +25,16 @@ export class NotImplementedError extends Error {
|
|
|
25
25
|
this.name = 'NotImplementedError'
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export class SignerError extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* Create a new signer error.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} message - The error's message.
|
|
34
|
+
*/
|
|
35
|
+
constructor (message) {
|
|
36
|
+
super(message)
|
|
37
|
+
|
|
38
|
+
this.name = 'SignerError'
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/signer.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
'use strict'
|
|
15
|
+
|
|
16
|
+
import { NotImplementedError } from './errors.js'
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('./wallet-account-read-only.js').Transaction} Transaction */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A minimal, cross-chain signer interface.
|
|
22
|
+
*
|
|
23
|
+
* @interface
|
|
24
|
+
*/
|
|
25
|
+
export class ISigner {
|
|
26
|
+
/**
|
|
27
|
+
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
28
|
+
*
|
|
29
|
+
* @param {string} relPath - The relative derivation path.
|
|
30
|
+
* @returns {Promise<ISigner>} The derived signer.
|
|
31
|
+
* @throws {SignerError} If the signer does not support derivation.
|
|
32
|
+
*/
|
|
33
|
+
async derive (relPath) {
|
|
34
|
+
throw new NotImplementedError('derive(relPath)')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Signs a transaction.
|
|
39
|
+
*
|
|
40
|
+
* @param {Transaction} tx - The transaction to sign.
|
|
41
|
+
* @returns {Promise<unknown>} The signed transaction.
|
|
42
|
+
*/
|
|
43
|
+
async signTransaction (tx) {
|
|
44
|
+
throw new NotImplementedError('signTransaction(tx)')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the signer's address.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<string>} The address.
|
|
51
|
+
*/
|
|
52
|
+
async getAddress () {
|
|
53
|
+
throw new NotImplementedError('getAddress()')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Disposes the signer and clears any secret material from memory.
|
|
58
|
+
*/
|
|
59
|
+
dispose () {
|
|
60
|
+
throw new NotImplementedError('dispose()')
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/wallet-manager.js
CHANGED
|
@@ -18,6 +18,7 @@ import * as bip39 from 'bip39'
|
|
|
18
18
|
import { NotImplementedError } from './errors.js'
|
|
19
19
|
|
|
20
20
|
/** @typedef {import('./wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
|
+
/** @typedef {import('./signer.js').ISigner} ISigner */
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @typedef {Object} WalletConfig
|
|
@@ -34,30 +35,49 @@ import { NotImplementedError } from './errors.js'
|
|
|
34
35
|
/** @abstract */
|
|
35
36
|
export default class WalletManager {
|
|
36
37
|
/**
|
|
37
|
-
* Creates a new wallet manager.
|
|
38
|
+
* Creates a new wallet manager from a BIP-39 seed.
|
|
38
39
|
*
|
|
39
|
-
* @
|
|
40
|
+
* @overload
|
|
41
|
+
* @param {string | Uint8Array} seed - The BIP-39 seed phrase or raw seed bytes.
|
|
40
42
|
* @param {WalletConfig} [config] - The wallet configuration.
|
|
41
43
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new wallet manager from a default signer.
|
|
47
|
+
*
|
|
48
|
+
* @overload
|
|
49
|
+
* @param {ISigner} signer - The default signer.
|
|
50
|
+
* @param {WalletConfig} [config] - The wallet configuration.
|
|
51
|
+
*/
|
|
52
|
+
constructor (seedOrSigner, config = {}) {
|
|
53
|
+
if (typeof seedOrSigner === 'string') {
|
|
54
|
+
if (!WalletManager.isValidSeedPhrase(seedOrSigner)) {
|
|
45
55
|
throw new Error('The seed phrase is invalid.')
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
seedOrSigner = bip39.mnemonicToSeedSync(seedOrSigner)
|
|
49
59
|
}
|
|
50
60
|
|
|
61
|
+
const isSeed = seedOrSigner instanceof Uint8Array
|
|
62
|
+
|
|
51
63
|
/** @private */
|
|
52
|
-
this._seed =
|
|
64
|
+
this._seed = isSeed ? seedOrSigner : undefined
|
|
53
65
|
|
|
54
66
|
/**
|
|
55
|
-
* The
|
|
67
|
+
* The default signer.
|
|
56
68
|
*
|
|
57
69
|
* @protected
|
|
58
|
-
* @type {
|
|
70
|
+
* @type {ISigner | undefined}
|
|
59
71
|
*/
|
|
60
|
-
this.
|
|
72
|
+
this._defaultSigner = isSeed ? undefined : seedOrSigner
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A map between signer names and signers added via {@link addSigner}.
|
|
76
|
+
*
|
|
77
|
+
* @protected
|
|
78
|
+
* @type {Record<string, ISigner>}
|
|
79
|
+
*/
|
|
80
|
+
this._signers = {}
|
|
61
81
|
|
|
62
82
|
/**
|
|
63
83
|
* A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
|
|
@@ -65,9 +85,17 @@ export default class WalletManager {
|
|
|
65
85
|
* {@link getAccount} and {@link getAccountByPath} methods.
|
|
66
86
|
*
|
|
67
87
|
* @protected
|
|
68
|
-
* @type {
|
|
88
|
+
* @type {Record<string, IWalletAccount>}
|
|
69
89
|
*/
|
|
70
90
|
this._accounts = {}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The wallet configuration.
|
|
94
|
+
*
|
|
95
|
+
* @protected
|
|
96
|
+
* @type {WalletConfig}
|
|
97
|
+
*/
|
|
98
|
+
this._config = config
|
|
71
99
|
}
|
|
72
100
|
|
|
73
101
|
/**
|
|
@@ -92,23 +120,93 @@ export default class WalletManager {
|
|
|
92
120
|
}
|
|
93
121
|
|
|
94
122
|
/**
|
|
95
|
-
* The seed
|
|
123
|
+
* The seed of the wallet.
|
|
96
124
|
*
|
|
97
|
-
* @type {Uint8Array}
|
|
125
|
+
* @type {Uint8Array | undefined}
|
|
98
126
|
*/
|
|
99
127
|
get seed () {
|
|
100
128
|
return this._seed
|
|
101
129
|
}
|
|
102
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Registers a signer under the given name.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} signerName - The signer name.
|
|
135
|
+
* @param {ISigner} signer - The signer.
|
|
136
|
+
* @returns {WalletManager} The wallet manager.
|
|
137
|
+
* @throws {Error} If `signerName` is an empty or blank string.
|
|
138
|
+
*/
|
|
139
|
+
addSigner (signerName, signer) {
|
|
140
|
+
if (!signerName.trim()) {
|
|
141
|
+
throw new Error('The signer name cannot be an empty or blank string.')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this._signers[signerName] = signer
|
|
145
|
+
return this
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns a signer. With no arguments, returns the default signer provided
|
|
150
|
+
* at construction. With a name, returns the signer registered under that
|
|
151
|
+
* name via {@link addSigner}.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} [signerName] - The signer name. Omit to get the default.
|
|
154
|
+
* @returns {ISigner} The signer.
|
|
155
|
+
* @throws {Error} If called with no arguments and no default signer was
|
|
156
|
+
* provided at construction, or if called with a name that is not registered.
|
|
157
|
+
*/
|
|
158
|
+
getSigner (signerName) {
|
|
159
|
+
if (signerName === undefined) {
|
|
160
|
+
if (this._defaultSigner === undefined) {
|
|
161
|
+
throw new Error('No default signer registered.')
|
|
162
|
+
}
|
|
163
|
+
return this._defaultSigner
|
|
164
|
+
}
|
|
165
|
+
const signer = this._signers[signerName]
|
|
166
|
+
if (signer === undefined) {
|
|
167
|
+
throw new Error(`No signer registered with name "${signerName}".`)
|
|
168
|
+
}
|
|
169
|
+
return signer
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns a shallow copy of the map of signers registered via {@link addSigner}.
|
|
174
|
+
* The default signer is not included; use {@link getSigner} with no arguments
|
|
175
|
+
* to retrieve it.
|
|
176
|
+
*
|
|
177
|
+
* @returns {Record<string, ISigner>} A map of signer names to signers. Empty if no signers have been registered.
|
|
178
|
+
*/
|
|
179
|
+
getSigners () {
|
|
180
|
+
return { ...this._signers }
|
|
181
|
+
}
|
|
182
|
+
|
|
103
183
|
/**
|
|
104
184
|
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
105
185
|
*
|
|
106
|
-
* @
|
|
186
|
+
* @overload
|
|
107
187
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
188
|
+
* @param {Object} [options] - Account options.
|
|
189
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
108
190
|
* @returns {Promise<IWalletAccount>} The account.
|
|
191
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
192
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
109
193
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns the wallet account associated with a registered signer. For
|
|
197
|
+
* non-derivable signers (e.g., private-key signers), returns the signer's
|
|
198
|
+
* single account. For derivable signers, returns the wallet account at the
|
|
199
|
+
* signer's root, with no further derivation.
|
|
200
|
+
*
|
|
201
|
+
* @overload
|
|
202
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
203
|
+
* @returns {Promise<IWalletAccount>} The account.
|
|
204
|
+
* @throws {Error} If no signer exists with the given name.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/** @abstract */
|
|
208
|
+
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
209
|
+
throw new NotImplementedError('getAccount(indexOrSignerName, options?)')
|
|
112
210
|
}
|
|
113
211
|
|
|
114
212
|
/**
|
|
@@ -116,10 +214,14 @@ export default class WalletManager {
|
|
|
116
214
|
*
|
|
117
215
|
* @abstract
|
|
118
216
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
217
|
+
* @param {Object} [options] - Account options.
|
|
218
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
119
219
|
* @returns {Promise<IWalletAccount>} The account.
|
|
220
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
221
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
120
222
|
*/
|
|
121
|
-
async getAccountByPath (path) {
|
|
122
|
-
throw new NotImplementedError('getAccountByPath(path)')
|
|
223
|
+
async getAccountByPath (path, options = {}) {
|
|
224
|
+
throw new NotImplementedError('getAccountByPath(path, options?)')
|
|
123
225
|
}
|
|
124
226
|
|
|
125
227
|
/**
|
|
@@ -133,15 +235,23 @@ export default class WalletManager {
|
|
|
133
235
|
}
|
|
134
236
|
|
|
135
237
|
/**
|
|
136
|
-
* Disposes all
|
|
238
|
+
* Disposes all wallet accounts and signers, clearing secret material from memory.
|
|
137
239
|
*/
|
|
138
240
|
dispose () {
|
|
139
241
|
for (const account of Object.values(this._accounts)) {
|
|
140
|
-
if (account.keyPair
|
|
242
|
+
if (account.keyPair?.privateKey) {
|
|
141
243
|
account.dispose()
|
|
142
244
|
}
|
|
143
245
|
}
|
|
144
246
|
|
|
247
|
+
this._defaultSigner?.dispose()
|
|
248
|
+
|
|
249
|
+
for (const signer of Object.values(this._signers)) {
|
|
250
|
+
signer.dispose()
|
|
251
|
+
}
|
|
252
|
+
|
|
145
253
|
this._accounts = {}
|
|
254
|
+
this._defaultSigner = undefined
|
|
255
|
+
this._signers = {}
|
|
146
256
|
}
|
|
147
257
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export type KeyPair = import("./src/wallet-account.js").KeyPair;
|
|
|
8
8
|
export { default } from "./src/wallet-manager.js";
|
|
9
9
|
export { default as WalletAccountReadOnly, IWalletAccountReadOnly } from "./src/wallet-account-read-only.js";
|
|
10
10
|
export { IWalletAccount } from "./src/wallet-account.js";
|
|
11
|
-
export { NotImplementedError } from "./src/errors.js";
|
|
11
|
+
export { NotImplementedError, SignerError } from "./src/errors.js";
|
|
12
|
+
export { ISigner } from "./src/signer.js";
|
package/types/src/errors.d.ts
CHANGED
|
@@ -6,3 +6,11 @@ export class NotImplementedError extends Error {
|
|
|
6
6
|
*/
|
|
7
7
|
constructor(methodName: string);
|
|
8
8
|
}
|
|
9
|
+
export class SignerError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new signer error.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} message - The error's message.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal, cross-chain signer interface.
|
|
3
|
+
*
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
6
|
+
export class ISigner {
|
|
7
|
+
/**
|
|
8
|
+
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
9
|
+
*
|
|
10
|
+
* @param {string} relPath - The relative derivation path.
|
|
11
|
+
* @returns {Promise<ISigner>} The derived signer.
|
|
12
|
+
* @throws {SignerError} If the signer does not support derivation.
|
|
13
|
+
*/
|
|
14
|
+
derive(relPath: string): Promise<ISigner>;
|
|
15
|
+
/**
|
|
16
|
+
* Signs a transaction.
|
|
17
|
+
*
|
|
18
|
+
* @param {Transaction} tx - The transaction to sign.
|
|
19
|
+
* @returns {Promise<unknown>} The signed transaction.
|
|
20
|
+
*/
|
|
21
|
+
signTransaction(tx: Transaction): Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the signer's address.
|
|
24
|
+
*
|
|
25
|
+
* @returns {Promise<string>} The address.
|
|
26
|
+
*/
|
|
27
|
+
getAddress(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Disposes the signer and clears any secret material from memory.
|
|
30
|
+
*/
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
33
|
+
export type Transaction = import("./wallet-account-read-only.js").Transaction;
|
|
34
|
+
export type SignerError = import("./errors.js").SignerError;
|
|
@@ -15,52 +15,130 @@ export default abstract class WalletManager {
|
|
|
15
15
|
*/
|
|
16
16
|
static isValidSeedPhrase(seedPhrase: string): boolean;
|
|
17
17
|
/**
|
|
18
|
-
* Creates a new wallet manager.
|
|
18
|
+
* Creates a new wallet manager from a BIP-39 seed.
|
|
19
19
|
*
|
|
20
|
-
* @param {string | Uint8Array} seed - The
|
|
20
|
+
* @param {string | Uint8Array} seed - The BIP-39 seed phrase or raw seed bytes.
|
|
21
21
|
* @param {WalletConfig} [config] - The wallet configuration.
|
|
22
22
|
*/
|
|
23
23
|
constructor(seed: string | Uint8Array, config?: WalletConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new wallet manager from a default signer.
|
|
26
|
+
*
|
|
27
|
+
* @param {ISigner} signer - The default signer.
|
|
28
|
+
* @param {WalletConfig} [config] - The wallet configuration.
|
|
29
|
+
*/
|
|
30
|
+
constructor(signer: ISigner, config?: WalletConfig);
|
|
24
31
|
/** @private */
|
|
25
|
-
private _seed;
|
|
32
|
+
private _seed: Uint8Array | undefined;
|
|
26
33
|
/**
|
|
27
|
-
* The
|
|
34
|
+
* The default signer provided at construction. Accessed via {@link getSigner}
|
|
35
|
+
* with no arguments.
|
|
28
36
|
*
|
|
29
37
|
* @protected
|
|
30
|
-
* @type {
|
|
38
|
+
* @type {ISigner | undefined}
|
|
31
39
|
*/
|
|
32
|
-
protected
|
|
40
|
+
protected _defaultSigner: ISigner | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* A map between signer names and signers added via {@link addSigner}.
|
|
43
|
+
*
|
|
44
|
+
* @protected
|
|
45
|
+
* @type {Record<string, ISigner>}
|
|
46
|
+
*/
|
|
47
|
+
protected _signers: Record<string, ISigner>;
|
|
33
48
|
/**
|
|
34
49
|
* A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
|
|
35
50
|
* all the accounts in this map, so developers are encouraged to map all accounts accessed through the
|
|
36
51
|
* {@link getAccount} and {@link getAccountByPath} methods.
|
|
37
52
|
*
|
|
38
53
|
* @protected
|
|
39
|
-
* @type {
|
|
54
|
+
* @type {Record<string, IWalletAccount>}
|
|
55
|
+
*/
|
|
56
|
+
protected _accounts: Record<string, IWalletAccount>;
|
|
57
|
+
/**
|
|
58
|
+
* The wallet configuration.
|
|
59
|
+
*
|
|
60
|
+
* @protected
|
|
61
|
+
* @type {WalletConfig}
|
|
62
|
+
*/
|
|
63
|
+
protected _config: WalletConfig;
|
|
64
|
+
/**
|
|
65
|
+
* The seed of the wallet.
|
|
66
|
+
*
|
|
67
|
+
* @type {Uint8Array | undefined}
|
|
68
|
+
*/
|
|
69
|
+
get seed(): Uint8Array | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Registers a signer under the given name.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} signerName - The signer name.
|
|
74
|
+
* @param {ISigner} signer - The signer.
|
|
75
|
+
* @returns {WalletManager} The wallet manager.
|
|
76
|
+
* @throws {Error} If `signerName` is an empty or blank string.
|
|
40
77
|
*/
|
|
41
|
-
|
|
78
|
+
addSigner(signerName: string, signer: ISigner): WalletManager;
|
|
42
79
|
/**
|
|
43
|
-
*
|
|
80
|
+
* Returns a signer. With no arguments, returns the default signer provided
|
|
81
|
+
* at construction. With a name, returns the signer registered under that
|
|
82
|
+
* name via {@link addSigner}.
|
|
44
83
|
*
|
|
45
|
-
* @
|
|
84
|
+
* @param {string} [signerName] - The signer name. Omit to get the default.
|
|
85
|
+
* @returns {ISigner} The signer.
|
|
86
|
+
* @throws {Error} If called with no arguments and no default signer was
|
|
87
|
+
* provided at construction, or if called with a name that is not registered.
|
|
46
88
|
*/
|
|
47
|
-
|
|
89
|
+
getSigner(signerName?: string): ISigner;
|
|
90
|
+
/**
|
|
91
|
+
* Returns a shallow copy of the map of signers registered via {@link addSigner}.
|
|
92
|
+
* The default signer is not included; use {@link getSigner} with no arguments
|
|
93
|
+
* to retrieve it.
|
|
94
|
+
*
|
|
95
|
+
* @returns {Record<string, ISigner>} A map of signer names to signers. Empty if no signers have been registered.
|
|
96
|
+
*/
|
|
97
|
+
getSigners(): Record<string, ISigner>;
|
|
48
98
|
/**
|
|
49
99
|
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
50
100
|
*
|
|
51
|
-
* @abstract
|
|
52
101
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
102
|
+
* @param {Object} [options] - Account options.
|
|
103
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
104
|
+
* @returns {Promise<IWalletAccount>} The account.
|
|
105
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
106
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
107
|
+
*/
|
|
108
|
+
abstract getAccount(
|
|
109
|
+
index?: number,
|
|
110
|
+
options?: {
|
|
111
|
+
signerName?: string;
|
|
112
|
+
},
|
|
113
|
+
): Promise<IWalletAccount>;
|
|
114
|
+
/**
|
|
115
|
+
* Returns the wallet account associated with a registered signer. For
|
|
116
|
+
* non-derivable signers (e.g., private-key signers), returns the signer's
|
|
117
|
+
* single account. For derivable signers, returns the wallet account at the
|
|
118
|
+
* signer's root, with no further derivation.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
53
121
|
* @returns {Promise<IWalletAccount>} The account.
|
|
122
|
+
* @throws {Error} If no signer exists with the given name.
|
|
54
123
|
*/
|
|
55
|
-
abstract getAccount(
|
|
124
|
+
abstract getAccount(signerName: string): Promise<IWalletAccount>;
|
|
56
125
|
/**
|
|
57
126
|
* Returns the wallet account at a specific [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) derivation path.
|
|
58
127
|
*
|
|
59
128
|
* @abstract
|
|
60
129
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
130
|
+
* @param {Object} [options] - Account options.
|
|
131
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
61
132
|
* @returns {Promise<IWalletAccount>} The account.
|
|
133
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
134
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
62
135
|
*/
|
|
63
|
-
abstract getAccountByPath(
|
|
136
|
+
abstract getAccountByPath(
|
|
137
|
+
path: string,
|
|
138
|
+
options?: {
|
|
139
|
+
signerName?: string;
|
|
140
|
+
},
|
|
141
|
+
): Promise<IWalletAccount>;
|
|
64
142
|
/**
|
|
65
143
|
* Returns the current fee rates.
|
|
66
144
|
*
|
|
@@ -69,11 +147,13 @@ export default abstract class WalletManager {
|
|
|
69
147
|
*/
|
|
70
148
|
abstract getFeeRates(): Promise<FeeRates>;
|
|
71
149
|
/**
|
|
72
|
-
* Disposes all
|
|
150
|
+
* Disposes all wallet accounts and signers, clearing secret material from memory.
|
|
73
151
|
*/
|
|
74
152
|
dispose(): void;
|
|
75
153
|
}
|
|
76
154
|
export type IWalletAccount = import("./wallet-account.js").IWalletAccount;
|
|
155
|
+
export type ISigner = import("./signer.js").ISigner;
|
|
156
|
+
export type SignerError = import("./errors.js").SignerError;
|
|
77
157
|
export type WalletConfig = {
|
|
78
158
|
/**
|
|
79
159
|
* - The maximum fee amount for transfer operations.
|