@xyo-network/wallet 5.1.21 → 5.1.23
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 +16 -13
- package/dist/browser/spec/AddressRoundTrip.spec.d.ts +0 -2
- package/dist/browser/spec/AddressRoundTrip.spec.d.ts.map +0 -1
- package/dist/browser/spec/HDWallet/HDWallet.browser.spec.d.ts +0 -2
- package/dist/browser/spec/HDWallet/HDWallet.browser.spec.d.ts.map +0 -1
- package/dist/browser/spec/HDWallet/HDWallet.node.spec.d.ts +0 -2
- package/dist/browser/spec/HDWallet/HDWallet.node.spec.d.ts.map +0 -1
- package/dist/browser/spec/HDWallet/HDWallet.spec.d.ts +0 -8
- package/dist/browser/spec/HDWallet/HDWallet.spec.d.ts.map +0 -1
- package/dist/neutral/spec/AddressRoundTrip.spec.d.ts +0 -2
- package/dist/neutral/spec/AddressRoundTrip.spec.d.ts.map +0 -1
- package/dist/neutral/spec/HDWallet/HDWallet.browser.spec.d.ts +0 -2
- package/dist/neutral/spec/HDWallet/HDWallet.browser.spec.d.ts.map +0 -1
- package/dist/neutral/spec/HDWallet/HDWallet.node.spec.d.ts +0 -2
- package/dist/neutral/spec/HDWallet/HDWallet.node.spec.d.ts.map +0 -1
- package/dist/neutral/spec/HDWallet/HDWallet.spec.d.ts +0 -8
- package/dist/neutral/spec/HDWallet/HDWallet.spec.d.ts.map +0 -1
- package/dist/node/spec/AddressRoundTrip.spec.d.ts +0 -2
- package/dist/node/spec/AddressRoundTrip.spec.d.ts.map +0 -1
- package/dist/node/spec/HDWallet/HDWallet.browser.spec.d.ts +0 -2
- package/dist/node/spec/HDWallet/HDWallet.browser.spec.d.ts.map +0 -1
- package/dist/node/spec/HDWallet/HDWallet.node.spec.d.ts +0 -2
- package/dist/node/spec/HDWallet/HDWallet.node.spec.d.ts.map +0 -1
- package/dist/node/spec/HDWallet/HDWallet.spec.d.ts +0 -8
- package/dist/node/spec/HDWallet/HDWallet.spec.d.ts.map +0 -1
- package/src/spec/AddressRoundTrip.spec.ts +0 -17
- package/src/spec/HDWallet/HDWallet.browser.spec.ts +0 -20
- package/src/spec/HDWallet/HDWallet.node.spec.ts +0 -11
- package/src/spec/HDWallet/HDWallet.spec.ts +0 -228
- package/src/spec/HDWallet/__snapshots__/HDWallet.node.spec.ts.snap +0 -841
- package/src/spec/HDWallet/__snapshots__/HDWallet.spec.ts.snap +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/wallet",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.23",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,27 +30,30 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src"
|
|
33
|
+
"src",
|
|
34
|
+
"!**/*.bench.*",
|
|
35
|
+
"!**/*.spec.*",
|
|
36
|
+
"!**/*.test.*"
|
|
34
37
|
],
|
|
35
38
|
"dependencies": {
|
|
36
39
|
"@scure/bip39": "~2.0.1",
|
|
37
|
-
"@xylabs/arraybuffer": "~5.0.
|
|
38
|
-
"@xylabs/assert": "~5.0.
|
|
39
|
-
"@xylabs/base": "~5.0.
|
|
40
|
-
"@xylabs/hex": "~5.0.
|
|
41
|
-
"@xylabs/static-implements": "~5.0.
|
|
42
|
-
"@xyo-network/account": "~5.1.
|
|
43
|
-
"@xyo-network/account-model": "~5.1.
|
|
44
|
-
"@xyo-network/key-model": "~5.1.
|
|
45
|
-
"@xyo-network/wallet-model": "~5.1.
|
|
40
|
+
"@xylabs/arraybuffer": "~5.0.33",
|
|
41
|
+
"@xylabs/assert": "~5.0.33",
|
|
42
|
+
"@xylabs/base": "~5.0.33",
|
|
43
|
+
"@xylabs/hex": "~5.0.33",
|
|
44
|
+
"@xylabs/static-implements": "~5.0.33",
|
|
45
|
+
"@xyo-network/account": "~5.1.23",
|
|
46
|
+
"@xyo-network/account-model": "~5.1.23",
|
|
47
|
+
"@xyo-network/key-model": "~5.1.23",
|
|
48
|
+
"@xyo-network/wallet-model": "~5.1.23",
|
|
46
49
|
"ethers": "~6.15.0"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
50
53
|
"@xylabs/tsconfig": "~7.2.8",
|
|
51
|
-
"@xylabs/vitest-matchers": "~5.0.
|
|
54
|
+
"@xylabs/vitest-matchers": "~5.0.33",
|
|
52
55
|
"typescript": "~5.9.3",
|
|
53
|
-
"vitest": "~4.0.
|
|
56
|
+
"vitest": "~4.0.9"
|
|
54
57
|
},
|
|
55
58
|
"publishConfig": {
|
|
56
59
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AddressRoundTrip.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/AddressRoundTrip.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.browser.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.browser.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.node.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.node.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { WalletStatic } from '@xyo-network/wallet-model';
|
|
2
|
-
/**
|
|
3
|
-
* Generates tests for a wallet type
|
|
4
|
-
* @param title The title of the test suite
|
|
5
|
-
* @param HDWallet The wallet type to test
|
|
6
|
-
*/
|
|
7
|
-
export declare const generateHDWalletTests: (title: string, HDWallet: WalletStatic) => void;
|
|
8
|
-
//# sourceMappingURL=HDWallet.spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.spec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,2BAA2B,CAAA;AA2F7E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,UAAU,YAAY,SAwF1E,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AddressRoundTrip.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/AddressRoundTrip.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.browser.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.browser.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.node.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.node.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { WalletStatic } from '@xyo-network/wallet-model';
|
|
2
|
-
/**
|
|
3
|
-
* Generates tests for a wallet type
|
|
4
|
-
* @param title The title of the test suite
|
|
5
|
-
* @param HDWallet The wallet type to test
|
|
6
|
-
*/
|
|
7
|
-
export declare const generateHDWalletTests: (title: string, HDWallet: WalletStatic) => void;
|
|
8
|
-
//# sourceMappingURL=HDWallet.spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.spec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,2BAA2B,CAAA;AA2F7E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,UAAU,YAAY,SAwF1E,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AddressRoundTrip.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/AddressRoundTrip.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.browser.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.browser.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.node.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.node.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { WalletStatic } from '@xyo-network/wallet-model';
|
|
2
|
-
/**
|
|
3
|
-
* Generates tests for a wallet type
|
|
4
|
-
* @param title The title of the test suite
|
|
5
|
-
* @param HDWallet The wallet type to test
|
|
6
|
-
*/
|
|
7
|
-
export declare const generateHDWalletTests: (title: string, HDWallet: WalletStatic) => void;
|
|
8
|
-
//# sourceMappingURL=HDWallet.spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HDWallet.spec.d.ts","sourceRoot":"","sources":["../../../../src/spec/HDWallet/HDWallet.spec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,2BAA2B,CAAA;AA2F7E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,UAAU,YAAY,SAwF1E,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Account } from '@xyo-network/account'
|
|
2
|
-
import {
|
|
3
|
-
describe, expect, it,
|
|
4
|
-
} from 'vitest'
|
|
5
|
-
|
|
6
|
-
import { HDWallet } from '../HDWallet.ts'
|
|
7
|
-
|
|
8
|
-
describe('Address', () => {
|
|
9
|
-
it('should round trip from BigInt', async () => {
|
|
10
|
-
for (let index = 0; index < 100; index++) {
|
|
11
|
-
const foo = await HDWallet.random()
|
|
12
|
-
const privateKey = BigInt(foo.privateKey)
|
|
13
|
-
const sharedAccount = await Account.fromPrivateKey(privateKey)
|
|
14
|
-
expect(sharedAccount).toBeDefined()
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe, expect, it,
|
|
3
|
-
} from 'vitest'
|
|
4
|
-
|
|
5
|
-
// import { HDWallet } from '../../HDWallet'
|
|
6
|
-
// import { generateHDWalletTests } from './HDWallet.spec'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @group jsdom
|
|
10
|
-
*/
|
|
11
|
-
/* describe.skip('Node Wallet Test', () => {
|
|
12
|
-
generateHDWalletTests('HDWallet: Browser', HDWallet)
|
|
13
|
-
})
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
describe('Node Wallet Test - Commented Out', () => {
|
|
17
|
-
it('Stub', () => {
|
|
18
|
-
expect(true).toBe(true)
|
|
19
|
-
})
|
|
20
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { describe } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { HDWallet } from '../../HDWallet.ts'
|
|
4
|
-
import { generateHDWalletTests } from './HDWallet.spec.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @group nodejs
|
|
8
|
-
*/
|
|
9
|
-
describe('Node Wallet Test', () => {
|
|
10
|
-
generateHDWalletTests('HDWallet: Node', HDWallet)
|
|
11
|
-
})
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import type { Address, Hex } from '@xylabs/hex'
|
|
2
|
-
import { isAddress } from '@xylabs/hex'
|
|
3
|
-
import { matchers } from '@xylabs/vitest-matchers'
|
|
4
|
-
import type { WalletInstance, WalletStatic } from '@xyo-network/wallet-model'
|
|
5
|
-
import {
|
|
6
|
-
defaultPath, Mnemonic, SigningKey,
|
|
7
|
-
} from 'ethers'
|
|
8
|
-
import {
|
|
9
|
-
describe, expect, it,
|
|
10
|
-
test,
|
|
11
|
-
} from 'vitest'
|
|
12
|
-
|
|
13
|
-
expect.extend(matchers)
|
|
14
|
-
|
|
15
|
-
import { HDWallet } from '../../HDWallet.ts'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The wallet types that can be tested
|
|
19
|
-
*/
|
|
20
|
-
type Wallet = HDWallet | WalletInstance
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The serializable information of a wallet
|
|
24
|
-
*/
|
|
25
|
-
interface WalletSnapshot {
|
|
26
|
-
address: Address
|
|
27
|
-
path: string | null
|
|
28
|
-
privateKey: Hex
|
|
29
|
-
publicKey: Hex
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Converts a compressed public key to an uncompressed public key
|
|
34
|
-
* @param compressed The compressed public key
|
|
35
|
-
* @returns The uncompressed public key
|
|
36
|
-
*/
|
|
37
|
-
const toUncompressedPublicKey = (compressed: string): string => SigningKey.computePublicKey(compressed, false).toLowerCase().replace('0x04', '')
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Standardizes the representation of a hex string
|
|
41
|
-
* @param unformatted The unformatted hex string
|
|
42
|
-
* @returns The formatted hex string
|
|
43
|
-
*/
|
|
44
|
-
const formatHexString = (unformatted: string): string => unformatted.toLowerCase().replace('0x', '')
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Serializes a wallet to its snapshot representation
|
|
48
|
-
* @param wallet The wallet to snapshot
|
|
49
|
-
* @returns The snapshot representation of the wallet
|
|
50
|
-
*/
|
|
51
|
-
const toWalletSnapshot = (wallet: Wallet): WalletSnapshot => {
|
|
52
|
-
const {
|
|
53
|
-
address, path, privateKey, publicKey,
|
|
54
|
-
} = wallet as WalletInstance
|
|
55
|
-
return {
|
|
56
|
-
address, path, privateKey, publicKey,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Snapshots the instances of two wallets to ensure repeatability
|
|
62
|
-
* of creation from the same source and prevent unintentional changes
|
|
63
|
-
* to the wallet protocol
|
|
64
|
-
* @param walletA The first wallet to snapshot
|
|
65
|
-
* @param walletB The second wallet to snapshot
|
|
66
|
-
*/
|
|
67
|
-
const snapshotWalletInstances = (walletA: Wallet, walletB: Wallet) => {
|
|
68
|
-
expect(toWalletSnapshot(walletA)).toMatchSnapshot()
|
|
69
|
-
expect([toWalletSnapshot(walletA), toWalletSnapshot(walletB)]).toMatchSnapshot()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Compares two wallets to ensure their public/private keys are equal
|
|
74
|
-
* @param sutA The first wallet to compare
|
|
75
|
-
* @param sutB The second wallet to compare
|
|
76
|
-
*/
|
|
77
|
-
const expectWalletsEqual = (sutA: WalletInstance, sutB: Wallet) => {
|
|
78
|
-
expect(sutA.address).toEqual(formatHexString(sutB.address))
|
|
79
|
-
expect(sutA.privateKey).toEqual(sutB.privateKey)
|
|
80
|
-
expect(sutA.private?.hex).toEqual(formatHexString(sutB.privateKey))
|
|
81
|
-
expect(sutA.publicKey).toEqual(sutB.publicKey)
|
|
82
|
-
expect(sutA.public?.hex).toEqual(toUncompressedPublicKey(sutB.publicKey))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Compares two wallets to ensure their public/private keys and paths are equal
|
|
87
|
-
* @param sutA The first wallet to compare
|
|
88
|
-
* @param sutB The second wallet to compare
|
|
89
|
-
*/
|
|
90
|
-
const expectWalletsAndPathsEqual = (sutA: WalletInstance, sutB: Wallet) => {
|
|
91
|
-
expectWalletsEqual(sutA, sutB)
|
|
92
|
-
expect(sutA.path).toEqual(sutB.path)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Generates tests for a wallet type
|
|
97
|
-
* @param title The title of the test suite
|
|
98
|
-
* @param HDWallet The wallet type to test
|
|
99
|
-
*/
|
|
100
|
-
export const generateHDWalletTests = (title: string, HDWallet: WalletStatic) => {
|
|
101
|
-
describe(title, () => {
|
|
102
|
-
const phrase = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
|
|
103
|
-
const paths = ['0/4', "44'/0'/0'", "44'/60'/0'/0/0", "44'/60'/0'/0/1", "49'/0'/0'", "84'/0'/0'", "84'/0'/0'/0"]
|
|
104
|
-
|
|
105
|
-
describe('constructor', () => {
|
|
106
|
-
it('can be created from mnemonic', async () => {
|
|
107
|
-
const sut = await HDWallet.fromPhrase(phrase)
|
|
108
|
-
console.log('address', sut.address)
|
|
109
|
-
console.log('privateKeyX', sut.privateKey)
|
|
110
|
-
const mnemonic = Mnemonic.fromPhrase(phrase)
|
|
111
|
-
console.log('mnemonic.entropy', mnemonic.entropy)
|
|
112
|
-
expect(isAddress(sut.address)).toBe(true)
|
|
113
|
-
expect(sut).toBeDefined()
|
|
114
|
-
})
|
|
115
|
-
it.each(paths)('works repeatably & interoperably with Ethers', async (path: string) => {
|
|
116
|
-
const sutA = await HDWallet.fromPhrase(phrase)
|
|
117
|
-
const sutB = await HDWallet.fromMnemonic(Mnemonic.fromPhrase(phrase))
|
|
118
|
-
expectWalletsAndPathsEqual(sutA, sutB)
|
|
119
|
-
snapshotWalletInstances(sutA, sutB)
|
|
120
|
-
const accountA = await sutA.derivePath(path)
|
|
121
|
-
const accountB = await sutB.derivePath(path)
|
|
122
|
-
expectWalletsAndPathsEqual(accountA, accountB)
|
|
123
|
-
snapshotWalletInstances(accountA, accountB)
|
|
124
|
-
})
|
|
125
|
-
})
|
|
126
|
-
describe('derivePath', () => {
|
|
127
|
-
it.each(paths)('works repeatably & interoperably from phrase & extended key', async (path: string) => {
|
|
128
|
-
const sutA = await HDWallet.fromPhrase(phrase)
|
|
129
|
-
const sutB = await HDWallet.fromExtendedKey(sutA.extendedKey)
|
|
130
|
-
expectWalletsEqual(sutA, sutB)
|
|
131
|
-
expect(sutA.path).not.toBeNull()
|
|
132
|
-
expect(sutB.path).not.toBeNull()
|
|
133
|
-
snapshotWalletInstances(sutA, sutB)
|
|
134
|
-
const accountA = await sutA.derivePath?.(path)
|
|
135
|
-
const accountB = await sutB.derivePath?.(path)
|
|
136
|
-
expectWalletsEqual(accountA, accountB)
|
|
137
|
-
expect(accountA.path).not.toBeNull()
|
|
138
|
-
expect(accountB.path).not.toBeNull()
|
|
139
|
-
snapshotWalletInstances(accountA, accountB)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('works when paths provided incrementally', async () => {
|
|
143
|
-
const parentRelativePath = "44'/60'/0'"
|
|
144
|
-
const childRelativePath = '0/1'
|
|
145
|
-
const sutA = await HDWallet.fromPhrase(phrase)
|
|
146
|
-
const sutB = await HDWallet.fromPhrase(phrase)
|
|
147
|
-
expectWalletsAndPathsEqual(sutA, sutB)
|
|
148
|
-
snapshotWalletInstances(sutA, sutB)
|
|
149
|
-
const accountA = await (await sutA.derivePath(parentRelativePath)).derivePath?.(childRelativePath)
|
|
150
|
-
const accountB = await sutB.derivePath?.([parentRelativePath, childRelativePath].join('/'))
|
|
151
|
-
expectWalletsAndPathsEqual(accountA, accountB)
|
|
152
|
-
snapshotWalletInstances(accountA, accountB)
|
|
153
|
-
})
|
|
154
|
-
it('works when paths provided absolutely', async () => {
|
|
155
|
-
const parentAbsolutePath = "m/44'/60'/0'"
|
|
156
|
-
const childRelativePath = '0/1'
|
|
157
|
-
const absolutePath = [parentAbsolutePath, childRelativePath].join('/')
|
|
158
|
-
const sutA = await HDWallet.fromPhrase(phrase, absolutePath)
|
|
159
|
-
const sutB = await HDWallet.fromPhrase(phrase, parentAbsolutePath)
|
|
160
|
-
expect(sutA.path).toEqual(absolutePath)
|
|
161
|
-
expect(sutB.path).toEqual(parentAbsolutePath)
|
|
162
|
-
// Skip intermediate snapshot since wallets currently have different paths
|
|
163
|
-
// snapshotWalletInstances(sutA, sutB)
|
|
164
|
-
const accountA = sutA
|
|
165
|
-
const accountB = await sutB.derivePath(childRelativePath)
|
|
166
|
-
expectWalletsAndPathsEqual(accountA, accountB)
|
|
167
|
-
// accountA and accountB should be the same instance
|
|
168
|
-
// expect(accountA).toBe(accountB)
|
|
169
|
-
snapshotWalletInstances(accountA, accountB)
|
|
170
|
-
})
|
|
171
|
-
it('returns cached instances on subsequent requests', async () => {
|
|
172
|
-
const parent = "44'/60'/0'"
|
|
173
|
-
const child = '0/1'
|
|
174
|
-
const sutA = await HDWallet.fromPhrase(phrase)
|
|
175
|
-
const sutB = await HDWallet.fromPhrase(phrase)
|
|
176
|
-
expectWalletsAndPathsEqual(sutA, sutB)
|
|
177
|
-
// sutA and sutB should be the same instance
|
|
178
|
-
expect(sutA).toBe(sutB)
|
|
179
|
-
const accountA = await (await sutA.derivePath(parent)).derivePath?.(child)
|
|
180
|
-
const accountB = await sutB.derivePath?.([parent, child].join('/'))
|
|
181
|
-
expectWalletsAndPathsEqual(accountA, accountB)
|
|
182
|
-
// accountA and accountB should be the same instance
|
|
183
|
-
// expect(accountA).toBe(accountB)
|
|
184
|
-
snapshotWalletInstances(accountA, accountB)
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
test('HDWallet tests generator is defined', () => {
|
|
191
|
-
expect(typeof generateHDWalletTests).toBe('function')
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
test('Same address, two paths', async () => {
|
|
195
|
-
const sut = await HDWallet.fromMnemonic(Mnemonic.fromPhrase('later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'))
|
|
196
|
-
const accountNode = await sut.derivePath('0')
|
|
197
|
-
expect(accountNode.path).toBe(`${defaultPath}/0`)
|
|
198
|
-
const accountA = await sut.derivePath('0/2')
|
|
199
|
-
const accountB = await accountNode.derivePath('2')
|
|
200
|
-
const accountAPrime = await accountNode.derivePath("0'/2")
|
|
201
|
-
const accountAPrime2 = await accountNode.derivePath("0/2'")
|
|
202
|
-
expect(accountA.address).toEqual(accountB.address)
|
|
203
|
-
expect(accountNode.address === accountB.address).toBe(false)
|
|
204
|
-
expect(accountA.address === accountAPrime.address).toBe(false)
|
|
205
|
-
expect(accountA.address === accountAPrime2.address).toBe(false)
|
|
206
|
-
|
|
207
|
-
expect(accountNode.address).toMatchSnapshot()
|
|
208
|
-
expect(accountA.address).toMatchSnapshot()
|
|
209
|
-
expect(accountB.address).toMatchSnapshot()
|
|
210
|
-
expect(accountAPrime.address).toMatchSnapshot()
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
test('Random Wallet', async () => {
|
|
214
|
-
const sut = await HDWallet.random()
|
|
215
|
-
expect(sut).toBeDefined()
|
|
216
|
-
expect(sut.address).toBeDefined()
|
|
217
|
-
expect(sut.privateKey).toBeDefined()
|
|
218
|
-
expect(sut.publicKey).toBeDefined()
|
|
219
|
-
expect(sut.extendedKey).toBeDefined()
|
|
220
|
-
expect(sut.path).toBeDefined()
|
|
221
|
-
expect(sut.path).toBe(defaultPath)
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
test('HDWallet can be created from mnemonic', async () => {
|
|
225
|
-
const sut = await HDWallet.fromPhrase('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', "m/44'/0'/0'/0/0")
|
|
226
|
-
expect(sut).toBeDefined()
|
|
227
|
-
console.log('privateKey', sut.privateKey)
|
|
228
|
-
})
|