@fleet-sdk/serializer 0.4.0 → 0.5.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @fleet-sdk/serializer
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 9dd0b55: Export `SigmaByteWriter` and `SigmaByteReader` classes
8
+ - Updated dependencies [6ecfd2e]
9
+ - @fleet-sdk/crypto@0.5.0
10
+
11
+ ## 0.4.1
12
+
13
+ ### Patch Changes
14
+
15
+ - d6ef248: Fix: export `decode()` function
16
+ - Updated dependencies [28e3467]
17
+ - @fleet-sdk/common@0.4.1
18
+ - @fleet-sdk/crypto@0.4.1
19
+
3
20
  ## 0.4.0
4
21
 
5
22
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { BytesInput } from '@fleet-sdk/crypto';
2
- import { HexString, Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
1
+ import { ByteInput as ByteInput$1, blake2b256, Coder } from '@fleet-sdk/crypto';
2
+ import { Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
3
3
 
4
- declare class SigmaReader {
4
+ declare class SigmaByteReader {
5
5
  #private;
6
6
  get isEmpty(): boolean;
7
- constructor(bytes: HexString | Uint8Array);
7
+ constructor(bytes: ByteInput$1);
8
8
  readBoolean(): boolean;
9
9
  readBits(length: number): ArrayLike<boolean>;
10
10
  readByte(): number;
@@ -16,22 +16,23 @@ declare class SigmaReader {
16
16
  readBigInt(): bigint;
17
17
  }
18
18
 
19
- declare class SigmaWriter {
19
+ declare class SigmaByteWriter {
20
20
  #private;
21
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;
22
+ constructor(length: number);
23
+ writeBoolean(value: boolean): SigmaByteWriter;
24
+ writeVLQ(value: number): SigmaByteWriter;
25
+ writeBigVLQ(value: bigint): SigmaByteWriter;
26
+ writeShort(value: number): SigmaByteWriter;
27
+ writeInt(value: number): SigmaByteWriter;
28
+ writeLong(value: bigint): SigmaByteWriter;
29
+ write(byte: number): SigmaByteWriter;
30
+ writeBytes(bytes: ArrayLike<number>): SigmaByteWriter;
31
+ writeHex(bytesHex: string): SigmaByteWriter;
32
+ writeBits(bits: ArrayLike<boolean>): SigmaByteWriter;
33
+ writeBigInt(value: bigint): SigmaByteWriter;
34
+ writeChecksum(length?: number, hashFn?: typeof blake2b256): SigmaByteWriter;
35
+ encode<T>(coder: Coder<Uint8Array, T>): T;
35
36
  toBytes(): Uint8Array;
36
37
  }
37
38
 
@@ -152,22 +153,24 @@ declare function isTuple(type: SType): type is STupleType;
152
153
  declare class SConstant<D = unknown, T extends SType = SType> {
153
154
  #private;
154
155
  constructor(type: T, data: D);
155
- static from<D, T extends SType = SType>(bytes: BytesInput): SConstant<D, T>;
156
+ static from<D, T extends SType = SType>(bytes: ByteInput$1): SConstant<D, T>;
156
157
  get type(): T;
157
158
  get data(): D;
158
159
  toBytes(): Uint8Array;
159
160
  toHex(): string;
160
161
  }
162
+ declare function decode<T>(value: ByteInput$1 | undefined): T | undefined;
163
+ declare function decode<T, K>(value: ByteInput$1 | undefined, coder: (input: T) => K): K | undefined;
161
164
  /** @deprecated use `decode` instead */
162
- declare function parse<T>(constant: BytesInput): T;
165
+ declare function parse<T>(constant: ByteInput$1): T;
163
166
  /** @deprecated use `decode` instead */
164
- declare function parse<T>(constant: BytesInput, mode: "strict"): T;
167
+ declare function parse<T>(constant: ByteInput$1, mode: "strict"): T;
165
168
  /** @deprecated use `decode` instead */
166
- declare function parse<T>(constant: BytesInput | undefined, mode: "safe"): T | undefined;
169
+ declare function parse<T>(constant: ByteInput$1 | undefined, mode: "safe"): T | undefined;
167
170
 
168
- declare function serializeBox(box: Box<Amount>): SigmaWriter;
169
- declare function serializeBox(box: Box<Amount>, writer: SigmaWriter): SigmaWriter;
170
- declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaWriter, distinctTokenIds: string[]): SigmaWriter;
171
+ declare function serializeBox(box: Box<Amount>): SigmaByteWriter;
172
+ declare function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;
173
+ declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaByteWriter, distinctTokenIds: string[]): SigmaByteWriter;
171
174
  /**
172
175
  * Estimates the byte size a box.
173
176
  * @returns byte size of the box.
@@ -179,16 +182,16 @@ type MinimalUnsignedTransaction = {
179
182
  dataInputs: readonly DataInput[];
180
183
  outputs: readonly BoxCandidate<Amount>[];
181
184
  };
182
- declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaWriter;
185
+ declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaByteWriter;
183
186
 
184
- declare class DataSerializer {
185
- static serialize(data: unknown, type: SType, writer: SigmaWriter): SigmaWriter;
186
- static deserialize(type: SType, reader: SigmaReader): unknown;
187
- }
187
+ declare const dataSerializer: {
188
+ serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter;
189
+ deserialize(type: SType, reader: SigmaByteReader): unknown;
190
+ };
188
191
 
189
- declare class TypeSerializer {
190
- static serialize(type: SType, writer: SigmaWriter): void;
191
- static deserialize(r: SigmaReader): SType;
192
- }
192
+ declare const typeSerializer: {
193
+ serialize(type: SType, writer: SigmaByteWriter): void;
194
+ deserialize(r: SigmaByteReader): SType;
195
+ };
193
196
 
194
- 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 };
197
+ export { type 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, SigmaByteReader, SigmaByteWriter, dataSerializer, decode, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction, typeSerializer };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { BytesInput } from '@fleet-sdk/crypto';
2
- import { HexString, Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
1
+ import { ByteInput as ByteInput$1, blake2b256, Coder } from '@fleet-sdk/crypto';
2
+ import { Box, Amount, BoxCandidate, UnsignedInput, DataInput } from '@fleet-sdk/common';
3
3
 
4
- declare class SigmaReader {
4
+ declare class SigmaByteReader {
5
5
  #private;
6
6
  get isEmpty(): boolean;
7
- constructor(bytes: HexString | Uint8Array);
7
+ constructor(bytes: ByteInput$1);
8
8
  readBoolean(): boolean;
9
9
  readBits(length: number): ArrayLike<boolean>;
10
10
  readByte(): number;
@@ -16,22 +16,23 @@ declare class SigmaReader {
16
16
  readBigInt(): bigint;
17
17
  }
18
18
 
19
- declare class SigmaWriter {
19
+ declare class SigmaByteWriter {
20
20
  #private;
21
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;
22
+ constructor(length: number);
23
+ writeBoolean(value: boolean): SigmaByteWriter;
24
+ writeVLQ(value: number): SigmaByteWriter;
25
+ writeBigVLQ(value: bigint): SigmaByteWriter;
26
+ writeShort(value: number): SigmaByteWriter;
27
+ writeInt(value: number): SigmaByteWriter;
28
+ writeLong(value: bigint): SigmaByteWriter;
29
+ write(byte: number): SigmaByteWriter;
30
+ writeBytes(bytes: ArrayLike<number>): SigmaByteWriter;
31
+ writeHex(bytesHex: string): SigmaByteWriter;
32
+ writeBits(bits: ArrayLike<boolean>): SigmaByteWriter;
33
+ writeBigInt(value: bigint): SigmaByteWriter;
34
+ writeChecksum(length?: number, hashFn?: typeof blake2b256): SigmaByteWriter;
35
+ encode<T>(coder: Coder<Uint8Array, T>): T;
35
36
  toBytes(): Uint8Array;
36
37
  }
37
38
 
@@ -152,22 +153,24 @@ declare function isTuple(type: SType): type is STupleType;
152
153
  declare class SConstant<D = unknown, T extends SType = SType> {
153
154
  #private;
154
155
  constructor(type: T, data: D);
155
- static from<D, T extends SType = SType>(bytes: BytesInput): SConstant<D, T>;
156
+ static from<D, T extends SType = SType>(bytes: ByteInput$1): SConstant<D, T>;
156
157
  get type(): T;
157
158
  get data(): D;
158
159
  toBytes(): Uint8Array;
159
160
  toHex(): string;
160
161
  }
162
+ declare function decode<T>(value: ByteInput$1 | undefined): T | undefined;
163
+ declare function decode<T, K>(value: ByteInput$1 | undefined, coder: (input: T) => K): K | undefined;
161
164
  /** @deprecated use `decode` instead */
162
- declare function parse<T>(constant: BytesInput): T;
165
+ declare function parse<T>(constant: ByteInput$1): T;
163
166
  /** @deprecated use `decode` instead */
164
- declare function parse<T>(constant: BytesInput, mode: "strict"): T;
167
+ declare function parse<T>(constant: ByteInput$1, mode: "strict"): T;
165
168
  /** @deprecated use `decode` instead */
166
- declare function parse<T>(constant: BytesInput | undefined, mode: "safe"): T | undefined;
169
+ declare function parse<T>(constant: ByteInput$1 | undefined, mode: "safe"): T | undefined;
167
170
 
168
- declare function serializeBox(box: Box<Amount>): SigmaWriter;
169
- declare function serializeBox(box: Box<Amount>, writer: SigmaWriter): SigmaWriter;
170
- declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaWriter, distinctTokenIds: string[]): SigmaWriter;
171
+ declare function serializeBox(box: Box<Amount>): SigmaByteWriter;
172
+ declare function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;
173
+ declare function serializeBox(box: BoxCandidate<Amount>, writer: SigmaByteWriter, distinctTokenIds: string[]): SigmaByteWriter;
171
174
  /**
172
175
  * Estimates the byte size a box.
173
176
  * @returns byte size of the box.
@@ -179,16 +182,16 @@ type MinimalUnsignedTransaction = {
179
182
  dataInputs: readonly DataInput[];
180
183
  outputs: readonly BoxCandidate<Amount>[];
181
184
  };
182
- declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaWriter;
185
+ declare function serializeTransaction(transaction: MinimalUnsignedTransaction): SigmaByteWriter;
183
186
 
184
- declare class DataSerializer {
185
- static serialize(data: unknown, type: SType, writer: SigmaWriter): SigmaWriter;
186
- static deserialize(type: SType, reader: SigmaReader): unknown;
187
- }
187
+ declare const dataSerializer: {
188
+ serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter;
189
+ deserialize(type: SType, reader: SigmaByteReader): unknown;
190
+ };
188
191
 
189
- declare class TypeSerializer {
190
- static serialize(type: SType, writer: SigmaWriter): void;
191
- static deserialize(r: SigmaReader): SType;
192
- }
192
+ declare const typeSerializer: {
193
+ serialize(type: SType, writer: SigmaByteWriter): void;
194
+ deserialize(r: SigmaByteReader): SType;
195
+ };
193
196
 
194
- 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 };
197
+ export { type 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, SigmaByteReader, SigmaByteWriter, dataSerializer, decode, estimateBoxSize, estimateVLQSize, isColl, isTuple, parse, serializeBox, serializeTransaction, typeSerializer };