@gsknnft/bigint-buffer 1.3.2 → 1.4.2

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.
Files changed (106) hide show
  1. package/README.md +123 -126
  2. package/build/Release/bigint_buffer.exp +0 -0
  3. package/build/Release/bigint_buffer.iobj +0 -0
  4. package/build/Release/bigint_buffer.ipdb +0 -0
  5. package/build/Release/bigint_buffer.lib +0 -0
  6. package/build/Release/bigint_buffer.node +0 -0
  7. package/build/Release/bigint_buffer.pdb +0 -0
  8. package/build/Release/obj/bigint_buffer/bigint_buffer.node.recipe +11 -0
  9. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.command.1.tlog +0 -0
  10. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.read.1.tlog +0 -0
  11. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.write.1.tlog +0 -0
  12. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/Cl.items.tlog +2 -0
  13. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/bigint_buffer.lastbuildstate +2 -0
  14. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.command.1.tlog +0 -0
  15. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.read.1.tlog +0 -0
  16. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.secondary.1.tlog +5 -0
  17. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.write.1.tlog +0 -0
  18. package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
  19. package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
  20. package/build/bigint_buffer.vcxproj +148 -0
  21. package/build/bigint_buffer.vcxproj.filters +67 -0
  22. package/build/binding.sln +19 -0
  23. package/build/config.gypi +522 -0
  24. package/dist/index.cjs +1 -205
  25. package/dist/index.js +347 -202
  26. package/dist/index.umd.js +1 -0
  27. package/dist/tsconfig.tsbuildinfo +1 -0
  28. package/dist/types/bigint-buffer.test.d.ts +1 -0
  29. package/dist/types/conversion/index.d.ts +1 -0
  30. package/dist/types/conversion/src/ts/index.d.ts +168 -0
  31. package/dist/types/conversion/test/bigintToBase64.test.d.ts +1 -0
  32. package/dist/types/conversion/test/bigintToBuf.test.d.ts +1 -0
  33. package/dist/types/conversion/test/bigintToHex.test.d.ts +1 -0
  34. package/dist/types/conversion/test/bigintToText.test.d.ts +1 -0
  35. package/dist/types/conversion/test/bufToBigint.test.d.ts +1 -0
  36. package/dist/types/conversion/test/hexToBigint.test.d.ts +1 -0
  37. package/dist/types/conversion/test/hexToBuf.test.d.ts +1 -0
  38. package/dist/types/conversion/test/parseHex.test.d.ts +1 -0
  39. package/dist/types/conversion/test/setup.test.d.ts +1 -0
  40. package/dist/types/conversion/test/textToBuf.test.d.ts +1 -0
  41. package/dist/types/conversion/vite.config.d.ts +2 -0
  42. package/dist/types/conversion/vitest.config.d.ts +2 -0
  43. package/dist/types/dist/dist/conversion/conversion/index.d.ts +1 -0
  44. package/dist/{index.d.ts → types/dist/dist/index.d.ts} +2 -0
  45. package/dist/types/index.bench.d.ts +1 -0
  46. package/dist/types/index.d.ts +80 -0
  47. package/dist/types/index.spec.d.ts +1 -0
  48. package/package.json +83 -49
  49. package/src/bigint-buffer.test.ts +11 -0
  50. package/src/conversion/.github/workflows/build-and-test.yml +116 -0
  51. package/src/conversion/CODE_OF_CONDUCT.md +134 -0
  52. package/src/conversion/LICENSE +21 -0
  53. package/src/conversion/README.md +48 -0
  54. package/src/conversion/docs/README.md +34 -0
  55. package/src/conversion/docs/functions/base64ToBigint.md +27 -0
  56. package/src/conversion/docs/functions/bigintToBase64.md +43 -0
  57. package/src/conversion/docs/functions/bigintToBuf.md +35 -0
  58. package/src/conversion/docs/functions/bigintToHex.md +43 -0
  59. package/src/conversion/docs/functions/bigintToText.md +31 -0
  60. package/src/conversion/docs/functions/bufToBigint.md +25 -0
  61. package/src/conversion/docs/functions/bufToHex.md +37 -0
  62. package/src/conversion/docs/functions/bufToText.md +27 -0
  63. package/src/conversion/docs/functions/hexToBigint.md +29 -0
  64. package/src/conversion/docs/functions/hexToBuf.md +37 -0
  65. package/src/conversion/docs/functions/parseHex.md +45 -0
  66. package/src/conversion/docs/functions/textToBigint.md +27 -0
  67. package/src/conversion/docs/functions/textToBuf.md +33 -0
  68. package/src/conversion/docs/functions/toBigIntBE.md +27 -0
  69. package/src/conversion/docs/functions/toBigIntLE.md +27 -0
  70. package/src/conversion/docs/functions/toBufferBE.md +33 -0
  71. package/src/conversion/docs/functions/toBufferLE.md +33 -0
  72. package/src/conversion/docs/functions/validateBigIntBuffer.md +15 -0
  73. package/src/conversion/docs/type-aliases/TypedArray.md +11 -0
  74. package/src/conversion/docs/variables/isNative.md +11 -0
  75. package/src/conversion/example.cjs +9 -0
  76. package/src/conversion/example.esm.js +11 -0
  77. package/src/conversion/index.ts +1 -0
  78. package/src/conversion/package.json +163 -0
  79. package/src/conversion/src/docs/index.md +47 -0
  80. package/src/conversion/src/ts/index.ts +514 -0
  81. package/src/conversion/test/bigintToBase64.test.ts +37 -0
  82. package/src/conversion/test/bigintToBuf.test.ts +43 -0
  83. package/src/conversion/test/bigintToHex.test.ts +52 -0
  84. package/src/conversion/test/bigintToText.test.ts +30 -0
  85. package/src/conversion/test/bufToBigint.test.ts +20 -0
  86. package/src/conversion/test/hexToBigint.test.ts +22 -0
  87. package/src/conversion/test/hexToBuf.test.ts +39 -0
  88. package/src/conversion/test/parseHex.test.ts +35 -0
  89. package/src/conversion/test/setup.test.ts +9 -0
  90. package/src/conversion/test/textToBuf.test.ts +26 -0
  91. package/src/conversion/tsconfig.json +57 -0
  92. package/src/conversion/tsconfig.rollup.json +9 -0
  93. package/src/conversion/typedoc.json +5 -0
  94. package/src/conversion/types/bindings.d.t.s +4 -0
  95. package/src/conversion/vite.config.ts +10 -0
  96. package/src/conversion/vitest.config.ts +15 -0
  97. package/src/index.bench.ts +5 -6
  98. package/src/index.spec.ts +232 -358
  99. package/src/index.ts +33 -28
  100. package/.travis.yml +0 -51
  101. package/PR_TEMPLATE.md +0 -53
  102. package/dist/node.js +0 -94
  103. package/karma.conf.js +0 -62
  104. package/rollup.cjs.config.js +0 -8
  105. package/rollup.esm.config.js +0 -15
  106. package/tsconfig.json +0 -20
