@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.spec.ts CHANGED
@@ -1,444 +1,318 @@
1
- import 'mocha';
2
- declare var process: {browser: boolean;};
3
-
4
- import * as chai from 'chai';
5
- import * as path from 'path';
6
-
7
- const lib = process.browser ?
8
- require('../../dist/index.js') :
9
- require(path.join(__dirname, '../../dist/index.cjs'));
10
- const toBigIntBE = lib.toBigIntBE;
11
- const toBigIntLE = lib.toBigIntLE;
12
- const toBufferBE = lib.toBufferBE;
13
- const toBufferLE = lib.toBufferLE;
14
-
15
- // Needed for should.not.be.undefined.
16
- /* tslint:disable:no-unused-expression */
17
-
18
- chai.should();
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+
3
+ let lib: Awaited<typeof import("./index.js")>;
4
+ let toBigIntBE: Awaited<typeof import("./index.js")>["toBigIntBE"];
5
+ let toBigIntLE: Awaited<typeof import("./index.js")>["toBigIntLE"];
6
+ let toBufferBE: Awaited<typeof import("./index.js")>["toBufferBE"];
7
+ let toBufferLE: Awaited<typeof import("./index.js")>["toBufferLE"];
8
+ // Removed unused variable assignments to fix lint errors
9
+
10
+ beforeAll(async () => {
11
+ lib = await import("./index.js");
12
+ toBigIntBE = lib.toBigIntBE;
13
+ toBigIntLE = lib.toBigIntLE;
14
+ toBufferBE = lib.toBufferBE;
15
+ toBufferLE = lib.toBufferLE;
16
+ // Removed assignments to undeclared variables
17
+ });
19
18
 
20
19
  const assertEquals = (n0: bigint, n1: bigint) => {
21
- chai.expect(n0.toString(16)).to.equal(n1.toString(16));
20
+ expect(n0.toString(16)).toBe(n1.toString(16));
22
21
  };
23
22
 
