@tetherto/wdk-wallet-evm 1.0.0-beta.20 → 1.0.0-beta.21

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/README.md CHANGED
@@ -46,17 +46,14 @@ import {
46
46
 
47
47
  ```javascript
48
48
  import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
49
- import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
50
49
 
51
50
  // Use a BIP-39 seed phrase (replace with your own secure phrase)
52
51
  const seedPhrase =
53
52
  'test only example nut use this real life secret phrase must random'
54
53
 
55
- // Create a root signer from the seed phrase
56
- const root = new SeedSignerEvm(seedPhrase)
57
-
58
- // Create wallet manager with provider config (provider is required for chain ops)
59
- const wallet = new WalletManagerEvm(root, {
54
+ // Create the wallet manager straight from the seed (recommended: derivation
55
+ // paths are handled for you) with provider config (provider is required for chain ops)
56
+ const wallet = new WalletManagerEvm(seedPhrase, {
60
57
  // Option 1: Using RPC URL
61
58
  provider: 'https://sepolia.drpc.org', // any EVM RPC
62
59
  transferMaxFee: 100000000000000n, // Optional: max fee in wei (BigInt)
@@ -65,7 +62,7 @@ const wallet = new WalletManagerEvm(root, {
65
62
  // OR
66
63
 
67
64
  // Option 2: Using EIP-1193 provider (e.g., from browser wallet)
68
- const wallet2 = new WalletManagerEvm(root, {
65
+ const wallet2 = new WalletManagerEvm(seedPhrase, {
69
66
  provider: window.ethereum, // EIP-1193 provider
70
67
  transferMaxFee: 100000000000000n, // Optional
71
68
  })
@@ -90,13 +87,18 @@ const pkAccount = new WalletAccountEvm(pkSigner, {
90
87
  })
91
88
  ```
92
89
 
93
- ### Single Account (no manager): Seed + path
90
+ ### Single Account (no manager): Seed
94
91
 
95
92
  ```javascript
96
93
  import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
97
94
 
98
- // From a BIP-39 seed phrase (or seed bytes) and a BIP-44 derivation path
99
- const account = new WalletAccountEvm(mnemonic, "0'/0/0", {
95
+ // From a BIP-39 seed phrase (or seed bytes); derives the default account m/44'/60'/0'/0/0
96
+ const account = new WalletAccountEvm(mnemonic, {
97
+ provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
98
+ })
99
+
100
+ // Or pick a specific account path, relative to m/44'/60'
101
+ const account5 = new WalletAccountEvm(mnemonic, "0'/0/5", {
100
102
  provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
101
103
  })
102
104
  ```
@@ -105,10 +107,8 @@ const account = new WalletAccountEvm(mnemonic, "0'/0/0", {
105
107
 
106
108
  ```javascript
107
109
  import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
108
- import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
109
110
 
110
- const root = new SeedSignerEvm(mnemonic)
111
- const wallet = new WalletManagerEvm(root, {
111
+ const wallet = new WalletManagerEvm(mnemonic, {
112
112
  provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
113
113
  })
114
114
 
@@ -284,30 +284,33 @@ account.dispose()
284
284
  wallet.dispose()
285
285
  ```
286
286
 
287
- ## 🔐 Signers
287
+ ## 🔐 Signers (advanced usage)
288
288
 
289
- Signers provide the cryptographic primitives for accounts. There are two signer implementations:
289
+ Signers provide the cryptographic primitives for accounts. The recommended way to use this package is passing the seed straight to `WalletManagerEvm` or `WalletAccountEvm` (as in the sections above); constructing your own signer is considered advanced usage. There are two signer implementations:
290
290
 
291
- - **SeedSignerEvm (root + child)**: Derives accounts from a BIP-39 seed using the BIP-44 Ethereum path. Can act as a root (for `WalletManagerEvm`) and derive children (for `WalletAccountEvm`).
292
- - **PrivateKeySignerEvm (child only)**: Wraps a raw private key in a memory-safe buffer. Cannot derive. Use directly with `WalletAccountEvm`. Not supported by `WalletManagerEvm`.
291
+ - **SeedSignerEvm**: Holds one HD node from a BIP-39 seed at any absolute BIP-32 path (default: `"m/44'/60'"`) and derives child signers relative to its own path. Always derivable.
292
+ - **PrivateKeySignerEvm**: Wraps a raw private key in a memory-safe buffer. Cannot derive. Use directly with `WalletAccountEvm`. Not supported as `WalletManagerEvm`'s default signer (registrable by name via `addSigner`).
293
293
 
294
294
  Examples:
295
295
 
296
296
  ```javascript
297
- // Root + manager (seed)
298
- import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
299
- import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
300
- const root = new SeedSignerEvm(mnemonic)
301
- const wallet = new WalletManagerEvm(root, { provider: 'https://...' })
302
- const account0 = await wallet.getAccount(0)
297
+ import WalletManagerEvm, { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
298
+ import { SeedSignerEvm, PrivateKeySignerEvm } from '@tetherto/wdk-wallet-evm/signers'
303
299
 
304
- // Single account from a private key
305
- import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
306
- import { PrivateKeySignerEvm } from '@tetherto/wdk-wallet-evm/signers'
307
- const signer = new PrivateKeySignerEvm('0x0123...')
300
+ // Manager from your own signer. The default path "m/44'/60'" works out of the box:
301
+ // accounts derive below the signer's own path (getAccount(0) -> m/44'/60'/0'/0/0)
302
+ const wallet = new WalletManagerEvm(new SeedSignerEvm(mnemonic), { provider: 'https://...' })
303
+
304
+ // Account from your own signer: derive the account below the signer's default path
305
+ const signer = await new SeedSignerEvm(mnemonic).derive("0'/0/0")
308
306
  const account = new WalletAccountEvm(signer, { provider: 'https://...' })
307
+
308
+ // Single account from a private key
309
+ const pkAccount = new WalletAccountEvm(new PrivateKeySignerEvm('0x0123...'), { provider: 'https://...' })
309
310
  ```
310
311
 
312
+ Notes for advanced usage: a `SeedSignerEvm` sits exactly at the path you give it, and both `derive` and the manager's `getAccount`/`getAccountByPath` work relative to that path. If you rely on a non-default tree, pass your own absolute path explicitly (e.g. `new SeedSignerEvm(mnemonic, "m/44'/61'")`) so the resulting account positions are the ones you expect.
313
+
311
314
  ## Key Capabilities
312
315
 
313
316
  - **BIP-39 Seed Phrase Support**: Generate and validate mnemonic seed phrases
package/index.js CHANGED
@@ -42,12 +42,13 @@
42
42
  /** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransactionDetails} EvmTransactionDetails */
43
43
 
44
44
  /** @typedef {import('./src/wallet-account-evm.js').ApproveOptions} ApproveOptions */
45
+ /** @typedef {import('./src/wallet-account-evm.js').SignerOptions} SignerOptions */
45
46
  /** @typedef {import('./src/wallet-account-evm.js').EvmApproveOptions} EvmApproveOptions */
46
47
 
47
- /** @typedef {import('./src/utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
48
-
49
48
  export { default } from './src/wallet-manager-evm.js'
50
49
 
51
50
  export { default as WalletAccountReadOnlyEvm } from './src/wallet-account-read-only-evm.js'
52
51
 
53
52
  export { default as WalletAccountEvm } from './src/wallet-account-evm.js'
53
+
54
+ export { ISigner } from '@tetherto/wdk-wallet'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "EVM wallet module for WDK (Wallet Development Kit) by Tether.",
5
5
  "homepage": "https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/",
6
6
  "keywords": [
@@ -32,8 +32,8 @@
32
32
  "dependencies": {
33
33
  "@noble/hashes": "1.8.0",
34
34
  "@noble/secp256k1": "2.2.3",
35
+ "@tetherto/wdk-wallet": "1.0.0-beta.21",
35
36
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
36
- "@tetherto/wdk-wallet": "1.0.0-beta.17",
37
37
  "bare-node-runtime": "^1.5.0",
38
38
  "bip39": "3.1.0",
39
39
  "ethers": "6.17.0",
@@ -63,6 +63,7 @@
63
63
  },
64
64
  "./signers": {
65
65
  "types": "./types/src/signers/index.d.ts",
66
+ "bare": "./src/signers/bare.js",
66
67
  "default": "./src/signers/index.js"
67
68
  },
68
69
  "./package": {
@@ -76,6 +77,7 @@
76
77
  "standard": {
77
78
  "ignore": [
78
79
  "bare.js",
80
+ "src/signers/bare.js",
79
81
  "tests/**/*.js"
80
82
  ]
81
83
  }
@@ -0,0 +1,20 @@
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 'bare-node-runtime/global'
17
+
18
+ export * from './index.js' with { imports: 'bare-node-runtime/imports' }
19
+
20
+ export { default } from './index.js' with { imports: 'bare-node-runtime/imports' }
@@ -11,15 +11,8 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // src/signers/index.js
15
- /**
16
- * Barrel exports for EVM signers.
17
- *
18
- * - `SeedSignerEvm`: derives accounts from a BIP-39 seed (BIP-44 path).
19
- * - `PrivateKeySignerEvm`: memory-safe wrapper around a raw private key.
20
- */
21
-
22
- /** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
23
-
14
+ export { ISignerEvm } from './signer-evm.js'
24
15
  export { default, default as SeedSignerEvm } from './seed-signer-evm.js'
25
16
  export { default as PrivateKeySignerEvm } from './private-key-signer-evm.js'
17
+
18
+ /** @typedef {import('./signer-evm.js').TransactionLike} TransactionLike */
@@ -15,95 +15,104 @@
15
15
 
16
16
  import { BaseWallet } from 'ethers'
17
17
 
18
- import { InvalidSignerError } from '@tetherto/wdk-wallet'
18
+ import { UnsupportedOperationError } from '@tetherto/wdk-wallet'
19
19
 
20
20
  import MemorySafeSigningKey from '../memory-safe/signing-key.js'
21
- import { ISignerEvm } from './seed-signer-evm.js'
22
21
 
23
- /** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
22
+ /** @typedef {import('./signer-evm.js').ISignerEvm} ISignerEvm */
24
23
  /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
24
+ /** @typedef {import('@tetherto/wdk-wallet').ValueError} ValueError */
25
+ /** @typedef {import('ethers').TransactionLike} TransactionLike */
25
26
  /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
26
27
  /** @typedef {import('ethers').Authorization} Authorization */
27
28
  /** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
28
29
 
29
30
  /**
30
- * @extends {ISignerEvm}
31
31
  * Signer that wraps a raw private key in a memory-safe buffer, exposing a minimal
32
32
  * interface for signing messages, transactions and typed data. This signer does
33
33
  * not support derivation and always represents a single account.
34
+ *
35
+ * @implements {ISignerEvm}
34
36
  */
35
- export default class PrivateKeySignerEvm extends ISignerEvm {
37
+ export default class PrivateKeySignerEvm {
36
38
  /**
37
39
  * Create a signer from a raw private key.
38
40
  *
39
- * @param {string|Uint8Array} privateKey - Hex string (with/without 0x) or raw key bytes.
41
+ * The supplied key is copied: the signer keeps its own internal copy alive until
42
+ * {@link dispose} zeroes it, and never wipes the supplied key, whose disposal
43
+ * remains the caller's responsibility.
44
+ *
45
+ * @param {string | Uint8Array} privateKey - The private key's hex string (with or without 0x) or byte sequence.
40
46
  */
41
47
  constructor (privateKey) {
42
- super()
43
-
44
- // Expect a Uint8Array buffer; accept hex string as convenience
45
- let privateKeyBuffer = privateKey
46
- if (typeof privateKey === 'string') {
47
- const hex = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey
48
- privateKeyBuffer = new Uint8Array(Buffer.from(hex, 'hex'))
49
- }
48
+ privateKey = typeof privateKey === 'string'
49
+ ? Buffer.from(privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey, 'hex')
50
+ : Buffer.from(privateKey)
50
51
 
51
52
  /** @private */
52
- this._signingKey = new MemorySafeSigningKey(privateKeyBuffer)
53
+ this._signingKey = new MemorySafeSigningKey(privateKey)
54
+
53
55
  /** @private */
54
- this._wallet = new BaseWallet(this._signingKey, null)
56
+ this._wallet = new BaseWallet(this._signingKey)
57
+
55
58
  /** @private */
56
59
  this._address = this._wallet.address
57
- /** @private */
58
- this._path = undefined
59
60
  }
60
61
 
61
62
  /**
62
- * Whether this signer can derive child signers. Always false: a private-key signer is a
63
- * single standalone account and is bound directly to a wallet account.
64
- * @type {boolean}
65
- */
66
- get isDerivable () { return false }
67
-
68
- /**
69
- * The account index. Always undefined for private key signers: a raw key has no
70
- * BIP-44 position, so reporting an index would be misleading.
71
- * @type {number|undefined}
63
+ * Whether this signer can derive child signers.
64
+ *
65
+ * @type {false}
72
66
  */
73
- get index () { return undefined }
67
+ get isDerivable () {
68
+ return false
69
+ }
74
70
 
75
71
  /**
76
- * The derivation path. Always undefined for private key signers.
77
- * @type {string|undefined}
72
+ * The BIP 0044 derivation path.
73
+ *
74
+ * @type {string | null}
78
75
  */
79
- get path () { return this._path }
76
+ get path () { return null }
80
77
 
81
78
  /**
82
79
  * The account's address.
80
+ *
81
+ * @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
82
+ * release: not all signers (e.g. hardware signers) can expose the address synchronously.
83
83
  * @type {string}
84
84
  */
85
85
  get address () { return this._address }
86
+
86
87
  /**
87
88
  * The account's key pair (private and public key buffers).
89
+ *
88
90
  * @type {KeyPair}
89
91
  */
90
92
  get keyPair () {
91
93
  return {
92
- privateKey: this._signingKey ? this._signingKey.privateKeyBuffer : null,
93
- publicKey: this._signingKey ? this._signingKey.publicKeyBuffer : null
94
+ privateKey: this._signingKey.privateKeyBuffer ?? null,
95
+ publicKey: this._signingKey.publicKeyBuffer
94
96
  }
95
97
  }
96
98
 
97
99
  /**
98
- * PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
99
- * @returns {Promise<never>}
100
- * @throws {InvalidSignerError} Always — private-key signers do not support derivation.
100
+ * Derive a child signer using a relative path (e.g., "0'/0/0").
101
+ *
102
+ * @param {string} path - The relative derivation path.
103
+ * @returns {Promise<never>} The derived signer.
104
+ * @throws {UnsupportedOperationError} If the signer does not support account derivation.
105
+ * @throws {ValueError} If the path is not valid.
101
106
  */
102
- async derive () {
103
- throw new InvalidSignerError('PrivateKeySignerEvm does not support derivation.')
107
+ async derive (path) {
108
+ throw new UnsupportedOperationError('derive(path)')
104
109
  }
105
110
 
106
- /** @returns {Promise<string>} */
111
+ /**
112
+ * Returns the account's address.
113
+ *
114
+ * @returns {Promise<string>} The account's address.
115
+ */
107
116
  async getAddress () {
108
117
  return this._address
109
118
  }
@@ -119,13 +128,13 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
119
128
  }
120
129
 
121
130
  /**
122
- * Signs a transaction and returns the serialized signed transaction hex.
131
+ * Signs a transaction.
123
132
  *
124
- * @param {UnsignedEvmTransaction} unsignedTx - The unsigned transaction object.
125
- * @returns {Promise<string>}
133
+ * @param {TransactionLike} tx - The transaction to sign.
134
+ * @returns {Promise<string>} The signed transaction as a hex string.
126
135
  */
127
- async signTransaction (unsignedTx) {
128
- return this._wallet.signTransaction(unsignedTx)
136
+ async signTransaction (tx) {
137
+ return this._wallet.signTransaction(tx)
129
138
  }
130
139
 
131
140
  /**
@@ -139,18 +148,19 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
139
148
  }
140
149
 
141
150
  /**
142
- * Sign an ERC-7702 authorization tuple.
143
- * @param {AuthorizationRequest} auth
144
- * @returns {Promise<Authorization>}
151
+ * Signs an ERC-7702 authorization tuple.
152
+ *
153
+ * @param {AuthorizationRequest} auth - The authorization request.
154
+ * @returns {Promise<Authorization>} The signed authorization.
145
155
  */
146
156
  async signAuthorization (auth) {
147
157
  return this._wallet.authorizeSync(auth)
148
158
  }
149
159
 
150
- /** Dispose secrets from memory. */
160
+ /**
161
+ * Disposes the signer, securely erasing its internal copy of the private key from memory.
162
+ */
151
163
  dispose () {
152
- if (this._signingKey) this._signingKey.dispose()
153
- this._signingKey = undefined
154
- this._wallet = undefined
164
+ this._signingKey.dispose()
155
165
  }
156
166
  }