UNPKG

0xweb

Version:

Contract package manager and other web3 tools

20 lines (16 loc) 553 B
import { $buffer } from '@dequanto/utils/$buffer'; (BigInt as any).prototype.toJSON = function () { return this.toString() }; (BigInt as any).prototype.toBuffer = function () { let hex = (this as bigint).toString(16); if (hex.length % 2 !== 0) { hex = `0${hex}`; } return $buffer.fromHex(hex); }; (BigInt as any).prototype.valueOf = function () { if (this > BigInt(Number.MAX_VALUE)) { throw new Error(`BigInt to Number overflows: ${this}`) } return Number(this); }; export function BigIntSerializer () {}