@tetherto/wdk-wallet 1.0.0-beta.25 → 1.0.0-beta.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet",
3
- "version": "1.0.0-beta.25",
3
+ "version": "1.0.0-beta.27",
4
4
  "description": "Base wallet and protocol classes for WDK (Wallet Development Kit) by Tether. For internal use only.",
5
5
  "homepage": "https://docs.wdk.tether.io/",
6
6
  "keywords": [
package/src/disposable.js CHANGED
@@ -27,7 +27,7 @@ export class IDisposable {
27
27
  }
28
28
 
29
29
  /**
30
- * Disposes the object along with all its data (cleaning up any sensitive field from memory).
30
+ * Disposes the object. Each implementation documents which secret material it clears from memory.
31
31
  */
32
32
  dispose () {
33
33
  throw new NotImplementedError('dispose()')
@@ -78,6 +78,15 @@ async function sleep (amount) {
78
78
 
79
79
  /** @interface */
80
80
  export class IWalletAccountReadOnly extends IWalletAccountReadOnlySimple {
81
+ /**
82
+ * The account's configuration.
83
+ *
84
+ * @type {Readonly<Record<string, unknown>>}
85
+ */
86
+ get config () {
87
+ throw new NotImplementedError('config')
88
+ }
89
+
81
90
  /**
82
91
  * Quotes the costs of a send transaction operation.
83
92
  *
@@ -139,10 +148,19 @@ export default class WalletAccountReadOnly {
139
148
  * Creates a new read-only wallet account.
140
149
  *
141
150
  * @param {string} [address] - The account's address.
151
+ * @param {Record<string, unknown>} [config] - The account's configuration (default: an empty object).
142
152
  */
143
- constructor (address) {
153
+ constructor (address, config = {}) {
144
154
  /** @private */
145
155
  this.__address = address
156
+
157
+ /**
158
+ * The account's configuration.
159
+ *
160
+ * @protected
161
+ * @type {Record<string, unknown>}
162
+ */
163
+ this._config = config
146
164
  }
147
165
 
148
166
  /**
@@ -155,6 +173,15 @@ export default class WalletAccountReadOnly {
155
173
  return this.__address
156
174
  }
157
175
 
176
+ /**
177
+ * The account's configuration.
178
+ *
179
+ * @type {Readonly<Record<string, unknown>>}
180
+ */
181
+ get config () {
182
+ return this._config
183
+ }
184
+
158
185
  /**
159
186
  * Returns the account's address.
160
187
  *
@@ -34,7 +34,7 @@ import { NotImplementedError } from './errors.js'
34
34
  /**
35
35
  * @typedef {Object} KeyPair
36
36
  * @property {Uint8Array} publicKey - The public key.
37
- * @property {Uint8Array | null} privateKey - The private key (null if the account has been disposed).
37
+ * @property {Uint8Array | null} privateKey - The private key (null if the signer exposes none or has been disposed).
38
38
  */
39
39
 
40
40
  /** @typedef {import('./disposable.js').IDisposable} IDisposable */
@@ -87,22 +87,24 @@ export default class WalletManager {
87
87
  this._defaultSigner = isSeed ? undefined : seedOrSigner
88
88
 
89
89
  /**
90
- * A map between signer names and signers added via {@link addSigner}.
90
+ * A map between signer names and signers added via {@link addSigner}. It has a null prototype, so names
91
+ * such as "constructor" or "__proto__" are treated as plain keys.
91
92
  *
92
93
  * @protected
93
94
  * @type {Record<string, TSigner>}
94
95
  */
95
- this._signers = {}
96
+ this._signers = Object.create(null)
96
97
 
97
98
  /**
98
99
  * A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
99
- * all the accounts in this map, so developers are encouraged to map all accounts accessed through the
100
- * {@link getAccount} and {@link getAccountByPath} methods.
100
+ * the accounts in this map that hold a private key, so developers are encouraged to map all accounts accessed
101
+ * through the {@link getAccount} and {@link getAccountByPath} methods. It has a null prototype, so lookups
102
+ * never resolve to inherited object properties.
101
103
  *
102
104
  * @protected
103
105
  * @type {Record<string, IWalletAccount>}
104
106
  */
105
- this._accounts = {}
107
+ this._accounts = Object.create(null)
106
108
 
107
109
  /**
108
110
  * The wallet configuration.
@@ -277,7 +279,9 @@ export default class WalletManager {
277
279
  }
278
280
 
279
281
  /**
280
- * Disposes all wallet accounts, clearing secret material from memory.
282
+ * Disposes the cached wallet accounts that hold a private key. An account created directly on a signer added via
283
+ * {@link addSigner} keeps its key. Signers supplied by the caller (as the default signer or via {@link addSigner})
284
+ * are never disposed, and the seed stored by this class is not cleared.
281
285
  */
282
286
  dispose () {
283
287
  if (this._disposed) return
@@ -288,7 +292,7 @@ export default class WalletManager {
288
292
  }
289
293
  }
290
294
 
291
- this._accounts = {}
295
+ this._accounts = Object.create(null)
292
296
 
293
297
  this._disposed = true
294
298
  }
@@ -7,7 +7,7 @@ export class IDisposable {
7
7
  */
8
8
  get disposed(): boolean;
9
9
  /**
10
- * Disposes the object along with all its data (cleaning up any sensitive field from memory).
10
+ * Disposes the object. Each implementation documents which secret material it clears from memory.
11
11
  */
12
12
  dispose(): void;
13
13
  }
@@ -11,6 +11,12 @@ export namespace FINALITY {
11
11
  }
12
12
  /** @interface */
13
13
  export interface IWalletAccountReadOnly extends IWalletAccountReadOnlySimple {
14
+ /**
15
+ * The account's configuration.
16
+ *
17
+ * @type {Readonly<Record<string, unknown>>}
18
+ */
19
+ get config(): Readonly<Record<string, unknown>>;
14
20
  /**
15
21
  * Quotes the costs of a send transaction operation.
16
22
  *
@@ -44,8 +50,9 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
44
50
  * Creates a new read-only wallet account.
45
51
  *
46
52
  * @param {string} [address] - The account's address.
53
+ * @param {Record<string, unknown>} [config] - The account's configuration (default: an empty object).
47
54
  */
48
- constructor(address?: string);
55
+ constructor(address?: string, config?: Record<string, unknown>);
49
56
  /**
50
57
  * The default poll cadence for {@link waitForTransaction}, in milliseconds,
51
58
  * applied when the caller doesn't provide an `interval`. Subclasses override
@@ -71,6 +78,19 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
71
78
  * @type {string | undefined}
72
79
  */
73
80
  protected get _address(): string | undefined;
81
+ /**
82
+ * The account's configuration.
83
+ *
84
+ * @protected
85
+ * @type {Record<string, unknown>}
86
+ */
87
+ protected _config: Record<string, unknown>;
88
+ /**
89
+ * The account's configuration.
90
+ *
91
+ * @type {Readonly<Record<string, unknown>>}
92
+ */
93
+ get config(): Readonly<Record<string, unknown>>;
74
94
  /**
75
95
  * Returns the account's address.
76
96
  *
@@ -107,7 +107,7 @@ export type KeyPair = {
107
107
  */
108
108
  publicKey: Uint8Array;
109
109
  /**
110
- * - The private key (null if the account has been disposed).
110
+ * - The private key (null if the signer exposes none or has been disposed).
111
111
  */
112
112
  privateKey: Uint8Array | null;
113
113
  };
@@ -46,7 +46,8 @@ export default abstract class WalletManager<TSigner extends ISigner = ISigner> i
46
46
  */
47
47
  protected _defaultSigner: TSigner | undefined;
48
48
  /**
49
- * A map between signer names and signers added via {@link addSigner}.
49
+ * A map between signer names and signers added via {@link addSigner}. It has a null prototype, so names
50
+ * such as "constructor" or "__proto__" are treated as plain keys.
50
51
  *
51
52
  * @protected
52
53
  * @type {Record<string, TSigner>}
@@ -54,8 +55,9 @@ export default abstract class WalletManager<TSigner extends ISigner = ISigner> i
54
55
  protected _signers: Record<string, TSigner>;
55
56
  /**
56
57
  * A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
57
- * all the accounts in this map, so developers are encouraged to map all accounts accessed through the
58
- * {@link getAccount} and {@link getAccountByPath} methods.
58
+ * the accounts in this map that hold a private key, so developers are encouraged to map all accounts accessed
59
+ * through the {@link getAccount} and {@link getAccountByPath} methods. It has a null prototype, so lookups
60
+ * never resolve to inherited object properties.
59
61
  *
60
62
  * @protected
61
63
  * @type {Record<string, IWalletAccount>}
@@ -163,7 +165,9 @@ export default abstract class WalletManager<TSigner extends ISigner = ISigner> i
163
165
  */
164
166
  abstract getFeeRates(): Promise<FeeRates>;
165
167
  /**
166
- * Disposes all wallet accounts, clearing secret material from memory.
168
+ * Disposes the cached wallet accounts that hold a private key. An account created directly on a signer added via
169
+ * {@link addSigner} keeps its key. Signers supplied by the caller (as the default signer or via {@link addSigner})
170
+ * are never disposed, and the seed stored by this class is not cleared.
167
171
  */
168
172
  dispose(): void;
169
173
  }