package/src/index.ts CHANGED
@@ -1,21 +1,24 @@
1
+ // Export robust Buffer/BigInt methods at top level
2
+ import * as conversionUtils from "./conversion/src/ts/index";
3
+ export { conversionUtils };
1
4
 
2
5
  interface ConverterInterface {
3
6
  toBigInt(buf: Buffer, bigEndian?: boolean): bigint;
4
- fromBigInt(num: BigInt, buf: Buffer, bigEndian?: boolean): Buffer;
7
+ fromBigInt(num: bigint, buf: Buffer, bigEndian?: boolean): Buffer;
5
8
  }
6
9
 
7
- declare var process: {browser: boolean;};
8
-
9
10
  let converter: ConverterInterface;
10
11
  export let isNative = false;
11
12
 
12
- if (!process.browser) {
13
+ if (typeof window === "undefined") {
13
14
  try {
14
- converter = require('bindings')('bigint_buffer');
15
- isNative = !process.browser && converter !== undefined;
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
16
+ converter = require("bindings")("bigint_buffer");
17
+ isNative = converter !== undefined;
16
18
  } catch (e) {
17
19
  console.warn(
18
- 'bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
20
+ "bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)", e
21
+ );
19
22
  }
20
23
  }
21
24
 
@@ -25,10 +28,10 @@ if (!process.browser) {
25
28
  * @returns A BigInt with the little-endian representation of buf.
26
29
  */
27
30
  export function toBigIntLE(buf: Buffer): bigint {
28
- if (process.browser || converter === undefined) {
31
+ if (typeof window !== "undefined" || converter === undefined) {
29
32
  const reversed = Buffer.from(buf);
30
33
  reversed.reverse();
31
- const hex = reversed.toString('hex');
34
+ const hex = reversed.toString("hex");
32
35
  if (hex.length === 0) {
33
36
  return BigInt(0);
34
37
  }
@@ -52,8 +55,8 @@ export function validateBigIntBuffer(): boolean {
52
55
  * @returns A BigInt with the big-endian representation of buf.
53
56
  */
54
57
  export function toBigIntBE(buf: Buffer): bigint {
55
- if (process.browser || converter === undefined) {
56
- const hex = buf.toString('hex');
58
+ if (typeof window !== "undefined" || converter === undefined) {
59
+ const hex = buf.toString("hex");
57
60
  if (hex.length === 0) {
58
61
  return BigInt(0);
59
62
  }
@@ -69,10 +72,12 @@ export function toBigIntBE(buf: Buffer): bigint {
69
72
  * @returns A little-endian buffer representation of num.
70
73
  */
71
74
  export function toBufferLE(num: bigint, width: number): Buffer {
72
- if (process.browser || converter === undefined) {
75
+ if (typeof window !== "undefined" || converter === undefined) {
73
76
  const hex = num.toString(16);
74
- const buffer =
75
- Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
77
+ const buffer = Buffer.from(
78
+ hex.padStart(width * 2, "0").slice(0, width * 2),
79
+ "hex"
80
+ );
76
81
  buffer.reverse();
77
82
  return buffer;
78
83
  }
@@ -87,9 +92,9 @@ export function toBufferLE(num: bigint, width: number): Buffer {
87
92
  * @returns A big-endian buffer representation of num.
88
93
  */
89
94
  export function toBufferBE(num: bigint, width: number): Buffer {
90
- if (process.browser || converter === undefined) {
95
+ if (typeof window !== "undefined" || converter === undefined) {
91
96
  const hex = num.toString(16);
92
- return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
97
+ return Buffer.from(hex.padStart(width * 2, "0").slice(0, width * 2), "hex");
93
98
  }
94
99
  return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
95
100
  }
@@ -104,7 +109,7 @@ export function toBufferBE(num: bigint, width: number): Buffer {
104
109
  */
105
110
  export function bigintToBuf(num: bigint): Buffer {
106
111
  if (num < BigInt(0)) {
107
- throw new Error('bigintToBuf: negative bigint values are not supported');
112
+ throw new Error("bigintToBuf: negative bigint values are not supported");
108
113
  }
109
114
  if (num === BigInt(0)) {
110
115
  return Buffer.from([0]);
@@ -132,11 +137,11 @@ export function bufToBigint(buf: Buffer): bigint {
132
137
  */
133
138
  export function bigintToHex(num: bigint): string {
134
139
  if (num < BigInt(0)) {
135
- throw new Error('bigintToHex: negative bigint values are not supported');
140
+ throw new Error("bigintToHex: negative bigint values are not supported");
136
141
  }
137
142
  const hex = num.toString(16);
138
143
  // Ensure even length for proper byte representation
139
- return hex.length % 2 === 0 ? hex : '0' + hex;
144
+ return hex.length % 2 === 0 ? hex : "0" + hex;
140
145
  }
141
146
 
142
147
  /**
@@ -146,7 +151,7 @@ export function bigintToHex(num: bigint): string {
146
151
  */
147
152
  export function hexToBigint(hex: string): bigint {
148
153
  // Remove '0x' prefix if present
149
- const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
154
+ const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
150
155
  if (cleanHex.length === 0) {
151
156
  return BigInt(0);
152
157
  }
@@ -169,12 +174,12 @@ export function bigintToText(num: bigint): string {
169
174
  */
170
175
  export function textToBigint(text: string): bigint {
171
176
  if (!text?.trim()) {
172
- throw new Error('textToBigint: input string cannot be empty');
177
+ throw new Error("textToBigint: input string cannot be empty");
173
178
  }
174
179
  try {
175
180
  return BigInt(text);
176
181
  } catch (e) {
177
- throw new Error(`textToBigint: invalid decimal string "${text}"`);
182
+ throw new Error(`textToBigint: invalid decimal string "${text}" ${e instanceof Error ? e.message : String(e)}`);
178
183
  }
179
184
  }
180
185
 
@@ -185,10 +190,10 @@ export function textToBigint(text: string): bigint {
185
190
  */
186
191
  export function bigintToBase64(num: bigint): string {
187
192
  if (num < BigInt(0)) {
188
- throw new Error('bigintToBase64: negative bigint values are not supported');
193
+ throw new Error("bigintToBase64: negative bigint values are not supported");
189
194
  }
190
195
  const buf = bigintToBuf(num);
191
- return buf.toString('base64');
196
+ return buf.toString("base64");
192
197
  }
193
198
 
194
199
  /**
@@ -198,13 +203,13 @@ export function bigintToBase64(num: bigint): string {
198
203
  */
199
204
  export function base64ToBigint(base64: string): bigint {
200
205
  if (!base64?.trim()) {
201
- throw new Error('base64ToBigint: input string cannot be empty');
206
+ throw new Error("base64ToBigint: input string cannot be empty");
202
207
  }
203
208
  // Trim whitespace and validate base64 format (allows padding)
204
209
  const cleaned = base64.trim();
205
210
  if (!/^[A-Za-z0-9+/]+=*$/.test(cleaned)) {
206
- throw new Error('base64ToBigint: invalid base64 string format');
211
+ throw new Error("base64ToBigint: invalid base64 string format");
207
212
  }
208
- const buf = Buffer.from(cleaned, 'base64');
213
+ const buf = Buffer.from(cleaned, "base64");
209
214
  return bufToBigint(buf);
210
- }
215
+ }
package/.travis.yml DELETED
@@ -1,51 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - node
4
- - '10'
5
- sudo : false
6
- env:
7
- global:
8
- - DISPLAY=:99.0
9
- - secure: SQDlqZZTkrbRW/wYLPgEwFQpkSrs65MiF0JgO+cwSCAG1m0c7EuBTzvttAXzKK+coZXjd2+QJcAOBi6YUP84OdSf31PojIy4/SLuZxuFQa0sGey+8oSDqgMntpSthO9nom0s6u2vB61IVfcRVIUNv5L3J5i5ZIGlKGgC2MIBzsnhx0L//eyh/bLszR27ajCT7RG+pnqpk010eaDtRabOJTtO0C2kbBQoW2SvJIisDsRj5zqVyl03pZJQQAJeseiNlLokucrgitDWENE+tEJ2w1x1yl+901tgU+BIi4iLQTezcSAxnF149U/Nof7LpCba+1Y+PPh1SRpO4100CT6O46qW0O1keVfTmZL/R3ghBM6H0AtV1s48k/XCpHV9CGwxjBHoCN1kKvSO9B1BJuAdlmgobOEdze+X81nilSBhBmYMI1XPLbXqTo2ImfaFeDzveuPJH6+HMCc+8sDlhgLcrOiteAsY8RsI0ngBkutsWWv7QcRq29e4VX2eBy0j1VJZNf0FPAcKpWF8eIaPw7Z0CuWMs2hM0v0ns58jDcOL+1k4kKyJ10OOmANqNX+NZYRJJ05dd/VMrlh37teARI64PFSG6eIoCniW0GtrUcpX4KhqpaRSUDpsKvncXNdNydumMyMQjeQqyHqahvIE2ONVXXELD2T/EV6TpazDR5KSSo0=
10
- - secure: ZwKAlaNZ8liLknkAfFN+TztrILi8Q06AknHUj0Zd+9PjzD5n6tpzp5g1nE0MEvF9bqkGkwf6vwWJVKcSXWM9J4a2pfoLe9wsVcjq+AkmWnZG0zV26ie3UPoa8d/PezRtxz+4vErvQcOqnESVPJAqeWCt0fH1WvnEcjaY3BYyyDbWwAPamWr/v9c4ZLKxJqJmgtczMCrRahd6Dz+HGGJ9BehhOXtse+rT5qFI6w2SMXaisDzk2twMu0fK1I66G2IsesIKErPigCeEPahsP2yu831+S18YvxJtao7tXpluMBf+RNhD9eI1evUu6IxpF419ANDJ7BpJ8uGfRVzIz9kQIAmcy/1s7g3otT633XngUfNYDisUeLJ39plclOHw+sVeLL49Xa9k+/U0CzlOThNlCj0hY2uJW3Ot9NjvKDjdR/UkgEBCl6nIDAnRQk9xSJ4ws1f9Yp5CgEXcXvu7077i6O8vG7+k08qHDSkxEEwQjB2PwjhcPfg9ieAwafblM3szYwzblL4UpROp/L/XmmzjR/cOVrS93RIpeLqDr2CCMKGd0GoOFtDse7u43SJMIAZ+O5DNtNpqIQ22V13p4P3L2C1RV3cjE55luEYVR1JZ7AzaxD+hZu2zcU2301MuSgFLTKMEu43HV1tPJ6QtCcSf+kH/LK/TPfTLveW23xkkZM0=
11
- matrix:
12
- - TEST_SUITE=test:node
13
- addons:
14
- chrome: stable
15
- services:
16
- - xvfb
17
- cache:
18
- directories:
19
- - $HOME/.npm
20
- matrix:
21
- fast_finish: true
22
- include:
23
- - os: linux
24
- node_js: '10'
25
- env: TEST_SUITE=test:browser
26
- - os: windows
27
- node_js: '10'
28
- env: TEST_SUITE=test:node
29
- script: npm run $TEST_SUITE
30
- before_deploy:
31
- - npm pack
32
- deploy:
33
- - provider: releases
34
- api_key: "$GITHUB_TOKEN"
35
- file_glob: true
36
- file: bigint-buffer-*.tgz
37
- skip_cleanup: true
38
- on:
39
- branch: master
40
- node: '10'
41
- condition: "$TEST_SUITE = test:node"
42
- tags: true
43
- - provider: npm
44
- api_key: "$NPM_TOKEN"
45
- skip_cleanup: true
46
- email: mwei@cs.ucsd.edu
47
- on:
48
- branch: master
49
- node: '10'
50
- condition: "$TEST_SUITE = test:node"
51
- tags: true
package/PR_TEMPLATE.md DELETED
@@ -1,53 +0,0 @@
1
-
2
- ---
3
-
4
- ## 📑 PR Template (PULL_REQUEST_TEMPLATE.md)
5
-
6
- ```markdown
7
- # Pull Request for @diamondprotocol/bigint-buffer
8
-
9
- Thank you for contributing to **@diamondprotocol/bigint-buffer**! Please fill out the details below.
10
-
11
- ---
12
-
13
- ## 📋 What does this PR do?
14
-
15
- <!--
16
- - Security fix? (describe vulnerability/CVE)
17
- - Feature addition? (describe feature, reason, protocol impact)
18
- - Bug fix? (link to test/issue)
19
- - CI/test/benchmark improvements?
20
- - Documentation or README changes?
21
- -->
22
-
23
- ---
24
-
25
- ## 🚦 Security & Breaking Change Checklist
26
-
27
- - [ ] I have **added or updated tests** for this change.
28
- - [ ] I have **run all test suites** and verified that everything passes.
29
- - [ ] If changing buffer size limits or any protocol-relevant logic:
30
- - [ ] I have documented the reason and added a warning in README.
31
- - [ ] I have included reference(s) to any relevant CVEs or advisories.
32
-
33
- ---
34
-
35
- ## 💬 Additional Notes
36
-
37
- <!--
38
- - Did you check compatibility with Solana, Jito, Vera, or protocol X?
39
- - Is there any API break?
40
- - Link to related issues, discussions, or upstream PRs if any.
41
- -->
42
-
43
- ---
44
-
45
- ## 🔗 Related Links
46
-
47
- - [bigint-buffer on npm](https://www.npmjs.com/package/bigint-buffer)
48
- - [Original repo](https://github.com/no2chem/bigint-buffer)
49
- - [Current security advisory](https://github.com/advisories/GHSA-3gc7-fjrx-p6mg)
50
-
51
- ---
52
-
53
- *Thank you for helping keep supply-chain infra safe and strong!*
package/dist/node.js DELETED
@@ -1,94 +0,0 @@
1
- var __importDefault = (undefined && undefined.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.isNative = void 0;
6
- exports.toBigIntLE = toBigIntLE;
7
- exports.validateBigIntBuffer = validateBigIntBuffer;
8
- exports.toBigIntBE = toBigIntBE;
9
- exports.toBufferLE = toBufferLE;
10
- exports.toBufferBE = toBufferBE;
11
- // etc.
12
- const bindings_1 = __importDefault(require("bindings"));
13
- (0, bindings_1.default)('bigint_buffer');
14
- let converter;
15
- exports.isNative = false;
16
- {
17
- try {
18
- converter = require('bindings')('bigint_buffer');
19
- exports.isNative = !false && converter !== undefined;
20
- }
21
- catch (e) {
22
- console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
23
- }
24
- }
25
- /**
26
- * Convert a little-endian buffer into a BigInt.
27
- * @param buf The little-endian buffer to convert
28
- * @returns A BigInt with the little-endian representation of buf.
29
- */
30
- function toBigIntLE(buf) {
31
- if (converter === undefined) {
32
- const reversed = Buffer.from(buf);
33
- reversed.reverse();
34
- const hex = reversed.toString('hex');
35
- if (hex.length === 0) {
36
- return BigInt(0);
37
- }
38
- return BigInt(`0x${hex}`);
39
- }
40
- return converter.toBigInt(buf, false);
41
- }
42
- function validateBigIntBuffer() {
43
- try {
44
- const test = toBigIntLE(Buffer.from([0x01, 0x00]));
45
- return test === BigInt(1);
46
- }
47
- catch {
48
- return false;
49
- }
50
- }
51
- /**
52
- * Convert a big-endian buffer into a BigInt
53
- * @param buf The big-endian buffer to convert.
54
- * @returns A BigInt with the big-endian representation of buf.
55
- */
56
- function toBigIntBE(buf) {
57
- if (converter === undefined) {
58
- const hex = buf.toString('hex');
59
- if (hex.length === 0) {
60
- return BigInt(0);
61
- }
62
- return BigInt(`0x${hex}`);
63
- }
64
- return converter.toBigInt(buf, true);
65
- }
66
- /**
67
- * Convert a BigInt to a little-endian buffer.
68
- * @param num The BigInt to convert.
69
- * @param width The number of bytes that the resulting buffer should be.
70
- * @returns A little-endian buffer representation of num.
71
- */
72
- function toBufferLE(num, width) {
73
- if (converter === undefined) {
74
- const hex = num.toString(16);
75
- const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
76
- buffer.reverse();
77
- return buffer;
78
- }
79
- // Allocation is done here, since it is slower using napi in C
80
- return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
81
- }
82
- /**
83
- * Convert a BigInt to a big-endian buffer.
84
- * @param num The BigInt to convert.
85
- * @param width The number of bytes that the resulting buffer should be.
86
- * @returns A big-endian buffer representation of num.
87
- */
88
- function toBufferBE(num, width) {
89
- if (converter === undefined) {
90
- const hex = num.toString(16);
91
- return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
92
- }
93
- return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
94
- }
package/karma.conf.js DELETED
@@ -1,62 +0,0 @@
1
- const webpack = require('webpack')
2
- module.exports = function (config) {
3
- const configuration = {
4
- browserNoActivityTimeout: 120000,
5
- frameworks: ['mocha'],
6
- files: [
7
- './build/src/*.spec.js'
8
- ],
9
- preprocessors: {
10
- './build/src//*.spec.js': ['webpack', 'env']
11
- },
12
- webpack : {
13
- mode: "production",
14
- devtool: 'inline-source-map',
15
- module: {
16
- // Suppress warning from mocha: "Critical dependency: the request of a dependency is an expression"
17
- // @see https://webpack.js.org/configuration/module/#module-contexts
18
- exprContextCritical: false
19
- },
20
- // Suppress fatal error: Cannot resolve module 'fs'
21
- // @relative https://github.com/pugjs/pug-loader/issues/8
22
- // @see https://github.com/webpack/docs/wiki/Configuration#node
23
- node: {
24
- fs: 'empty',
25
- bindings: 'empty'
26
- },
27
- resolve: {
28
- extensions: ['.ts', '.js', '.json']
29
- }, plugins: [ new webpack.NormalModuleReplacementPlugin(
30
- /\.\/index/,
31
- './build/src/bromwser.js'
32
- ),
33
- ],
34
- },
35
- singleRun: true,
36
- reporters: ['mocha'],
37
- plugins: [
38
- 'karma-chrome-launcher',
39
- 'karma-env-preprocessor',
40
- 'karma-webpack',
41
- 'karma-mocha',
42
- 'karma-mocha-reporter'
43
- ],
44
- mime: {
45
- 'text/x-typescript': ['ts','tsx']
46
- },
47
- browsers: ['Chrome'],
48
- customLaunchers: {
49
- Chrome_travis_ci: {
50
- base: 'Chrome',
51
- flags: ['--no-sandbox']
52
- }
53
- }
54
- };
55
-
56
- if(process.env.TRAVIS) {
57
- configuration.browsers = ['Chrome_travis_ci'];
58
- }
59
-
60
- config.set(configuration);
61
- }
62
-
@@ -1,8 +0,0 @@
1
- export default {
2
- input: 'build/src/index.js',
3
- output: {
4
- file: 'dist/index.cjs',
5
- format: 'cjs',
6
- },
7
- external: ['bindings'],
8
- };
@@ -1,15 +0,0 @@
1
- import replace from '@rollup/plugin-replace';
2
-
3
- export default {
4
- input: 'build/src/index.js',
5
- output: {
6
- file: 'dist/index.js',
7
- format: 'esm'
8
- },
9
- external: ['bindings'],
10
- plugins: [
11
- replace({
12
- 'process.browser': 'false'
13
- })
14
- ]
15
- };
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./node_modules/gts/tsconfig-google.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "rootDir": ".",
6
- "outDir": "build",
7
- "target" : "esnext",
8
- "lib" : [ "esnext" ],
9
- "sourceMap": true
10
- },
11
- "include": [
12
- "src/*.ts",
13
- "src/**/*.ts",
14
- "test/*.ts",
15
- "test/**/*.ts"
16
- ],
17
- "exclude": [
18
- "node_modules"
19
- ]
20
- }