@fleet-sdk/common 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +1 -1
  3. package/dist/index.d.mts +268 -0
  4. package/dist/index.d.ts +268 -0
  5. package/dist/index.js +604 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +551 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +9 -9
  10. package/src/utils/{arrayUtils.ts → array.ts} +4 -0
  11. package/src/utils/assertions.ts +68 -22
  12. package/src/utils/{bigIntUtils.ts → bigInt.ts} +10 -76
  13. package/src/utils/bytes.bench.ts +43 -0
  14. package/src/utils/bytes.ts +34 -0
  15. package/src/utils/index.ts +5 -6
  16. package/src/utils/object.ts +28 -0
  17. package/src/utils/{boxUtils.ts → utxo.ts} +3 -4
  18. package/dist/cjs/index.d.ts +0 -3
  19. package/dist/cjs/index.js +0 -20
  20. package/dist/cjs/index.js.map +0 -1
  21. package/dist/cjs/models/collection.d.ts +0 -20
  22. package/dist/cjs/models/collection.js +0 -76
  23. package/dist/cjs/models/collection.js.map +0 -1
  24. package/dist/cjs/models/index.d.ts +0 -1
  25. package/dist/cjs/models/index.js +0 -18
  26. package/dist/cjs/models/index.js.map +0 -1
  27. package/dist/cjs/types/boxes.d.ts +0 -22
  28. package/dist/cjs/types/boxes.js +0 -3
  29. package/dist/cjs/types/boxes.js.map +0 -1
  30. package/dist/cjs/types/common.d.ts +0 -23
  31. package/dist/cjs/types/common.js +0 -19
  32. package/dist/cjs/types/common.js.map +0 -1
  33. package/dist/cjs/types/contextExtension.d.ts +0 -4
  34. package/dist/cjs/types/contextExtension.js +0 -3
  35. package/dist/cjs/types/contextExtension.js.map +0 -1
  36. package/dist/cjs/types/index.d.ts +0 -8
  37. package/dist/cjs/types/index.js +0 -25
  38. package/dist/cjs/types/index.js.map +0 -1
  39. package/dist/cjs/types/inputs.d.ts +0 -37
  40. package/dist/cjs/types/inputs.js +0 -3
  41. package/dist/cjs/types/inputs.js.map +0 -1
  42. package/dist/cjs/types/proverResult.d.ts +0 -6
  43. package/dist/cjs/types/proverResult.js +0 -3
  44. package/dist/cjs/types/proverResult.js.map +0 -1
  45. package/dist/cjs/types/registers.d.ts +0 -9
  46. package/dist/cjs/types/registers.js +0 -3
  47. package/dist/cjs/types/registers.js.map +0 -1
  48. package/dist/cjs/types/token.d.ts +0 -18
  49. package/dist/cjs/types/token.js +0 -3
  50. package/dist/cjs/types/token.js.map +0 -1
  51. package/dist/cjs/types/transactions.d.ts +0 -22
  52. package/dist/cjs/types/transactions.js +0 -3
  53. package/dist/cjs/types/transactions.js.map +0 -1
  54. package/dist/cjs/utils/arrayUtils.d.ts +0 -25
  55. package/dist/cjs/utils/arrayUtils.js +0 -155
  56. package/dist/cjs/utils/arrayUtils.js.map +0 -1
  57. package/dist/cjs/utils/assertions.d.ts +0 -8
  58. package/dist/cjs/utils/assertions.js +0 -40
  59. package/dist/cjs/utils/assertions.js.map +0 -1
  60. package/dist/cjs/utils/bigIntLiterals.d.ts +0 -7
  61. package/dist/cjs/utils/bigIntLiterals.js +0 -12
  62. package/dist/cjs/utils/bigIntLiterals.js.map +0 -1
  63. package/dist/cjs/utils/bigIntUtils.d.ts +0 -54
  64. package/dist/cjs/utils/bigIntUtils.js +0 -183
  65. package/dist/cjs/utils/bigIntUtils.js.map +0 -1
  66. package/dist/cjs/utils/boxUtils.d.ts +0 -23
  67. package/dist/cjs/utils/boxUtils.js +0 -121
  68. package/dist/cjs/utils/boxUtils.js.map +0 -1
  69. package/dist/cjs/utils/index.d.ts +0 -7
  70. package/dist/cjs/utils/index.js +0 -24
  71. package/dist/cjs/utils/index.js.map +0 -1
  72. package/dist/cjs/utils/objectUtils.d.ts +0 -4
  73. package/dist/cjs/utils/objectUtils.js +0 -27
  74. package/dist/cjs/utils/objectUtils.js.map +0 -1
  75. package/dist/cjs/utils/stringUtils.d.ts +0 -7
  76. package/dist/cjs/utils/stringUtils.js +0 -21
  77. package/dist/cjs/utils/stringUtils.js.map +0 -1
  78. package/dist/esm/index.d.ts +0 -3
  79. package/dist/esm/index.js +0 -4
  80. package/dist/esm/index.js.map +0 -1
  81. package/dist/esm/models/collection.d.ts +0 -20
  82. package/dist/esm/models/collection.js +0 -72
  83. package/dist/esm/models/collection.js.map +0 -1
  84. package/dist/esm/models/index.d.ts +0 -1
  85. package/dist/esm/models/index.js +0 -2
  86. package/dist/esm/models/index.js.map +0 -1
  87. package/dist/esm/types/boxes.d.ts +0 -22
  88. package/dist/esm/types/boxes.js +0 -2
  89. package/dist/esm/types/boxes.js.map +0 -1
  90. package/dist/esm/types/common.d.ts +0 -23
  91. package/dist/esm/types/common.js +0 -16
  92. package/dist/esm/types/common.js.map +0 -1
  93. package/dist/esm/types/contextExtension.d.ts +0 -4
  94. package/dist/esm/types/contextExtension.js +0 -2
  95. package/dist/esm/types/contextExtension.js.map +0 -1
  96. package/dist/esm/types/index.d.ts +0 -8
  97. package/dist/esm/types/index.js +0 -9
  98. package/dist/esm/types/index.js.map +0 -1
  99. package/dist/esm/types/inputs.d.ts +0 -37
  100. package/dist/esm/types/inputs.js +0 -2
  101. package/dist/esm/types/inputs.js.map +0 -1
  102. package/dist/esm/types/proverResult.d.ts +0 -6
  103. package/dist/esm/types/proverResult.js +0 -2
  104. package/dist/esm/types/proverResult.js.map +0 -1
  105. package/dist/esm/types/registers.d.ts +0 -9
  106. package/dist/esm/types/registers.js +0 -2
  107. package/dist/esm/types/registers.js.map +0 -1
  108. package/dist/esm/types/token.d.ts +0 -18
  109. package/dist/esm/types/token.js +0 -2
  110. package/dist/esm/types/token.js.map +0 -1
  111. package/dist/esm/types/transactions.d.ts +0 -22
  112. package/dist/esm/types/transactions.js +0 -2
  113. package/dist/esm/types/transactions.js.map +0 -1
  114. package/dist/esm/utils/arrayUtils.d.ts +0 -25
  115. package/dist/esm/utils/arrayUtils.js +0 -139
  116. package/dist/esm/utils/arrayUtils.js.map +0 -1
  117. package/dist/esm/utils/assertions.d.ts +0 -8
  118. package/dist/esm/utils/assertions.js +0 -32
  119. package/dist/esm/utils/assertions.js.map +0 -1
  120. package/dist/esm/utils/bigIntLiterals.d.ts +0 -7
  121. package/dist/esm/utils/bigIntLiterals.js +0 -9
  122. package/dist/esm/utils/bigIntLiterals.js.map +0 -1
  123. package/dist/esm/utils/bigIntUtils.d.ts +0 -54
  124. package/dist/esm/utils/bigIntUtils.js +0 -170
  125. package/dist/esm/utils/bigIntUtils.js.map +0 -1
  126. package/dist/esm/utils/boxUtils.d.ts +0 -23
  127. package/dist/esm/utils/boxUtils.js +0 -113
  128. package/dist/esm/utils/boxUtils.js.map +0 -1
  129. package/dist/esm/utils/index.d.ts +0 -7
  130. package/dist/esm/utils/index.js +0 -8
  131. package/dist/esm/utils/index.js.map +0 -1
  132. package/dist/esm/utils/objectUtils.d.ts +0 -4
  133. package/dist/esm/utils/objectUtils.js +0 -20
  134. package/dist/esm/utils/objectUtils.js.map +0 -1
  135. package/dist/esm/utils/stringUtils.d.ts +0 -7
  136. package/dist/esm/utils/stringUtils.js +0 -16
  137. package/dist/esm/utils/stringUtils.js.map +0 -1
  138. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  139. package/dist/tsconfig.tsbuildinfo +0 -1
  140. package/src/utils/bigIntLiterals.ts +0 -9
  141. package/src/utils/objectUtils.ts +0 -23
  142. package/src/utils/stringUtils.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @fleet-sdk/common
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5a79c57: Add `concatBytes()` function.
8
+ - a491ab9: Add `ensureDefaults()` function.
9
+ - 3236dd8: Add new assertion functions:
10
+ - `assertTypeOf()` - uses `typeof` to check for JavaScript type primitives;
11
+ - `assertInstanceOf()` - uses `instanceof` to check for object instances.
12
+ - 9bd393b: Add `depthOf()` function.
13
+
3
14
  ## 0.1.3
