Skip to content

Instantly share code, notes, and snippets.

@itslukej
Last active May 22, 2021 17:07
Show Gist options
  • Select an option

  • Save itslukej/526e27c017a5c0956e12c35d8bc201b3 to your computer and use it in GitHub Desktop.

Select an option

Save itslukej/526e27c017a5c0956e12c35d8bc201b3 to your computer and use it in GitHub Desktop.
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