Skip to content

Commit beb66fe

Browse files
committed
fix: address review comments on PR #95
- export ISignerEvm only from src/signers/index.js - drop redundant @extends tag on ISignerEvm - path/index return null on PrivateKeySignerEvm (null convention, aligned in ISignerEvm, WalletAccountEvm and wdk-wallet's IWalletAccount) - unify path/index descriptions across signer docs - reorder test cases so both signer suites follow the same order Deferred for the ongoing interface discussion: - moving sign() to ISigner: #95 (comment) - derive() doc spec alignment: #95 (comment)
1 parent bdcc93c commit beb66fe

12 files changed

Lines changed: 61 additions & 72 deletions

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ export { default as WalletAccountReadOnlyEvm } from './src/wallet-account-read-o
4040
export { default as WalletAccountEvm } from './src/wallet-account-evm.js'
4141

4242
export { ISigner } from '@tetherto/wdk-wallet'
43-
44-
export { ISignerEvm } from './src/signers/signer-evm.js'

src/signers/private-key-signer-evm.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export default class PrivateKeySignerEvm {
5353
this._wallet = new BaseWallet(this._signingKey, null)
5454
/** @private */
5555
this._address = this._wallet.address
56-
/** @private */
57-
this._path = undefined
5856
}
5957

6058
/**
@@ -66,19 +64,18 @@ export default class PrivateKeySignerEvm {
6664
get isDerivable () { return false }
6765

6866
/**
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.
67+
* The last component index of the BIP 0044 derivation path.
7168
*
72-
* @type {number|undefined}
69+
* @type {number | null}
7370
*/
74-
get index () { return undefined }
71+
get index () { return null }
7572

7673
/**
77-
* The derivation path. Always undefined for private key signers.
74+
* The BIP 0044 derivation path.
7875
*
79-
* @type {string|undefined}
76+
* @type {string | null}
8077
*/
81-
get path () { return this._path }
78+
get path () { return null }
8279

8380
/**
8481
* The account's address.

src/signers/seed-signer-evm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class SeedSignerEvm {
9999
}
100100

101101
/**
102-
* The last component index of the derivation path.
102+
* The last component index of the BIP 0044 derivation path.
103103
*
104104
* @type {number}
105105
*/
@@ -108,7 +108,7 @@ export default class SeedSignerEvm {
108108
}
109109

110110
/**
111-
* The full derivation path of this signer's account.
111+
* The BIP 0044 derivation path.
112112
*
113113
* @type {string}
114114
*/

src/signers/signer-evm.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ import { ISigner, NotImplementedError } from '@tetherto/wdk-wallet'
2323
/**
2424
* Interface for EVM signers, extending the base `ISigner` from `@tetherto/wdk-wallet`.
2525
*
26-
* @extends {ISigner}
2726
* @interface
2827
*/
2928
export class ISignerEvm extends ISigner {
3029
/**
31-
* The last component index for the derivation path of this signer, when applicable.
30+
* The last component index of the BIP 0044 derivation path.
3231
*
33-
* @type {number | undefined}
32+
* @type {number | null}
3433
*/
3534
get index () {
3635
throw new NotImplementedError('index')
3736
}
3837

3938
/**
40-
* The full derivation path of this signer's account, when applicable.
39+
* The BIP 0044 derivation path.
4140
*
42-
* @type {string | undefined}
41+
* @type {string | null}
4342
*/
4443
get path () {
4544
throw new NotImplementedError('path')

src/wallet-account-evm.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
8989
}
9090

9191
/**
92-
* The derivation path's index of this account, or undefined if the account's
92+
* The derivation path's index of this account, or null if the account's
9393
* signer is not bound to a BIP-44 position (e.g. private-key signers).
9494
*
95-
* @type {number | undefined}
95+
* @type {number | null}
9696
*/
9797
get index () {
9898
return this._signer.index
9999
}
100100

101101
/**
102102
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
103-
* or undefined if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
103+
* or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
104104
*
105-
* @type {string | undefined}
105+
* @type {string | null}
106106
*/
107107
get path () {
108108
return this._signer.path

tests/signers/private-key-signer-evm.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ describe('PrivateKeySignerEvm', () => {
6060

6161
expect(signer.isDerivable).toBe(false)
6262
expect(signer.address).toBe(EXPECTED_ADDRESS)
63-
expect(signer.path).toBeUndefined()
64-
expect(signer.index).toBeUndefined()
63+
expect(signer.path).toBeNull()
64+
expect(signer.index).toBeNull()
6565

6666
signer.dispose()
6767
})

tests/signers/seed-signer-evm.test.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ const EXPECTED_TYPED_DATA_SIGNATURE = '0xd5d54d9a7fe501ab5dc1532a443a4f70bc8b6ad
5959

6060
describe('SeedSignerEvm', () => {
6161
describe('constructor', () => {
62-
test('should throw if the seed phrase is invalid', () => {
63-
expect(() => { new SeedSignerEvm('invalid seed phrase') }) // eslint-disable-line no-new
64-
.toThrow('The seed phrase is invalid.')
65-
})
66-
67-
test('should throw if both seed and root are provided', async () => {
68-
const root = new SeedSignerEvm(VALID_SEED_PHRASE)
69-
const child = await root.derive("0'/0/0")
70-
expect(() => { new SeedSignerEvm(VALID_SEED_PHRASE, { root: child }) }) // eslint-disable-line no-new
71-
.toThrow('Provide either a seed or a root, not both.')
72-
child.dispose()
73-
root.dispose()
74-
})
75-
7662
test('should create a signer with the account at index 0 by default', () => {
7763
const signer = new SeedSignerEvm(VALID_SEED_PHRASE)
7864

@@ -99,6 +85,20 @@ describe('SeedSignerEvm', () => {
9985

10086
signer.dispose()
10187
})
88+
89+
test('should throw if the seed phrase is invalid', () => {
90+
expect(() => { new SeedSignerEvm('invalid seed phrase') }) // eslint-disable-line no-new
91+
.toThrow('The seed phrase is invalid.')
92+
})
93+
94+
test('should throw if both seed and root are provided', async () => {
95+
const root = new SeedSignerEvm(VALID_SEED_PHRASE)
96+
const child = await root.derive("0'/0/0")
97+
expect(() => { new SeedSignerEvm(VALID_SEED_PHRASE, { root: child }) }) // eslint-disable-line no-new
98+
.toThrow('Provide either a seed or a root, not both.')
99+
child.dispose()
100+
root.dispose()
101+
})
102102
})
103103

104104
describe('keyPair', () => {
@@ -113,15 +113,6 @@ describe('SeedSignerEvm', () => {
113113
})
114114

115115
describe('derive', () => {
116-
test('should throw if the path is invalid', async () => {
117-
const signer = new SeedSignerEvm(VALID_SEED_PHRASE)
118-
119-
await expect(signer.derive("a'/b/c"))
120-
.rejects.toThrow('invalid path component')
121-
122-
signer.dispose()
123-
})
124-
125116
test('should derive a child signer with the correct address and path', async () => {
126117
const root = new SeedSignerEvm(VALID_SEED_PHRASE)
127118
const child = await root.derive("0'/0/0")
@@ -137,6 +128,15 @@ describe('SeedSignerEvm', () => {
137128
root.dispose()
138129
})
139130

131+
test('should throw if the path is invalid', async () => {
132+
const signer = new SeedSignerEvm(VALID_SEED_PHRASE)
133+
134+
await expect(signer.derive("a'/b/c"))
135+
.rejects.toThrow('invalid path component')
136+
137+
signer.dispose()
138+
})
139+
140140
test('should throw when deriving from a disposed signer', async () => {
141141
const root = new SeedSignerEvm(VALID_SEED_PHRASE)
142142
root.dispose()

types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export { default } from "./src/wallet-manager-evm.js";
22
export { default as WalletAccountReadOnlyEvm } from "./src/wallet-account-read-only-evm.js";
33
export { default as WalletAccountEvm } from "./src/wallet-account-evm.js";
44
export { ISigner } from "@tetherto/wdk-wallet";
5-
export { ISignerEvm } from "./src/signers/signer-evm.js";
65
export type TypedDataDomain = import("ethers").TypedDataDomain;
76
export type TypedDataField = import("ethers").TypedDataField;
87
export type AuthorizationRequest = import("ethers").AuthorizationRequest;

types/src/signers/private-key-signer-evm.d.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export default class PrivateKeySignerEvm implements ISignerEvm {
1818
private _wallet;
1919
/** @private */
2020
private _address;
21-
/** @private */
22-
private _path;
2321
/**
2422
* Whether this signer can derive child signers. Always false: a private-key signer is a
2523
* single standalone account and is bound directly to a wallet account.
@@ -28,18 +26,17 @@ export default class PrivateKeySignerEvm implements ISignerEvm {
2826
*/
2927
get isDerivable(): boolean;
3028
/**
31-
* The account index. Always undefined for private key signers: a raw key has no
32-
* BIP-44 position, so reporting an index would be misleading.
29+
* The last component index of the BIP 0044 derivation path.
3330
*
34-
* @type {number|undefined}
31+
* @type {number | null}
3532
*/
36-
get index(): number | undefined;
33+
get index(): number | null;
3734
/**
38-
* The derivation path. Always undefined for private key signers.
35+
* The BIP 0044 derivation path.
3936
*
40-
* @type {string|undefined}
37+
* @type {string | null}
4138
*/
42-
get path(): string | undefined;
39+
get path(): string | null;
4340
/**
4441
* The account's address.
4542
*

types/src/signers/seed-signer-evm.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ export default class SeedSignerEvm implements ISignerEvm {
3232
*/
3333
get isDerivable(): boolean;
3434
/**
35-
* The last component index of the derivation path.
35+
* The last component index of the BIP 0044 derivation path.
3636
*
3737
* @type {number}
3838
*/
3939
get index(): number;
4040
/**
41-
* The full derivation path of this signer's account.
41+
* The BIP 0044 derivation path.
4242
*
4343
* @type {string}
4444
*/

0 commit comments

Comments
 (0)