@fleet-sdk/common 0.4.1 → 0.6.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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +29 -28
- package/dist/index.d.ts +29 -28
- package/dist/index.js +51 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -7,20 +7,6 @@ type SortingSelector<T> = (item: T) => string | number | bigint;
|
|
7
7
|
type SortingDirection = "asc" | "desc";
|
8
8
|
type FilterPredicate<T> = (item: T) => boolean;
|
9
9
|
type BuildOutputType = "default" | "EIP-12";
|
10
|
-
declare enum Network {
|
11
|
-
Mainnet = 0,
|
12
|
-
Testnet = 16
|
13
|
-
}
|
14
|
-
declare enum AddressType {
|
15
|
-
P2PK = 1,
|
16
|
-
P2SH = 2,
|
17
|
-
P2S = 3
|
18
|
-
}
|
19
|
-
declare const ergoTreeHeaderFlags: {
|
20
|
-
readonly sizeInclusion: 8;
|
21
|
-
readonly constantSegregation: 16;
|
22
|
-
};
|
23
|
-
type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];
|
24
10
|
|
25
11
|
type NonMandatoryRegisters<T = HexString> = {
|
26
12
|
R4?: T;
|
@@ -162,6 +148,23 @@ type Block = {
|
|
162
148
|
size: number;
|
163
149
|
};
|
164
150
|
|
151
|
+
type EnumConst<T extends object> = T[keyof T];
|
152
|
+
declare enum Network {
|
153
|
+
Mainnet = 0,
|
154
|
+
Testnet = 16
|
155
|
+
}
|
156
|
+
declare enum AddressType {
|
157
|
+
P2PK = 1,
|
158
|
+
P2SH = 2,
|
159
|
+
P2S = 3,
|
160
|
+
ADH = 4
|
161
|
+
}
|
162
|
+
declare const ergoTreeHeaderFlags: {
|
163
|
+
readonly sizeInclusion: 8;
|
164
|
+
readonly constantSegregation: 16;
|
165
|
+
};
|
166
|
+
type ErgoTreeHeaderFlag = EnumConst<typeof ergoTreeHeaderFlags>;
|
167
|
+
|
165
168
|
type ObjectSelector<T> = (item: T) => T[keyof T];
|
166
169
|
/**
|
167
170
|
* Returns the first element of an array.
|
@@ -354,7 +357,7 @@ type ParsingOptions = {
|
|
354
357
|
};
|
355
358
|
/**
|
356
359
|
* Parse a decimal string into a bigint with options
|
357
|
-
* @param
|
360
|
+
* @param input
|
358
361
|
* @param options
|
359
362
|
*
|
360
363
|
* @example
|
@@ -362,7 +365,7 @@ type ParsingOptions = {
|
|
362
365
|
* undecimalize("1", { decimals: 2 }) // 100n
|
363
366
|
* undecimalize("1", 2) // 100n
|
364
367
|
*/
|
365
|
-
declare function undecimalize(
|
368
|
+
declare function undecimalize(input: string, options?: ParsingOptions | number): bigint;
|
366
369
|
type FormattingOptions = {
|
367
370
|
/**
|
368
371
|
* Number of decimals.
|
@@ -450,8 +453,8 @@ declare function max<T extends bigint | number>(...numbers: T[]): T;
|
|
450
453
|
* // { nanoErgs: 30n, tokens: [{ tokenId: "test", amount: 50n }] }
|
451
454
|
* ```
|
452
455
|
*/
|
453
|
-
declare function utxoSum(boxes:
|
454
|
-
declare function utxoSum(boxes:
|
456
|
+
declare function utxoSum(boxes: readonly BoxAmounts[]): BoxSummary;
|
457
|
+
declare function utxoSum(boxes: readonly BoxAmounts[], tokenId: TokenId): bigint;
|
455
458
|
/**
|
456
459
|
* Calculates the difference between two utxos or utxo sets.
|
457
460
|
* @param minuend
|
@@ -466,7 +469,7 @@ declare function utxoSum(boxes: MinimalBoxAmountsArray, tokenId: TokenId): bigin
|
|
466
469
|
* // { nanoErgs: 20n, tokens: [{ tokenId: "test", amount: 30n }] }
|
467
470
|
* ```
|
468
471
|
*/
|
469
|
-
declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[]): BoxSummary;
|
472
|
+
declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[], ignoreSubtrahendLeftoverTokens?: boolean): BoxSummary;
|
470
473
|
/**
|
471
474
|
* Checks if the given registers are densely packed.
|
472
475
|
* @param registers
|
@@ -514,10 +517,10 @@ type BoxSummary = {
|
|
514
517
|
nanoErgs: bigint;
|
515
518
|
tokens: TokenAmount<bigint>[];
|
516
519
|
};
|
517
|
-
type
|
520
|
+
type BoxAmounts = {
|
518
521
|
value: Amount;
|
519
522
|
assets: TokenAmount<Amount>[];
|
520
|
-
}
|
523
|
+
};
|
521
524
|
/**
|
522
525
|
* Ensures that the value and asset amounts of a given box are represented as BigInts.
|
523
526
|
* @returns A new box object with BigInt representation for the value and asset amounts.
|
@@ -555,11 +558,11 @@ type EnsureDefaultsOptions = {
|
|
555
558
|
*/
|
556
559
|
declare function ensureDefaults<T extends object, R extends object>(partial: T | undefined, defaults: R, options?: EnsureDefaultsOptions): R & T;
|
557
560
|
|
558
|
-
type
|
561
|
+
type ErrorMessage = string | Error | (() => string);
|
559
562
|
type Constructable = Function;
|
560
|
-
type
|
561
|
-
declare function assert(condition: boolean, error:
|
562
|
-
declare function assertTypeOf<T>(obj: T, expected:
|
563
|
+
type JSPrimitive = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
564
|
+
declare function assert(condition: boolean, error: ErrorMessage): asserts condition;
|
565
|
+
declare function assertTypeOf<T>(obj: T, expected: JSPrimitive): asserts obj;
|
563
566
|
declare function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj;
|
564
567
|
declare function isEmpty<T>(target: T | null | undefined): target is undefined | null;
|
565
568
|
declare function some<T>(target: T | null | undefined): target is T;
|
@@ -642,10 +645,8 @@ declare class FleetError extends Error {
|
|
642
645
|
constructor(message?: string, options?: ErrorOptions);
|
643
646
|
}
|
644
647
|
declare class NotSupportedError extends FleetError {
|
645
|
-
constructor(message?: string);
|
646
648
|
}
|
647
649
|
declare class BlockchainProviderError extends FleetError {
|
648
|
-
constructor(message?: string, options?: ErrorOptions);
|
649
650
|
}
|
650
651
|
|
651
|
-
export { AddressType, Amount,
|
652
|
+
export { AddressType, type Amount, type Base58String, type Block, type BlockHeader, type BlockHeaderId, type BlockTransactions, BlockchainProviderError, type Box, type BoxAmounts, type BoxCandidate, type BoxId, type BoxSummary, type BuildOutputType, Collection, type CollectionAddOptions, type ContextExtension, type DataInput, type EIP12UnsignedDataInput, type EIP12UnsignedInput, type EIP12UnsignedTransaction, type EnsureDefaultsOptions, type EnumConst, type ErgoTreeHeaderFlag, type ErgoTreeHex, type ErrorMessage, type FilterPredicate, FleetError, type HexString, Network, type NewToken, type NonMandatoryRegisters, NotSupportedError, type OneOrMore, type PoWSolution, type ProverResult, type SignedInput, type SignedTransaction, type SortingDirection, type SortingSelector, type TokenAmount, type TokenId, type TokenTargetAmount, type TransactionId, type UTxOFilterParams, type UnsignedInput, type UnsignedTransaction, _0n, _10n, _127n, _128n, _1n, _63n, _7n, areEqual, areEqualBy, areRegistersDenselyPacked, assert, assertInstanceOf, assertTypeOf, at, byteSizeOf, chunk, clearUndefined, concatBytes, decimalize, depthOf, endsWith, ensureBigInt, ensureDefaults, ensureUTxOBigInt, ergoTreeHeaderFlags, first, hasDuplicates, hasDuplicatesBy, hasKey, isDefined, isEmpty, isFalsy, isHex, isTruthy, isUndefined, last, max, min, orderBy, percent, some, startsWith, sumBy, undecimalize, uniq, uniqBy, utxoDiff, utxoFilter, utxoSum };
|
package/dist/index.d.ts
CHANGED
@@ -7,20 +7,6 @@ type SortingSelector<T> = (item: T) => string | number | bigint;
|
|
7
7
|
type SortingDirection = "asc" | "desc";
|
8
8
|
type FilterPredicate<T> = (item: T) => boolean;
|
9
9
|
type BuildOutputType = "default" | "EIP-12";
|
10
|
-
declare enum Network {
|
11
|
-
Mainnet = 0,
|
12
|
-
Testnet = 16
|
13
|
-
}
|
14
|
-
declare enum AddressType {
|
15
|
-
P2PK = 1,
|
16
|
-
P2SH = 2,
|
17
|
-
P2S = 3
|
18
|
-
}
|
19
|
-
declare const ergoTreeHeaderFlags: {
|
20
|
-
readonly sizeInclusion: 8;
|
21
|
-
readonly constantSegregation: 16;
|
22
|
-
};
|
23
|
-
type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];
|
24
10
|
|
25
11
|
type NonMandatoryRegisters<T = HexString> = {
|
26
12
|
R4?: T;
|
@@ -162,6 +148,23 @@ type Block = {
|
|
162
148
|
size: number;
|
163
149
|
};
|
164
150
|
|
151
|
+
type EnumConst<T extends object> = T[keyof T];
|
152
|
+
declare enum Network {
|
153
|
+
Mainnet = 0,
|
154
|
+
Testnet = 16
|
155
|
+
}
|
156
|
+
declare enum AddressType {
|
157
|
+
P2PK = 1,
|
158
|
+
P2SH = 2,
|
159
|
+
P2S = 3,
|
160
|
+
ADH = 4
|
161
|
+
}
|
162
|
+
declare const ergoTreeHeaderFlags: {
|
163
|
+
readonly sizeInclusion: 8;
|
164
|
+
readonly constantSegregation: 16;
|
165
|
+
};
|
166
|
+
type ErgoTreeHeaderFlag = EnumConst<typeof ergoTreeHeaderFlags>;
|
167
|
+
|
165
168
|
type ObjectSelector<T> = (item: T) => T[keyof T];
|
166
169
|
/**
|
167
170
|
* Returns the first element of an array.
|
@@ -354,7 +357,7 @@ type ParsingOptions = {
|
|
354
357
|
};
|
355
358
|
/**
|
356
359
|
* Parse a decimal string into a bigint with options
|
357
|
-
* @param
|
360
|
+
* @param input
|
358
361
|
* @param options
|
359
362
|
*
|
360
363
|
* @example
|
@@ -362,7 +365,7 @@ type ParsingOptions = {
|
|
362
365
|
* undecimalize("1", { decimals: 2 }) // 100n
|
363
366
|
* undecimalize("1", 2) // 100n
|
364
367
|
*/
|
365
|
-
declare function undecimalize(
|
368
|
+
declare function undecimalize(input: string, options?: ParsingOptions | number): bigint;
|
366
369
|
type FormattingOptions = {
|
367
370
|
/**
|
368
371
|
* Number of decimals.
|
@@ -450,8 +453,8 @@ declare function max<T extends bigint | number>(...numbers: T[]): T;
|
|
450
453
|
* // { nanoErgs: 30n, tokens: [{ tokenId: "test", amount: 50n }] }
|
451
454
|
* ```
|
452
455
|
*/
|
453
|
-
declare function utxoSum(boxes:
|
454
|
-
declare function utxoSum(boxes:
|
456
|
+
declare function utxoSum(boxes: readonly BoxAmounts[]): BoxSummary;
|
457
|
+
declare function utxoSum(boxes: readonly BoxAmounts[], tokenId: TokenId): bigint;
|
455
458
|
/**
|
456
459
|
* Calculates the difference between two utxos or utxo sets.
|
457
460
|
* @param minuend
|
@@ -466,7 +469,7 @@ declare function utxoSum(boxes: MinimalBoxAmountsArray, tokenId: TokenId): bigin
|
|
466
469
|
* // { nanoErgs: 20n, tokens: [{ tokenId: "test", amount: 30n }] }
|
467
470
|
* ```
|
468
471
|
*/
|
469
|
-
declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[]): BoxSummary;
|
472
|
+
declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[], ignoreSubtrahendLeftoverTokens?: boolean): BoxSummary;
|
470
473
|
/**
|
471
474
|
* Checks if the given registers are densely packed.
|
472
475
|
* @param registers
|
@@ -514,10 +517,10 @@ type BoxSummary = {
|
|
514
517
|
nanoErgs: bigint;
|
515
518
|
tokens: TokenAmount<bigint>[];
|
516
519
|
};
|
517
|
-
type
|
520
|
+
type BoxAmounts = {
|
518
521
|
value: Amount;
|
519
522
|
assets: TokenAmount<Amount>[];
|
520
|
-
}
|
523
|
+
};
|
521
524
|
/**
|
522
525
|
* Ensures that the value and asset amounts of a given box are represented as BigInts.
|
523
526
|
* @returns A new box object with BigInt representation for the value and asset amounts.
|
@@ -555,11 +558,11 @@ type EnsureDefaultsOptions = {
|
|
555
558
|
*/
|
556
559
|
declare function ensureDefaults<T extends object, R extends object>(partial: T | undefined, defaults: R, options?: EnsureDefaultsOptions): R & T;
|
557
560
|
|
558
|
-
type
|
561
|
+
type ErrorMessage = string | Error | (() => string);
|
559
562
|
type Constructable = Function;
|
560
|
-
type
|
561
|
-
declare function assert(condition: boolean, error:
|
562
|
-
declare function assertTypeOf<T>(obj: T, expected:
|
563
|
+
type JSPrimitive = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
564
|
+
declare function assert(condition: boolean, error: ErrorMessage): asserts condition;
|
565
|
+
declare function assertTypeOf<T>(obj: T, expected: JSPrimitive): asserts obj;
|
563
566
|
declare function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj;
|
564
567
|
declare function isEmpty<T>(target: T | null | undefined): target is undefined | null;
|
565
568
|
declare function some<T>(target: T | null | undefined): target is T;
|
@@ -642,10 +645,8 @@ declare class FleetError extends Error {
|
|
642
645
|
constructor(message?: string, options?: ErrorOptions);
|
643
646
|
}
|
644
647
|
declare class NotSupportedError extends FleetError {
|
645
|
-
constructor(message?: string);
|
646
648
|
}
|
647
649
|
declare class BlockchainProviderError extends FleetError {
|
648
|
-
constructor(message?: string, options?: ErrorOptions);
|
649
650
|
}
|
650
651
|
|
651
|
-
export { AddressType, Amount,
|
652
|
+
export { AddressType, type Amount, type Base58String, type Block, type BlockHeader, type BlockHeaderId, type BlockTransactions, BlockchainProviderError, type Box, type BoxAmounts, type BoxCandidate, type BoxId, type BoxSummary, type BuildOutputType, Collection, type CollectionAddOptions, type ContextExtension, type DataInput, type EIP12UnsignedDataInput, type EIP12UnsignedInput, type EIP12UnsignedTransaction, type EnsureDefaultsOptions, type EnumConst, type ErgoTreeHeaderFlag, type ErgoTreeHex, type ErrorMessage, type FilterPredicate, FleetError, type HexString, Network, type NewToken, type NonMandatoryRegisters, NotSupportedError, type OneOrMore, type PoWSolution, type ProverResult, type SignedInput, type SignedTransaction, type SortingDirection, type SortingSelector, type TokenAmount, type TokenId, type TokenTargetAmount, type TransactionId, type UTxOFilterParams, type UnsignedInput, type UnsignedTransaction, _0n, _10n, _127n, _128n, _1n, _63n, _7n, areEqual, areEqualBy, areRegistersDenselyPacked, assert, assertInstanceOf, assertTypeOf, at, byteSizeOf, chunk, clearUndefined, concatBytes, decimalize, depthOf, endsWith, ensureBigInt, ensureDefaults, ensureUTxOBigInt, ergoTreeHeaderFlags, first, hasDuplicates, hasDuplicatesBy, hasKey, isDefined, isEmpty, isFalsy, isHex, isTruthy, isUndefined, last, max, min, orderBy, percent, some, startsWith, sumBy, undecimalize, uniq, uniqBy, utxoDiff, utxoFilter, utxoSum };
|
package/dist/index.js
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
// src/utils/assertions.ts
|
4
4
|
function assert(condition, error) {
|
5
|
-
if (condition)
|
6
|
-
return;
|
5
|
+
if (condition) return;
|
7
6
|
let err = void 0;
|
8
7
|
switch (typeof error) {
|
9
8
|
case "string":
|
@@ -23,22 +22,21 @@ function assertTypeOf(obj, expected) {
|
|
23
22
|
throw new Error(`Expected an object of type '${expected}', got '${type}'.`);
|
24
23
|
}
|
25
24
|
}
|
26
|
-
var toString = (value) => Object.prototype.toString.call(value);
|
27
25
|
function getTypeName(value) {
|
28
|
-
if (value === null)
|
29
|
-
return "null";
|
26
|
+
if (value === null) return "null";
|
30
27
|
const type = typeof value;
|
31
|
-
return type === "object" || type === "function" ? toString(value).slice(8, -1) : type;
|
28
|
+
return type === "object" || type === "function" ? Object.prototype.toString.call(value).slice(8, -1) : type;
|
32
29
|
}
|
33
30
|
function assertInstanceOf(obj, expected) {
|
34
31
|
const condition = obj instanceof expected;
|
35
32
|
if (!condition) {
|
36
|
-
throw new Error(
|
33
|
+
throw new Error(
|
34
|
+
`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`
|
35
|
+
);
|
37
36
|
}
|
38
37
|
}
|
39
38
|
function isEmpty(target) {
|
40
|
-
if (!target)
|
41
|
-
return true;
|
39
|
+
if (!target) return true;
|
42
40
|
return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;
|
43
41
|
}
|
44
42
|
function some(target) {
|
@@ -62,21 +60,18 @@ function hasKey(o, key) {
|
|
62
60
|
|
63
61
|
// src/utils/array.ts
|
64
62
|
function first(array) {
|
65
|
-
if (!array)
|
66
|
-
return void 0;
|
63
|
+
if (!array) return void 0;
|
67
64
|
assert(array.length > 0, "Empty array.");
|
68
65
|
return array[0];
|
69
66
|
}
|
70
67
|
function last(array) {
|
71
|
-
if (!array)
|
72
|
-
return void 0;
|
68
|
+
if (!array) return void 0;
|
73
69
|
assert(array.length > 0, "Empty array.");
|
74
70
|
return at(array, -1);
|
75
71
|
}
|
76
72
|
function at(array, index) {
|
77
73
|
const len = array?.length;
|
78
|
-
if (!len)
|
79
|
-
return void 0;
|
74
|
+
if (!len) return void 0;
|
80
75
|
if (index < 0) {
|
81
76
|
index += len;
|
82
77
|
}
|
@@ -104,20 +99,16 @@ function chunk(array, size) {
|
|
104
99
|
}
|
105
100
|
function orderBy(array, iteratee, order = "asc") {
|
106
101
|
return [...array].sort((a, b) => {
|
107
|
-
if (iteratee(a) > iteratee(b))
|
108
|
-
|
109
|
-
|
110
|
-
return order === "asc" ? -1 : 1;
|
111
|
-
} else {
|
112
|
-
return 0;
|
113
|
-
}
|
102
|
+
if (iteratee(a) > iteratee(b)) return order === "asc" ? 1 : -1;
|
103
|
+
if (iteratee(a) < iteratee(b)) return order === "asc" ? -1 : 1;
|
104
|
+
return 0;
|
114
105
|
});
|
115
106
|
}
|
116
107
|
function areEqual(array1, array2) {
|
117
108
|
if (array1 === array2) {
|
118
109
|
return true;
|
119
110
|
}
|
120
|
-
if (array1.length
|
111
|
+
if (array1.length !== array2.length) {
|
121
112
|
return false;
|
122
113
|
}
|
123
114
|
for (let i = 0; i < array1.length; i++) {
|
@@ -131,7 +122,7 @@ function areEqualBy(array1, array2, selector) {
|
|
131
122
|
if (array1 === array2) {
|
132
123
|
return true;
|
133
124
|
}
|
134
|
-
if (array1.length
|
125
|
+
if (array1.length !== array2.length) {
|
135
126
|
return false;
|
136
127
|
}
|
137
128
|
for (let i = 0; i < array1.length; i++) {
|
@@ -205,22 +196,20 @@ var _128n = BigInt(128);
|
|
205
196
|
function ensureBigInt(number) {
|
206
197
|
return typeof number === "bigint" ? number : BigInt(number);
|
207
198
|
}
|
208
|
-
function undecimalize(
|
209
|
-
if (!
|
210
|
-
|
211
|
-
}
|
212
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
199
|
+
function undecimalize(input, options) {
|
200
|
+
if (!input) return _0n;
|
201
|
+
options = typeof options === "number" ? { decimals: options } : options;
|
213
202
|
if (isUndefined(options)) {
|
214
203
|
options = {};
|
215
204
|
}
|
216
205
|
options.decimals = options.decimals || 0;
|
217
206
|
options.decimalMark = options.decimalMark || ".";
|
218
|
-
const fragments =
|
207
|
+
const fragments = input.split(options.decimalMark);
|
219
208
|
if (fragments.length > 2) {
|
220
209
|
throw new Error("Invalid numeric string.");
|
221
210
|
}
|
222
211
|
let [integer, decimal] = fragments;
|
223
|
-
integer =
|
212
|
+
integer = removeLeadingZeros(integer);
|
224
213
|
const negative = integer.startsWith("-") ? "-" : "";
|
225
214
|
if (!decimal) {
|
226
215
|
decimal = "0".repeat(options.decimals);
|
@@ -237,39 +226,36 @@ function decimalize(value, options) {
|
|
237
226
|
if (!options) {
|
238
227
|
return value.toString();
|
239
228
|
}
|
240
|
-
options = typeof options
|
229
|
+
options = typeof options === "number" ? { decimals: options } : options;
|
241
230
|
options.decimals = options.decimals || 0;
|
242
231
|
options.decimalMark = options.decimalMark || ".";
|
243
232
|
const pow = _10n ** BigInt(options.decimals);
|
244
233
|
const integer = value / pow;
|
245
234
|
const decimal = value - integer * pow;
|
246
|
-
return
|
235
|
+
return buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);
|
247
236
|
}
|
248
237
|
function percent(value, percentage, precision = 2n) {
|
249
238
|
return value * percentage / 10n ** precision;
|
250
239
|
}
|
251
|
-
function
|
252
|
-
const
|
253
|
-
const
|
254
|
-
if (
|
255
|
-
|
256
|
-
} else {
|
257
|
-
return integerPart;
|
258
|
-
}
|
240
|
+
function buildFormattedDecimal(integer, decimal, options) {
|
241
|
+
const int = addThousandMarks(integer, options.thousandMark);
|
242
|
+
const dec = stripTrailingZeros(decimal.padStart(options.decimals, "0"));
|
243
|
+
if (dec) return `${int}${options.decimalMark}${dec}`;
|
244
|
+
return int;
|
259
245
|
}
|
260
|
-
function
|
246
|
+
function addThousandMarks(value, mark) {
|
261
247
|
if (!mark) {
|
262
248
|
return value;
|
263
249
|
}
|
264
250
|
return value.replace(/\B(?=(\d{3})+(?!\d))/g, mark);
|
265
251
|
}
|
266
|
-
function
|
252
|
+
function stripTrailingZeros(value) {
|
267
253
|
if (!value.endsWith("0")) {
|
268
254
|
return value;
|
269
255
|
}
|
270
256
|
return value.replace(/\.?0+$/, "");
|
271
257
|
}
|
272
|
-
function
|
258
|
+
function removeLeadingZeros(value) {
|
273
259
|
if (!value.startsWith("0")) {
|
274
260
|
return value;
|
275
261
|
}
|
@@ -331,20 +317,26 @@ function utxoSum(boxes, tokenId) {
|
|
331
317
|
tokens: Object.keys(balances).filter((x) => x !== NANOERGS_TOKEN_ID).map((tokenId2) => ({ tokenId: tokenId2, amount: balances[tokenId2] }))
|
332
318
|
};
|
333
319
|
}
|
334
|
-
function utxoDiff(minuend, subtrahend) {
|
335
|
-
if (Array.isArray(minuend))
|
336
|
-
|
337
|
-
}
|
338
|
-
if (Array.isArray(subtrahend)) {
|
339
|
-
subtrahend = utxoSum(subtrahend);
|
340
|
-
}
|
320
|
+
function utxoDiff(minuend, subtrahend, ignoreSubtrahendLeftoverTokens = false) {
|
321
|
+
if (Array.isArray(minuend)) minuend = utxoSum(minuend);
|
322
|
+
if (Array.isArray(subtrahend)) subtrahend = utxoSum(subtrahend);
|
341
323
|
const tokens = [];
|
342
324
|
const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;
|
325
|
+
const subtrahendTokens = new Map(subtrahend.tokens.map((t) => [t.tokenId, t.amount]));
|
343
326
|
for (const token of minuend.tokens) {
|
344
|
-
const
|
327
|
+
const subtrahendAmount = subtrahendTokens.get(token.tokenId) || _0n;
|
328
|
+
const balance = token.amount - (subtrahendAmount || _0n);
|
345
329
|
if (balance !== _0n) {
|
346
330
|
tokens.push({ tokenId: token.tokenId, amount: balance });
|
347
331
|
}
|
332
|
+
if (subtrahendAmount > _0n) {
|
333
|
+
subtrahendTokens.delete(token.tokenId);
|
334
|
+
}
|
335
|
+
}
|
336
|
+
if (!ignoreSubtrahendLeftoverTokens && subtrahendTokens.size > 0) {
|
337
|
+
for (const [tokenId, amount] of subtrahendTokens) {
|
338
|
+
tokens.push({ tokenId, amount: -amount });
|
339
|
+
}
|
348
340
|
}
|
349
341
|
return { nanoErgs, tokens };
|
350
342
|
}
|
@@ -428,10 +420,8 @@ function clearUndefined(value) {
|
|
428
420
|
return result;
|
429
421
|
}
|
430
422
|
function ensureDefaults(partial, defaults, options) {
|
431
|
-
if (isEmpty(partial))
|
432
|
-
|
433
|
-
if (options?.keepUndefinedKeys)
|
434
|
-
return { ...defaults, ...partial };
|
423
|
+
if (isEmpty(partial)) return defaults;
|
424
|
+
if (options?.keepUndefinedKeys) return { ...defaults, ...partial };
|
435
425
|
const merged = { ...defaults, ...partial };
|
436
426
|
for (const key in merged) {
|
437
427
|
merged[key] = partial[key] ?? defaults[key];
|
@@ -451,18 +441,14 @@ function concatBytes(...arrays) {
|
|
451
441
|
return r;
|
452
442
|
}
|
453
443
|
function isHex(value) {
|
454
|
-
if (!value || value.length % 2)
|
455
|
-
|
456
|
-
if (!value.startsWith("0x")) {
|
457
|
-
value = "0x" + value;
|
458
|
-
}
|
459
|
-
return !isNaN(Number(value));
|
444
|
+
if (!value || value.length % 2) return false;
|
445
|
+
return !Number.isNaN(Number(value.startsWith("0x") ? value : `0x${value}`));
|
460
446
|
}
|
461
447
|
function byteSizeOf(hex) {
|
462
448
|
return hex.length / 2;
|
463
449
|
}
|
464
450
|
|
465
|
-
// src/types/
|
451
|
+
// src/types/enums.ts
|
466
452
|
var Network = /* @__PURE__ */ ((Network2) => {
|
467
453
|
Network2[Network2["Mainnet"] = 0] = "Mainnet";
|
468
454
|
Network2[Network2["Testnet"] = 16] = "Testnet";
|
@@ -472,6 +458,7 @@ var AddressType = /* @__PURE__ */ ((AddressType2) => {
|
|
472
458
|
AddressType2[AddressType2["P2PK"] = 1] = "P2PK";
|
473
459
|
AddressType2[AddressType2["P2SH"] = 2] = "P2SH";
|
474
460
|
AddressType2[AddressType2["P2S"] = 3] = "P2S";
|
461
|
+
AddressType2[AddressType2["ADH"] = 4] = "ADH";
|
475
462
|
return AddressType2;
|
476
463
|
})(AddressType || {});
|
477
464
|
var ergoTreeHeaderFlags = {
|
@@ -579,14 +566,8 @@ var FleetError = class extends Error {
|
|
579
566
|
}
|
580
567
|
};
|
581
568
|
var NotSupportedError = class extends FleetError {
|
582
|
-
constructor(message) {
|
583
|
-
super(message);
|
584
|
-
}
|
585
569
|
};
|
586
570
|
var BlockchainProviderError = class extends FleetError {
|
587
|
-
constructor(message, options) {
|
588
|
-
super(message, options);
|
589
|
-
}
|
590
571
|
};
|
591
572
|
|
592
573
|
exports.AddressType = AddressType;
|
@@ -644,5 +625,5 @@ exports.uniqBy = uniqBy;
|
|
644
625
|
exports.utxoDiff = utxoDiff;
|
645
626
|
exports.utxoFilter = utxoFilter;
|
646
627
|
exports.utxoSum = utxoSum;
|
647
|
-
//# sourceMappingURL=
|
628
|
+
//# sourceMappingURL=index.js.map
|
648
629
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/utils/assertions.ts","../src/utils/array.ts","../src/utils/bigInt.ts","../src/utils/utxo.ts","../src/utils/object.ts","../src/utils/bytes.ts","../src/types/common.ts","../src/models/collection.ts","../src/error.ts"],"names":["min","max","tokenId","Network","AddressType"],"mappings":";AAeO,SAAS,OAAO,WAAoB,OAAmD;AAC5F,MAAI;AAAW;AAEf,MAAI,MAAyB;AAC7B,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AACH,YAAM,I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,SAAS;AAChD,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,oBAAN,cAAgC,WAAW;AAAA,EAChD,YAAY,SAAkB;AAC5B,UAAM,OAAO;AAAA,EACf;AACF;AAEO,IAAM,0BAAN,cAAsC,WAAW;AAAA,EACtD,YAAY,SAAkB,SAAwB;AACpD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF","sourcesContent":["export type AssertErrorMessageInput = string | Error | (() => string);\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype Constructable = Function;\n\ntype JSPrimitiveTypes =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\nexport function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition {\n if (condition) return;\n\n let err: Error | undefined = undefined;\n switch (typeof error) {\n case \"string\":\n err = new Error(error);\n break;\n case \"function\":\n err = new Error(error());\n break;\n default:\n err = error;\n }\n\n throw err;\n}\n\nexport function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj {\n const type = typeof obj;\n\n if (type !== expected) {\n throw new Error(`Expected an object of type '${expected}', got '${type}'.`);\n }\n}\n\nconst toString = (value: unknown) => Object.prototype.toString.call(value);\nfunction getTypeName(value: unknown): string {\n if (value === null) return \"null\";\n const type = typeof value;\n\n return type === \"object\" || type === \"function\" ? toString(value).slice(8, -1) : type;\n}\n\nexport function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj {\n const condition = obj instanceof expected;\n\n if (!condition) {\n throw new Error(`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`);\n }\n}\n\nexport function isEmpty<T>(target: T | null | undefined): target is undefined | null {\n if (!target) return true;\n\n return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;\n}\n\nexport function some<T>(target: T | null | undefined): target is T {\n return !isEmpty(target);\n}\n\nexport function isTruthy<T>(value?: T): value is NonNullable<T> {\n return !!value;\n}\n\nexport function isFalsy<T>(value?: T): value is undefined {\n return !value;\n}\n\nexport function isUndefined(v: unknown): v is undefined {\n return v === undefined || v === null || Number.isNaN(v);\n}\n\nexport function isDefined<T>(v: T | undefined): v is T {\n return !isUndefined(v);\n}\n\nexport function hasKey(o: unknown, key: PropertyKey): boolean {\n return Object.prototype.hasOwnProperty.call(o, key);\n}\n","import { SortingDirection, SortingSelector } from \"../types\";\nimport { assert, isEmpty } from \"./assertions\";\n\ntype ObjectSelector<T> = (item: T) => T[keyof T];\n\n/**\n * Returns the first element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function first(array: undefined): undefined;\nexport function first<T>(array: ArrayLike<T>): T;\nexport function first<T>(array: ArrayLike<T> | undefined): T | number | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return array[0];\n}\n\n/**\n * Returns the last element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function last(array: undefined): undefined;\nexport function last<T>(array: ArrayLike<T>): T;\nexport function last<T>(array: ArrayLike<T> | undefined): T | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return at(array, -1);\n}\n\n/**\n * Returns the element at the specified index. Negative indices are counted from the end of the array.\n * @param array\n * @param index\n */\nexport function at(array: undefined, index: number): undefined;\nexport function at<T>(array: ArrayLike<T>, index: number): T;\nexport function at<T>(array: ArrayLike<T> | undefined, index: number): T | undefined {\n const len = array?.length;\n if (!len) return undefined;\n\n if (index < 0) {\n index += len;\n }\n\n return array[index];\n}\n\n/**\n * Check for duplicate elements using the equality operator\n */\nexport function hasDuplicates<T>(array: T[]): boolean {\n return array.some((item, index) => {\n return array.indexOf(item) !== index;\n });\n}\n\n/**\n * Check for duplicate keys in complex elements\n */\nexport function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean {\n return array.some((item, index) => {\n return array.findIndex((x) => selector(x) === selector(item)) !== index;\n });\n}\n\n/**\n * Turns an array into chunks of the specified size\n * @param array\n * @param size\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const chunks = chunk(array, 2);\n * console.log(chunks);\n * // [[1, 2], [3, 4], [5]]\n * ```\n */\nexport function chunk<T>(array: T[], size: number): T[][] {\n if (array.length <= size) {\n return [array];\n }\n\n const chunks: T[][] = [];\n for (let i = 0; i < array.length; i += size) {\n chunks.push(array.slice(i, i + size));\n }\n\n return chunks;\n}\n\n/**\n * Sorts an array of objects by the specified property\n * @param array\n * @param iteratee\n * @param order\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const sorted = orderBy(array, (item) => item.age, \"desc\");\n * console.log(sorted);\n * // [{ name: \"Jane\", age: 30 }, { name: \"John\", age: 25 }]\n * ```\n */\nexport function orderBy<T>(\n array: T[],\n iteratee: SortingSelector<T>,\n order: SortingDirection = \"asc\"\n): T[] {\n return [...array].sort((a: T, b: T) => {\n if (iteratee(a) > iteratee(b)) {\n return order === \"asc\" ? 1 : -1;\n } else if (iteratee(a) < iteratee(b)) {\n return order === \"asc\" ? -1 : 1;\n } else {\n return 0;\n }\n });\n}\n\n/**\n * Checks if arrays are equal\n * @param array1\n * @param array2\n *\n * @example\n * ```\n * const array1 = [1, 2, 3];\n * const array2 = [1, 2, 3];\n * const array3 = [1, 2, 4];\n * const array4 = [1, 2, 3, 4];\n * areEqual(array1, array2); // true\n * areEqual(array1, array3); // false\n * areEqual(array1, array4); // false\n * ```\n */\nexport function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length != array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if arrays are equal by the specified property\n * @param array1\n * @param array2\n * @param selector\n *\n * @example\n * ```\n * const array1 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array2 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array3 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 31 }];\n *\n * areEqualBy(array1, array2, (item) => item.age); // true\n * areEqualBy(array1, array3, (item) => item.age); // false\n * ```\n */\nexport function areEqualBy<T>(\n array1: ArrayLike<T>,\n array2: ArrayLike<T>,\n selector: ObjectSelector<T>\n): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length != array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (selector(array1[i]) !== selector(array2[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array starts with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [1, 2];\n * const target2 = [1, 3];\n *\n * startsWith(array, target1); // true\n * startsWith(array, target2); // false\n * ```\n */\nexport function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n for (let i = 0; i < target.length; i++) {\n if (target[i] !== array[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array ends with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [4, 5];\n * const target2 = [3, 5];\n *\n * endsWith(array, target1); // true\n * endsWith(array, target2); // false\n * ```\n */\nexport function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n const offset = array.length - target.length;\n\n for (let i = target.length - 1; i >= 0; i--) {\n if (target[i] !== array[i + offset]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Makes an array unique by removing duplicate elements\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, 3, 4, 5, 5];\n * const unique = uniq(array);\n * console.log(unique);\n * // [1, 2, 3, 4, 5]\n * ```\n */\nexport function uniq<T>(array: Array<T>): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(new Set(array));\n}\n\n/**\n * Makes an array unique by removing duplicate elements using the specified property\n * @param array\n * @param selector\n * @param selection\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }, { name: \"John\", age: 30 }];\n * const unique = uniqBy(array, (item) => item.name);\n * console.log(unique);\n * // [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }]\n * ```\n */\nexport function uniqBy<T>(\n array: Array<T>,\n selector: ObjectSelector<T>,\n selection: \"keep-first\" | \"keep-last\" = \"keep-first\"\n): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(\n array\n .reduce((map, e) => {\n const key = selector(e);\n\n if (selection === \"keep-first\" && map.has(key)) {\n return map;\n }\n\n return map.set(key, e);\n }, new Map())\n .values()\n );\n}\n\n/**\n * Returns the depth of an array\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, [4, 5, [6, 7]]];\n * const depth = depthOf(array);\n * console.log(depth);\n * // 3\n */\nexport function depthOf(array: unknown | unknown[]): number {\n return Array.isArray(array) ? 1 + Math.max(0, ...array.map(depthOf)) : 0;\n}\n","import { Amount } from \"../types\";\nimport { first } from \"./array\";\nimport { isEmpty, isUndefined } from \"./assertions\";\n\ntype NumberLike = string | number | bigint | boolean;\n\nexport const _0n = BigInt(0);\nexport const _1n = BigInt(1);\nexport const _7n = BigInt(7);\nexport const _10n = BigInt(10);\nexport const _63n = BigInt(63);\nexport const _127n = BigInt(127);\nexport const _128n = BigInt(128);\n\n/**\n * Ensure that the given value is a bigint\n * @param number\n */\nexport function ensureBigInt(number: NumberLike): bigint {\n return typeof number === \"bigint\" ? number : BigInt(number);\n}\n\ntype ParsingOptions = {\n /**\n * Number of decimals.\n */\n decimals?: number;\n\n /**\n * Thousand mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Parse a decimal string into a bigint with options\n * @param decimalStr\n * @param options\n *\n * @example\n * undecimalize(\"129.8379183\", { decimals: 9 }) // 129837918300n\n * undecimalize(\"1\", { decimals: 2 }) // 100n\n * undecimalize(\"1\", 2) // 100n\n */\nexport function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint {\n if (!decimalStr) {\n return _0n;\n }\n\n options = typeof options == \"number\" ? { decimals: options } : options;\n if (isUndefined(options)) {\n options = {};\n }\n\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const fragments = decimalStr.split(options.decimalMark);\n if (fragments.length > 2) {\n throw new Error(\"Invalid numeric string.\");\n }\n\n let [integer, decimal] = fragments;\n integer = _removeLeadingZeros(integer);\n const negative = integer.startsWith(\"-\") ? \"-\" : \"\";\n\n if (!decimal) {\n decimal = \"0\".repeat(options.decimals);\n } else if (decimal.length < options.decimals) {\n decimal = decimal.padEnd(options.decimals, \"0\");\n }\n\n return BigInt(negative + _stripNonDigits(integer + decimal));\n}\n\n/**\n * Strip all non-digits from a string\n * @param value\n */\nfunction _stripNonDigits(value: string): string {\n return value.replace(/\\D/g, \"\");\n}\n\ntype FormattingOptions = {\n /**\n * Number of decimals.\n */\n decimals: number;\n\n /**\n * Thousand mark char.\n */\n thousandMark?: string;\n\n /**\n * Decimal mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Format a bigint into a decimal string with options\n * @param value\n * @param options\n *\n * @example\n * decimalize(129837918300n, { decimals: 9 }) // \"129.8379183\"\n * decimalize(100n, { decimals: 2 }) // \"1\"\n */\nexport function decimalize(value: Amount, options?: FormattingOptions | number): string {\n value = ensureBigInt(value);\n if (!options) {\n return value.toString();\n }\n\n options = typeof options == \"number\" ? { decimals: options } : options;\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const pow = _10n ** BigInt(options.decimals);\n const integer = value / pow;\n const decimal = value - integer * pow;\n\n return _buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);\n}\n\n/**\n * Format a bigint percentage into a decimal string with options\n * @param value\n * @param percentage\n * @param precision\n *\n * @example\n * ```\n * percent(3498n, 1n) // 34n(1%)\n * percent(3498n, 2n) // 69n(2%)\n * percent(3498n, 10n) // 349n(10%)\n * ```\n *\n */\nexport function percent(value: bigint, percentage: bigint, precision = 2n) {\n return (value * percentage) / 10n ** precision;\n}\n\nfunction _buildFormattedDecimal(\n integer: string,\n decimal: string,\n options: FormattingOptions\n): string {\n const integerPart = _addThousandMarks(integer, options.thousandMark);\n const decimalPart = _stripTrailingZeros(decimal.padStart(options.decimals, \"0\"));\n\n if (decimalPart) {\n return `${integerPart}${options.decimalMark}${decimalPart}`;\n } else {\n return integerPart;\n }\n}\n\nfunction _addThousandMarks(value: string, mark?: string): string {\n if (!mark) {\n return value;\n }\n\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, mark);\n}\n\nfunction _stripTrailingZeros(value: string): string {\n if (!value.endsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/\\.?0+$/, \"\");\n}\n\nfunction _removeLeadingZeros(value: string): string {\n if (!value.startsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/^0+\\.?/, \"\");\n}\n\n/**\n * Sum a collection of numbers by a given iteratee\n * @param collection\n * @param iteratee\n * @param condition\n *\n * @example\n * ```\n * const values = [\n * { key: 1, value: 100n },\n * { key: 2, value: 200n },\n * { key: 3, value: 300n },\n * { key: 4, value: 400n },\n * ];\n *\n * sumBy(values, x => x.value) // 1000n\n * sumBy(values, x => x.value, x => x.key < 0) // 0n\n * sumBy(values, x => x.value, x => x.key % 2 === 0) // 600n\n */\nexport function sumBy<T>(\n collection: readonly T[],\n iteratee: (value: T) => bigint,\n condition?: (value: T) => boolean\n): bigint {\n let acc = _0n;\n if (isEmpty(collection)) {\n return acc;\n }\n\n for (const item of collection) {\n if (isUndefined(condition) || condition(item)) {\n acc += iteratee(item);\n }\n }\n\n return acc;\n}\n\n/**\n * Get the minimum value from a collection of numbers\n * @param numbers\n */\nexport function min<T extends bigint | number>(...numbers: T[]): T {\n let min = first(numbers);\n\n for (const num of numbers) {\n if (num < min) {\n min = num;\n }\n }\n\n return min;\n}\n\n/**\n * Get the maximum value from a collection of numbers\n * @param numbers\n */\nexport function max<T extends bigint | number>(...numbers: T[]): T {\n let max = first(numbers);\n\n for (const num of numbers) {\n if (num > max) {\n max = num;\n }\n }\n\n return max;\n}\n","import { Amount, Box, BoxCandidate, NonMandatoryRegisters, TokenAmount, TokenId } from \"../types\";\nimport { isDefined, isEmpty, isUndefined } from \"./assertions\";\nimport { ensureBigInt } from \"./bigInt\";\nimport { _0n } from \"./bigInt\";\n\nconst NANOERGS_TOKEN_ID = \"nanoErgs\";\n\n/**\n * Calculates the sum of all nanoErgs and tokens in the given boxes.\n * @param boxes\n *\n * @example\n * ```\n * const boxes = [\n * { value: \"10\", assets: [{ tokenId: \"test\", amount: \"20\" }] },\n * { value: 20n, assets: [{ tokenId: \"test\", amount: 30n }] }\n * ];\n *\n * const sum = utxoSum(boxes);\n * console.log(sum);\n * // { nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }\n * ```\n */\nexport function utxoSum(boxes: MinimalBoxAmountsArray): BoxSummary;\nexport function utxoSum(boxes: MinimalBoxAmountsArray, tokenId: TokenId): bigint;\nexport function utxoSum(boxes: MinimalBoxAmountsArray, tokenId?: TokenId): BoxSummary | bigint {\n const balances: { [tokenId: string]: bigint } = {};\n\n for (const box of boxes) {\n if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {\n balances[NANOERGS_TOKEN_ID] = (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);\n }\n\n if (tokenId !== NANOERGS_TOKEN_ID) {\n for (const token of box.assets) {\n if (isDefined(tokenId) && tokenId !== token.tokenId) {\n continue;\n }\n\n balances[token.tokenId] = (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);\n }\n }\n }\n\n if (isDefined(tokenId)) {\n return balances[tokenId] || _0n;\n }\n\n return {\n nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,\n tokens: Object.keys(balances)\n .filter((x) => x !== NANOERGS_TOKEN_ID)\n .map((tokenId) => ({ tokenId, amount: balances[tokenId] }))\n };\n}\n\n/**\n * Calculates the difference between two utxos or utxo sets.\n * @param minuend\n * @param subtrahend\n *\n * @example\n * ```\n * const minuend = [{ nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }];\n * const subtrahend = [{ nanoErgs: 10n, tokens: [{ tokenId: \"test\", amount: 20n }] }];\n * const diff = utxoDiff(minuend, subtrahend);\n * console.log(diff);\n * // { nanoErgs: 20n, tokens: [{ tokenId: \"test\", amount: 30n }] }\n * ```\n */\nexport function utxoDiff(\n minuend: BoxSummary | Box<Amount>[],\n subtrahend: BoxSummary | Box<Amount>[]\n): BoxSummary {\n if (Array.isArray(minuend)) {\n minuend = utxoSum(minuend);\n }\n\n if (Array.isArray(subtrahend)) {\n subtrahend = utxoSum(subtrahend);\n }\n\n const tokens: TokenAmount<bigint>[] = [];\n const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;\n\n for (const token of minuend.tokens) {\n const balance =\n token.amount - (subtrahend.tokens.find((t) => t.tokenId === token.tokenId)?.amount || _0n);\n\n if (balance !== _0n) {\n tokens.push({ tokenId: token.tokenId, amount: balance });\n }\n }\n\n return { nanoErgs, tokens };\n}\n\nconst MIN_NON_MANDATORY_REGISTER_INDEX = 4;\nconst MAX_NON_MANDATORY_REGISTER_INDEX = 9;\n\n/**\n * Checks if the given registers are densely packed.\n * @param registers\n *\n * @example\n * ```\n * const registers = {\n * R4: \"deadbeef\",\n * R6: \"cafe\",\n * };\n * const result = areRegistersDenselyPacked(registers);\n * console.log(result);\n * // false\n */\nexport function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {\n let lastIndex = 0;\n for (let i = MIN_NON_MANDATORY_REGISTER_INDEX; i <= MAX_NON_MANDATORY_REGISTER_INDEX; i++) {\n const key = `R${i}` as keyof NonMandatoryRegisters;\n if (registers[key]) {\n if (i === MIN_NON_MANDATORY_REGISTER_INDEX) {\n lastIndex = i;\n continue;\n }\n\n if (i - lastIndex > 1) {\n return false;\n }\n\n lastIndex = i;\n }\n }\n\n return true;\n}\n\n/**\n * Filters the given utxos by the given filter parameters.\n * @param utxos\n * @param filterParams\n */\nexport function utxoFilter<T extends Amount>(utxos: Box<T>[], filterParams: UTxOFilterParams<T>) {\n if (isEmpty(filterParams) || isEmpty(utxos)) {\n return utxos;\n }\n\n const { by, max } = filterParams;\n let filtered = utxos;\n\n if (by) {\n filtered = utxos.filter(by);\n if (isEmpty(filtered)) {\n return filtered;\n }\n }\n\n if (!max) {\n return filtered;\n }\n\n if (isDefined(max.aggregatedDistinctTokens)) {\n const tokenIds = _getDistinctTokenIds(filtered, max.aggregatedDistinctTokens);\n filtered = filtered.filter(\n (utxo) => isEmpty(utxo.assets) || utxo.assets.every((token) => tokenIds.has(token.tokenId))\n );\n }\n\n if (isDefined(max.count) && filtered.length > max.count) {\n filtered = filtered.slice(0, max.count);\n }\n\n return filtered;\n}\n\nfunction _getDistinctTokenIds(utxos: Box[], max: number): Set<string> {\n const tokenIds = new Set<string>();\n\n for (let i = 0; i < utxos.length && tokenIds.size < max; i++) {\n if (isEmpty(utxos[i].assets) || utxos[i].assets.length > max) {\n continue;\n }\n\n for (const token of utxos[i].assets) {\n tokenIds.add(token.tokenId);\n }\n }\n\n return tokenIds;\n}\n\n/**\n * Parameters for filtering unspent transaction outputs (UTxOs).\n */\nexport type UTxOFilterParams<T extends Amount> = {\n /**\n * A function that returns a boolean indicating whether a given UTxO should be included in the filtered results.\n */\n by?: (utxo: Box<T>) => boolean;\n /**\n * An object specifying the maximum number of UTxOs and distinct tokens to include in the filtered results.\n */\n max?: {\n /**\n * The maximum number of UTxOs to include in the filtered results.\n */\n count?: number;\n /**\n * The maximum number of distinct tokens to include in the filtered results.\n */\n aggregatedDistinctTokens?: number;\n };\n};\n\nexport type BoxSummary = {\n nanoErgs: bigint;\n tokens: TokenAmount<bigint>[];\n};\n\nexport type MinimalBoxAmountsArray = readonly {\n value: Amount;\n assets: TokenAmount<Amount>[];\n}[];\n\n/**\n * Ensures that the value and asset amounts of a given box are represented as BigInts.\n * @returns A new box object with BigInt representation for the value and asset amounts.\n */\nexport function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;\nexport function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;\nexport function ensureUTxOBigInt(\n box: Box<Amount> | BoxCandidate<Amount>\n): BoxCandidate<bigint> | Box<bigint> {\n return {\n ...box,\n value: ensureBigInt(box.value),\n assets: box.assets.map((token) => ({\n tokenId: token.tokenId,\n amount: ensureBigInt(token.amount)\n }))\n };\n}\n","import { isEmpty, isUndefined } from \"./assertions\";\n\n/**\n * Remove undefined values from an object\n * @param value\n *\n * @example\n * ```\n * const obj = { a: 1, b: undefined };\n * const result = clearUndefined(obj);\n * console.log(result); // { a: 1 }\n * ```\n */\nexport function clearUndefined(value: Record<string, unknown>) {\n const result: Record<string, unknown> = {};\n for (const key in value) {\n const val = value[key];\n if (!isUndefined(val)) {\n result[key] = val;\n }\n }\n\n return result;\n}\n\nexport type EnsureDefaultsOptions = { keepUndefinedKeys: boolean };\n\n/**\n * Ensure that the options object has all the default values\n * @param partial\n * @param defaults\n *\n * @example\n * ```\n * const options = { a: 1 };\n * const defaults = { a: 2, b: 3 };\n * const result = ensureDefaults(options, defaults);\n * console.log(result); // { a: 1, b: 3 }\n * ```\n */\nexport function ensureDefaults<T extends object, R extends object>(\n partial: T | undefined,\n defaults: R,\n options?: EnsureDefaultsOptions\n): R & T {\n if (isEmpty(partial)) return defaults as R & T;\n if (options?.keepUndefinedKeys) return { ...defaults, ...partial };\n\n const merged = { ...defaults, ...partial } as Record<string, unknown>;\n for (const key in merged) {\n merged[key] = partial[key as keyof T] ?? defaults[key as keyof R];\n }\n\n return merged as R & T;\n}\n","import { assertInstanceOf } from \".\";\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));\n\n let pad = 0;\n for (const bytes of arrays) {\n assertInstanceOf(bytes, Uint8Array);\n\n r.set(bytes, pad);\n pad += bytes.length;\n }\n\n return r;\n}\n\nexport function isHex(value?: string) {\n if (!value || value.length % 2) return false;\n\n if (!value.startsWith(\"0x\")) {\n value = \"0x\" + value;\n }\n\n return !isNaN(Number(value));\n}\n\n/**\n * Get hex string size in bytes\n * @param hex\n * @returns the byte size if the hex string\n */\nexport function byteSizeOf(hex: string): number {\n return hex.length / 2;\n}\n","export type HexString = string;\nexport type ErgoTreeHex = string;\nexport type Base58String = string;\nexport type Amount = string | bigint;\n\nexport type OneOrMore<T> = T | T[];\n\nexport type SortingSelector<T> = (item: T) => string | number | bigint;\nexport type SortingDirection = \"asc\" | \"desc\";\n\nexport type FilterPredicate<T> = (item: T) => boolean;\n\nexport type BuildOutputType = \"default\" | \"EIP-12\";\n\nexport enum Network {\n Mainnet = 0x00,\n Testnet = 0x10\n}\n\nexport enum AddressType {\n P2PK = 1,\n P2SH = 2,\n P2S = 3\n}\n\nexport const ergoTreeHeaderFlags = {\n sizeInclusion: 0x08,\n constantSegregation: 0x10\n} as const;\n\nexport type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];\n","import { OneOrMore } from \"../types\";\nimport { isDefined } from \"../utils\";\n\nexport type CollectionAddOptions = { index?: number };\n\n/**\n * Collection abstract model\n *\n * @example\n * Define a new collection class with internal type `number` and external type `string`\n * ```\n * class TestCollection extends Collection<number, string> {\n * protected _map(item: string | number): number {\n * return Number(item);\n * }\n * // Some other methods\n * }\n * ```\n *\n */\nexport abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {\n protected readonly _items: InternalType[];\n\n constructor() {\n this._items = [];\n }\n\n protected _isIndexOutOfBounds(index: number): boolean {\n return index < 0 || index >= this._items.length;\n }\n\n [Symbol.iterator](): Iterator<InternalType> {\n let counter = 0;\n\n return {\n next: () => {\n return {\n done: counter >= this.length,\n value: this._items[counter++]\n };\n }\n };\n }\n\n /**\n * Number of items in the collection\n */\n public get length(): number {\n return this._items.length;\n }\n\n /**\n * True if the collection is empty\n */\n public get isEmpty(): boolean {\n return this.length === 0;\n }\n\n /**\n * Get item at index\n * @param index\n * @throws RangeError if index is out of bounds\n */\n public at(index: number): InternalType {\n if (this._isIndexOutOfBounds(index)) {\n throw new RangeError(`Index '${index}' is out of range.`);\n }\n\n return this._items[index];\n }\n\n /**\n * Add item to the collection\n * @param items\n * @param options\n * @returns The new length of the collection\n */\n public add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n return this._addOneOrMore(items, options);\n }\n\n abstract remove(item: unknown): number;\n\n /**\n * Map external type to internal type\n * @param item\n * @protected\n */\n protected abstract _map(item: ExternalType | InternalType): InternalType;\n\n protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number {\n if (isDefined(options) && isDefined(options.index)) {\n if (options.index === this.length) {\n this._items.push(this._map(item));\n\n return this.length;\n }\n\n if (this._isIndexOutOfBounds(options.index)) {\n throw new RangeError(`Index '${options.index}' is out of range.`);\n }\n\n this._items.splice(options.index, 0, this._map(item));\n\n return this.length;\n }\n\n this._items.push(this._map(item));\n\n return this._items.length;\n }\n\n protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n if (Array.isArray(items)) {\n if (isDefined(options) && isDefined(options.index)) {\n items = items.reverse();\n }\n\n for (const item of items) {\n this._addOne(item, options);\n }\n } else {\n this._addOne(items, options);\n }\n\n return this.length;\n }\n\n /**\n * Get the collection as an array\n */\n public toArray(): InternalType[] {\n return [...this._items];\n }\n\n public reduce<U>(\n callbackFn: (\n accumulator: U,\n currentValue: InternalType,\n currentIndex: number,\n array: InternalType[]\n ) => U,\n initialValue: U\n ): U {\n return this._items.reduce(callbackFn, initialValue);\n }\n}\n","export class FleetError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = new.target.name;\n }\n}\n\nexport class NotSupportedError extends FleetError {\n constructor(message?: string) {\n super(message);\n }\n}\n\nexport class BlockchainProviderError extends FleetError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n"]}
|
1
|
+
{"version":3,"sources":["../src/utils/assertions.ts","../src/utils/array.ts","../src/utils/bigInt.ts","../src/utils/utxo.ts","../src/utils/object.ts","../src/utils/bytes.ts","../src/types/enums.ts","../src/models/collection.ts","../src/error.ts"],"names":["min","max","tokenId","Network","AddressType"],"mappings":";;;AAeO,SAAS,MAAA,CAAO,WAAoB,KAAwC,EAAA;AACjF,EAAA,IAAI,SAAW,EAAA,OAAA;AAEf,EAAA,IAAI,GAAyB,GAAA,KAAA,CAAA,CAAA;AAC7B,EAAA,QAAQ,OAAO,KAAO;AAAA,IACpB,KAAK,QAAA;AACH,MAAM,GAAA,GAAA,IAAI,MAAM,KAAK,CAAA,CAAA;AACrB,MAAA,MAAA;AAAA,IACF,KAAK,UAAA;AACH,MAAM,GAAA,GAAA,IAAI,KAAM,CAAA,KAAA,EAAO,CAAA,CAAA;AACvB,MAAA,MAAA;AAAA,IACF;AACE,MAAM,GAAA,GAAA,KAAA,CAAA;AAAA,GACV;AAEA,EAAM,MAAA,GAAA,CAAA;AACR,CAAA;AAEO,SAAS,YAAA,CAAgB,KAAQ,QAAoC,EAAA;AAC1E,EAAA,MAAM,OAAO,OAAO,GAAA,CAAA;AAEpB,EAAA,IAAI,SAAS,QAAU,EAAA;AACrB,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,4BAAA,EAA+B,QAAQ,CAAA,QAAA,EAAW,IAAI,CAAI,EAAA,CAAA,CAAA,CAAA;AAAA,GAC5E;AACF,CAAA;AAEA,SAAS,YAAY,KAAwB,EAAA;AAC3C,EAAI,IAAA,KAAA,KAAU,MAAa,OAAA,MAAA,CAAA;AAC3B,EAAA,MAAM,OAAO,OAAO,KAAA,CAAA;AAEpB,EAAA,OAAO,IAAS,KAAA,QAAA,IAAY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,CAAO,MAAO,CAAA,UAAA,EAAY,YAAY,CAAA,CAAA;AAAA,GACpD;AACF,EAAA;;;AC1Ja,IAAA,UAAA,GAAN,cAAyB,KAAM,CAAA;AAAA,EACpC,WAAA,CAAY,SAAkB,OAAwB,EAAA;AACpD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAEtB,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA,CAAA;AAChD,IAAA,IAAA,CAAK,OAAO,GAAW,CAAA,MAAA,CAAA,IAAA,CAAA;AAAA,GACzB;AACF,EAAA;AAEa,IAAA,iBAAA,GAAN,cAAgC,UAAW,CAAA;AAAC,EAAA;AAEtC,IAAA,uBAAA,GAAN,cAAsC,UAAW,CAAA;AAAC","file":"index.js","sourcesContent":["export type ErrorMessage = string | Error | (() => string);\n\n// biome-ignore lint/complexity/noBannedTypes: <explanation>\ntype Constructable = Function;\n\ntype JSPrimitive =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\nexport function assert(condition: boolean, error: ErrorMessage): asserts condition {\n if (condition) return;\n\n let err: Error | undefined = undefined;\n switch (typeof error) {\n case \"string\":\n err = new Error(error);\n break;\n case \"function\":\n err = new Error(error());\n break;\n default:\n err = error;\n }\n\n throw err;\n}\n\nexport function assertTypeOf<T>(obj: T, expected: JSPrimitive): asserts obj {\n const type = typeof obj;\n\n if (type !== expected) {\n throw new Error(`Expected an object of type '${expected}', got '${type}'.`);\n }\n}\n\nfunction getTypeName(value: unknown): string {\n if (value === null) return \"null\";\n const type = typeof value;\n\n return type === \"object\" || type === \"function\"\n ? Object.prototype.toString.call(value).slice(8, -1)\n : type;\n}\n\nexport function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj {\n const condition = obj instanceof expected;\n\n if (!condition) {\n throw new Error(\n `Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`\n );\n }\n}\n\nexport function isEmpty<T>(target: T | null | undefined): target is undefined | null {\n if (!target) return true;\n\n return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;\n}\n\nexport function some<T>(target: T | null | undefined): target is T {\n return !isEmpty(target);\n}\n\nexport function isTruthy<T>(value?: T): value is NonNullable<T> {\n return !!value;\n}\n\nexport function isFalsy<T>(value?: T): value is undefined {\n return !value;\n}\n\nexport function isUndefined(v: unknown): v is undefined {\n return v === undefined || v === null || Number.isNaN(v);\n}\n\nexport function isDefined<T>(v: T | undefined): v is T {\n return !isUndefined(v);\n}\n\nexport function hasKey(o: unknown, key: PropertyKey): boolean {\n return Object.prototype.hasOwnProperty.call(o, key);\n}\n","import type { SortingDirection, SortingSelector } from \"../types\";\nimport { assert, isEmpty } from \"./assertions\";\n\ntype ObjectSelector<T> = (item: T) => T[keyof T];\n\n/**\n * Returns the first element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function first(array: undefined): undefined;\nexport function first<T>(array: ArrayLike<T>): T;\nexport function first<T>(array: ArrayLike<T> | undefined): T | number | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return array[0];\n}\n\n/**\n * Returns the last element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function last(array: undefined): undefined;\nexport function last<T>(array: ArrayLike<T>): T;\nexport function last<T>(array: ArrayLike<T> | undefined): T | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return at(array, -1);\n}\n\n/**\n * Returns the element at the specified index. Negative indices are counted from the end of the array.\n * @param array\n * @param index\n */\nexport function at(array: undefined, index: number): undefined;\nexport function at<T>(array: ArrayLike<T>, index: number): T;\nexport function at<T>(array: ArrayLike<T> | undefined, index: number): T | undefined {\n const len = array?.length;\n if (!len) return undefined;\n\n if (index < 0) {\n index += len;\n }\n\n return array[index];\n}\n\n/**\n * Check for duplicate elements using the equality operator\n */\nexport function hasDuplicates<T>(array: T[]): boolean {\n return array.some((item, index) => {\n return array.indexOf(item) !== index;\n });\n}\n\n/**\n * Check for duplicate keys in complex elements\n */\nexport function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean {\n return array.some((item, index) => {\n return array.findIndex((x) => selector(x) === selector(item)) !== index;\n });\n}\n\n/**\n * Turns an array into chunks of the specified size\n * @param array\n * @param size\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const chunks = chunk(array, 2);\n * console.log(chunks);\n * // [[1, 2], [3, 4], [5]]\n * ```\n */\nexport function chunk<T>(array: T[], size: number): T[][] {\n if (array.length <= size) {\n return [array];\n }\n\n const chunks: T[][] = [];\n for (let i = 0; i < array.length; i += size) {\n chunks.push(array.slice(i, i + size));\n }\n\n return chunks;\n}\n\n/**\n * Sorts an array of objects by the specified property\n * @param array\n * @param iteratee\n * @param order\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const sorted = orderBy(array, (item) => item.age, \"desc\");\n * console.log(sorted);\n * // [{ name: \"Jane\", age: 30 }, { name: \"John\", age: 25 }]\n * ```\n */\nexport function orderBy<T>(\n array: T[],\n iteratee: SortingSelector<T>,\n order: SortingDirection = \"asc\"\n): T[] {\n return [...array].sort((a: T, b: T) => {\n if (iteratee(a) > iteratee(b)) return order === \"asc\" ? 1 : -1;\n if (iteratee(a) < iteratee(b)) return order === \"asc\" ? -1 : 1;\n return 0;\n });\n}\n\n/**\n * Checks if arrays are equal\n * @param array1\n * @param array2\n *\n * @example\n * ```\n * const array1 = [1, 2, 3];\n * const array2 = [1, 2, 3];\n * const array3 = [1, 2, 4];\n * const array4 = [1, 2, 3, 4];\n * areEqual(array1, array2); // true\n * areEqual(array1, array3); // false\n * areEqual(array1, array4); // false\n * ```\n */\nexport function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length !== array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if arrays are equal by the specified property\n * @param array1\n * @param array2\n * @param selector\n *\n * @example\n * ```\n * const array1 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array2 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array3 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 31 }];\n *\n * areEqualBy(array1, array2, (item) => item.age); // true\n * areEqualBy(array1, array3, (item) => item.age); // false\n * ```\n */\nexport function areEqualBy<T>(\n array1: ArrayLike<T>,\n array2: ArrayLike<T>,\n selector: ObjectSelector<T>\n): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length !== array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (selector(array1[i]) !== selector(array2[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array starts with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [1, 2];\n * const target2 = [1, 3];\n *\n * startsWith(array, target1); // true\n * startsWith(array, target2); // false\n * ```\n */\nexport function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n for (let i = 0; i < target.length; i++) {\n if (target[i] !== array[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array ends with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [4, 5];\n * const target2 = [3, 5];\n *\n * endsWith(array, target1); // true\n * endsWith(array, target2); // false\n * ```\n */\nexport function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n const offset = array.length - target.length;\n\n for (let i = target.length - 1; i >= 0; i--) {\n if (target[i] !== array[i + offset]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Makes an array unique by removing duplicate elements\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, 3, 4, 5, 5];\n * const unique = uniq(array);\n * console.log(unique);\n * // [1, 2, 3, 4, 5]\n * ```\n */\nexport function uniq<T>(array: Array<T>): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(new Set(array));\n}\n\n/**\n * Makes an array unique by removing duplicate elements using the specified property\n * @param array\n * @param selector\n * @param selection\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }, { name: \"John\", age: 30 }];\n * const unique = uniqBy(array, (item) => item.name);\n * console.log(unique);\n * // [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }]\n * ```\n */\nexport function uniqBy<T>(\n array: Array<T>,\n selector: ObjectSelector<T>,\n selection: \"keep-first\" | \"keep-last\" = \"keep-first\"\n): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(\n array\n .reduce((map, e) => {\n const key = selector(e);\n\n if (selection === \"keep-first\" && map.has(key)) {\n return map;\n }\n\n return map.set(key, e);\n }, new Map())\n .values()\n );\n}\n\n/**\n * Returns the depth of an array\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, [4, 5, [6, 7]]];\n * const depth = depthOf(array);\n * console.log(depth);\n * // 3\n */\nexport function depthOf(array: unknown | unknown[]): number {\n return Array.isArray(array) ? 1 + Math.max(0, ...array.map(depthOf)) : 0;\n}\n","import type { Amount } from \"../types\";\nimport { first } from \"./array\";\nimport { isEmpty, isUndefined } from \"./assertions\";\n\ntype NumberLike = string | number | bigint | boolean;\n\nexport const _0n = BigInt(0);\nexport const _1n = BigInt(1);\nexport const _7n = BigInt(7);\nexport const _10n = BigInt(10);\nexport const _63n = BigInt(63);\nexport const _127n = BigInt(127);\nexport const _128n = BigInt(128);\n\n/**\n * Ensure that the given value is a bigint\n * @param number\n */\nexport function ensureBigInt(number: NumberLike): bigint {\n return typeof number === \"bigint\" ? number : BigInt(number);\n}\n\ntype ParsingOptions = {\n /**\n * Number of decimals.\n */\n decimals?: number;\n\n /**\n * Thousand mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Parse a decimal string into a bigint with options\n * @param input\n * @param options\n *\n * @example\n * undecimalize(\"129.8379183\", { decimals: 9 }) // 129837918300n\n * undecimalize(\"1\", { decimals: 2 }) // 100n\n * undecimalize(\"1\", 2) // 100n\n */\nexport function undecimalize(input: string, options?: ParsingOptions | number): bigint {\n if (!input) return _0n;\n\n options = typeof options === \"number\" ? { decimals: options } : options;\n if (isUndefined(options)) {\n options = {};\n }\n\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const fragments = input.split(options.decimalMark);\n if (fragments.length > 2) {\n throw new Error(\"Invalid numeric string.\");\n }\n\n let [integer, decimal] = fragments;\n integer = removeLeadingZeros(integer);\n const negative = integer.startsWith(\"-\") ? \"-\" : \"\";\n\n if (!decimal) {\n decimal = \"0\".repeat(options.decimals);\n } else if (decimal.length < options.decimals) {\n decimal = decimal.padEnd(options.decimals, \"0\");\n }\n\n return BigInt(negative + _stripNonDigits(integer + decimal));\n}\n\n/**\n * Strip all non-digits from a string\n * @param value\n */\nfunction _stripNonDigits(value: string): string {\n return value.replace(/\\D/g, \"\");\n}\n\ntype FormattingOptions = {\n /**\n * Number of decimals.\n */\n decimals: number;\n\n /**\n * Thousand mark char.\n */\n thousandMark?: string;\n\n /**\n * Decimal mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Format a bigint into a decimal string with options\n * @param value\n * @param options\n *\n * @example\n * decimalize(129837918300n, { decimals: 9 }) // \"129.8379183\"\n * decimalize(100n, { decimals: 2 }) // \"1\"\n */\nexport function decimalize(value: Amount, options?: FormattingOptions | number): string {\n value = ensureBigInt(value);\n if (!options) {\n return value.toString();\n }\n\n options = typeof options === \"number\" ? { decimals: options } : options;\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const pow = _10n ** BigInt(options.decimals);\n const integer = value / pow;\n const decimal = value - integer * pow;\n\n return buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);\n}\n\n/**\n * Format a bigint percentage into a decimal string with options\n * @param value\n * @param percentage\n * @param precision\n *\n * @example\n * ```\n * percent(3498n, 1n) // 34n(1%)\n * percent(3498n, 2n) // 69n(2%)\n * percent(3498n, 10n) // 349n(10%)\n * ```\n *\n */\nexport function percent(value: bigint, percentage: bigint, precision = 2n) {\n return (value * percentage) / 10n ** precision;\n}\n\nfunction buildFormattedDecimal(\n integer: string,\n decimal: string,\n options: FormattingOptions\n): string {\n const int = addThousandMarks(integer, options.thousandMark);\n const dec = stripTrailingZeros(decimal.padStart(options.decimals, \"0\"));\n if (dec) return `${int}${options.decimalMark}${dec}`;\n return int;\n}\n\nfunction addThousandMarks(value: string, mark?: string): string {\n if (!mark) {\n return value;\n }\n\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, mark);\n}\n\nfunction stripTrailingZeros(value: string): string {\n if (!value.endsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/\\.?0+$/, \"\");\n}\n\nfunction removeLeadingZeros(value: string): string {\n if (!value.startsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/^0+\\.?/, \"\");\n}\n\n/**\n * Sum a collection of numbers by a given iteratee\n * @param collection\n * @param iteratee\n * @param condition\n *\n * @example\n * ```\n * const values = [\n * { key: 1, value: 100n },\n * { key: 2, value: 200n },\n * { key: 3, value: 300n },\n * { key: 4, value: 400n },\n * ];\n *\n * sumBy(values, x => x.value) // 1000n\n * sumBy(values, x => x.value, x => x.key < 0) // 0n\n * sumBy(values, x => x.value, x => x.key % 2 === 0) // 600n\n */\nexport function sumBy<T>(\n collection: readonly T[],\n iteratee: (value: T) => bigint,\n condition?: (value: T) => boolean\n): bigint {\n let acc = _0n;\n if (isEmpty(collection)) {\n return acc;\n }\n\n for (const item of collection) {\n if (isUndefined(condition) || condition(item)) {\n acc += iteratee(item);\n }\n }\n\n return acc;\n}\n\n/**\n * Get the minimum value from a collection of numbers\n * @param numbers\n */\nexport function min<T extends bigint | number>(...numbers: T[]): T {\n let min = first(numbers);\n\n for (const num of numbers) {\n if (num < min) {\n min = num;\n }\n }\n\n return min;\n}\n\n/**\n * Get the maximum value from a collection of numbers\n * @param numbers\n */\nexport function max<T extends bigint | number>(...numbers: T[]): T {\n let max = first(numbers);\n\n for (const num of numbers) {\n if (num > max) {\n max = num;\n }\n }\n\n return max;\n}\n","import type {\n Amount,\n Box,\n BoxCandidate,\n NonMandatoryRegisters,\n TokenAmount,\n TokenId\n} from \"../types\";\nimport { isDefined, isEmpty, isUndefined } from \"./assertions\";\nimport { ensureBigInt } from \"./bigInt\";\nimport { _0n } from \"./bigInt\";\n\nconst NANOERGS_TOKEN_ID = \"nanoErgs\";\n\n/**\n * Calculates the sum of all nanoErgs and tokens in the given boxes.\n * @param boxes\n *\n * @example\n * ```\n * const boxes = [\n * { value: \"10\", assets: [{ tokenId: \"test\", amount: \"20\" }] },\n * { value: 20n, assets: [{ tokenId: \"test\", amount: 30n }] }\n * ];\n *\n * const sum = utxoSum(boxes);\n * console.log(sum);\n * // { nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }\n * ```\n */\nexport function utxoSum(boxes: readonly BoxAmounts[]): BoxSummary;\nexport function utxoSum(boxes: readonly BoxAmounts[], tokenId: TokenId): bigint;\nexport function utxoSum(boxes: readonly BoxAmounts[], tokenId?: TokenId) {\n const balances: { [tokenId: string]: bigint } = {};\n\n for (const box of boxes) {\n if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {\n balances[NANOERGS_TOKEN_ID] =\n (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);\n }\n\n if (tokenId !== NANOERGS_TOKEN_ID) {\n for (const token of box.assets) {\n if (isDefined(tokenId) && tokenId !== token.tokenId) {\n continue;\n }\n\n balances[token.tokenId] =\n (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);\n }\n }\n }\n\n if (isDefined(tokenId)) {\n return balances[tokenId] || _0n;\n }\n\n return {\n nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,\n tokens: Object.keys(balances)\n .filter((x) => x !== NANOERGS_TOKEN_ID)\n .map((tokenId) => ({ tokenId, amount: balances[tokenId] }))\n };\n}\n\n/**\n * Calculates the difference between two utxos or utxo sets.\n * @param minuend\n * @param subtrahend\n *\n * @example\n * ```\n * const minuend = [{ nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }];\n * const subtrahend = [{ nanoErgs: 10n, tokens: [{ tokenId: \"test\", amount: 20n }] }];\n * const diff = utxoDiff(minuend, subtrahend);\n * console.log(diff);\n * // { nanoErgs: 20n, tokens: [{ tokenId: \"test\", amount: 30n }] }\n * ```\n */\nexport function utxoDiff(\n minuend: BoxSummary | Box<Amount>[],\n subtrahend: BoxSummary | Box<Amount>[],\n ignoreSubtrahendLeftoverTokens = false\n): BoxSummary {\n if (Array.isArray(minuend)) minuend = utxoSum(minuend);\n if (Array.isArray(subtrahend)) subtrahend = utxoSum(subtrahend);\n\n const tokens: TokenAmount<bigint>[] = [];\n const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;\n const subtrahendTokens = new Map(subtrahend.tokens.map((t) => [t.tokenId, t.amount]));\n\n for (const token of minuend.tokens) {\n const subtrahendAmount = subtrahendTokens.get(token.tokenId) || _0n;\n const balance = token.amount - (subtrahendAmount || _0n);\n\n if (balance !== _0n) {\n tokens.push({ tokenId: token.tokenId, amount: balance });\n }\n\n if (subtrahendAmount > _0n) {\n subtrahendTokens.delete(token.tokenId);\n }\n }\n\n if (!ignoreSubtrahendLeftoverTokens && subtrahendTokens.size > 0) {\n for (const [tokenId, amount] of subtrahendTokens) {\n tokens.push({ tokenId, amount: -amount });\n }\n }\n\n return { nanoErgs, tokens };\n}\n\nconst MIN_NON_MANDATORY_REGISTER_INDEX = 4;\nconst MAX_NON_MANDATORY_REGISTER_INDEX = 9;\n\n/**\n * Checks if the given registers are densely packed.\n * @param registers\n *\n * @example\n * ```\n * const registers = {\n * R4: \"deadbeef\",\n * R6: \"cafe\",\n * };\n * const result = areRegistersDenselyPacked(registers);\n * console.log(result);\n * // false\n */\nexport function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {\n let lastIndex = 0;\n for (\n let i = MIN_NON_MANDATORY_REGISTER_INDEX;\n i <= MAX_NON_MANDATORY_REGISTER_INDEX;\n i++\n ) {\n const key = `R${i}` as keyof NonMandatoryRegisters;\n if (registers[key]) {\n if (i === MIN_NON_MANDATORY_REGISTER_INDEX) {\n lastIndex = i;\n continue;\n }\n\n if (i - lastIndex > 1) {\n return false;\n }\n\n lastIndex = i;\n }\n }\n\n return true;\n}\n\n/**\n * Filters the given utxos by the given filter parameters.\n * @param utxos\n * @param filterParams\n */\nexport function utxoFilter<T extends Amount>(\n utxos: Box<T>[],\n filterParams: UTxOFilterParams<T>\n) {\n if (isEmpty(filterParams) || isEmpty(utxos)) {\n return utxos;\n }\n\n const { by, max } = filterParams;\n let filtered = utxos;\n\n if (by) {\n filtered = utxos.filter(by);\n if (isEmpty(filtered)) {\n return filtered;\n }\n }\n\n if (!max) {\n return filtered;\n }\n\n if (isDefined(max.aggregatedDistinctTokens)) {\n const tokenIds = _getDistinctTokenIds(filtered, max.aggregatedDistinctTokens);\n filtered = filtered.filter(\n (utxo) =>\n isEmpty(utxo.assets) || utxo.assets.every((token) => tokenIds.has(token.tokenId))\n );\n }\n\n if (isDefined(max.count) && filtered.length > max.count) {\n filtered = filtered.slice(0, max.count);\n }\n\n return filtered;\n}\n\nfunction _getDistinctTokenIds(utxos: Box[], max: number): Set<string> {\n const tokenIds = new Set<string>();\n\n for (let i = 0; i < utxos.length && tokenIds.size < max; i++) {\n if (isEmpty(utxos[i].assets) || utxos[i].assets.length > max) {\n continue;\n }\n\n for (const token of utxos[i].assets) {\n tokenIds.add(token.tokenId);\n }\n }\n\n return tokenIds;\n}\n\n/**\n * Parameters for filtering unspent transaction outputs (UTxOs).\n */\nexport type UTxOFilterParams<T extends Amount> = {\n /**\n * A function that returns a boolean indicating whether a given UTxO should be included in the filtered results.\n */\n by?: (utxo: Box<T>) => boolean;\n /**\n * An object specifying the maximum number of UTxOs and distinct tokens to include in the filtered results.\n */\n max?: {\n /**\n * The maximum number of UTxOs to include in the filtered results.\n */\n count?: number;\n /**\n * The maximum number of distinct tokens to include in the filtered results.\n */\n aggregatedDistinctTokens?: number;\n };\n};\n\nexport type BoxSummary = {\n nanoErgs: bigint;\n tokens: TokenAmount<bigint>[];\n};\n\nexport type BoxAmounts = {\n value: Amount;\n assets: TokenAmount<Amount>[];\n};\n\n/**\n * Ensures that the value and asset amounts of a given box are represented as BigInts.\n * @returns A new box object with BigInt representation for the value and asset amounts.\n */\nexport function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;\nexport function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;\nexport function ensureUTxOBigInt(\n box: Box<Amount> | BoxCandidate<Amount>\n): BoxCandidate<bigint> | Box<bigint> {\n return {\n ...box,\n value: ensureBigInt(box.value),\n assets: box.assets.map((token) => ({\n tokenId: token.tokenId,\n amount: ensureBigInt(token.amount)\n }))\n };\n}\n","import { isEmpty, isUndefined } from \"./assertions\";\n\n/**\n * Remove undefined values from an object\n * @param value\n *\n * @example\n * ```\n * const obj = { a: 1, b: undefined };\n * const result = clearUndefined(obj);\n * console.log(result); // { a: 1 }\n * ```\n */\nexport function clearUndefined(value: Record<string, unknown>) {\n const result: Record<string, unknown> = {};\n for (const key in value) {\n const val = value[key];\n if (!isUndefined(val)) {\n result[key] = val;\n }\n }\n\n return result;\n}\n\nexport type EnsureDefaultsOptions = { keepUndefinedKeys: boolean };\n\n/**\n * Ensure that the options object has all the default values\n * @param partial\n * @param defaults\n *\n * @example\n * ```\n * const options = { a: 1 };\n * const defaults = { a: 2, b: 3 };\n * const result = ensureDefaults(options, defaults);\n * console.log(result); // { a: 1, b: 3 }\n * ```\n */\nexport function ensureDefaults<T extends object, R extends object>(\n partial: T | undefined,\n defaults: R,\n options?: EnsureDefaultsOptions\n): R & T {\n if (isEmpty(partial)) return defaults as R & T;\n if (options?.keepUndefinedKeys) return { ...defaults, ...partial };\n\n const merged = { ...defaults, ...partial } as Record<string, unknown>;\n for (const key in merged) {\n merged[key] = partial[key as keyof T] ?? defaults[key as keyof R];\n }\n\n return merged as R & T;\n}\n","import { assertInstanceOf } from \".\";\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));\n\n let pad = 0;\n for (const bytes of arrays) {\n assertInstanceOf(bytes, Uint8Array);\n\n r.set(bytes, pad);\n pad += bytes.length;\n }\n\n return r;\n}\n\nexport function isHex(value?: string) {\n if (!value || value.length % 2) return false;\n return !Number.isNaN(Number(value.startsWith(\"0x\") ? value : `0x${value}`));\n}\n\n/**\n * Get hex string size in bytes\n * @param hex\n * @returns the byte size if the hex string\n */\nexport function byteSizeOf(hex: string): number {\n return hex.length / 2;\n}\n","export type EnumConst<T extends object> = T[keyof T];\n\nexport enum Network {\n Mainnet = 0x00,\n Testnet = 0x10\n}\n\nexport enum AddressType {\n P2PK = 1,\n P2SH = 2,\n P2S = 3,\n ADH = 4\n}\n\nexport const ergoTreeHeaderFlags = {\n sizeInclusion: 0x08,\n constantSegregation: 0x10\n} as const;\n\nexport type ErgoTreeHeaderFlag = EnumConst<typeof ergoTreeHeaderFlags>;\n","import type { OneOrMore } from \"../types\";\nimport { isDefined } from \"../utils\";\n\nexport type CollectionAddOptions = { index?: number };\n\n/**\n * Collection abstract model\n *\n * @example\n * Define a new collection class with internal type `number` and external type `string`\n * ```\n * class TestCollection extends Collection<number, string> {\n * protected _map(item: string | number): number {\n * return Number(item);\n * }\n * // Some other methods\n * }\n * ```\n *\n */\nexport abstract class Collection<InternalType, ExternalType>\n implements Iterable<InternalType>\n{\n protected readonly _items: InternalType[];\n\n constructor() {\n this._items = [];\n }\n\n protected _isIndexOutOfBounds(index: number): boolean {\n return index < 0 || index >= this._items.length;\n }\n\n [Symbol.iterator](): Iterator<InternalType> {\n let counter = 0;\n\n return {\n next: () => {\n return {\n done: counter >= this.length,\n value: this._items[counter++]\n };\n }\n };\n }\n\n /**\n * Number of items in the collection\n */\n public get length(): number {\n return this._items.length;\n }\n\n /**\n * True if the collection is empty\n */\n public get isEmpty(): boolean {\n return this.length === 0;\n }\n\n /**\n * Get item at index\n * @param index\n * @throws RangeError if index is out of bounds\n */\n public at(index: number): InternalType {\n if (this._isIndexOutOfBounds(index)) {\n throw new RangeError(`Index '${index}' is out of range.`);\n }\n\n return this._items[index];\n }\n\n /**\n * Add item to the collection\n * @param items\n * @param options\n * @returns The new length of the collection\n */\n public add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n return this._addOneOrMore(items, options);\n }\n\n abstract remove(item: unknown): number;\n\n /**\n * Map external type to internal type\n * @param item\n * @protected\n */\n protected abstract _map(item: ExternalType | InternalType): InternalType;\n\n protected _addOne(\n item: InternalType | ExternalType,\n options?: CollectionAddOptions\n ): number {\n if (isDefined(options) && isDefined(options.index)) {\n if (options.index === this.length) {\n this._items.push(this._map(item));\n\n return this.length;\n }\n\n if (this._isIndexOutOfBounds(options.index)) {\n throw new RangeError(`Index '${options.index}' is out of range.`);\n }\n\n this._items.splice(options.index, 0, this._map(item));\n\n return this.length;\n }\n\n this._items.push(this._map(item));\n\n return this._items.length;\n }\n\n protected _addOneOrMore(\n items: OneOrMore<ExternalType>,\n options?: CollectionAddOptions\n ): number {\n if (Array.isArray(items)) {\n if (isDefined(options) && isDefined(options.index)) {\n items = items.reverse();\n }\n\n for (const item of items) {\n this._addOne(item, options);\n }\n } else {\n this._addOne(items, options);\n }\n\n return this.length;\n }\n\n /**\n * Get the collection as an array\n */\n public toArray(): InternalType[] {\n return [...this._items];\n }\n\n public reduce<U>(\n callbackFn: (\n accumulator: U,\n currentValue: InternalType,\n currentIndex: number,\n array: InternalType[]\n ) => U,\n initialValue: U\n ): U {\n return this._items.reduce(callbackFn, initialValue);\n }\n}\n","export class FleetError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = new.target.name;\n }\n}\n\nexport class NotSupportedError extends FleetError {}\n\nexport class BlockchainProviderError extends FleetError {}\n"]}
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
// src/utils/assertions.ts
|
2
2
|
function assert(condition, error) {
|
3
|
-
if (condition)
|
4
|
-
return;
|
3
|
+
if (condition) return;
|
5
4
|
let err = void 0;
|
6
5
|
switch (typeof error) {
|
7
6
|
case "string":
|
@@ -21,22 +20,21 @@ function assertTypeOf(obj, expected) {
|
|
21
20
|
throw new Error(`Expected an object of type '${expected}', got '${type}'.`);
|
22
21
|
}
|
23
22
|
}
|
24
|
-
var toString = (value) => Object.prototype.toString.call(value);
|
25
23
|
function getTypeName(value) {
|
26
|
-
if (value === null)
|
27
|
-
return "null";
|
24
|
+
if (value === null) return "null";
|
28
25
|
const type = typeof value;
|
29
|
-
return type === "object" || type === "function" ? toString(value).slice(8, -1) : type;
|
26
|
+
return type === "object" || type === "function" ? Object.prototype.toString.call(value).slice(8, -1) : type;
|
30
27
|
}
|
31
28
|
function assertInstanceOf(obj, expected) {
|
32
29
|
const condition = obj instanceof expected;
|
33
30
|
if (!condition) {
|
34
|
-
throw new Error(
|
31
|
+
throw new Error(
|
32
|
+
`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`
|
33
|
+
);
|
35
34
|
}
|
36
35
|
}
|
37
36
|
function isEmpty(target) {
|
38
|
-
if (!target)
|
39
|
-
return true;
|
37
|
+
if (!target) return true;
|
40
38
|
return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;
|
41
39
|
}
|
42
40
|
function some(target) {
|
@@ -60,21 +58,18 @@ function hasKey(o, key) {
|
|
60
58
|
|
61
59
|
// src/utils/array.ts
|
62
60
|
function first(array) {
|
63
|
-
if (!array)
|
64
|
-
return void 0;
|
61
|
+
if (!array) return void 0;
|
65
62
|
assert(array.length > 0, "Empty array.");
|
66
63
|
return array[0];
|
67
64
|
}
|
68
65
|
function last(array) {
|
69
|
-
if (!array)
|
70
|
-
return void 0;
|
66
|
+
if (!array) return void 0;
|
71
67
|
assert(array.length > 0, "Empty array.");
|
72
68
|
return at(array, -1);
|
73
69
|
}
|
74
70
|
function at(array, index) {
|
75
71
|
const len = array?.length;
|
76
|
-
if (!len)
|
77
|
-
return void 0;
|
72
|
+
if (!len) return void 0;
|
78
73
|
if (index < 0) {
|
79
74
|
index += len;
|
80
75
|
}
|
@@ -102,20 +97,16 @@ function chunk(array, size) {
|
|
102
97
|
}
|
103
98
|
function orderBy(array, iteratee, order = "asc") {
|
104
99
|
return [...array].sort((a, b) => {
|
105
|
-
if (iteratee(a) > iteratee(b))
|
106
|
-
|
107
|
-
|
108
|
-
return order === "asc" ? -1 : 1;
|
109
|
-
} else {
|
110
|
-
return 0;
|
111
|
-
}
|
100
|
+
if (iteratee(a) > iteratee(b)) return order === "asc" ? 1 : -1;
|
101
|
+
if (iteratee(a) < iteratee(b)) return order === "asc" ? -1 : 1;
|
102
|
+
return 0;
|
112
103
|
});
|
113
104
|
}
|
114
105
|
function areEqual(array1, array2) {
|
115
106
|
if (array1 === array2) {
|
116
107
|
return true;
|
117
108
|
}
|
118
|
-
if (array1.length
|
109
|
+
if (array1.length !== array2.length) {
|
119
110
|
return false;
|
120
111
|
}
|
121
112
|
for (let i = 0; i < array1.length; i++) {
|
@@ -129,7 +120,7 @@ function areEqualBy(array1, array2, selector) {
|
|
129
120
|
if (array1 === array2) {
|
130
121
|
return true;
|
131
122
|
}
|
132
|
-
if (array1.length
|
123
|
+
if (array1.length !== array2.length) {
|
133
124
|
return false;
|
134
125
|
}
|
135
126
|
for (let i = 0; i < array1.length; i++) {
|
@@ -203,22 +194,20 @@ var _128n = BigInt(128);
|
|
203
194
|
function ensureBigInt(number) {
|
204
195
|
return typeof number === "bigint" ? number : BigInt(number);
|
205
196
|
}
|
206
|
-
function undecimalize(
|
207
|
-
if (!
|
208
|
-
|
209
|
-
}
|
210
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
197
|
+
function undecimalize(input, options) {
|
198
|
+
if (!input) return _0n;
|
199
|
+
options = typeof options === "number" ? { decimals: options } : options;
|
211
200
|
if (isUndefined(options)) {
|
212
201
|
options = {};
|
213
202
|
}
|
214
203
|
options.decimals = options.decimals || 0;
|
215
204
|
options.decimalMark = options.decimalMark || ".";
|
216
|
-
const fragments =
|
205
|
+
const fragments = input.split(options.decimalMark);
|
217
206
|
if (fragments.length > 2) {
|
218
207
|
throw new Error("Invalid numeric string.");
|
219
208
|
}
|
220
209
|
let [integer, decimal] = fragments;
|
221
|
-
integer =
|
210
|
+
integer = removeLeadingZeros(integer);
|
222
211
|
const negative = integer.startsWith("-") ? "-" : "";
|
223
212
|
if (!decimal) {
|
224
213
|
decimal = "0".repeat(options.decimals);
|
@@ -235,39 +224,36 @@ function decimalize(value, options) {
|
|
235
224
|
if (!options) {
|
236
225
|
return value.toString();
|
237
226
|
}
|
238
|
-
options = typeof options
|
227
|
+
options = typeof options === "number" ? { decimals: options } : options;
|
239
228
|
options.decimals = options.decimals || 0;
|
240
229
|
options.decimalMark = options.decimalMark || ".";
|
241
230
|
const pow = _10n ** BigInt(options.decimals);
|
242
231
|
const integer = value / pow;
|
243
232
|
const decimal = value - integer * pow;
|
244
|
-
return
|
233
|
+
return buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);
|
245
234
|
}
|
246
235
|
function percent(value, percentage, precision = 2n) {
|
247
236
|
return value * percentage / 10n ** precision;
|
248
237
|
}
|
249
|
-
function
|
250
|
-
const
|
251
|
-
const
|
252
|
-
if (
|
253
|
-
|
254
|
-
} else {
|
255
|
-
return integerPart;
|
256
|
-
}
|
238
|
+
function buildFormattedDecimal(integer, decimal, options) {
|
239
|
+
const int = addThousandMarks(integer, options.thousandMark);
|
240
|
+
const dec = stripTrailingZeros(decimal.padStart(options.decimals, "0"));
|
241
|
+
if (dec) return `${int}${options.decimalMark}${dec}`;
|
242
|
+
return int;
|
257
243
|
}
|
258
|
-
function
|
244
|
+
function addThousandMarks(value, mark) {
|
259
245
|
if (!mark) {
|
260
246
|
return value;
|
261
247
|
}
|
262
248
|
return value.replace(/\B(?=(\d{3})+(?!\d))/g, mark);
|
263
249
|
}
|
264
|
-
function
|
250
|
+
function stripTrailingZeros(value) {
|
265
251
|
if (!value.endsWith("0")) {
|
266
252
|
return value;
|
267
253
|
}
|
268
254
|
return value.replace(/\.?0+$/, "");
|
269
255
|
}
|
270
|
-
function
|
256
|
+
function removeLeadingZeros(value) {
|
271
257
|
if (!value.startsWith("0")) {
|
272
258
|
return value;
|
273
259
|
}
|
@@ -329,20 +315,26 @@ function utxoSum(boxes, tokenId) {
|
|
329
315
|
tokens: Object.keys(balances).filter((x) => x !== NANOERGS_TOKEN_ID).map((tokenId2) => ({ tokenId: tokenId2, amount: balances[tokenId2] }))
|
330
316
|
};
|
331
317
|
}
|
332
|
-
function utxoDiff(minuend, subtrahend) {
|
333
|
-
if (Array.isArray(minuend))
|
334
|
-
|
335
|
-
}
|
336
|
-
if (Array.isArray(subtrahend)) {
|
337
|
-
subtrahend = utxoSum(subtrahend);
|
338
|
-
}
|
318
|
+
function utxoDiff(minuend, subtrahend, ignoreSubtrahendLeftoverTokens = false) {
|
319
|
+
if (Array.isArray(minuend)) minuend = utxoSum(minuend);
|
320
|
+
if (Array.isArray(subtrahend)) subtrahend = utxoSum(subtrahend);
|
339
321
|
const tokens = [];
|
340
322
|
const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;
|
323
|
+
const subtrahendTokens = new Map(subtrahend.tokens.map((t) => [t.tokenId, t.amount]));
|
341
324
|
for (const token of minuend.tokens) {
|
342
|
-
const
|
325
|
+
const subtrahendAmount = subtrahendTokens.get(token.tokenId) || _0n;
|
326
|
+
const balance = token.amount - (subtrahendAmount || _0n);
|
343
327
|
if (balance !== _0n) {
|
344
328
|
tokens.push({ tokenId: token.tokenId, amount: balance });
|
345
329
|
}
|
330
|
+
if (subtrahendAmount > _0n) {
|
331
|
+
subtrahendTokens.delete(token.tokenId);
|
332
|
+
}
|
333
|
+
}
|
334
|
+
if (!ignoreSubtrahendLeftoverTokens && subtrahendTokens.size > 0) {
|
335
|
+
for (const [tokenId, amount] of subtrahendTokens) {
|
336
|
+
tokens.push({ tokenId, amount: -amount });
|
337
|
+
}
|
346
338
|
}
|
347
339
|
return { nanoErgs, tokens };
|
348
340
|
}
|
@@ -426,10 +418,8 @@ function clearUndefined(value) {
|
|
426
418
|
return result;
|
427
419
|
}
|
428
420
|
function ensureDefaults(partial, defaults, options) {
|
429
|
-
if (isEmpty(partial))
|
430
|
-
|
431
|
-
if (options?.keepUndefinedKeys)
|
432
|
-
return { ...defaults, ...partial };
|
421
|
+
if (isEmpty(partial)) return defaults;
|
422
|
+
if (options?.keepUndefinedKeys) return { ...defaults, ...partial };
|
433
423
|
const merged = { ...defaults, ...partial };
|
434
424
|
for (const key in merged) {
|
435
425
|
merged[key] = partial[key] ?? defaults[key];
|
@@ -449,18 +439,14 @@ function concatBytes(...arrays) {
|
|
449
439
|
return r;
|
450
440
|
}
|
451
441
|
function isHex(value) {
|
452
|
-
if (!value || value.length % 2)
|
453
|
-
|
454
|
-
if (!value.startsWith("0x")) {
|
455
|
-
value = "0x" + value;
|
456
|
-
}
|
457
|
-
return !isNaN(Number(value));
|
442
|
+
if (!value || value.length % 2) return false;
|
443
|
+
return !Number.isNaN(Number(value.startsWith("0x") ? value : `0x${value}`));
|
458
444
|
}
|
459
445
|
function byteSizeOf(hex) {
|
460
446
|
return hex.length / 2;
|
461
447
|
}
|
462
448
|
|
463
|
-
// src/types/
|
449
|
+
// src/types/enums.ts
|
464
450
|
var Network = /* @__PURE__ */ ((Network2) => {
|
465
451
|
Network2[Network2["Mainnet"] = 0] = "Mainnet";
|
466
452
|
Network2[Network2["Testnet"] = 16] = "Testnet";
|
@@ -470,6 +456,7 @@ var AddressType = /* @__PURE__ */ ((AddressType2) => {
|
|
470
456
|
AddressType2[AddressType2["P2PK"] = 1] = "P2PK";
|
471
457
|
AddressType2[AddressType2["P2SH"] = 2] = "P2SH";
|
472
458
|
AddressType2[AddressType2["P2S"] = 3] = "P2S";
|
459
|
+
AddressType2[AddressType2["ADH"] = 4] = "ADH";
|
473
460
|
return AddressType2;
|
474
461
|
})(AddressType || {});
|
475
462
|
var ergoTreeHeaderFlags = {
|
@@ -577,16 +564,10 @@ var FleetError = class extends Error {
|
|
577
564
|
}
|
578
565
|
};
|
579
566
|
var NotSupportedError = class extends FleetError {
|
580
|
-
constructor(message) {
|
581
|
-
super(message);
|
582
|
-
}
|
583
567
|
};
|
584
568
|
var BlockchainProviderError = class extends FleetError {
|
585
|
-
constructor(message, options) {
|
586
|
-
super(message, options);
|
587
|
-
}
|
588
569
|
};
|
589
570
|
|
590
571
|
export { AddressType, BlockchainProviderError, Collection, FleetError, Network, NotSupportedError, _0n, _10n, _127n, _128n, _1n, _63n, _7n, areEqual, areEqualBy, areRegistersDenselyPacked, assert, assertInstanceOf, assertTypeOf, at, byteSizeOf, chunk, clearUndefined, concatBytes, decimalize, depthOf, endsWith, ensureBigInt, ensureDefaults, ensureUTxOBigInt, ergoTreeHeaderFlags, first, hasDuplicates, hasDuplicatesBy, hasKey, isDefined, isEmpty, isFalsy, isHex, isTruthy, isUndefined, last, max, min, orderBy, percent, some, startsWith, sumBy, undecimalize, uniq, uniqBy, utxoDiff, utxoFilter, utxoSum };
|
591
|
-
//# sourceMappingURL=
|
572
|
+
//# sourceMappingURL=index.mjs.map
|
592
573
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/utils/assertions.ts","../src/utils/array.ts","../src/utils/bigInt.ts","../src/utils/utxo.ts","../src/utils/object.ts","../src/utils/bytes.ts","../src/types/common.ts","../src/models/collection.ts","../src/error.ts"],"names":["min","max","tokenId","Network","AddressType"],"mappings":";AAeO,SAAS,OAAO,WAAoB,OAAmD;AAC5F,MAAI;AAAW;AAEf,MAAI,MAAyB;AAC7B,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AACH,YAAM,IAAI,MAAM,KAAK;AACrB;AAAA,IACF,KAAK;AACH,YAAM,IAAI,MAAM,MAAM,CAAC;AACvB;AAAA,IACF;AACE,YAAM;AAAA,EACV;AAEA,QAAM;AACR;AAEO,SAAS,aAAgB,KAAQ,UAAyC;AAC/E,QAAM,OAAO,OAAO;AAEpB,MAAI,SAAS,UAAU;AACrB,UAAM,IAAI,MAAM,+BAA+B,QAAQ,WAAW,IAAI,IAAI;AAAA,EAC5E;AACF;AAEA,IAAM,WAAW,CAAC,UAAmB,OAAO,UAAU,SAAS,KAAK,KAAK;AACzE,SAAS,YAAY,OAAwB;AAC3C,MAAI,UAAU;AAAM,WAAO;AAC3B,QAAM,OAAO,OAAO;AAEpB,SAAO,SAAS,YAAY,SAAS,aAAa,SAAS,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI;AACnF;AAEO,SAAS,iBAAoB,KAAQ,UAAsC;AAChF,QAAM,YAAY,eAAe;AAEjC,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,4BAA4B,SAAS,IAAI,WAAW,YAAY,GAAG,CAAC,IAAI;AAAA,EAC1F;AACF;AAEO,SAAS,QAAW,QAA0D;AACnF,MAAI,CAAC;AAAQ,WAAO;AAEpB,SAAO,MAAM,QAAQ,MAAM,IAAI,OAAO,WAAW,IAAI,OAAO,KAAK,MAAM,EAAE,WAAW;AACtF;AAEO,SAAS,KAAQ,QAA2C;AACjE,SAAO,CAAC,QAAQ,MAAM;AACxB;AAEO,SAAS,SAAY,OAAoC;AAC9D,SAAO,CAAC,CAAC;AACX;AAEO,SAAS,QAAW,OAA+B;AACxD,SAAO,CAAC;A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,MAAM;AAAA,EACxB;AAAA,EAEO,OACL,YAMA,cACG;AACH,WAAO,KAAK,OAAO,OAAO,YAAY,YAAY;AAAA,EACpD;AACF;;;AClJO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,SAAkB,SAAwB;AACpD,UAAM,SAAS,OAAO;AAEtB,WAAO,eAAe,MAAM,WAAW,SAAS;AAChD,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,oBAAN,cAAgC,WAAW;AAAA,EAChD,YAAY,SAAkB;AAC5B,UAAM,OAAO;AAAA,EACf;AACF;AAEO,IAAM,0BAAN,cAAsC,WAAW;AAAA,EACtD,YAAY,SAAkB,SAAwB;AACpD,UAAM,SAAS,OAAO;AAAA,EACxB;AACF","sourcesContent":["export type AssertErrorMessageInput = string | Error | (() => string);\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype Constructable = Function;\n\ntype JSPrimitiveTypes =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\nexport function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition {\n if (condition) return;\n\n let err: Error | undefined = undefined;\n switch (typeof error) {\n case \"string\":\n err = new Error(error);\n break;\n case \"function\":\n err = new Error(error());\n break;\n default:\n err = error;\n }\n\n throw err;\n}\n\nexport function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj {\n const type = typeof obj;\n\n if (type !== expected) {\n throw new Error(`Expected an object of type '${expected}', got '${type}'.`);\n }\n}\n\nconst toString = (value: unknown) => Object.prototype.toString.call(value);\nfunction getTypeName(value: unknown): string {\n if (value === null) return \"null\";\n const type = typeof value;\n\n return type === \"object\" || type === \"function\" ? toString(value).slice(8, -1) : type;\n}\n\nexport function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj {\n const condition = obj instanceof expected;\n\n if (!condition) {\n throw new Error(`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`);\n }\n}\n\nexport function isEmpty<T>(target: T | null | undefined): target is undefined | null {\n if (!target) return true;\n\n return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;\n}\n\nexport function some<T>(target: T | null | undefined): target is T {\n return !isEmpty(target);\n}\n\nexport function isTruthy<T>(value?: T): value is NonNullable<T> {\n return !!value;\n}\n\nexport function isFalsy<T>(value?: T): value is undefined {\n return !value;\n}\n\nexport function isUndefined(v: unknown): v is undefined {\n return v === undefined || v === null || Number.isNaN(v);\n}\n\nexport function isDefined<T>(v: T | undefined): v is T {\n return !isUndefined(v);\n}\n\nexport function hasKey(o: unknown, key: PropertyKey): boolean {\n return Object.prototype.hasOwnProperty.call(o, key);\n}\n","import { SortingDirection, SortingSelector } from \"../types\";\nimport { assert, isEmpty } from \"./assertions\";\n\ntype ObjectSelector<T> = (item: T) => T[keyof T];\n\n/**\n * Returns the first element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function first(array: undefined): undefined;\nexport function first<T>(array: ArrayLike<T>): T;\nexport function first<T>(array: ArrayLike<T> | undefined): T | number | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return array[0];\n}\n\n/**\n * Returns the last element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function last(array: undefined): undefined;\nexport function last<T>(array: ArrayLike<T>): T;\nexport function last<T>(array: ArrayLike<T> | undefined): T | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return at(array, -1);\n}\n\n/**\n * Returns the element at the specified index. Negative indices are counted from the end of the array.\n * @param array\n * @param index\n */\nexport function at(array: undefined, index: number): undefined;\nexport function at<T>(array: ArrayLike<T>, index: number): T;\nexport function at<T>(array: ArrayLike<T> | undefined, index: number): T | undefined {\n const len = array?.length;\n if (!len) return undefined;\n\n if (index < 0) {\n index += len;\n }\n\n return array[index];\n}\n\n/**\n * Check for duplicate elements using the equality operator\n */\nexport function hasDuplicates<T>(array: T[]): boolean {\n return array.some((item, index) => {\n return array.indexOf(item) !== index;\n });\n}\n\n/**\n * Check for duplicate keys in complex elements\n */\nexport function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean {\n return array.some((item, index) => {\n return array.findIndex((x) => selector(x) === selector(item)) !== index;\n });\n}\n\n/**\n * Turns an array into chunks of the specified size\n * @param array\n * @param size\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const chunks = chunk(array, 2);\n * console.log(chunks);\n * // [[1, 2], [3, 4], [5]]\n * ```\n */\nexport function chunk<T>(array: T[], size: number): T[][] {\n if (array.length <= size) {\n return [array];\n }\n\n const chunks: T[][] = [];\n for (let i = 0; i < array.length; i += size) {\n chunks.push(array.slice(i, i + size));\n }\n\n return chunks;\n}\n\n/**\n * Sorts an array of objects by the specified property\n * @param array\n * @param iteratee\n * @param order\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const sorted = orderBy(array, (item) => item.age, \"desc\");\n * console.log(sorted);\n * // [{ name: \"Jane\", age: 30 }, { name: \"John\", age: 25 }]\n * ```\n */\nexport function orderBy<T>(\n array: T[],\n iteratee: SortingSelector<T>,\n order: SortingDirection = \"asc\"\n): T[] {\n return [...array].sort((a: T, b: T) => {\n if (iteratee(a) > iteratee(b)) {\n return order === \"asc\" ? 1 : -1;\n } else if (iteratee(a) < iteratee(b)) {\n return order === \"asc\" ? -1 : 1;\n } else {\n return 0;\n }\n });\n}\n\n/**\n * Checks if arrays are equal\n * @param array1\n * @param array2\n *\n * @example\n * ```\n * const array1 = [1, 2, 3];\n * const array2 = [1, 2, 3];\n * const array3 = [1, 2, 4];\n * const array4 = [1, 2, 3, 4];\n * areEqual(array1, array2); // true\n * areEqual(array1, array3); // false\n * areEqual(array1, array4); // false\n * ```\n */\nexport function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length != array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if arrays are equal by the specified property\n * @param array1\n * @param array2\n * @param selector\n *\n * @example\n * ```\n * const array1 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array2 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array3 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 31 }];\n *\n * areEqualBy(array1, array2, (item) => item.age); // true\n * areEqualBy(array1, array3, (item) => item.age); // false\n * ```\n */\nexport function areEqualBy<T>(\n array1: ArrayLike<T>,\n array2: ArrayLike<T>,\n selector: ObjectSelector<T>\n): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length != array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (selector(array1[i]) !== selector(array2[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array starts with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [1, 2];\n * const target2 = [1, 3];\n *\n * startsWith(array, target1); // true\n * startsWith(array, target2); // false\n * ```\n */\nexport function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n for (let i = 0; i < target.length; i++) {\n if (target[i] !== array[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array ends with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [4, 5];\n * const target2 = [3, 5];\n *\n * endsWith(array, target1); // true\n * endsWith(array, target2); // false\n * ```\n */\nexport function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n const offset = array.length - target.length;\n\n for (let i = target.length - 1; i >= 0; i--) {\n if (target[i] !== array[i + offset]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Makes an array unique by removing duplicate elements\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, 3, 4, 5, 5];\n * const unique = uniq(array);\n * console.log(unique);\n * // [1, 2, 3, 4, 5]\n * ```\n */\nexport function uniq<T>(array: Array<T>): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(new Set(array));\n}\n\n/**\n * Makes an array unique by removing duplicate elements using the specified property\n * @param array\n * @param selector\n * @param selection\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }, { name: \"John\", age: 30 }];\n * const unique = uniqBy(array, (item) => item.name);\n * console.log(unique);\n * // [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }]\n * ```\n */\nexport function uniqBy<T>(\n array: Array<T>,\n selector: ObjectSelector<T>,\n selection: \"keep-first\" | \"keep-last\" = \"keep-first\"\n): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(\n array\n .reduce((map, e) => {\n const key = selector(e);\n\n if (selection === \"keep-first\" && map.has(key)) {\n return map;\n }\n\n return map.set(key, e);\n }, new Map())\n .values()\n );\n}\n\n/**\n * Returns the depth of an array\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, [4, 5, [6, 7]]];\n * const depth = depthOf(array);\n * console.log(depth);\n * // 3\n */\nexport function depthOf(array: unknown | unknown[]): number {\n return Array.isArray(array) ? 1 + Math.max(0, ...array.map(depthOf)) : 0;\n}\n","import { Amount } from \"../types\";\nimport { first } from \"./array\";\nimport { isEmpty, isUndefined } from \"./assertions\";\n\ntype NumberLike = string | number | bigint | boolean;\n\nexport const _0n = BigInt(0);\nexport const _1n = BigInt(1);\nexport const _7n = BigInt(7);\nexport const _10n = BigInt(10);\nexport const _63n = BigInt(63);\nexport const _127n = BigInt(127);\nexport const _128n = BigInt(128);\n\n/**\n * Ensure that the given value is a bigint\n * @param number\n */\nexport function ensureBigInt(number: NumberLike): bigint {\n return typeof number === \"bigint\" ? number : BigInt(number);\n}\n\ntype ParsingOptions = {\n /**\n * Number of decimals.\n */\n decimals?: number;\n\n /**\n * Thousand mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Parse a decimal string into a bigint with options\n * @param decimalStr\n * @param options\n *\n * @example\n * undecimalize(\"129.8379183\", { decimals: 9 }) // 129837918300n\n * undecimalize(\"1\", { decimals: 2 }) // 100n\n * undecimalize(\"1\", 2) // 100n\n */\nexport function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint {\n if (!decimalStr) {\n return _0n;\n }\n\n options = typeof options == \"number\" ? { decimals: options } : options;\n if (isUndefined(options)) {\n options = {};\n }\n\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const fragments = decimalStr.split(options.decimalMark);\n if (fragments.length > 2) {\n throw new Error(\"Invalid numeric string.\");\n }\n\n let [integer, decimal] = fragments;\n integer = _removeLeadingZeros(integer);\n const negative = integer.startsWith(\"-\") ? \"-\" : \"\";\n\n if (!decimal) {\n decimal = \"0\".repeat(options.decimals);\n } else if (decimal.length < options.decimals) {\n decimal = decimal.padEnd(options.decimals, \"0\");\n }\n\n return BigInt(negative + _stripNonDigits(integer + decimal));\n}\n\n/**\n * Strip all non-digits from a string\n * @param value\n */\nfunction _stripNonDigits(value: string): string {\n return value.replace(/\\D/g, \"\");\n}\n\ntype FormattingOptions = {\n /**\n * Number of decimals.\n */\n decimals: number;\n\n /**\n * Thousand mark char.\n */\n thousandMark?: string;\n\n /**\n * Decimal mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Format a bigint into a decimal string with options\n * @param value\n * @param options\n *\n * @example\n * decimalize(129837918300n, { decimals: 9 }) // \"129.8379183\"\n * decimalize(100n, { decimals: 2 }) // \"1\"\n */\nexport function decimalize(value: Amount, options?: FormattingOptions | number): string {\n value = ensureBigInt(value);\n if (!options) {\n return value.toString();\n }\n\n options = typeof options == \"number\" ? { decimals: options } : options;\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const pow = _10n ** BigInt(options.decimals);\n const integer = value / pow;\n const decimal = value - integer * pow;\n\n return _buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);\n}\n\n/**\n * Format a bigint percentage into a decimal string with options\n * @param value\n * @param percentage\n * @param precision\n *\n * @example\n * ```\n * percent(3498n, 1n) // 34n(1%)\n * percent(3498n, 2n) // 69n(2%)\n * percent(3498n, 10n) // 349n(10%)\n * ```\n *\n */\nexport function percent(value: bigint, percentage: bigint, precision = 2n) {\n return (value * percentage) / 10n ** precision;\n}\n\nfunction _buildFormattedDecimal(\n integer: string,\n decimal: string,\n options: FormattingOptions\n): string {\n const integerPart = _addThousandMarks(integer, options.thousandMark);\n const decimalPart = _stripTrailingZeros(decimal.padStart(options.decimals, \"0\"));\n\n if (decimalPart) {\n return `${integerPart}${options.decimalMark}${decimalPart}`;\n } else {\n return integerPart;\n }\n}\n\nfunction _addThousandMarks(value: string, mark?: string): string {\n if (!mark) {\n return value;\n }\n\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, mark);\n}\n\nfunction _stripTrailingZeros(value: string): string {\n if (!value.endsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/\\.?0+$/, \"\");\n}\n\nfunction _removeLeadingZeros(value: string): string {\n if (!value.startsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/^0+\\.?/, \"\");\n}\n\n/**\n * Sum a collection of numbers by a given iteratee\n * @param collection\n * @param iteratee\n * @param condition\n *\n * @example\n * ```\n * const values = [\n * { key: 1, value: 100n },\n * { key: 2, value: 200n },\n * { key: 3, value: 300n },\n * { key: 4, value: 400n },\n * ];\n *\n * sumBy(values, x => x.value) // 1000n\n * sumBy(values, x => x.value, x => x.key < 0) // 0n\n * sumBy(values, x => x.value, x => x.key % 2 === 0) // 600n\n */\nexport function sumBy<T>(\n collection: readonly T[],\n iteratee: (value: T) => bigint,\n condition?: (value: T) => boolean\n): bigint {\n let acc = _0n;\n if (isEmpty(collection)) {\n return acc;\n }\n\n for (const item of collection) {\n if (isUndefined(condition) || condition(item)) {\n acc += iteratee(item);\n }\n }\n\n return acc;\n}\n\n/**\n * Get the minimum value from a collection of numbers\n * @param numbers\n */\nexport function min<T extends bigint | number>(...numbers: T[]): T {\n let min = first(numbers);\n\n for (const num of numbers) {\n if (num < min) {\n min = num;\n }\n }\n\n return min;\n}\n\n/**\n * Get the maximum value from a collection of numbers\n * @param numbers\n */\nexport function max<T extends bigint | number>(...numbers: T[]): T {\n let max = first(numbers);\n\n for (const num of numbers) {\n if (num > max) {\n max = num;\n }\n }\n\n return max;\n}\n","import { Amount, Box, BoxCandidate, NonMandatoryRegisters, TokenAmount, TokenId } from \"../types\";\nimport { isDefined, isEmpty, isUndefined } from \"./assertions\";\nimport { ensureBigInt } from \"./bigInt\";\nimport { _0n } from \"./bigInt\";\n\nconst NANOERGS_TOKEN_ID = \"nanoErgs\";\n\n/**\n * Calculates the sum of all nanoErgs and tokens in the given boxes.\n * @param boxes\n *\n * @example\n * ```\n * const boxes = [\n * { value: \"10\", assets: [{ tokenId: \"test\", amount: \"20\" }] },\n * { value: 20n, assets: [{ tokenId: \"test\", amount: 30n }] }\n * ];\n *\n * const sum = utxoSum(boxes);\n * console.log(sum);\n * // { nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }\n * ```\n */\nexport function utxoSum(boxes: MinimalBoxAmountsArray): BoxSummary;\nexport function utxoSum(boxes: MinimalBoxAmountsArray, tokenId: TokenId): bigint;\nexport function utxoSum(boxes: MinimalBoxAmountsArray, tokenId?: TokenId): BoxSummary | bigint {\n const balances: { [tokenId: string]: bigint } = {};\n\n for (const box of boxes) {\n if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {\n balances[NANOERGS_TOKEN_ID] = (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);\n }\n\n if (tokenId !== NANOERGS_TOKEN_ID) {\n for (const token of box.assets) {\n if (isDefined(tokenId) && tokenId !== token.tokenId) {\n continue;\n }\n\n balances[token.tokenId] = (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);\n }\n }\n }\n\n if (isDefined(tokenId)) {\n return balances[tokenId] || _0n;\n }\n\n return {\n nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,\n tokens: Object.keys(balances)\n .filter((x) => x !== NANOERGS_TOKEN_ID)\n .map((tokenId) => ({ tokenId, amount: balances[tokenId] }))\n };\n}\n\n/**\n * Calculates the difference between two utxos or utxo sets.\n * @param minuend\n * @param subtrahend\n *\n * @example\n * ```\n * const minuend = [{ nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }];\n * const subtrahend = [{ nanoErgs: 10n, tokens: [{ tokenId: \"test\", amount: 20n }] }];\n * const diff = utxoDiff(minuend, subtrahend);\n * console.log(diff);\n * // { nanoErgs: 20n, tokens: [{ tokenId: \"test\", amount: 30n }] }\n * ```\n */\nexport function utxoDiff(\n minuend: BoxSummary | Box<Amount>[],\n subtrahend: BoxSummary | Box<Amount>[]\n): BoxSummary {\n if (Array.isArray(minuend)) {\n minuend = utxoSum(minuend);\n }\n\n if (Array.isArray(subtrahend)) {\n subtrahend = utxoSum(subtrahend);\n }\n\n const tokens: TokenAmount<bigint>[] = [];\n const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;\n\n for (const token of minuend.tokens) {\n const balance =\n token.amount - (subtrahend.tokens.find((t) => t.tokenId === token.tokenId)?.amount || _0n);\n\n if (balance !== _0n) {\n tokens.push({ tokenId: token.tokenId, amount: balance });\n }\n }\n\n return { nanoErgs, tokens };\n}\n\nconst MIN_NON_MANDATORY_REGISTER_INDEX = 4;\nconst MAX_NON_MANDATORY_REGISTER_INDEX = 9;\n\n/**\n * Checks if the given registers are densely packed.\n * @param registers\n *\n * @example\n * ```\n * const registers = {\n * R4: \"deadbeef\",\n * R6: \"cafe\",\n * };\n * const result = areRegistersDenselyPacked(registers);\n * console.log(result);\n * // false\n */\nexport function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {\n let lastIndex = 0;\n for (let i = MIN_NON_MANDATORY_REGISTER_INDEX; i <= MAX_NON_MANDATORY_REGISTER_INDEX; i++) {\n const key = `R${i}` as keyof NonMandatoryRegisters;\n if (registers[key]) {\n if (i === MIN_NON_MANDATORY_REGISTER_INDEX) {\n lastIndex = i;\n continue;\n }\n\n if (i - lastIndex > 1) {\n return false;\n }\n\n lastIndex = i;\n }\n }\n\n return true;\n}\n\n/**\n * Filters the given utxos by the given filter parameters.\n * @param utxos\n * @param filterParams\n */\nexport function utxoFilter<T extends Amount>(utxos: Box<T>[], filterParams: UTxOFilterParams<T>) {\n if (isEmpty(filterParams) || isEmpty(utxos)) {\n return utxos;\n }\n\n const { by, max } = filterParams;\n let filtered = utxos;\n\n if (by) {\n filtered = utxos.filter(by);\n if (isEmpty(filtered)) {\n return filtered;\n }\n }\n\n if (!max) {\n return filtered;\n }\n\n if (isDefined(max.aggregatedDistinctTokens)) {\n const tokenIds = _getDistinctTokenIds(filtered, max.aggregatedDistinctTokens);\n filtered = filtered.filter(\n (utxo) => isEmpty(utxo.assets) || utxo.assets.every((token) => tokenIds.has(token.tokenId))\n );\n }\n\n if (isDefined(max.count) && filtered.length > max.count) {\n filtered = filtered.slice(0, max.count);\n }\n\n return filtered;\n}\n\nfunction _getDistinctTokenIds(utxos: Box[], max: number): Set<string> {\n const tokenIds = new Set<string>();\n\n for (let i = 0; i < utxos.length && tokenIds.size < max; i++) {\n if (isEmpty(utxos[i].assets) || utxos[i].assets.length > max) {\n continue;\n }\n\n for (const token of utxos[i].assets) {\n tokenIds.add(token.tokenId);\n }\n }\n\n return tokenIds;\n}\n\n/**\n * Parameters for filtering unspent transaction outputs (UTxOs).\n */\nexport type UTxOFilterParams<T extends Amount> = {\n /**\n * A function that returns a boolean indicating whether a given UTxO should be included in the filtered results.\n */\n by?: (utxo: Box<T>) => boolean;\n /**\n * An object specifying the maximum number of UTxOs and distinct tokens to include in the filtered results.\n */\n max?: {\n /**\n * The maximum number of UTxOs to include in the filtered results.\n */\n count?: number;\n /**\n * The maximum number of distinct tokens to include in the filtered results.\n */\n aggregatedDistinctTokens?: number;\n };\n};\n\nexport type BoxSummary = {\n nanoErgs: bigint;\n tokens: TokenAmount<bigint>[];\n};\n\nexport type MinimalBoxAmountsArray = readonly {\n value: Amount;\n assets: TokenAmount<Amount>[];\n}[];\n\n/**\n * Ensures that the value and asset amounts of a given box are represented as BigInts.\n * @returns A new box object with BigInt representation for the value and asset amounts.\n */\nexport function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;\nexport function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;\nexport function ensureUTxOBigInt(\n box: Box<Amount> | BoxCandidate<Amount>\n): BoxCandidate<bigint> | Box<bigint> {\n return {\n ...box,\n value: ensureBigInt(box.value),\n assets: box.assets.map((token) => ({\n tokenId: token.tokenId,\n amount: ensureBigInt(token.amount)\n }))\n };\n}\n","import { isEmpty, isUndefined } from \"./assertions\";\n\n/**\n * Remove undefined values from an object\n * @param value\n *\n * @example\n * ```\n * const obj = { a: 1, b: undefined };\n * const result = clearUndefined(obj);\n * console.log(result); // { a: 1 }\n * ```\n */\nexport function clearUndefined(value: Record<string, unknown>) {\n const result: Record<string, unknown> = {};\n for (const key in value) {\n const val = value[key];\n if (!isUndefined(val)) {\n result[key] = val;\n }\n }\n\n return result;\n}\n\nexport type EnsureDefaultsOptions = { keepUndefinedKeys: boolean };\n\n/**\n * Ensure that the options object has all the default values\n * @param partial\n * @param defaults\n *\n * @example\n * ```\n * const options = { a: 1 };\n * const defaults = { a: 2, b: 3 };\n * const result = ensureDefaults(options, defaults);\n * console.log(result); // { a: 1, b: 3 }\n * ```\n */\nexport function ensureDefaults<T extends object, R extends object>(\n partial: T | undefined,\n defaults: R,\n options?: EnsureDefaultsOptions\n): R & T {\n if (isEmpty(partial)) return defaults as R & T;\n if (options?.keepUndefinedKeys) return { ...defaults, ...partial };\n\n const merged = { ...defaults, ...partial } as Record<string, unknown>;\n for (const key in merged) {\n merged[key] = partial[key as keyof T] ?? defaults[key as keyof R];\n }\n\n return merged as R & T;\n}\n","import { assertInstanceOf } from \".\";\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));\n\n let pad = 0;\n for (const bytes of arrays) {\n assertInstanceOf(bytes, Uint8Array);\n\n r.set(bytes, pad);\n pad += bytes.length;\n }\n\n return r;\n}\n\nexport function isHex(value?: string) {\n if (!value || value.length % 2) return false;\n\n if (!value.startsWith(\"0x\")) {\n value = \"0x\" + value;\n }\n\n return !isNaN(Number(value));\n}\n\n/**\n * Get hex string size in bytes\n * @param hex\n * @returns the byte size if the hex string\n */\nexport function byteSizeOf(hex: string): number {\n return hex.length / 2;\n}\n","export type HexString = string;\nexport type ErgoTreeHex = string;\nexport type Base58String = string;\nexport type Amount = string | bigint;\n\nexport type OneOrMore<T> = T | T[];\n\nexport type SortingSelector<T> = (item: T) => string | number | bigint;\nexport type SortingDirection = \"asc\" | \"desc\";\n\nexport type FilterPredicate<T> = (item: T) => boolean;\n\nexport type BuildOutputType = \"default\" | \"EIP-12\";\n\nexport enum Network {\n Mainnet = 0x00,\n Testnet = 0x10\n}\n\nexport enum AddressType {\n P2PK = 1,\n P2SH = 2,\n P2S = 3\n}\n\nexport const ergoTreeHeaderFlags = {\n sizeInclusion: 0x08,\n constantSegregation: 0x10\n} as const;\n\nexport type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];\n","import { OneOrMore } from \"../types\";\nimport { isDefined } from \"../utils\";\n\nexport type CollectionAddOptions = { index?: number };\n\n/**\n * Collection abstract model\n *\n * @example\n * Define a new collection class with internal type `number` and external type `string`\n * ```\n * class TestCollection extends Collection<number, string> {\n * protected _map(item: string | number): number {\n * return Number(item);\n * }\n * // Some other methods\n * }\n * ```\n *\n */\nexport abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {\n protected readonly _items: InternalType[];\n\n constructor() {\n this._items = [];\n }\n\n protected _isIndexOutOfBounds(index: number): boolean {\n return index < 0 || index >= this._items.length;\n }\n\n [Symbol.iterator](): Iterator<InternalType> {\n let counter = 0;\n\n return {\n next: () => {\n return {\n done: counter >= this.length,\n value: this._items[counter++]\n };\n }\n };\n }\n\n /**\n * Number of items in the collection\n */\n public get length(): number {\n return this._items.length;\n }\n\n /**\n * True if the collection is empty\n */\n public get isEmpty(): boolean {\n return this.length === 0;\n }\n\n /**\n * Get item at index\n * @param index\n * @throws RangeError if index is out of bounds\n */\n public at(index: number): InternalType {\n if (this._isIndexOutOfBounds(index)) {\n throw new RangeError(`Index '${index}' is out of range.`);\n }\n\n return this._items[index];\n }\n\n /**\n * Add item to the collection\n * @param items\n * @param options\n * @returns The new length of the collection\n */\n public add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n return this._addOneOrMore(items, options);\n }\n\n abstract remove(item: unknown): number;\n\n /**\n * Map external type to internal type\n * @param item\n * @protected\n */\n protected abstract _map(item: ExternalType | InternalType): InternalType;\n\n protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number {\n if (isDefined(options) && isDefined(options.index)) {\n if (options.index === this.length) {\n this._items.push(this._map(item));\n\n return this.length;\n }\n\n if (this._isIndexOutOfBounds(options.index)) {\n throw new RangeError(`Index '${options.index}' is out of range.`);\n }\n\n this._items.splice(options.index, 0, this._map(item));\n\n return this.length;\n }\n\n this._items.push(this._map(item));\n\n return this._items.length;\n }\n\n protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n if (Array.isArray(items)) {\n if (isDefined(options) && isDefined(options.index)) {\n items = items.reverse();\n }\n\n for (const item of items) {\n this._addOne(item, options);\n }\n } else {\n this._addOne(items, options);\n }\n\n return this.length;\n }\n\n /**\n * Get the collection as an array\n */\n public toArray(): InternalType[] {\n return [...this._items];\n }\n\n public reduce<U>(\n callbackFn: (\n accumulator: U,\n currentValue: InternalType,\n currentIndex: number,\n array: InternalType[]\n ) => U,\n initialValue: U\n ): U {\n return this._items.reduce(callbackFn, initialValue);\n }\n}\n","export class FleetError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = new.target.name;\n }\n}\n\nexport class NotSupportedError extends FleetError {\n constructor(message?: string) {\n super(message);\n }\n}\n\nexport class BlockchainProviderError extends FleetError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n"]}
|
1
|
+
{"version":3,"sources":["../src/utils/assertions.ts","../src/utils/array.ts","../src/utils/bigInt.ts","../src/utils/utxo.ts","../src/utils/object.ts","../src/utils/bytes.ts","../src/types/enums.ts","../src/models/collection.ts","../src/error.ts"],"names":["min","max","tokenId","Network","AddressType"],"mappings":";AAeO,SAAS,MAAA,CAAO,WAAoB,KAAwC,EAAA;AACjF,EAAA,IAAI,SAAW,EAAA,OAAA;AAEf,EAAA,IAAI,GAAyB,GAAA,KAAA,CAAA,CAAA;AAC7B,EAAA,QAAQ,OAAO,KAAO;AAAA,IACpB,KAAK,QAAA;AACH,MAAM,GAAA,GAAA,IAAI,MAAM,KAAK,CAAA,CAAA;AACrB,MAAA,MAAA;AAAA,IACF,KAAK,UAAA;AACH,MAAM,GAAA,GAAA,IAAI,KAAM,CAAA,KAAA,EAAO,CAAA,CAAA;AACvB,MAAA,MAAA;AAAA,IACF;AACE,MAAM,GAAA,GAAA,KAAA,CAAA;AAAA,GACV;AAEA,EAAM,MAAA,GAAA,CAAA;AACR,CAAA;AAEO,SAAS,YAAA,CAAgB,KAAQ,QAAoC,EAAA;AAC1E,EAAA,MAAM,OAAO,OAAO,GAAA,CAAA;AAEpB,EAAA,IAAI,SAAS,QAAU,EAAA;AACrB,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,4BAAA,EAA+B,QAAQ,CAAA,QAAA,EAAW,IAAI,CAA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AK,CAAA,MAAA,CAAA;AAAA,GACd;AAAA;AAAA;AAAA;AAAA,EAKO,OAA0B,GAAA;AAC/B,IAAO,OAAA,CAAC,GAAG,IAAA,CAAK,MAAM,CAAA,CAAA;AAAA,GACxB;AAAA,EAEO,MAAA,CACL,YAMA,YACG,EAAA;AACH,IAAA,OAAO,IAAK,CAAA,MAAA,CAAO,MAAO,CAAA,UAAA,EAAY,YAAY,CAAA,CAAA;AAAA,GACpD;AACF,EAAA;;;AC1Ja,IAAA,UAAA,GAAN,cAAyB,KAAM,CAAA;AAAA,EACpC,WAAA,CAAY,SAAkB,OAAwB,EAAA;AACpD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAEtB,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA,CAAA;AAChD,IAAA,IAAA,CAAK,OAAO,GAAW,CAAA,MAAA,CAAA,IAAA,CAAA;AAAA,GACzB;AACF,EAAA;AAEa,IAAA,iBAAA,GAAN,cAAgC,UAAW,CAAA;AAAC,EAAA;AAEtC,IAAA,uBAAA,GAAN,cAAsC,UAAW,CAAA;AAAC","file":"index.mjs","sourcesContent":["export type ErrorMessage = string | Error | (() => string);\n\n// biome-ignore lint/complexity/noBannedTypes: <explanation>\ntype Constructable = Function;\n\ntype JSPrimitive =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"undefined\"\n | \"object\"\n | \"function\";\n\nexport function assert(condition: boolean, error: ErrorMessage): asserts condition {\n if (condition) return;\n\n let err: Error | undefined = undefined;\n switch (typeof error) {\n case \"string\":\n err = new Error(error);\n break;\n case \"function\":\n err = new Error(error());\n break;\n default:\n err = error;\n }\n\n throw err;\n}\n\nexport function assertTypeOf<T>(obj: T, expected: JSPrimitive): asserts obj {\n const type = typeof obj;\n\n if (type !== expected) {\n throw new Error(`Expected an object of type '${expected}', got '${type}'.`);\n }\n}\n\nfunction getTypeName(value: unknown): string {\n if (value === null) return \"null\";\n const type = typeof value;\n\n return type === \"object\" || type === \"function\"\n ? Object.prototype.toString.call(value).slice(8, -1)\n : type;\n}\n\nexport function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj {\n const condition = obj instanceof expected;\n\n if (!condition) {\n throw new Error(\n `Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`\n );\n }\n}\n\nexport function isEmpty<T>(target: T | null | undefined): target is undefined | null {\n if (!target) return true;\n\n return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;\n}\n\nexport function some<T>(target: T | null | undefined): target is T {\n return !isEmpty(target);\n}\n\nexport function isTruthy<T>(value?: T): value is NonNullable<T> {\n return !!value;\n}\n\nexport function isFalsy<T>(value?: T): value is undefined {\n return !value;\n}\n\nexport function isUndefined(v: unknown): v is undefined {\n return v === undefined || v === null || Number.isNaN(v);\n}\n\nexport function isDefined<T>(v: T | undefined): v is T {\n return !isUndefined(v);\n}\n\nexport function hasKey(o: unknown, key: PropertyKey): boolean {\n return Object.prototype.hasOwnProperty.call(o, key);\n}\n","import type { SortingDirection, SortingSelector } from \"../types\";\nimport { assert, isEmpty } from \"./assertions\";\n\ntype ObjectSelector<T> = (item: T) => T[keyof T];\n\n/**\n * Returns the first element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function first(array: undefined): undefined;\nexport function first<T>(array: ArrayLike<T>): T;\nexport function first<T>(array: ArrayLike<T> | undefined): T | number | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return array[0];\n}\n\n/**\n * Returns the last element of an array.\n * @param array\n * @throws an error if the array is empty.\n */\nexport function last(array: undefined): undefined;\nexport function last<T>(array: ArrayLike<T>): T;\nexport function last<T>(array: ArrayLike<T> | undefined): T | undefined {\n if (!array) return undefined;\n assert(array.length > 0, \"Empty array.\");\n\n return at(array, -1);\n}\n\n/**\n * Returns the element at the specified index. Negative indices are counted from the end of the array.\n * @param array\n * @param index\n */\nexport function at(array: undefined, index: number): undefined;\nexport function at<T>(array: ArrayLike<T>, index: number): T;\nexport function at<T>(array: ArrayLike<T> | undefined, index: number): T | undefined {\n const len = array?.length;\n if (!len) return undefined;\n\n if (index < 0) {\n index += len;\n }\n\n return array[index];\n}\n\n/**\n * Check for duplicate elements using the equality operator\n */\nexport function hasDuplicates<T>(array: T[]): boolean {\n return array.some((item, index) => {\n return array.indexOf(item) !== index;\n });\n}\n\n/**\n * Check for duplicate keys in complex elements\n */\nexport function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean {\n return array.some((item, index) => {\n return array.findIndex((x) => selector(x) === selector(item)) !== index;\n });\n}\n\n/**\n * Turns an array into chunks of the specified size\n * @param array\n * @param size\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const chunks = chunk(array, 2);\n * console.log(chunks);\n * // [[1, 2], [3, 4], [5]]\n * ```\n */\nexport function chunk<T>(array: T[], size: number): T[][] {\n if (array.length <= size) {\n return [array];\n }\n\n const chunks: T[][] = [];\n for (let i = 0; i < array.length; i += size) {\n chunks.push(array.slice(i, i + size));\n }\n\n return chunks;\n}\n\n/**\n * Sorts an array of objects by the specified property\n * @param array\n * @param iteratee\n * @param order\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const sorted = orderBy(array, (item) => item.age, \"desc\");\n * console.log(sorted);\n * // [{ name: \"Jane\", age: 30 }, { name: \"John\", age: 25 }]\n * ```\n */\nexport function orderBy<T>(\n array: T[],\n iteratee: SortingSelector<T>,\n order: SortingDirection = \"asc\"\n): T[] {\n return [...array].sort((a: T, b: T) => {\n if (iteratee(a) > iteratee(b)) return order === \"asc\" ? 1 : -1;\n if (iteratee(a) < iteratee(b)) return order === \"asc\" ? -1 : 1;\n return 0;\n });\n}\n\n/**\n * Checks if arrays are equal\n * @param array1\n * @param array2\n *\n * @example\n * ```\n * const array1 = [1, 2, 3];\n * const array2 = [1, 2, 3];\n * const array3 = [1, 2, 4];\n * const array4 = [1, 2, 3, 4];\n * areEqual(array1, array2); // true\n * areEqual(array1, array3); // false\n * areEqual(array1, array4); // false\n * ```\n */\nexport function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length !== array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if arrays are equal by the specified property\n * @param array1\n * @param array2\n * @param selector\n *\n * @example\n * ```\n * const array1 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array2 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }];\n * const array3 = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 31 }];\n *\n * areEqualBy(array1, array2, (item) => item.age); // true\n * areEqualBy(array1, array3, (item) => item.age); // false\n * ```\n */\nexport function areEqualBy<T>(\n array1: ArrayLike<T>,\n array2: ArrayLike<T>,\n selector: ObjectSelector<T>\n): boolean {\n if (array1 === array2) {\n return true;\n }\n\n if (array1.length !== array2.length) {\n return false;\n }\n\n for (let i = 0; i < array1.length; i++) {\n if (selector(array1[i]) !== selector(array2[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array starts with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [1, 2];\n * const target2 = [1, 3];\n *\n * startsWith(array, target1); // true\n * startsWith(array, target2); // false\n * ```\n */\nexport function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n for (let i = 0; i < target.length; i++) {\n if (target[i] !== array[i]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Checks if the array ends with the specified target\n * @param array\n * @param target\n *\n * @example\n * ```\n * const array = [1, 2, 3, 4, 5];\n * const target1 = [4, 5];\n * const target2 = [3, 5];\n *\n * endsWith(array, target1); // true\n * endsWith(array, target2); // false\n * ```\n */\nexport function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {\n if (array === target) {\n return true;\n }\n\n if (target.length > array.length) {\n return false;\n }\n\n const offset = array.length - target.length;\n\n for (let i = target.length - 1; i >= 0; i--) {\n if (target[i] !== array[i + offset]) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Makes an array unique by removing duplicate elements\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, 3, 4, 5, 5];\n * const unique = uniq(array);\n * console.log(unique);\n * // [1, 2, 3, 4, 5]\n * ```\n */\nexport function uniq<T>(array: Array<T>): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(new Set(array));\n}\n\n/**\n * Makes an array unique by removing duplicate elements using the specified property\n * @param array\n * @param selector\n * @param selection\n *\n * @example\n * ```\n * const array = [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }, { name: \"John\", age: 30 }];\n * const unique = uniqBy(array, (item) => item.name);\n * console.log(unique);\n * // [{ name: \"John\", age: 25 }, { name: \"Jane\", age: 30 }]\n * ```\n */\nexport function uniqBy<T>(\n array: Array<T>,\n selector: ObjectSelector<T>,\n selection: \"keep-first\" | \"keep-last\" = \"keep-first\"\n): Array<T> {\n if (isEmpty(array)) {\n return array;\n }\n\n return Array.from(\n array\n .reduce((map, e) => {\n const key = selector(e);\n\n if (selection === \"keep-first\" && map.has(key)) {\n return map;\n }\n\n return map.set(key, e);\n }, new Map())\n .values()\n );\n}\n\n/**\n * Returns the depth of an array\n * @param array\n *\n * @example\n * ```\n * const array = [1, 2, 3, [4, 5, [6, 7]]];\n * const depth = depthOf(array);\n * console.log(depth);\n * // 3\n */\nexport function depthOf(array: unknown | unknown[]): number {\n return Array.isArray(array) ? 1 + Math.max(0, ...array.map(depthOf)) : 0;\n}\n","import type { Amount } from \"../types\";\nimport { first } from \"./array\";\nimport { isEmpty, isUndefined } from \"./assertions\";\n\ntype NumberLike = string | number | bigint | boolean;\n\nexport const _0n = BigInt(0);\nexport const _1n = BigInt(1);\nexport const _7n = BigInt(7);\nexport const _10n = BigInt(10);\nexport const _63n = BigInt(63);\nexport const _127n = BigInt(127);\nexport const _128n = BigInt(128);\n\n/**\n * Ensure that the given value is a bigint\n * @param number\n */\nexport function ensureBigInt(number: NumberLike): bigint {\n return typeof number === \"bigint\" ? number : BigInt(number);\n}\n\ntype ParsingOptions = {\n /**\n * Number of decimals.\n */\n decimals?: number;\n\n /**\n * Thousand mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Parse a decimal string into a bigint with options\n * @param input\n * @param options\n *\n * @example\n * undecimalize(\"129.8379183\", { decimals: 9 }) // 129837918300n\n * undecimalize(\"1\", { decimals: 2 }) // 100n\n * undecimalize(\"1\", 2) // 100n\n */\nexport function undecimalize(input: string, options?: ParsingOptions | number): bigint {\n if (!input) return _0n;\n\n options = typeof options === \"number\" ? { decimals: options } : options;\n if (isUndefined(options)) {\n options = {};\n }\n\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const fragments = input.split(options.decimalMark);\n if (fragments.length > 2) {\n throw new Error(\"Invalid numeric string.\");\n }\n\n let [integer, decimal] = fragments;\n integer = removeLeadingZeros(integer);\n const negative = integer.startsWith(\"-\") ? \"-\" : \"\";\n\n if (!decimal) {\n decimal = \"0\".repeat(options.decimals);\n } else if (decimal.length < options.decimals) {\n decimal = decimal.padEnd(options.decimals, \"0\");\n }\n\n return BigInt(negative + _stripNonDigits(integer + decimal));\n}\n\n/**\n * Strip all non-digits from a string\n * @param value\n */\nfunction _stripNonDigits(value: string): string {\n return value.replace(/\\D/g, \"\");\n}\n\ntype FormattingOptions = {\n /**\n * Number of decimals.\n */\n decimals: number;\n\n /**\n * Thousand mark char.\n */\n thousandMark?: string;\n\n /**\n * Decimal mark char.\n * Default: `.`\n */\n decimalMark?: string;\n};\n\n/**\n * Format a bigint into a decimal string with options\n * @param value\n * @param options\n *\n * @example\n * decimalize(129837918300n, { decimals: 9 }) // \"129.8379183\"\n * decimalize(100n, { decimals: 2 }) // \"1\"\n */\nexport function decimalize(value: Amount, options?: FormattingOptions | number): string {\n value = ensureBigInt(value);\n if (!options) {\n return value.toString();\n }\n\n options = typeof options === \"number\" ? { decimals: options } : options;\n options.decimals = options.decimals || 0;\n options.decimalMark = options.decimalMark || \".\";\n\n const pow = _10n ** BigInt(options.decimals);\n const integer = value / pow;\n const decimal = value - integer * pow;\n\n return buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);\n}\n\n/**\n * Format a bigint percentage into a decimal string with options\n * @param value\n * @param percentage\n * @param precision\n *\n * @example\n * ```\n * percent(3498n, 1n) // 34n(1%)\n * percent(3498n, 2n) // 69n(2%)\n * percent(3498n, 10n) // 349n(10%)\n * ```\n *\n */\nexport function percent(value: bigint, percentage: bigint, precision = 2n) {\n return (value * percentage) / 10n ** precision;\n}\n\nfunction buildFormattedDecimal(\n integer: string,\n decimal: string,\n options: FormattingOptions\n): string {\n const int = addThousandMarks(integer, options.thousandMark);\n const dec = stripTrailingZeros(decimal.padStart(options.decimals, \"0\"));\n if (dec) return `${int}${options.decimalMark}${dec}`;\n return int;\n}\n\nfunction addThousandMarks(value: string, mark?: string): string {\n if (!mark) {\n return value;\n }\n\n return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, mark);\n}\n\nfunction stripTrailingZeros(value: string): string {\n if (!value.endsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/\\.?0+$/, \"\");\n}\n\nfunction removeLeadingZeros(value: string): string {\n if (!value.startsWith(\"0\")) {\n return value;\n }\n\n return value.replace(/^0+\\.?/, \"\");\n}\n\n/**\n * Sum a collection of numbers by a given iteratee\n * @param collection\n * @param iteratee\n * @param condition\n *\n * @example\n * ```\n * const values = [\n * { key: 1, value: 100n },\n * { key: 2, value: 200n },\n * { key: 3, value: 300n },\n * { key: 4, value: 400n },\n * ];\n *\n * sumBy(values, x => x.value) // 1000n\n * sumBy(values, x => x.value, x => x.key < 0) // 0n\n * sumBy(values, x => x.value, x => x.key % 2 === 0) // 600n\n */\nexport function sumBy<T>(\n collection: readonly T[],\n iteratee: (value: T) => bigint,\n condition?: (value: T) => boolean\n): bigint {\n let acc = _0n;\n if (isEmpty(collection)) {\n return acc;\n }\n\n for (const item of collection) {\n if (isUndefined(condition) || condition(item)) {\n acc += iteratee(item);\n }\n }\n\n return acc;\n}\n\n/**\n * Get the minimum value from a collection of numbers\n * @param numbers\n */\nexport function min<T extends bigint | number>(...numbers: T[]): T {\n let min = first(numbers);\n\n for (const num of numbers) {\n if (num < min) {\n min = num;\n }\n }\n\n return min;\n}\n\n/**\n * Get the maximum value from a collection of numbers\n * @param numbers\n */\nexport function max<T extends bigint | number>(...numbers: T[]): T {\n let max = first(numbers);\n\n for (const num of numbers) {\n if (num > max) {\n max = num;\n }\n }\n\n return max;\n}\n","import type {\n Amount,\n Box,\n BoxCandidate,\n NonMandatoryRegisters,\n TokenAmount,\n TokenId\n} from \"../types\";\nimport { isDefined, isEmpty, isUndefined } from \"./assertions\";\nimport { ensureBigInt } from \"./bigInt\";\nimport { _0n } from \"./bigInt\";\n\nconst NANOERGS_TOKEN_ID = \"nanoErgs\";\n\n/**\n * Calculates the sum of all nanoErgs and tokens in the given boxes.\n * @param boxes\n *\n * @example\n * ```\n * const boxes = [\n * { value: \"10\", assets: [{ tokenId: \"test\", amount: \"20\" }] },\n * { value: 20n, assets: [{ tokenId: \"test\", amount: 30n }] }\n * ];\n *\n * const sum = utxoSum(boxes);\n * console.log(sum);\n * // { nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }\n * ```\n */\nexport function utxoSum(boxes: readonly BoxAmounts[]): BoxSummary;\nexport function utxoSum(boxes: readonly BoxAmounts[], tokenId: TokenId): bigint;\nexport function utxoSum(boxes: readonly BoxAmounts[], tokenId?: TokenId) {\n const balances: { [tokenId: string]: bigint } = {};\n\n for (const box of boxes) {\n if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {\n balances[NANOERGS_TOKEN_ID] =\n (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);\n }\n\n if (tokenId !== NANOERGS_TOKEN_ID) {\n for (const token of box.assets) {\n if (isDefined(tokenId) && tokenId !== token.tokenId) {\n continue;\n }\n\n balances[token.tokenId] =\n (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);\n }\n }\n }\n\n if (isDefined(tokenId)) {\n return balances[tokenId] || _0n;\n }\n\n return {\n nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,\n tokens: Object.keys(balances)\n .filter((x) => x !== NANOERGS_TOKEN_ID)\n .map((tokenId) => ({ tokenId, amount: balances[tokenId] }))\n };\n}\n\n/**\n * Calculates the difference between two utxos or utxo sets.\n * @param minuend\n * @param subtrahend\n *\n * @example\n * ```\n * const minuend = [{ nanoErgs: 30n, tokens: [{ tokenId: \"test\", amount: 50n }] }];\n * const subtrahend = [{ nanoErgs: 10n, tokens: [{ tokenId: \"test\", amount: 20n }] }];\n * const diff = utxoDiff(minuend, subtrahend);\n * console.log(diff);\n * // { nanoErgs: 20n, tokens: [{ tokenId: \"test\", amount: 30n }] }\n * ```\n */\nexport function utxoDiff(\n minuend: BoxSummary | Box<Amount>[],\n subtrahend: BoxSummary | Box<Amount>[],\n ignoreSubtrahendLeftoverTokens = false\n): BoxSummary {\n if (Array.isArray(minuend)) minuend = utxoSum(minuend);\n if (Array.isArray(subtrahend)) subtrahend = utxoSum(subtrahend);\n\n const tokens: TokenAmount<bigint>[] = [];\n const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;\n const subtrahendTokens = new Map(subtrahend.tokens.map((t) => [t.tokenId, t.amount]));\n\n for (const token of minuend.tokens) {\n const subtrahendAmount = subtrahendTokens.get(token.tokenId) || _0n;\n const balance = token.amount - (subtrahendAmount || _0n);\n\n if (balance !== _0n) {\n tokens.push({ tokenId: token.tokenId, amount: balance });\n }\n\n if (subtrahendAmount > _0n) {\n subtrahendTokens.delete(token.tokenId);\n }\n }\n\n if (!ignoreSubtrahendLeftoverTokens && subtrahendTokens.size > 0) {\n for (const [tokenId, amount] of subtrahendTokens) {\n tokens.push({ tokenId, amount: -amount });\n }\n }\n\n return { nanoErgs, tokens };\n}\n\nconst MIN_NON_MANDATORY_REGISTER_INDEX = 4;\nconst MAX_NON_MANDATORY_REGISTER_INDEX = 9;\n\n/**\n * Checks if the given registers are densely packed.\n * @param registers\n *\n * @example\n * ```\n * const registers = {\n * R4: \"deadbeef\",\n * R6: \"cafe\",\n * };\n * const result = areRegistersDenselyPacked(registers);\n * console.log(result);\n * // false\n */\nexport function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {\n let lastIndex = 0;\n for (\n let i = MIN_NON_MANDATORY_REGISTER_INDEX;\n i <= MAX_NON_MANDATORY_REGISTER_INDEX;\n i++\n ) {\n const key = `R${i}` as keyof NonMandatoryRegisters;\n if (registers[key]) {\n if (i === MIN_NON_MANDATORY_REGISTER_INDEX) {\n lastIndex = i;\n continue;\n }\n\n if (i - lastIndex > 1) {\n return false;\n }\n\n lastIndex = i;\n }\n }\n\n return true;\n}\n\n/**\n * Filters the given utxos by the given filter parameters.\n * @param utxos\n * @param filterParams\n */\nexport function utxoFilter<T extends Amount>(\n utxos: Box<T>[],\n filterParams: UTxOFilterParams<T>\n) {\n if (isEmpty(filterParams) || isEmpty(utxos)) {\n return utxos;\n }\n\n const { by, max } = filterParams;\n let filtered = utxos;\n\n if (by) {\n filtered = utxos.filter(by);\n if (isEmpty(filtered)) {\n return filtered;\n }\n }\n\n if (!max) {\n return filtered;\n }\n\n if (isDefined(max.aggregatedDistinctTokens)) {\n const tokenIds = _getDistinctTokenIds(filtered, max.aggregatedDistinctTokens);\n filtered = filtered.filter(\n (utxo) =>\n isEmpty(utxo.assets) || utxo.assets.every((token) => tokenIds.has(token.tokenId))\n );\n }\n\n if (isDefined(max.count) && filtered.length > max.count) {\n filtered = filtered.slice(0, max.count);\n }\n\n return filtered;\n}\n\nfunction _getDistinctTokenIds(utxos: Box[], max: number): Set<string> {\n const tokenIds = new Set<string>();\n\n for (let i = 0; i < utxos.length && tokenIds.size < max; i++) {\n if (isEmpty(utxos[i].assets) || utxos[i].assets.length > max) {\n continue;\n }\n\n for (const token of utxos[i].assets) {\n tokenIds.add(token.tokenId);\n }\n }\n\n return tokenIds;\n}\n\n/**\n * Parameters for filtering unspent transaction outputs (UTxOs).\n */\nexport type UTxOFilterParams<T extends Amount> = {\n /**\n * A function that returns a boolean indicating whether a given UTxO should be included in the filtered results.\n */\n by?: (utxo: Box<T>) => boolean;\n /**\n * An object specifying the maximum number of UTxOs and distinct tokens to include in the filtered results.\n */\n max?: {\n /**\n * The maximum number of UTxOs to include in the filtered results.\n */\n count?: number;\n /**\n * The maximum number of distinct tokens to include in the filtered results.\n */\n aggregatedDistinctTokens?: number;\n };\n};\n\nexport type BoxSummary = {\n nanoErgs: bigint;\n tokens: TokenAmount<bigint>[];\n};\n\nexport type BoxAmounts = {\n value: Amount;\n assets: TokenAmount<Amount>[];\n};\n\n/**\n * Ensures that the value and asset amounts of a given box are represented as BigInts.\n * @returns A new box object with BigInt representation for the value and asset amounts.\n */\nexport function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;\nexport function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;\nexport function ensureUTxOBigInt(\n box: Box<Amount> | BoxCandidate<Amount>\n): BoxCandidate<bigint> | Box<bigint> {\n return {\n ...box,\n value: ensureBigInt(box.value),\n assets: box.assets.map((token) => ({\n tokenId: token.tokenId,\n amount: ensureBigInt(token.amount)\n }))\n };\n}\n","import { isEmpty, isUndefined } from \"./assertions\";\n\n/**\n * Remove undefined values from an object\n * @param value\n *\n * @example\n * ```\n * const obj = { a: 1, b: undefined };\n * const result = clearUndefined(obj);\n * console.log(result); // { a: 1 }\n * ```\n */\nexport function clearUndefined(value: Record<string, unknown>) {\n const result: Record<string, unknown> = {};\n for (const key in value) {\n const val = value[key];\n if (!isUndefined(val)) {\n result[key] = val;\n }\n }\n\n return result;\n}\n\nexport type EnsureDefaultsOptions = { keepUndefinedKeys: boolean };\n\n/**\n * Ensure that the options object has all the default values\n * @param partial\n * @param defaults\n *\n * @example\n * ```\n * const options = { a: 1 };\n * const defaults = { a: 2, b: 3 };\n * const result = ensureDefaults(options, defaults);\n * console.log(result); // { a: 1, b: 3 }\n * ```\n */\nexport function ensureDefaults<T extends object, R extends object>(\n partial: T | undefined,\n defaults: R,\n options?: EnsureDefaultsOptions\n): R & T {\n if (isEmpty(partial)) return defaults as R & T;\n if (options?.keepUndefinedKeys) return { ...defaults, ...partial };\n\n const merged = { ...defaults, ...partial } as Record<string, unknown>;\n for (const key in merged) {\n merged[key] = partial[key as keyof T] ?? defaults[key as keyof R];\n }\n\n return merged as R & T;\n}\n","import { assertInstanceOf } from \".\";\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));\n\n let pad = 0;\n for (const bytes of arrays) {\n assertInstanceOf(bytes, Uint8Array);\n\n r.set(bytes, pad);\n pad += bytes.length;\n }\n\n return r;\n}\n\nexport function isHex(value?: string) {\n if (!value || value.length % 2) return false;\n return !Number.isNaN(Number(value.startsWith(\"0x\") ? value : `0x${value}`));\n}\n\n/**\n * Get hex string size in bytes\n * @param hex\n * @returns the byte size if the hex string\n */\nexport function byteSizeOf(hex: string): number {\n return hex.length / 2;\n}\n","export type EnumConst<T extends object> = T[keyof T];\n\nexport enum Network {\n Mainnet = 0x00,\n Testnet = 0x10\n}\n\nexport enum AddressType {\n P2PK = 1,\n P2SH = 2,\n P2S = 3,\n ADH = 4\n}\n\nexport const ergoTreeHeaderFlags = {\n sizeInclusion: 0x08,\n constantSegregation: 0x10\n} as const;\n\nexport type ErgoTreeHeaderFlag = EnumConst<typeof ergoTreeHeaderFlags>;\n","import type { OneOrMore } from \"../types\";\nimport { isDefined } from \"../utils\";\n\nexport type CollectionAddOptions = { index?: number };\n\n/**\n * Collection abstract model\n *\n * @example\n * Define a new collection class with internal type `number` and external type `string`\n * ```\n * class TestCollection extends Collection<number, string> {\n * protected _map(item: string | number): number {\n * return Number(item);\n * }\n * // Some other methods\n * }\n * ```\n *\n */\nexport abstract class Collection<InternalType, ExternalType>\n implements Iterable<InternalType>\n{\n protected readonly _items: InternalType[];\n\n constructor() {\n this._items = [];\n }\n\n protected _isIndexOutOfBounds(index: number): boolean {\n return index < 0 || index >= this._items.length;\n }\n\n [Symbol.iterator](): Iterator<InternalType> {\n let counter = 0;\n\n return {\n next: () => {\n return {\n done: counter >= this.length,\n value: this._items[counter++]\n };\n }\n };\n }\n\n /**\n * Number of items in the collection\n */\n public get length(): number {\n return this._items.length;\n }\n\n /**\n * True if the collection is empty\n */\n public get isEmpty(): boolean {\n return this.length === 0;\n }\n\n /**\n * Get item at index\n * @param index\n * @throws RangeError if index is out of bounds\n */\n public at(index: number): InternalType {\n if (this._isIndexOutOfBounds(index)) {\n throw new RangeError(`Index '${index}' is out of range.`);\n }\n\n return this._items[index];\n }\n\n /**\n * Add item to the collection\n * @param items\n * @param options\n * @returns The new length of the collection\n */\n public add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {\n return this._addOneOrMore(items, options);\n }\n\n abstract remove(item: unknown): number;\n\n /**\n * Map external type to internal type\n * @param item\n * @protected\n */\n protected abstract _map(item: ExternalType | InternalType): InternalType;\n\n protected _addOne(\n item: InternalType | ExternalType,\n options?: CollectionAddOptions\n ): number {\n if (isDefined(options) && isDefined(options.index)) {\n if (options.index === this.length) {\n this._items.push(this._map(item));\n\n return this.length;\n }\n\n if (this._isIndexOutOfBounds(options.index)) {\n throw new RangeError(`Index '${options.index}' is out of range.`);\n }\n\n this._items.splice(options.index, 0, this._map(item));\n\n return this.length;\n }\n\n this._items.push(this._map(item));\n\n return this._items.length;\n }\n\n protected _addOneOrMore(\n items: OneOrMore<ExternalType>,\n options?: CollectionAddOptions\n ): number {\n if (Array.isArray(items)) {\n if (isDefined(options) && isDefined(options.index)) {\n items = items.reverse();\n }\n\n for (const item of items) {\n this._addOne(item, options);\n }\n } else {\n this._addOne(items, options);\n }\n\n return this.length;\n }\n\n /**\n * Get the collection as an array\n */\n public toArray(): InternalType[] {\n return [...this._items];\n }\n\n public reduce<U>(\n callbackFn: (\n accumulator: U,\n currentValue: InternalType,\n currentIndex: number,\n array: InternalType[]\n ) => U,\n initialValue: U\n ): U {\n return this._items.reduce(callbackFn, initialValue);\n }\n}\n","export class FleetError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = new.target.name;\n }\n}\n\nexport class NotSupportedError extends FleetError {}\n\nexport class BlockchainProviderError extends FleetError {}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fleet-sdk/common",
|
3
|
-
"version": "0.4
|
3
|
+
"version": "0.6.4",
|
4
4
|
"description": "Internal utility functions, constants and types shared across @fleet-sdk packages.",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.mjs",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"blockchain"
|
30
30
|
],
|
31
31
|
"engines": {
|
32
|
-
"node": ">=
|
32
|
+
"node": ">=18"
|
33
33
|
},
|
34
34
|
"files": [
|
35
35
|
"dist",
|