@fleet-sdk/serializer 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/index.d.mts +191 -0
- package/dist/index.d.ts +191 -0
- package/dist/index.js +974 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +937 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -0
- package/src/_test-vectors/boxVectors.ts +207 -0
- package/src/_test-vectors/constantVectors.ts +457 -0
- package/src/_test-vectors/transactionVectors.ts +590 -0
- package/src/coders/bigint.ts +73 -0
- package/src/coders/index.ts +4 -0
- package/src/coders/sigmaReader.ts +81 -0
- package/src/coders/sigmaWriter.ts +106 -0
- package/src/coders/vlq.ts +141 -0
- package/src/coders/zigZag.ts +46 -0
- package/src/index.ts +4 -0
- package/src/serializers/boxSerializer.ts +139 -0
- package/src/serializers/dataSerializer.ts +141 -0
- package/src/serializers/index.ts +4 -0
- package/src/serializers/transactionSerializer.ts +76 -0
- package/src/serializers/typeSerializer.ts +148 -0
- package/src/sigmaConstant.ts +59 -0
- package/src/types/base.ts +46 -0
- package/src/types/constructors.test-d.ts +147 -0
- package/src/types/constructors.ts +144 -0
- package/src/types/descriptors.ts +105 -0
- package/src/types/generics.ts +42 -0
- package/src/types/index.ts +18 -0
- package/src/types/monomorphics.ts +11 -0
- package/src/types/primitives.ts +97 -0
package/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# @fleet-sdk/serializer
|
2
|
+
|
3
|
+
## 0.2.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 76d4c3d: Introduce `serializer` package.
|
8
|
+
- cd877ce: Add embedded `SColl` support.
|
9
|
+
- cd877ce: Add `SPair` type support.
|
10
|
+
- e532fb8: Add type string representation.
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- Updated dependencies [5a79c57]
|
15
|
+
- Updated dependencies [8a13a29]
|
16
|
+
- Updated dependencies [a491ab9]
|
17
|
+
- Updated dependencies [3236dd8]
|
18
|
+
- Updated dependencies [9bd393b]
|
19
|
+
- Updated dependencies [2ab9661]
|
20
|
+
- Updated dependencies [2ab9661]
|
21
|
+
- @fleet-sdk/common@0.2.0
|
22
|
+
- @fleet-sdk/crypto@0.2.0
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Nautilus Team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
# @fleet-sdk/serializer [](https://github.com/fleet-sdk/fleet/blob/master/LICENSE) [](https://www.npmjs.com/package/@fleet-sdk/serializer)
|
2
|
+
|
3
|
+
Ergo constant serializer and parser.
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
import { BytesInput } from '@fleet-sdk/crypto';
|
2
|
+
import { HexString, Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
|
3
|
+
|
4
|
+
declare class SigmaReader {
|
5
|
+
#private;
|
6
|
+
get isEmpty(): boolean;
|
7
|
+
constructor(bytes: HexString | Uint8Array);
|
8
|
+
readBoolean(): boolean;
|
9
|
+
readBits(length: number): ArrayLike<boolean>;
|
10
|
+
readByte(): number;
|
11
|
+
readBytes(length: number): Uint8Array;
|
12
|
+
readVlq(): number;
|
13
|
+
readShort(): number;
|
14
|
+
readInt(): number;
|
15
|
+
readLong(): bigint;
|
16
|
+
readBigInt(): bigint;
|
17
|
+
}
|
18
|
+
|
19
|
+
declare class SigmaWriter {
|
20
|
+
#private;
|
21
|
+
get length(): number;
|
22
|
+
constructor(maxLength: number);
|
23
|
+
writeBoolean(value: boolean): SigmaWriter;
|
24
|
+
writeVLQ(value: number): SigmaWriter;
|
25
|
+
writeBigVLQ(value: bigint): SigmaWriter;
|
26
|
+
writeShort(value: number): SigmaWriter;
|
27
|
+
writeInt(value: number): SigmaWriter;
|
28
|
+
writeLong(value: bigint): SigmaWriter;
|
29
|
+
write(byte: number): SigmaWriter;
|
30
|
+
writeBytes(bytes: Uint8Array): SigmaWriter;
|
31
|
+
writeHex(bytesHex: string): SigmaWriter;
|
32
|
+
writeBits(bits: ArrayLike<boolean>): SigmaWriter;
|
33
|
+
writeBigInt(value: bigint): SigmaWriter;
|
34
|
+
toHex(): string;
|
35
|
+
toBytes(): Uint8Array;
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Estimates the byte size of a given unsigned integer.
|
40
|
+
* @param value: the value to be evaluated.
|
41
|
+
* @returns the byte size of the value.
|
42
|
+
*/
|
43
|
+
declare function estimateVLQSize(value: number | bigint | string): number;
|
44
|
+
|
45
|
+
declare abstract class SType<I = unknown, O = I> {
|
46
|
+
abstract get code(): number;
|
47
|
+
abstract get embeddable(): boolean;
|
48
|
+
coerce(data: I): O;
|
49
|
+
abstract toString(): string;
|
50
|
+
}
|
51
|
+
declare abstract class SMonomorphicType<I, O = I> extends SType<I, O> {
|
52
|
+
abstract get code(): number;
|
53
|
+
get embeddable(): boolean;
|
54
|
+
}
|
55
|
+
declare abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {
|
56
|
+
abstract get code(): number;
|
57
|
+
get embeddable(): boolean;
|
58
|
+
}
|
59
|
+
declare abstract class SGenericType<T extends SType | SType[]> extends SType {
|
60
|
+
#private;
|
61
|
+
constructor(type: T);
|
62
|
+
abstract get code(): number;
|
63
|
+
get elementsType(): T;
|
64
|
+
get embeddable(): boolean;
|
65
|
+
}
|
66
|
+
|
67
|
+
declare class SCollType<T extends SType = SType> extends SGenericType<T> {
|
68
|
+
get code(): number;
|
69
|
+
coerce<I, O>(elements: I[]): O[] | Uint8Array;
|
70
|
+
toString(): string;
|
71
|
+
}
|
72
|
+
declare class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {
|
73
|
+
get code(): number;
|
74
|
+
coerce<I, O>(elements: I[]): O[];
|
75
|
+
toString(): string;
|
76
|
+
}
|
77
|
+
|
78
|
+
declare class SUnitType extends SMonomorphicType<undefined> {
|
79
|
+
get code(): 0x62;
|
80
|
+
toString(): string;
|
81
|
+
}
|
82
|
+
|
83
|
+
type BigIntInput = string | bigint;
|
84
|
+
type ByteInput = Uint8Array | string;
|
85
|
+
type SConstructor<T = unknown, S extends SType = SType | SCollType<SType>> = (arg?: T) => S;
|
86
|
+
type SProxy<T extends SType, I, O = I> = {
|
87
|
+
(value: I): SConstant<O, T>;
|
88
|
+
(value?: I): T;
|
89
|
+
};
|
90
|
+
declare const SByte: SProxy<SByteType, number, number>;
|
91
|
+
declare const SBool: SProxy<SBoolType, boolean, boolean>;
|
92
|
+
declare const SShort: SProxy<SShortType, number, number>;
|
93
|
+
declare const SInt: SProxy<SIntType, number, number>;
|
94
|
+
declare const SLong: SProxy<SLongType, BigIntInput, bigint>;
|
95
|
+
declare const SBigInt: SProxy<SBigIntType, BigIntInput, bigint>;
|
96
|
+
declare const SGroupElement: SProxy<SGroupElementType, ByteInput, Uint8Array>;
|
97
|
+
declare const SSigmaProp: SProxy<SSigmaPropType, SConstant<Uint8Array, SType<unknown, unknown>>, SConstant<Uint8Array, SType<unknown, unknown>>>;
|
98
|
+
type SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;
|
99
|
+
declare const SUnit: SUnit;
|
100
|
+
type SColl = {
|
101
|
+
<D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;
|
102
|
+
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput | D[]): SConstant<Uint8Array, T>;
|
103
|
+
<D, T extends SType>(type: SConstructor<D, T>, elements: D[]): SConstant<D[], T>;
|
104
|
+
};
|
105
|
+
declare const SColl: SColl;
|
106
|
+
type ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;
|
107
|
+
type SPair = {
|
108
|
+
<L, R>(left: SConstant<L>, right: SConstant<R>): SConstant<[L, R], STupleType>;
|
109
|
+
<LD, RD, LT extends SType, RT extends SType>(left: SConstructor<LD, LT>, right: SConstructor<RD, RT>): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;
|
110
|
+
};
|
111
|
+
declare const SPair: SPair;
|
112
|
+
|
113
|
+
declare class SBoolType extends SPrimitiveType<boolean> {
|
114
|
+
get code(): 0x01;
|
115
|
+
toString(): string;
|
116
|
+
}
|
117
|
+
declare class SByteType extends SPrimitiveType<number> {
|
118
|
+
get code(): 0x02;
|
119
|
+
toString(): string;
|
120
|
+
}
|
121
|
+
declare class SShortType extends SPrimitiveType<number> {
|
122
|
+
get code(): 0x03;
|
123
|
+
toString(): string;
|
124
|
+
}
|
125
|
+
declare class SIntType extends SPrimitiveType<number> {
|
126
|
+
get code(): 0x04;
|
127
|
+
toString(): string;
|
128
|
+
}
|
129
|
+
declare class SLongType extends SPrimitiveType<BigIntInput, bigint> {
|
130
|
+
get code(): 0x05;
|
131
|
+
coerce(data: BigIntInput): bigint;
|
132
|
+
toString(): string;
|
133
|
+
}
|
134
|
+
declare class SBigIntType extends SPrimitiveType<string | bigint, bigint> {
|
135
|
+
get code(): number;
|
136
|
+
coerce(data: BigIntInput): bigint;
|
137
|
+
toString(): string;
|
138
|
+
}
|
139
|
+
declare class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {
|
140
|
+
get code(): 0x07;
|
141
|
+
coerce(data: ByteInput): Uint8Array;
|
142
|
+
toString(): string;
|
143
|
+
}
|
144
|
+
declare class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {
|
145
|
+
get code(): 0x08;
|
146
|
+
toString(): string;
|
147
|
+
}
|
148
|
+
|
149
|
+
declare function isColl(type: SType): type is SCollType;
|
150
|
+
declare function isTuple(type: SType): type is STupleType;
|
151
|
+
|
152
|
+
declare class SConstant<D = unknown, T extends SType = SType> {
|
153
|
+
#private;
|
154
|
+
constructor(type: T, data: D);
|
155
|
+
static from<D, T extends SType = SType>(bytes: BytesInput): SConstant<D, T>;
|
156
|
+
get type(): T;
|
157
|
+
get data(): D;
|
158
|
+
toBytes(): Uint8Array;
|
159
|
+
toHex(): string;
|
160
|
+
}
|
161
|
+
declare function parse<T>(bytes: BytesInput): T;
|
162
|
+
declare function parse<T>(bytes: BytesInput, mode: "strict"): T;
|
163
|
+
declare function parse<T>(bytes: BytesInput, mode: "safe"): T | undefined;
|
164
|
+
|
165
|
+
declare function serializeBox(box: Box<Amount>): SigmaWriter;
|
166
|
+
declare function serializeBox(box: Box<Amount>, writer: SigmaWriter): SigmaWriter;
|
167
|
+
declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaWriter, distinctTokenIds: string[]): SigmaWriter;
|
168
|
+
/**
|
169
|
+
* Estimates the byte size a box.
|
170
|
+
* @returns byte size of the box.
|
171
|
+
*/
|
172
|
+
declare function estimateBoxSize(box: Box<Amount> | BoxCandidate<Amount>, withValue?: Amount): number;
|
173
|
+
|
174
|
+
type MinimalUnsignedTransaction = {
|
175
|
+
inputs: readonly UnsignedInput[];
|
176
|
+
dataInputs: readonly DataInput[];
|
177
|
+
outputs: readonly BoxCandidate<Amount>[];
|
178
|
+
};
|
179
|
+
declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaWriter;
|
180
|
+
|
181
|
+
declare class DataSerializer {
|
182
|
+
static serialize(data: unknown, type: SType, writer: SigmaWriter): SigmaWriter;
|
183
|
+
static deserialize(type: SType, reader: SigmaReader): unknown;
|
184
|
+
}
|
185
|
+
|
186
|
+
declare class TypeSerializer {
|
187
|
+
static serialize(type: SType, writer: SigmaWriter): void;
|
188
|
+
static deserialize(r: SigmaReader): SType;
|
189
|
+
}
|
190
|
+
|
191
|
+
export { DataSerializer, MinimalUnsignedTransaction, SBigInt, SBigIntType, SBool, SBoolType, SByte, SByteType, SColl, SCollType, SConstant, SGenericType, SGroupElement, SGroupElementType, SInt, SIntType, SLong, SLongType, SMonomorphicType, SPair, SPrimitiveType, SShort, SShortType, SSigmaProp, SSigmaPropType, STupleType, SType, SUnit, SUnitType, TypeSerializer, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
import { BytesInput } from '@fleet-sdk/crypto';
|
2
|
+
import { HexString, Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
|
3
|
+
|
4
|
+
declare class SigmaReader {
|
5
|
+
#private;
|
6
|
+
get isEmpty(): boolean;
|
7
|
+
constructor(bytes: HexString | Uint8Array);
|
8
|
+
readBoolean(): boolean;
|
9
|
+
readBits(length: number): ArrayLike<boolean>;
|
10
|
+
readByte(): number;
|
11
|
+
readBytes(length: number): Uint8Array;
|
12
|
+
readVlq(): number;
|
13
|
+
readShort(): number;
|
14
|
+
readInt(): number;
|
15
|
+
readLong(): bigint;
|
16
|
+
readBigInt(): bigint;
|
17
|
+
}
|
18
|
+
|
19
|
+
declare class SigmaWriter {
|
20
|
+
#private;
|
21
|
+
get length(): number;
|
22
|
+
constructor(maxLength: number);
|
23
|
+
writeBoolean(value: boolean): SigmaWriter;
|
24
|
+
writeVLQ(value: number): SigmaWriter;
|
25
|
+
writeBigVLQ(value: bigint): SigmaWriter;
|
26
|
+
writeShort(value: number): SigmaWriter;
|
27
|
+
writeInt(value: number): SigmaWriter;
|
28
|
+
writeLong(value: bigint): SigmaWriter;
|
29
|
+
write(byte: number): SigmaWriter;
|
30
|
+
writeBytes(bytes: Uint8Array): SigmaWriter;
|
31
|
+
writeHex(bytesHex: string): SigmaWriter;
|
32
|
+
writeBits(bits: ArrayLike<boolean>): SigmaWriter;
|
33
|
+
writeBigInt(value: bigint): SigmaWriter;
|
34
|
+
toHex(): string;
|
35
|
+
toBytes(): Uint8Array;
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Estimates the byte size of a given unsigned integer.
|
40
|
+
* @param value: the value to be evaluated.
|
41
|
+
* @returns the byte size of the value.
|
42
|
+
*/
|
43
|
+
declare function estimateVLQSize(value: number | bigint | string): number;
|
44
|
+
|
45
|
+
declare abstract class SType<I = unknown, O = I> {
|
46
|
+
abstract get code(): number;
|
47
|
+
abstract get embeddable(): boolean;
|
48
|
+
coerce(data: I): O;
|
49
|
+
abstract toString(): string;
|
50
|
+
}
|
51
|
+
declare abstract class SMonomorphicType<I, O = I> extends SType<I, O> {
|
52
|
+
abstract get code(): number;
|
53
|
+
get embeddable(): boolean;
|
54
|
+
}
|
55
|
+
declare abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {
|
56
|
+
abstract get code(): number;
|
57
|
+
get embeddable(): boolean;
|
58
|
+
}
|
59
|
+
declare abstract class SGenericType<T extends SType | SType[]> extends SType {
|
60
|
+
#private;
|
61
|
+
constructor(type: T);
|
62
|
+
abstract get code(): number;
|
63
|
+
get elementsType(): T;
|
64
|
+
get embeddable(): boolean;
|
65
|
+
}
|
66
|
+
|
67
|
+
declare class SCollType<T extends SType = SType> extends SGenericType<T> {
|
68
|
+
get code(): number;
|
69
|
+
coerce<I, O>(elements: I[]): O[] | Uint8Array;
|
70
|
+
toString(): string;
|
71
|
+
}
|
72
|
+
declare class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {
|
73
|
+
get code(): number;
|
74
|
+
coerce<I, O>(elements: I[]): O[];
|
75
|
+
toString(): string;
|
76
|
+
}
|
77
|
+
|
78
|
+
declare class SUnitType extends SMonomorphicType<undefined> {
|
79
|
+
get code(): 0x62;
|
80
|
+
toString(): string;
|
81
|
+
}
|
82
|
+
|
83
|
+
type BigIntInput = string | bigint;
|
84
|
+
type ByteInput = Uint8Array | string;
|
85
|
+
type SConstructor<T = unknown, S extends SType = SType | SCollType<SType>> = (arg?: T) => S;
|
86
|
+
type SProxy<T extends SType, I, O = I> = {
|
87
|
+
(value: I): SConstant<O, T>;
|
88
|
+
(value?: I): T;
|
89
|
+
};
|
90
|
+
declare const SByte: SProxy<SByteType, number, number>;
|
91
|
+
declare const SBool: SProxy<SBoolType, boolean, boolean>;
|
92
|
+
declare const SShort: SProxy<SShortType, number, number>;
|
93
|
+
declare const SInt: SProxy<SIntType, number, number>;
|
94
|
+
declare const SLong: SProxy<SLongType, BigIntInput, bigint>;
|
95
|
+
declare const SBigInt: SProxy<SBigIntType, BigIntInput, bigint>;
|
96
|
+
declare const SGroupElement: SProxy<SGroupElementType, ByteInput, Uint8Array>;
|
97
|
+
declare const SSigmaProp: SProxy<SSigmaPropType, SConstant<Uint8Array, SType<unknown, unknown>>, SConstant<Uint8Array, SType<unknown, unknown>>>;
|
98
|
+
type SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;
|
99
|
+
declare const SUnit: SUnit;
|
100
|
+
type SColl = {
|
101
|
+
<D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;
|
102
|
+
<D, T extends SByteType>(type: SConstructor<D, T>, elements: ByteInput | D[]): SConstant<Uint8Array, T>;
|
103
|
+
<D, T extends SType>(type: SConstructor<D, T>, elements: D[]): SConstant<D[], T>;
|
104
|
+
};
|
105
|
+
declare const SColl: SColl;
|
106
|
+
type ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;
|
107
|
+
type SPair = {
|
108
|
+
<L, R>(left: SConstant<L>, right: SConstant<R>): SConstant<[L, R], STupleType>;
|
109
|
+
<LD, RD, LT extends SType, RT extends SType>(left: SConstructor<LD, LT>, right: SConstructor<RD, RT>): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;
|
110
|
+
};
|
111
|
+
declare const SPair: SPair;
|
112
|
+
|
113
|
+
declare class SBoolType extends SPrimitiveType<boolean> {
|
114
|
+
get code(): 0x01;
|
115
|
+
toString(): string;
|
116
|
+
}
|
117
|
+
declare class SByteType extends SPrimitiveType<number> {
|
118
|
+
get code(): 0x02;
|
119
|
+
toString(): string;
|
120
|
+
}
|
121
|
+
declare class SShortType extends SPrimitiveType<number> {
|
122
|
+
get code(): 0x03;
|
123
|
+
toString(): string;
|
124
|
+
}
|
125
|
+
declare class SIntType extends SPrimitiveType<number> {
|
126
|
+
get code(): 0x04;
|
127
|
+
toString(): string;
|
128
|
+
}
|
129
|
+
declare class SLongType extends SPrimitiveType<BigIntInput, bigint> {
|
130
|
+
get code(): 0x05;
|
131
|
+
coerce(data: BigIntInput): bigint;
|
132
|
+
toString(): string;
|
133
|
+
}
|
134
|
+
declare class SBigIntType extends SPrimitiveType<string | bigint, bigint> {
|
135
|
+
get code(): number;
|
136
|
+
coerce(data: BigIntInput): bigint;
|
137
|
+
toString(): string;
|
138
|
+
}
|
139
|
+
declare class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {
|
140
|
+
get code(): 0x07;
|
141
|
+
coerce(data: ByteInput): Uint8Array;
|
142
|
+
toString(): string;
|
143
|
+
}
|
144
|
+
declare class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {
|
145
|
+
get code(): 0x08;
|
146
|
+
toString(): string;
|
147
|
+
}
|
148
|
+
|
149
|
+
declare function isColl(type: SType): type is SCollType;
|
150
|
+
declare function isTuple(type: SType): type is STupleType;
|
151
|
+
|
152
|
+
declare class SConstant<D = unknown, T extends SType = SType> {
|
153
|
+
#private;
|
154
|
+
constructor(type: T, data: D);
|
155
|
+
static from<D, T extends SType = SType>(bytes: BytesInput): SConstant<D, T>;
|
156
|
+
get type(): T;
|
157
|
+
get data(): D;
|
158
|
+
toBytes(): Uint8Array;
|
159
|
+
toHex(): string;
|
160
|
+
}
|
161
|
+
declare function parse<T>(bytes: BytesInput): T;
|
162
|
+
declare function parse<T>(bytes: BytesInput, mode: "strict"): T;
|
163
|
+
declare function parse<T>(bytes: BytesInput, mode: "safe"): T | undefined;
|
164
|
+
|
165
|
+
declare function serializeBox(box: Box<Amount>): SigmaWriter;
|
166
|
+
declare function serializeBox(box: Box<Amount>, writer: SigmaWriter): SigmaWriter;
|
167
|
+
declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaWriter, distinctTokenIds: string[]): SigmaWriter;
|
168
|
+
/**
|
169
|
+
* Estimates the byte size a box.
|
170
|
+
* @returns byte size of the box.
|
171
|
+
*/
|
172
|
+
declare function estimateBoxSize(box: Box<Amount> | BoxCandidate<Amount>, withValue?: Amount): number;
|
173
|
+
|
174
|
+
type MinimalUnsignedTransaction = {
|
175
|
+
inputs: readonly UnsignedInput[];
|
176
|
+
dataInputs: readonly DataInput[];
|
177
|
+
outputs: readonly BoxCandidate<Amount>[];
|
178
|
+
};
|
179
|
+
declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaWriter;
|
180
|
+
|
181
|
+
declare class DataSerializer {
|
182
|
+
static serialize(data: unknown, type: SType, writer: SigmaWriter): SigmaWriter;
|
183
|
+
static deserialize(type: SType, reader: SigmaReader): unknown;
|
184
|
+
}
|
185
|
+
|
186
|
+
declare class TypeSerializer {
|
187
|
+
static serialize(type: SType, writer: SigmaWriter): void;
|
188
|
+
static deserialize(r: SigmaReader): SType;
|
189
|
+
}
|
190
|
+
|
191
|
+
export { DataSerializer, MinimalUnsignedTransaction, SBigInt, SBigIntType, SBool, SBoolType, SByte, SByteType, SColl, SCollType, SConstant, SGenericType, SGroupElement, SGroupElementType, SInt, SIntType, SLong, SLongType, SMonomorphicType, SPair, SPrimitiveType, SShort, SShortType, SSigmaProp, SSigmaPropType, STupleType, SType, SUnit, SUnitType, TypeSerializer, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction };
|