24
- describe('Try buffer conversion (little endian)', () => {
25
- it('0 should equal 0n', () => {
26
- assertEquals(toBigIntLE(Buffer.from([0])), BigInt('0'));
23
+ describe("Try buffer conversion (little endian)", () => {
24
+ it("0 should equal 0n", () => {
25
+ assertEquals(toBigIntLE(Buffer.from([0])), BigInt("0"));
27
26
  });
28
27
 
29
- it('1 should equal 1n', async () => {
30
- assertEquals(toBigIntLE(Buffer.from([1])), BigInt('1'));
28
+ it("1 should equal 1n", async () => {
29
+ assertEquals(toBigIntLE(Buffer.from([1])), BigInt("1"));
31
30
  });
32
31
 
33
- it('0xdead should equal 0xdeadn', async () => {
34
- assertEquals(toBigIntLE(Buffer.from([0xad, 0xde])), BigInt(`0xdead`));
32
+ it("0xdead should equal 0xdeadn", async () => {
33
+ assertEquals(toBigIntLE(Buffer.from([0xad, 0xde])), BigInt("0xdead"));
35
34
  });
36
35
 
37
- it('0xdeadbeef should equal 0xdeadbeefn', async () => {
36
+ it("0xdeadbeef should equal 0xdeadbeefn", async () => {
38
37
  assertEquals(
39
- toBigIntLE(Buffer.from([0xef, 0xbe, 0xad, 0xde])),
40
- BigInt(`0xdeadbeef`));
38
+ toBigIntLE(Buffer.from([0xef, 0xbe, 0xad, 0xde])),
39
+ BigInt("0xdeadbeef")
40
+ );
41
41
  });
42
42
 
43
- it('0xbadc0ffee0 should equal 0xbadc0ffee0n', async () => {
43
+ it("0xbadc0ffee0 should equal 0xbadc0ffee0n", async () => {
44
44
  assertEquals(
45
- toBigIntLE(Buffer.from([0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
46
- BigInt(`0xbadc0ffee0`));
45
+ toBigIntLE(Buffer.from([0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
46
+ BigInt("0xbadc0ffee0")
47
+ );
47
48
  });
48
49
 
49
- it('0xbadc0ffee0dd should equal 0xbadc0ffee0ddn', async () => {
50
+ it("0xbadc0ffee0dd should equal 0xbadc0ffee0ddn", async () => {
50
51
  assertEquals(
51
- toBigIntLE(Buffer.from([0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
52
- BigInt(`0xbadc0ffee0dd`));
52
+ toBigIntLE(Buffer.from([0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
53
+ BigInt("0xbadc0ffee0dd")
54
+ );
53
55
  });
54
56
 
55
- it('0xbadc0ffee0ddf0 should equal 0xbadc0ffee0ddf0n', async () => {
57
+ it("0xbadc0ffee0ddf0 should equal 0xbadc0ffee0ddf0n", async () => {
56
58
  assertEquals(
57
- toBigIntLE(Buffer.from([0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
58
- BigInt(`0xbadc0ffee0ddf0`));
59
+ toBigIntLE(Buffer.from([0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
60
+ BigInt("0xbadc0ffee0ddf0")
61
+ );
59
62
  });
60
63
 
61
- it('0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn', async () => {
64
+ it("0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn", async () => {
62
65
  assertEquals(
63
- toBigIntLE(
64
- Buffer.from([0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
65
- BigInt(`0xbadc0ffee0ddf00d`));
66
- });
67
-
68
- it('0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn',
69
- async () => {
70
- assertEquals(
71
- toBigIntLE(Buffer.from([
72
- 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc,
73
- 0xba
74
- ])),
75
- BigInt(`0xbadc0ffee0ddf00ddeadbeef`));
76
- });
77
- it('0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefn',
78
- async () => {
79
- assertEquals(
80
- toBigIntLE(Buffer.from([
81
- 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0,
82
- 0xfe, 0x0f, 0xdc, 0xba, 0xef, 0xbe, 0xad, 0xde,
83
- 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba
84
- ])),
85
- BigInt(`0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef`));
86
- });
87
- it('0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeef should equal 0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeefn',
88
- async () => {
89
- assertEquals(
90
- toBigIntLE(Buffer.from([
91
- 0xef, 0xbe, 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd,
92
- 0xe0, 0xfe, 0x0f, 0xdc, 0xba, 0xef, 0xbe, 0xad, 0xde,
93
- 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba
94
- ])),
95
- BigInt(`0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeef`));
96
- });
97
- });
98
-
99
- describe('Try buffer conversion (big endian)', () => {
100
- it('0 should equal 0n', () => {
101
- assertEquals(toBigIntBE(Buffer.from([0])), BigInt(`0`));
66
+ toBigIntLE(Buffer.from([0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])),
67
+ BigInt("0xbadc0ffee0ddf00d")
68
+ );
102
69
  });
103
70
 
104
- it('1 should equal 1n', async () => {
105
- assertEquals(toBigIntBE(Buffer.from([1])), BigInt(`1`));
106
- });
107
-
108
- it('0xdead should equal 0xdeadn', async () => {
109
- assertEquals(toBigIntBE(Buffer.from([0xde, 0xad])), BigInt(`0xdead`));
110
- });
111
-
112
- it('0xdeadbeef should equal 0xdeadbeefn', async () => {
71
+ it("0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn", async () => {
113
72
  assertEquals(
114
- toBigIntBE(Buffer.from([0xde, 0xad, 0xbe, 0xef])),
115
- BigInt(`0xdeadbeef`));
73
+ toBigIntLE(
74
+ Buffer.from([
75
+ 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc,
76
+ 0xba,
77
+ ])
78
+ ),
79
+ BigInt("0xbadc0ffee0ddf00ddeadbeef")
80
+ );
116
81
  });
117
82
 
118
- it('0xbadc0ffee0 should equal 0xbadc0ffee0n', async () => {
83
+ it("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefn", async () => {
119
84
  assertEquals(
120
- toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0])),
121
- BigInt(`0xbadc0ffee0`));
122
- });
123
-
124
- it('0xbadc0ffee0dd should equal 0xbadc0ffee0ddn', async () => {
85
+ toBigIntLE(
86
+ Buffer.from([
87
+ 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc,
88
+ 0xba, 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f,
89
+ 0xdc, 0xba,
90
+ ])
91
+ ),
92
+ BigInt("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef")
93
+ );
94
+ });
95
+
96
+ it("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeef should equal 0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeefn", async () => {
125
97
  assertEquals(
126
- toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd])),
127
- BigInt(`0xbadc0ffee0dd`));
128
- });
129
-
130
- it('0xbadc0ffee0ddf0 should equal 0xbadc0ffee0ddf0n', async () => {
131
- assertEquals(
132
- toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0])),
133
- BigInt(`0xbadc0ffee0ddf0`));
134
- });
135
-
136
- it('0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn', async () => {
137
- assertEquals(
138
- toBigIntBE(
139
- Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d])),
140
- BigInt(`0xbadc0ffee0ddf00d`));
141
- });
142
-
143
- it('0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn',
144
- async () => {
145
- assertEquals(
146
- toBigIntBE(Buffer.from([
147
- 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe,
148
- 0xef
149
- ])),
150
- BigInt(`0xbadc0ffee0ddf00ddeadbeef`));
151
- });
152
-
153
- it('long value should equal long val', async () => {
154
- assertEquals(
155
- toBigIntBE(Buffer.from(
156
- 'badc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef',
157
- 'hex')),
158
- BigInt(
159
- `0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef`));
160
- });
161
-
162
- it('other long value should equal long val', async () => {
163
- assertEquals(
164
- toBigIntBE(Buffer.from(
165
- 'd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544',
166
- 'hex')),
167
- BigInt(
168
- `0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544`));
98
+ toBigIntLE(
99
+ Buffer.from([
100
+ 0xef, 0xbe, 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe,
101
+ 0x0f, 0xdc, 0xba, 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0,
102
+ 0xfe, 0x0f, 0xdc, 0xba,
103
+ ])
104
+ ),
105
+ BigInt("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbeef")
106
+ );
169
107
  });
170
108
  });
171
109
 
172
- describe('Try bigint conversion (little endian)', () => {
173
- it('0 should equal 0n', () => {
174
- toBufferLE(BigInt(`0`), 8).should.deep.equal(Buffer.from([
175
- 0, 0, 0, 0, 0, 0, 0, 0
176
- ]));
177
- });
178
-
179
- it('1 should equal 1n', async () => {
180
- toBufferLE(BigInt(`1`), 8).should.deep.equal(Buffer.from([
181
- 1, 0, 0, 0, 0, 0, 0, 0
182
- ]));
183
- });
184
-
185
-
186
- it('1 should equal 1n (32 byte)', async () => {
187
- toBufferLE(BigInt(`1`), 32)
188
- .should.deep.equal(Buffer.from(
189
- '0100000000000000000000000000000000000000000000000000000000000000',
190
- 'hex'));
110
+ describe("Try buffer conversion (big endian)", () => {
111
+ it("0 should equal 0n", () => {
112
+ assertEquals(toBigIntBE(Buffer.from([0])), BigInt("0"));
191
113
  });
192
114
 
193
- it('0xdead should equal 0xdeadn (6 byte)', async () => {
194
- toBufferLE(BigInt(`0xdead`), 6).should.deep.equal(Buffer.from([
195
- 0xad, 0xde, 0, 0, 0, 0
196
- ]));
115
+ it("1 should equal 1n", async () => {
116
+ assertEquals(toBigIntBE(Buffer.from([1])), BigInt("1"));
197
117
  });
198
118
 
199
- it('0xdeadbeef should equal 0xdeadbeef0000000000n (9 byte)', async () => {
200
- toBufferLE(BigInt(`0xdeadbeef`), 9).should.deep.equal(Buffer.from([
201
- 0xef, 0xbe, 0xad, 0xde, 0, 0, 0, 0, 0
202
- ]));
119
+ it("0xdead should equal 0xdeadn", async () => {
120
+ assertEquals(toBigIntBE(Buffer.from([0xde, 0xad])), BigInt("0xdead"));
203
121
  });
204
122
 
205
- it('0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn (8 byte)',
206
- async () => {
207
- toBufferLE(BigInt(`0xbadc0ffee0ddf00d`), 8)
208
- .should.deep.equal(
209
- Buffer.from([0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba]));
210
- });
211
-
212
- it('0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn',
213
- async () => {
214
- toBufferLE(BigInt(`0xbadc0ffee0ddf00ddeadbeef`), 12)
215
- .should.deep.equal(Buffer.from([
216
- 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc,
217
- 0xba
218
- ]));
219
- });
220
-
221
- it('long value should equal long val', async () => {
222
- toBufferLE(BigInt(`0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef`), 24)
223
- .should.deep.equal(Buffer.from([
224
- 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0,
225
- 0xfe, 0x0f, 0xdc, 0xba, 0xef, 0xbe, 0xad, 0xde,
226
- 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba
227
- ]));
228
- });
229
- });
230
-
231
-
232
- describe('Try bigint conversion (big endian)', () => {
233
- it('0 should equal 0n', () => {
234
- toBufferBE(BigInt(`0`), 8).should.deep.equal(Buffer.from([
235
- 0, 0, 0, 0, 0, 0, 0, 0
236
- ]));
237
- });
238
-
239
- it('1 should equal 1n', async () => {
240
- toBufferBE(BigInt(`1`), 8).should.deep.equal(Buffer.from([
241
- 0, 0, 0, 0, 0, 0, 0, 1
242
- ]));
243
- });
244
-
245
- it('1 should equal 1n (32 byte)', async () => {
246
- toBufferBE(BigInt(`1`), 32)
247
- .should.deep.equal(Buffer.from(
248
- '0000000000000000000000000000000000000000000000000000000000000001',
249
- 'hex'));
250
- });
251
-
252
- it('0xdead should equal 0xdeadn (6 byte)', async () => {
253
- toBufferBE(BigInt(`0xdead`), 6).should.deep.equal(Buffer.from([
254
- 0, 0, 0, 0, 0xde, 0xad
255
- ]));
256
- });
257
-
258
- it('0xdeadbeef should equal 0xdeadbeef0000000000n (9 byte)', async () => {
259
- toBufferBE(BigInt(`0xdeadbeef`), 9).should.deep.equal(Buffer.from([
260
- 0, 0, 0, 0, 0, 0xde, 0xad, 0xbe, 0xef
261
- ]));
123
+ it("0xdeadbeef should equal 0xdeadbeefn", async () => {
124
+ assertEquals(
125
+ toBigIntBE(Buffer.from([0xde, 0xad, 0xbe, 0xef])),
126
+ BigInt("0xdeadbeef")
127
+ );
262
128
  });
263
129
 
264
- it('0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn (8 byte)',
265
- async () => {
266
- toBufferBE(BigInt(`0xbadc0ffee0ddf00d`), 8)
267
- .should.deep.equal(
268
- Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d]));
269
- });
270
-
271
- it('0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn',
272
- async () => {
273
- toBufferBE(BigInt(`0xbadc0ffee0ddf00ddeadbeef`), 12)
274
- .should.deep.equal(Buffer.from([
275
- 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe,
276
- 0xef
277
- ]));
278
- });
279
-
280
- it('long value should equal long val', async () => {
281
- toBufferBE(BigInt(`0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef`), 24)
282
- .should.deep.equal(Buffer.from([
283
- 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d,
284
- 0xde, 0xad, 0xbe, 0xef, 0xba, 0xdc, 0x0f, 0xfe,
285
- 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe, 0xef
286
- ]));
130
+ it("0xbadc0ffee0 should equal 0xbadc0ffee0n", async () => {
131
+ assertEquals(
132
+ toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0])),
133
+ BigInt("0xbadc0ffee0")
134
+ );
287
135
  });
288
- });
289
-
290
- describe('Conversion Utilities - bigintToBuf and bufToBigint', () => {
291
- const bigintToBuf = lib.bigintToBuf;
292
- const bufToBigint = lib.bufToBigint;
293
136
 
294
- it('should convert 0 to buffer', () => {
295
- const buf = bigintToBuf(BigInt(0));
296
- buf.should.deep.equal(Buffer.from([0]));
137
+ it("0xbadc0ffee0dd should equal 0xbadc0ffee0ddn", async () => {
138
+ assertEquals(
139
+ toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd])),
140
+ BigInt("0xbadc0ffee0dd")
141
+ );
297
142
  });
298
143
 
299
- it('should convert small number to buffer', () => {
300
- const buf = bigintToBuf(BigInt(123456789));
301
- assertEquals(bufToBigint(buf), BigInt(123456789));
144
+ it("0xbadc0ffee0ddf0 should equal 0xbadc0ffee0ddf0n", async () => {
145
+ assertEquals(
146
+ toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0])),
147
+ BigInt("0xbadc0ffee0ddf0")
148
+ );
302
149
  });
303
150
 
304
- it('should round-trip convert medium numbers', () => {
305
- const original = BigInt('0xdeadbeef');
306
- const buf = bigintToBuf(original);
307
- const result = bufToBigint(buf);
308
- assertEquals(result, original);
151
+ it("0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn", async () => {
152
+ assertEquals(
153
+ toBigIntBE(Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d])),
154
+ BigInt("0xbadc0ffee0ddf00d")
155
+ );
309
156
  });
310
157
 
311
- it('should round-trip convert large numbers', () => {
312
- const original = BigInt('0xbadc0ffee0ddf00ddeadbeef');
313
- const buf = bigintToBuf(original);
314
- const result = bufToBigint(buf);
315
- assertEquals(result, original);
158
+ it("0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn", async () => {
159
+ assertEquals(
160
+ toBigIntBE(Buffer.from("badc0ffee0ddf00ddeadbeef", "hex")),
161
+ BigInt("0xbadc0ffee0ddf00ddeadbeef")
162
+ );
316
163
  });
317
164
 
318
- it('should throw error for negative bigint', () => {
319
- chai.expect(() => bigintToBuf(BigInt(-1))).to.throw('negative bigint');
165
+ it("long value should equal long val", async () => {
166
+ assertEquals(
167
+ toBigIntBE(
168
+ Buffer.from(
169
+ "badc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef",
170
+ "hex"
171
+ )
172
+ ),
173
+ BigInt(
174
+ "0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef"
175
+ )
176
+ );
177
+ });
178
+
179
+ it("other long value should equal long val", async () => {
180
+ assertEquals(
181
+ toBigIntBE(
182
+ Buffer.from(
183
+ "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
184
+ "hex"
185
+ )
186
+ ),
187
+ BigInt(
188
+ "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
189
+ )
190
+ );
320
191
  });
321
192
  });
322
193
 
323
- describe('Conversion Utilities - bigintToHex and hexToBigint', () => {
324
- const bigintToHex = lib.bigintToHex;
325
- const hexToBigint = lib.hexToBigint;
326
-
327
- it('should convert 0 to hex', () => {
328
- bigintToHex(BigInt(0)).should.equal('00');
194
+ describe("Try bigint conversion (little endian)", () => {
195
+ it("0 should equal 0n", () => {
196
+ expect(toBufferLE(BigInt("0"), 8)).toEqual(
197
+ Buffer.from([0, 0, 0, 0, 0, 0, 0, 0])
198
+ );
329
199
  });
330
200
 
331
- it('should convert small number to hex', () => {
332
- bigintToHex(BigInt(255)).should.equal('ff');
201
+ it("1 should equal 1n", async () => {
202
+ expect(toBufferLE(BigInt("1"), 8)).toEqual(
203
+ Buffer.from([1, 0, 0, 0, 0, 0, 0, 0])
204
+ );
333
205
  });
334
206
 
335
- it('should convert number to even-length hex', () => {
336
- bigintToHex(BigInt(15)).should.equal('0f');
207
+ it("1 should equal 1n (32 byte)", async () => {
208
+ expect(toBufferLE(BigInt("1"), 32)).toEqual(
209
+ Buffer.from(
210
+ "0100000000000000000000000000000000000000000000000000000000000000",
211
+ "hex"
212
+ )
213
+ );
337
214
  });
338
215
 
339
- it('should convert hex string to bigint', () => {
340
- assertEquals(hexToBigint('deadbeef'), BigInt('0xdeadbeef'));
216
+ it("0xdead should equal 0xdeadn (6 byte)", async () => {
217
+ expect(toBufferLE(BigInt("0xdead"), 6)).toEqual(
218
+ Buffer.from([0xad, 0xde, 0, 0, 0, 0])
219
+ );
341
220
  });
342
221
 
343
- it('should handle hex string with 0x prefix', () => {
344
- assertEquals(hexToBigint('0xdeadbeef'), BigInt('0xdeadbeef'));
222
+ it("0xdeadbeef should equal 0xdeadbeef0000000000n (9 byte)", async () => {
223
+ expect(toBufferLE(BigInt("0xdeadbeef"), 9)).toEqual(
224
+ Buffer.from([0xef, 0xbe, 0xad, 0xde, 0, 0, 0, 0, 0])
225
+ );
345
226
  });
346
227
 
347
- it('should round-trip convert', () => {
348
- const original = BigInt('0xbadc0ffee0ddf00ddeadbeef');
349
- const hex = bigintToHex(original);
350
- const result = hexToBigint(hex);
351
- assertEquals(result, original);
228
+ it("0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn (8 byte)", async () => {
229
+ expect(toBufferLE(BigInt("0xbadc0ffee0ddf00d"), 8)).toEqual(
230
+ Buffer.from([0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba])
231
+ );
352
232
  });
353
233
 
354
- it('should handle empty string', () => {
355
- assertEquals(hexToBigint(''), BigInt(0));
234
+ it("0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn", async () => {
235
+ expect(toBufferLE(BigInt("0xbadc0ffee0ddf00ddeadbeef"), 12)).toEqual(
236
+ Buffer.from([
237
+ 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba,
238
+ ])
239
+ );
356
240
  });
357
241
 
358
- it('should throw error for negative bigint', () => {
359
- chai.expect(() => bigintToHex(BigInt(-1))).to.throw('negative bigint');
242
+ it("long value should equal long val", async () => {
243
+ expect(
244
+ toBufferLE(
245
+ BigInt("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef"),
246
+ 24
247
+ )
248
+ ).toEqual(
249
+ Buffer.from([
250
+ 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba,
251
+ 0xef, 0xbe, 0xad, 0xde, 0x0d, 0xf0, 0xdd, 0xe0, 0xfe, 0x0f, 0xdc, 0xba,
252
+ ])
253
+ );
360
254
  });
361
255
  });
362
256
 
363
- describe('Conversion Utilities - bigintToText and textToBigint', () => {
364
- const bigintToText = lib.bigintToText;
365
- const textToBigint = lib.textToBigint;
366
-
367
- it('should convert 0 to text', () => {
368
- bigintToText(BigInt(0)).should.equal('0');
369
- });
370
-
371
- it('should convert positive number to text', () => {
372
- bigintToText(BigInt(123456789)).should.equal('123456789');
373
- });
374
-
375
- it('should convert large number to text', () => {
376
- bigintToText(BigInt('0xdeadbeef')).should.equal('3735928559');
377
- });
378
-
379
- it('should convert text to bigint', () => {
380
- assertEquals(textToBigint('123456789'), BigInt(123456789));
381
- });
382
-
383
- it('should round-trip convert', () => {
384
- const original = BigInt('9876543210123456789');
385
- const text = bigintToText(original);
386
- const result = textToBigint(text);
387
- assertEquals(result, original);
257
+ describe("Try bigint conversion (big endian)", () => {
258
+ it("0 should equal 0n", () => {
259
+ expect(toBufferBE(BigInt("0"), 8)).toEqual(
260
+ Buffer.from([0, 0, 0, 0, 0, 0, 0, 0])
261
+ );
388
262
  });
389
263
 
390
- it('should throw error for empty string', () => {
391
- chai.expect(() => textToBigint('')).to.throw('cannot be empty');
264
+ it("1 should equal 1n", async () => {
265
+ expect(toBufferBE(BigInt("1"), 8)).toEqual(
266
+ Buffer.from([0, 0, 0, 0, 0, 0, 0, 1])
267
+ );
392
268
  });
393
269
 
394
- it('should throw error for invalid decimal string', () => {
395
- chai.expect(() => textToBigint('abc')).to.throw('invalid decimal');
270
+ it("1 should equal 1n (32 byte)", async () => {
271
+ expect(toBufferBE(BigInt("1"), 32)).toEqual(
272
+ Buffer.from(
273
+ "0000000000000000000000000000000000000000000000000000000000000001",
274
+ "hex"
275
+ )
276
+ );
396
277
  });
397
- });
398
-
399
- describe('Conversion Utilities - bigintToBase64 and base64ToBigint', () => {
400
- const bigintToBase64 = lib.bigintToBase64;
401
- const base64ToBigint = lib.base64ToBigint;
402
278
 
403
- it('should convert 0 to base64', () => {
404
- const b64 = bigintToBase64(BigInt(0));
405
- b64.should.be.a('string');
406
- assertEquals(base64ToBigint(b64), BigInt(0));
279
+ it("0xdead should equal 0xdeadn (6 byte)", async () => {
280
+ expect(toBufferBE(BigInt("0xdead"), 6)).toEqual(
281
+ Buffer.from([0, 0, 0, 0, 0xde, 0xad])
282
+ );
407
283
  });
408
284
 
409
- it('should convert small number to base64', () => {
410
- const original = BigInt(123456789);
411
- const b64 = bigintToBase64(original);
412
- b64.should.equal('B1vNFQ==');
285
+ it("0xdeadbeef should equal 0xdeadbeef0000000000n (9 byte)", async () => {
286
+ expect(toBufferBE(BigInt("0xdeadbeef"), 9)).toEqual(
287
+ Buffer.from([0, 0, 0, 0, 0, 0xde, 0xad, 0xbe, 0xef])
288
+ );
413
289
  });
414
290
 
415
- it('should convert base64 to bigint', () => {
416
- assertEquals(base64ToBigint('B1vNFQ=='), BigInt(123456789));
291
+ it("0xbadc0ffee0ddf00d should equal 0xbadc0ffee0ddf00dn (8 byte)", async () => {
292
+ expect(toBufferBE(BigInt("0xbadc0ffee0ddf00d"), 8)).toEqual(
293
+ Buffer.from([0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d])
294
+ );
417
295
  });
418
296
 
419
- it('should round-trip convert medium numbers', () => {
420
- const original = BigInt('0xdeadbeef');
421
- const b64 = bigintToBase64(original);
422
- const result = base64ToBigint(b64);
423
- assertEquals(result, original);
297
+ it("0xbadc0ffee0ddf00ddeadbeef should equal 0xbadc0ffee0ddf00ddeadbeefn", async () => {
298
+ expect(toBufferBE(BigInt("0xbadc0ffee0ddf00ddeadbeef"), 12)).toEqual(
299
+ Buffer.from([
300
+ 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe, 0xef,
301
+ ])
302
+ );
424
303
  });
425
304
 
426
- it('should round-trip convert large numbers', () => {
427
- const original = BigInt('0xbadc0ffee0ddf00ddeadbeef');
428
- const b64 = bigintToBase64(original);
429
- const result = base64ToBigint(b64);
430
- assertEquals(result, original);
305
+ it("long value should equal long val", async () => {
306
+ expect(
307
+ toBufferBE(
308
+ BigInt("0xbadc0ffee0ddf00ddeadbeefbadc0ffee0ddf00ddeadbeef"),
309
+ 24
310
+ )
311
+ ).toEqual(
312
+ Buffer.from([
313
+ 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe, 0xef,
314
+ 0xba, 0xdc, 0x0f, 0xfe, 0xe0, 0xdd, 0xf0, 0x0d, 0xde, 0xad, 0xbe, 0xef,
315
+ ])
316
+ );
431
317
  });
432
-
433
- it('should throw error for negative bigint', () => {
434
- chai.expect(() => bigintToBase64(BigInt(-1))).to.throw('negative bigint');
435
- });
436
-
437
- it('should throw error for empty base64 string', () => {
438
- chai.expect(() => base64ToBigint('')).to.throw('cannot be empty');
439
- });
440
-
441
- it('should throw error for invalid base64 string', () => {
442
- chai.expect(() => base64ToBigint('invalid!@#')).to.throw('invalid base64');
443
- });
444
- });
318
+ });