4
15
 
5
16
  ### Patch Changes
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @fleet-sdk/core [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/common)](https://www.npmjs.com/package/@fleet-sdk/common)
1
+ # @fleet-sdk/common [![License](https://badgen.net/github/license/fleet-sdk/fleet/)](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [![npm](https://badgen.net/npm/v/@fleet-sdk/common)](https://www.npmjs.com/package/@fleet-sdk/common)
2
2
 
3
3
  Internal utility functions, constants and types shared across @fleet-sdk packages.
@@ -0,0 +1,268 @@
1
+ type HexString = string;
2
+ type ErgoTreeHex = string;
3
+ type Base58String = string;
4
+ type Amount = string | bigint;
5
+ type OneOrMore<T> = T | T[];
6
+ type SortingSelector<T> = (item: T) => string | number | bigint;
7
+ type SortingDirection = "asc" | "desc";
8
+ type FilterPredicate<T> = (item: T) => boolean;
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
+
25
+ type NonMandatoryRegisters = {
26
+ R4?: HexString;
27
+ R5?: HexString;
28
+ R6?: HexString;
29
+ R7?: HexString;
30
+ R8?: HexString;
31
+ R9?: HexString;
32
+ };
33
+
34
+ type TokenId = string;
35
+ type TokenBase<AmountType> = {
36
+ amount: AmountType;
37
+ };
38
+ type TokenAmount<AmountType> = TokenBase<AmountType> & {
39
+ tokenId: TokenId;
40
+ };
41
+ type NewToken<AmountType> = TokenBase<AmountType> & {
42
+ tokenId?: TokenId;
43
+ name?: string;
44
+ decimals?: number;
45
+ description?: string;
46
+ };
47
+ type TokenTargetAmount<AmountType> = {
48
+ tokenId: TokenId;
49
+ amount?: AmountType;
50
+ };
51
+
52
+ type ContextExtension = {
53
+ [key: number]: HexString | undefined;
54
+ };
55
+
56
+ type ProverResult = {
57
+ readonly proofBytes: HexString;
58
+ readonly extension: ContextExtension;
59
+ };
60
+
61
+ type SignedInput = {
62
+ readonly boxId: BoxId;
63
+ readonly spendingProof: ProverResult;
64
+ };
65
+ type UnsignedInput = {
66
+ boxId: BoxId;
67
+ extension: ContextExtension;
68
+ };
69
+ type EIP12UnsignedInput = UnsignedInput & {
70
+ transactionId: TransactionId;
71
+ index: number;
72
+ ergoTree: ErgoTreeHex;
73
+ creationHeight: number;
74
+ value: string;
75
+ assets: TokenAmount<string>[];
76
+ additionalRegisters: NonMandatoryRegisters;
77
+ };
78
+ type EIP12UnsignedDataInput = {
79
+ boxId: BoxId;
80
+ transactionId: TransactionId;
81
+ index: number;
82
+ ergoTree: ErgoTreeHex;
83
+ creationHeight: number;
84
+ value: string;
85
+ assets: TokenAmount<string>[];
86
+ additionalRegisters: NonMandatoryRegisters;
87
+ };
88
+ type DataInput = {
89
+ boxId: BoxId;
90
+ };
91
+
92
+ type TransactionId = string;
93
+ type UnsignedTransaction = {
94
+ id?: TransactionId;
95
+ inputs: UnsignedInput[];
96
+ dataInputs: DataInput[];
97
+ outputs: BoxCandidate<Amount>[];
98
+ };
99
+ type EIP12UnsignedTransaction = {
100
+ id?: TransactionId;
101
+ inputs: EIP12UnsignedInput[];
102
+ dataInputs: EIP12UnsignedDataInput[];
103
+ outputs: BoxCandidate<string>[];
104
+ };
105
+ type SignedTransaction = {
106
+ readonly id: TransactionId;
107
+ readonly inputs: SignedInput[];
108
+ readonly dataInputs: DataInput[];
109
+ readonly outputs: Box<Amount>[];
110
+ };
111
+
112
+ type BoxId = string;
113
+ type AmountType = string | bigint;
114
+ type BoxBaseType<T extends AmountType, R extends NonMandatoryRegisters> = {
115
+ ergoTree: ErgoTreeHex;
116
+ creationHeight: number;
117
+ value: T;
118
+ assets: TokenAmount<T>[];
119
+ additionalRegisters: R;
120
+ };
121
+ type BoxCandidate<T extends AmountType, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
122
+ boxId?: BoxId;
123
+ };
124
+ type Box<T extends AmountType, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
125
+ boxId: BoxId;
126
+ transactionId: TransactionId;
127
+ index: number;
128
+ };
129
+
130
+ type ObjectSelector<T> = (item: T) => T[keyof T];
131
+ declare function first(array: undefined): undefined;
132
+ declare function first<T>(array: ArrayLike<T>): T;
133
+ declare function last(array: undefined): undefined;
134
+ declare function last<T>(array: ArrayLike<T>): T;
135
+ declare function at(array: undefined, index: number): undefined;
136
+ declare function at<T>(array: ArrayLike<T>, index: number): T;
137
+ /**
138
+ * Check for duplicate elements using the equality operator
139
+ */
140
+ declare function hasDuplicates<T>(array: T[]): boolean;
141
+ /**
142
+ * Check for duplicate keys in complex elements
143
+ */
144
+ declare function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean;
145
+ declare function chunk<T>(array: T[], size: number): T[][];
146
+ declare function orderBy<T>(array: T[], iteratee: SortingSelector<T>, order?: SortingDirection): T[];
147
+ declare function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean;
148
+ declare function areEqualBy<T>(array1: ArrayLike<T>, array2: ArrayLike<T>, selector: ObjectSelector<T>): boolean;
149
+ declare function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
150
+ declare function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
151
+ declare function uniq<T>(array: Array<T>): Array<T>;
152
+ declare function uniqBy<T>(array: Array<T>, selector: ObjectSelector<T>, selection?: "keep-first" | "keep-last"): Array<T>;
153
+ declare function depthOf(array: unknown | unknown[]): number;
154
+
155
+ type NumberLike = string | number | bigint | boolean;
156
+ declare const _0n: bigint;
157
+ declare const _1n: bigint;
158
+ declare const _7n: bigint;
159
+ declare const _10n: bigint;
160
+ declare const _63n: bigint;
161
+ declare const _127n: bigint;
162
+ declare const _128n: bigint;
163
+ declare function ensureBigInt(number: NumberLike): bigint;
164
+ type ParsingOptions = {
165
+ /**
166
+ * Number of decimals.
167
+ */
168
+ decimals?: number;
169
+ /**
170
+ * Thousand mark char.
171
+ * Default: `.`
172
+ */
173
+ decimalMark?: string;
174
+ };
175
+ declare function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint;
176
+ type FormattingOptions = {
177
+ /**
178
+ * Number of decimals.
179
+ */
180
+ decimals: number;
181
+ /**
182
+ * Thousand mark char.
183
+ */
184
+ thousandMark?: string;
185
+ /**
186
+ * Decimal mark char.
187
+ * Default: `.`
188
+ */
189
+ decimalMark?: string;
190
+ };
191
+ declare function decimalize(value: Amount, options?: FormattingOptions | number): string;
192
+ declare function percent(value: bigint, percentage: bigint, precision?: bigint): bigint;
193
+ declare function sumBy<T>(collection: readonly T[], iteratee: (value: T) => bigint, condition?: (value: T) => boolean): bigint;
194
+ declare function min<T extends bigint | number>(...numbers: T[]): T;
195
+ declare function max<T extends bigint | number>(...numbers: T[]): T;
196
+
197
+ declare function utxoSum(boxes: MinimalBoxAmounts): BoxSummary;
198
+ declare function utxoSum(boxes: MinimalBoxAmounts, tokenId: TokenId): bigint;
199
+ declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[]): BoxSummary;
200
+ declare function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean;
201
+ declare function utxoFilter<T extends AmountType>(utxos: Box<T>[], filterParams: UTxOFilterParams<T>): Box<T>[];
202
+ type UTxOFilterParams<T extends AmountType> = {
203
+ by?: (utxo: Box<T>) => boolean;
204
+ max?: {
205
+ count?: number;
206
+ aggregatedDistinctTokens?: number;
207
+ };
208
+ };
209
+ type BoxSummary = {
210
+ nanoErgs: bigint;
211
+ tokens: TokenAmount<bigint>[];
212
+ };
213
+ type MinimalBoxAmounts = readonly {
214
+ value: Amount;
215
+ assets: TokenAmount<Amount>[];
216
+ }[];
217
+ declare function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;
218
+ declare function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;
219
+
220
+ declare function clearUndefined(value: Record<string, unknown>): Record<string, unknown>;
221
+ declare function ensureDefaults<T extends Partial<R>, R extends object = Required<T>>(options: T | undefined, defaults: R): R & T;
222
+
223
+ type AssertErrorMessageInput = string | Error | (() => string);
224
+ type Constructable = Function;
225
+ type JSPrimitiveTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
226
+ declare function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition;
227
+ declare function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj;
228
+ declare function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj;
229
+ declare function isEmpty<T extends object>(obj?: T): obj is undefined;
230
+ declare function isEmpty<T>(array?: T[]): array is undefined;
231
+ declare function some<T extends object>(obj?: T): obj is T;
232
+ declare function some<T>(array?: T[]): array is T[];
233
+ declare function isTruthy<T>(value?: T): value is NonNullable<T>;
234
+ declare function isFalsy<T>(value?: T): value is undefined;
235
+ declare function isUndefined(v: unknown): v is undefined;
236
+ declare function isDefined<T>(v: T | undefined): v is T;
237
+ declare function hasKey(o: unknown, key: PropertyKey): boolean;
238
+
239
+ declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
240
+ declare function isHex(value?: string): boolean;
241
+ /**
242
+ * Get hex string size in bytes
243
+ * @param hex
244
+ * @returns the byte size if the hex string
245
+ */
246
+ declare function byteSizeOf(hex: string): number;
247
+
248
+ type CollectionAddOptions = {
249
+ index?: number;
250
+ };
251
+ declare abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {
252
+ protected readonly _items: InternalType[];
253
+ constructor();
254
+ protected _isIndexOutOfBounds(index: number): boolean;
255
+ [Symbol.iterator](): Iterator<InternalType>;
256
+ get length(): number;
257
+ get isEmpty(): boolean;
258
+ at(index: number): InternalType;
259
+ add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
260
+ abstract remove(item: unknown): number;
261
+ protected abstract _map(item: ExternalType | InternalType): InternalType;
262
+ protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number;
263
+ protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
264
+ toArray(): InternalType[];
265
+ reduce<U>(callbackFn: (accumulator: U, currentValue: InternalType, currentIndex: number, array: InternalType[]) => U, initialValue: U): U;
266
+ }
267
+
268
+ export { AddressType, Amount, AmountType, AssertErrorMessageInput, Base58String, Box, BoxCandidate, BoxId, BoxSummary, BuildOutputType, Collection, CollectionAddOptions, ContextExtension, DataInput, EIP12UnsignedDataInput, EIP12UnsignedInput, EIP12UnsignedTransaction, ErgoTreeHeaderFlag, ErgoTreeHex, FilterPredicate, HexString, MinimalBoxAmounts, Network, NewToken, NonMandatoryRegisters, OneOrMore, ProverResult, SignedInput, SignedTransaction, SortingDirection, SortingSelector, TokenAmount, TokenId, TokenTargetAmount, TransactionId, UTxOFilterParams, UnsignedInput, 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 };
@@ -0,0 +1,268 @@
1
+ type HexString = string;
2
+ type ErgoTreeHex = string;
3
+ type Base58String = string;
4
+ type Amount = string | bigint;
5
+ type OneOrMore<T> = T | T[];
6
+ type SortingSelector<T> = (item: T) => string | number | bigint;
7
+ type SortingDirection = "asc" | "desc";
8
+ type FilterPredicate<T> = (item: T) => boolean;
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
+
25
+ type NonMandatoryRegisters = {
26
+ R4?: HexString;
27
+ R5?: HexString;
28
+ R6?: HexString;
29
+ R7?: HexString;
30
+ R8?: HexString;
31
+ R9?: HexString;
32
+ };
33
+
34
+ type TokenId = string;
35
+ type TokenBase<AmountType> = {
36
+ amount: AmountType;
37
+ };
38
+ type TokenAmount<AmountType> = TokenBase<AmountType> & {
39
+ tokenId: TokenId;
40
+ };
41
+ type NewToken<AmountType> = TokenBase<AmountType> & {
42
+ tokenId?: TokenId;
43
+ name?: string;
44
+ decimals?: number;
45
+ description?: string;
46
+ };
47
+ type TokenTargetAmount<AmountType> = {
48
+ tokenId: TokenId;
49
+ amount?: AmountType;
50
+ };
51
+
52
+ type ContextExtension = {
53
+ [key: number]: HexString | undefined;
54
+ };
55
+
56
+ type ProverResult = {
57
+ readonly proofBytes: HexString;
58
+ readonly extension: ContextExtension;
59
+ };
60
+
61
+ type SignedInput = {
62
+ readonly boxId: BoxId;
63
+ readonly spendingProof: ProverResult;
64
+ };
65
+ type UnsignedInput = {
66
+ boxId: BoxId;
67
+ extension: ContextExtension;
68
+ };
69
+ type EIP12UnsignedInput = UnsignedInput & {
70
+ transactionId: TransactionId;
71
+ index: number;
72
+ ergoTree: ErgoTreeHex;
73
+ creationHeight: number;
74
+ value: string;
75
+ assets: TokenAmount<string>[];
76
+ additionalRegisters: NonMandatoryRegisters;
77
+ };
78
+ type EIP12UnsignedDataInput = {
79
+ boxId: BoxId;
80
+ transactionId: TransactionId;
81
+ index: number;
82
+ ergoTree: ErgoTreeHex;
83
+ creationHeight: number;
84
+ value: string;
85
+ assets: TokenAmount<string>[];
86
+ additionalRegisters: NonMandatoryRegisters;
87
+ };
88
+ type DataInput = {
89
+ boxId: BoxId;
90
+ };
91
+
92
+ type TransactionId = string;
93
+ type UnsignedTransaction = {
94
+ id?: TransactionId;
95
+ inputs: UnsignedInput[];
96
+ dataInputs: DataInput[];
97
+ outputs: BoxCandidate<Amount>[];
98
+ };
99
+ type EIP12UnsignedTransaction = {
100
+ id?: TransactionId;
101
+ inputs: EIP12UnsignedInput[];
102
+ dataInputs: EIP12UnsignedDataInput[];
103
+ outputs: BoxCandidate<string>[];
104
+ };
105
+ type SignedTransaction = {
106
+ readonly id: TransactionId;
107
+ readonly inputs: SignedInput[];
108
+ readonly dataInputs: DataInput[];
109
+ readonly outputs: Box<Amount>[];
110
+ };
111
+
112
+ type BoxId = string;
113
+ type AmountType = string | bigint;
114
+ type BoxBaseType<T extends AmountType, R extends NonMandatoryRegisters> = {
115
+ ergoTree: ErgoTreeHex;
116
+ creationHeight: number;
117
+ value: T;
118
+ assets: TokenAmount<T>[];
119
+ additionalRegisters: R;
120
+ };
121
+ type BoxCandidate<T extends AmountType, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
122
+ boxId?: BoxId;
123
+ };
124
+ type Box<T extends AmountType, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
125
+ boxId: BoxId;
126
+ transactionId: TransactionId;
127
+ index: number;
128
+ };
129
+
130
+ type ObjectSelector<T> = (item: T) => T[keyof T];
131
+ declare function first(array: undefined): undefined;
132
+ declare function first<T>(array: ArrayLike<T>): T;
133
+ declare function last(array: undefined): undefined;
134
+ declare function last<T>(array: ArrayLike<T>): T;
135
+ declare function at(array: undefined, index: number): undefined;
136
+ declare function at<T>(array: ArrayLike<T>, index: number): T;
137
+ /**
138
+ * Check for duplicate elements using the equality operator
139
+ */
140
+ declare function hasDuplicates<T>(array: T[]): boolean;
141
+ /**
142
+ * Check for duplicate keys in complex elements
143
+ */
144
+ declare function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean;
145
+ declare function chunk<T>(array: T[], size: number): T[][];
146
+ declare function orderBy<T>(array: T[], iteratee: SortingSelector<T>, order?: SortingDirection): T[];
147
+ declare function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean;
148
+ declare function areEqualBy<T>(array1: ArrayLike<T>, array2: ArrayLike<T>, selector: ObjectSelector<T>): boolean;
149
+ declare function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
150
+ declare function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
151
+ declare function uniq<T>(array: Array<T>): Array<T>;
152
+ declare function uniqBy<T>(array: Array<T>, selector: ObjectSelector<T>, selection?: "keep-first" | "keep-last"): Array<T>;
153
+ declare function depthOf(array: unknown | unknown[]): number;
154
+
155
+ type NumberLike = string | number | bigint | boolean;
156
+ declare const _0n: bigint;
157
+ declare const _1n: bigint;
158
+ declare const _7n: bigint;
159
+ declare const _10n: bigint;
160
+ declare const _63n: bigint;
161
+ declare const _127n: bigint;
162
+ declare const _128n: bigint;
163
+ declare function ensureBigInt(number: NumberLike): bigint;
164
+ type ParsingOptions = {
165
+ /**
166
+ * Number of decimals.
167
+ */
168
+ decimals?: number;
169
+ /**
170
+ * Thousand mark char.
171
+ * Default: `.`
172
+ */
173
+ decimalMark?: string;
174
+ };
175
+ declare function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint;
176
+ type FormattingOptions = {
177
+ /**
178
+ * Number of decimals.
179
+ */
180
+ decimals: number;
181
+ /**
182
+ * Thousand mark char.
183
+ */
184
+ thousandMark?: string;
185
+ /**
186
+ * Decimal mark char.
187
+ * Default: `.`
188
+ */
189
+ decimalMark?: string;
190
+ };
191
+ declare function decimalize(value: Amount, options?: FormattingOptions | number): string;
192
+ declare function percent(value: bigint, percentage: bigint, precision?: bigint): bigint;
193
+ declare function sumBy<T>(collection: readonly T[], iteratee: (value: T) => bigint, condition?: (value: T) => boolean): bigint;
194
+ declare function min<T extends bigint | number>(...numbers: T[]): T;
195
+ declare function max<T extends bigint | number>(...numbers: T[]): T;
196
+
197
+ declare function utxoSum(boxes: MinimalBoxAmounts): BoxSummary;
198
+ declare function utxoSum(boxes: MinimalBoxAmounts, tokenId: TokenId): bigint;
199
+ declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[]): BoxSummary;
200
+ declare function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean;
201
+ declare function utxoFilter<T extends AmountType>(utxos: Box<T>[], filterParams: UTxOFilterParams<T>): Box<T>[];
202
+ type UTxOFilterParams<T extends AmountType> = {
203
+ by?: (utxo: Box<T>) => boolean;
204
+ max?: {
205
+ count?: number;
206
+ aggregatedDistinctTokens?: number;
207
+ };
208
+ };
209
+ type BoxSummary = {
210
+ nanoErgs: bigint;
211
+ tokens: TokenAmount<bigint>[];
212
+ };
213
+ type MinimalBoxAmounts = readonly {
214
+ value: Amount;
215
+ assets: TokenAmount<Amount>[];
216
+ }[];
217
+ declare function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;
218
+ declare function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;
219
+
220
+ declare function clearUndefined(value: Record<string, unknown>): Record<string, unknown>;
221
+ declare function ensureDefaults<T extends Partial<R>, R extends object = Required<T>>(options: T | undefined, defaults: R): R & T;
222
+
223
+ type AssertErrorMessageInput = string | Error | (() => string);
224
+ type Constructable = Function;
225
+ type JSPrimitiveTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
226
+ declare function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition;
227
+ declare function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj;
228
+ declare function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj;
229
+ declare function isEmpty<T extends object>(obj?: T): obj is undefined;
230
+ declare function isEmpty<T>(array?: T[]): array is undefined;
231
+ declare function some<T extends object>(obj?: T): obj is T;
232
+ declare function some<T>(array?: T[]): array is T[];
233
+ declare function isTruthy<T>(value?: T): value is NonNullable<T>;
234
+ declare function isFalsy<T>(value?: T): value is undefined;
235
+ declare function isUndefined(v: unknown): v is undefined;
236
+ declare function isDefined<T>(v: T | undefined): v is T;
237
+ declare function hasKey(o: unknown, key: PropertyKey): boolean;
238
+
239
+ declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
240
+ declare function isHex(value?: string): boolean;
241
+ /**
242
+ * Get hex string size in bytes
243
+ * @param hex
244
+ * @returns the byte size if the hex string
245
+ */
246
+ declare function byteSizeOf(hex: string): number;
247
+
248
+ type CollectionAddOptions = {
249
+ index?: number;
250
+ };
251
+ declare abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {
252
+ protected readonly _items: InternalType[];
253
+ constructor();
254
+ protected _isIndexOutOfBounds(index: number): boolean;
255
+ [Symbol.iterator](): Iterator<InternalType>;
256
+ get length(): number;
257
+ get isEmpty(): boolean;
258
+ at(index: number): InternalType;
259
+ add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
260
+ abstract remove(item: unknown): number;
261
+ protected abstract _map(item: ExternalType | InternalType): InternalType;
262
+ protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number;
263
+ protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
264
+ toArray(): InternalType[];
265
+ reduce<U>(callbackFn: (accumulator: U, currentValue: InternalType, currentIndex: number, array: InternalType[]) => U, initialValue: U): U;
266
+ }
267
+
268
+ export { AddressType, Amount, AmountType, AssertErrorMessageInput, Base58String, Box, BoxCandidate, BoxId, BoxSummary, BuildOutputType, Collection, CollectionAddOptions, ContextExtension, DataInput, EIP12UnsignedDataInput, EIP12UnsignedInput, EIP12UnsignedTransaction, ErgoTreeHeaderFlag, ErgoTreeHex, FilterPredicate, HexString, MinimalBoxAmounts, Network, NewToken, NonMandatoryRegisters, OneOrMore, ProverResult, SignedInput, SignedTransaction, SortingDirection, SortingSelector, TokenAmount, TokenId, TokenTargetAmount, TransactionId, UTxOFilterParams, UnsignedInput, 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 };