forked from Zondax/filecoin-signing-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
119 lines (88 loc) · 3.59 KB
/
index.js
File metadata and controls
119 lines (88 loc) · 3.59 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
import * as wasm from '@zondax/filecoin-signing-tools'
import * as js from '@zondax/filecoin-signing-tools/js'
function log(text) {
document.getElementById('output').innerHTML += text + '\n'
}
/////////////////////////////////
// Generate Mnemonic
let mnemonic = wasm.generateMnemonic()
log('<h2>[wasm.mnemonic_generate]</h2>' + mnemonic)
log('mnemonic')
/////////////////////////////////
// Derive key
let key = wasm.keyDerive(mnemonic, 'm/44\'/461\'/0/0/0', '')
log('<h2>[wasm.key_derive]</h2>')
log(`<b>address </b> ${key.address}`)
log(`<b>public key </b> ${key.public_hexstring}`)
log(`<b>private key </b> ${key.private_hexstring}`)
log(`<b>public array </b> ${key.public_raw}`)
log(`<b>private array</b> ${key.private_raw}`)
log(`<b>public base64</b> ${key.public_base64}`)
log(`<b>private base64</b> ${key.private_base64}`)
/////////////////////////////////
// Recover key
let recovered_key = wasm.keyRecover(Buffer.from('6a1a68774457742a8bc69db5491df5ae7677687d49e1003a78e2d60959d5f7a7',"hex"))
log('<h2>[wasm.key_recover]</h2>')
log(`<b>address </b> ${recovered_key.address}`)
log(`<b>public key </b> ${recovered_key.public_hexstring}`)
log(`<b>private key </b> ${recovered_key.private_hexstring}`)
log(`<b>public array </b> ${recovered_key.public_raw}`)
log(`<b>private array</b> ${recovered_key.private_raw}`)
/////////////////////////////////
// Sign transaction
log('<h2>[wasm.sign_transaction]</h2>')
const unsigned_tx = {
'to': 't17uoq6tp427uzv7fztkbsnn64iwotfrristwpryy',
'from': key.address,
'nonce': 1,
'value': '100000',
'gasprice': '2500',
'gaslimit': 25000,
'gaspremium': '2500',
'gasfeecap': '2500',
'method': 4,
'params': '',
}
console.log('About to call wasm.transactionSignLotus():')
wasm.transactionSignLotus(unsigned_tx, key.private_raw)
console.log('Done calling wasm.transactionSignLotus()')
log(`unsigned_tx = ${JSON.stringify(unsigned_tx, 0, 4)}`)
let signed_tx = wasm.transactionSign(unsigned_tx, key.private_raw)
log('\n...sign...\n')
log(`signed_tx = ${JSON.stringify(signed_tx, 0, 4)}`)
// PURE JS LIB
/////////////////////////////////
// Generate Mnemonic
mnemonic = js.generateMnemonic()
log('<h2>[js.mnemonic_generate]</h2>' + mnemonic)
log('mnemonic')
/////////////////////////////////
// Derive key
key = js.keyDerive(mnemonic, 'm/44\'/461\'/0/0/0', '')
log('<h2>[js.key_derive]</h2>')
log(`<b>address </b> ${key.address}`)
log(`<b>public key </b> ${key.public_hexstring}`)
log(`<b>private key </b> ${key.private_hexstring}`)
log(`<b>public array </b> ${key.public_raw}`)
log(`<b>private array</b> ${key.private_raw}`)
log(`<b>public base64</b> ${key.public_base64}`)
log(`<b>private base64</b> ${key.private_base64}`)
/////////////////////////////////
// Recover key
recovered_key = js.keyRecover(Buffer.from('6a1a68774457742a8bc69db5491df5ae7677687d49e1003a78e2d60959d5f7a7',"hex"))
log('<h2>[js.key_recover]</h2>')
log(`<b>address </b> ${recovered_key.address}`)
log(`<b>public key </b> ${recovered_key.public_hexstring}`)
log(`<b>private key </b> ${recovered_key.private_hexstring}`)
log(`<b>public array </b> ${recovered_key.public_raw}`)
log(`<b>private array</b> ${recovered_key.private_raw}`)
/////////////////////////////////
// Sign transaction
log('<h2>[js.sign_transaction]</h2>')
console.log('About to call js.transactionSignLotus():')
js.transactionSignLotus(unsigned_tx, key.private_raw)
console.log('Done calling js.transactionSignLotus()')
log(`unsigned_tx = ${JSON.stringify(unsigned_tx, 0, 4)}`)
signed_tx = js.transactionSign(unsigned_tx, key.private_raw)
log('\n...sign...\n')
log(`signed_tx = ${JSON.stringify(signed_tx, 0, 4)}`)