forked from Loren779/tron-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bip.tests.js
42 lines (32 loc) · 1.74 KB
/
bip.tests.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
import { generateKeypair } from './src/utils/bipUtil';
import { keccak256 } from 'js-sha3';
import { byteArray2hexStr, hexStr2byteArray } from "./src/utils/crypto/code";
import { SHA256 } from "./src/utils/crypto/crypto";
import { encode58 } from "./src/utils/crypto/base58";
const mnemonic0 = '00000000000000000000000000000000';
const mnemonic12 = 'ceiling present easily example nurse silver ecology plug accident decrease special aware';
const mnemonic24 = 'hub purpose pistol mountain tape possible aware board decorate good chair only';
const biptest = (mnemonic, vn) => {
//console.log("Mnemonic (0 words): ", mnemonic)
const keypair = generateKeypair(mnemonic, vn)
console.log('Private Key:', keypair.pwd);
// console.log('Password = base64(Private Key): ', keypair.pk);
// console.log('Public Key:', keypair.pubKey);
let pubKey = keypair.pubKey.slice(2);
let sha3 = keccak256(hexStr2byteArray(pubKey));
//console.log('sha3 = SHA3(Public Key[1, 65)): ', sha3);
let address = "41" +keypair.address
//console.log('Address = 41||sha3[12,32): : ', address);
let sha256_0 = SHA256(hexStr2byteArray(address));
//console.log('sha256_0 = SHA256(Address): ', byteArray2hexStr(sha256_0));
let sha256_1 = SHA256(sha256_0);
//console.log('sha256_1 = SHA256(sha256_0): ', byteArray2hexStr(sha256_1));
let checkSum = byteArray2hexStr(sha256_1).slice(0, 8);
//console.log("checkSum = sha256_1[0, 4): ", checkSum);
let addchecksum = address + checkSum;
//console.log("addchecksum = address || checkSum: ", addchecksum);
let base58Address = encode58(hexStr2byteArray(addchecksum));
console.log("base58Address = Base58(addchecksum): ", base58Address);
//console.log("-----------------------------------------------------------------");
}
biptest(mnemonic24, 0);