@fleet-sdk/serializer 0.5.0 → 0.7.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,20 @@
1
1
  # @fleet-sdk/serializer
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9fceb6f: **🚨 BREAKING CHANGE**: `decode` function now returns `SConstant` instead of data directly
8
+ - 62025c4: Introduce `stypeof` utility function
9
+
10
+ ## 0.6.4
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [504974e]
15
+ - @fleet-sdk/common@0.6.4
16
+ - @fleet-sdk/crypto@0.6.4
17
+
3
18
  ## 0.5.0
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -159,8 +159,23 @@ declare class SConstant<D = unknown, T extends SType = SType> {
159
159
  toBytes(): Uint8Array;
160
160
  toHex(): string;
161
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;
162
+ /**
163
+ * Decodes a byte input into a Sigma constant of type `SConstant<D, T>`.
164
+ *
165
+ * @template D - The data type of the constant.
166
+ * @template T - The type of the constant.
167
+ * @param value - The value to decode.
168
+ * @returns The decoded constant or `undefined` if the value is `undefined` or decoding fails.
169
+ */
170
+ declare function decode<D = unknown, T extends SType = SType>(value?: ByteInput$1): SConstant<D, T> | undefined;
171
+ /**
172
+ * Returns the `SType` of the given value.
173
+ *
174
+ * @param value - The value to check the SType of.
175
+ * @returns The SType of the value, or `undefined` if the value is `undefined` or
176
+ * deserialization fails.
177
+ */
178
+ declare function stypeof(value?: ByteInput$1): SType | undefined;
164
179
  /** @deprecated use `decode` instead */
165
180
  declare function parse<T>(constant: ByteInput$1): T;
166
181
  /** @deprecated use `decode` instead */
@@ -194,4 +209,4 @@ declare const typeSerializer: {
194
209
  deserialize(r: SigmaByteReader): SType;
195
210
  };
196
211
 
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 };
212
+ 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, stypeof, typeSerializer };
package/dist/index.d.ts CHANGED
@@ -159,8 +159,23 @@ declare class SConstant<D = unknown, T extends SType = SType> {
159
159
  toBytes(): Uint8Array;
160
160
  toHex(): string;
161
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;
162
+ /**
163
+ * Decodes a byte input into a Sigma constant of type `SConstant<D, T>`.
164
+ *
165
+ * @template D - The data type of the constant.
166
+ * @template T - The type of the constant.
167
+ * @param value - The value to decode.
168
+ * @returns The decoded constant or `undefined` if the value is `undefined` or decoding fails.
169
+ */
170
+ declare function decode<D = unknown, T extends SType = SType>(value?: ByteInput$1): SConstant<D, T> | undefined;
171
+ /**
172
+ * Returns the `SType` of the given value.
173
+ *
174
+ * @param value - The value to check the SType of.
175
+ * @returns The SType of the value, or `undefined` if the value is `undefined` or
176
+ * deserialization fails.
177
+ */
178
+ declare function stypeof(value?: ByteInput$1): SType | undefined;
164
179
  /** @deprecated use `decode` instead */
165
180
  declare function parse<T>(constant: ByteInput$1): T;
166
181
  /** @deprecated use `decode` instead */
@@ -194,4 +209,4 @@ declare const typeSerializer: {
194
209
  deserialize(r: SigmaByteReader): SType;
195
210
  };
196
211
 
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 };
212
+ 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, stypeof, typeSerializer };
package/dist/index.js CHANGED
@@ -37,9 +37,7 @@ function negateAndMask(value) {
37
37
  function writeVLQ(writer, value) {
38
38
  if (value === 0) return writer.write(0);
39
39
  if (value < 0) {
40
- throw new RangeError(
41
- "Variable Length Quantity not supported for negative numbers."
42
- );
40
+ throw new RangeError("Variable Length Quantity not supported for negative numbers.");
43
41
  }
44
42
  let val = value;
45
43
  do {
@@ -67,9 +65,7 @@ function readVLQ(reader) {
67
65
  function writeBigVLQ(writer, value) {
68
66
  if (value === common._0n) return writer.write(0);
69
67
  if (value < common._0n) {
70
- throw new RangeError(
71
- "Variable Length Quantity not supported for negative numbers"
72
- );
68
+ throw new RangeError("Variable Length Quantity not supported for negative numbers");
73
69
  }
74
70
  let val = value;
75
71
  do {
@@ -482,10 +478,7 @@ function genericProxy(ctor, handler) {
482
478
  }
483
479
  var SByte = monoProxy(SByteType, descriptors.byte);
484
480
  var SBool = monoProxy(SBoolType, descriptors.bool);
485
- var SShort = monoProxy(
486
- SShortType,
487
- descriptors.short
488
- );
481
+ var SShort = monoProxy(SShortType, descriptors.short);
489
482
  var SInt = monoProxy(SIntType, descriptors.int);
490
483
  var SLong = monoProxy(
491
484
  SLongType,
@@ -495,37 +488,31 @@ var SBigInt = monoProxy(
495
488
  SBigIntType,
496
489
  descriptors.bigInt
497
490
  );
498
- var SGroupElement = monoProxy(SGroupElementType, descriptors.groupElement);
491
+ var SGroupElement = monoProxy(
492
+ SGroupElementType,
493
+ descriptors.groupElement
494
+ );
499
495
  var SSigmaProp = monoProxy(
500
496
  SSigmaPropType,
501
497
  descriptors.sigmaProp
502
498
  );
503
499
  var SUnit = monoProxy(SUnitType, void 0, true);
504
- var SColl = genericProxy(
505
- SCollType,
506
- (target, _, args) => {
507
- const [type, elements] = args;
508
- const elementsType = type();
509
- if (!elements) return () => new target(elementsType);
510
- return new SConstant(new target(elementsType), elements);
500
+ var SColl = genericProxy(SCollType, (target, _, args) => {
501
+ const [type, elements] = args;
502
+ const elementsType = type();
503
+ if (!elements) return () => new target(elementsType);
504
+ return new SConstant(new target(elementsType), elements);
505
+ });
506
+ var SPair = genericProxy(STupleType, (target, _, args) => {
507
+ const [left, right] = args;
508
+ if (typeof left === "function" && typeof right === "function") {
509
+ return () => new target([left(), right()]);
511
510
  }
512
- );
513
- var SPair = genericProxy(
514
- STupleType,
515
- (target, _, args) => {
516
- const [left, right] = args;
517
- if (typeof left === "function" && typeof right === "function") {
518
- return () => new target([left(), right()]);
519
- }
520
- if (left instanceof SConstant && right instanceof SConstant) {
521
- return new SConstant(new target([left.type, right.type]), [
522
- left.data,
523
- right.data
524
- ]);
525
- }
526
- throw new Error("Invalid tuple declaration.");
511
+ if (left instanceof SConstant && right instanceof SConstant) {
512
+ return new SConstant(new target([left.type, right.type]), [left.data, right.data]);
527
513
  }
528
- );
514
+ throw new Error("Invalid tuple declaration.");
515
+ });
529
516
 
530
517
  // src/serializers/dataSerializer.ts
531
518
  var GROUP_ELEMENT_LENGTH = 33;
@@ -554,9 +541,7 @@ var dataSerializer = {
554
541
  writer.write(PROVE_DLOG_OP);
555
542
  return dataSerializer.serialize(node.data, node.type, writer);
556
543
  }
557
- throw Error(
558
- "Serialization error: SigmaProp operation not implemented."
559
- );
544
+ throw Error("Serialization error: SigmaProp operation not implemented.");
560
545
  }
561
546
  }
562
547
  }
@@ -567,10 +552,7 @@ var dataSerializer = {
567
552
  `SColl[Byte] expected an UInt8Array, got ${typeof data}.`
568
553
  );
569
554
  } else {
570
- common.assert(
571
- Array.isArray(data),
572
- `SColl expected an array, got ${typeof data}.`
573
- );
555
+ common.assert(Array.isArray(data), `SColl expected an array, got ${typeof data}.`);
574
556
  }
575
557
  writer.writeVLQ(data.length);
576
558
  switch (type.elementsType.code) {
@@ -656,9 +638,7 @@ var dataSerializer = {
656
638
  return void 0;
657
639
  }
658
640
  }
659
- throw new Error(
660
- `Parsing error: '0x${type.code.toString(16)}' type not implemented.`
661
- );
641
+ throw new Error(`Parsing error: '0x${type.code.toString(16)}' type not implemented.`);
662
642
  }
663
643
  };
664
644
  var typeSerializer = {
@@ -669,9 +649,7 @@ var typeSerializer = {
669
649
  writer.write(type.code);
670
650
  } else if (isColl(type)) {
671
651
  if (type.elementsType.embeddable) {
672
- writer.write(
673
- descriptors.coll.simpleCollTypeCode + type.elementsType.code
674
- );
652
+ writer.write(descriptors.coll.simpleCollTypeCode + type.elementsType.code);
675
653
  } else if (isColl(type.elementsType)) {
676
654
  const nestedColl = type.elementsType;
677
655
  if (nestedColl.elementsType.embeddable) {
@@ -733,10 +711,7 @@ var typeSerializer = {
733
711
  },
734
712
  deserialize(r) {
735
713
  const byte = r.readByte();
736
- common.assert(
737
- byte > 0,
738
- `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`
739
- );
714
+ common.assert(byte > 0, `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`);
740
715
  if (byte < descriptors.tuple.genericTupleTypeCode) {
741
716
  const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);
742
717
  const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);
@@ -819,11 +794,21 @@ var SConstant = class _SConstant {
819
794
  return crypto.hex.encode(this.toBytes());
820
795
  }
821
796
  };
822
- function decode(value, coder) {
823
- if (common.isUndefined(value)) return;
824
- const data = parse(value, "safe");
825
- if (common.isUndefined(data)) return;
826
- return coder ? coder(data) : data;
797
+ function decode(value) {
798
+ if (value === void 0) return;
799
+ try {
800
+ return SConstant.from(value);
801
+ } catch {
802
+ return;
803
+ }
804
+ }
805
+ function stypeof(value) {
806
+ if (!value) return;
807
+ try {
808
+ return typeSerializer.deserialize(new SigmaByteReader(value));
809
+ } catch {
810
+ return;
811
+ }
827
812
  }
828
813
  function parse(constant, mode = "strict") {
829
814
  if (mode === "strict") return SConstant.from(constant ?? "").data;
@@ -913,9 +898,7 @@ function serializeTransaction(transaction) {
913
898
  writer.writeVLQ(distinctTokenIds.length);
914
899
  distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));
915
900
  writer.writeVLQ(transaction.outputs.length);
916
- transaction.outputs.map(
917
- (output) => serializeBox(output, writer, distinctTokenIds)
918
- );
901
+ transaction.outputs.map((output) => serializeBox(output, writer, distinctTokenIds));
919
902
  return writer;
920
903
  }
921
904
  function writeInput(writer, input) {
@@ -943,9 +926,7 @@ function writeExtension(writer, extension) {
943
926
  }
944
927
  function getDistinctTokenIds(outputs) {
945
928
  const tokenIds = /* @__PURE__ */ new Set();
946
- outputs.flatMap(
947
- (output) => output.assets.map((asset) => tokenIds.add(asset.tokenId))
948
- );
929
+ outputs.flatMap((output) => output.assets.map((asset) => tokenIds.add(asset.tokenId)));
949
930
  return Array.from(tokenIds);
950
931
  }
951
932
 
@@ -987,6 +968,7 @@ exports.isTuple = isTuple;
987
968
  exports.parse = parse;
988
969
  exports.serializeBox = serializeBox;
989
970
  exports.serializeTransaction = serializeTransaction;
971
+ exports.stypeof = stypeof;
990
972
  exports.typeSerializer = typeSerializer;
991
- //# sourceMappingURL=out.js.map
973
+ //# sourceMappingURL=index.js.map
992
974
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/coders/sigmaByteReader.ts","../src/coders/bigint.ts","../src/coders/vlq.ts","../src/coders/zigZag.ts","../src/coders/sigmaByteWriter.ts","../src/sigmaConstant.ts","../src/serializers/dataSerializer.ts","../src/types/base.ts","../src/types/primitives.ts","../src/types/monomorphics.ts","../src/types/descriptors.ts","../src/types/generics.ts","../src/types/constructors.ts","../src/serializers/typeSerializer.ts","../src/serializers/boxSerializer.ts","../src/serializers/transactionSerializer.ts"],"names":["hex","_0n","assert","ensureBigInt","isEmpty","first","isUndefined","isDefined"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAyB,aAAa,WAAW;;;ACDjD,SAAS,KAAK,aAAa;AAOpB,SAAS,YAAYA,MAAqB;AAE/C,QAAM,QAAQ,OAAOA,KAAI,SAAS,IAAI,MAAMA,IAAG,KAAK,KAAKA,IAAG,EAAE;AAC9D,QAAM,WAAW,OAAO,SAASA,KAAI,MAAM,GAAG,CAAC,GAAG,EAAE;AACpD,MAAI,MAAO,SAAU,QAAO,CAAC,cAAc,KAAK;AAEhD,SAAO;AACT;AAOO,SAAS,YAAY,OAAuB;AAGjD,QAAM,WAAW,SAAS;AAC1B,MAAIA,QAAO,WAAW,QAAQ,cAAc,KAAK,GAAG,SAAS,EAAE;AAC/D,MAAIA,KAAI,SAAS,EAAG,CAAAA,OAAM,IAAIA,IAAG;AAEjC,MAAI,YAAY,MAAO,OAAO,SAASA,KAAI,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG;AAC3D,WAAO,KAAKA,IAAG;AAAA,EACjB;AAEA,SAAOA;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exToBigInt } from \"./bigint\";\nimport { readBigVLQ, readVLQ } from \"./vlq\";\nimport { zigZagDecode, zigZagDecodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteReader {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get isEmpty(): boolean {\n return isEmpty(this.#bytes);\n }\n\n constructor(bytes: ByteInput) {\n this.#bytes = ensureBytes(bytes);\n this.#cursor = 0;\n }\n\n public readBoolean(): boolean {\n return this.readByte() === 0x01;\n }\n\n public readBits(length: number): ArrayLike<boolean> {\n const bits = new Array<boolean>(length);\n let bitOffset = 0;\n\n for (let i = 0; i < length; i++) {\n const bit = (this.#bytes[this.#cursor] >> bitOffset++) & 1;\n bits[i] = bit === 1;\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return bits;\n }\n\n public readByte(): number {\n return this.#bytes[this.#cursor++];\n }\n\n public readBytes(length: number): Uint8Array {\n return this.#bytes.subarray(this.#cursor, (this.#cursor += length));\n }\n\n public readVlq(): number {\n return readVLQ(this);\n }\n\n public readShort(): number {\n return Number(zigZagDecode(readVLQ(this)));\n }\n\n public readInt(): number {\n return Number(this.readLong());\n }\n\n public readLong(): bigint {\n return zigZagDecodeBigInt(readBigVLQ(this));\n }\n\n public readBigInt(): bigint {\n const len = readVLQ(this);\n return hexToBigInt(hex.encode(this.readBytes(len)));\n }\n}\n","import { _0n, first } from \"@fleet-sdk/common\";\n\n/**\n * Converts a hex string to bigint.\n * @param hex The hex string to be converted.\n * @returns The bigint value represented by the hex string.\n */\nexport function hexToBigInt(hex: string): bigint {\n // https://coolaj86.com/articles/convert-hex-to-decimal-with-js-bigints/\n const value = BigInt(hex.length % 2 ? `0x0${hex}` : `0x${hex}`);\n const highByte = Number.parseInt(hex.slice(0, 2), 16);\n if (0x80 & highByte) return -negateAndMask(value);\n\n return value;\n}\n\n/**\n * Serializes a `BigInt` to a hex string\n * @param value The bigint value to be serialized\n * @returns Hex representation for the provided `number`.\n */\nexport function bigIntToHex(value: bigint): string {\n // implementation inspired on\n // https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/\n const positive = value >= _0n;\n let hex = (positive ? value : negateAndMask(value)).toString(16);\n if (hex.length % 2) hex = `0${hex}`;\n\n if (positive && 0x80 & Number.parseInt(hex.slice(0, 2), 16)) {\n return `00${hex}`;\n }\n\n return hex;\n}\n\n/**\n * Returns the two’s complement of a bigint value.\n * @param value The bigint value to negate.\n * @returns The two’s complement of `number` as a bigint.\n */\nexport function negateAndMask(value: bigint): bigint {\n let val = value;\n const negative = val < _0n;\n if (negative) val = -val; // turn into a positive number\n\n const bits = val.toString(2);\n let len = bits.length; // convert to binary\n const mod = len % 8;\n\n if (mod > 0) {\n len += 8 - mod;\n } else if (negative && first(bits) === \"1\" && bits.indexOf(\"1\", 1) !== -1) {\n len += 8;\n }\n\n const mask = (1n << BigInt(len)) - 1n; // create a mask\n return (~val & mask) + 1n; // invert bits, mask it, and add one\n}\n","import { _0n, _127n, _128n, _7n, ensureBigInt } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader } from \"./sigmaByteReader\";\nimport type { SigmaByteWriter } from \"./sigmaByteWriter\";\n\n/**\n * A **variable-length quantity (VLQ)** is a universal code that uses an arbitrary number\n * of binary octets (eight-bit bytes) to represent an arbitrarily large integer. A VLQ\n * is essentially a base-128 representation of an unsigned integer with the addition of\n * the eighth bit to mark continuation of bytes. VLQ is identical to LEB128 except in\n * endianness. See the example below.\n */\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeVLQ(\n writer: SigmaByteWriter,\n value: number\n): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n if (value === 0) return writer.write(0);\n if (value < 0) {\n throw new RangeError(\n \"Variable Length Quantity not supported for negative numbers.\"\n );\n }\n\n let val = value;\n do {\n let lower7bits = val & 0x7f;\n val >>= 7;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readVLQ(reader: SigmaByteReader): number {\n if (reader.isEmpty) {\n return 0;\n }\n\n let value = 0;\n let shift = 0;\n let lower7bits = 0;\n\n do {\n lower7bits = reader.readByte();\n value |= (lower7bits & 0x7f) << shift;\n shift += 7;\n } while ((lower7bits & 0x80) !== 0);\n\n return value;\n}\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Big integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeBigVLQ(\n writer: SigmaByteWriter,\n value: bigint\n): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n\n if (value === _0n) return writer.write(0);\n if (value < _0n) {\n throw new RangeError(\n \"Variable Length Quantity not supported for negative numbers\"\n );\n }\n\n let val = value;\n do {\n let lower7bits = Number(val & _127n);\n val >>= _7n;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned big integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readBigVLQ(reader: SigmaByteReader): bigint {\n if (reader.isEmpty) return _0n;\n\n let value = _0n;\n let shift = _0n;\n let lower7bits = _0n;\n\n do {\n lower7bits = BigInt(reader.readByte());\n value |= (lower7bits & _127n) << shift;\n shift += _7n;\n } while ((lower7bits & _128n) !== _0n);\n\n return value;\n}\n\n/**\n * Estimates the byte size of a given unsigned integer.\n * @param value: the value to be evaluated.\n * @returns the byte size of the value.\n */\nexport function estimateVLQSize(value: number | bigint | string): number {\n let size = 0;\n let val = value;\n if (typeof val === \"number\") {\n do {\n size++;\n val = Math.floor(val / 128);\n } while (val > 0);\n\n return size;\n }\n\n val = ensureBigInt(val);\n do {\n size++;\n val /= _128n;\n } while (val > _0n);\n\n return size;\n}\n","import { _1n, _63n } from \"@fleet-sdk/common\";\n\n/**\n * ZigZag encoding maps signed integers to unsigned integers so that numbers\n * with a small absolute value (for instance, -1) have a small variant encoded\n * value too. It does this in a way that \"zig-zags\" back and forth through the\n * positive and negative integers, so that -1 is encoded as 1, 1 is encoded as 2,\n * -2 is encoded as 3, and so on.\n * @see https://developers.google.com/protocol-buffers/docs/encoding#types\n */\n\n/**\n * Encode a signed integer.\n * @param input Signed integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncode(input: number): number {\n return (input << 1) ^ (input >> 63);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed integer\n */\nexport function zigZagDecode(input: number): number {\n return (input >> 1) ^ -(input & 1);\n}\n\n/**\n * Encode a signed big integer.\n * @param input Signed big integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncodeBigInt(input: bigint): bigint {\n return (input << _1n) ^ (input >> _63n);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed big integer\n */\nexport function zigZagDecodeBigInt(input: bigint): bigint {\n return (input >> _1n) ^ -(input & _1n);\n}\n","import { blake2b256, type Coder, hex } from \"@fleet-sdk/crypto\";\nimport { bigIntToHex } from \"./bigint\";\nimport { writeBigVLQ, writeVLQ } from \"./vlq\";\nimport { zigZagEncode, zigZagEncodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteWriter {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get length() {\n return this.#cursor;\n }\n\n constructor(length: number) {\n this.#bytes = new Uint8Array(length);\n this.#cursor = 0;\n }\n\n public writeBoolean(value: boolean): SigmaByteWriter {\n this.write(value === true ? 0x01 : 0x00);\n\n return this;\n }\n\n public writeVLQ(value: number): SigmaByteWriter {\n return writeVLQ(this, value);\n }\n\n public writeBigVLQ(value: bigint): SigmaByteWriter {\n return writeBigVLQ(this, value);\n }\n\n public writeShort(value: number): SigmaByteWriter {\n this.writeVLQ(zigZagEncode(value));\n return this;\n }\n\n public writeInt(value: number): SigmaByteWriter {\n this.writeLong(BigInt(value));\n return this;\n }\n\n public writeLong(value: bigint): SigmaByteWriter {\n this.writeBigVLQ(zigZagEncodeBigInt(value));\n return this;\n }\n\n public write(byte: number): SigmaByteWriter {\n this.#bytes[this.#cursor++] = byte;\n return this;\n }\n\n public writeBytes(bytes: ArrayLike<number>): SigmaByteWriter {\n this.#bytes.set(bytes, this.#cursor);\n this.#cursor += bytes.length;\n return this;\n }\n\n public writeHex(bytesHex: string): SigmaByteWriter {\n return this.writeBytes(hex.decode(bytesHex));\n }\n\n public writeBits(bits: ArrayLike<boolean>): SigmaByteWriter {\n let bitOffset = 0;\n\n for (let i = 0; i < bits.length; i++) {\n if (bits[i]) {\n this.#bytes[this.#cursor] |= 1 << bitOffset++;\n } else {\n this.#bytes[this.#cursor] &= ~(1 << bitOffset++);\n }\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return this;\n }\n\n public writeBigInt(value: bigint): SigmaByteWriter {\n const hex = bigIntToHex(value);\n return this.writeVLQ(hex.length / 2).writeHex(hex);\n }\n\n public writeChecksum(length = 4, hashFn = blake2b256): SigmaByteWriter {\n const hash = hashFn(this.toBytes());\n return this.writeBytes(length ? hash.subarray(0, length) : hash);\n }\n\n public encode<T>(coder: Coder<Uint8Array, T>): T {\n return coder.encode(this.toBytes());\n }\n\n public toBytes(): Uint8Array {\n if (this.#cursor === this.#bytes.length) return this.#bytes;\n return this.#bytes.subarray(0, this.#cursor);\n }\n}\n","import { assert, isUndefined } from \"@fleet-sdk/common\";\nimport { type ByteInput, hex } from \"@fleet-sdk/crypto\";\nimport { SigmaByteReader, SigmaByteWriter } from \"./coders\";\nimport { dataSerializer } from \"./serializers/dataSerializer\";\nimport { typeSerializer } from \"./serializers/typeSerializer\";\nimport type { SType } from \"./types\";\n\nexport const MAX_CONSTANT_LENGTH = 4096;\n\nexport class SConstant<D = unknown, T extends SType = SType> {\n readonly #type: T;\n readonly #data: D;\n\n constructor(type: T, data: D) {\n this.#type = type;\n this.#data = type.coerce(data) as D;\n }\n\n static from<D, T extends SType = SType>(bytes: ByteInput): SConstant<D, T> {\n assert(bytes.length > 0, \"Empty constant bytes.\");\n\n const reader = new SigmaByteReader(bytes);\n const type = typeSerializer.deserialize(reader);\n const data = dataSerializer.deserialize(type, reader);\n\n return new SConstant(type as T, data as D);\n }\n\n get type(): T {\n return this.#type;\n }\n\n get data(): D {\n return this.#data;\n }\n\n toBytes(): Uint8Array {\n const writer = new SigmaByteWriter(MAX_CONSTANT_LENGTH);\n typeSerializer.serialize(this.type, writer);\n dataSerializer.serialize(this.data, this.type, writer);\n\n return writer.toBytes();\n }\n\n toHex(): string {\n return hex.encode(this.toBytes());\n }\n}\n\nexport function decode<T>(value: ByteInput | undefined): T | undefined;\nexport function decode<T, K>(\n value: ByteInput | undefined,\n coder: (input: T) => K\n): K | undefined;\nexport function decode<T, K>(\n value: ByteInput | undefined,\n coder?: (input: T) => K\n): T | K | undefined {\n if (isUndefined(value)) return;\n const data = parse<T>(value, \"safe\");\n if (isUndefined(data)) return;\n\n return coder ? coder(data) : data;\n}\n\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput, mode: \"strict\"): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"safe\"\n): T | undefined;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"strict\" | \"safe\" = \"strict\"\n) {\n if (mode === \"strict\") return SConstant.from<T>(constant ?? \"\").data;\n if (!constant) return;\n\n try {\n return SConstant.from<T>(constant).data;\n } catch {\n return;\n }\n}\n","import { assert } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport {\n isColl,\n isTuple,\n type SCollType,\n type STupleType,\n type SType\n} from \"../types\";\nimport { descriptors } from \"../types/descriptors\";\n\nconst GROUP_ELEMENT_LENGTH = 33;\nconst PROVE_DLOG_OP = 0xcd;\n\nexport const dataSerializer = {\n serialize(\n data: unknown,\n type: SType,\n writer: SigmaByteWriter\n ): SigmaByteWriter {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return writer.writeBoolean(data as boolean);\n case descriptors.byte.code:\n return writer.write(data as number);\n case descriptors.short.code:\n return writer.writeShort(data as number);\n case descriptors.int.code:\n return writer.writeInt(data as number);\n case descriptors.long.code:\n return writer.writeLong(data as bigint);\n case descriptors.bigInt.code:\n return writer.writeBigInt(data as bigint);\n case descriptors.groupElement.code:\n return writer.writeBytes(data as Uint8Array);\n case descriptors.sigmaProp.code: {\n const node = data as SConstant<SConstant<Uint8Array>>;\n if (node.type === descriptors.groupElement) {\n writer.write(PROVE_DLOG_OP);\n return dataSerializer.serialize(node.data, node.type, writer);\n }\n\n throw Error(\n \"Serialization error: SigmaProp operation not implemented.\"\n );\n }\n }\n }\n\n if (isColl(type)) {\n if (type.elementsType.code === descriptors.byte.code) {\n assert(\n data instanceof Uint8Array,\n `SColl[Byte] expected an UInt8Array, got ${typeof data}.`\n );\n } else {\n assert(\n Array.isArray(data),\n `SColl expected an array, got ${typeof data}.`\n );\n }\n\n writer.writeVLQ(data.length);\n switch (type.elementsType.code) {\n case descriptors.bool.code: {\n return writer.writeBits(data as boolean[]);\n }\n case descriptors.byte.code: {\n return writer.writeBytes(data as Uint8Array);\n }\n default: {\n for (let i = 0; i < data.length; i++) {\n dataSerializer.serialize(data[i], type.elementsType, writer);\n }\n\n return writer;\n }\n }\n }\n\n if (isTuple(type)) {\n assert(\n Array.isArray(data),\n `STupleType serialization expected an array, got ${typeof data}.`\n );\n\n const len = type.elementsType.length;\n for (let i = 0; i < len; i++) {\n dataSerializer.serialize(data[i], type.elementsType[i], writer);\n }\n\n return writer;\n }\n\n if (type.code === descriptors.unit.code) return writer;\n\n throw Error(\n `Serialization error: '0x${type.code.toString(16)}' type not implemented.`\n );\n },\n\n deserialize(type: SType, reader: SigmaByteReader): unknown {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return reader.readBoolean();\n case descriptors.byte.code:\n return reader.readByte();\n case descriptors.short.code:\n return reader.readShort();\n case descriptors.int.code:\n return reader.readInt();\n case descriptors.long.code:\n return reader.readLong();\n case descriptors.bigInt.code:\n return reader.readBigInt();\n case descriptors.groupElement.code:\n return reader.readBytes(GROUP_ELEMENT_LENGTH);\n case descriptors.sigmaProp.code: {\n if (reader.readByte() === PROVE_DLOG_OP) {\n return this.deserialize(descriptors.groupElement, reader);\n }\n\n break;\n }\n }\n } else {\n switch (type.code) {\n case descriptors.coll.code: {\n const length = reader.readVlq();\n const embeddedType = (type as SCollType).elementsType;\n\n switch (embeddedType.code) {\n case descriptors.bool.code:\n return reader.readBits(length);\n case descriptors.byte.code:\n return reader.readBytes(length);\n default: {\n const elements = new Array(length);\n for (let i = 0; i < length; i++) {\n elements[i] = this.deserialize(embeddedType, reader);\n }\n\n return elements;\n }\n }\n }\n case descriptors.tuple.code: {\n return (type as STupleType).elementsType.map((t) =>\n this.deserialize(t, reader)\n );\n }\n case descriptors.unit.code:\n return undefined;\n }\n }\n\n throw new Error(\n `Parsing error: '0x${type.code.toString(16)}' type not implemented.`\n );\n }\n};\n","export abstract class SType<I = unknown, O = I> {\n abstract get code(): number;\n abstract get embeddable(): boolean;\n\n coerce(data: I): O {\n // a bit hacky but most of types will not need a specific coercion function.\n return data as unknown as O;\n }\n\n abstract toString(): string;\n}\n\nexport abstract class SMonomorphicType<I, O = I> extends SType<I, O> {\n abstract get code(): number;\n\n get embeddable(): boolean {\n return false;\n }\n}\n\nexport abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {\n abstract get code(): number;\n\n override get embeddable(): boolean {\n return true;\n }\n}\n\nexport abstract class SGenericType<T extends SType | SType[]> extends SType {\n readonly #internalType: T;\n\n constructor(type: T) {\n super();\n this.#internalType = type;\n }\n\n abstract get code(): number;\n\n get elementsType(): T {\n return this.#internalType;\n }\n\n get embeddable(): boolean {\n return false;\n }\n}\n","import { ensureBigInt } from \"@fleet-sdk/common\";\nimport { hex } from \"@fleet-sdk/crypto\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { SPrimitiveType } from \"./base\";\nimport type { BigIntInput, ByteInput } from \"./constructors\";\n\nexport class SBoolType extends SPrimitiveType<boolean> {\n get code(): 0x01 {\n return 0x01;\n }\n\n toString(): string {\n return \"SBool\";\n }\n}\n\nexport class SByteType extends SPrimitiveType<number> {\n get code(): 0x02 {\n return 0x02;\n }\n\n toString(): string {\n return \"SByte\";\n }\n}\n\nexport class SShortType extends SPrimitiveType<number> {\n get code(): 0x03 {\n return 0x03;\n }\n\n toString(): string {\n return \"SShort\";\n }\n}\n\nexport class SIntType extends SPrimitiveType<number> {\n get code(): 0x04 {\n return 0x04;\n }\n\n toString(): string {\n return \"SInt\";\n }\n}\n\nexport class SLongType extends SPrimitiveType<BigIntInput, bigint> {\n get code(): 0x05 {\n return 0x05;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SLong\";\n }\n}\n\nexport class SBigIntType extends SPrimitiveType<string | bigint, bigint> {\n get code(): number {\n return 0x06;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SBigInt\";\n }\n}\n\nexport class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {\n get code(): 0x07 {\n return 0x07;\n }\n\n override coerce(data: ByteInput): Uint8Array {\n return typeof data === \"string\" ? hex.decode(data) : data;\n }\n\n toString(): string {\n return \"SGroupElement\";\n }\n}\n\nexport class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {\n get code(): 0x08 {\n return 0x08;\n }\n\n toString(): string {\n return \"SSigmaProp\";\n }\n}\n","import { SMonomorphicType } from \"./base\";\n\nexport class SUnitType extends SMonomorphicType<undefined> {\n get code(): 0x62 {\n return 0x62;\n }\n\n toString(): string {\n return \"SUnit\";\n }\n}\n","import type { SType } from \"./base\";\nimport type { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport const constructorCode = Object.freeze({\n embeddable: 0,\n\n simpleColl: 1,\n nestedColl: 2,\n\n option: 3,\n optionCollection: 4,\n\n pairOne: 5,\n pairTwo: 6,\n symmetricPair: 7,\n genericTuple: 8\n});\n\nconst MAX_PRIMITIVE_TYPE_CODE = 0x0b;\nexport const PRIMITIVE_TYPE_RANGE = MAX_PRIMITIVE_TYPE_CODE + 0x01;\nconst typeCodeOf = (ctor: number) => PRIMITIVE_TYPE_RANGE * ctor;\n\ntype Descriptor = { code: number; embeddable: boolean };\n\nconst collDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.simpleColl),\n embeddable: false,\n simpleCollTypeCode: typeCodeOf(constructorCode.simpleColl),\n nestedCollTypeCode: typeCodeOf(constructorCode.nestedColl)\n}) satisfies Descriptor;\n\nconst tupleDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.pairOne),\n embeddable: false,\n pairOneTypeCode: typeCodeOf(constructorCode.pairOne),\n pairTwoTypeCode: typeCodeOf(constructorCode.pairTwo),\n tripleTypeCode: typeCodeOf(constructorCode.pairTwo),\n symmetricPairTypeCode: typeCodeOf(constructorCode.symmetricPair),\n quadrupleTypeCode: typeCodeOf(constructorCode.symmetricPair),\n genericTupleTypeCode: typeCodeOf(constructorCode.genericTuple)\n}) satisfies Descriptor;\n\nexport const descriptors = {\n bool: new SBoolType(),\n byte: new SByteType(),\n short: new SShortType(),\n int: new SIntType(),\n long: new SLongType(),\n bigInt: new SBigIntType(),\n groupElement: new SGroupElementType(),\n sigmaProp: new SSigmaPropType(),\n unit: new SUnitType(),\n coll: collDescriptor,\n tuple: tupleDescriptor\n} satisfies { [key: string]: Descriptor };\n\nexport function isColl(type: SType): type is SCollType {\n return (\n type.code >= descriptors.coll.simpleCollTypeCode &&\n type.code <= descriptors.coll.nestedCollTypeCode + MAX_PRIMITIVE_TYPE_CODE\n );\n}\n\nexport function isTuple(type: SType): type is STupleType {\n return (\n type.code >= descriptors.tuple.pairOneTypeCode &&\n type.code <= descriptors.tuple.genericTupleTypeCode\n );\n}\n\nexport function getPrimitiveType(typeCode: number) {\n switch (typeCode) {\n case descriptors.bool.code:\n return descriptors.bool;\n case descriptors.byte.code:\n return descriptors.byte;\n case descriptors.short.code:\n return descriptors.short;\n case descriptors.int.code:\n return descriptors.int;\n case descriptors.long.code:\n return descriptors.long;\n case descriptors.bigInt.code:\n return descriptors.bigInt;\n case descriptors.groupElement.code:\n return descriptors.groupElement;\n case descriptors.sigmaProp.code:\n return descriptors.sigmaProp;\n default:\n throw new Error(\n `The type code '0x${typeCode.toString(16)}' is not a valid primitive type code.`\n );\n }\n}\n","import { hex } from \"@fleet-sdk/crypto\";\nimport { SGenericType, type SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\n\nexport class SCollType<T extends SType = SType> extends SGenericType<T> {\n get code(): number {\n return descriptors.coll.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] | Uint8Array {\n if (\n this.elementsType.code === descriptors.byte.code &&\n !(elements instanceof Uint8Array)\n ) {\n return typeof elements === \"string\"\n ? hex.decode(elements)\n : Uint8Array.from(elements as ArrayLike<number>);\n }\n\n return elements.map((el) => this.elementsType.coerce(el)) as O[];\n }\n\n toString(): string {\n return `SColl[${this.elementsType.toString()}]`;\n }\n}\n\nexport class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {\n get code(): number {\n return descriptors.tuple.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] {\n const output = new Array(elements.length);\n for (let i = 0; i < elements.length; i++) {\n output[i] = this.elementsType[i].coerce(elements[i]);\n }\n\n return output;\n }\n\n toString(): string {\n return `(${this.elementsType.map((el) => el.toString()).join(\", \")})`;\n }\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { SConstant } from \"../sigmaConstant\";\nimport type { SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\nimport { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport type BigIntInput = string | bigint;\nexport type ByteInput = Uint8Array | string;\n\nexport type SConstructor<\n T = unknown,\n S extends SType = SType | SCollType<SType>\n> = (arg?: T) => S;\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\ntype Any = any;\n\ntype Constructable<T = Any> = { new (...args: Any): T };\ntype GenericProxyArgs<R> = R extends (...args: Any) => unknown\n ? Parameters<R>\n : [];\n\ntype SProxy<T extends SType, I, O = I> = {\n (value: I): SConstant<O, T>;\n (value?: I): T;\n};\n\n/**\n * Creates a proxy for monomorphic types, this allows constructor\n * functions to be equivalent to their corresponding type.\n *\n * This function will return one instance of `ctor` if not params as set.\n * Otherwise it will return an `SigmaConstant` instance of `ctor` type.\n *\n * @example\n * // SInt is a proxy for SIntType\n * (intConstant instanceof SInt) === true\n * (intConstant instanceof SIntType) === true\n * @param ctor Class to be proxied.\n * @param cache If defined, proxy will return this instead of a new instance of `ctor`.\n * @param forceConstruction If true, bypasses the constant creation and returns a type.\n * @returns\n */\nfunction monoProxy<T extends SType, I, O = I>(\n ctor: Constructable<T>,\n cache?: T,\n forceConstruction?: boolean\n): SProxy<T, I, O> {\n return new Proxy(ctor, {\n apply: (target, _, args) => {\n const instance = cache ?? new target();\n if (!forceConstruction && isEmpty(args)) return instance;\n\n return new (SConstant as Constructable)(instance, ...args);\n }\n }) as Any;\n}\n\n/**\n * Creates a proxy for generic types.\n */\nfunction genericProxy<T extends SType, R>(\n ctor: Constructable<T>,\n handler: (\n target: Constructable<T>,\n thisArgs: unknown,\n args: GenericProxyArgs<R>\n ) => unknown\n) {\n return new Proxy(ctor, {\n apply: handler\n }) as R;\n}\n\nexport const SByte = monoProxy<SByteType, number>(SByteType, descriptors.byte);\n\nexport const SBool = monoProxy<SBoolType, boolean>(SBoolType, descriptors.bool);\n\nexport const SShort = monoProxy<SShortType, number>(\n SShortType,\n descriptors.short\n);\n\nexport const SInt = monoProxy<SIntType, number>(SIntType, descriptors.int);\n\nexport const SLong = monoProxy<SLongType, BigIntInput, bigint>(\n SLongType,\n descriptors.long\n);\n\nexport const SBigInt = monoProxy<SBigIntType, BigIntInput, bigint>(\n SBigIntType,\n descriptors.bigInt\n);\n\nexport const SGroupElement = monoProxy<\n SGroupElementType,\n ByteInput,\n Uint8Array\n>(SGroupElementType, descriptors.groupElement);\n\nexport const SSigmaProp = monoProxy<SSigmaPropType, SConstant<Uint8Array>>(\n SSigmaPropType,\n descriptors.sigmaProp\n);\n\ntype SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;\nexport const SUnit: SUnit = monoProxy(SUnitType, undefined, true);\n\ntype SColl = {\n <D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;\n <D, T extends SByteType>(\n type: SConstructor<D, T>,\n elements: ByteInput | D[]\n ): SConstant<Uint8Array, T>;\n <D, T extends SType>(\n type: SConstructor<D, T>,\n elements: D[]\n ): SConstant<D[], T>;\n};\n\nexport const SColl = genericProxy<SCollType, SColl>(\n SCollType,\n (target, _, args) => {\n const [type, elements] = args;\n const elementsType = type();\n if (!elements) return () => new target(elementsType);\n\n return new SConstant(new target(elementsType), elements);\n }\n);\n\nexport function STuple(...items: SConstant[]) {\n return new SConstant(\n new STupleType(items.map((x) => x.type)),\n items.map((x) => x.data)\n );\n}\n\ntype ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;\ntype SPair = {\n <L, R>(\n left: SConstant<L>,\n right: SConstant<R>\n ): SConstant<[L, R], STupleType>;\n <LD, RD, LT extends SType, RT extends SType>(\n left: SConstructor<LD, LT>,\n right: SConstructor<RD, RT>\n ): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;\n};\n\nexport const SPair = genericProxy<STupleType, SPair>(\n STupleType,\n (target, _, args) => {\n const [left, right] = args;\n\n if (typeof left === \"function\" && typeof right === \"function\") {\n return () => new target([left(), right()]);\n }\n\n if (left instanceof SConstant && right instanceof SConstant) {\n return new SConstant(new target([left.type, right.type]), [\n left.data,\n right.data\n ]);\n }\n\n throw new Error(\"Invalid tuple declaration.\");\n }\n);\n","import { assert, first, last } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport { isColl, isTuple, SCollType, STupleType, type SType } from \"../types\";\nimport {\n constructorCode,\n descriptors,\n getPrimitiveType,\n PRIMITIVE_TYPE_RANGE\n} from \"../types/descriptors\";\n\nexport const typeSerializer = {\n serialize(type: SType, writer: SigmaByteWriter) {\n if (type.embeddable) {\n writer.write(type.code);\n } else if (type.code === descriptors.unit.code) {\n writer.write(type.code);\n } else if (isColl(type)) {\n if (type.elementsType.embeddable) {\n writer.write(\n descriptors.coll.simpleCollTypeCode + type.elementsType.code\n );\n } else if (isColl(type.elementsType)) {\n const nestedColl = type.elementsType;\n if (nestedColl.elementsType.embeddable) {\n writer.write(\n descriptors.coll.nestedCollTypeCode + nestedColl.elementsType.code\n );\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(nestedColl, writer);\n }\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(type.elementsType, writer);\n }\n } else if (isTuple(type)) {\n switch (type.elementsType.length) {\n case 2: {\n const left = first(type.elementsType);\n const right = last(type.elementsType);\n\n if (left.embeddable) {\n if (left.code === right.code) {\n // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n writer.write(descriptors.tuple.symmetricPairTypeCode + left.code);\n } else {\n // Pair of types where first is primitive (`(_, Int)`)\n writer.write(descriptors.tuple.pairOneTypeCode + left.code);\n this.serialize(right, writer);\n }\n } else if (right.embeddable) {\n // Pair of types where second is primitive (`(Int, _)`)\n writer.write(descriptors.tuple.pairTwoTypeCode + right.code);\n this.serialize(left, writer);\n } else {\n // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n writer.write(descriptors.tuple.pairOneTypeCode);\n this.serialize(left, writer);\n this.serialize(right, writer);\n }\n\n return;\n }\n case 3:\n writer.write(descriptors.tuple.tripleTypeCode);\n break;\n case 4:\n writer.write(descriptors.tuple.quadrupleTypeCode);\n break;\n default: {\n const len = type.elementsType.length;\n assert(\n len >= 2 && len <= 255,\n \"Invalid type: tuples must have between 2 and 255 items.\"\n );\n\n // Generic tuple\n writer.write(descriptors.tuple.genericTupleTypeCode);\n writer.writeVLQ(len);\n }\n }\n\n for (let i = 0; i < type.elementsType.length; i++) {\n this.serialize(type.elementsType[i], writer);\n }\n } else {\n throw new Error(\"Serialization error: type not implemented.\");\n }\n },\n\n deserialize(r: SigmaByteReader): SType {\n const byte = r.readByte();\n assert(\n byte > 0,\n `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`\n );\n\n if (byte < descriptors.tuple.genericTupleTypeCode) {\n const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);\n const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);\n\n switch (ctorCode) {\n case constructorCode.embeddable: {\n return getPrimitiveType(embdCode);\n }\n case constructorCode.simpleColl: {\n const internal =\n embdCode === 0 ? this.deserialize(r) : getPrimitiveType(embdCode);\n\n return new SCollType(internal);\n }\n case constructorCode.nestedColl: {\n return new SCollType(new SCollType(getPrimitiveType(embdCode)));\n }\n case constructorCode.pairOne: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r)] // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n : [getPrimitiveType(embdCode), this.deserialize(r)]; // Pair of types where first is primitive (`(_, Int)`)\n\n return new STupleType(internal);\n }\n case constructorCode.pairTwo: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r), this.deserialize(r)] // Triple of types\n : [this.deserialize(r), getPrimitiveType(embdCode)];\n\n return new STupleType(internal);\n }\n case constructorCode.symmetricPair: {\n const internal =\n embdCode === 0\n ? [\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r)\n ] // Quadruple of types\n : [getPrimitiveType(embdCode), getPrimitiveType(embdCode)]; // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n\n return new STupleType(internal);\n }\n }\n }\n\n switch (byte) {\n case descriptors.tuple.genericTupleTypeCode: {\n const len = r.readVlq();\n const wrapped = new Array<SType>(len);\n for (let i = 0; i < len; i++) {\n wrapped[i] = this.deserialize(r);\n }\n\n return new STupleType(wrapped);\n }\n case descriptors.unit.code: {\n return descriptors.unit;\n }\n }\n\n throw new Error(\"Not implemented.\");\n }\n};\n","import {\n type Amount,\n type Box,\n type BoxCandidate,\n byteSizeOf,\n ensureBigInt,\n isDefined,\n isEmpty,\n isUndefined,\n type NonMandatoryRegisters,\n some,\n type TokenAmount\n} from \"@fleet-sdk/common\";\nimport { estimateVLQSize, SigmaByteWriter } from \"../coders\";\n\nconst MAX_UINT16_VALUE = 65535;\n\nexport function serializeBox(box: Box<Amount>): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount>,\n writer: SigmaByteWriter\n): SigmaByteWriter;\nexport function serializeBox(\n box: BoxCandidate<Amount>,\n writer: SigmaByteWriter,\n distinctTokenIds: string[]\n): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount> | BoxCandidate<Amount>,\n writer = new SigmaByteWriter(5_0000),\n distinctTokenIds?: string[]\n): SigmaByteWriter {\n writer.writeBigVLQ(ensureBigInt(box.value));\n writer.writeHex(box.ergoTree);\n writer.writeVLQ(box.creationHeight);\n writeTokens(writer, box.assets, distinctTokenIds);\n writeRegisters(writer, box.additionalRegisters);\n\n if (isDefined(distinctTokenIds)) return writer;\n if (!isBox(box)) throw new Error(\"Invalid box type.\");\n return writer.writeHex(box.transactionId).writeVLQ(box.index);\n}\n\nfunction isBox<T extends Amount>(\n box: Box<Amount> | BoxCandidate<Amount>\n): box is Box<T> {\n const castedBox = box as Box<T>;\n\n return isDefined(castedBox.transactionId) && isDefined(castedBox.index);\n}\n\nfunction writeTokens(\n writer: SigmaByteWriter,\n tokens: TokenAmount<Amount>[],\n tokenIds?: string[]\n): void {\n if (isEmpty(tokens)) {\n writer.write(0);\n\n return;\n }\n\n writer.writeVLQ(tokens.length);\n if (some(tokenIds)) {\n tokens.map((token) =>\n writer\n .writeVLQ(tokenIds.indexOf(token.tokenId))\n .writeBigVLQ(ensureBigInt(token.amount))\n );\n } else {\n tokens.map((token) =>\n writer.writeHex(token.tokenId).writeBigVLQ(ensureBigInt(token.amount))\n );\n }\n}\n\nfunction writeRegisters(\n writer: SigmaByteWriter,\n registers: NonMandatoryRegisters\n): void {\n const keys = Object.keys(registers).sort();\n let length = 0;\n\n for (const key of keys) {\n if (registers[key as keyof NonMandatoryRegisters]) length++;\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const register = registers[key as keyof NonMandatoryRegisters];\n if (isDefined(register)) writer.writeHex(register);\n }\n}\n\n/**\n * Estimates the byte size a box.\n * @returns byte size of the box.\n */\nexport function estimateBoxSize(\n box: Box<Amount> | BoxCandidate<Amount>,\n withValue?: Amount\n): number {\n if (isUndefined(box.creationHeight)) {\n throw new Error(\"Box size estimation error: creation height is undefined.\");\n }\n\n let size = 0;\n\n size += estimateVLQSize(isDefined(withValue) ? withValue : box.value);\n size += byteSizeOf(box.ergoTree);\n size += estimateVLQSize(box.creationHeight);\n\n size += estimateVLQSize(box.assets.length);\n for (const asset of box.assets) {\n size += byteSizeOf(asset.tokenId) + estimateVLQSize(asset.amount);\n }\n\n let registersLength = 0;\n for (const key in box.additionalRegisters) {\n const register =\n box.additionalRegisters[key as keyof NonMandatoryRegisters];\n if (register) {\n size += byteSizeOf(register);\n registersLength++;\n }\n }\n\n size += estimateVLQSize(registersLength);\n size += 32; // transaction id (BLAKE2b 256 hash)\n size += estimateVLQSize(isBox(box) ? box.index : MAX_UINT16_VALUE);\n\n return size;\n}\n","import {\n type Amount,\n type BoxCandidate,\n type ContextExtension,\n type DataInput,\n isDefined,\n type UnsignedInput\n} from \"@fleet-sdk/common\";\nimport { SigmaByteWriter } from \"../coders\";\nimport { serializeBox } from \"./boxSerializer\";\n\nexport type MinimalUnsignedTransaction = {\n inputs: readonly UnsignedInput[];\n dataInputs: readonly DataInput[];\n outputs: readonly BoxCandidate<Amount>[];\n};\n\nexport function serializeTransaction(\n transaction: MinimalUnsignedTransaction\n): SigmaByteWriter {\n const writer = new SigmaByteWriter(100_000);\n\n // write inputs\n writer.writeVLQ(transaction.inputs.length);\n transaction.inputs.map((input) => writeInput(writer, input));\n\n // write data inputs\n writer.writeVLQ(transaction.dataInputs.length);\n transaction.dataInputs.map((dataInput) => writer.writeHex(dataInput.boxId));\n\n // write distinct token IDs\n const distinctTokenIds = getDistinctTokenIds(transaction.outputs);\n writer.writeVLQ(distinctTokenIds.length);\n distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));\n\n // write outputs\n writer.writeVLQ(transaction.outputs.length);\n transaction.outputs.map((output) =>\n serializeBox(output, writer, distinctTokenIds)\n );\n\n return writer;\n}\n\nfunction writeInput(writer: SigmaByteWriter, input: UnsignedInput): void {\n writer.writeHex(input.boxId);\n writer.write(0); // empty proof\n writeExtension(writer, input.extension);\n}\n\nfunction writeExtension(\n writer: SigmaByteWriter,\n extension: ContextExtension\n): void {\n const keys = Object.keys(extension);\n let length = 0;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n length++;\n }\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n writer.writeVLQ(Number(key)).writeHex(ext);\n }\n }\n}\n\nfunction getDistinctTokenIds(outputs: readonly BoxCandidate<Amount>[]) {\n const tokenIds = new Set<string>();\n outputs.flatMap((output) =>\n output.assets.map((asset) => tokenIds.add(asset.tokenId))\n );\n\n return Array.from(tokenIds);\n}\n"]}
1
+ {"version":3,"sources":["../src/coders/bigint.ts","../src/coders/vlq.ts","../src/coders/zigZag.ts","../src/coders/sigmaByteReader.ts","../src/coders/sigmaByteWriter.ts","../src/types/base.ts","../src/types/primitives.ts","../src/types/monomorphics.ts","../src/types/descriptors.ts","../src/types/generics.ts","../src/types/constructors.ts","../src/serializers/dataSerializer.ts","../src/serializers/typeSerializer.ts","../src/sigmaConstant.ts","../src/serializers/boxSerializer.ts","../src/serializers/transactionSerializer.ts"],"names":["hex","_0n","first","_127n","_7n","_128n","ensureBigInt","_1n","_63n","isEmpty","ensureBytes","blake2b256","assert","last","isDefined","some","isUndefined","byteSizeOf"],"mappings":";;;;;;AAOO,SAAS,YAAYA,IAAqB,EAAA;AAE/C,EAAM,MAAA,KAAA,GAAQ,MAAOA,CAAAA,IAAAA,CAAI,MAAS,GAAA,CAAA,GAAI,MAAMA,IAAG,CAAA,CAAA,GAAK,CAAKA,EAAAA,EAAAA,IAAG,CAAE,CAAA,CAAA,CAAA;AAC9D,EAAM,MAAA,QAAA,GAAW,OAAO,QAASA,CAAAA,IAAAA,CAAI,MAAM,CAAG,EAAA,CAAC,GAAG,EAAE,CAAA,CAAA;AACpD,EAAA,IAAI,GAAO,GAAA,QAAA,EAAiB,OAAA,CAAC,cAAc,KAAK,CAAA,CAAA;AAEhD,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAOO,SAAS,YAAY,KAAuB,EAAA;AAGjD,EAAA,MAAM,WAAW,KAAS,IAAAC,UAAA,CAAA;AAC1B,EAAA,IAAID,QAAO,QAAW,GAAA,KAAA,GAAQ,cAAc,KAAK,CAAA,E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AA,CAAA;AAC5B","file":"index.js","sourcesContent":["import { _0n, first } from \"@fleet-sdk/common\";\n\n/**\n * Converts a hex string to bigint.\n * @param hex The hex string to be converted.\n * @returns The bigint value represented by the hex string.\n */\nexport function hexToBigInt(hex: string): bigint {\n // https://coolaj86.com/articles/convert-hex-to-decimal-with-js-bigints/\n const value = BigInt(hex.length % 2 ? `0x0${hex}` : `0x${hex}`);\n const highByte = Number.parseInt(hex.slice(0, 2), 16);\n if (0x80 & highByte) return -negateAndMask(value);\n\n return value;\n}\n\n/**\n * Serializes a `BigInt` to a hex string\n * @param value The bigint value to be serialized\n * @returns Hex representation for the provided `number`.\n */\nexport function bigIntToHex(value: bigint): string {\n // implementation inspired on\n // https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/\n const positive = value >= _0n;\n let hex = (positive ? value : negateAndMask(value)).toString(16);\n if (hex.length % 2) hex = `0${hex}`;\n\n if (positive && 0x80 & Number.parseInt(hex.slice(0, 2), 16)) {\n return `00${hex}`;\n }\n\n return hex;\n}\n\n/**\n * Returns the two’s complement of a bigint value.\n * @param value The bigint value to negate.\n * @returns The two’s complement of `number` as a bigint.\n */\nexport function negateAndMask(value: bigint): bigint {\n let val = value;\n const negative = val < _0n;\n if (negative) val = -val; // turn into a positive number\n\n const bits = val.toString(2);\n let len = bits.length; // convert to binary\n const mod = len % 8;\n\n if (mod > 0) {\n len += 8 - mod;\n } else if (negative && first(bits) === \"1\" && bits.indexOf(\"1\", 1) !== -1) {\n len += 8;\n }\n\n const mask = (1n << BigInt(len)) - 1n; // create a mask\n return (~val & mask) + 1n; // invert bits, mask it, and add one\n}\n","import { _0n, _127n, _128n, _7n, ensureBigInt } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader } from \"./sigmaByteReader\";\nimport type { SigmaByteWriter } from \"./sigmaByteWriter\";\n\n/**\n * A **variable-length quantity (VLQ)** is a universal code that uses an arbitrary number\n * of binary octets (eight-bit bytes) to represent an arbitrarily large integer. A VLQ\n * is essentially a base-128 representation of an unsigned integer with the addition of\n * the eighth bit to mark continuation of bytes. VLQ is identical to LEB128 except in\n * endianness. See the example below.\n */\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeVLQ(writer: SigmaByteWriter, value: number): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n if (value === 0) return writer.write(0);\n if (value < 0) {\n throw new RangeError(\"Variable Length Quantity not supported for negative numbers.\");\n }\n\n let val = value;\n do {\n let lower7bits = val & 0x7f;\n val >>= 7;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readVLQ(reader: SigmaByteReader): number {\n if (reader.isEmpty) {\n return 0;\n }\n\n let value = 0;\n let shift = 0;\n let lower7bits = 0;\n\n do {\n lower7bits = reader.readByte();\n value |= (lower7bits & 0x7f) << shift;\n shift += 7;\n } while ((lower7bits & 0x80) !== 0);\n\n return value;\n}\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Big integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeBigVLQ(writer: SigmaByteWriter, value: bigint): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n\n if (value === _0n) return writer.write(0);\n if (value < _0n) {\n throw new RangeError(\"Variable Length Quantity not supported for negative numbers\");\n }\n\n let val = value;\n do {\n let lower7bits = Number(val & _127n);\n val >>= _7n;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned big integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readBigVLQ(reader: SigmaByteReader): bigint {\n if (reader.isEmpty) return _0n;\n\n let value = _0n;\n let shift = _0n;\n let lower7bits = _0n;\n\n do {\n lower7bits = BigInt(reader.readByte());\n value |= (lower7bits & _127n) << shift;\n shift += _7n;\n } while ((lower7bits & _128n) !== _0n);\n\n return value;\n}\n\n/**\n * Estimates the byte size of a given unsigned integer.\n * @param value: the value to be evaluated.\n * @returns the byte size of the value.\n */\nexport function estimateVLQSize(value: number | bigint | string): number {\n let size = 0;\n let val = value;\n if (typeof val === \"number\") {\n do {\n size++;\n val = Math.floor(val / 128);\n } while (val > 0);\n\n return size;\n }\n\n val = ensureBigInt(val);\n do {\n size++;\n val /= _128n;\n } while (val > _0n);\n\n return size;\n}\n","import { _1n, _63n } from \"@fleet-sdk/common\";\n\n/**\n * ZigZag encoding maps signed integers to unsigned integers so that numbers\n * with a small absolute value (for instance, -1) have a small variant encoded\n * value too. It does this in a way that \"zig-zags\" back and forth through the\n * positive and negative integers, so that -1 is encoded as 1, 1 is encoded as 2,\n * -2 is encoded as 3, and so on.\n * @see https://developers.google.com/protocol-buffers/docs/encoding#types\n */\n\n/**\n * Encode a signed integer.\n * @param input Signed integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncode(input: number): number {\n return (input << 1) ^ (input >> 63);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed integer\n */\nexport function zigZagDecode(input: number): number {\n return (input >> 1) ^ -(input & 1);\n}\n\n/**\n * Encode a signed big integer.\n * @param input Signed big integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncodeBigInt(input: bigint): bigint {\n return (input << _1n) ^ (input >> _63n);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed big integer\n */\nexport function zigZagDecodeBigInt(input: bigint): bigint {\n return (input >> _1n) ^ -(input & _1n);\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { type ByteInput, ensureBytes, hex } from \"@fleet-sdk/crypto\";\nimport { hexToBigInt } from \"./bigint\";\nimport { readBigVLQ, readVLQ } from \"./vlq\";\nimport { zigZagDecode, zigZagDecodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteReader {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get isEmpty(): boolean {\n return isEmpty(this.#bytes);\n }\n\n constructor(bytes: ByteInput) {\n this.#bytes = ensureBytes(bytes);\n this.#cursor = 0;\n }\n\n public readBoolean(): boolean {\n return this.readByte() === 0x01;\n }\n\n public readBits(length: number): ArrayLike<boolean> {\n const bits = new Array<boolean>(length);\n let bitOffset = 0;\n\n for (let i = 0; i < length; i++) {\n const bit = (this.#bytes[this.#cursor] >> bitOffset++) & 1;\n bits[i] = bit === 1;\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return bits;\n }\n\n public readByte(): number {\n return this.#bytes[this.#cursor++];\n }\n\n public readBytes(length: number): Uint8Array {\n return this.#bytes.subarray(this.#cursor, (this.#cursor += length));\n }\n\n public readVlq(): number {\n return readVLQ(this);\n }\n\n public readShort(): number {\n return Number(zigZagDecode(readVLQ(this)));\n }\n\n public readInt(): number {\n return Number(this.readLong());\n }\n\n public readLong(): bigint {\n return zigZagDecodeBigInt(readBigVLQ(this));\n }\n\n public readBigInt(): bigint {\n const len = readVLQ(this);\n return hexToBigInt(hex.encode(this.readBytes(len)));\n }\n}\n","import { blake2b256, type Coder, hex } from \"@fleet-sdk/crypto\";\nimport { bigIntToHex } from \"./bigint\";\nimport { writeBigVLQ, writeVLQ } from \"./vlq\";\nimport { zigZagEncode, zigZagEncodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteWriter {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get length() {\n return this.#cursor;\n }\n\n constructor(length: number) {\n this.#bytes = new Uint8Array(length);\n this.#cursor = 0;\n }\n\n public writeBoolean(value: boolean): SigmaByteWriter {\n this.write(value === true ? 0x01 : 0x00);\n\n return this;\n }\n\n public writeVLQ(value: number): SigmaByteWriter {\n return writeVLQ(this, value);\n }\n\n public writeBigVLQ(value: bigint): SigmaByteWriter {\n return writeBigVLQ(this, value);\n }\n\n public writeShort(value: number): SigmaByteWriter {\n this.writeVLQ(zigZagEncode(value));\n return this;\n }\n\n public writeInt(value: number): SigmaByteWriter {\n this.writeLong(BigInt(value));\n return this;\n }\n\n public writeLong(value: bigint): SigmaByteWriter {\n this.writeBigVLQ(zigZagEncodeBigInt(value));\n return this;\n }\n\n public write(byte: number): SigmaByteWriter {\n this.#bytes[this.#cursor++] = byte;\n return this;\n }\n\n public writeBytes(bytes: ArrayLike<number>): SigmaByteWriter {\n this.#bytes.set(bytes, this.#cursor);\n this.#cursor += bytes.length;\n return this;\n }\n\n public writeHex(bytesHex: string): SigmaByteWriter {\n return this.writeBytes(hex.decode(bytesHex));\n }\n\n public writeBits(bits: ArrayLike<boolean>): SigmaByteWriter {\n let bitOffset = 0;\n\n for (let i = 0; i < bits.length; i++) {\n if (bits[i]) {\n this.#bytes[this.#cursor] |= 1 << bitOffset++;\n } else {\n this.#bytes[this.#cursor] &= ~(1 << bitOffset++);\n }\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return this;\n }\n\n public writeBigInt(value: bigint): SigmaByteWriter {\n const hex = bigIntToHex(value);\n return this.writeVLQ(hex.length / 2).writeHex(hex);\n }\n\n public writeChecksum(length = 4, hashFn = blake2b256): SigmaByteWriter {\n const hash = hashFn(this.toBytes());\n return this.writeBytes(length ? hash.subarray(0, length) : hash);\n }\n\n public encode<T>(coder: Coder<Uint8Array, T>): T {\n return coder.encode(this.toBytes());\n }\n\n public toBytes(): Uint8Array {\n if (this.#cursor === this.#bytes.length) return this.#bytes;\n return this.#bytes.subarray(0, this.#cursor);\n }\n}\n","export abstract class SType<I = unknown, O = I> {\n abstract get code(): number;\n abstract get embeddable(): boolean;\n\n coerce(data: I): O {\n // a bit hacky but most of types will not need a specific coercion function.\n return data as unknown as O;\n }\n\n abstract toString(): string;\n}\n\nexport abstract class SMonomorphicType<I, O = I> extends SType<I, O> {\n abstract get code(): number;\n\n get embeddable(): boolean {\n return false;\n }\n}\n\nexport abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {\n abstract get code(): number;\n\n override get embeddable(): boolean {\n return true;\n }\n}\n\nexport abstract class SGenericType<T extends SType | SType[]> extends SType {\n readonly #internalType: T;\n\n constructor(type: T) {\n super();\n this.#internalType = type;\n }\n\n abstract get code(): number;\n\n get elementsType(): T {\n return this.#internalType;\n }\n\n get embeddable(): boolean {\n return false;\n }\n}\n","import { ensureBigInt } from \"@fleet-sdk/common\";\nimport { hex } from \"@fleet-sdk/crypto\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { SPrimitiveType } from \"./base\";\nimport type { BigIntInput, ByteInput } from \"./constructors\";\n\nexport class SBoolType extends SPrimitiveType<boolean> {\n get code(): 0x01 {\n return 0x01;\n }\n\n toString(): string {\n return \"SBool\";\n }\n}\n\nexport class SByteType extends SPrimitiveType<number> {\n get code(): 0x02 {\n return 0x02;\n }\n\n toString(): string {\n return \"SByte\";\n }\n}\n\nexport class SShortType extends SPrimitiveType<number> {\n get code(): 0x03 {\n return 0x03;\n }\n\n toString(): string {\n return \"SShort\";\n }\n}\n\nexport class SIntType extends SPrimitiveType<number> {\n get code(): 0x04 {\n return 0x04;\n }\n\n toString(): string {\n return \"SInt\";\n }\n}\n\nexport class SLongType extends SPrimitiveType<BigIntInput, bigint> {\n get code(): 0x05 {\n return 0x05;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SLong\";\n }\n}\n\nexport class SBigIntType extends SPrimitiveType<string | bigint, bigint> {\n get code(): number {\n return 0x06;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SBigInt\";\n }\n}\n\nexport class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {\n get code(): 0x07 {\n return 0x07;\n }\n\n override coerce(data: ByteInput): Uint8Array {\n return typeof data === \"string\" ? hex.decode(data) : data;\n }\n\n toString(): string {\n return \"SGroupElement\";\n }\n}\n\nexport class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {\n get code(): 0x08 {\n return 0x08;\n }\n\n toString(): string {\n return \"SSigmaProp\";\n }\n}\n","import { SMonomorphicType } from \"./base\";\n\nexport class SUnitType extends SMonomorphicType<undefined> {\n get code(): 0x62 {\n return 0x62;\n }\n\n toString(): string {\n return \"SUnit\";\n }\n}\n","import type { SType } from \"./base\";\nimport type { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport const constructorCode = Object.freeze({\n embeddable: 0,\n\n simpleColl: 1,\n nestedColl: 2,\n\n option: 3,\n optionCollection: 4,\n\n pairOne: 5,\n pairTwo: 6,\n symmetricPair: 7,\n genericTuple: 8\n});\n\nconst MAX_PRIMITIVE_TYPE_CODE = 0x0b;\nexport const PRIMITIVE_TYPE_RANGE = MAX_PRIMITIVE_TYPE_CODE + 0x01;\nconst typeCodeOf = (ctor: number) => PRIMITIVE_TYPE_RANGE * ctor;\n\ntype Descriptor = { code: number; embeddable: boolean };\n\nconst collDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.simpleColl),\n embeddable: false,\n simpleCollTypeCode: typeCodeOf(constructorCode.simpleColl),\n nestedCollTypeCode: typeCodeOf(constructorCode.nestedColl)\n}) satisfies Descriptor;\n\nconst tupleDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.pairOne),\n embeddable: false,\n pairOneTypeCode: typeCodeOf(constructorCode.pairOne),\n pairTwoTypeCode: typeCodeOf(constructorCode.pairTwo),\n tripleTypeCode: typeCodeOf(constructorCode.pairTwo),\n symmetricPairTypeCode: typeCodeOf(constructorCode.symmetricPair),\n quadrupleTypeCode: typeCodeOf(constructorCode.symmetricPair),\n genericTupleTypeCode: typeCodeOf(constructorCode.genericTuple)\n}) satisfies Descriptor;\n\nexport const descriptors = {\n bool: new SBoolType(),\n byte: new SByteType(),\n short: new SShortType(),\n int: new SIntType(),\n long: new SLongType(),\n bigInt: new SBigIntType(),\n groupElement: new SGroupElementType(),\n sigmaProp: new SSigmaPropType(),\n unit: new SUnitType(),\n coll: collDescriptor,\n tuple: tupleDescriptor\n} satisfies { [key: string]: Descriptor };\n\nexport function isColl(type: SType): type is SCollType {\n return (\n type.code >= descriptors.coll.simpleCollTypeCode &&\n type.code <= descriptors.coll.nestedCollTypeCode + MAX_PRIMITIVE_TYPE_CODE\n );\n}\n\nexport function isTuple(type: SType): type is STupleType {\n return (\n type.code >= descriptors.tuple.pairOneTypeCode &&\n type.code <= descriptors.tuple.genericTupleTypeCode\n );\n}\n\nexport function getPrimitiveType(typeCode: number) {\n switch (typeCode) {\n case descriptors.bool.code:\n return descriptors.bool;\n case descriptors.byte.code:\n return descriptors.byte;\n case descriptors.short.code:\n return descriptors.short;\n case descriptors.int.code:\n return descriptors.int;\n case descriptors.long.code:\n return descriptors.long;\n case descriptors.bigInt.code:\n return descriptors.bigInt;\n case descriptors.groupElement.code:\n return descriptors.groupElement;\n case descriptors.sigmaProp.code:\n return descriptors.sigmaProp;\n default:\n throw new Error(\n `The type code '0x${typeCode.toString(16)}' is not a valid primitive type code.`\n );\n }\n}\n","import { hex } from \"@fleet-sdk/crypto\";\nimport { SGenericType, type SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\n\nexport class SCollType<T extends SType = SType> extends SGenericType<T> {\n get code(): number {\n return descriptors.coll.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] | Uint8Array {\n if (\n this.elementsType.code === descriptors.byte.code &&\n !(elements instanceof Uint8Array)\n ) {\n return typeof elements === \"string\"\n ? hex.decode(elements)\n : Uint8Array.from(elements as ArrayLike<number>);\n }\n\n return elements.map((el) => this.elementsType.coerce(el)) as O[];\n }\n\n toString(): string {\n return `SColl[${this.elementsType.toString()}]`;\n }\n}\n\nexport class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {\n get code(): number {\n return descriptors.tuple.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] {\n const output = new Array(elements.length);\n for (let i = 0; i < elements.length; i++) {\n output[i] = this.elementsType[i].coerce(elements[i]);\n }\n\n return output;\n }\n\n toString(): string {\n return `(${this.elementsType.map((el) => el.toString()).join(\", \")})`;\n }\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { SConstant } from \"../sigmaConstant\";\nimport type { SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\nimport { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport type BigIntInput = string | bigint;\nexport type ByteInput = Uint8Array | string;\n\nexport type SConstructor<T = unknown, S extends SType = SType | SCollType<SType>> = (\n arg?: T\n) => S;\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\ntype Any = any;\n\ntype Constructable<T = Any> = { new (...args: Any): T };\ntype GenericProxyArgs<R> = R extends (...args: Any) => unknown ? Parameters<R> : [];\n\ntype SProxy<T extends SType, I, O = I> = {\n (value: I): SConstant<O, T>;\n (value?: I): T;\n};\n\n/**\n * Creates a proxy for monomorphic types, this allows constructor\n * functions to be equivalent to their corresponding type.\n *\n * This function will return one instance of `ctor` if not params as set.\n * Otherwise it will return an `SigmaConstant` instance of `ctor` type.\n *\n * @example\n * // SInt is a proxy for SIntType\n * (intConstant instanceof SInt) === true\n * (intConstant instanceof SIntType) === true\n * @param ctor Class to be proxied.\n * @param cache If defined, proxy will return this instead of a new instance of `ctor`.\n * @param forceConstruction If true, bypasses the constant creation and returns a type.\n * @returns\n */\nfunction monoProxy<T extends SType, I, O = I>(\n ctor: Constructable<T>,\n cache?: T,\n forceConstruction?: boolean\n): SProxy<T, I, O> {\n return new Proxy(ctor, {\n apply: (target, _, args) => {\n const instance = cache ?? new target();\n if (!forceConstruction && isEmpty(args)) return instance;\n\n return new (SConstant as Constructable)(instance, ...args);\n }\n }) as Any;\n}\n\n/**\n * Creates a proxy for generic types.\n */\nfunction genericProxy<T extends SType, R>(\n ctor: Constructable<T>,\n handler: (\n target: Constructable<T>,\n thisArgs: unknown,\n args: GenericProxyArgs<R>\n ) => unknown\n) {\n return new Proxy(ctor, {\n apply: handler\n }) as R;\n}\n\nexport const SByte = monoProxy<SByteType, number>(SByteType, descriptors.byte);\n\nexport const SBool = monoProxy<SBoolType, boolean>(SBoolType, descriptors.bool);\n\nexport const SShort = monoProxy<SShortType, number>(SShortType, descriptors.short);\n\nexport const SInt = monoProxy<SIntType, number>(SIntType, descriptors.int);\n\nexport const SLong = monoProxy<SLongType, BigIntInput, bigint>(\n SLongType,\n descriptors.long\n);\n\nexport const SBigInt = monoProxy<SBigIntType, BigIntInput, bigint>(\n SBigIntType,\n descriptors.bigInt\n);\n\nexport const SGroupElement = monoProxy<SGroupElementType, ByteInput, Uint8Array>(\n SGroupElementType,\n descriptors.groupElement\n);\n\nexport const SSigmaProp = monoProxy<SSigmaPropType, SConstant<Uint8Array>>(\n SSigmaPropType,\n descriptors.sigmaProp\n);\n\ntype SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;\nexport const SUnit: SUnit = monoProxy(SUnitType, undefined, true);\n\ntype SColl = {\n <D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;\n <D, T extends SByteType>(\n type: SConstructor<D, T>,\n elements: ByteInput | D[]\n ): SConstant<Uint8Array, T>;\n <D, T extends SType>(type: SConstructor<D, T>, elements: D[]): SConstant<D[], T>;\n};\n\nexport const SColl = genericProxy<SCollType, SColl>(SCollType, (target, _, args) => {\n const [type, elements] = args;\n const elementsType = type();\n if (!elements) return () => new target(elementsType);\n\n return new SConstant(new target(elementsType), elements);\n});\n\nexport function STuple(...items: SConstant[]) {\n return new SConstant(\n new STupleType(items.map((x) => x.type)),\n items.map((x) => x.data)\n );\n}\n\ntype ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;\ntype SPair = {\n <L, R>(left: SConstant<L>, right: SConstant<R>): SConstant<[L, R], STupleType>;\n <LD, RD, LT extends SType, RT extends SType>(\n left: SConstructor<LD, LT>,\n right: SConstructor<RD, RT>\n ): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;\n};\n\nexport const SPair = genericProxy<STupleType, SPair>(STupleType, (target, _, args) => {\n const [left, right] = args;\n\n if (typeof left === \"function\" && typeof right === \"function\") {\n return () => new target([left(), right()]);\n }\n\n if (left instanceof SConstant && right instanceof SConstant) {\n return new SConstant(new target([left.type, right.type]), [left.data, right.data]);\n }\n\n throw new Error(\"Invalid tuple declaration.\");\n});\n","import { assert } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { isColl, isTuple, type SCollType, type STupleType, type SType } from \"../types\";\nimport { descriptors } from \"../types/descriptors\";\n\nconst GROUP_ELEMENT_LENGTH = 33;\nconst PROVE_DLOG_OP = 0xcd;\n\nexport const dataSerializer = {\n serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return writer.writeBoolean(data as boolean);\n case descriptors.byte.code:\n return writer.write(data as number);\n case descriptors.short.code:\n return writer.writeShort(data as number);\n case descriptors.int.code:\n return writer.writeInt(data as number);\n case descriptors.long.code:\n return writer.writeLong(data as bigint);\n case descriptors.bigInt.code:\n return writer.writeBigInt(data as bigint);\n case descriptors.groupElement.code:\n return writer.writeBytes(data as Uint8Array);\n case descriptors.sigmaProp.code: {\n const node = data as SConstant<SConstant<Uint8Array>>;\n if (node.type === descriptors.groupElement) {\n writer.write(PROVE_DLOG_OP);\n return dataSerializer.serialize(node.data, node.type, writer);\n }\n\n throw Error(\"Serialization error: SigmaProp operation not implemented.\");\n }\n }\n }\n\n if (isColl(type)) {\n if (type.elementsType.code === descriptors.byte.code) {\n assert(\n data instanceof Uint8Array,\n `SColl[Byte] expected an UInt8Array, got ${typeof data}.`\n );\n } else {\n assert(Array.isArray(data), `SColl expected an array, got ${typeof data}.`);\n }\n\n writer.writeVLQ(data.length);\n switch (type.elementsType.code) {\n case descriptors.bool.code: {\n return writer.writeBits(data as boolean[]);\n }\n case descriptors.byte.code: {\n return writer.writeBytes(data as Uint8Array);\n }\n default: {\n for (let i = 0; i < data.length; i++) {\n dataSerializer.serialize(data[i], type.elementsType, writer);\n }\n\n return writer;\n }\n }\n }\n\n if (isTuple(type)) {\n assert(\n Array.isArray(data),\n `STupleType serialization expected an array, got ${typeof data}.`\n );\n\n const len = type.elementsType.length;\n for (let i = 0; i < len; i++) {\n dataSerializer.serialize(data[i], type.elementsType[i], writer);\n }\n\n return writer;\n }\n\n if (type.code === descriptors.unit.code) return writer;\n\n throw Error(\n `Serialization error: '0x${type.code.toString(16)}' type not implemented.`\n );\n },\n\n deserialize(type: SType, reader: SigmaByteReader): unknown {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return reader.readBoolean();\n case descriptors.byte.code:\n return reader.readByte();\n case descriptors.short.code:\n return reader.readShort();\n case descriptors.int.code:\n return reader.readInt();\n case descriptors.long.code:\n return reader.readLong();\n case descriptors.bigInt.code:\n return reader.readBigInt();\n case descriptors.groupElement.code:\n return reader.readBytes(GROUP_ELEMENT_LENGTH);\n case descriptors.sigmaProp.code: {\n if (reader.readByte() === PROVE_DLOG_OP) {\n return this.deserialize(descriptors.groupElement, reader);\n }\n\n break;\n }\n }\n } else {\n switch (type.code) {\n case descriptors.coll.code: {\n const length = reader.readVlq();\n const embeddedType = (type as SCollType).elementsType;\n\n switch (embeddedType.code) {\n case descriptors.bool.code:\n return reader.readBits(length);\n case descriptors.byte.code:\n return reader.readBytes(length);\n default: {\n const elements = new Array(length);\n for (let i = 0; i < length; i++) {\n elements[i] = this.deserialize(embeddedType, reader);\n }\n\n return elements;\n }\n }\n }\n case descriptors.tuple.code: {\n return (type as STupleType).elementsType.map((t) =>\n this.deserialize(t, reader)\n );\n }\n case descriptors.unit.code:\n return undefined;\n }\n }\n\n throw new Error(`Parsing error: '0x${type.code.toString(16)}' type not implemented.`);\n }\n};\n","import { assert, first, last } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport { isColl, isTuple, SCollType, STupleType, type SType } from \"../types\";\nimport {\n constructorCode,\n descriptors,\n getPrimitiveType,\n PRIMITIVE_TYPE_RANGE\n} from \"../types/descriptors\";\n\nexport const typeSerializer = {\n serialize(type: SType, writer: SigmaByteWriter) {\n if (type.embeddable) {\n writer.write(type.code);\n } else if (type.code === descriptors.unit.code) {\n writer.write(type.code);\n } else if (isColl(type)) {\n if (type.elementsType.embeddable) {\n writer.write(descriptors.coll.simpleCollTypeCode + type.elementsType.code);\n } else if (isColl(type.elementsType)) {\n const nestedColl = type.elementsType;\n if (nestedColl.elementsType.embeddable) {\n writer.write(\n descriptors.coll.nestedCollTypeCode + nestedColl.elementsType.code\n );\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(nestedColl, writer);\n }\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(type.elementsType, writer);\n }\n } else if (isTuple(type)) {\n switch (type.elementsType.length) {\n case 2: {\n const left = first(type.elementsType);\n const right = last(type.elementsType);\n\n if (left.embeddable) {\n if (left.code === right.code) {\n // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n writer.write(descriptors.tuple.symmetricPairTypeCode + left.code);\n } else {\n // Pair of types where first is primitive (`(_, Int)`)\n writer.write(descriptors.tuple.pairOneTypeCode + left.code);\n this.serialize(right, writer);\n }\n } else if (right.embeddable) {\n // Pair of types where second is primitive (`(Int, _)`)\n writer.write(descriptors.tuple.pairTwoTypeCode + right.code);\n this.serialize(left, writer);\n } else {\n // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n writer.write(descriptors.tuple.pairOneTypeCode);\n this.serialize(left, writer);\n this.serialize(right, writer);\n }\n\n return;\n }\n case 3:\n writer.write(descriptors.tuple.tripleTypeCode);\n break;\n case 4:\n writer.write(descriptors.tuple.quadrupleTypeCode);\n break;\n default: {\n const len = type.elementsType.length;\n assert(\n len >= 2 && len <= 255,\n \"Invalid type: tuples must have between 2 and 255 items.\"\n );\n\n // Generic tuple\n writer.write(descriptors.tuple.genericTupleTypeCode);\n writer.writeVLQ(len);\n }\n }\n\n for (let i = 0; i < type.elementsType.length; i++) {\n this.serialize(type.elementsType[i], writer);\n }\n } else {\n throw new Error(\"Serialization error: type not implemented.\");\n }\n },\n\n deserialize(r: SigmaByteReader): SType {\n const byte = r.readByte();\n assert(byte > 0, `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`);\n\n if (byte < descriptors.tuple.genericTupleTypeCode) {\n const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);\n const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);\n\n switch (ctorCode) {\n case constructorCode.embeddable: {\n return getPrimitiveType(embdCode);\n }\n case constructorCode.simpleColl: {\n const internal =\n embdCode === 0 ? this.deserialize(r) : getPrimitiveType(embdCode);\n\n return new SCollType(internal);\n }\n case constructorCode.nestedColl: {\n return new SCollType(new SCollType(getPrimitiveType(embdCode)));\n }\n case constructorCode.pairOne: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r)] // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n : [getPrimitiveType(embdCode), this.deserialize(r)]; // Pair of types where first is primitive (`(_, Int)`)\n\n return new STupleType(internal);\n }\n case constructorCode.pairTwo: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r), this.deserialize(r)] // Triple of types\n : [this.deserialize(r), getPrimitiveType(embdCode)];\n\n return new STupleType(internal);\n }\n case constructorCode.symmetricPair: {\n const internal =\n embdCode === 0\n ? [\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r)\n ] // Quadruple of types\n : [getPrimitiveType(embdCode), getPrimitiveType(embdCode)]; // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n\n return new STupleType(internal);\n }\n }\n }\n\n switch (byte) {\n case descriptors.tuple.genericTupleTypeCode: {\n const len = r.readVlq();\n const wrapped = new Array<SType>(len);\n for (let i = 0; i < len; i++) {\n wrapped[i] = this.deserialize(r);\n }\n\n return new STupleType(wrapped);\n }\n case descriptors.unit.code: {\n return descriptors.unit;\n }\n }\n\n throw new Error(\"Not implemented.\");\n }\n};\n","import { assert, isUndefined } from \"@fleet-sdk/common\";\nimport { type ByteInput, hex } from \"@fleet-sdk/crypto\";\nimport { SigmaByteReader, SigmaByteWriter } from \"./coders\";\nimport { dataSerializer } from \"./serializers/dataSerializer\";\nimport { typeSerializer } from \"./serializers/typeSerializer\";\nimport type { SType } from \"./types\";\n\nexport const MAX_CONSTANT_LENGTH = 4096;\n\nexport class SConstant<D = unknown, T extends SType = SType> {\n readonly #type: T;\n readonly #data: D;\n\n constructor(type: T, data: D) {\n this.#type = type;\n this.#data = type.coerce(data) as D;\n }\n\n static from<D, T extends SType = SType>(bytes: ByteInput): SConstant<D, T> {\n assert(bytes.length > 0, \"Empty constant bytes.\");\n\n const reader = new SigmaByteReader(bytes);\n const type = typeSerializer.deserialize(reader);\n const data = dataSerializer.deserialize(type, reader);\n\n return new SConstant(type as T, data as D);\n }\n\n get type(): T {\n return this.#type;\n }\n\n get data(): D {\n return this.#data;\n }\n\n toBytes(): Uint8Array {\n const writer = new SigmaByteWriter(MAX_CONSTANT_LENGTH);\n typeSerializer.serialize(this.type, writer);\n dataSerializer.serialize(this.data, this.type, writer);\n\n return writer.toBytes();\n }\n\n toHex(): string {\n return hex.encode(this.toBytes());\n }\n}\n\n/**\n * Decodes a byte input into a Sigma constant of type `SConstant<D, T>`.\n *\n * @template D - The data type of the constant.\n * @template T - The type of the constant.\n * @param value - The value to decode.\n * @returns The decoded constant or `undefined` if the value is `undefined` or decoding fails.\n */\nexport function decode<D = unknown, T extends SType = SType>(\n value?: ByteInput\n): SConstant<D, T> | undefined {\n if (value === undefined) return;\n\n try {\n return SConstant.from<D, T>(value);\n } catch {\n return;\n }\n}\n\n/**\n * Returns the `SType` of the given value.\n *\n * @param value - The value to check the SType of.\n * @returns The SType of the value, or `undefined` if the value is `undefined` or\n * deserialization fails.\n */\nexport function stypeof(value?: ByteInput): SType | undefined {\n if (!value) return;\n\n try {\n return typeSerializer.deserialize(new SigmaByteReader(value));\n } catch {\n return;\n }\n}\n\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput, mode: \"strict\"): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput | undefined, mode: \"safe\"): T | undefined;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"strict\" | \"safe\" = \"strict\"\n) {\n if (mode === \"strict\") return SConstant.from<T>(constant ?? \"\").data;\n if (!constant) return;\n\n try {\n return SConstant.from<T>(constant).data;\n } catch {\n return;\n }\n}\n","import {\n type Amount,\n type Box,\n type BoxCandidate,\n byteSizeOf,\n ensureBigInt,\n isDefined,\n isEmpty,\n isUndefined,\n type NonMandatoryRegisters,\n some,\n type TokenAmount\n} from \"@fleet-sdk/common\";\nimport { estimateVLQSize, SigmaByteWriter } from \"../coders\";\n\nconst MAX_UINT16_VALUE = 65535;\n\nexport function serializeBox(box: Box<Amount>): SigmaByteWriter;\nexport function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;\nexport function serializeBox(\n box: BoxCandidate<Amount>,\n writer: SigmaByteWriter,\n distinctTokenIds: string[]\n): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount> | BoxCandidate<Amount>,\n writer = new SigmaByteWriter(5_0000),\n distinctTokenIds?: string[]\n): SigmaByteWriter {\n writer.writeBigVLQ(ensureBigInt(box.value));\n writer.writeHex(box.ergoTree);\n writer.writeVLQ(box.creationHeight);\n writeTokens(writer, box.assets, distinctTokenIds);\n writeRegisters(writer, box.additionalRegisters);\n\n if (isDefined(distinctTokenIds)) return writer;\n if (!isBox(box)) throw new Error(\"Invalid box type.\");\n return writer.writeHex(box.transactionId).writeVLQ(box.index);\n}\n\nfunction isBox<T extends Amount>(box: Box<Amount> | BoxCandidate<Amount>): box is Box<T> {\n const castedBox = box as Box<T>;\n\n return isDefined(castedBox.transactionId) && isDefined(castedBox.index);\n}\n\nfunction writeTokens(\n writer: SigmaByteWriter,\n tokens: TokenAmount<Amount>[],\n tokenIds?: string[]\n): void {\n if (isEmpty(tokens)) {\n writer.write(0);\n\n return;\n }\n\n writer.writeVLQ(tokens.length);\n if (some(tokenIds)) {\n tokens.map((token) =>\n writer\n .writeVLQ(tokenIds.indexOf(token.tokenId))\n .writeBigVLQ(ensureBigInt(token.amount))\n );\n } else {\n tokens.map((token) =>\n writer.writeHex(token.tokenId).writeBigVLQ(ensureBigInt(token.amount))\n );\n }\n}\n\nfunction writeRegisters(writer: SigmaByteWriter, registers: NonMandatoryRegisters): void {\n const keys = Object.keys(registers).sort();\n let length = 0;\n\n for (const key of keys) {\n if (registers[key as keyof NonMandatoryRegisters]) length++;\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const register = registers[key as keyof NonMandatoryRegisters];\n if (isDefined(register)) writer.writeHex(register);\n }\n}\n\n/**\n * Estimates the byte size a box.\n * @returns byte size of the box.\n */\nexport function estimateBoxSize(\n box: Box<Amount> | BoxCandidate<Amount>,\n withValue?: Amount\n): number {\n if (isUndefined(box.creationHeight)) {\n throw new Error(\"Box size estimation error: creation height is undefined.\");\n }\n\n let size = 0;\n\n size += estimateVLQSize(isDefined(withValue) ? withValue : box.value);\n size += byteSizeOf(box.ergoTree);\n size += estimateVLQSize(box.creationHeight);\n\n size += estimateVLQSize(box.assets.length);\n for (const asset of box.assets) {\n size += byteSizeOf(asset.tokenId) + estimateVLQSize(asset.amount);\n }\n\n let registersLength = 0;\n for (const key in box.additionalRegisters) {\n const register = box.additionalRegisters[key as keyof NonMandatoryRegisters];\n if (register) {\n size += byteSizeOf(register);\n registersLength++;\n }\n }\n\n size += estimateVLQSize(registersLength);\n size += 32; // transaction id (BLAKE2b 256 hash)\n size += estimateVLQSize(isBox(box) ? box.index : MAX_UINT16_VALUE);\n\n return size;\n}\n","import {\n type Amount,\n type BoxCandidate,\n type ContextExtension,\n type DataInput,\n isDefined,\n type UnsignedInput\n} from \"@fleet-sdk/common\";\nimport { SigmaByteWriter } from \"../coders\";\nimport { serializeBox } from \"./boxSerializer\";\n\nexport type MinimalUnsignedTransaction = {\n inputs: readonly UnsignedInput[];\n dataInputs: readonly DataInput[];\n outputs: readonly BoxCandidate<Amount>[];\n};\n\nexport function serializeTransaction(\n transaction: MinimalUnsignedTransaction\n): SigmaByteWriter {\n const writer = new SigmaByteWriter(100_000);\n\n // write inputs\n writer.writeVLQ(transaction.inputs.length);\n transaction.inputs.map((input) => writeInput(writer, input));\n\n // write data inputs\n writer.writeVLQ(transaction.dataInputs.length);\n transaction.dataInputs.map((dataInput) => writer.writeHex(dataInput.boxId));\n\n // write distinct token IDs\n const distinctTokenIds = getDistinctTokenIds(transaction.outputs);\n writer.writeVLQ(distinctTokenIds.length);\n distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));\n\n // write outputs\n writer.writeVLQ(transaction.outputs.length);\n transaction.outputs.map((output) => serializeBox(output, writer, distinctTokenIds));\n\n return writer;\n}\n\nfunction writeInput(writer: SigmaByteWriter, input: UnsignedInput): void {\n writer.writeHex(input.boxId);\n writer.write(0); // empty proof\n writeExtension(writer, input.extension);\n}\n\nfunction writeExtension(writer: SigmaByteWriter, extension: ContextExtension): void {\n const keys = Object.keys(extension);\n let length = 0;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n length++;\n }\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n writer.writeVLQ(Number(key)).writeHex(ext);\n }\n }\n}\n\nfunction getDistinctTokenIds(outputs: readonly BoxCandidate<Amount>[]) {\n const tokenIds = new Set<string>();\n outputs.flatMap((output) => output.assets.map((asset) => tokenIds.add(asset.tokenId)));\n\n return Array.from(tokenIds);\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ensureBigInt, _0n, _128n, isEmpty, assert, first, last, isUndefined, isDefined, some, byteSizeOf, _7n, _1n, _63n, _127n } from '@fleet-sdk/common';
1
+ import { ensureBigInt, _0n, _128n, isEmpty, assert, first, last, isDefined, some, isUndefined, byteSizeOf, _7n, _1n, _63n, _127n } from '@fleet-sdk/common';
2
2
  import { ensureBytes, hex, blake2b256 } from '@fleet-sdk/crypto';
3
3
 
4
4
  // src/coders/sigmaByteReader.ts
@@ -35,9 +35,7 @@ function negateAndMask(value) {
35
35
  function writeVLQ(writer, value) {
36
36
  if (value === 0) return writer.write(0);
37
37
  if (value < 0) {
38
- throw new RangeError(
39
- "Variable Length Quantity not supported for negative numbers."
40
- );
38
+ throw new RangeError("Variable Length Quantity not supported for negative numbers.");
41
39
  }
42
40
  let val = value;
43
41
  do {
@@ -65,9 +63,7 @@ function readVLQ(reader) {
65
63
  function writeBigVLQ(writer, value) {
66
64
  if (value === _0n) return writer.write(0);
67
65
  if (value < _0n) {
68
- throw new RangeError(
69
- "Variable Length Quantity not supported for negative numbers"
70
- );
66
+ throw new RangeError("Variable Length Quantity not supported for negative numbers");
71
67
  }
72
68
  let val = value;
73
69
  do {
@@ -480,10 +476,7 @@ function genericProxy(ctor, handler) {
480
476
  }
481
477
  var SByte = monoProxy(SByteType, descriptors.byte);
482
478
  var SBool = monoProxy(SBoolType, descriptors.bool);
483
- var SShort = monoProxy(
484
- SShortType,
485
- descriptors.short
486
- );
479
+ var SShort = monoProxy(SShortType, descriptors.short);
487
480
  var SInt = monoProxy(SIntType, descriptors.int);
488
481
  var SLong = monoProxy(
489
482
  SLongType,
@@ -493,37 +486,31 @@ var SBigInt = monoProxy(
493
486
  SBigIntType,
494
487
  descriptors.bigInt
495
488
  );
496
- var SGroupElement = monoProxy(SGroupElementType, descriptors.groupElement);
489
+ var SGroupElement = monoProxy(
490
+ SGroupElementType,
491
+ descriptors.groupElement
492
+ );
497
493
  var SSigmaProp = monoProxy(
498
494
  SSigmaPropType,
499
495
  descriptors.sigmaProp
500
496
  );
501
497
  var SUnit = monoProxy(SUnitType, void 0, true);
502
- var SColl = genericProxy(
503
- SCollType,
504
- (target, _, args) => {
505
- const [type, elements] = args;
506
- const elementsType = type();
507
- if (!elements) return () => new target(elementsType);
508
- return new SConstant(new target(elementsType), elements);
498
+ var SColl = genericProxy(SCollType, (target, _, args) => {
499
+ const [type, elements] = args;
500
+ const elementsType = type();
501
+ if (!elements) return () => new target(elementsType);
502
+ return new SConstant(new target(elementsType), elements);
503
+ });
504
+ var SPair = genericProxy(STupleType, (target, _, args) => {
505
+ const [left, right] = args;
506
+ if (typeof left === "function" && typeof right === "function") {
507
+ return () => new target([left(), right()]);
509
508
  }
510
- );
511
- var SPair = genericProxy(
512
- STupleType,
513
- (target, _, args) => {
514
- const [left, right] = args;
515
- if (typeof left === "function" && typeof right === "function") {
516
- return () => new target([left(), right()]);
517
- }
518
- if (left instanceof SConstant && right instanceof SConstant) {
519
- return new SConstant(new target([left.type, right.type]), [
520
- left.data,
521
- right.data
522
- ]);
523
- }
524
- throw new Error("Invalid tuple declaration.");
509
+ if (left instanceof SConstant && right instanceof SConstant) {
510
+ return new SConstant(new target([left.type, right.type]), [left.data, right.data]);
525
511
  }
526
- );
512
+ throw new Error("Invalid tuple declaration.");
513
+ });
527
514
 
528
515
  // src/serializers/dataSerializer.ts
529
516
  var GROUP_ELEMENT_LENGTH = 33;
@@ -552,9 +539,7 @@ var dataSerializer = {
552
539
  writer.write(PROVE_DLOG_OP);
553
540
  return dataSerializer.serialize(node.data, node.type, writer);
554
541
  }
555
- throw Error(
556
- "Serialization error: SigmaProp operation not implemented."
557
- );
542
+ throw Error("Serialization error: SigmaProp operation not implemented.");
558
543
  }
559
544
  }
560
545
  }
@@ -565,10 +550,7 @@ var dataSerializer = {
565
550
  `SColl[Byte] expected an UInt8Array, got ${typeof data}.`
566
551
  );
567
552
  } else {
568
- assert(
569
- Array.isArray(data),
570
- `SColl expected an array, got ${typeof data}.`
571
- );
553
+ assert(Array.isArray(data), `SColl expected an array, got ${typeof data}.`);
572
554
  }
573
555
  writer.writeVLQ(data.length);
574
556
  switch (type.elementsType.code) {
@@ -654,9 +636,7 @@ var dataSerializer = {
654
636
  return void 0;
655
637
  }
656
638
  }
657
- throw new Error(
658
- `Parsing error: '0x${type.code.toString(16)}' type not implemented.`
659
- );
639
+ throw new Error(`Parsing error: '0x${type.code.toString(16)}' type not implemented.`);
660
640
  }
661
641
  };
662
642
  var typeSerializer = {
@@ -667,9 +647,7 @@ var typeSerializer = {
667
647
  writer.write(type.code);
668
648
  } else if (isColl(type)) {
669
649
  if (type.elementsType.embeddable) {
670
- writer.write(
671
- descriptors.coll.simpleCollTypeCode + type.elementsType.code
672
- );
650
+ writer.write(descriptors.coll.simpleCollTypeCode + type.elementsType.code);
673
651
  } else if (isColl(type.elementsType)) {
674
652
  const nestedColl = type.elementsType;
675
653
  if (nestedColl.elementsType.embeddable) {
@@ -731,10 +709,7 @@ var typeSerializer = {
731
709
  },
732
710
  deserialize(r) {
733
711
  const byte = r.readByte();
734
- assert(
735
- byte > 0,
736
- `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`
737
- );
712
+ assert(byte > 0, `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`);
738
713
  if (byte < descriptors.tuple.genericTupleTypeCode) {
739
714
  const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);
740
715
  const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);
@@ -817,11 +792,21 @@ var SConstant = class _SConstant {
817
792
  return hex.encode(this.toBytes());
818
793
  }
819
794
  };
820
- function decode(value, coder) {
821
- if (isUndefined(value)) return;
822
- const data = parse(value, "safe");
823
- if (isUndefined(data)) return;
824
- return coder ? coder(data) : data;
795
+ function decode(value) {
796
+ if (value === void 0) return;
797
+ try {
798
+ return SConstant.from(value);
799
+ } catch {
800
+ return;
801
+ }
802
+ }
803
+ function stypeof(value) {
804
+ if (!value) return;
805
+ try {
806
+ return typeSerializer.deserialize(new SigmaByteReader(value));
807
+ } catch {
808
+ return;
809
+ }
825
810
  }
826
811
  function parse(constant, mode = "strict") {
827
812
  if (mode === "strict") return SConstant.from(constant ?? "").data;
@@ -911,9 +896,7 @@ function serializeTransaction(transaction) {
911
896
  writer.writeVLQ(distinctTokenIds.length);
912
897
  distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));
913
898
  writer.writeVLQ(transaction.outputs.length);
914
- transaction.outputs.map(
915
- (output) => serializeBox(output, writer, distinctTokenIds)
916
- );
899
+ transaction.outputs.map((output) => serializeBox(output, writer, distinctTokenIds));
917
900
  return writer;
918
901
  }
919
902
  function writeInput(writer, input) {
@@ -941,12 +924,10 @@ function writeExtension(writer, extension) {
941
924
  }
942
925
  function getDistinctTokenIds(outputs) {
943
926
  const tokenIds = /* @__PURE__ */ new Set();
944
- outputs.flatMap(
945
- (output) => output.assets.map((asset) => tokenIds.add(asset.tokenId))
946
- );
927
+ outputs.flatMap((output) => output.assets.map((asset) => tokenIds.add(asset.tokenId)));
947
928
  return Array.from(tokenIds);
948
929
  }
949
930
 
950
- export { 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 };
951
- //# sourceMappingURL=out.js.map
931
+ export { 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, stypeof, typeSerializer };
932
+ //# sourceMappingURL=index.mjs.map
952
933
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/coders/sigmaByteReader.ts","../src/coders/bigint.ts","../src/coders/vlq.ts","../src/coders/zigZag.ts","../src/coders/sigmaByteWriter.ts","../src/sigmaConstant.ts","../src/serializers/dataSerializer.ts","../src/types/base.ts","../src/types/primitives.ts","../src/types/monomorphics.ts","../src/types/descriptors.ts","../src/types/generics.ts","../src/types/constructors.ts","../src/serializers/typeSerializer.ts","../src/serializers/boxSerializer.ts","../src/serializers/transactionSerializer.ts"],"names":["hex","_0n","assert","ensureBigInt","isEmpty","first","isUndefined","isDefined"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAyB,aAAa,WAAW;;;ACDjD,SAAS,KAAK,aAAa;AAOpB,SAAS,YAAYA,MAAqB;AAE/C,QAAM,QAAQ,OAAOA,KAAI,SAAS,IAAI,MAAMA,IAAG,KAAK,KAAKA,IAAG,EAAE;AAC9D,QAAM,WAAW,OAAO,SAASA,KAAI,MAAM,GAAG,CAAC,GAAG,EAAE;AACpD,MAAI,MAAO,SAAU,QAAO,CAAC,cAAc,KAAK;AAEhD,SAAO;AACT;AAOO,SAAS,YAAY,OA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AoB,SAA0C;AACrE,QAAM,WAAW,oBAAI,IAAY;AACjC,UAAQ;AAAA,IAAQ,CAAC,WACf,OAAO,OAAO,IAAI,CAAC,UAAU,SAAS,IAAI,MAAM,OAAO,CAAC;AAAA,EAC1D;AAEA,SAAO,MAAM,KAAK,QAAQ;AAC5B","sourcesContent":["import { isEmpty } from \"@fleet-sdk/common\";\nimport { type ByteInput, ensureBytes, hex } from \"@fleet-sdk/crypto\";\nimport { hexToBigInt } from \"./bigint\";\nimport { readBigVLQ, readVLQ } from \"./vlq\";\nimport { zigZagDecode, zigZagDecodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteReader {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get isEmpty(): boolean {\n return isEmpty(this.#bytes);\n }\n\n constructor(bytes: ByteInput) {\n this.#bytes = ensureBytes(bytes);\n this.#cursor = 0;\n }\n\n public readBoolean(): boolean {\n return this.readByte() === 0x01;\n }\n\n public readBits(length: number): ArrayLike<boolean> {\n const bits = new Array<boolean>(length);\n let bitOffset = 0;\n\n for (let i = 0; i < length; i++) {\n const bit = (this.#bytes[this.#cursor] >> bitOffset++) & 1;\n bits[i] = bit === 1;\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return bits;\n }\n\n public readByte(): number {\n return this.#bytes[this.#cursor++];\n }\n\n public readBytes(length: number): Uint8Array {\n return this.#bytes.subarray(this.#cursor, (this.#cursor += length));\n }\n\n public readVlq(): number {\n return readVLQ(this);\n }\n\n public readShort(): number {\n return Number(zigZagDecode(readVLQ(this)));\n }\n\n public readInt(): number {\n return Number(this.readLong());\n }\n\n public readLong(): bigint {\n return zigZagDecodeBigInt(readBigVLQ(this));\n }\n\n public readBigInt(): bigint {\n const len = readVLQ(this);\n return hexToBigInt(hex.encode(this.readBytes(len)));\n }\n}\n","import { _0n, first } from \"@fleet-sdk/common\";\n\n/**\n * Converts a hex string to bigint.\n * @param hex The hex string to be converted.\n * @returns The bigint value represented by the hex string.\n */\nexport function hexToBigInt(hex: string): bigint {\n // https://coolaj86.com/articles/convert-hex-to-decimal-with-js-bigints/\n const value = BigInt(hex.length % 2 ? `0x0${hex}` : `0x${hex}`);\n const highByte = Number.parseInt(hex.slice(0, 2), 16);\n if (0x80 & highByte) return -negateAndMask(value);\n\n return value;\n}\n\n/**\n * Serializes a `BigInt` to a hex string\n * @param value The bigint value to be serialized\n * @returns Hex representation for the provided `number`.\n */\nexport function bigIntToHex(value: bigint): string {\n // implementation inspired on\n // https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/\n const positive = value >= _0n;\n let hex = (positive ? value : negateAndMask(value)).toString(16);\n if (hex.length % 2) hex = `0${hex}`;\n\n if (positive && 0x80 & Number.parseInt(hex.slice(0, 2), 16)) {\n return `00${hex}`;\n }\n\n return hex;\n}\n\n/**\n * Returns the two’s complement of a bigint value.\n * @param value The bigint value to negate.\n * @returns The two’s complement of `number` as a bigint.\n */\nexport function negateAndMask(value: bigint): bigint {\n let val = value;\n const negative = val < _0n;\n if (negative) val = -val; // turn into a positive number\n\n const bits = val.toString(2);\n let len = bits.length; // convert to binary\n const mod = len % 8;\n\n if (mod > 0) {\n len += 8 - mod;\n } else if (negative && first(bits) === \"1\" && bits.indexOf(\"1\", 1) !== -1) {\n len += 8;\n }\n\n const mask = (1n << BigInt(len)) - 1n; // create a mask\n return (~val & mask) + 1n; // invert bits, mask it, and add one\n}\n","import { _0n, _127n, _128n, _7n, ensureBigInt } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader } from \"./sigmaByteReader\";\nimport type { SigmaByteWriter } from \"./sigmaByteWriter\";\n\n/**\n * A **variable-length quantity (VLQ)** is a universal code that uses an arbitrary number\n * of binary octets (eight-bit bytes) to represent an arbitrarily large integer. A VLQ\n * is essentially a base-128 representation of an unsigned integer with the addition of\n * the eighth bit to mark continuation of bytes. VLQ is identical to LEB128 except in\n * endianness. See the example below.\n */\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeVLQ(\n writer: SigmaByteWriter,\n value: number\n): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n if (value === 0) return writer.write(0);\n if (value < 0) {\n throw new RangeError(\n \"Variable Length Quantity not supported for negative numbers.\"\n );\n }\n\n let val = value;\n do {\n let lower7bits = val & 0x7f;\n val >>= 7;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readVLQ(reader: SigmaByteReader): number {\n if (reader.isEmpty) {\n return 0;\n }\n\n let value = 0;\n let shift = 0;\n let lower7bits = 0;\n\n do {\n lower7bits = reader.readByte();\n value |= (lower7bits & 0x7f) << shift;\n shift += 7;\n } while ((lower7bits & 0x80) !== 0);\n\n return value;\n}\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Big integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeBigVLQ(\n writer: SigmaByteWriter,\n value: bigint\n): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n\n if (value === _0n) return writer.write(0);\n if (value < _0n) {\n throw new RangeError(\n \"Variable Length Quantity not supported for negative numbers\"\n );\n }\n\n let val = value;\n do {\n let lower7bits = Number(val & _127n);\n val >>= _7n;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned big integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readBigVLQ(reader: SigmaByteReader): bigint {\n if (reader.isEmpty) return _0n;\n\n let value = _0n;\n let shift = _0n;\n let lower7bits = _0n;\n\n do {\n lower7bits = BigInt(reader.readByte());\n value |= (lower7bits & _127n) << shift;\n shift += _7n;\n } while ((lower7bits & _128n) !== _0n);\n\n return value;\n}\n\n/**\n * Estimates the byte size of a given unsigned integer.\n * @param value: the value to be evaluated.\n * @returns the byte size of the value.\n */\nexport function estimateVLQSize(value: number | bigint | string): number {\n let size = 0;\n let val = value;\n if (typeof val === \"number\") {\n do {\n size++;\n val = Math.floor(val / 128);\n } while (val > 0);\n\n return size;\n }\n\n val = ensureBigInt(val);\n do {\n size++;\n val /= _128n;\n } while (val > _0n);\n\n return size;\n}\n","import { _1n, _63n } from \"@fleet-sdk/common\";\n\n/**\n * ZigZag encoding maps signed integers to unsigned integers so that numbers\n * with a small absolute value (for instance, -1) have a small variant encoded\n * value too. It does this in a way that \"zig-zags\" back and forth through the\n * positive and negative integers, so that -1 is encoded as 1, 1 is encoded as 2,\n * -2 is encoded as 3, and so on.\n * @see https://developers.google.com/protocol-buffers/docs/encoding#types\n */\n\n/**\n * Encode a signed integer.\n * @param input Signed integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncode(input: number): number {\n return (input << 1) ^ (input >> 63);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed integer\n */\nexport function zigZagDecode(input: number): number {\n return (input >> 1) ^ -(input & 1);\n}\n\n/**\n * Encode a signed big integer.\n * @param input Signed big integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncodeBigInt(input: bigint): bigint {\n return (input << _1n) ^ (input >> _63n);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed big integer\n */\nexport function zigZagDecodeBigInt(input: bigint): bigint {\n return (input >> _1n) ^ -(input & _1n);\n}\n","import { blake2b256, type Coder, hex } from \"@fleet-sdk/crypto\";\nimport { bigIntToHex } from \"./bigint\";\nimport { writeBigVLQ, writeVLQ } from \"./vlq\";\nimport { zigZagEncode, zigZagEncodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteWriter {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get length() {\n return this.#cursor;\n }\n\n constructor(length: number) {\n this.#bytes = new Uint8Array(length);\n this.#cursor = 0;\n }\n\n public writeBoolean(value: boolean): SigmaByteWriter {\n this.write(value === true ? 0x01 : 0x00);\n\n return this;\n }\n\n public writeVLQ(value: number): SigmaByteWriter {\n return writeVLQ(this, value);\n }\n\n public writeBigVLQ(value: bigint): SigmaByteWriter {\n return writeBigVLQ(this, value);\n }\n\n public writeShort(value: number): SigmaByteWriter {\n this.writeVLQ(zigZagEncode(value));\n return this;\n }\n\n public writeInt(value: number): SigmaByteWriter {\n this.writeLong(BigInt(value));\n return this;\n }\n\n public writeLong(value: bigint): SigmaByteWriter {\n this.writeBigVLQ(zigZagEncodeBigInt(value));\n return this;\n }\n\n public write(byte: number): SigmaByteWriter {\n this.#bytes[this.#cursor++] = byte;\n return this;\n }\n\n public writeBytes(bytes: ArrayLike<number>): SigmaByteWriter {\n this.#bytes.set(bytes, this.#cursor);\n this.#cursor += bytes.length;\n return this;\n }\n\n public writeHex(bytesHex: string): SigmaByteWriter {\n return this.writeBytes(hex.decode(bytesHex));\n }\n\n public writeBits(bits: ArrayLike<boolean>): SigmaByteWriter {\n let bitOffset = 0;\n\n for (let i = 0; i < bits.length; i++) {\n if (bits[i]) {\n this.#bytes[this.#cursor] |= 1 << bitOffset++;\n } else {\n this.#bytes[this.#cursor] &= ~(1 << bitOffset++);\n }\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return this;\n }\n\n public writeBigInt(value: bigint): SigmaByteWriter {\n const hex = bigIntToHex(value);\n return this.writeVLQ(hex.length / 2).writeHex(hex);\n }\n\n public writeChecksum(length = 4, hashFn = blake2b256): SigmaByteWriter {\n const hash = hashFn(this.toBytes());\n return this.writeBytes(length ? hash.subarray(0, length) : hash);\n }\n\n public encode<T>(coder: Coder<Uint8Array, T>): T {\n return coder.encode(this.toBytes());\n }\n\n public toBytes(): Uint8Array {\n if (this.#cursor === this.#bytes.length) return this.#bytes;\n return this.#bytes.subarray(0, this.#cursor);\n }\n}\n","import { assert, isUndefined } from \"@fleet-sdk/common\";\nimport { type ByteInput, hex } from \"@fleet-sdk/crypto\";\nimport { SigmaByteReader, SigmaByteWriter } from \"./coders\";\nimport { dataSerializer } from \"./serializers/dataSerializer\";\nimport { typeSerializer } from \"./serializers/typeSerializer\";\nimport type { SType } from \"./types\";\n\nexport const MAX_CONSTANT_LENGTH = 4096;\n\nexport class SConstant<D = unknown, T extends SType = SType> {\n readonly #type: T;\n readonly #data: D;\n\n constructor(type: T, data: D) {\n this.#type = type;\n this.#data = type.coerce(data) as D;\n }\n\n static from<D, T extends SType = SType>(bytes: ByteInput): SConstant<D, T> {\n assert(bytes.length > 0, \"Empty constant bytes.\");\n\n const reader = new SigmaByteReader(bytes);\n const type = typeSerializer.deserialize(reader);\n const data = dataSerializer.deserialize(type, reader);\n\n return new SConstant(type as T, data as D);\n }\n\n get type(): T {\n return this.#type;\n }\n\n get data(): D {\n return this.#data;\n }\n\n toBytes(): Uint8Array {\n const writer = new SigmaByteWriter(MAX_CONSTANT_LENGTH);\n typeSerializer.serialize(this.type, writer);\n dataSerializer.serialize(this.data, this.type, writer);\n\n return writer.toBytes();\n }\n\n toHex(): string {\n return hex.encode(this.toBytes());\n }\n}\n\nexport function decode<T>(value: ByteInput | undefined): T | undefined;\nexport function decode<T, K>(\n value: ByteInput | undefined,\n coder: (input: T) => K\n): K | undefined;\nexport function decode<T, K>(\n value: ByteInput | undefined,\n coder?: (input: T) => K\n): T | K | undefined {\n if (isUndefined(value)) return;\n const data = parse<T>(value, \"safe\");\n if (isUndefined(data)) return;\n\n return coder ? coder(data) : data;\n}\n\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput, mode: \"strict\"): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"safe\"\n): T | undefined;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"strict\" | \"safe\" = \"strict\"\n) {\n if (mode === \"strict\") return SConstant.from<T>(constant ?? \"\").data;\n if (!constant) return;\n\n try {\n return SConstant.from<T>(constant).data;\n } catch {\n return;\n }\n}\n","import { assert } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport {\n isColl,\n isTuple,\n type SCollType,\n type STupleType,\n type SType\n} from \"../types\";\nimport { descriptors } from \"../types/descriptors\";\n\nconst GROUP_ELEMENT_LENGTH = 33;\nconst PROVE_DLOG_OP = 0xcd;\n\nexport const dataSerializer = {\n serialize(\n data: unknown,\n type: SType,\n writer: SigmaByteWriter\n ): SigmaByteWriter {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return writer.writeBoolean(data as boolean);\n case descriptors.byte.code:\n return writer.write(data as number);\n case descriptors.short.code:\n return writer.writeShort(data as number);\n case descriptors.int.code:\n return writer.writeInt(data as number);\n case descriptors.long.code:\n return writer.writeLong(data as bigint);\n case descriptors.bigInt.code:\n return writer.writeBigInt(data as bigint);\n case descriptors.groupElement.code:\n return writer.writeBytes(data as Uint8Array);\n case descriptors.sigmaProp.code: {\n const node = data as SConstant<SConstant<Uint8Array>>;\n if (node.type === descriptors.groupElement) {\n writer.write(PROVE_DLOG_OP);\n return dataSerializer.serialize(node.data, node.type, writer);\n }\n\n throw Error(\n \"Serialization error: SigmaProp operation not implemented.\"\n );\n }\n }\n }\n\n if (isColl(type)) {\n if (type.elementsType.code === descriptors.byte.code) {\n assert(\n data instanceof Uint8Array,\n `SColl[Byte] expected an UInt8Array, got ${typeof data}.`\n );\n } else {\n assert(\n Array.isArray(data),\n `SColl expected an array, got ${typeof data}.`\n );\n }\n\n writer.writeVLQ(data.length);\n switch (type.elementsType.code) {\n case descriptors.bool.code: {\n return writer.writeBits(data as boolean[]);\n }\n case descriptors.byte.code: {\n return writer.writeBytes(data as Uint8Array);\n }\n default: {\n for (let i = 0; i < data.length; i++) {\n dataSerializer.serialize(data[i], type.elementsType, writer);\n }\n\n return writer;\n }\n }\n }\n\n if (isTuple(type)) {\n assert(\n Array.isArray(data),\n `STupleType serialization expected an array, got ${typeof data}.`\n );\n\n const len = type.elementsType.length;\n for (let i = 0; i < len; i++) {\n dataSerializer.serialize(data[i], type.elementsType[i], writer);\n }\n\n return writer;\n }\n\n if (type.code === descriptors.unit.code) return writer;\n\n throw Error(\n `Serialization error: '0x${type.code.toString(16)}' type not implemented.`\n );\n },\n\n deserialize(type: SType, reader: SigmaByteReader): unknown {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return reader.readBoolean();\n case descriptors.byte.code:\n return reader.readByte();\n case descriptors.short.code:\n return reader.readShort();\n case descriptors.int.code:\n return reader.readInt();\n case descriptors.long.code:\n return reader.readLong();\n case descriptors.bigInt.code:\n return reader.readBigInt();\n case descriptors.groupElement.code:\n return reader.readBytes(GROUP_ELEMENT_LENGTH);\n case descriptors.sigmaProp.code: {\n if (reader.readByte() === PROVE_DLOG_OP) {\n return this.deserialize(descriptors.groupElement, reader);\n }\n\n break;\n }\n }\n } else {\n switch (type.code) {\n case descriptors.coll.code: {\n const length = reader.readVlq();\n const embeddedType = (type as SCollType).elementsType;\n\n switch (embeddedType.code) {\n case descriptors.bool.code:\n return reader.readBits(length);\n case descriptors.byte.code:\n return reader.readBytes(length);\n default: {\n const elements = new Array(length);\n for (let i = 0; i < length; i++) {\n elements[i] = this.deserialize(embeddedType, reader);\n }\n\n return elements;\n }\n }\n }\n case descriptors.tuple.code: {\n return (type as STupleType).elementsType.map((t) =>\n this.deserialize(t, reader)\n );\n }\n case descriptors.unit.code:\n return undefined;\n }\n }\n\n throw new Error(\n `Parsing error: '0x${type.code.toString(16)}' type not implemented.`\n );\n }\n};\n","export abstract class SType<I = unknown, O = I> {\n abstract get code(): number;\n abstract get embeddable(): boolean;\n\n coerce(data: I): O {\n // a bit hacky but most of types will not need a specific coercion function.\n return data as unknown as O;\n }\n\n abstract toString(): string;\n}\n\nexport abstract class SMonomorphicType<I, O = I> extends SType<I, O> {\n abstract get code(): number;\n\n get embeddable(): boolean {\n return false;\n }\n}\n\nexport abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {\n abstract get code(): number;\n\n override get embeddable(): boolean {\n return true;\n }\n}\n\nexport abstract class SGenericType<T extends SType | SType[]> extends SType {\n readonly #internalType: T;\n\n constructor(type: T) {\n super();\n this.#internalType = type;\n }\n\n abstract get code(): number;\n\n get elementsType(): T {\n return this.#internalType;\n }\n\n get embeddable(): boolean {\n return false;\n }\n}\n","import { ensureBigInt } from \"@fleet-sdk/common\";\nimport { hex } from \"@fleet-sdk/crypto\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { SPrimitiveType } from \"./base\";\nimport type { BigIntInput, ByteInput } from \"./constructors\";\n\nexport class SBoolType extends SPrimitiveType<boolean> {\n get code(): 0x01 {\n return 0x01;\n }\n\n toString(): string {\n return \"SBool\";\n }\n}\n\nexport class SByteType extends SPrimitiveType<number> {\n get code(): 0x02 {\n return 0x02;\n }\n\n toString(): string {\n return \"SByte\";\n }\n}\n\nexport class SShortType extends SPrimitiveType<number> {\n get code(): 0x03 {\n return 0x03;\n }\n\n toString(): string {\n return \"SShort\";\n }\n}\n\nexport class SIntType extends SPrimitiveType<number> {\n get code(): 0x04 {\n return 0x04;\n }\n\n toString(): string {\n return \"SInt\";\n }\n}\n\nexport class SLongType extends SPrimitiveType<BigIntInput, bigint> {\n get code(): 0x05 {\n return 0x05;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SLong\";\n }\n}\n\nexport class SBigIntType extends SPrimitiveType<string | bigint, bigint> {\n get code(): number {\n return 0x06;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SBigInt\";\n }\n}\n\nexport class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {\n get code(): 0x07 {\n return 0x07;\n }\n\n override coerce(data: ByteInput): Uint8Array {\n return typeof data === \"string\" ? hex.decode(data) : data;\n }\n\n toString(): string {\n return \"SGroupElement\";\n }\n}\n\nexport class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {\n get code(): 0x08 {\n return 0x08;\n }\n\n toString(): string {\n return \"SSigmaProp\";\n }\n}\n","import { SMonomorphicType } from \"./base\";\n\nexport class SUnitType extends SMonomorphicType<undefined> {\n get code(): 0x62 {\n return 0x62;\n }\n\n toString(): string {\n return \"SUnit\";\n }\n}\n","import type { SType } from \"./base\";\nimport type { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport const constructorCode = Object.freeze({\n embeddable: 0,\n\n simpleColl: 1,\n nestedColl: 2,\n\n option: 3,\n optionCollection: 4,\n\n pairOne: 5,\n pairTwo: 6,\n symmetricPair: 7,\n genericTuple: 8\n});\n\nconst MAX_PRIMITIVE_TYPE_CODE = 0x0b;\nexport const PRIMITIVE_TYPE_RANGE = MAX_PRIMITIVE_TYPE_CODE + 0x01;\nconst typeCodeOf = (ctor: number) => PRIMITIVE_TYPE_RANGE * ctor;\n\ntype Descriptor = { code: number; embeddable: boolean };\n\nconst collDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.simpleColl),\n embeddable: false,\n simpleCollTypeCode: typeCodeOf(constructorCode.simpleColl),\n nestedCollTypeCode: typeCodeOf(constructorCode.nestedColl)\n}) satisfies Descriptor;\n\nconst tupleDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.pairOne),\n embeddable: false,\n pairOneTypeCode: typeCodeOf(constructorCode.pairOne),\n pairTwoTypeCode: typeCodeOf(constructorCode.pairTwo),\n tripleTypeCode: typeCodeOf(constructorCode.pairTwo),\n symmetricPairTypeCode: typeCodeOf(constructorCode.symmetricPair),\n quadrupleTypeCode: typeCodeOf(constructorCode.symmetricPair),\n genericTupleTypeCode: typeCodeOf(constructorCode.genericTuple)\n}) satisfies Descriptor;\n\nexport const descriptors = {\n bool: new SBoolType(),\n byte: new SByteType(),\n short: new SShortType(),\n int: new SIntType(),\n long: new SLongType(),\n bigInt: new SBigIntType(),\n groupElement: new SGroupElementType(),\n sigmaProp: new SSigmaPropType(),\n unit: new SUnitType(),\n coll: collDescriptor,\n tuple: tupleDescriptor\n} satisfies { [key: string]: Descriptor };\n\nexport function isColl(type: SType): type is SCollType {\n return (\n type.code >= descriptors.coll.simpleCollTypeCode &&\n type.code <= descriptors.coll.nestedCollTypeCode + MAX_PRIMITIVE_TYPE_CODE\n );\n}\n\nexport function isTuple(type: SType): type is STupleType {\n return (\n type.code >= descriptors.tuple.pairOneTypeCode &&\n type.code <= descriptors.tuple.genericTupleTypeCode\n );\n}\n\nexport function getPrimitiveType(typeCode: number) {\n switch (typeCode) {\n case descriptors.bool.code:\n return descriptors.bool;\n case descriptors.byte.code:\n return descriptors.byte;\n case descriptors.short.code:\n return descriptors.short;\n case descriptors.int.code:\n return descriptors.int;\n case descriptors.long.code:\n return descriptors.long;\n case descriptors.bigInt.code:\n return descriptors.bigInt;\n case descriptors.groupElement.code:\n return descriptors.groupElement;\n case descriptors.sigmaProp.code:\n return descriptors.sigmaProp;\n default:\n throw new Error(\n `The type code '0x${typeCode.toString(16)}' is not a valid primitive type code.`\n );\n }\n}\n","import { hex } from \"@fleet-sdk/crypto\";\nimport { SGenericType, type SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\n\nexport class SCollType<T extends SType = SType> extends SGenericType<T> {\n get code(): number {\n return descriptors.coll.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] | Uint8Array {\n if (\n this.elementsType.code === descriptors.byte.code &&\n !(elements instanceof Uint8Array)\n ) {\n return typeof elements === \"string\"\n ? hex.decode(elements)\n : Uint8Array.from(elements as ArrayLike<number>);\n }\n\n return elements.map((el) => this.elementsType.coerce(el)) as O[];\n }\n\n toString(): string {\n return `SColl[${this.elementsType.toString()}]`;\n }\n}\n\nexport class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {\n get code(): number {\n return descriptors.tuple.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] {\n const output = new Array(elements.length);\n for (let i = 0; i < elements.length; i++) {\n output[i] = this.elementsType[i].coerce(elements[i]);\n }\n\n return output;\n }\n\n toString(): string {\n return `(${this.elementsType.map((el) => el.toString()).join(\", \")})`;\n }\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { SConstant } from \"../sigmaConstant\";\nimport type { SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\nimport { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport type BigIntInput = string | bigint;\nexport type ByteInput = Uint8Array | string;\n\nexport type SConstructor<\n T = unknown,\n S extends SType = SType | SCollType<SType>\n> = (arg?: T) => S;\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\ntype Any = any;\n\ntype Constructable<T = Any> = { new (...args: Any): T };\ntype GenericProxyArgs<R> = R extends (...args: Any) => unknown\n ? Parameters<R>\n : [];\n\ntype SProxy<T extends SType, I, O = I> = {\n (value: I): SConstant<O, T>;\n (value?: I): T;\n};\n\n/**\n * Creates a proxy for monomorphic types, this allows constructor\n * functions to be equivalent to their corresponding type.\n *\n * This function will return one instance of `ctor` if not params as set.\n * Otherwise it will return an `SigmaConstant` instance of `ctor` type.\n *\n * @example\n * // SInt is a proxy for SIntType\n * (intConstant instanceof SInt) === true\n * (intConstant instanceof SIntType) === true\n * @param ctor Class to be proxied.\n * @param cache If defined, proxy will return this instead of a new instance of `ctor`.\n * @param forceConstruction If true, bypasses the constant creation and returns a type.\n * @returns\n */\nfunction monoProxy<T extends SType, I, O = I>(\n ctor: Constructable<T>,\n cache?: T,\n forceConstruction?: boolean\n): SProxy<T, I, O> {\n return new Proxy(ctor, {\n apply: (target, _, args) => {\n const instance = cache ?? new target();\n if (!forceConstruction && isEmpty(args)) return instance;\n\n return new (SConstant as Constructable)(instance, ...args);\n }\n }) as Any;\n}\n\n/**\n * Creates a proxy for generic types.\n */\nfunction genericProxy<T extends SType, R>(\n ctor: Constructable<T>,\n handler: (\n target: Constructable<T>,\n thisArgs: unknown,\n args: GenericProxyArgs<R>\n ) => unknown\n) {\n return new Proxy(ctor, {\n apply: handler\n }) as R;\n}\n\nexport const SByte = monoProxy<SByteType, number>(SByteType, descriptors.byte);\n\nexport const SBool = monoProxy<SBoolType, boolean>(SBoolType, descriptors.bool);\n\nexport const SShort = monoProxy<SShortType, number>(\n SShortType,\n descriptors.short\n);\n\nexport const SInt = monoProxy<SIntType, number>(SIntType, descriptors.int);\n\nexport const SLong = monoProxy<SLongType, BigIntInput, bigint>(\n SLongType,\n descriptors.long\n);\n\nexport const SBigInt = monoProxy<SBigIntType, BigIntInput, bigint>(\n SBigIntType,\n descriptors.bigInt\n);\n\nexport const SGroupElement = monoProxy<\n SGroupElementType,\n ByteInput,\n Uint8Array\n>(SGroupElementType, descriptors.groupElement);\n\nexport const SSigmaProp = monoProxy<SSigmaPropType, SConstant<Uint8Array>>(\n SSigmaPropType,\n descriptors.sigmaProp\n);\n\ntype SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;\nexport const SUnit: SUnit = monoProxy(SUnitType, undefined, true);\n\ntype SColl = {\n <D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;\n <D, T extends SByteType>(\n type: SConstructor<D, T>,\n elements: ByteInput | D[]\n ): SConstant<Uint8Array, T>;\n <D, T extends SType>(\n type: SConstructor<D, T>,\n elements: D[]\n ): SConstant<D[], T>;\n};\n\nexport const SColl = genericProxy<SCollType, SColl>(\n SCollType,\n (target, _, args) => {\n const [type, elements] = args;\n const elementsType = type();\n if (!elements) return () => new target(elementsType);\n\n return new SConstant(new target(elementsType), elements);\n }\n);\n\nexport function STuple(...items: SConstant[]) {\n return new SConstant(\n new STupleType(items.map((x) => x.type)),\n items.map((x) => x.data)\n );\n}\n\ntype ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;\ntype SPair = {\n <L, R>(\n left: SConstant<L>,\n right: SConstant<R>\n ): SConstant<[L, R], STupleType>;\n <LD, RD, LT extends SType, RT extends SType>(\n left: SConstructor<LD, LT>,\n right: SConstructor<RD, RT>\n ): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;\n};\n\nexport const SPair = genericProxy<STupleType, SPair>(\n STupleType,\n (target, _, args) => {\n const [left, right] = args;\n\n if (typeof left === \"function\" && typeof right === \"function\") {\n return () => new target([left(), right()]);\n }\n\n if (left instanceof SConstant && right instanceof SConstant) {\n return new SConstant(new target([left.type, right.type]), [\n left.data,\n right.data\n ]);\n }\n\n throw new Error(\"Invalid tuple declaration.\");\n }\n);\n","import { assert, first, last } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport { isColl, isTuple, SCollType, STupleType, type SType } from \"../types\";\nimport {\n constructorCode,\n descriptors,\n getPrimitiveType,\n PRIMITIVE_TYPE_RANGE\n} from \"../types/descriptors\";\n\nexport const typeSerializer = {\n serialize(type: SType, writer: SigmaByteWriter) {\n if (type.embeddable) {\n writer.write(type.code);\n } else if (type.code === descriptors.unit.code) {\n writer.write(type.code);\n } else if (isColl(type)) {\n if (type.elementsType.embeddable) {\n writer.write(\n descriptors.coll.simpleCollTypeCode + type.elementsType.code\n );\n } else if (isColl(type.elementsType)) {\n const nestedColl = type.elementsType;\n if (nestedColl.elementsType.embeddable) {\n writer.write(\n descriptors.coll.nestedCollTypeCode + nestedColl.elementsType.code\n );\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(nestedColl, writer);\n }\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(type.elementsType, writer);\n }\n } else if (isTuple(type)) {\n switch (type.elementsType.length) {\n case 2: {\n const left = first(type.elementsType);\n const right = last(type.elementsType);\n\n if (left.embeddable) {\n if (left.code === right.code) {\n // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n writer.write(descriptors.tuple.symmetricPairTypeCode + left.code);\n } else {\n // Pair of types where first is primitive (`(_, Int)`)\n writer.write(descriptors.tuple.pairOneTypeCode + left.code);\n this.serialize(right, writer);\n }\n } else if (right.embeddable) {\n // Pair of types where second is primitive (`(Int, _)`)\n writer.write(descriptors.tuple.pairTwoTypeCode + right.code);\n this.serialize(left, writer);\n } else {\n // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n writer.write(descriptors.tuple.pairOneTypeCode);\n this.serialize(left, writer);\n this.serialize(right, writer);\n }\n\n return;\n }\n case 3:\n writer.write(descriptors.tuple.tripleTypeCode);\n break;\n case 4:\n writer.write(descriptors.tuple.quadrupleTypeCode);\n break;\n default: {\n const len = type.elementsType.length;\n assert(\n len >= 2 && len <= 255,\n \"Invalid type: tuples must have between 2 and 255 items.\"\n );\n\n // Generic tuple\n writer.write(descriptors.tuple.genericTupleTypeCode);\n writer.writeVLQ(len);\n }\n }\n\n for (let i = 0; i < type.elementsType.length; i++) {\n this.serialize(type.elementsType[i], writer);\n }\n } else {\n throw new Error(\"Serialization error: type not implemented.\");\n }\n },\n\n deserialize(r: SigmaByteReader): SType {\n const byte = r.readByte();\n assert(\n byte > 0,\n `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`\n );\n\n if (byte < descriptors.tuple.genericTupleTypeCode) {\n const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);\n const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);\n\n switch (ctorCode) {\n case constructorCode.embeddable: {\n return getPrimitiveType(embdCode);\n }\n case constructorCode.simpleColl: {\n const internal =\n embdCode === 0 ? this.deserialize(r) : getPrimitiveType(embdCode);\n\n return new SCollType(internal);\n }\n case constructorCode.nestedColl: {\n return new SCollType(new SCollType(getPrimitiveType(embdCode)));\n }\n case constructorCode.pairOne: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r)] // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n : [getPrimitiveType(embdCode), this.deserialize(r)]; // Pair of types where first is primitive (`(_, Int)`)\n\n return new STupleType(internal);\n }\n case constructorCode.pairTwo: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r), this.deserialize(r)] // Triple of types\n : [this.deserialize(r), getPrimitiveType(embdCode)];\n\n return new STupleType(internal);\n }\n case constructorCode.symmetricPair: {\n const internal =\n embdCode === 0\n ? [\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r)\n ] // Quadruple of types\n : [getPrimitiveType(embdCode), getPrimitiveType(embdCode)]; // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n\n return new STupleType(internal);\n }\n }\n }\n\n switch (byte) {\n case descriptors.tuple.genericTupleTypeCode: {\n const len = r.readVlq();\n const wrapped = new Array<SType>(len);\n for (let i = 0; i < len; i++) {\n wrapped[i] = this.deserialize(r);\n }\n\n return new STupleType(wrapped);\n }\n case descriptors.unit.code: {\n return descriptors.unit;\n }\n }\n\n throw new Error(\"Not implemented.\");\n }\n};\n","import {\n type Amount,\n type Box,\n type BoxCandidate,\n byteSizeOf,\n ensureBigInt,\n isDefined,\n isEmpty,\n isUndefined,\n type NonMandatoryRegisters,\n some,\n type TokenAmount\n} from \"@fleet-sdk/common\";\nimport { estimateVLQSize, SigmaByteWriter } from \"../coders\";\n\nconst MAX_UINT16_VALUE = 65535;\n\nexport function serializeBox(box: Box<Amount>): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount>,\n writer: SigmaByteWriter\n): SigmaByteWriter;\nexport function serializeBox(\n box: BoxCandidate<Amount>,\n writer: SigmaByteWriter,\n distinctTokenIds: string[]\n): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount> | BoxCandidate<Amount>,\n writer = new SigmaByteWriter(5_0000),\n distinctTokenIds?: string[]\n): SigmaByteWriter {\n writer.writeBigVLQ(ensureBigInt(box.value));\n writer.writeHex(box.ergoTree);\n writer.writeVLQ(box.creationHeight);\n writeTokens(writer, box.assets, distinctTokenIds);\n writeRegisters(writer, box.additionalRegisters);\n\n if (isDefined(distinctTokenIds)) return writer;\n if (!isBox(box)) throw new Error(\"Invalid box type.\");\n return writer.writeHex(box.transactionId).writeVLQ(box.index);\n}\n\nfunction isBox<T extends Amount>(\n box: Box<Amount> | BoxCandidate<Amount>\n): box is Box<T> {\n const castedBox = box as Box<T>;\n\n return isDefined(castedBox.transactionId) && isDefined(castedBox.index);\n}\n\nfunction writeTokens(\n writer: SigmaByteWriter,\n tokens: TokenAmount<Amount>[],\n tokenIds?: string[]\n): void {\n if (isEmpty(tokens)) {\n writer.write(0);\n\n return;\n }\n\n writer.writeVLQ(tokens.length);\n if (some(tokenIds)) {\n tokens.map((token) =>\n writer\n .writeVLQ(tokenIds.indexOf(token.tokenId))\n .writeBigVLQ(ensureBigInt(token.amount))\n );\n } else {\n tokens.map((token) =>\n writer.writeHex(token.tokenId).writeBigVLQ(ensureBigInt(token.amount))\n );\n }\n}\n\nfunction writeRegisters(\n writer: SigmaByteWriter,\n registers: NonMandatoryRegisters\n): void {\n const keys = Object.keys(registers).sort();\n let length = 0;\n\n for (const key of keys) {\n if (registers[key as keyof NonMandatoryRegisters]) length++;\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const register = registers[key as keyof NonMandatoryRegisters];\n if (isDefined(register)) writer.writeHex(register);\n }\n}\n\n/**\n * Estimates the byte size a box.\n * @returns byte size of the box.\n */\nexport function estimateBoxSize(\n box: Box<Amount> | BoxCandidate<Amount>,\n withValue?: Amount\n): number {\n if (isUndefined(box.creationHeight)) {\n throw new Error(\"Box size estimation error: creation height is undefined.\");\n }\n\n let size = 0;\n\n size += estimateVLQSize(isDefined(withValue) ? withValue : box.value);\n size += byteSizeOf(box.ergoTree);\n size += estimateVLQSize(box.creationHeight);\n\n size += estimateVLQSize(box.assets.length);\n for (const asset of box.assets) {\n size += byteSizeOf(asset.tokenId) + estimateVLQSize(asset.amount);\n }\n\n let registersLength = 0;\n for (const key in box.additionalRegisters) {\n const register =\n box.additionalRegisters[key as keyof NonMandatoryRegisters];\n if (register) {\n size += byteSizeOf(register);\n registersLength++;\n }\n }\n\n size += estimateVLQSize(registersLength);\n size += 32; // transaction id (BLAKE2b 256 hash)\n size += estimateVLQSize(isBox(box) ? box.index : MAX_UINT16_VALUE);\n\n return size;\n}\n","import {\n type Amount,\n type BoxCandidate,\n type ContextExtension,\n type DataInput,\n isDefined,\n type UnsignedInput\n} from \"@fleet-sdk/common\";\nimport { SigmaByteWriter } from \"../coders\";\nimport { serializeBox } from \"./boxSerializer\";\n\nexport type MinimalUnsignedTransaction = {\n inputs: readonly UnsignedInput[];\n dataInputs: readonly DataInput[];\n outputs: readonly BoxCandidate<Amount>[];\n};\n\nexport function serializeTransaction(\n transaction: MinimalUnsignedTransaction\n): SigmaByteWriter {\n const writer = new SigmaByteWriter(100_000);\n\n // write inputs\n writer.writeVLQ(transaction.inputs.length);\n transaction.inputs.map((input) => writeInput(writer, input));\n\n // write data inputs\n writer.writeVLQ(transaction.dataInputs.length);\n transaction.dataInputs.map((dataInput) => writer.writeHex(dataInput.boxId));\n\n // write distinct token IDs\n const distinctTokenIds = getDistinctTokenIds(transaction.outputs);\n writer.writeVLQ(distinctTokenIds.length);\n distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));\n\n // write outputs\n writer.writeVLQ(transaction.outputs.length);\n transaction.outputs.map((output) =>\n serializeBox(output, writer, distinctTokenIds)\n );\n\n return writer;\n}\n\nfunction writeInput(writer: SigmaByteWriter, input: UnsignedInput): void {\n writer.writeHex(input.boxId);\n writer.write(0); // empty proof\n writeExtension(writer, input.extension);\n}\n\nfunction writeExtension(\n writer: SigmaByteWriter,\n extension: ContextExtension\n): void {\n const keys = Object.keys(extension);\n let length = 0;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n length++;\n }\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n writer.writeVLQ(Number(key)).writeHex(ext);\n }\n }\n}\n\nfunction getDistinctTokenIds(outputs: readonly BoxCandidate<Amount>[]) {\n const tokenIds = new Set<string>();\n outputs.flatMap((output) =>\n output.assets.map((asset) => tokenIds.add(asset.tokenId))\n );\n\n return Array.from(tokenIds);\n}\n"]}
1
+ {"version":3,"sources":["../src/coders/bigint.ts","../src/coders/vlq.ts","../src/coders/zigZag.ts","../src/coders/sigmaByteReader.ts","../src/coders/sigmaByteWriter.ts","../src/types/base.ts","../src/types/primitives.ts","../src/types/monomorphics.ts","../src/types/descriptors.ts","../src/types/generics.ts","../src/types/constructors.ts","../src/serializers/dataSerializer.ts","../src/serializers/typeSerializer.ts","../src/sigmaConstant.ts","../src/serializers/boxSerializer.ts","../src/serializers/transactionSerializer.ts"],"names":["hex","_0n","ensureBigInt","isEmpty","first","assert","isUndefined","isDefined"],"mappings":";;;;AAOO,SAAS,YAAYA,IAAqB,EAAA;AAE/C,EAAM,MAAA,KAAA,GAAQ,MAAOA,CAAAA,IAAAA,CAAI,MAAS,GAAA,CAAA,GAAI,MAAMA,IAAG,CAAA,CAAA,GAAK,CAAKA,EAAAA,EAAAA,IAAG,CAAE,CAAA,CAAA,CAAA;AAC9D,EAAM,MAAA,QAAA,GAAW,OAAO,QAASA,CAAAA,IAAAA,CAAI,MAAM,CAAG,EAAA,CAAC,GAAG,EAAE,CAAA,CAAA;AACpD,EAAA,IAAI,GAAO,GAAA,QAAA,EAAiB,OA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AAA,MAAA,CAAO,MAAO,CAAA,GAAA,CAAI,CAAC,KAAA,KAAU,QAAS,CAAA,GAAA,CAAI,KAAM,CAAA,OAAO,CAAC,CAAC,CAAA,CAAA;AAErF,EAAO,OAAA,KAAA,CAAM,KAAK,QAAQ,CAAA,CAAA;AAC5B","file":"index.mjs","sourcesContent":["import { _0n, first } from \"@fleet-sdk/common\";\n\n/**\n * Converts a hex string to bigint.\n * @param hex The hex string to be converted.\n * @returns The bigint value represented by the hex string.\n */\nexport function hexToBigInt(hex: string): bigint {\n // https://coolaj86.com/articles/convert-hex-to-decimal-with-js-bigints/\n const value = BigInt(hex.length % 2 ? `0x0${hex}` : `0x${hex}`);\n const highByte = Number.parseInt(hex.slice(0, 2), 16);\n if (0x80 & highByte) return -negateAndMask(value);\n\n return value;\n}\n\n/**\n * Serializes a `BigInt` to a hex string\n * @param value The bigint value to be serialized\n * @returns Hex representation for the provided `number`.\n */\nexport function bigIntToHex(value: bigint): string {\n // implementation inspired on\n // https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/\n const positive = value >= _0n;\n let hex = (positive ? value : negateAndMask(value)).toString(16);\n if (hex.length % 2) hex = `0${hex}`;\n\n if (positive && 0x80 & Number.parseInt(hex.slice(0, 2), 16)) {\n return `00${hex}`;\n }\n\n return hex;\n}\n\n/**\n * Returns the two’s complement of a bigint value.\n * @param value The bigint value to negate.\n * @returns The two’s complement of `number` as a bigint.\n */\nexport function negateAndMask(value: bigint): bigint {\n let val = value;\n const negative = val < _0n;\n if (negative) val = -val; // turn into a positive number\n\n const bits = val.toString(2);\n let len = bits.length; // convert to binary\n const mod = len % 8;\n\n if (mod > 0) {\n len += 8 - mod;\n } else if (negative && first(bits) === \"1\" && bits.indexOf(\"1\", 1) !== -1) {\n len += 8;\n }\n\n const mask = (1n << BigInt(len)) - 1n; // create a mask\n return (~val & mask) + 1n; // invert bits, mask it, and add one\n}\n","import { _0n, _127n, _128n, _7n, ensureBigInt } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader } from \"./sigmaByteReader\";\nimport type { SigmaByteWriter } from \"./sigmaByteWriter\";\n\n/**\n * A **variable-length quantity (VLQ)** is a universal code that uses an arbitrary number\n * of binary octets (eight-bit bytes) to represent an arbitrarily large integer. A VLQ\n * is essentially a base-128 representation of an unsigned integer with the addition of\n * the eighth bit to mark continuation of bytes. VLQ is identical to LEB128 except in\n * endianness. See the example below.\n */\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeVLQ(writer: SigmaByteWriter, value: number): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n if (value === 0) return writer.write(0);\n if (value < 0) {\n throw new RangeError(\"Variable Length Quantity not supported for negative numbers.\");\n }\n\n let val = value;\n do {\n let lower7bits = val & 0x7f;\n val >>= 7;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readVLQ(reader: SigmaByteReader): number {\n if (reader.isEmpty) {\n return 0;\n }\n\n let value = 0;\n let shift = 0;\n let lower7bits = 0;\n\n do {\n lower7bits = reader.readByte();\n value |= (lower7bits & 0x7f) << shift;\n shift += 7;\n } while ((lower7bits & 0x80) !== 0);\n\n return value;\n}\n\n/**\n * Write an unsigned integer value as VLQ to a `SigmaByteWriter`.\n * @param value: Big integer value\n * @param writer: Sigma writer\n * @returns Sigma writer passed as function argument.\n */\nexport function writeBigVLQ(writer: SigmaByteWriter, value: bigint): SigmaByteWriter {\n // source: https://stackoverflow.com/a/3564685\n\n if (value === _0n) return writer.write(0);\n if (value < _0n) {\n throw new RangeError(\"Variable Length Quantity not supported for negative numbers\");\n }\n\n let val = value;\n do {\n let lower7bits = Number(val & _127n);\n val >>= _7n;\n if (val > 0) lower7bits |= 0x80;\n writer.write(lower7bits);\n } while (val > 0);\n\n return writer;\n}\n\n/**\n * Decode VLQ bytes to an unsigned big integer value\n * @param reader VLQ bytes\n * @returns Unsigned integer value\n */\nexport function readBigVLQ(reader: SigmaByteReader): bigint {\n if (reader.isEmpty) return _0n;\n\n let value = _0n;\n let shift = _0n;\n let lower7bits = _0n;\n\n do {\n lower7bits = BigInt(reader.readByte());\n value |= (lower7bits & _127n) << shift;\n shift += _7n;\n } while ((lower7bits & _128n) !== _0n);\n\n return value;\n}\n\n/**\n * Estimates the byte size of a given unsigned integer.\n * @param value: the value to be evaluated.\n * @returns the byte size of the value.\n */\nexport function estimateVLQSize(value: number | bigint | string): number {\n let size = 0;\n let val = value;\n if (typeof val === \"number\") {\n do {\n size++;\n val = Math.floor(val / 128);\n } while (val > 0);\n\n return size;\n }\n\n val = ensureBigInt(val);\n do {\n size++;\n val /= _128n;\n } while (val > _0n);\n\n return size;\n}\n","import { _1n, _63n } from \"@fleet-sdk/common\";\n\n/**\n * ZigZag encoding maps signed integers to unsigned integers so that numbers\n * with a small absolute value (for instance, -1) have a small variant encoded\n * value too. It does this in a way that \"zig-zags\" back and forth through the\n * positive and negative integers, so that -1 is encoded as 1, 1 is encoded as 2,\n * -2 is encoded as 3, and so on.\n * @see https://developers.google.com/protocol-buffers/docs/encoding#types\n */\n\n/**\n * Encode a signed integer.\n * @param input Signed integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncode(input: number): number {\n return (input << 1) ^ (input >> 63);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed integer\n */\nexport function zigZagDecode(input: number): number {\n return (input >> 1) ^ -(input & 1);\n}\n\n/**\n * Encode a signed big integer.\n * @param input Signed big integer\n * @returns ZigZag-encoded value\n */\nexport function zigZagEncodeBigInt(input: bigint): bigint {\n return (input << _1n) ^ (input >> _63n);\n}\n\n/**\n * Decode a ZigZag-encoded value.\n * @param input ZigZag-encoded value\n * @returns Signed big integer\n */\nexport function zigZagDecodeBigInt(input: bigint): bigint {\n return (input >> _1n) ^ -(input & _1n);\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { type ByteInput, ensureBytes, hex } from \"@fleet-sdk/crypto\";\nimport { hexToBigInt } from \"./bigint\";\nimport { readBigVLQ, readVLQ } from \"./vlq\";\nimport { zigZagDecode, zigZagDecodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteReader {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get isEmpty(): boolean {\n return isEmpty(this.#bytes);\n }\n\n constructor(bytes: ByteInput) {\n this.#bytes = ensureBytes(bytes);\n this.#cursor = 0;\n }\n\n public readBoolean(): boolean {\n return this.readByte() === 0x01;\n }\n\n public readBits(length: number): ArrayLike<boolean> {\n const bits = new Array<boolean>(length);\n let bitOffset = 0;\n\n for (let i = 0; i < length; i++) {\n const bit = (this.#bytes[this.#cursor] >> bitOffset++) & 1;\n bits[i] = bit === 1;\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return bits;\n }\n\n public readByte(): number {\n return this.#bytes[this.#cursor++];\n }\n\n public readBytes(length: number): Uint8Array {\n return this.#bytes.subarray(this.#cursor, (this.#cursor += length));\n }\n\n public readVlq(): number {\n return readVLQ(this);\n }\n\n public readShort(): number {\n return Number(zigZagDecode(readVLQ(this)));\n }\n\n public readInt(): number {\n return Number(this.readLong());\n }\n\n public readLong(): bigint {\n return zigZagDecodeBigInt(readBigVLQ(this));\n }\n\n public readBigInt(): bigint {\n const len = readVLQ(this);\n return hexToBigInt(hex.encode(this.readBytes(len)));\n }\n}\n","import { blake2b256, type Coder, hex } from \"@fleet-sdk/crypto\";\nimport { bigIntToHex } from \"./bigint\";\nimport { writeBigVLQ, writeVLQ } from \"./vlq\";\nimport { zigZagEncode, zigZagEncodeBigInt } from \"./zigZag\";\n\nexport class SigmaByteWriter {\n readonly #bytes: Uint8Array;\n #cursor: number;\n\n public get length() {\n return this.#cursor;\n }\n\n constructor(length: number) {\n this.#bytes = new Uint8Array(length);\n this.#cursor = 0;\n }\n\n public writeBoolean(value: boolean): SigmaByteWriter {\n this.write(value === true ? 0x01 : 0x00);\n\n return this;\n }\n\n public writeVLQ(value: number): SigmaByteWriter {\n return writeVLQ(this, value);\n }\n\n public writeBigVLQ(value: bigint): SigmaByteWriter {\n return writeBigVLQ(this, value);\n }\n\n public writeShort(value: number): SigmaByteWriter {\n this.writeVLQ(zigZagEncode(value));\n return this;\n }\n\n public writeInt(value: number): SigmaByteWriter {\n this.writeLong(BigInt(value));\n return this;\n }\n\n public writeLong(value: bigint): SigmaByteWriter {\n this.writeBigVLQ(zigZagEncodeBigInt(value));\n return this;\n }\n\n public write(byte: number): SigmaByteWriter {\n this.#bytes[this.#cursor++] = byte;\n return this;\n }\n\n public writeBytes(bytes: ArrayLike<number>): SigmaByteWriter {\n this.#bytes.set(bytes, this.#cursor);\n this.#cursor += bytes.length;\n return this;\n }\n\n public writeHex(bytesHex: string): SigmaByteWriter {\n return this.writeBytes(hex.decode(bytesHex));\n }\n\n public writeBits(bits: ArrayLike<boolean>): SigmaByteWriter {\n let bitOffset = 0;\n\n for (let i = 0; i < bits.length; i++) {\n if (bits[i]) {\n this.#bytes[this.#cursor] |= 1 << bitOffset++;\n } else {\n this.#bytes[this.#cursor] &= ~(1 << bitOffset++);\n }\n\n if (bitOffset === 8) {\n bitOffset = 0;\n this.#cursor++;\n }\n }\n\n if (bitOffset > 0) this.#cursor++;\n\n return this;\n }\n\n public writeBigInt(value: bigint): SigmaByteWriter {\n const hex = bigIntToHex(value);\n return this.writeVLQ(hex.length / 2).writeHex(hex);\n }\n\n public writeChecksum(length = 4, hashFn = blake2b256): SigmaByteWriter {\n const hash = hashFn(this.toBytes());\n return this.writeBytes(length ? hash.subarray(0, length) : hash);\n }\n\n public encode<T>(coder: Coder<Uint8Array, T>): T {\n return coder.encode(this.toBytes());\n }\n\n public toBytes(): Uint8Array {\n if (this.#cursor === this.#bytes.length) return this.#bytes;\n return this.#bytes.subarray(0, this.#cursor);\n }\n}\n","export abstract class SType<I = unknown, O = I> {\n abstract get code(): number;\n abstract get embeddable(): boolean;\n\n coerce(data: I): O {\n // a bit hacky but most of types will not need a specific coercion function.\n return data as unknown as O;\n }\n\n abstract toString(): string;\n}\n\nexport abstract class SMonomorphicType<I, O = I> extends SType<I, O> {\n abstract get code(): number;\n\n get embeddable(): boolean {\n return false;\n }\n}\n\nexport abstract class SPrimitiveType<I, O = I> extends SMonomorphicType<I, O> {\n abstract get code(): number;\n\n override get embeddable(): boolean {\n return true;\n }\n}\n\nexport abstract class SGenericType<T extends SType | SType[]> extends SType {\n readonly #internalType: T;\n\n constructor(type: T) {\n super();\n this.#internalType = type;\n }\n\n abstract get code(): number;\n\n get elementsType(): T {\n return this.#internalType;\n }\n\n get embeddable(): boolean {\n return false;\n }\n}\n","import { ensureBigInt } from \"@fleet-sdk/common\";\nimport { hex } from \"@fleet-sdk/crypto\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { SPrimitiveType } from \"./base\";\nimport type { BigIntInput, ByteInput } from \"./constructors\";\n\nexport class SBoolType extends SPrimitiveType<boolean> {\n get code(): 0x01 {\n return 0x01;\n }\n\n toString(): string {\n return \"SBool\";\n }\n}\n\nexport class SByteType extends SPrimitiveType<number> {\n get code(): 0x02 {\n return 0x02;\n }\n\n toString(): string {\n return \"SByte\";\n }\n}\n\nexport class SShortType extends SPrimitiveType<number> {\n get code(): 0x03 {\n return 0x03;\n }\n\n toString(): string {\n return \"SShort\";\n }\n}\n\nexport class SIntType extends SPrimitiveType<number> {\n get code(): 0x04 {\n return 0x04;\n }\n\n toString(): string {\n return \"SInt\";\n }\n}\n\nexport class SLongType extends SPrimitiveType<BigIntInput, bigint> {\n get code(): 0x05 {\n return 0x05;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SLong\";\n }\n}\n\nexport class SBigIntType extends SPrimitiveType<string | bigint, bigint> {\n get code(): number {\n return 0x06;\n }\n\n override coerce(data: BigIntInput): bigint {\n return ensureBigInt(data);\n }\n\n toString(): string {\n return \"SBigInt\";\n }\n}\n\nexport class SGroupElementType extends SPrimitiveType<ByteInput, Uint8Array> {\n get code(): 0x07 {\n return 0x07;\n }\n\n override coerce(data: ByteInput): Uint8Array {\n return typeof data === \"string\" ? hex.decode(data) : data;\n }\n\n toString(): string {\n return \"SGroupElement\";\n }\n}\n\nexport class SSigmaPropType extends SPrimitiveType<SConstant<Uint8Array>> {\n get code(): 0x08 {\n return 0x08;\n }\n\n toString(): string {\n return \"SSigmaProp\";\n }\n}\n","import { SMonomorphicType } from \"./base\";\n\nexport class SUnitType extends SMonomorphicType<undefined> {\n get code(): 0x62 {\n return 0x62;\n }\n\n toString(): string {\n return \"SUnit\";\n }\n}\n","import type { SType } from \"./base\";\nimport type { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport const constructorCode = Object.freeze({\n embeddable: 0,\n\n simpleColl: 1,\n nestedColl: 2,\n\n option: 3,\n optionCollection: 4,\n\n pairOne: 5,\n pairTwo: 6,\n symmetricPair: 7,\n genericTuple: 8\n});\n\nconst MAX_PRIMITIVE_TYPE_CODE = 0x0b;\nexport const PRIMITIVE_TYPE_RANGE = MAX_PRIMITIVE_TYPE_CODE + 0x01;\nconst typeCodeOf = (ctor: number) => PRIMITIVE_TYPE_RANGE * ctor;\n\ntype Descriptor = { code: number; embeddable: boolean };\n\nconst collDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.simpleColl),\n embeddable: false,\n simpleCollTypeCode: typeCodeOf(constructorCode.simpleColl),\n nestedCollTypeCode: typeCodeOf(constructorCode.nestedColl)\n}) satisfies Descriptor;\n\nconst tupleDescriptor = Object.freeze({\n code: typeCodeOf(constructorCode.pairOne),\n embeddable: false,\n pairOneTypeCode: typeCodeOf(constructorCode.pairOne),\n pairTwoTypeCode: typeCodeOf(constructorCode.pairTwo),\n tripleTypeCode: typeCodeOf(constructorCode.pairTwo),\n symmetricPairTypeCode: typeCodeOf(constructorCode.symmetricPair),\n quadrupleTypeCode: typeCodeOf(constructorCode.symmetricPair),\n genericTupleTypeCode: typeCodeOf(constructorCode.genericTuple)\n}) satisfies Descriptor;\n\nexport const descriptors = {\n bool: new SBoolType(),\n byte: new SByteType(),\n short: new SShortType(),\n int: new SIntType(),\n long: new SLongType(),\n bigInt: new SBigIntType(),\n groupElement: new SGroupElementType(),\n sigmaProp: new SSigmaPropType(),\n unit: new SUnitType(),\n coll: collDescriptor,\n tuple: tupleDescriptor\n} satisfies { [key: string]: Descriptor };\n\nexport function isColl(type: SType): type is SCollType {\n return (\n type.code >= descriptors.coll.simpleCollTypeCode &&\n type.code <= descriptors.coll.nestedCollTypeCode + MAX_PRIMITIVE_TYPE_CODE\n );\n}\n\nexport function isTuple(type: SType): type is STupleType {\n return (\n type.code >= descriptors.tuple.pairOneTypeCode &&\n type.code <= descriptors.tuple.genericTupleTypeCode\n );\n}\n\nexport function getPrimitiveType(typeCode: number) {\n switch (typeCode) {\n case descriptors.bool.code:\n return descriptors.bool;\n case descriptors.byte.code:\n return descriptors.byte;\n case descriptors.short.code:\n return descriptors.short;\n case descriptors.int.code:\n return descriptors.int;\n case descriptors.long.code:\n return descriptors.long;\n case descriptors.bigInt.code:\n return descriptors.bigInt;\n case descriptors.groupElement.code:\n return descriptors.groupElement;\n case descriptors.sigmaProp.code:\n return descriptors.sigmaProp;\n default:\n throw new Error(\n `The type code '0x${typeCode.toString(16)}' is not a valid primitive type code.`\n );\n }\n}\n","import { hex } from \"@fleet-sdk/crypto\";\nimport { SGenericType, type SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\n\nexport class SCollType<T extends SType = SType> extends SGenericType<T> {\n get code(): number {\n return descriptors.coll.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] | Uint8Array {\n if (\n this.elementsType.code === descriptors.byte.code &&\n !(elements instanceof Uint8Array)\n ) {\n return typeof elements === \"string\"\n ? hex.decode(elements)\n : Uint8Array.from(elements as ArrayLike<number>);\n }\n\n return elements.map((el) => this.elementsType.coerce(el)) as O[];\n }\n\n toString(): string {\n return `SColl[${this.elementsType.toString()}]`;\n }\n}\n\nexport class STupleType<T extends SType[] = SType[]> extends SGenericType<T> {\n get code(): number {\n return descriptors.tuple.code;\n }\n\n override coerce<I, O>(elements: I[]): O[] {\n const output = new Array(elements.length);\n for (let i = 0; i < elements.length; i++) {\n output[i] = this.elementsType[i].coerce(elements[i]);\n }\n\n return output;\n }\n\n toString(): string {\n return `(${this.elementsType.map((el) => el.toString()).join(\", \")})`;\n }\n}\n","import { isEmpty } from \"@fleet-sdk/common\";\nimport { SConstant } from \"../sigmaConstant\";\nimport type { SType } from \"./base\";\nimport { descriptors } from \"./descriptors\";\nimport { SCollType, STupleType } from \"./generics\";\nimport { SUnitType } from \"./monomorphics\";\nimport {\n SBigIntType,\n SBoolType,\n SByteType,\n SGroupElementType,\n SIntType,\n SLongType,\n SShortType,\n SSigmaPropType\n} from \"./primitives\";\n\nexport type BigIntInput = string | bigint;\nexport type ByteInput = Uint8Array | string;\n\nexport type SConstructor<T = unknown, S extends SType = SType | SCollType<SType>> = (\n arg?: T\n) => S;\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\ntype Any = any;\n\ntype Constructable<T = Any> = { new (...args: Any): T };\ntype GenericProxyArgs<R> = R extends (...args: Any) => unknown ? Parameters<R> : [];\n\ntype SProxy<T extends SType, I, O = I> = {\n (value: I): SConstant<O, T>;\n (value?: I): T;\n};\n\n/**\n * Creates a proxy for monomorphic types, this allows constructor\n * functions to be equivalent to their corresponding type.\n *\n * This function will return one instance of `ctor` if not params as set.\n * Otherwise it will return an `SigmaConstant` instance of `ctor` type.\n *\n * @example\n * // SInt is a proxy for SIntType\n * (intConstant instanceof SInt) === true\n * (intConstant instanceof SIntType) === true\n * @param ctor Class to be proxied.\n * @param cache If defined, proxy will return this instead of a new instance of `ctor`.\n * @param forceConstruction If true, bypasses the constant creation and returns a type.\n * @returns\n */\nfunction monoProxy<T extends SType, I, O = I>(\n ctor: Constructable<T>,\n cache?: T,\n forceConstruction?: boolean\n): SProxy<T, I, O> {\n return new Proxy(ctor, {\n apply: (target, _, args) => {\n const instance = cache ?? new target();\n if (!forceConstruction && isEmpty(args)) return instance;\n\n return new (SConstant as Constructable)(instance, ...args);\n }\n }) as Any;\n}\n\n/**\n * Creates a proxy for generic types.\n */\nfunction genericProxy<T extends SType, R>(\n ctor: Constructable<T>,\n handler: (\n target: Constructable<T>,\n thisArgs: unknown,\n args: GenericProxyArgs<R>\n ) => unknown\n) {\n return new Proxy(ctor, {\n apply: handler\n }) as R;\n}\n\nexport const SByte = monoProxy<SByteType, number>(SByteType, descriptors.byte);\n\nexport const SBool = monoProxy<SBoolType, boolean>(SBoolType, descriptors.bool);\n\nexport const SShort = monoProxy<SShortType, number>(SShortType, descriptors.short);\n\nexport const SInt = monoProxy<SIntType, number>(SIntType, descriptors.int);\n\nexport const SLong = monoProxy<SLongType, BigIntInput, bigint>(\n SLongType,\n descriptors.long\n);\n\nexport const SBigInt = monoProxy<SBigIntType, BigIntInput, bigint>(\n SBigIntType,\n descriptors.bigInt\n);\n\nexport const SGroupElement = monoProxy<SGroupElementType, ByteInput, Uint8Array>(\n SGroupElementType,\n descriptors.groupElement\n);\n\nexport const SSigmaProp = monoProxy<SSigmaPropType, SConstant<Uint8Array>>(\n SSigmaPropType,\n descriptors.sigmaProp\n);\n\ntype SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;\nexport const SUnit: SUnit = monoProxy(SUnitType, undefined, true);\n\ntype SColl = {\n <D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;\n <D, T extends SByteType>(\n type: SConstructor<D, T>,\n elements: ByteInput | D[]\n ): SConstant<Uint8Array, T>;\n <D, T extends SType>(type: SConstructor<D, T>, elements: D[]): SConstant<D[], T>;\n};\n\nexport const SColl = genericProxy<SCollType, SColl>(SCollType, (target, _, args) => {\n const [type, elements] = args;\n const elementsType = type();\n if (!elements) return () => new target(elementsType);\n\n return new SConstant(new target(elementsType), elements);\n});\n\nexport function STuple(...items: SConstant[]) {\n return new SConstant(\n new STupleType(items.map((x) => x.type)),\n items.map((x) => x.data)\n );\n}\n\ntype ByteInputOr<D, T extends SType> = T extends SByteType ? ByteInput | D : D;\ntype SPair = {\n <L, R>(left: SConstant<L>, right: SConstant<R>): SConstant<[L, R], STupleType>;\n <LD, RD, LT extends SType, RT extends SType>(\n left: SConstructor<LD, LT>,\n right: SConstructor<RD, RT>\n ): SConstructor<[ByteInputOr<LD, LT>, ByteInputOr<RD, RT>]>;\n};\n\nexport const SPair = genericProxy<STupleType, SPair>(STupleType, (target, _, args) => {\n const [left, right] = args;\n\n if (typeof left === \"function\" && typeof right === \"function\") {\n return () => new target([left(), right()]);\n }\n\n if (left instanceof SConstant && right instanceof SConstant) {\n return new SConstant(new target([left.type, right.type]), [left.data, right.data]);\n }\n\n throw new Error(\"Invalid tuple declaration.\");\n});\n","import { assert } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport type { SConstant } from \"../sigmaConstant\";\nimport { isColl, isTuple, type SCollType, type STupleType, type SType } from \"../types\";\nimport { descriptors } from \"../types/descriptors\";\n\nconst GROUP_ELEMENT_LENGTH = 33;\nconst PROVE_DLOG_OP = 0xcd;\n\nexport const dataSerializer = {\n serialize(data: unknown, type: SType, writer: SigmaByteWriter): SigmaByteWriter {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return writer.writeBoolean(data as boolean);\n case descriptors.byte.code:\n return writer.write(data as number);\n case descriptors.short.code:\n return writer.writeShort(data as number);\n case descriptors.int.code:\n return writer.writeInt(data as number);\n case descriptors.long.code:\n return writer.writeLong(data as bigint);\n case descriptors.bigInt.code:\n return writer.writeBigInt(data as bigint);\n case descriptors.groupElement.code:\n return writer.writeBytes(data as Uint8Array);\n case descriptors.sigmaProp.code: {\n const node = data as SConstant<SConstant<Uint8Array>>;\n if (node.type === descriptors.groupElement) {\n writer.write(PROVE_DLOG_OP);\n return dataSerializer.serialize(node.data, node.type, writer);\n }\n\n throw Error(\"Serialization error: SigmaProp operation not implemented.\");\n }\n }\n }\n\n if (isColl(type)) {\n if (type.elementsType.code === descriptors.byte.code) {\n assert(\n data instanceof Uint8Array,\n `SColl[Byte] expected an UInt8Array, got ${typeof data}.`\n );\n } else {\n assert(Array.isArray(data), `SColl expected an array, got ${typeof data}.`);\n }\n\n writer.writeVLQ(data.length);\n switch (type.elementsType.code) {\n case descriptors.bool.code: {\n return writer.writeBits(data as boolean[]);\n }\n case descriptors.byte.code: {\n return writer.writeBytes(data as Uint8Array);\n }\n default: {\n for (let i = 0; i < data.length; i++) {\n dataSerializer.serialize(data[i], type.elementsType, writer);\n }\n\n return writer;\n }\n }\n }\n\n if (isTuple(type)) {\n assert(\n Array.isArray(data),\n `STupleType serialization expected an array, got ${typeof data}.`\n );\n\n const len = type.elementsType.length;\n for (let i = 0; i < len; i++) {\n dataSerializer.serialize(data[i], type.elementsType[i], writer);\n }\n\n return writer;\n }\n\n if (type.code === descriptors.unit.code) return writer;\n\n throw Error(\n `Serialization error: '0x${type.code.toString(16)}' type not implemented.`\n );\n },\n\n deserialize(type: SType, reader: SigmaByteReader): unknown {\n if (type.embeddable) {\n switch (type.code) {\n case descriptors.bool.code:\n return reader.readBoolean();\n case descriptors.byte.code:\n return reader.readByte();\n case descriptors.short.code:\n return reader.readShort();\n case descriptors.int.code:\n return reader.readInt();\n case descriptors.long.code:\n return reader.readLong();\n case descriptors.bigInt.code:\n return reader.readBigInt();\n case descriptors.groupElement.code:\n return reader.readBytes(GROUP_ELEMENT_LENGTH);\n case descriptors.sigmaProp.code: {\n if (reader.readByte() === PROVE_DLOG_OP) {\n return this.deserialize(descriptors.groupElement, reader);\n }\n\n break;\n }\n }\n } else {\n switch (type.code) {\n case descriptors.coll.code: {\n const length = reader.readVlq();\n const embeddedType = (type as SCollType).elementsType;\n\n switch (embeddedType.code) {\n case descriptors.bool.code:\n return reader.readBits(length);\n case descriptors.byte.code:\n return reader.readBytes(length);\n default: {\n const elements = new Array(length);\n for (let i = 0; i < length; i++) {\n elements[i] = this.deserialize(embeddedType, reader);\n }\n\n return elements;\n }\n }\n }\n case descriptors.tuple.code: {\n return (type as STupleType).elementsType.map((t) =>\n this.deserialize(t, reader)\n );\n }\n case descriptors.unit.code:\n return undefined;\n }\n }\n\n throw new Error(`Parsing error: '0x${type.code.toString(16)}' type not implemented.`);\n }\n};\n","import { assert, first, last } from \"@fleet-sdk/common\";\nimport type { SigmaByteReader, SigmaByteWriter } from \"../coders\";\nimport { isColl, isTuple, SCollType, STupleType, type SType } from \"../types\";\nimport {\n constructorCode,\n descriptors,\n getPrimitiveType,\n PRIMITIVE_TYPE_RANGE\n} from \"../types/descriptors\";\n\nexport const typeSerializer = {\n serialize(type: SType, writer: SigmaByteWriter) {\n if (type.embeddable) {\n writer.write(type.code);\n } else if (type.code === descriptors.unit.code) {\n writer.write(type.code);\n } else if (isColl(type)) {\n if (type.elementsType.embeddable) {\n writer.write(descriptors.coll.simpleCollTypeCode + type.elementsType.code);\n } else if (isColl(type.elementsType)) {\n const nestedColl = type.elementsType;\n if (nestedColl.elementsType.embeddable) {\n writer.write(\n descriptors.coll.nestedCollTypeCode + nestedColl.elementsType.code\n );\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(nestedColl, writer);\n }\n } else {\n writer.write(descriptors.coll.simpleCollTypeCode);\n this.serialize(type.elementsType, writer);\n }\n } else if (isTuple(type)) {\n switch (type.elementsType.length) {\n case 2: {\n const left = first(type.elementsType);\n const right = last(type.elementsType);\n\n if (left.embeddable) {\n if (left.code === right.code) {\n // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n writer.write(descriptors.tuple.symmetricPairTypeCode + left.code);\n } else {\n // Pair of types where first is primitive (`(_, Int)`)\n writer.write(descriptors.tuple.pairOneTypeCode + left.code);\n this.serialize(right, writer);\n }\n } else if (right.embeddable) {\n // Pair of types where second is primitive (`(Int, _)`)\n writer.write(descriptors.tuple.pairTwoTypeCode + right.code);\n this.serialize(left, writer);\n } else {\n // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n writer.write(descriptors.tuple.pairOneTypeCode);\n this.serialize(left, writer);\n this.serialize(right, writer);\n }\n\n return;\n }\n case 3:\n writer.write(descriptors.tuple.tripleTypeCode);\n break;\n case 4:\n writer.write(descriptors.tuple.quadrupleTypeCode);\n break;\n default: {\n const len = type.elementsType.length;\n assert(\n len >= 2 && len <= 255,\n \"Invalid type: tuples must have between 2 and 255 items.\"\n );\n\n // Generic tuple\n writer.write(descriptors.tuple.genericTupleTypeCode);\n writer.writeVLQ(len);\n }\n }\n\n for (let i = 0; i < type.elementsType.length; i++) {\n this.serialize(type.elementsType[i], writer);\n }\n } else {\n throw new Error(\"Serialization error: type not implemented.\");\n }\n },\n\n deserialize(r: SigmaByteReader): SType {\n const byte = r.readByte();\n assert(byte > 0, `Parsing Error: Unexpected type code '0x${byte.toString(16)}'`);\n\n if (byte < descriptors.tuple.genericTupleTypeCode) {\n const ctorCode = Math.floor(byte / PRIMITIVE_TYPE_RANGE);\n const embdCode = Math.floor(byte % PRIMITIVE_TYPE_RANGE);\n\n switch (ctorCode) {\n case constructorCode.embeddable: {\n return getPrimitiveType(embdCode);\n }\n case constructorCode.simpleColl: {\n const internal =\n embdCode === 0 ? this.deserialize(r) : getPrimitiveType(embdCode);\n\n return new SCollType(internal);\n }\n case constructorCode.nestedColl: {\n return new SCollType(new SCollType(getPrimitiveType(embdCode)));\n }\n case constructorCode.pairOne: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r)] // Pair of non-primitive types (`((Int, Byte), (Boolean,Box))`, etc.)\n : [getPrimitiveType(embdCode), this.deserialize(r)]; // Pair of types where first is primitive (`(_, Int)`)\n\n return new STupleType(internal);\n }\n case constructorCode.pairTwo: {\n const internal =\n embdCode === 0\n ? [this.deserialize(r), this.deserialize(r), this.deserialize(r)] // Triple of types\n : [this.deserialize(r), getPrimitiveType(embdCode)];\n\n return new STupleType(internal);\n }\n case constructorCode.symmetricPair: {\n const internal =\n embdCode === 0\n ? [\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r),\n this.deserialize(r)\n ] // Quadruple of types\n : [getPrimitiveType(embdCode), getPrimitiveType(embdCode)]; // Symmetric pair of primitive types (`(Int, Int)`, `(Byte,Byte)`, etc.)\n\n return new STupleType(internal);\n }\n }\n }\n\n switch (byte) {\n case descriptors.tuple.genericTupleTypeCode: {\n const len = r.readVlq();\n const wrapped = new Array<SType>(len);\n for (let i = 0; i < len; i++) {\n wrapped[i] = this.deserialize(r);\n }\n\n return new STupleType(wrapped);\n }\n case descriptors.unit.code: {\n return descriptors.unit;\n }\n }\n\n throw new Error(\"Not implemented.\");\n }\n};\n","import { assert, isUndefined } from \"@fleet-sdk/common\";\nimport { type ByteInput, hex } from \"@fleet-sdk/crypto\";\nimport { SigmaByteReader, SigmaByteWriter } from \"./coders\";\nimport { dataSerializer } from \"./serializers/dataSerializer\";\nimport { typeSerializer } from \"./serializers/typeSerializer\";\nimport type { SType } from \"./types\";\n\nexport const MAX_CONSTANT_LENGTH = 4096;\n\nexport class SConstant<D = unknown, T extends SType = SType> {\n readonly #type: T;\n readonly #data: D;\n\n constructor(type: T, data: D) {\n this.#type = type;\n this.#data = type.coerce(data) as D;\n }\n\n static from<D, T extends SType = SType>(bytes: ByteInput): SConstant<D, T> {\n assert(bytes.length > 0, \"Empty constant bytes.\");\n\n const reader = new SigmaByteReader(bytes);\n const type = typeSerializer.deserialize(reader);\n const data = dataSerializer.deserialize(type, reader);\n\n return new SConstant(type as T, data as D);\n }\n\n get type(): T {\n return this.#type;\n }\n\n get data(): D {\n return this.#data;\n }\n\n toBytes(): Uint8Array {\n const writer = new SigmaByteWriter(MAX_CONSTANT_LENGTH);\n typeSerializer.serialize(this.type, writer);\n dataSerializer.serialize(this.data, this.type, writer);\n\n return writer.toBytes();\n }\n\n toHex(): string {\n return hex.encode(this.toBytes());\n }\n}\n\n/**\n * Decodes a byte input into a Sigma constant of type `SConstant<D, T>`.\n *\n * @template D - The data type of the constant.\n * @template T - The type of the constant.\n * @param value - The value to decode.\n * @returns The decoded constant or `undefined` if the value is `undefined` or decoding fails.\n */\nexport function decode<D = unknown, T extends SType = SType>(\n value?: ByteInput\n): SConstant<D, T> | undefined {\n if (value === undefined) return;\n\n try {\n return SConstant.from<D, T>(value);\n } catch {\n return;\n }\n}\n\n/**\n * Returns the `SType` of the given value.\n *\n * @param value - The value to check the SType of.\n * @returns The SType of the value, or `undefined` if the value is `undefined` or\n * deserialization fails.\n */\nexport function stypeof(value?: ByteInput): SType | undefined {\n if (!value) return;\n\n try {\n return typeSerializer.deserialize(new SigmaByteReader(value));\n } catch {\n return;\n }\n}\n\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput, mode: \"strict\"): T;\n/** @deprecated use `decode` instead */\nexport function parse<T>(constant: ByteInput | undefined, mode: \"safe\"): T | undefined;\n/** @deprecated use `decode` instead */\nexport function parse<T>(\n constant: ByteInput | undefined,\n mode: \"strict\" | \"safe\" = \"strict\"\n) {\n if (mode === \"strict\") return SConstant.from<T>(constant ?? \"\").data;\n if (!constant) return;\n\n try {\n return SConstant.from<T>(constant).data;\n } catch {\n return;\n }\n}\n","import {\n type Amount,\n type Box,\n type BoxCandidate,\n byteSizeOf,\n ensureBigInt,\n isDefined,\n isEmpty,\n isUndefined,\n type NonMandatoryRegisters,\n some,\n type TokenAmount\n} from \"@fleet-sdk/common\";\nimport { estimateVLQSize, SigmaByteWriter } from \"../coders\";\n\nconst MAX_UINT16_VALUE = 65535;\n\nexport function serializeBox(box: Box<Amount>): SigmaByteWriter;\nexport function serializeBox(box: Box<Amount>, writer: SigmaByteWriter): SigmaByteWriter;\nexport function serializeBox(\n box: BoxCandidate<Amount>,\n writer: SigmaByteWriter,\n distinctTokenIds: string[]\n): SigmaByteWriter;\nexport function serializeBox(\n box: Box<Amount> | BoxCandidate<Amount>,\n writer = new SigmaByteWriter(5_0000),\n distinctTokenIds?: string[]\n): SigmaByteWriter {\n writer.writeBigVLQ(ensureBigInt(box.value));\n writer.writeHex(box.ergoTree);\n writer.writeVLQ(box.creationHeight);\n writeTokens(writer, box.assets, distinctTokenIds);\n writeRegisters(writer, box.additionalRegisters);\n\n if (isDefined(distinctTokenIds)) return writer;\n if (!isBox(box)) throw new Error(\"Invalid box type.\");\n return writer.writeHex(box.transactionId).writeVLQ(box.index);\n}\n\nfunction isBox<T extends Amount>(box: Box<Amount> | BoxCandidate<Amount>): box is Box<T> {\n const castedBox = box as Box<T>;\n\n return isDefined(castedBox.transactionId) && isDefined(castedBox.index);\n}\n\nfunction writeTokens(\n writer: SigmaByteWriter,\n tokens: TokenAmount<Amount>[],\n tokenIds?: string[]\n): void {\n if (isEmpty(tokens)) {\n writer.write(0);\n\n return;\n }\n\n writer.writeVLQ(tokens.length);\n if (some(tokenIds)) {\n tokens.map((token) =>\n writer\n .writeVLQ(tokenIds.indexOf(token.tokenId))\n .writeBigVLQ(ensureBigInt(token.amount))\n );\n } else {\n tokens.map((token) =>\n writer.writeHex(token.tokenId).writeBigVLQ(ensureBigInt(token.amount))\n );\n }\n}\n\nfunction writeRegisters(writer: SigmaByteWriter, registers: NonMandatoryRegisters): void {\n const keys = Object.keys(registers).sort();\n let length = 0;\n\n for (const key of keys) {\n if (registers[key as keyof NonMandatoryRegisters]) length++;\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const register = registers[key as keyof NonMandatoryRegisters];\n if (isDefined(register)) writer.writeHex(register);\n }\n}\n\n/**\n * Estimates the byte size a box.\n * @returns byte size of the box.\n */\nexport function estimateBoxSize(\n box: Box<Amount> | BoxCandidate<Amount>,\n withValue?: Amount\n): number {\n if (isUndefined(box.creationHeight)) {\n throw new Error(\"Box size estimation error: creation height is undefined.\");\n }\n\n let size = 0;\n\n size += estimateVLQSize(isDefined(withValue) ? withValue : box.value);\n size += byteSizeOf(box.ergoTree);\n size += estimateVLQSize(box.creationHeight);\n\n size += estimateVLQSize(box.assets.length);\n for (const asset of box.assets) {\n size += byteSizeOf(asset.tokenId) + estimateVLQSize(asset.amount);\n }\n\n let registersLength = 0;\n for (const key in box.additionalRegisters) {\n const register = box.additionalRegisters[key as keyof NonMandatoryRegisters];\n if (register) {\n size += byteSizeOf(register);\n registersLength++;\n }\n }\n\n size += estimateVLQSize(registersLength);\n size += 32; // transaction id (BLAKE2b 256 hash)\n size += estimateVLQSize(isBox(box) ? box.index : MAX_UINT16_VALUE);\n\n return size;\n}\n","import {\n type Amount,\n type BoxCandidate,\n type ContextExtension,\n type DataInput,\n isDefined,\n type UnsignedInput\n} from \"@fleet-sdk/common\";\nimport { SigmaByteWriter } from \"../coders\";\nimport { serializeBox } from \"./boxSerializer\";\n\nexport type MinimalUnsignedTransaction = {\n inputs: readonly UnsignedInput[];\n dataInputs: readonly DataInput[];\n outputs: readonly BoxCandidate<Amount>[];\n};\n\nexport function serializeTransaction(\n transaction: MinimalUnsignedTransaction\n): SigmaByteWriter {\n const writer = new SigmaByteWriter(100_000);\n\n // write inputs\n writer.writeVLQ(transaction.inputs.length);\n transaction.inputs.map((input) => writeInput(writer, input));\n\n // write data inputs\n writer.writeVLQ(transaction.dataInputs.length);\n transaction.dataInputs.map((dataInput) => writer.writeHex(dataInput.boxId));\n\n // write distinct token IDs\n const distinctTokenIds = getDistinctTokenIds(transaction.outputs);\n writer.writeVLQ(distinctTokenIds.length);\n distinctTokenIds.map((tokenId) => writer.writeHex(tokenId));\n\n // write outputs\n writer.writeVLQ(transaction.outputs.length);\n transaction.outputs.map((output) => serializeBox(output, writer, distinctTokenIds));\n\n return writer;\n}\n\nfunction writeInput(writer: SigmaByteWriter, input: UnsignedInput): void {\n writer.writeHex(input.boxId);\n writer.write(0); // empty proof\n writeExtension(writer, input.extension);\n}\n\nfunction writeExtension(writer: SigmaByteWriter, extension: ContextExtension): void {\n const keys = Object.keys(extension);\n let length = 0;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n length++;\n }\n }\n\n writer.writeVLQ(length);\n if (length === 0) return;\n\n for (const key of keys) {\n const ext = extension[key as unknown as keyof ContextExtension];\n if (isDefined(ext)) {\n writer.writeVLQ(Number(key)).writeHex(ext);\n }\n }\n}\n\nfunction getDistinctTokenIds(outputs: readonly BoxCandidate<Amount>[]) {\n const tokenIds = new Set<string>();\n outputs.flatMap((output) => output.assets.map((asset) => tokenIds.add(asset.tokenId)));\n\n return Array.from(tokenIds);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleet-sdk/serializer",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Ergo constant serializer and parser.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -31,8 +31,8 @@
31
31
  "serialization"
32
32
  ],
33
33
  "dependencies": {
34
- "@fleet-sdk/common": "^0.4.1",
35
- "@fleet-sdk/crypto": "^0.5.0"
34
+ "@fleet-sdk/common": "^0.6.4",
35
+ "@fleet-sdk/crypto": "^0.6.4"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=18"