@exodus/bigint 3.0.1 → 4.0.0
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/CHANGELOG.md +10 -0
- package/README.md +4 -1
- package/package.json +6 -4
- package/src/bn.js +0 -160
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.0](https://github.com/ExodusMovement/hydra/compare/@exodus/bigint@3.0.1...@exodus/bigint@4.0.0) (2025-10-21)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
- remove /bn.js export (#14160)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- feat!: remove /bn.js export (#14160)
|
|
15
|
+
|
|
6
16
|
## [3.0.1](https://github.com/ExodusMovement/hydra/compare/@exodus/bigint@3.0.0...@exodus/bigint@3.0.1) (2024-11-01)
|
|
7
17
|
|
|
8
18
|
Re-licensed under MIT license.
|
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @exodus/bigint
|
|
2
2
|
|
|
3
|
-
Immutable API wrapper for
|
|
3
|
+
Immutable API wrapper for BigInt numbers.
|
|
4
|
+
|
|
5
|
+
> ⚠️ Warning:
|
|
6
|
+
> These days you should probably just use BigInt directly.
|
|
4
7
|
|
|
5
8
|
## Usage
|
|
6
9
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bigint",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "bigint
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "bigint wrapper for native BigInt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": "Exodus Movement, Inc.",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"bn.js": "^4.11.0",
|
|
18
17
|
"minimalistic-assert": "^1.0.1"
|
|
19
18
|
},
|
|
20
19
|
"scripts": {
|
|
@@ -29,5 +28,8 @@
|
|
|
29
28
|
"bugs": {
|
|
30
29
|
"url": "https://github.com/ExodusMovement/hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abigint"
|
|
31
30
|
},
|
|
32
|
-
"
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"provenance": false
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "dd404f90b5ed03b47027726a301f7dcca5887ef7"
|
|
33
35
|
}
|
package/src/bn.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import assert from 'minimalistic-assert'
|
|
2
|
-
import BN from 'bn.js'
|
|
3
|
-
|
|
4
|
-
// TODO: calculator delegator should wrap/unwrap all BN instances
|
|
5
|
-
// so that callers never gett a raw BN instance back
|
|
6
|
-
|
|
7
|
-
const FACTORY_SYMBOL = Symbol('bn-wrapper')
|
|
8
|
-
|
|
9
|
-
const unwrap = (value) => (value instanceof Wrapper ? value.unwrap() : value)
|
|
10
|
-
|
|
11
|
-
const BI_ZERO = new BN(0)
|
|
12
|
-
|
|
13
|
-
export default class Wrapper {
|
|
14
|
-
static wrapperName = 'bn.js'
|
|
15
|
-
static isUnderlyingInstance(a) {
|
|
16
|
-
return BN.isBN(a)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static wrap(value, base = 10) {
|
|
20
|
-
if (!BN.isBN(value)) {
|
|
21
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
22
|
-
throw new TypeError(`Unsupported type: ${typeof value}`)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (base !== 10 && base !== 16) throw new TypeError(`Unsupported base: ${base}`)
|
|
26
|
-
|
|
27
|
-
value = new BN(value, base)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return new Wrapper(FACTORY_SYMBOL, value)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
__value__
|
|
34
|
-
|
|
35
|
-
constructor(factorySymbol, value) {
|
|
36
|
-
if (factorySymbol !== FACTORY_SYMBOL) throw new Error('use wrap() instead')
|
|
37
|
-
|
|
38
|
-
this.__value__ = value
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
unwrap() {
|
|
42
|
-
return this.__value__
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
add(value) {
|
|
46
|
-
return Wrapper.wrap(this.__value__.add(unwrap(value)))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
mutateAdd(value) {
|
|
50
|
-
this.__value__.iadd(unwrap(value))
|
|
51
|
-
return this
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
sub(value) {
|
|
55
|
-
return Wrapper.wrap(this.__value__.sub(unwrap(value)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
mutateSub(value) {
|
|
59
|
-
this.__value__.isub(unwrap(value))
|
|
60
|
-
return this
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
mul(value) {
|
|
64
|
-
return Wrapper.wrap(this.__value__.mul(unwrap(value)))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
mutateMul(value) {
|
|
68
|
-
this.__value__.imul(unwrap(value))
|
|
69
|
-
return this
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
div(value) {
|
|
73
|
-
return Wrapper.wrap(this.__value__.div(unwrap(value)))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
mutateDiv(value) {
|
|
77
|
-
this.__value__.idivn(unwrap(value))
|
|
78
|
-
return this
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
mod(value) {
|
|
82
|
-
return Wrapper.wrap(this.__value__.mod(unwrap(value)))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
pow(value) {
|
|
86
|
-
return Wrapper.wrap(this.__value__.pow(unwrap(value)))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
negate() {
|
|
90
|
-
return Wrapper.wrap(this.__value__.neg())
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
mutateNegate() {
|
|
94
|
-
return Wrapper.wrap(this.__value__.ineg())
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
abs() {
|
|
98
|
-
return this.isNegative() ? Wrapper.wrap(this.__value__.abs()) : this
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
mutateAbs() {
|
|
102
|
-
this.__value__.iabs()
|
|
103
|
-
return this
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
gte(value) {
|
|
107
|
-
return this.__value__.gte(unwrap(value))
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
gt(value) {
|
|
111
|
-
return this.__value__.gt(unwrap(value))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
lte(value) {
|
|
115
|
-
return this.__value__.lte(unwrap(value))
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
lt(value) {
|
|
119
|
-
return this.__value__.lt(unwrap(value))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
eq(value) {
|
|
123
|
-
return this.__value__.eq(unwrap(value))
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
isZero() {
|
|
127
|
-
return this.__value__.isZero()
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
isNegative() {
|
|
131
|
-
return this.__value__.isNeg()
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
isPositive() {
|
|
135
|
-
return this.__value__.gt(BI_ZERO)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
toNumber() {
|
|
139
|
-
// false alarm, this is not a NumberUnit instance
|
|
140
|
-
// eslint-disable-next-line @exodus/hydra/no-unsafe-number-unit-methods
|
|
141
|
-
return this.__value__.toNumber()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
toString(base) {
|
|
145
|
-
assert(typeof base === 'number', 'expected number "base"')
|
|
146
|
-
return this.__value__.toString(base)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
toBaseBufferLE(length) {
|
|
150
|
-
return this.__value__.toBuffer('le', length)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
toBaseBufferBE(length) {
|
|
154
|
-
return this.__value__.toBuffer('be', length)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
isBigIntWrapper() {
|
|
158
|
-
return true
|
|
159
|
-
}
|
|
160
|
-
}
|