@fleet-sdk/common 0.1.2 → 0.2.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 +23 -0
- package/README.md +1 -1
- package/dist/index.d.mts +268 -0
- package/dist/index.d.ts +268 -0
- package/dist/index.js +604 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +551 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -9
- package/src/index.ts +1 -0
- package/src/models/collection.ts +107 -0
- package/src/models/index.ts +1 -0
- package/src/types/boxes.ts +2 -2
- package/src/types/common.ts +10 -3
- package/src/types/inputs.ts +3 -3
- package/src/utils/{arrayUtils.ts → array.ts} +26 -21
- package/src/utils/assertions.ts +90 -0
- package/src/utils/{bigIntUtils.ts → bigInt.ts} +28 -65
- package/src/utils/bytes.bench.ts +43 -0
- package/src/utils/bytes.ts +34 -0
- package/src/utils/index.ts +6 -6
- package/src/utils/object.ts +28 -0
- package/src/utils/{boxUtils.ts → utxo.ts} +27 -5
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types/boxes.d.ts +0 -22
- package/dist/cjs/types/boxes.js +0 -3
- package/dist/cjs/types/boxes.js.map +0 -1
- package/dist/cjs/types/common.d.ts +0 -18
- package/dist/cjs/types/common.js +0 -15
- package/dist/cjs/types/common.js.map +0 -1
- package/dist/cjs/types/contextExtension.d.ts +0 -4
- package/dist/cjs/types/contextExtension.js +0 -3
- package/dist/cjs/types/contextExtension.js.map +0 -1
- package/dist/cjs/types/index.d.ts +0 -8
- package/dist/cjs/types/index.js +0 -25
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/inputs.d.ts +0 -37
- package/dist/cjs/types/inputs.js +0 -3
- package/dist/cjs/types/inputs.js.map +0 -1
- package/dist/cjs/types/proverResult.d.ts +0 -6
- package/dist/cjs/types/proverResult.js +0 -3
- package/dist/cjs/types/proverResult.js.map +0 -1
- package/dist/cjs/types/registers.d.ts +0 -9
- package/dist/cjs/types/registers.js +0 -3
- package/dist/cjs/types/registers.js.map +0 -1
- package/dist/cjs/types/token.d.ts +0 -18
- package/dist/cjs/types/token.js +0 -3
- package/dist/cjs/types/token.js.map +0 -1
- package/dist/cjs/types/transactions.d.ts +0 -22
- package/dist/cjs/types/transactions.js +0 -3
- package/dist/cjs/types/transactions.js.map +0 -1
- package/dist/cjs/utils/arrayUtils.d.ts +0 -26
- package/dist/cjs/utils/arrayUtils.js +0 -151
- package/dist/cjs/utils/arrayUtils.js.map +0 -1
- package/dist/cjs/utils/bigIntLiterals.d.ts +0 -7
- package/dist/cjs/utils/bigIntLiterals.js +0 -12
- package/dist/cjs/utils/bigIntLiterals.js.map +0 -1
- package/dist/cjs/utils/bigIntUtils.d.ts +0 -51
- package/dist/cjs/utils/bigIntUtils.js +0 -158
- package/dist/cjs/utils/bigIntUtils.js.map +0 -1
- package/dist/cjs/utils/boxUtils.d.ts +0 -21
- package/dist/cjs/utils/boxUtils.js +0 -110
- package/dist/cjs/utils/boxUtils.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -6
- package/dist/cjs/utils/index.js +0 -23
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/objectUtils.d.ts +0 -3
- package/dist/cjs/utils/objectUtils.js +0 -23
- package/dist/cjs/utils/objectUtils.js.map +0 -1
- package/dist/cjs/utils/stringUtils.d.ts +0 -7
- package/dist/cjs/utils/stringUtils.js +0 -21
- package/dist/cjs/utils/stringUtils.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/types/boxes.d.ts +0 -22
- package/dist/esm/types/boxes.js +0 -2
- package/dist/esm/types/boxes.js.map +0 -1
- package/dist/esm/types/common.d.ts +0 -18
- package/dist/esm/types/common.js +0 -12
- package/dist/esm/types/common.js.map +0 -1
- package/dist/esm/types/contextExtension.d.ts +0 -4
- package/dist/esm/types/contextExtension.js +0 -2
- package/dist/esm/types/contextExtension.js.map +0 -1
- package/dist/esm/types/index.d.ts +0 -8
- package/dist/esm/types/index.js +0 -9
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/types/inputs.d.ts +0 -37
- package/dist/esm/types/inputs.js +0 -2
- package/dist/esm/types/inputs.js.map +0 -1
- package/dist/esm/types/proverResult.d.ts +0 -6
- package/dist/esm/types/proverResult.js +0 -2
- package/dist/esm/types/proverResult.js.map +0 -1
- package/dist/esm/types/registers.d.ts +0 -9
- package/dist/esm/types/registers.js +0 -2
- package/dist/esm/types/registers.js.map +0 -1
- package/dist/esm/types/token.d.ts +0 -18
- package/dist/esm/types/token.js +0 -2
- package/dist/esm/types/token.js.map +0 -1
- package/dist/esm/types/transactions.d.ts +0 -22
- package/dist/esm/types/transactions.js +0 -2
- package/dist/esm/types/transactions.js.map +0 -1
- package/dist/esm/utils/arrayUtils.d.ts +0 -26
- package/dist/esm/utils/arrayUtils.js +0 -135
- package/dist/esm/utils/arrayUtils.js.map +0 -1
- package/dist/esm/utils/bigIntLiterals.d.ts +0 -7
- package/dist/esm/utils/bigIntLiterals.js +0 -9
- package/dist/esm/utils/bigIntLiterals.js.map +0 -1
- package/dist/esm/utils/bigIntUtils.d.ts +0 -51
- package/dist/esm/utils/bigIntUtils.js +0 -148
- package/dist/esm/utils/bigIntUtils.js.map +0 -1
- package/dist/esm/utils/boxUtils.d.ts +0 -21
- package/dist/esm/utils/boxUtils.js +0 -103
- package/dist/esm/utils/boxUtils.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -6
- package/dist/esm/utils/index.js +0 -7
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/esm/utils/objectUtils.d.ts +0 -3
- package/dist/esm/utils/objectUtils.js +0 -17
- package/dist/esm/utils/objectUtils.js.map +0 -1
- package/dist/esm/utils/stringUtils.d.ts +0 -7
- package/dist/esm/utils/stringUtils.js +0 -16
- package/dist/esm/utils/stringUtils.js.map +0 -1
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/utils/bigIntLiterals.ts +0 -9
- package/src/utils/objectUtils.ts +0 -19
- package/src/utils/stringUtils.ts +0 -18
@@ -1,18 +0,0 @@
|
|
1
|
-
export type HexString = string;
|
2
|
-
export type ErgoTree = string;
|
3
|
-
export type Base58String = string;
|
4
|
-
export type Amount = string | bigint;
|
5
|
-
export type OneOrMore<T> = T | T[];
|
6
|
-
export type SortingSelector<T> = (item: T) => string | number | bigint;
|
7
|
-
export type SortingDirection = "asc" | "desc";
|
8
|
-
export type FilterPredicate<T> = (item: T) => boolean;
|
9
|
-
export type BuildOutputType = "default" | "EIP-12";
|
10
|
-
export declare enum Network {
|
11
|
-
Mainnet = 0,
|
12
|
-
Testnet = 16
|
13
|
-
}
|
14
|
-
export declare enum AddressType {
|
15
|
-
P2PK = 1,
|
16
|
-
P2SH = 2,
|
17
|
-
P2S = 3
|
18
|
-
}
|
package/dist/cjs/types/common.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AddressType = exports.Network = void 0;
|
4
|
-
var Network;
|
5
|
-
(function (Network) {
|
6
|
-
Network[Network["Mainnet"] = 0] = "Mainnet";
|
7
|
-
Network[Network["Testnet"] = 16] = "Testnet";
|
8
|
-
})(Network || (exports.Network = Network = {}));
|
9
|
-
var AddressType;
|
10
|
-
(function (AddressType) {
|
11
|
-
AddressType[AddressType["P2PK"] = 1] = "P2PK";
|
12
|
-
AddressType[AddressType["P2SH"] = 2] = "P2SH";
|
13
|
-
AddressType[AddressType["P2S"] = 3] = "P2S";
|
14
|
-
})(AddressType || (exports.AddressType = AddressType = {}));
|
15
|
-
//# sourceMappingURL=common.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/types/common.ts"],"names":[],"mappings":";;;AAcA,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,2CAAgB,CAAA;IAChB,4CAAgB,CAAA;AAClB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAED,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,6CAAQ,CAAA;IACR,6CAAQ,CAAA;IACR,2CAAO,CAAA;AACT,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"contextExtension.js","sourceRoot":"","sources":["../../../src/types/contextExtension.ts"],"names":[],"mappings":""}
|
package/dist/cjs/types/index.js
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./boxes"), exports);
|
18
|
-
__exportStar(require("./contextExtension"), exports);
|
19
|
-
__exportStar(require("./inputs"), exports);
|
20
|
-
__exportStar(require("./common"), exports);
|
21
|
-
__exportStar(require("./proverResult"), exports);
|
22
|
-
__exportStar(require("./registers"), exports);
|
23
|
-
__exportStar(require("./token"), exports);
|
24
|
-
__exportStar(require("./transactions"), exports);
|
25
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,qDAAmC;AACnC,2CAAyB;AACzB,2CAAyB;AACzB,iDAA+B;AAC/B,8CAA4B;AAC5B,0CAAwB;AACxB,iDAA+B"}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
import { BoxId } from "./boxes";
|
2
|
-
import { ErgoTree } from "./common";
|
3
|
-
import { ContextExtension } from "./contextExtension";
|
4
|
-
import { ProverResult } from "./proverResult";
|
5
|
-
import { NonMandatoryRegisters } from "./registers";
|
6
|
-
import { TokenAmount } from "./token";
|
7
|
-
import { TransactionId } from "./transactions";
|
8
|
-
export type SignedInput = {
|
9
|
-
readonly boxId: BoxId;
|
10
|
-
readonly spendingProof: ProverResult;
|
11
|
-
};
|
12
|
-
export type UnsignedInput = {
|
13
|
-
boxId: BoxId;
|
14
|
-
extension: ContextExtension;
|
15
|
-
};
|
16
|
-
export type EIP12UnsignedInput = UnsignedInput & {
|
17
|
-
transactionId: TransactionId;
|
18
|
-
index: number;
|
19
|
-
ergoTree: ErgoTree;
|
20
|
-
creationHeight: number;
|
21
|
-
value: string;
|
22
|
-
assets: TokenAmount<string>[];
|
23
|
-
additionalRegisters: NonMandatoryRegisters;
|
24
|
-
};
|
25
|
-
export type EIP12UnsignedDataInput = {
|
26
|
-
boxId: BoxId;
|
27
|
-
transactionId: TransactionId;
|
28
|
-
index: number;
|
29
|
-
ergoTree: ErgoTree;
|
30
|
-
creationHeight: number;
|
31
|
-
value: string;
|
32
|
-
assets: TokenAmount<string>[];
|
33
|
-
additionalRegisters: NonMandatoryRegisters;
|
34
|
-
};
|
35
|
-
export type DataInput = {
|
36
|
-
boxId: BoxId;
|
37
|
-
};
|
package/dist/cjs/types/inputs.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/types/inputs.ts"],"names":[],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"proverResult.js","sourceRoot":"","sources":["../../../src/types/proverResult.ts"],"names":[],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"registers.js","sourceRoot":"","sources":["../../../src/types/registers.ts"],"names":[],"mappings":""}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export type TokenId = string;
|
2
|
-
type TokenBase<AmountType> = {
|
3
|
-
amount: AmountType;
|
4
|
-
};
|
5
|
-
export type TokenAmount<AmountType> = TokenBase<AmountType> & {
|
6
|
-
tokenId: TokenId;
|
7
|
-
};
|
8
|
-
export type NewToken<AmountType> = TokenBase<AmountType> & {
|
9
|
-
tokenId?: TokenId;
|
10
|
-
name?: string;
|
11
|
-
decimals?: number;
|
12
|
-
description?: string;
|
13
|
-
};
|
14
|
-
export type TokenTargetAmount<AmountType> = {
|
15
|
-
tokenId: TokenId;
|
16
|
-
amount?: AmountType;
|
17
|
-
};
|
18
|
-
export {};
|
package/dist/cjs/types/token.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../src/types/token.ts"],"names":[],"mappings":""}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { Box, BoxCandidate } from "./boxes";
|
2
|
-
import { Amount } from "./common";
|
3
|
-
import { DataInput, EIP12UnsignedDataInput, EIP12UnsignedInput, SignedInput, UnsignedInput } from "./inputs";
|
4
|
-
export type TransactionId = string;
|
5
|
-
export type UnsignedTransaction = {
|
6
|
-
id?: TransactionId;
|
7
|
-
inputs: UnsignedInput[];
|
8
|
-
dataInputs: DataInput[];
|
9
|
-
outputs: BoxCandidate<Amount>[];
|
10
|
-
};
|
11
|
-
export type EIP12UnsignedTransaction = {
|
12
|
-
id?: TransactionId;
|
13
|
-
inputs: EIP12UnsignedInput[];
|
14
|
-
dataInputs: EIP12UnsignedDataInput[];
|
15
|
-
outputs: BoxCandidate<string>[];
|
16
|
-
};
|
17
|
-
export type SignedTransaction = {
|
18
|
-
readonly id: TransactionId;
|
19
|
-
readonly inputs: SignedInput[];
|
20
|
-
readonly dataInputs: DataInput[];
|
21
|
-
readonly outputs: Box<Amount>[];
|
22
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../../src/types/transactions.ts"],"names":[],"mappings":""}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { SortingDirection, SortingSelector } from "../types";
|
2
|
-
type ObjectSelector<T> = (item: T) => T[keyof T];
|
3
|
-
export declare function isEmpty<T extends object>(obj?: T): obj is undefined;
|
4
|
-
export declare function isEmpty<T>(array?: T[]): array is undefined;
|
5
|
-
export declare function some<T extends object>(obj?: T): obj is T;
|
6
|
-
export declare function some<T>(array?: T[]): array is T[];
|
7
|
-
export declare function first(array: undefined): undefined;
|
8
|
-
export declare function first(array: Uint8Array): number;
|
9
|
-
export declare function first<T>(array: ArrayLike<T>): T;
|
10
|
-
/**
|
11
|
-
* Check for duplicate elements using the equality operator
|
12
|
-
*/
|
13
|
-
export declare function hasDuplicates<T>(array: T[]): boolean;
|
14
|
-
/**
|
15
|
-
* Check for duplicate keys in complex elements
|
16
|
-
*/
|
17
|
-
export declare function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean;
|
18
|
-
export declare function chunk<T>(array: T[], size: number): T[][];
|
19
|
-
export declare function orderBy<T>(array: T[], iteratee: SortingSelector<T>, order?: SortingDirection): T[];
|
20
|
-
export declare function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean;
|
21
|
-
export declare function areEqualBy<T>(array1: ArrayLike<T>, array2: ArrayLike<T>, selector: ObjectSelector<T>): boolean;
|
22
|
-
export declare function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
|
23
|
-
export declare function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
|
24
|
-
export declare function uniq<T>(array: Array<T>): Array<T>;
|
25
|
-
export declare function uniqBy<T>(array: Array<T>, selector: ObjectSelector<T>, selection?: "keep-first" | "keep-last"): Array<T>;
|
26
|
-
export {};
|
@@ -1,151 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uniqBy = exports.uniq = exports.endsWith = exports.startsWith = exports.areEqualBy = exports.areEqual = exports.orderBy = exports.chunk = exports.hasDuplicatesBy = exports.hasDuplicates = exports.first = exports.some = exports.isEmpty = void 0;
|
4
|
-
function isEmpty(obj) {
|
5
|
-
if (!obj) {
|
6
|
-
return true;
|
7
|
-
}
|
8
|
-
return Array.isArray(obj) ? obj.length === 0 : Object.keys(obj).length === 0;
|
9
|
-
}
|
10
|
-
exports.isEmpty = isEmpty;
|
11
|
-
function some(obj) {
|
12
|
-
return !isEmpty(obj);
|
13
|
-
}
|
14
|
-
exports.some = some;
|
15
|
-
function first(array) {
|
16
|
-
if (!array) {
|
17
|
-
return;
|
18
|
-
}
|
19
|
-
if (!array[0]) {
|
20
|
-
throw Error("Empty array.");
|
21
|
-
}
|
22
|
-
return array[0];
|
23
|
-
}
|
24
|
-
exports.first = first;
|
25
|
-
/**
|
26
|
-
* Check for duplicate elements using the equality operator
|
27
|
-
*/
|
28
|
-
function hasDuplicates(array) {
|
29
|
-
return array.some((item, index) => {
|
30
|
-
return array.indexOf(item) !== index;
|
31
|
-
});
|
32
|
-
}
|
33
|
-
exports.hasDuplicates = hasDuplicates;
|
34
|
-
/**
|
35
|
-
* Check for duplicate keys in complex elements
|
36
|
-
*/
|
37
|
-
function hasDuplicatesBy(array, selector) {
|
38
|
-
return array.some((item, index) => {
|
39
|
-
return array.findIndex((x) => selector(x) === selector(item)) !== index;
|
40
|
-
});
|
41
|
-
}
|
42
|
-
exports.hasDuplicatesBy = hasDuplicatesBy;
|
43
|
-
function chunk(array, size) {
|
44
|
-
if (array.length <= size) {
|
45
|
-
return [array];
|
46
|
-
}
|
47
|
-
const chunks = [];
|
48
|
-
for (let i = 0; i < array.length; i += size) {
|
49
|
-
chunks.push(array.slice(i, i + size));
|
50
|
-
}
|
51
|
-
return chunks;
|
52
|
-
}
|
53
|
-
exports.chunk = chunk;
|
54
|
-
function orderBy(array, iteratee, order = "asc") {
|
55
|
-
return [...array].sort((a, b) => {
|
56
|
-
if (iteratee(a) > iteratee(b)) {
|
57
|
-
return order === "asc" ? 1 : -1;
|
58
|
-
}
|
59
|
-
else if (iteratee(a) < iteratee(b)) {
|
60
|
-
return order === "asc" ? -1 : 1;
|
61
|
-
}
|
62
|
-
else {
|
63
|
-
return 0;
|
64
|
-
}
|
65
|
-
});
|
66
|
-
}
|
67
|
-
exports.orderBy = orderBy;
|
68
|
-
function areEqual(array1, array2) {
|
69
|
-
if (array1 === array2) {
|
70
|
-
return true;
|
71
|
-
}
|
72
|
-
if (array1.length != array2.length) {
|
73
|
-
return false;
|
74
|
-
}
|
75
|
-
for (let i = 0; i < array1.length; i++) {
|
76
|
-
if (array1[i] !== array2[i]) {
|
77
|
-
return false;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
return true;
|
81
|
-
}
|
82
|
-
exports.areEqual = areEqual;
|
83
|
-
function areEqualBy(array1, array2, selector) {
|
84
|
-
if (array1 === array2) {
|
85
|
-
return true;
|
86
|
-
}
|
87
|
-
if (array1.length != array2.length) {
|
88
|
-
return false;
|
89
|
-
}
|
90
|
-
for (let i = 0; i < array1.length; i++) {
|
91
|
-
if (selector(array1[i]) !== selector(array2[i])) {
|
92
|
-
return false;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
return true;
|
96
|
-
}
|
97
|
-
exports.areEqualBy = areEqualBy;
|
98
|
-
function startsWith(array, target) {
|
99
|
-
if (array === target) {
|
100
|
-
return true;
|
101
|
-
}
|
102
|
-
if (target.length > array.length) {
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
for (let i = 0; i < target.length; i++) {
|
106
|
-
if (target[i] !== array[i]) {
|
107
|
-
return false;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
return true;
|
111
|
-
}
|
112
|
-
exports.startsWith = startsWith;
|
113
|
-
function endsWith(array, target) {
|
114
|
-
if (array === target) {
|
115
|
-
return true;
|
116
|
-
}
|
117
|
-
if (target.length > array.length) {
|
118
|
-
return false;
|
119
|
-
}
|
120
|
-
const offset = array.length - target.length;
|
121
|
-
for (let i = target.length - 1; i >= 0; i--) {
|
122
|
-
if (target[i] !== array[i + offset]) {
|
123
|
-
return false;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
return true;
|
127
|
-
}
|
128
|
-
exports.endsWith = endsWith;
|
129
|
-
function uniq(array) {
|
130
|
-
if (isEmpty(array)) {
|
131
|
-
return array;
|
132
|
-
}
|
133
|
-
return Array.from(new Set(array));
|
134
|
-
}
|
135
|
-
exports.uniq = uniq;
|
136
|
-
function uniqBy(array, selector, selection = "keep-first") {
|
137
|
-
if (isEmpty(array)) {
|
138
|
-
return array;
|
139
|
-
}
|
140
|
-
return Array.from(array
|
141
|
-
.reduce((map, e) => {
|
142
|
-
const key = selector(e);
|
143
|
-
if (selection === "keep-first" && map.has(key)) {
|
144
|
-
return map;
|
145
|
-
}
|
146
|
-
return map.set(key, e);
|
147
|
-
}, new Map())
|
148
|
-
.values());
|
149
|
-
}
|
150
|
-
exports.uniqBy = uniqBy;
|
151
|
-
//# sourceMappingURL=arrayUtils.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"arrayUtils.js","sourceRoot":"","sources":["../../../src/utils/arrayUtils.ts"],"names":[],"mappings":";;;AAMA,SAAgB,OAAO,CAAI,GAAkB;IAC3C,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC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AAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAlBD,4BAkBC;AAED,SAAgB,IAAI,CAAI,KAAe;IACrC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACpC,CAAC;AAND,oBAMC;AAED,SAAgB,MAAM,CACpB,KAAe,EACf,QAA2B,EAC3B,YAAwC,YAAY;IAEpD,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,KAAK,CAAC,IAAI,CACf,KAAK;SACF,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACjB,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAExB,IAAI,SAAS,KAAK,YAAY,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC9C,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC;SACZ,MAAM,EAAE,CACZ,CAAC;AACJ,CAAC;AAtBD,wBAsBC"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// Make some ECMAScript parsers happy by not using bigint literals like 123n
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports._128n = exports._127n = exports._63n = exports._10n = exports._7n = exports._1n = exports._0n = void 0;
|
5
|
-
exports._0n = BigInt(0);
|
6
|
-
exports._1n = BigInt(1);
|
7
|
-
exports._7n = BigInt(7);
|
8
|
-
exports._10n = BigInt(10);
|
9
|
-
exports._63n = BigInt(63);
|
10
|
-
exports._127n = BigInt(127);
|
11
|
-
exports._128n = BigInt(128);
|
12
|
-
//# sourceMappingURL=bigIntLiterals.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"bigIntLiterals.js","sourceRoot":"","sources":["../../../src/utils/bigIntLiterals.ts"],"names":[],"mappings":";AAAA,4EAA4E;;;AAE/D,QAAA,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAChB,QAAA,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAChB,QAAA,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAChB,QAAA,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAClB,QAAA,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAClB,QAAA,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACpB,QAAA,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC"}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { Amount } from "../types";
|
2
|
-
type NumberLike = string | number | bigint | boolean;
|
3
|
-
export declare function ensureBigInt(number: NumberLike): bigint;
|
4
|
-
type ParsingOptions = {
|
5
|
-
/**
|
6
|
-
* Number of decimals.
|
7
|
-
*/
|
8
|
-
decimals?: number;
|
9
|
-
/**
|
10
|
-
* Thousand mark char.
|
11
|
-
* Default: `.`
|
12
|
-
*/
|
13
|
-
decimalMark?: string;
|
14
|
-
};
|
15
|
-
export declare function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint;
|
16
|
-
type FormattingOptions = {
|
17
|
-
/**
|
18
|
-
* Number of decimals.
|
19
|
-
*/
|
20
|
-
decimals: number;
|
21
|
-
/**
|
22
|
-
* Thousand mark char.
|
23
|
-
*/
|
24
|
-
thousandMark?: string;
|
25
|
-
/**
|
26
|
-
* Decimal mark char.
|
27
|
-
* Default: `.`
|
28
|
-
*/
|
29
|
-
decimalMark?: string;
|
30
|
-
};
|
31
|
-
export declare function decimalize(value: Amount, options?: FormattingOptions | number): string;
|
32
|
-
export declare function sumBy<T>(collection: readonly T[], iteratee: (value: T) => bigint, condition?: (value: T) => boolean): bigint;
|
33
|
-
/**
|
34
|
-
* Converts a hex string to bigint.
|
35
|
-
* @param hex The hex string to be converted.
|
36
|
-
* @returns The bigint value represented by the hex string.
|
37
|
-
*/
|
38
|
-
export declare function hexToBigInt(hex: string): bigint;
|
39
|
-
/**
|
40
|
-
* Serializes a `BigInt` to a hex string
|
41
|
-
* @param value The bigint value to be serialized
|
42
|
-
* @returns Hex representation for the provided `number`.
|
43
|
-
*/
|
44
|
-
export declare function bigIntToHex(value: bigint): string;
|
45
|
-
/**
|
46
|
-
* Returns the two’s complement of a bigint value.
|
47
|
-
* @param value The bigint value to negate.
|
48
|
-
* @returns The two’s complement of `number` as a bigint.
|
49
|
-
*/
|
50
|
-
export declare function _bitNegate(value: bigint): bigint;
|
51
|
-
export {};
|
@@ -1,158 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports._bitNegate = exports.bigIntToHex = exports.hexToBigInt = exports.sumBy = exports.decimalize = exports.undecimalize = exports.ensureBigInt = void 0;
|
4
|
-
const arrayUtils_1 = require("./arrayUtils");
|
5
|
-
const bigIntLiterals_1 = require("./bigIntLiterals");
|
6
|
-
const objectUtils_1 = require("./objectUtils");
|
7
|
-
function ensureBigInt(number) {
|
8
|
-
return typeof number === "bigint" ? number : BigInt(number);
|
9
|
-
}
|
10
|
-
exports.ensureBigInt = ensureBigInt;
|
11
|
-
function undecimalize(decimalStr, options) {
|
12
|
-
if (!decimalStr) {
|
13
|
-
return bigIntLiterals_1._0n;
|
14
|
-
}
|
15
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
16
|
-
if ((0, objectUtils_1.isUndefined)(options)) {
|
17
|
-
options = {};
|
18
|
-
}
|
19
|
-
options.decimals = options.decimals || 0;
|
20
|
-
options.decimalMark = options.decimalMark || ".";
|
21
|
-
const fragments = decimalStr.split(options.decimalMark);
|
22
|
-
if (fragments.length > 2) {
|
23
|
-
throw new Error("Invalid numeric string.");
|
24
|
-
}
|
25
|
-
let [integer, decimal] = fragments;
|
26
|
-
integer = _removeLeadingZeros(integer);
|
27
|
-
const negative = integer.startsWith("-") ? "-" : "";
|
28
|
-
if (!decimal) {
|
29
|
-
decimal = "0".repeat(options.decimals);
|
30
|
-
}
|
31
|
-
else if (decimal.length < options.decimals) {
|
32
|
-
decimal = decimal.padEnd(options.decimals, "0");
|
33
|
-
}
|
34
|
-
return BigInt(negative + _stripNonDigits(integer + decimal));
|
35
|
-
}
|
36
|
-
exports.undecimalize = undecimalize;
|
37
|
-
function _stripNonDigits(value) {
|
38
|
-
return value.replace(/\D/g, "");
|
39
|
-
}
|
40
|
-
function decimalize(value, options) {
|
41
|
-
value = ensureBigInt(value);
|
42
|
-
if (!options) {
|
43
|
-
return value.toString();
|
44
|
-
}
|
45
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
46
|
-
options.decimals = options.decimals || 0;
|
47
|
-
options.decimalMark = options.decimalMark || ".";
|
48
|
-
const pow = bigIntLiterals_1._10n ** BigInt(options.decimals);
|
49
|
-
const integer = value / pow;
|
50
|
-
const decimal = value - integer * pow;
|
51
|
-
return _buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);
|
52
|
-
}
|
53
|
-
exports.decimalize = decimalize;
|
54
|
-
function _buildFormattedDecimal(integer, decimal, options) {
|
55
|
-
const integerPart = _addThousandMarks(integer, options.thousandMark);
|
56
|
-
const decimalPart = _stripTrailingZeros(decimal.padStart(options.decimals, "0"));
|
57
|
-
if (decimalPart) {
|
58
|
-
return `${integerPart}${options.decimalMark}${decimalPart}`;
|
59
|
-
}
|
60
|
-
else {
|
61
|
-
return integerPart;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
function _addThousandMarks(value, mark) {
|
65
|
-
if (!mark) {
|
66
|
-
return value;
|
67
|
-
}
|
68
|
-
return value.replace(/\B(?=(\d{3})+(?!\d))/g, mark);
|
69
|
-
}
|
70
|
-
function _stripTrailingZeros(value) {
|
71
|
-
if (!value.endsWith("0")) {
|
72
|
-
return value;
|
73
|
-
}
|
74
|
-
return value.replace(/\.?0+$/, "");
|
75
|
-
}
|
76
|
-
function _removeLeadingZeros(value) {
|
77
|
-
if (!value.startsWith("0")) {
|
78
|
-
return value;
|
79
|
-
}
|
80
|
-
return value.replace(/^0+\.?/, "");
|
81
|
-
}
|
82
|
-
function sumBy(collection, iteratee, condition) {
|
83
|
-
let acc = bigIntLiterals_1._0n;
|
84
|
-
if ((0, arrayUtils_1.isEmpty)(collection)) {
|
85
|
-
return acc;
|
86
|
-
}
|
87
|
-
for (const item of collection) {
|
88
|
-
if ((0, objectUtils_1.isUndefined)(condition) || condition(item)) {
|
89
|
-
acc += iteratee(item);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return acc;
|
93
|
-
}
|
94
|
-
exports.sumBy = sumBy;
|
95
|
-
/**
|
96
|
-
* Converts a hex string to bigint.
|
97
|
-
* @param hex The hex string to be converted.
|
98
|
-
* @returns The bigint value represented by the hex string.
|
99
|
-
*/
|
100
|
-
function hexToBigInt(hex) {
|
101
|
-
// https://coolaj86.com/articles/convert-hex-to-decimal-with-js-bigints/
|
102
|
-
if (hex.length % 2) {
|
103
|
-
hex = "0" + hex;
|
104
|
-
}
|
105
|
-
const value = BigInt("0x" + hex);
|
106
|
-
const highByte = parseInt(hex.slice(0, 2), 16);
|
107
|
-
if (0x80 & highByte) {
|
108
|
-
return -_bitNegate(value); // add two's complement and invert the number to negative
|
109
|
-
}
|
110
|
-
return value;
|
111
|
-
}
|
112
|
-
exports.hexToBigInt = hexToBigInt;
|
113
|
-
/**
|
114
|
-
* Serializes a `BigInt` to a hex string
|
115
|
-
* @param value The bigint value to be serialized
|
116
|
-
* @returns Hex representation for the provided `number`.
|
117
|
-
*/
|
118
|
-
function bigIntToHex(value) {
|
119
|
-
// implementation inspired on
|
120
|
-
// https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/
|
121
|
-
const positive = value >= bigIntLiterals_1._0n;
|
122
|
-
if (!positive) {
|
123
|
-
value = _bitNegate(value);
|
124
|
-
}
|
125
|
-
let hex = value.toString(16);
|
126
|
-
if (hex.length % 2) {
|
127
|
-
hex = "0" + hex;
|
128
|
-
}
|
129
|
-
if (positive && 0x80 & parseInt(hex.slice(0, 2), 16)) {
|
130
|
-
hex = "00" + hex;
|
131
|
-
}
|
132
|
-
return hex;
|
133
|
-
}
|
134
|
-
exports.bigIntToHex = bigIntToHex;
|
135
|
-
/**
|
136
|
-
* Returns the two’s complement of a bigint value.
|
137
|
-
* @param value The bigint value to negate.
|
138
|
-
* @returns The two’s complement of `number` as a bigint.
|
139
|
-
*/
|
140
|
-
function _bitNegate(value) {
|
141
|
-
const negative = value < bigIntLiterals_1._0n;
|
142
|
-
if (negative) {
|
143
|
-
value = -value; // turn into a positive number
|
144
|
-
}
|
145
|
-
const bits = value.toString(2);
|
146
|
-
let bitLen = bits.length; // convert to binary
|
147
|
-
const mod = bitLen % 8;
|
148
|
-
if (mod > 0) {
|
149
|
-
bitLen += 8 - mod;
|
150
|
-
}
|
151
|
-
else if (negative && (0, arrayUtils_1.first)(bits) === "1" && bits.indexOf("1", 1) !== -1) {
|
152
|
-
bitLen += 8;
|
153
|
-
}
|
154
|
-
const mask = (1n << BigInt(bitLen)) - 1n; // create a mask
|
155
|
-
return (~value & mask) + 1n; // invert bits, mask it, and add one
|
156
|
-
}
|
157
|
-
exports._bitNegate = _bitNegate;
|
158
|
-
//# sourceMappingURL=bigIntUtils.js.map
|