@gsknnft/bigint-buffer 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -3
- package/build/Release/bigint_buffer.node +0 -0
- package/dist/build/Release/bigint_buffer.node +0 -0
- package/dist/conversion/index.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/{types/dist/dist/index.d.ts → index.d.ts} +1 -2
- package/dist/index.js +360 -333
- package/dist/index.umd.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/conversion/index.d.ts +2 -1
- package/dist/types/conversion/src/ts/converter.d.ts +14 -0
- package/dist/types/conversion/src/ts/index.d.ts +19 -10
- package/dist/types/conversion/test/fixedPoint.test.d.ts +1 -0
- package/dist/types/index.d.ts +1 -2
- package/package.json +153 -132
- package/prebuilds/win32-x64/@gsknnft+bigint-buffer.node +0 -0
- package/scripts/postinstall.cjs +38 -0
- package/build/Release/bigint_buffer.exp +0 -0
- package/build/Release/bigint_buffer.iobj +0 -0
- package/build/Release/bigint_buffer.ipdb +0 -0
- package/build/Release/bigint_buffer.lib +0 -0
- package/build/Release/bigint_buffer.pdb +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.node.recipe +0 -11
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.command.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.read.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.write.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/Cl.items.tlog +0 -2
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/bigint_buffer.lastbuildstate +0 -2
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.command.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.read.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.secondary.1.tlog +0 -5
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.write.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
- package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
- package/build/bigint_buffer.vcxproj +0 -148
- package/build/bigint_buffer.vcxproj.filters +0 -64
- package/build/binding.sln +0 -19
- package/build/config.gypi +0 -525
- package/build/conversion/index.js +0 -18
- package/build/conversion/index.js.map +0 -1
- package/build/conversion/src/ts/fixedPoint/index.d.ts +0 -12
- package/build/conversion/src/ts/fixedPoint/index.js +0 -79
- package/build/conversion/src/ts/fixedPoint/index.js.map +0 -1
- package/build/conversion/src/ts/index.d.ts +0 -169
- package/build/conversion/src/ts/index.js +0 -453
- package/build/conversion/src/ts/index.js.map +0 -1
- package/build/conversion/test/bigintToBase64.test.js +0 -72
- package/build/conversion/test/bigintToBase64.test.js.map +0 -1
- package/build/conversion/test/bigintToBuf.test.js +0 -77
- package/build/conversion/test/bigintToBuf.test.js.map +0 -1
- package/build/conversion/test/bigintToHex.test.js +0 -86
- package/build/conversion/test/bigintToHex.test.js.map +0 -1
- package/build/conversion/test/bigintToText.test.js +0 -63
- package/build/conversion/test/bigintToText.test.js.map +0 -1
- package/build/conversion/test/bufToBigint.test.js +0 -55
- package/build/conversion/test/bufToBigint.test.js.map +0 -1
- package/build/conversion/test/hexToBigint.test.js +0 -56
- package/build/conversion/test/hexToBigint.test.js.map +0 -1
- package/build/conversion/test/hexToBuf.test.js +0 -73
- package/build/conversion/test/hexToBuf.test.js.map +0 -1
- package/build/conversion/test/parseHex.test.js +0 -69
- package/build/conversion/test/parseHex.test.js.map +0 -1
- package/build/conversion/test/textToBuf.test.js +0 -59
- package/build/conversion/test/textToBuf.test.js.map +0 -1
- package/build/index.js +0 -242
- package/build/index.js.map +0 -1
- package/dist/types/conversion/src/ts/fixedPoint/index.d.ts +0 -12
- package/dist/types/dist/dist/conversion/conversion/index.d.ts +0 -1
- package/src/bigint-buffer.test.ts +0 -11
- package/src/conversion/.github/workflows/build-and-test.yml +0 -116
- package/src/conversion/CODE_OF_CONDUCT.md +0 -134
- package/src/conversion/LICENSE +0 -21
- package/src/conversion/README.md +0 -48
- package/src/conversion/docs/README.md +0 -42
- package/src/conversion/docs/functions/base64ToBigint.md +0 -27
- package/src/conversion/docs/functions/bigintToBase64.md +0 -43
- package/src/conversion/docs/functions/bigintToBuf.md +0 -35
- package/src/conversion/docs/functions/bigintToHex.md +0 -43
- package/src/conversion/docs/functions/bigintToText.md +0 -31
- package/src/conversion/docs/functions/bufToBigint.md +0 -25
- package/src/conversion/docs/functions/bufToHex.md +0 -37
- package/src/conversion/docs/functions/bufToText.md +0 -27
- package/src/conversion/docs/functions/hexToBigint.md +0 -29
- package/src/conversion/docs/functions/hexToBuf.md +0 -37
- package/src/conversion/docs/functions/parseHex.md +0 -45
- package/src/conversion/docs/functions/textToBigint.md +0 -27
- package/src/conversion/docs/functions/textToBuf.md +0 -33
- package/src/conversion/docs/functions/toBigIntBE.md +0 -27
- package/src/conversion/docs/functions/toBigIntLE.md +0 -27
- package/src/conversion/docs/functions/toBufferBE.md +0 -33
- package/src/conversion/docs/functions/toBufferLE.md +0 -33
- package/src/conversion/docs/functions/validateBigIntBuffer.md +0 -15
- package/src/conversion/docs/type-aliases/TypedArray.md +0 -11
- package/src/conversion/docs/variables/isNative.md +0 -11
- package/src/conversion/example.cjs +0 -9
- package/src/conversion/example.esm.js +0 -11
- package/src/conversion/index.ts +0 -1
- package/src/conversion/package.json +0 -163
- package/src/conversion/src/docs/index.md +0 -52
- package/src/conversion/src/ts/fixedPoint/index.ts +0 -87
- package/src/conversion/src/ts/index.ts +0 -529
- package/src/conversion/test/bigintToBase64.test.ts +0 -37
- package/src/conversion/test/bigintToBuf.test.ts +0 -43
- package/src/conversion/test/bigintToHex.test.ts +0 -52
- package/src/conversion/test/bigintToText.test.ts +0 -30
- package/src/conversion/test/bufToBigint.test.ts +0 -20
- package/src/conversion/test/hexToBigint.test.ts +0 -22
- package/src/conversion/test/hexToBuf.test.ts +0 -39
- package/src/conversion/test/parseHex.test.ts +0 -35
- package/src/conversion/test/setup.test.ts +0 -9
- package/src/conversion/test/textToBuf.test.ts +0 -26
- package/src/conversion/tsconfig.json +0 -57
- package/src/conversion/tsconfig.rollup.json +0 -9
- package/src/conversion/typedoc.json +0 -5
- package/src/conversion/types/bindings.d.t.s +0 -4
- package/src/conversion/vite.config.ts +0 -10
- package/src/conversion/vitest.config.ts +0 -15
- package/src/index.bench.ts +0 -206
- package/src/index.spec.ts +0 -318
- package/src/index.ts +0 -215
package/README.md
CHANGED
|
@@ -5,7 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
Secure BigInt ⇆ Buffer conversion with native bindings, browser fallbacks, and the `bigint-conversion` helper APIs built in. This is the actively maintained fork of the original `bigint-buffer`.
|
|
7
7
|
|
|
8
|
-
**Upgrade notice:**
|
|
8
|
+
**Upgrade notice:** The current 1.4.7 line ships chunked, allocation-free BE/LE converters (Buffer.read/writeBigUInt64* when available) that are fuzzed across empty, tiny, and huge buffers, alongside FixedPoint utilities and packaged native bindings. CI-verified for Node 20–24. Upgrade for the fastest conversions and consistent behaviour across environments.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Migration Guide
|
|
13
|
+
|
|
14
|
+
- If upgrading from legacy `bigint-buffer`, switch all imports to `@gsknnft/bigint-buffer`.
|
|
15
|
+
- All helpers are now available as named exports (no default export).
|
|
16
|
+
- For Electron, ensure the native binary is included in `extraResources` or `asarUnpack` so it ends up under `resources/app.asar.unpacked/node_modules/@gsknnft/bigint-buffer/build/Release/`.
|
|
17
|
+
- If your packager relocates files, set `BIGINT_BUFFER_NATIVE_PATH` to the directory containing `build/Release/bigint_buffer.node` before launching the app.
|
|
18
|
+
- For browser, add polyfills for `Buffer`, `path`, and `fs` as needed (see below).
|
|
19
|
+
- ESM, CJS, and TypeScript types are all supported out of the box.
|
|
20
|
+
|
|
21
|
+
---
|
|
9
22
|
|
|
10
23
|
[](https://www.npmjs.com/package/@gsknnft/bigint-buffer)
|
|
11
24
|
[](https://nodejs.org)
|
|
@@ -52,6 +65,34 @@ const sum = addFixedPoint(fp, fp); // Add two FixedPoints
|
|
|
52
65
|
const avg = averageFixedPoint([fp, fp]); // Average FixedPoints
|
|
53
66
|
```
|
|
54
67
|
|
|
68
|
+
// Browser usage (with polyfills)
|
|
69
|
+
import { toBigIntBE } from "@gsknnft/bigint-buffer";
|
|
70
|
+
// Polyfill Buffer if needed:
|
|
71
|
+
// import { Buffer } from "buffer";
|
|
72
|
+
|
|
73
|
+
// CJS usage
|
|
74
|
+
const { toBigIntBE } = require("@gsknnft/bigint-buffer");
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Performance
|
|
78
|
+
- BE/LE conversions now stream bytes directly from buffers (64-bit chunks via Buffer.read/writeBigUInt64* when available) with no intermediate hex copies.
|
|
79
|
+
- JS fallback matches the native binding semantics and is exercised against empty, tiny, and very large inputs in CI.
|
|
80
|
+
- Native bindings still load automatically when present; the optimized fallback keeps browser and non-native runtimes fast.
|
|
81
|
+
- Browser bundlers must polyfill Node built-ins: add a node polyfill plugin (e.g. `rollup-plugin-polyfill-node`) or explicit aliases for `buffer`, `path`, and `fs` so the fallback loader can resolve.
|
|
82
|
+
|
|
83
|
+
### Pushing Performance Further
|
|
84
|
+
- For very large buffers, consider enabling the native binding (included in npm tarball) or adding SIMD/native glue in your host app if you need throughput beyond JS.
|
|
85
|
+
|
|
86
|
+
### Electron Packaging
|
|
87
|
+
- Ensure the native binding ships with your app: add `node_modules/@gsknnft/bigint-buffer/build/Release/bigint_buffer.node` to `extraResources`/`asarUnpack` so it ends up under `resources/app.asar.unpacked/node_modules/@gsknnft/bigint-buffer/build/Release/`.
|
|
88
|
+
- If your packager relocates files, set `BIGINT_BUFFER_NATIVE_PATH` to the directory containing `build/Release/bigint_buffer.node` before launching the app.
|
|
89
|
+
|
|
90
|
+
The loader will check, in order:
|
|
91
|
+
- `dist/build/Release/bigint_buffer.node`
|
|
92
|
+
- `build/Release/bigint_buffer.node`
|
|
93
|
+
- Electron asar-unpacked path
|
|
94
|
+
- `BIGINT_BUFFER_NATIVE_PATH` (if set)
|
|
95
|
+
|
|
55
96
|
### Conversion Utilities
|
|
56
97
|
```ts
|
|
57
98
|
import { conversionUtils } from "@gsknnft/bigint-buffer";
|
|
@@ -61,6 +102,10 @@ const hex = conversionUtils.bigintToHex(123456789n, true); // '0x...' format
|
|
|
61
102
|
const text = conversionUtils.bigintToText(123456789n);
|
|
62
103
|
```
|
|
63
104
|
|
|
105
|
+
// All helpers are available as named exports:
|
|
106
|
+
import { bigintToBuf, bufToBigint, bigintToHex, hexToBigint } from "@gsknnft/bigint-buffer";
|
|
107
|
+
```
|
|
108
|
+
|
|
64
109
|
---
|
|
65
110
|
|
|
66
111
|
## Runtime
|
|
@@ -88,11 +133,12 @@ npm run rebuild:native # rebuild the N-API binding
|
|
|
88
133
|
- Core: `toBigIntBE/LE`, `toBufferBE/LE`, `validateBigIntBuffer`, `isNative`
|
|
89
134
|
- Conversion: `bigintToBuf`, `bufToBigint`, `bigintToHex`, `hexToBigint`, `bigintToText`, `textToBigint`, `bigintToBase64`, `base64ToBigint`, `bufToHex`, `hexToBuf`, `textToBuf`, `bufToText`, `parseHex`
|
|
90
135
|
|
|
136
|
+
All helpers are available as named exports in both ESM and CJS. TypeScript types are included.
|
|
137
|
+
|
|
91
138
|
All helpers are endian-safe and validated across Node and browser builds.
|
|
92
139
|
|
|
93
140
|
---
|
|
94
141
|
|
|
95
|
-
|
|
96
|
-
- Version: 1.4.5 (FixedPoint, native bindings out-of-the-box, improved JS fallback)
|
|
142
|
+
- Version: 1.4.7 (FixedPoint, native bindings out-of-the-box, improved JS fallback, robust loader, and stable exports)
|
|
97
143
|
- Node: 20+ (tested through 24 LTS under CI)
|
|
98
144
|
- Issues: https://github.com/gsknnft/bigint-buffer/issues
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty
|
|
1
|
+
"use strict";var $=Object.create;var m=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var O=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of j(e))!U.call(t,o)&&o!==n&&m(t,o,{get:()=>e[o],enumerable:!(r=k(e,o))||r.enumerable});return t};var v=(t,e,n)=>(n=t!=null?$(A(t)):{},O(e||!t||!t.__esModule?m(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let E=!1,l,B;const I=typeof globalThis<"u"&&typeof globalThis.document<"u";let s,h;typeof process<"u"&&process.versions?.node&&!I&&(s=require("path"),h=require("fs"));const T=()=>{if(s)try{const t=require.resolve("@gsknnft/bigint-buffer/package.json");return s.dirname(t)}catch{return}},W=()=>{if(!s)return[];const t=new Set,e=o=>{if(!o)return;const i=s.resolve(o);t.has(i)||t.add(i)},n=T(),r=typeof process<"u"&&process.resourcesPath;return e(process.env?.BIGINT_BUFFER_NATIVE_PATH),e(n),e(n?s.join(n,"dist"):void 0),e(r?s.join(r,"app.asar.unpacked","node_modules","@gsknnft","bigint-buffer"):void 0),e(s.resolve(__dirname,"..")),e(s.resolve(__dirname,"../..")),e(s.resolve(__dirname,"../../..")),e(s.resolve(__dirname,"../../../..")),e(s.resolve(__dirname,"../../../../..")),Array.from(t)},q=()=>{if(!(!s||!h))for(const t of W()){const e=s.join(t,"build","Release","bigint_buffer.node");if(h.existsSync(e))return t}},D=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){const e=t.default;if(typeof e=="function")return e;if(e&&typeof e=="object"&&typeof e.default=="function")return e.default}throw new TypeError("bindings is not a function")},H=()=>{if(s)try{const t=require("node-gyp-build"),e=T();return e?t(e):void 0}catch(t){B=t;return}};function _(){const t=H();if(t)return t;try{const e=require("bindings"),n=D(e),r=q();return n(r?{bindings:"bigint_buffer",module_root:r}:"bigint_buffer")}catch(e){B=e;return}}I||(l=_(),E=l!==void 0,!E&&B!==void 0&&process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL!=="1"&&console.warn("bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",B));l===void 0&&(l={toBigInt:(t,e=!0)=>{const n=Buffer.from(t);e||n.reverse();const r=n.toString("hex");return r.length===0?0n:BigInt(`0x${r}`)},fromBigInt:(t,e,n=!0)=>{const r=t.toString(16),o=e.length,i=r.padStart(o*2,"0").slice(0,o*2),c=Buffer.from(i,"hex");return n||c.reverse(),c.copy(e),e}});I||_();function y(t,e=!1,n){const r=t.match(/^(0x)?([\da-fA-F]+)$/);if(r==null)throw new RangeError("input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'");let o=r[2];return e?"0x"+o:o}function V(t,e=!1,n){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return y(t.toString(16),e)}function G(t){return BigInt(y(t,!0))}const x=9,M=/^-?0x[0-9a-f]+$/i,b="0x0",X=t=>t.startsWith("0x")||t.startsWith("0X")?t:`0x${t}`,p=t=>{if(t===0n)return b;const e=t<0n,n=e?-t:t,r=V(n);return`${e?"-":""}0x${r}`},u=t=>{if(!t)return 0n;const e=t.trim();if(e.length===0)return 0n;const n=e.startsWith("-"),r=n?e.slice(1):e,o=X(r),i=G(o);return n?-i:i};function C(t,e=x){if(!Number.isFinite(t))return b;const n=10n**BigInt(e),r=BigInt(Math.round(t*Number(n)));return p(r)}function z(t,e=9){if(!t)return 0;const n=t.trim();if(n.length===0)return 0;const r=n.startsWith("-"),o=r?n.slice(1):n,i=r?-BigInt(o):BigInt(o),c=10**e;return Number(i)/c}function Z(t,e){return p(u(t)+u(e))}function J(t,e){return p(u(t)-u(e))}function K(t){if(t.length===0)return b;const e=t.reduce((n,r)=>n+u(r),0n);return p(e/BigInt(t.length))}function Q(t,e){const n=u(t)-u(e);return n===0n?0:n>0n?1:-1}function Y(t){return u(t)}const tt=typeof Buffer.prototype.readBigUInt64LE=="function",et=typeof Buffer.prototype.readBigUInt64BE=="function",nt=typeof Buffer.prototype.writeBigUInt64LE=="function",rt=typeof Buffer.prototype.writeBigUInt64BE=="function",ot=tt?(t,e)=>t.readBigUInt64LE(e):(t,e)=>{let n=0n;for(let r=7;r>=0;r--)n=(n<<8n)+BigInt(t[e+r]);return n},it=et?(t,e)=>t.readBigUInt64BE(e):(t,e)=>{let n=0n;for(let r=0;r<8;r++)n=(n<<8n)+BigInt(t[e+r]);return n},ft=nt?(t,e,n)=>{t.writeBigUInt64LE(n,e)}:(t,e,n)=>{let r=n;for(let o=0;o<8;o++)t[e+o]=Number(r&0xffn),r>>=8n},st=rt?(t,e,n)=>{t.writeBigUInt64BE(n,e)}:(t,e,n)=>{let r=n;for(let o=7;o>=0;o--)t[e+o]=Number(r&0xffn),r>>=8n},ut=t=>{let e=0n,n=1n;const r=t.length,o=r&7;for(let i=0;i<o;i++)e+=BigInt(t[i])*n,n<<=8n;for(let i=o;i<r;i+=8){const c=ot(t,i);e+=c*n,n<<=64n}return e},ct=t=>{const e=t.length;if(e===0)return 0n;let n=0n;const r=e&7;let o=0;if(r!==0)for(;o<r;o++)n=(n<<8n)+BigInt(t[o]);for(;o<e;o+=8){const i=it(t,o);n=(n<<64n)+i}return n},at=(t,e)=>{const n=e.length;let r=t,o=0;const i=n-n%8;for(;o<i;o+=8)ft(e,o,r&0xffffffffffffffffn),r>>=64n;for(;o<n;o++)e[o]=Number(r&0xffn),r>>=8n;return e},dt=(t,e)=>{const n=e.length;let r=t,o=n;const i=n&-8;for(;o>i;)o--,e[o]=Number(r&0xffn),r>>=8n;for(;o>0;o-=8){const c=r&0xffffffffffffffffn;st(e,o-8,c),r>>=64n}return e},gt=t=>{if(t===0n)return 1;let e=t,n=0;for(;e>0n;)n++,e>>=8n;return n},lt={toBigInt:(t,e=!0)=>e?ct(t):ut(t),fromBigInt:(t,e,n=!0)=>n?dt(t,e):at(t,e)},w=typeof globalThis<"u"&&typeof globalThis.document<"u";let f,a;w||(f=require("path"),a=require("fs"));const Bt=()=>{if(!f)return[];const t=S(),e=typeof process<"u"&&process.resourcesPath;return[process.env?.BIGINT_BUFFER_NATIVE_PATH,t,t?f.join(t,"dist"):void 0,e?f.join(e,"app.asar.unpacked","node_modules","@gsknnft","bigint-buffer"):void 0,f.resolve(__dirname,".."),f.resolve(__dirname,"."),f.resolve(__dirname,"../.."),f.resolve(__dirname,"../../.."),f.resolve(__dirname,"../../../..")].filter(n=>!!n)},bt=()=>{if(!(!f||!a))for(const t of Bt()){const e=f.join(t,"build","Release","bigint_buffer.node");if(a.existsSync(e))return t;const n=f.join(t,"dist","build","Release","bigint_buffer.node");if(a.existsSync(n))return f.join(t,"dist")}},pt=()=>{if(f)try{const t=require("node-gyp-build"),e=S();return e?t(e):void 0}catch(t){d=t;return}},ht=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){const e=t.default;if(typeof e=="function")return e;if(e&&typeof e=="object"&&typeof e.default=="function")return e.default}throw new TypeError("bindings is not a function")};let g=lt,d;exports.isNative=!1;const It=()=>{d=void 0;const t=pt();if(t)return t;try{const e=require("bindings"),n=ht(e),r=bt();return n(r?{bindings:"bigint_buffer",module_root:r}:"bigint_buffer")}catch(e){d=d??e;return}};if(!w){const t=It();t!==void 0?(g=t,exports.isNative=!0):d!==void 0&&process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL!=="1"&&console.warn("bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",d)}function N(t){return g.toBigInt(t,!1)}function mt(){try{return N(Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function R(t){return g.toBigInt(t,!0)}function vt(t,e){if(e<0)throw new RangeError("toBufferLE width must be non-negative");const n=e===0?Buffer.alloc(0):Buffer.allocUnsafe(e);return g.fromBigInt(t,n,!1)}function P(t,e){if(e<0)throw new RangeError("toBufferBE width must be non-negative");const n=e===0?Buffer.alloc(0):Buffer.allocUnsafe(e);return g.fromBigInt(t,n,!0)}function F(t){if(t<BigInt(0))throw new Error("bigintToBuf: negative bigint values are not supported");const e=gt(t);return P(t,e)}function L(t){return R(t)}function Et(t){if(t<BigInt(0))throw new Error("bigintToHex: negative bigint values are not supported");const e=t.toString(16);return e.length%2===0?e:"0"+e}function Tt(t){const e=t.startsWith("0x")?t.slice(2):t;return e.length===0?BigInt(0):BigInt(`0x${e}`)}function _t(t){return t.toString(10)}function yt(t){if(!t?.trim())throw new Error("textToBigint: input string cannot be empty");try{return BigInt(t)}catch(e){throw new Error(`textToBigint: invalid decimal string "${t}" ${e instanceof Error?e.message:String(e)}`)}}function xt(t){if(t<BigInt(0))throw new Error("bigintToBase64: negative bigint values are not supported");return F(t).toString("base64")}function wt(t){if(!t?.trim())throw new Error("base64ToBigint: input string cannot be empty");const e=t.trim();if(!/^[A-Za-z0-9+/]+=*$/.test(e))throw new Error("base64ToBigint: invalid base64 string format");const n=Buffer.from(e,"base64");return L(n)}function S(){if(!f)return;try{const e=require.resolve("@gsknnft/bigint-buffer/package.json");return f.dirname(e)}catch{}if(!a)return;let t=__dirname;for(;;){const e=f.join(t,"package.json");if(a.existsSync(e))return t;const n=f.dirname(t);if(n===t)break;t=n}}exports.FIXED_POINT_DECIMALS=x;exports.FIXED_POINT_PATTERN=M;exports.ZERO_FIXED_POINT=b;exports.addFixedPoint=Z;exports.averageFixedPoint=K;exports.base64ToBigint=wt;exports.bigintToBase64=xt;exports.bigintToBuf=F;exports.bigintToHex=Et;exports.bigintToText=_t;exports.bufToBigint=L;exports.compareFixedPoint=Q;exports.fixedPointToBigInt=Y;exports.fromFixedPoint=z;exports.hexToBigint=Tt;exports.subtractFixedPoint=J;exports.textToBigint=yt;exports.toBigIntBE=R;exports.toBigIntLE=N;exports.toBigIntValue=u;exports.toBufferBE=P;exports.toBufferLE=vt;exports.toFixedPoint=C;exports.validateBigIntBuffer=mt;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { conversionUtils };
|
|
1
|
+
export { FIXED_POINT_DECIMALS, FIXED_POINT_PATTERN, ZERO_FIXED_POINT, toFixedPoint, fromFixedPoint, addFixedPoint, subtractFixedPoint, averageFixedPoint, compareFixedPoint, fixedPointToBigInt, toBigIntValue, } from "./conversion/src/ts/index";
|
|
3
2
|
export declare let isNative: boolean;
|
|
4
3
|
/**
|
|
5
4
|
* Convert a little-endian buffer into a BigInt.
|