This repository has been archived by the owner on Nov 4, 2020. It is now read-only.
forked from social-dist0rtion-protocol/paper-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
98 lines (85 loc) · 2.66 KB
/
index.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
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
var Web3 = require('web3')
var qr = require('qr-image')
let base64url = require('base64url')
const URL = "https://sundai.io"
const COMPRESS = true
const AUTOPRINT = false
const MINEFOR = false//"feeddeadbeef"
const DISPLAYPK = false;
var web3 = new Web3(URL)
const workDir = process.cwd();
let result = ""
if(MINEFOR){
while(!result.address || result.address.toLowerCase().indexOf("0x"+MINEFOR)!==0){
result = web3.eth.accounts.create();
//console.log(result.address)
}
}else{
result = web3.eth.accounts.create();
}
let PK = result.privateKey
if(DISPLAYPK) console.log(PK);
let pkLink
if(COMPRESS){
function pkToUrl(pk) {
return base64url(web3.utils.hexToBytes(pk))
}
let encoded = pkToUrl(PK)
pkLink = URL+"/pk#"+encoded
}else{
pkLink = URL+"/pk#"+PK.replace("0x","")
}
//console.log(pkLink)
var private = qr.image(pkLink, { type: 'png' });
private.pipe(require('fs').createWriteStream('private.png'));
var publicAddress = result.address
var public = qr.image(URL+"/"+publicAddress, { type: 'svg' });
public.pipe(require('fs').createWriteStream('public.svg'));
//console.log("public.svg"+URL+"/"+publicAddress)
console.log(publicAddress)
var fs = require('fs')
fs.readFile("templatesundai.html", 'utf8', (err,data) => {
if (err) {
return console.log(err);
}
var result = data
.replace(/\*\*PUBLIC\*\*/g, publicAddress.substring(0,8)+"......"+publicAddress.substring(publicAddress.length-7))
.replace(/\*\*PATH\*\*/g, workDir);
//console.log(result);
fs.writeFile("generated.html", result, 'utf8', function (err) {
if (err) return console.log(err);
fs.appendFile('addresses.txt',publicAddress+"\n", function (err) {
if (err) throw err;
});
var html = fs.readFileSync('./generated.html', 'utf8');
var conversion = require("phantom-html-to-pdf")();
console.log("Generating PDF...")
conversion({
html: html,
allowLocalFilesAccess: true,
phantomPath: require("phantomjs-prebuilt").path,
settings: {
javascriptEnabled : true,
resourceTimeout: 10000
},
paperSize: {
format: 'A4',
orientation: 'portrait',
margin: {
top: "0in",
left: "0in",
right:"0in"
},
},
}, function(err, pdf) {
var output = fs.createWriteStream('./generated.pdf')
//console.log(pdf.logs);
//console.log(pdf.numberOfPages);
// since pdf.stream is a node.js stream you can use it
// to save the pdf to a file (like in this example) or to
// respond an http request.
pdf.stream.pipe(output);
conversion.kill();
});
});
});