@@ -5,7 +5,7 @@ let DashHd = require("dashhd");
5
5
let DashKeys = require ( "dashkeys" ) ;
6
6
let DashTx = require ( "dashtx" ) ;
7
7
let DashPlatform = require ( "./dashplatform.js" ) ;
8
- let CBOR = require ( "CBOR " ) ;
8
+ let CBOR = require ( "cbor " ) ;
9
9
10
10
let KeyUtils = require ( "./key-utils.js" ) ;
11
11
@@ -54,53 +54,80 @@ let KEY_TYPES = {
54
54
ECDSA_SECP256K1 : 0 ,
55
55
} ;
56
56
57
+ let network = "testnet" ;
58
+ let coinType = 5 ; // DASH
59
+ if ( network === "testnet" ) {
60
+ coinType = 1 ; // testnet
61
+ }
62
+ //coinType = 1;
63
+
57
64
let identityEcdsaPath = "" ;
58
65
{
59
66
// m/purpose'/coin_type'/feature'/subfeature'/keytype'/identityindex'/keyindex'
60
67
// ex: m/9'/5'/5'/0'/0'/<id>/<key>
61
68
let purposeDip13 = 9 ;
62
- let coinDash = 5 ;
63
69
let featureId = 5 ;
64
70
let subfeatureKey = 0 ;
65
71
let keyType = KEY_TYPES . ECDSA_SECP256K1 ;
66
- identityEcdsaPath = `m/${ purposeDip13 } '/${ coinDash } '/${ featureId } '/${ subfeatureKey } '/${ keyType } '` ;
72
+ identityEcdsaPath = `m/${ purposeDip13 } '/${ coinType } '/${ featureId } '/${ subfeatureKey } '/${ keyType } '` ;
67
73
}
68
74
69
75
async function main ( ) {
70
76
void ( await WasmDpp . default ( ) ) ;
71
77
72
- let network = "testnet" ;
73
-
74
78
let dashTx = DashTx . create ( KeyUtils ) ;
75
79
76
80
// let phrase = await DashPhrase.generate();
77
81
let phrase =
78
- "casino reveal crop open ordinary garment spy pizza clown exercise poem enjoy" ;
82
+ "wool panel expand embrace try lab rescue reason drop fog stand kangaroo" ;
83
+ console . log ( `Phrase:` ) ;
84
+ console . log ( phrase ) ;
79
85
let salt = "" ;
80
86
let seedBytes = await DashPhrase . toSeed ( phrase , salt ) ;
81
- let walletKey = await DashHd . fromSeed ( seedBytes ) ;
87
+ console . log ( "Seed:" ) ;
88
+ console . log ( DashTx . utils . bytesToHex ( seedBytes ) ) ;
89
+ let walletKey = await DashHd . fromSeed ( seedBytes , { coinType } ) ;
90
+ let walletId = await DashHd . toId ( walletKey ) ;
91
+ console . log ( `Wallet ID:` ) ;
92
+ console . log ( walletId ) ;
82
93
83
94
let accountIndex = 0 ; // pick the desired account for paying the fee
84
- let addressIndex = 8 ; // pick an address with funds
85
- let accountKey = await walletKey . deriveAccount ( accountIndex ) ;
86
- let use = DashHd . RECEIVE ;
87
- let xprvKey = await accountKey . deriveXKey ( use ) ;
88
- let addressKey = await xprvKey . deriveAddress ( addressIndex ) ;
89
- if ( ! addressKey . privateKey ) {
90
- throw new Error ( "not an error, just a lint hack" ) ;
95
+ let addressIndex = 0 ; // pick an address with funds
96
+ let accountKey ;
97
+ for ( let a = 0 ; a <= accountIndex ; a += 1 ) {
98
+ accountKey = await walletKey . deriveAccount ( a ) ;
99
+
100
+ for ( let usage of [ DashHd . RECEIVE , DashHd . CHANGE ] ) {
101
+ let xprvKey = await accountKey . deriveXKey ( usage ) ;
102
+
103
+ let addressKey ;
104
+ let addr ;
105
+ let pkh ;
106
+ let wif ;
107
+ for ( let i = 0 ; i <= addressIndex ; i += 1 ) {
108
+ addressKey = await xprvKey . deriveAddress ( i ) ;
109
+ if ( ! addressKey . privateKey ) {
110
+ throw new Error ( "not an error, just a lint hack" ) ;
111
+ }
112
+
113
+ addr = await DashHd . toAddr ( addressKey . publicKey , { version : network } ) ;
114
+ let pkhBytes = await DashKeys . addrToPkh ( addr , {
115
+ //@ts -ignore
116
+ version : network ,
117
+ } ) ;
118
+ pkh = DashKeys . utils . bytesToHex ( pkhBytes ) ;
119
+ wif = await DashHd . toWif ( addressKey . privateKey , { version : network } ) ;
120
+ console . log ( ) ;
121
+ console . log (
122
+ `[m/44'/${ coinType } '/${ a } '/${ usage } /${ i } ] Address: ${ addr } ` ,
123
+ ) ;
124
+ // TODO is _this_ the assetLockPrivateKey??
125
+ console . log ( `[m/44'/${ coinType } '/${ a } /${ usage } /${ i } ] WIF: ${ wif } ` ) ;
126
+ }
127
+ }
91
128
}
92
129
93
- let addr = await DashHd . toAddr ( addressKey . publicKey , { version : network } ) ;
94
- let pkhBytes = await DashKeys . addrToPkh ( addr , {
95
- //@ts -ignore
96
- version : network ,
97
- } ) ;
98
- let pkh = DashKeys . utils . bytesToHex ( pkhBytes ) ;
99
- let wif = await DashHd . toWif ( addressKey . privateKey , { version : network } ) ;
100
- console . log ( ) ;
101
- console . log ( `Address: ${ addr } ` ) ;
102
- // TODO is _this_ the assetLockPrivateKey??
103
- console . log ( `WIF: ${ wif } ` ) ;
130
+ process . exit ( 1 ) ;
104
131
105
132
KeyUtils . set ( addr , {
106
133
address : addr ,
@@ -226,6 +253,7 @@ async function main() {
226
253
let cbor = CBOR . encodeCanonical ( stateTransition ) ;
227
254
console . log ( `cbor:` ) ;
228
255
console . log ( DashTx . utils . bytesToHex ( cbor ) ) ;
256
+ console . log ( bytesToBase64 ( cbor ) ) ;
229
257
230
258
let sigBytes = await KeyUtils . sign ( addressKey . privateKey , cbor ) ;
231
259
let sigHex = DashTx . utils . bytesToHex ( sigBytes ) ;
0 commit comments