@fleet-sdk/serializer 0.8.2 → 0.8.5
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 +20 -0
- package/dist/index.d.mts +54 -16
- package/dist/index.d.ts +54 -16
- package/dist/index.js +302 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +300 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# @fleet-sdk/serializer
|
2
2
|
|
3
|
+
## 0.8.5
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- be6867a: Add `deserializeBox` function
|
8
|
+
- 3b2a774: Add `deserializeTransaction` function
|
9
|
+
- 2e627a5: Add `SBox` constant serialization and deserialization.
|
10
|
+
- Updated dependencies [07bafd5]
|
11
|
+
- @fleet-sdk/common@0.8.5
|
12
|
+
- @fleet-sdk/crypto@0.8.5
|
13
|
+
|
14
|
+
## 0.8.3
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- 9c04d3c: Add `SignedTransaction` serialization
|
19
|
+
- Updated dependencies [9c04d3c]
|
20
|
+
- @fleet-sdk/common@0.8.3
|
21
|
+
- @fleet-sdk/crypto@0.8.3
|
22
|
+
|
3
23
|
## 0.8.2
|
4
24
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
import { ByteInput as ByteInput$1, blake2b256, Coder } from '@fleet-sdk/crypto';
|
2
|
-
import { Box, Amount, BoxCandidate,
|
2
|
+
import { Box, Amount, BoxCandidate, UnsignedTransaction, SignedTransaction } from '@fleet-sdk/common';
|
3
3
|
|
4
4
|
declare class SigmaByteReader {
|
5
5
|
#private;
|
6
6
|
get isEmpty(): boolean;
|
7
|
+
get bytes(): Uint8Array;
|
8
|
+
get cursor(): number;
|
7
9
|
constructor(bytes: ByteInput$1);
|
10
|
+
readArray<T>(readFn: (reader: SigmaByteReader, index: number) => T): Array<T>;
|
8
11
|
readBool(): boolean;
|
9
12
|
readBits(length: number): ArrayLike<boolean>;
|
10
13
|
readByte(): number;
|
11
14
|
readBytes(length: number): Uint8Array;
|
12
|
-
|
15
|
+
readUInt(): number;
|
16
|
+
readBigUInt(): bigint;
|
13
17
|
readI8(): number;
|
14
18
|
readI16(): number;
|
15
19
|
readI32(): number;
|
16
20
|
readI64(): bigint;
|
17
21
|
readI256(): bigint;
|
22
|
+
/**
|
23
|
+
* Returns bytes without advancing the cursor.
|
24
|
+
*/
|
25
|
+
peek(count: number, offset?: number): Uint8Array;
|
26
|
+
/**
|
27
|
+
* Checks if the current position in the byte array starts with the given bytes.
|
28
|
+
*/
|
29
|
+
match(bytes: Uint8Array, offset?: number): boolean;
|
18
30
|
}
|
19
31
|
|
20
32
|
declare class SigmaByteWriter {
|
@@ -22,8 +34,8 @@ declare class SigmaByteWriter {
|
|
22
34
|
get length(): number;
|
23
35
|
constructor(length: number);
|
24
36
|
writeBool(value: boolean): SigmaByteWriter;
|
25
|
-
|
26
|
-
|
37
|
+
writeUInt(value: number): SigmaByteWriter;
|
38
|
+
writeBigUInt(value: bigint): SigmaByteWriter;
|
27
39
|
writeI16(value: number): SigmaByteWriter;
|
28
40
|
writeI32(value: number): SigmaByteWriter;
|
29
41
|
writeI64(value: bigint): SigmaByteWriter;
|
@@ -33,6 +45,16 @@ declare class SigmaByteWriter {
|
|
33
45
|
writeHex(bytesHex: string): SigmaByteWriter;
|
34
46
|
writeBits(bits: ArrayLike<boolean>): SigmaByteWriter;
|
35
47
|
writeChecksum(length?: number, hashFn?: typeof blake2b256): SigmaByteWriter;
|
48
|
+
/**
|
49
|
+
* Writes a length-delimited array of items to the byte stream using a provided
|
50
|
+
* serializer function.
|
51
|
+
*
|
52
|
+
* @typeParam T - The type of items in the array.
|
53
|
+
* @param items - The array of items to serialize and write.
|
54
|
+
* @param serializer - A function that serializes each item and writes it using the provided SigmaByteWriter.
|
55
|
+
* @returns The current instance of SigmaByteWriter for method chaining.
|
56
|
+
*/
|
57
|
+
writeArray<T>(items: T[], serializer: (item: T, writer: SigmaByteWriter) => void): SigmaByteWriter;
|
36
58
|
encode<T>(coder: Coder<Uint8Array, T>): T;
|
37
59
|
toBytes(): Uint8Array;
|
38
60
|
}
|
@@ -81,6 +103,10 @@ declare class SUnitType extends SMonomorphicType<undefined> {
|
|
81
103
|
get code(): 0x62;
|
82
104
|
toString(): string;
|
83
105
|
}
|
106
|
+
declare class SBoxType extends SMonomorphicType<SConstant<Box<bigint>>> {
|
107
|
+
get code(): 0x63;
|
108
|
+
toString(): string;
|
109
|
+
}
|
84
110
|
|
85
111
|
type BigIntInput = string | bigint;
|
86
112
|
type ByteInput = Uint8Array | string;
|
@@ -97,8 +123,10 @@ declare const SLong: SProxy<SLongType, BigIntInput, bigint>;
|
|
97
123
|
declare const SBigInt: SProxy<SBigIntType, BigIntInput, bigint>;
|
98
124
|
declare const SGroupElement: SProxy<SGroupElementType, ByteInput, Uint8Array<ArrayBufferLike>>;
|
99
125
|
declare const SSigmaProp: SProxy<SSigmaPropType, SConstant<Uint8Array<ArrayBufferLike>, SType<unknown, unknown>>, SConstant<Uint8Array<ArrayBufferLike>, SType<unknown, unknown>>>;
|
100
|
-
type SUnit = (
|
126
|
+
type SUnit = () => SConstant<undefined, SUnitType>;
|
101
127
|
declare const SUnit: SUnit;
|
128
|
+
type SBox = (value?: Box) => SConstant<Box<bigint>, SBoxType>;
|
129
|
+
declare const SBox: SBox;
|
102
130
|
type SColl = {
|
103
131
|
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput | D[]): SConstant<Uint8Array, T>;
|
104
132
|
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput[]): SConstant<Uint8Array[], T>;
|
@@ -155,7 +183,7 @@ declare function isTuple(type: SType): type is STupleType;
|
|
155
183
|
declare class SConstant<D = unknown, T extends SType = SType> {
|
156
184
|
#private;
|
157
185
|
constructor(type: T, data: D);
|
158
|
-
static from<D, T extends SType = SType>(bytes: ByteInput$1): SConstant<D, T>;
|
186
|
+
static from<D, T extends SType = SType>(bytes: ByteInput$1 | SigmaByteReader): SConstant<D, T>;
|
159
187
|
get type(): T;
|
160
188
|
get data(): D;
|
161
189
|
toBytes(): Uint8Array;
|
@@ -185,21 +213,31 @@ declare function parse<T>(constant: ByteInput$1, mode: "strict"): T;
|
|
185
213
|
/** @deprecated use `decode` instead */
|
186
214
|
declare function parse<T>(constant: ByteInput$1 | undefined, mode: "safe"): T | undefined;
|
187
215
|
|
188
|
-
declare function serializeBox(box: Box<Amount>): SigmaByteWriter;
|
189
|
-
declare function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;
|
190
|
-
declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaByteWriter, distinctTokenIds: string[]): SigmaByteWriter;
|
216
|
+
declare function serializeBox(box: Box<Amount> | BoxCandidate<Amount>, writer?: SigmaByteWriter, distinctTokenIds?: string[]): SigmaByteWriter;
|
191
217
|
/**
|
192
218
|
* Estimates the byte size a box.
|
193
219
|
* @returns byte size of the box.
|
194
220
|
*/
|
195
221
|
declare function estimateBoxSize(box: Box<Amount> | BoxCandidate<Amount>, withValue?: Amount): number;
|
222
|
+
/**
|
223
|
+
* Deserializes a box embedded in a transaction.
|
224
|
+
*
|
225
|
+
* It efficiently calculates the box ID by accumulating the serialized data during
|
226
|
+
* deserialization and applying blake2b256 hashing, avoiding redundant serialization
|
227
|
+
* operations.
|
228
|
+
*
|
229
|
+
* @param reader - SigmaByteReader containing the serialized box data
|
230
|
+
* @param distinctTokenIds - Array of TokenIDs referenced in the parent transaction
|
231
|
+
* @param transactionId - ID of the transaction containing this box
|
232
|
+
* @param index - Index position of the box in the transaction outputs
|
233
|
+
* @returns A fully deserialized Box with all properties including boxId
|
234
|
+
*/
|
235
|
+
declare function deserializeEmbeddedBox(reader: SigmaByteReader, distinctTokenIds: string[], transactionId: string, index: number): Box<bigint>;
|
236
|
+
declare function deserializeBox(input: ByteInput | SigmaByteReader): BoxCandidate<bigint> | Box<bigint>;
|
196
237
|
|
197
|
-
type
|
198
|
-
|
199
|
-
|
200
|
-
outputs: readonly BoxCandidate<Amount>[];
|
201
|
-
};
|
202
|
-
declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaByteWriter;
|
238
|
+
type Transaction = UnsignedTransaction | SignedTransaction;
|
239
|
+
declare function serializeTransaction(transaction: Transaction): SigmaByteWriter;
|
240
|
+
declare function deserializeTransaction<T extends Transaction>(input: ByteInput): T;
|
203
241
|
|
204
242
|
declare const dataSerializer: {
|
205
243
|
serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter;
|
@@ -211,4 +249,4 @@ declare const typeSerializer: {
|
|
211
249
|
deserialize(r: SigmaByteReader): SType;
|
212
250
|
};
|
213
251
|
|
214
|
-
export {
|
252
|
+
export { SBigInt, SBigIntType, SBool, SBoolType, SBox, SBoxType, SByte, SByteType, SColl, SCollType, SConstant, SGenericType, SGroupElement, SGroupElementType, SInt, SIntType, SLong, SLongType, SMonomorphicType, SPair, SPrimitiveType, SShort, SShortType, SSigmaProp, SSigmaPropType, STupleType, SType, SUnit, SUnitType, SigmaByteReader, SigmaByteWriter, dataSerializer, decode, deserializeBox, deserializeEmbeddedBox, deserializeTransaction, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction, stypeof, typeSerializer };
|
package/dist/index.d.ts
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
import { ByteInput as ByteInput$1, blake2b256, Coder } from '@fleet-sdk/crypto';
|
2
|
-
import { Box, Amount, BoxCandidate,
|
2
|
+
import { Box, Amount, BoxCandidate, UnsignedTransaction, SignedTransaction } from '@fleet-sdk/common';
|
3
3
|
|
4
4
|
declare class SigmaByteReader {
|
5
5
|
#private;
|
6
6
|
get isEmpty(): boolean;
|
7
|
+
get bytes(): Uint8Array;
|
8
|
+
get cursor(): number;
|
7
9
|
constructor(bytes: ByteInput$1);
|
10
|
+
readArray<T>(readFn: (reader: SigmaByteReader, index: number) => T): Array<T>;
|
8
11
|
readBool(): boolean;
|
9
12
|
readBits(length: number): ArrayLike<boolean>;
|
10
13
|
readByte(): number;
|
11
14
|
readBytes(length: number): Uint8Array;
|
12
|
-
|
15
|
+
readUInt(): number;
|
16
|
+
readBigUInt(): bigint;
|
13
17
|
readI8(): number;
|
14
18
|
readI16(): number;
|
15
19
|
readI32(): number;
|
16
20
|
readI64(): bigint;
|
17
21
|
readI256(): bigint;
|
22
|
+
/**
|
23
|
+
* Returns bytes without advancing the cursor.
|
24
|
+
*/
|
25
|
+
peek(count: number, offset?: number): Uint8Array;
|
26
|
+
/**
|
27
|
+
* Checks if the current position in the byte array starts with the given bytes.
|
28
|
+
*/
|
29
|
+
match(bytes: Uint8Array, offset?: number): boolean;
|
18
30
|
}
|
19
31
|
|
20
32
|
declare class SigmaByteWriter {
|
@@ -22,8 +34,8 @@ declare class SigmaByteWriter {
|
|
22
34
|
get length(): number;
|
23
35
|
constructor(length: number);
|
24
36
|
writeBool(value: boolean): SigmaByteWriter;
|
25
|
-
|
26
|
-
|
37
|
+
writeUInt(value: number): SigmaByteWriter;
|
38
|
+
writeBigUInt(value: bigint): SigmaByteWriter;
|
27
39
|
writeI16(value: number): SigmaByteWriter;
|
28
40
|
writeI32(value: number): SigmaByteWriter;
|
29
41
|
writeI64(value: bigint): SigmaByteWriter;
|
@@ -33,6 +45,16 @@ declare class SigmaByteWriter {
|
|
33
45
|
writeHex(bytesHex: string): SigmaByteWriter;
|
34
46
|
writeBits(bits: ArrayLike<boolean>): SigmaByteWriter;
|
35
47
|
writeChecksum(length?: number, hashFn?: typeof blake2b256): SigmaByteWriter;
|
48
|
+
/**
|
49
|
+
* Writes a length-delimited array of items to the byte stream using a provided
|
50
|
+
* serializer function.
|
51
|
+
*
|
52
|
+
* @typeParam T - The type of items in the array.
|
53
|
+
* @param items - The array of items to serialize and write.
|
54
|
+
* @param serializer - A function that serializes each item and writes it using the provided SigmaByteWriter.
|
55
|
+
* @returns The current instance of SigmaByteWriter for method chaining.
|
56
|
+
*/
|
57
|
+
writeArray<T>(items: T[], serializer: (item: T, writer: SigmaByteWriter) => void): SigmaByteWriter;
|
36
58
|
encode<T>(coder: Coder<Uint8Array, T>): T;
|
37
59
|
toBytes(): Uint8Array;
|
38
60
|
}
|
@@ -81,6 +103,10 @@ declare class SUnitType extends SMonomorphicType<undefined> {
|
|
81
103
|
get code(): 0x62;
|
82
104
|
toString(): string;
|
83
105
|
}
|
106
|
+
declare class SBoxType extends SMonomorphicType<SConstant<Box<bigint>>> {
|
107
|
+
get code(): 0x63;
|
108
|
+
toString(): string;
|
109
|
+
}
|
84
110
|
|
85
111
|
type BigIntInput = string | bigint;
|
86
112
|
type ByteInput = Uint8Array | string;
|
@@ -97,8 +123,10 @@ declare const SLong: SProxy<SLongType, BigIntInput, bigint>;
|
|
97
123
|
declare const SBigInt: SProxy<SBigIntType, BigIntInput, bigint>;
|
98
124
|
declare const SGroupElement: SProxy<SGroupElementType, ByteInput, Uint8Array<ArrayBufferLike>>;
|
99
125
|
declare const SSigmaProp: SProxy<SSigmaPropType, SConstant<Uint8Array<ArrayBufferLike>, SType<unknown, unknown>>, SConstant<Uint8Array<ArrayBufferLike>, SType<unknown, unknown>>>;
|
100
|
-
type SUnit = (
|
126
|
+
type SUnit = () => SConstant<undefined, SUnitType>;
|
101
127
|
declare const SUnit: SUnit;
|
128
|
+
type SBox = (value?: Box) => SConstant<Box<bigint>, SBoxType>;
|
129
|
+
declare const SBox: SBox;
|
102
130
|
type SColl = {
|
103
131
|
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput | D[]): SConstant<Uint8Array, T>;
|
104
132
|
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput[]): SConstant<Uint8Array[], T>;
|
@@ -155,7 +183,7 @@ declare function isTuple(type: SType): type is STupleType;
|
|
155
183
|
declare class SConstant<D = unknown, T extends SType = SType> {
|
156
184
|
#private;
|
157
185
|
constructor(type: T, data: D);
|
158
|
-
static from<D, T extends SType = SType>(bytes: ByteInput$1): SConstant<D, T>;
|
186
|
+
static from<D, T extends SType = SType>(bytes: ByteInput$1 | SigmaByteReader): SConstant<D, T>;
|
159
187
|
get type(): T;
|
160
188
|
get data(): D;
|
161
189
|
toBytes(): Uint8Array;
|
@@ -185,21 +213,31 @@ declare function parse<T>(constant: ByteInput$1, mode: "strict"): T;
|
|
185
213
|
/** @deprecated use `decode` instead */
|
186
214
|
declare function parse<T>(constant: ByteInput$1 | undefined, mode: "safe"): T | undefined;
|
187
215
|
|
188
|
-
declare function serializeBox(box: Box<Amount>): SigmaByteWriter;
|
189
|
-
declare function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;
|
190
|
-
declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaByteWriter, distinctTokenIds: string[]): SigmaByteWriter;
|
216
|
+
declare function serializeBox(box: Box<Amount> | BoxCandidate<Amount>, writer?: SigmaByteWriter, distinctTokenIds?: string[]): SigmaByteWriter;
|
191
217
|
/**
|
192
218
|
* Estimates the byte size a box.
|
193
219
|
* @returns byte size of the box.
|
194
220
|
*/
|
195
221
|
declare function estimateBoxSize(box: Box<Amount> | BoxCandidate<Amount>, withValue?: Amount): number;
|
222
|
+
/**
|
223
|
+
* Deserializes a box embedded in a transaction.
|
224
|
+
*
|
225
|
+
* It efficiently calculates the box ID by accumulating the serialized data during
|
226
|
+
* deserialization and applying blake2b256 hashing, avoiding redundant serialization
|
227
|
+
* operations.
|
228
|
+
*
|
229
|
+
* @param reader - SigmaByteReader containing the serialized box data
|
230
|
+
* @param distinctTokenIds - Array of TokenIDs referenced in the parent transaction
|
231
|
+
* @param transactionId - ID of the transaction containing this box
|
232
|
+
* @param index - Index position of the box in the transaction outputs
|
233
|
+
* @returns A fully deserialized Box with all properties including boxId
|
234
|
+
*/
|
235
|
+
declare function deserializeEmbeddedBox(reader: SigmaByteReader, distinctTokenIds: string[], transactionId: string, index: number): Box<bigint>;
|
236
|
+
declare function deserializeBox(input: ByteInput | SigmaByteReader): BoxCandidate<bigint> | Box<bigint>;
|
196
237
|
|
197
|
-
type
|
198
|
-
|
199
|
-
|
200
|
-
outputs: readonly BoxCandidate<Amount>[];
|
201
|
-
};
|
202
|
-
declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaByteWriter;
|
238
|
+
type Transaction = UnsignedTransaction | SignedTransaction;
|
239
|
+
declare function serializeTransaction(transaction: Transaction): SigmaByteWriter;
|
240
|
+
declare function deserializeTransaction<T extends Transaction>(input: ByteInput): T;
|
203
241
|
|
204
242
|
declare const dataSerializer: {
|
205
243
|
serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter;
|
@@ -211,4 +249,4 @@ declare const typeSerializer: {
|
|
211
249
|
deserialize(r: SigmaByteReader): SType;
|
212
250
|
};
|
213
251
|
|
214
|
-
export {
|
252
|
+
export { SBigInt, SBigIntType, SBool, SBoolType, SBox, SBoxType, SByte, SByteType, SColl, SCollType, SConstant, SGenericType, SGroupElement, SGroupElementType, SInt, SIntType, SLong, SLongType, SMonomorphicType, SPair, SPrimitiveType, SShort, SShortType, SSigmaProp, SSigmaPropType, STupleType, SType, SUnit, SUnitType, SigmaByteReader, SigmaByteWriter, dataSerializer, decode, deserializeBox, deserializeEmbeddedBox, deserializeTransaction, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction, stypeof, typeSerializer };
|