@ocap/util 1.24.2 → 1.24.4
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/esm/bn.d.ts +5 -0
- package/esm/bn.js +7 -0
- package/esm/curve.d.ts +8 -8
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/lib/bn.d.ts +5 -0
- package/lib/bn.js +13 -0
- package/lib/curve.d.ts +8 -8
- package/lib/index.d.ts +1 -1
- package/lib/index.js +15 -15
- package/package.json +3 -4
package/esm/bn.d.ts
ADDED
package/esm/bn.js
ADDED
package/esm/curve.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function calcConstantCost({ amount, fixedPrice, decimal, }: {
|
|
|
18
18
|
amount: string;
|
|
19
19
|
fixedPrice: string;
|
|
20
20
|
decimal: number;
|
|
21
|
-
}):
|
|
21
|
+
}): import("bn.js");
|
|
22
22
|
/**
|
|
23
23
|
* linear Curve
|
|
24
24
|
* Price = basePrice + slope * currentSupply
|
|
@@ -28,7 +28,7 @@ export declare function calcLinearPrice({ basePrice, slope, currentSupply, decim
|
|
|
28
28
|
slope: string;
|
|
29
29
|
currentSupply: string;
|
|
30
30
|
decimal: number;
|
|
31
|
-
}):
|
|
31
|
+
}): import("bn.js");
|
|
32
32
|
/**
|
|
33
33
|
* Linear Curve
|
|
34
34
|
* mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
|
|
@@ -41,7 +41,7 @@ export declare function calcLinearCost(params: {
|
|
|
41
41
|
slope: string;
|
|
42
42
|
decimal: number;
|
|
43
43
|
direction: Direction;
|
|
44
|
-
}):
|
|
44
|
+
}): import("bn.js");
|
|
45
45
|
/**
|
|
46
46
|
* Quadratic Curve
|
|
47
47
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
@@ -51,7 +51,7 @@ export declare function calcQuadraticPrice(params: {
|
|
|
51
51
|
currentSupply: string;
|
|
52
52
|
constant: string;
|
|
53
53
|
decimal: number;
|
|
54
|
-
}):
|
|
54
|
+
}): import("bn.js");
|
|
55
55
|
/**
|
|
56
56
|
* Quadratic Curve
|
|
57
57
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
@@ -65,20 +65,20 @@ export declare function calcQuadraticCost(params: {
|
|
|
65
65
|
constant: string;
|
|
66
66
|
decimal: number;
|
|
67
67
|
direction: Direction;
|
|
68
|
-
}):
|
|
68
|
+
}): import("bn.js");
|
|
69
69
|
export declare function calcFee({ reserveAmount, feeRate }: {
|
|
70
70
|
reserveAmount: string;
|
|
71
71
|
feeRate: string;
|
|
72
|
-
}):
|
|
72
|
+
}): import("bn.js");
|
|
73
73
|
export declare function calcPrice({ currentSupply, decimal, curve }: {
|
|
74
74
|
currentSupply: string;
|
|
75
75
|
decimal: number;
|
|
76
76
|
curve: any;
|
|
77
|
-
}):
|
|
77
|
+
}): import("bn.js");
|
|
78
78
|
export declare function calcCost({ amount, decimal, currentSupply, direction, curve, }: {
|
|
79
79
|
amount: string;
|
|
80
80
|
decimal: number;
|
|
81
81
|
currentSupply: string;
|
|
82
82
|
curve: any;
|
|
83
83
|
direction: Direction;
|
|
84
|
-
}):
|
|
84
|
+
}): import("bn.js");
|
package/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LiteralUnion } from 'type-fest';
|
|
2
2
|
import rightPad from 'lodash/padEnd';
|
|
3
3
|
import leftPad from 'lodash/padStart';
|
|
4
|
-
import BN from 'bn
|
|
4
|
+
import { BN } from './bn';
|
|
5
5
|
export declare const isBase58btc: (data: any) => boolean;
|
|
6
6
|
export type BytesType = string | Buffer | Uint8Array;
|
|
7
7
|
export type EncodingType = LiteralUnion<'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer', string>;
|
package/esm/index.js
CHANGED
|
@@ -9,8 +9,8 @@ import rightPad from 'lodash/padEnd';
|
|
|
9
9
|
import leftPad from 'lodash/padStart';
|
|
10
10
|
import base58 from 'bs58';
|
|
11
11
|
import base64 from 'base64-url';
|
|
12
|
-
import BN from 'bn.js';
|
|
13
12
|
import * as utf8 from 'utf8';
|
|
13
|
+
import { BN } from './bn';
|
|
14
14
|
const DID_PREFIX = 'did:abt:';
|
|
15
15
|
const zero = new BN(0);
|
|
16
16
|
const negative1 = new BN(-1);
|
package/lib/bn.d.ts
ADDED
package/lib/bn.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BN = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
class WrapBN extends bn_js_1.default {
|
|
9
|
+
constructor(value, base, endian) {
|
|
10
|
+
super(value === null ? '0' : value, base, endian);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BN = WrapBN;
|
package/lib/curve.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function calcConstantCost({ amount, fixedPrice, decimal, }: {
|
|
|
18
18
|
amount: string;
|
|
19
19
|
fixedPrice: string;
|
|
20
20
|
decimal: number;
|
|
21
|
-
}):
|
|
21
|
+
}): import("bn.js");
|
|
22
22
|
/**
|
|
23
23
|
* linear Curve
|
|
24
24
|
* Price = basePrice + slope * currentSupply
|
|
@@ -28,7 +28,7 @@ export declare function calcLinearPrice({ basePrice, slope, currentSupply, decim
|
|
|
28
28
|
slope: string;
|
|
29
29
|
currentSupply: string;
|
|
30
30
|
decimal: number;
|
|
31
|
-
}):
|
|
31
|
+
}): import("bn.js");
|
|
32
32
|
/**
|
|
33
33
|
* Linear Curve
|
|
34
34
|
* mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
|
|
@@ -41,7 +41,7 @@ export declare function calcLinearCost(params: {
|
|
|
41
41
|
slope: string;
|
|
42
42
|
decimal: number;
|
|
43
43
|
direction: Direction;
|
|
44
|
-
}):
|
|
44
|
+
}): import("bn.js");
|
|
45
45
|
/**
|
|
46
46
|
* Quadratic Curve
|
|
47
47
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
@@ -51,7 +51,7 @@ export declare function calcQuadraticPrice(params: {
|
|
|
51
51
|
currentSupply: string;
|
|
52
52
|
constant: string;
|
|
53
53
|
decimal: number;
|
|
54
|
-
}):
|
|
54
|
+
}): import("bn.js");
|
|
55
55
|
/**
|
|
56
56
|
* Quadratic Curve
|
|
57
57
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
@@ -65,20 +65,20 @@ export declare function calcQuadraticCost(params: {
|
|
|
65
65
|
constant: string;
|
|
66
66
|
decimal: number;
|
|
67
67
|
direction: Direction;
|
|
68
|
-
}):
|
|
68
|
+
}): import("bn.js");
|
|
69
69
|
export declare function calcFee({ reserveAmount, feeRate }: {
|
|
70
70
|
reserveAmount: string;
|
|
71
71
|
feeRate: string;
|
|
72
|
-
}):
|
|
72
|
+
}): import("bn.js");
|
|
73
73
|
export declare function calcPrice({ currentSupply, decimal, curve }: {
|
|
74
74
|
currentSupply: string;
|
|
75
75
|
decimal: number;
|
|
76
76
|
curve: any;
|
|
77
|
-
}):
|
|
77
|
+
}): import("bn.js");
|
|
78
78
|
export declare function calcCost({ amount, decimal, currentSupply, direction, curve, }: {
|
|
79
79
|
amount: string;
|
|
80
80
|
decimal: number;
|
|
81
81
|
currentSupply: string;
|
|
82
82
|
curve: any;
|
|
83
83
|
direction: Direction;
|
|
84
|
-
}):
|
|
84
|
+
}): import("bn.js");
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LiteralUnion } from 'type-fest';
|
|
2
2
|
import rightPad from 'lodash/padEnd';
|
|
3
3
|
import leftPad from 'lodash/padStart';
|
|
4
|
-
import BN from 'bn
|
|
4
|
+
import { BN } from './bn';
|
|
5
5
|
export declare const isBase58btc: (data: any) => boolean;
|
|
6
6
|
export type BytesType = string | Buffer | Uint8Array;
|
|
7
7
|
export type EncodingType = LiteralUnion<'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer', string>;
|
package/lib/index.js
CHANGED
|
@@ -53,12 +53,12 @@ const padStart_1 = __importDefault(require("lodash/padStart"));
|
|
|
53
53
|
exports.leftPad = padStart_1.default;
|
|
54
54
|
const bs58_1 = __importDefault(require("bs58"));
|
|
55
55
|
const base64_url_1 = __importDefault(require("base64-url"));
|
|
56
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
57
|
-
exports.BN = bn_js_1.default;
|
|
58
56
|
const utf8 = __importStar(require("utf8"));
|
|
57
|
+
const bn_1 = require("./bn");
|
|
58
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return bn_1.BN; } });
|
|
59
59
|
const DID_PREFIX = 'did:abt:';
|
|
60
|
-
const zero = new
|
|
61
|
-
const negative1 = new
|
|
60
|
+
const zero = new bn_1.BN(0);
|
|
61
|
+
const negative1 = new bn_1.BN(-1);
|
|
62
62
|
const base58btc = {
|
|
63
63
|
encode: (v) => `z${bs58_1.default.encode(v)}`,
|
|
64
64
|
decode: (v) => bs58_1.default.decode(v.slice(1)),
|
|
@@ -88,26 +88,26 @@ exports.isBase58btc = isBase58btc;
|
|
|
88
88
|
*/
|
|
89
89
|
const numberToBN = (arg) => {
|
|
90
90
|
if (typeof arg === 'string' || typeof arg === 'number') {
|
|
91
|
-
let multiplier = new
|
|
91
|
+
let multiplier = new bn_1.BN(1); // eslint-disable-line
|
|
92
92
|
const formattedString = String(arg).toLowerCase().trim();
|
|
93
93
|
const isHexPrefixed = formattedString.substr(0, 2) === '0x' || formattedString.substr(0, 3) === '-0x';
|
|
94
94
|
let stringArg = (0, exports.stripHexPrefix)(formattedString); // eslint-disable-line
|
|
95
95
|
if (stringArg.substr(0, 1) === '-') {
|
|
96
96
|
stringArg = (0, exports.stripHexPrefix)(stringArg.slice(1));
|
|
97
|
-
multiplier = new
|
|
97
|
+
multiplier = new bn_1.BN(-1, 10);
|
|
98
98
|
}
|
|
99
99
|
stringArg = stringArg === '' ? '0' : stringArg;
|
|
100
100
|
if ((!stringArg.match(/^-?[0-9]+$/) && stringArg.match(/^[0-9A-Fa-f]+$/)) ||
|
|
101
101
|
stringArg.match(/^[a-fA-F]+$/) ||
|
|
102
102
|
(isHexPrefixed === true && stringArg.match(/^[0-9A-Fa-f]+$/))) {
|
|
103
|
-
return new
|
|
103
|
+
return new bn_1.BN(stringArg, 16).mul(multiplier);
|
|
104
104
|
}
|
|
105
105
|
if ((stringArg.match(/^-?[0-9]+$/) || stringArg === '') && isHexPrefixed === false) {
|
|
106
|
-
return new
|
|
106
|
+
return new bn_1.BN(stringArg, 10).mul(multiplier);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
if ((0, exports.isBN)(arg)) {
|
|
110
|
-
return new
|
|
110
|
+
return new bn_1.BN(arg.toString(10), 10);
|
|
111
111
|
}
|
|
112
112
|
throw new Error(`[number-to-bn] while converting number ${JSON.stringify(arg)} to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.`);
|
|
113
113
|
};
|
|
@@ -150,7 +150,7 @@ exports.stripHexPrefix = stripHexPrefix;
|
|
|
150
150
|
* @param {Object} object
|
|
151
151
|
* @returns {Boolean}
|
|
152
152
|
*/
|
|
153
|
-
const isBN = (object) => object instanceof
|
|
153
|
+
const isBN = (object) => object instanceof bn_1.BN || (object && object.constructor && object.constructor.name === 'BN');
|
|
154
154
|
exports.isBN = isBN;
|
|
155
155
|
/**
|
|
156
156
|
* Returns true if object is BigNumber, otherwise false
|
|
@@ -198,7 +198,7 @@ const toBN = (num, base = 10) => {
|
|
|
198
198
|
try {
|
|
199
199
|
if (typeof num === 'number' && num > 0) {
|
|
200
200
|
const numStr = Number(num).toLocaleString('fullwide', { useGrouping: false });
|
|
201
|
-
return new
|
|
201
|
+
return new bn_1.BN(numStr, base);
|
|
202
202
|
}
|
|
203
203
|
return (0, exports.numberToBN)(num);
|
|
204
204
|
}
|
|
@@ -299,7 +299,7 @@ const numberToHex = (value) => {
|
|
|
299
299
|
}
|
|
300
300
|
const num = (0, exports.toBN)(value);
|
|
301
301
|
const result = num.toString(16);
|
|
302
|
-
return num.lt(new
|
|
302
|
+
return num.lt(new bn_1.BN(0)) ? `-0x${result.substr(1)}` : `0x${result}`;
|
|
303
303
|
};
|
|
304
304
|
exports.numberToHex = numberToHex;
|
|
305
305
|
/**
|
|
@@ -472,13 +472,13 @@ const fromTokenToUnit = (input, decimal = 18) => {
|
|
|
472
472
|
while (fraction.length < baseLength) {
|
|
473
473
|
fraction += '0';
|
|
474
474
|
}
|
|
475
|
-
whole = new
|
|
476
|
-
fraction = new
|
|
475
|
+
whole = new bn_1.BN(whole);
|
|
476
|
+
fraction = new bn_1.BN(fraction);
|
|
477
477
|
let unit = whole.mul(base).add(fraction);
|
|
478
478
|
if (negative) {
|
|
479
479
|
unit = unit.mul(negative1);
|
|
480
480
|
}
|
|
481
|
-
return new
|
|
481
|
+
return new bn_1.BN(unit.toString(10), 10);
|
|
482
482
|
};
|
|
483
483
|
exports.fromTokenToUnit = fromTokenToUnit;
|
|
484
484
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/util",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.4",
|
|
4
4
|
"description": "utils shared across multiple forge js libs, works in both node.js and browser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcblock",
|
|
@@ -12,14 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"base64-url": "^2.3.3",
|
|
15
|
-
"bn.js": "5.2.
|
|
15
|
+
"bn.js": "5.2.2",
|
|
16
16
|
"bs58": "^5.0.0",
|
|
17
17
|
"lodash": "^4.17.21",
|
|
18
18
|
"utf8": "^3.0.0",
|
|
19
|
-
"@ocap/types": "^1.24.
|
|
19
|
+
"@ocap/types": "^1.24.4"
|
|
20
20
|
},
|
|
21
21
|
"resolutions": {
|
|
22
|
-
"bn.js": "5.2.1",
|
|
23
22
|
"elliptic": "6.5.3"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|