Last active
May 22, 2021 17:07
-
-
Save itslukej/526e27c017a5c0956e12c35d8bc201b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { toBigIntBE, toBufferBE } from 'bigint-buffer'; | |
| export function encode(hash: string) { | |
| const buffer = Buffer.from(hash, "hex"); | |
| return [toBigIntBE(buffer.slice(0, 8)), toBigIntBE(buffer.slice(8, 16))]; | |
| } | |
| export function decode(first: bigint, second: bigint) { | |
| const buffer1 = toBufferBE(first, 8); | |
| const buffer2 = toBufferBE(second, 8); | |
| return buffer1.toString('hex') + buffer2.toString('hex'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment