forked from uvmetal/neo-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.js
92 lines (70 loc) · 2.57 KB
/
create.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
const base64url = require('base64url')
const pdf = require('html-pdf')
const bip39 = require('bip39')
const qr = require('qr-image')
const fs = require('fs')
const util = require('util')
const { default: Neon, wallet, api, rpc } = require('@cityofzion/neon-js')
// const WIF = require('wif')
const COMPRESS = false
var publicAddress = process.argv[2]
let PK = process.argv[3]
let URL = process.argv[4]
if (!URL) URL = ''
let WIF = process.argv[5]
let bip39Mnemonic
if (PK) {
console.log('Input Private Key: \n'+PK)
bip39Mnemonic = bip39.entropyToMnemonic(PK)
console.log('BIP-39 Mnemonic: \n'+bip39Mnemonic)
let reversedPK = bip39.mnemonicToEntropy(bip39Mnemonic)
console.log('Mnemonic Reversed Back to PK: \n'+reversedPK)
if (PK !== reversedPK) {
console.log('Seed did not reverse to private key. Please try again.')
console.log('Got: \n'+reversedPK+' and should have been: \n'+PK)
return
}
}
let pkLink
if (COMPRESS) {
function pkToUrl(pk) {
// return base64url(web3.utils.hexToBytes(pk))
return null
}
let encoded = pkToUrl(PK)
pkLink = URL+'/pk#'+encoded
} else {
pkLink = PK.replace('0x','')
}
console.log('pkLink: '+pkLink)
var private = qr.image('Private Key: \n'+pkLink+'\nWIF: \n'+WIF+'\nSeed: '+bip39Mnemonic, { type: 'png' })
private.pipe(require('fs').createWriteStream('private.png'))
var public = qr.image('Public\nURL: \n'+URL+'\nPublic Address: \n'+publicAddress, { type: 'svg' })
public.pipe(require('fs').createWriteStream('public.svg'))
console.log('publicAddress: '+publicAddress)
fs.readFile('template.html', 'utf8', (err,data) => {
if (err) {
return console.log(err)
}
var result = data.replace(/\*\*PUBLIC\*\*/g,publicAddress.substring(0,9)+'......'+publicAddress.substring(publicAddress.length-8))
result = result.replace(/\*\*URL\*\*/g,URL)
result = result.replace(/'\.\//g, '\'file://'+__dirname+'/')
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
})
let cwd = 'file://' + process.cwd() + '/'
console.log(`cwd: ${cwd}`)
var html = fs.readFileSync('./generated.html', 'utf8')
var options = {
// Rendering options
format: 'Letter',
'base': cwd, // Base path that's used to load files (images, css, js) when they aren't referenced using a host
}
pdf.create(html, options).toFile('./generated.pdf', function(err, res) {
if (err) return console.log(err)
console.log('res: '+util.inspect(res, {depth: null}))
})
})
})