-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
30 lines (20 loc) · 941 Bytes
/
client.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
var { PrivateKey, key, Address, Signature } = require("bitsharesjs");
var seedrandom = require('seedrandom');
var bip39 = require("bip39");
//var rng = seedrandom();
//let seed = rng().toString();
// let privateKey = PrivateKey.fromSeed(key.normalize_brainKey(seed));
var mnemonic = bip39.generateMnemonic();
let privateKey = PrivateKey.fromSeed(key.normalize_brainKey(mnemonic));
let publicKey = privateKey.toPublicKey();
let address = Address.fromPublic(publicKey);
var text = "ello";
var signed = Signature.signBuffer(text, privateKey);
var signedHex = signed.toHex();
console.log("\nmnemonic:", mnemonic.toString());
console.log("\nPrivate key:", privateKey.toWif().toString());
console.log("\nPublic key :", publicKey.toString(), "\n");
console.log("\naddress:", address.toString());
console.log("\nsigned:", signedHex);
var signed2 = Signature.fromHex(signedHex);
console.log("\nv:", signed2.verifyBuffer("ello", publicKey))