-
Notifications
You must be signed in to change notification settings - Fork 0
/
walletgen
executable file
·249 lines (205 loc) · 6.27 KB
/
walletgen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env node
'use strict';
const ArgumentParser = require('argparse').ArgumentParser;
const readline = require('readline');
const library = require('./library')
var coins = ['bitcoin','bitcoin-testnet','ethereum']
var parser = new ArgumentParser({
version: '0.0.1',
addHelp:true,
description: 'HD Wallet generator',
});
parser.addArgument(
[ '-m', '--mnemonic' ],
{
help: 'generate 24 mnemonic words and the equivalent seed and output them in the commandline',
action: 'storeTrue'
}
);
parser.addArgument(
[ '-w', '--words' ],
{
help: 'generate 24 mnemonic words and output it in the commandline',
action: 'storeTrue'
}
);
parser.addArgument(
[ '-s', '--seed' ],
{
help: 'generate a seed and output it in the commandline',
action: 'storeTrue'
}
);
parser.addArgument(
['--seedfromwords' ],
{
help: 'get seed from 24 words (input a string)',
action: 'store'
}
);
parser.addArgument(
[ '-d', '--data' ],
{
help: 'give data from 24 mnemonic words, an account number and a network',
action: 'storeTrue'
}
);
parser.addArgument(
[ '-e', '--datafromseed' ],
{
help: 'give data from seed, an account number and a network',
action: 'storeTrue'
}
);
parser.addArgument(
[ '-k', '--key' ],
{
help: 'give a private key from a seed, network and number',
action: 'store',
nargs: 3,
metavar: ['SEED', 'NETWORK','ACCOUNT_NUMBER']
}
);
parser.addArgument(
[ '-a', '--address' ],
{
help: 'give an address from a seed, network and number',
action: 'store',
nargs: 3,
metavar: ['SEED', 'NETWORK','ACCOUNT_NUMBER']
}
);
function print_words(){
const mnemo = library.create_mnemonic()
console.log(mnemo[0])
}
function print_seed(){
const mnemo = library.create_mnemonic()
console.log(mnemo[1].toString('hex'))
}
function print_mnemonic(){
const mnemo = library.create_mnemonic()
console.log("Your 24 mnemonic words are: \n" + mnemo[0] + "\n")
console.log("The equivalent master seed is: \n" + mnemo[1].toString('hex') + "\n")
}
function get_privatekey(data){
return data[0].toString('hex')
}
function get_address(data){
return data[1]
}
function print_accountfromseed(seed,network,account_number){
if(!coins.includes(network)){
throw "Wrong Network : should be ethereum or bitcoin or bitcoin-testnet!"
}
const data = library.account_from_seed(seed,account_number,network)
if(network === "bitcoin"){
console.log("private key : " + data[0].toString('hex') + "\n")
console.log("WIF : " + data[2] + "\n")
console.log("public key : " + data[3].toString('hex') + "\n")
console.log("address : " + data[1] + "\n")
}
else if(network === "bitcoin-testnet"){
console.log("private key : " + data[0].toString('hex') + "\n")
console.log("WIF : " + data[2] + "\n")
console.log("public key : " + data[3].toString('hex') + "\n")
console.log("address : " + data[1] + "\n")
}
else if(network === "ethereum"){
console.log("private key : " + data[0].toString('hex') + "\n")
console.log("address : " + data[1] + "\n")
}
}
function print_account(words,network,account_number){
const seed = library.create_seed(words)
console.log("seed:" + seed.toString('hex'))
print_accountfromseed(seed,network,account_number)
}
function print_privatekey(seed,network,account_number){
if(!coins.includes(network)){
throw "Wrong Network : should be ethereum or bitcoin or bitcoin-testnet!"
}
const data = library.account_from_seed(seed,account_number,network)
console.log(get_privatekey(data).toString('hex'))
}
function print_address(seed,network,account_number){
if(!coins.includes(network)){
throw "Wrong Network : should be ethereum or bitcoin or bitcoin-testnet!"
}
const data = library.account_from_seed(seed,account_number,network)
console.log(get_address(data).toString('hex'))
}
var args = parser.parseArgs();
//console.dir(args);
const vals = Object.values(args)
const nb = vals.filter(Boolean).length
if(nb>1){
throw "Error : too many arguments"
}
if(args['mnemonic']){
print_mnemonic()
}
else if(args['words']){
print_words()
}
else if(args['seed']){
print_seed()
}
if(args['seedfromwords']){
const words = args['seedfromwords']
const seed = library.create_seed(words)
console.log(seed.toString('hex'))
}
if(args['data']){
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Please input 24 mnemonic words :\n", function(words) {
rl.question("Please enter network (bitcoin, bitcoin-testnet or ethereum) :", function(network) {
if(!coins.includes(network)){
throw "Wrong Network : should be ethereum or bitcoin or bitcoin-testnet!"
}
rl.question("Please enter account number :", function(nb) {
const account = parseInt(nb)
console.log("words:" + words)
console.log("type:" + typeof(words))
console.log("\n ********** Account Data ********** \n")
print_account(words,network,account)
rl.close();
})
})
});
}
if(args['datafromseed']){
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Please input seed :\n", function(s) {
rl.question("Please enter network (bitcoin, bitcoin-testnet or ethereum) :", function(network) {
if(!coins.includes(network)){
throw "Wrong Network : should be ethereum or bitcoin or bitcoin-testnet!"
}
rl.question("Please enter account number :", function(nb) {
const seed = new Buffer.from(s, 'hex')
const account = parseInt(nb)
console.log("\n ********** Account Data ********** \n")
print_accountfromseed(seed,network,account)
rl.close();
})
})
});
}
if(args['key']){
const seed = new Buffer.from(args['key'][0],'hex')
const network = args['key'][1]
const account_number = parseInt(args['key'][2])
print_privatekey(seed,network,account_number)
}
if(args.address){
const seed = new Buffer.from(args['address'][0],'hex')
const network = args['address'][1]
const account_number = parseInt(args['address'][2])
print_address(seed,network,account_number)
}