diff options
Diffstat (limited to 'src/js/fio-util.js')
-rw-r--r-- | src/js/fio-util.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/js/fio-util.js b/src/js/fio-util.js new file mode 100644 index 0000000..35cb1ba --- /dev/null +++ b/src/js/fio-util.js | |||
@@ -0,0 +1,19 @@ | |||
1 | function FIObufferToPublic(pubBuf) { | ||
2 | const Buffer = libs.buffer.Buffer; | ||
3 | const FIO_PUBLIC_PREFIX = "FIO"; | ||
4 | |||
5 | let checksum = libs.createHash("rmd160").update(pubBuf).digest("hex").slice(0, 8); | ||
6 | pubBuf = Buffer.concat([pubBuf, Buffer.from(checksum, "hex")]); | ||
7 | return FIO_PUBLIC_PREFIX.concat(libs.bs58.encode(pubBuf)); | ||
8 | } | ||
9 | |||
10 | function FIObufferToPrivate(privBuf) { | ||
11 | const Buffer = libs.buffer.Buffer; | ||
12 | const FIO_PRIVATE_PREFIX = "80"; | ||
13 | |||
14 | privBuf = Buffer.concat([Buffer.from(FIO_PRIVATE_PREFIX, "hex"), privBuf]); | ||
15 | let tmp = libs.createHash("sha256").update(privBuf).digest(); | ||
16 | let checksum = libs.createHash("sha256").update(tmp).digest("hex").slice(0, 8); | ||
17 | privBuf = Buffer.concat([privBuf, Buffer.from(checksum, "hex")]); | ||
18 | return libs.bs58.encode(privBuf); | ||
19 | } \ No newline at end of file | ||