-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathltc-p2sh-convert.js
37 lines (33 loc) · 925 Bytes
/
ltc-p2sh-convert.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
/**
* @author UMU618 <umu618@hotmail.com>
* @copyright MEET.ONE 2019
* @description Use block-always-using-brace npm-coding-style.
* @install yarn add bs58check
*/
'use strict'
const bsc = require('bs58check')
for (let i = 2; i < process.argv.length; ++i) {
convert(process.argv[i])
}
function convert(str) {
try {
const buffer = bsc.decode(str)
if (buffer.length == 21) {
if (buffer[0] == 5) {
buffer[0] = 50
const m = bsc.encode(buffer)
console.log(str, '->', m)
} else if (buffer[0] == 50) {
buffer[0] = 5
const three = bsc.encode(buffer)
console.log(three, '<-', str)
} else {
console.error(`convert('${str}') error: invalid version byte, ${buffer[0]}`)
}
} else {
console.error(`convert('${str}') error: invalid length`)
}
} catch(err) {
console.error(`convert('${str}') error:`, err.message)
}
}