This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddress.js
64 lines (47 loc) · 2.21 KB
/
address.js
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
/*
Create bitcoin wallet
Author: Alex Ishida <[email protected]>
Version: 1.0
Date: 15/08/2017
References:
https://bitcore.io/api/lib/address
https://bitcore.io/api/lib/public-key
http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript
Link to get free testnet btc:
https://testnet.manu.backend.hamburg/faucet
Example:
node address.js
*/
const bitcore = require('bitcore-lib');
const crypto = require('crypto');
// if you use mainnet comment the line below
const network = bitcore.Networks.testnet;
const buf = crypto.randomBytes(256);
const hash = bitcore.crypto.Hash.sha256(buf);
var private_key = bitcore.PrivateKey.fromBuffer(hash,network);
var private_key_wif = private_key.toWIF();
var public_key = new bitcore.PublicKey(private_key);
var address = public_key.toAddress();
var bn = bitcore.crypto.BN.fromBuffer(hash);
var private_key_comp = new bitcore.PrivateKey(bn,network);
var private_key_wif_comp = private_key_comp.toWIF();
var public_key_comp = new bitcore.PublicKey(private_key_comp);
var address_comp = public_key_comp.toAddress();
// Return json
var json = "{ \"private_key\": \""+ private_key +"\", \"private_key_wif\": \""+ private_key_wif+ "\", \"public_key\": \""+ public_key+ "\", \"address\": \""+ address+ "\",";
json = json + " \"private_key_compressed\": \""+ private_key_comp +"\", \"private_key_wif_compressed\": \""+ private_key_wif_comp+ "\", \"public_key_compressed\": \""+ public_key_comp+ "\", \"address_compressed\": \""+ address_comp+ "\" }";
console.log(json);
/*console.log("---------------------------------------");
console.log("Rede: " + network);
console.log("---------------------------------------");
console.log("Private Key: " + private_key);
console.log("Private Key WIF: " + private_key_wif);
console.log("Public Key: " + public_key);
console.log("Address: " + address);
console.log("---------------------------------------");
console.log("Private Key Compressed: " + private_key_comp);
console.log("Private Key WIF Compressed: " + private_key_wif_comp);
console.log("Public Key Compressed: " + public_key_comp);
console.log("Address Compressed: " + address_comp);
console.log("---------------------------------------");
*/