Repository navigation
Expand file tree
/
Copy pathwallet.js
More file actions
125 lines (125 loc) · 4.4 KB
/
Copy pathwallet.js
File metadata and controls
125 lines (125 loc) · 4.4 KB
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
// Generated by LiveScript 1.5.0
(function(){
var bitcoin, zcash, bip32utils, bip39, hdkey, waves, monero, network, buf2hex, getWavesFullpairByIndex, getMoneroFullpairByIndex, getLibrary, getBitcoinFullpairByIndex, getEthereumFullpairByIndex, getFullpairByIndex, getAddressByIndex, generateKeys, generateWallet, out$ = typeof exports != 'undefined' && exports || this;
bitcoin = require('bitcoinjs-lib');
zcash = require('bitcoinjs-lib-zcash');
bip32utils = require('bip32-utils');
bip39 = require('bip39');
hdkey = require('ethereumjs-wallet/hdkey');
waves = require('waves.js/dist/waves.js');
monero = {};
network = bitcoin.networks.bitcoin;
buf2hex = function(buffer){
return Array.prototype.map.call(buffer, function(x){
return ('00' + x.toString(16)).slice(-2);
}).join('');
};
getWavesFullpairByIndex = function(mnemonic, index, network){
var chainId, utils, ref$, address, keys, privateKey, publicKey;
chainId = network.messagePrefix === 'Waves'
? 'W'.charCodeAt(0)
: 'T'.charCodeAt(0);
utils = new waves['default']({
chainId: chainId
});
ref$ = utils.createAccount(mnemonic + " / " + index), address = ref$.address, keys = ref$.keys;
privateKey = keys.privateKey, publicKey = keys.publicKey;
return {
address: address,
privateKey: buf2hex(privateKey),
publicKey: buf2hex(publicKey)
};
};
getMoneroFullpairByIndex = function(mnemonic, index, network){
var ref$, address, spendKey, viewKey;
ref$ = monero.generateAddress(mnemonic + " / " + index), address = ref$.address, spendKey = ref$.spendKey, viewKey = ref$.viewKey;
return {
address: address,
privateKey: spendKey,
viewKey: viewKey
};
};
getLibrary = function(network){
switch (false) {
case !(network.messagePrefix.indexOf('Zcash Signed Message') > -1):
return zcash;
default:
return bitcoin;
}
};
getBitcoinFullpairByIndex = function(mnemonic, index, network){
var seed, hdnode, address, privateKey, publicKey;
seed = bip39.mnemonicToSeedHex(mnemonic);
hdnode = getLibrary(network).HDNode.fromSeedHex(seed, network).derive(index);
address = hdnode.getAddress();
privateKey = hdnode.keyPair.toWIF();
publicKey = hdnode.getPublicKeyBuffer().toString('hex');
return {
address: address,
privateKey: privateKey,
publicKey: publicKey
};
};
getEthereumFullpairByIndex = function(mnemonic, index, network){
var seed, wallet, w, address, privateKey, publicKey;
seed = bip39.mnemonicToSeed(mnemonic);
wallet = hdkey.fromMasterSeed(seed);
w = wallet.derivePath("0").deriveChild(index).getWallet();
address = "0x" + w.getAddress().toString('hex');
privateKey = w.getPrivateKeyString();
publicKey = w.getPublicKeyString();
return {
address: address,
privateKey: privateKey,
publicKey: publicKey
};
};
out$.getFullpairByIndex = getFullpairByIndex = function(mnemonic, index, network){
var type, fun;
type = network != null ? network.messagePrefix : void 8;
fun = (function(){
switch (false) {
case type != null:
return "Wrong Type";
case type !== 'Monero':
return getMoneroFullpairByIndex;
case !(type === 'Waves' || type === 'WavesTest'):
return getWavesFullpairByIndex;
case type !== 'Ethereum':
return getEthereumFullpairByIndex;
default:
return getBitcoinFullpairByIndex;
}
}());
return fun(mnemonic, index, network);
};
out$.getAddressByIndex = getAddressByIndex = function(mnemonic, index, network){
return getFullpairByIndex(mnemonic, index, network).address;
};
out$.generateKeys = generateKeys = function(mnemonic){
var seed, hdnode, privateKey, address, publicKey;
seed = bip39.mnemonicToSeedHex(mnemonic);
hdnode = bitcoin.HDNode.fromSeedHex(seed, network).derive(0);
privateKey = hdnode.keyPair.toWIF();
address = hdnode.getAddress();
publicKey = hdnode.getPublicKeyBuffer().toString('hex');
return {
privateKey: privateKey,
address: address,
publicKey: publicKey
};
};
out$.generateWallet = generateWallet = function(){
var mnemonic, keys;
mnemonic = bip39.generateMnemonic();
keys = generateKeys(mnemonic);
return {
mnemonic: mnemonic,
address: keys.address
};
};
/*
bitcoin.HDNode.from-seed-hex
HDNode.from-seed-hex
*/
}).call(this);