7
7
selectStxDerivation ,
8
8
fetchUsernameForAccountByDerivationType ,
9
9
} from '../src' ;
10
- import { mnemonicToSeed } from 'bip39' ;
10
+ // https://github.com/paulmillr/scure-bip39
11
+ // Secure, audited & minimal implementation of BIP39 mnemonic phrases.
12
+ import { mnemonicToSeed } from '@scure/bip39' ;
11
13
import { fromBase58 , fromSeed } from 'bip32' ;
12
14
import { TransactionVersion } from '@stacks/transactions' ;
13
15
import { StacksMainnet } from '@stacks/network' ;
@@ -22,7 +24,7 @@ const DATA_ADDRESS = 'SP30RZ44NTH2D95M1HSWVMM8VVHSAFY71VF3XQZ0K';
22
24
23
25
test ( 'keys are serialized, and can be deserialized properly using wallet private key for stx' , async ( ) => {
24
26
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
25
- const rootNode1 = fromSeed ( rootPrivateKey ) ;
27
+ const rootNode1 = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
26
28
const derived = await deriveWalletKeys ( rootNode1 ) ;
27
29
const rootNode = fromBase58 ( derived . rootKey ) ;
28
30
const account = deriveAccount ( {
@@ -38,7 +40,7 @@ test('keys are serialized, and can be deserialized properly using wallet private
38
40
39
41
test ( 'keys are serialized, and can be deserialized properly using data private key for stx' , async ( ) => {
40
42
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
41
- const rootNode1 = fromSeed ( rootPrivateKey ) ;
43
+ const rootNode1 = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
42
44
const derived = await deriveWalletKeys ( rootNode1 ) ;
43
45
const rootNode = fromBase58 ( derived . rootKey ) ;
44
46
const account = deriveAccount ( {
@@ -54,14 +56,14 @@ test('keys are serialized, and can be deserialized properly using data private k
54
56
55
57
test ( 'backwards compatible legacy config private key derivation' , async ( ) => {
56
58
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
57
- const rootNode = fromSeed ( rootPrivateKey ) ;
59
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
58
60
const legacyKey = deriveLegacyConfigPrivateKey ( rootNode ) ;
59
61
expect ( legacyKey ) . toEqual ( '767b51d866d068b02ce126afe3737896f4d0c486263d9b932f2822109565a3c6' ) ;
60
62
} ) ;
61
63
62
64
test ( 'derive derivation path without username' , async ( ) => {
63
65
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
64
- const rootNode = fromSeed ( rootPrivateKey ) ;
66
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
65
67
const network = new StacksMainnet ( ) ;
66
68
const { username, stxDerivationType } = await selectStxDerivation ( {
67
69
username : undefined ,
@@ -75,7 +77,7 @@ test('derive derivation path without username', async () => {
75
77
76
78
test ( 'derive derivation path with username owned by address of stx derivation path' , async ( ) => {
77
79
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
78
- const rootNode = fromSeed ( rootPrivateKey ) ;
80
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
79
81
const network = new StacksMainnet ( ) ;
80
82
81
83
fetchMock . once ( JSON . stringify ( { address : DATA_ADDRESS } ) ) ;
@@ -92,7 +94,7 @@ test('derive derivation path with username owned by address of stx derivation pa
92
94
93
95
test ( 'derive derivation path with username owned by address of unknown derivation path' , async ( ) => {
94
96
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
95
- const rootNode = fromSeed ( rootPrivateKey ) ;
97
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
96
98
const network = new StacksMainnet ( ) ;
97
99
98
100
fetchMock . once ( JSON . stringify ( { address : 'SP000000000000000000002Q6VF78' } ) ) ;
@@ -109,7 +111,7 @@ test('derive derivation path with username owned by address of unknown derivatio
109
111
110
112
test ( 'derive derivation path with username owned by address of data derivation path' , async ( ) => {
111
113
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
112
- const rootNode = fromSeed ( rootPrivateKey ) ;
114
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
113
115
const network = new StacksMainnet ( ) ;
114
116
115
117
fetchMock . once ( JSON . stringify ( { address : 'SP30RZ44NTH2D95M1HSWVMM8VVHSAFY71VF3XQZ0K' } ) ) ;
@@ -126,7 +128,7 @@ test('derive derivation path with username owned by address of data derivation p
126
128
127
129
test ( 'derive derivation path with new username owned by address of stx derivation path' , async ( ) => {
128
130
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
129
- const rootNode = fromSeed ( rootPrivateKey ) ;
131
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
130
132
const network = new StacksMainnet ( ) ;
131
133
132
134
fetchMock . once ( JSON . stringify ( { names : [ 'public_profile_for_testing.id.blockstack' ] } ) ) ;
@@ -146,7 +148,7 @@ test('derive derivation path with new username owned by address of stx derivatio
146
148
147
149
test ( 'derive derivation path with new username owned by address of data derivation path' , async ( ) => {
148
150
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
149
- const rootNode = fromSeed ( rootPrivateKey ) ;
151
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
150
152
const network = new StacksMainnet ( ) ;
151
153
152
154
fetchMock
@@ -171,7 +173,7 @@ test('derive derivation path with new username owned by address of data derivati
171
173
172
174
test ( 'derive derivation path with username and without network' , async ( ) => {
173
175
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
174
- const rootNode = fromSeed ( rootPrivateKey ) ;
176
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
175
177
176
178
const { username, stxDerivationType } = await selectStxDerivation ( {
177
179
username : 'public_profile_for_testing.id.blockstack' ,
@@ -184,7 +186,7 @@ test('derive derivation path with username and without network', async () => {
184
186
185
187
test ( 'derive derivation path without username and without network' , async ( ) => {
186
188
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
187
- const rootNode = fromSeed ( rootPrivateKey ) ;
189
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
188
190
189
191
const { username, stxDerivationType } = await selectStxDerivation ( {
190
192
username : undefined ,
@@ -197,7 +199,7 @@ test('derive derivation path without username and without network', async () =>
197
199
198
200
test ( 'fetch username owned by derivation type' , async ( ) => {
199
201
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
200
- const rootNode = fromSeed ( rootPrivateKey ) ;
202
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
201
203
202
204
fetchMock . once ( JSON . stringify ( { names : [ 'public_profile_for_testing.id.blockstack' ] } ) ) ;
203
205
@@ -212,7 +214,7 @@ test('fetch username owned by derivation type', async () => {
212
214
213
215
test ( 'fetch username owned by different derivation type' , async ( ) => {
214
216
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
215
- const rootNode = fromSeed ( rootPrivateKey ) ;
217
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
216
218
217
219
fetchMock . once ( JSON . stringify ( { names : [ ] } ) ) ;
218
220
@@ -227,7 +229,7 @@ test('fetch username owned by different derivation type', async () => {
227
229
228
230
test ( 'fetch username defaults to mainnet' , async ( ) => {
229
231
const rootPrivateKey = await mnemonicToSeed ( SECRET_KEY ) ;
230
- const rootNode = fromSeed ( rootPrivateKey ) ;
232
+ const rootNode = fromSeed ( Buffer . from ( rootPrivateKey ) ) ;
231
233
232
234
fetchMock . once ( JSON . stringify ( { names : [ 'public_profile_for_testing.id.blockstack' ] } ) ) ;
233
235
0 commit comments