@layerzerolabs/lz-serdes 3.0.16 → 3.0.17
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 +7 -0
- package/dist/index.cjs +13 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
-
var result =
|
|
6
|
+
var result = __getOwnPropDesc(target, key) ;
|
|
7
7
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
8
|
if (decorator = decorators[i])
|
|
9
|
-
result = (
|
|
10
|
-
if (
|
|
11
|
-
__defProp(target, key, result);
|
|
9
|
+
result = (decorator(target, key, result) ) || result;
|
|
10
|
+
if (result) __defProp(target, key, result);
|
|
12
11
|
return result;
|
|
13
12
|
};
|
|
14
13
|
|
|
@@ -198,35 +197,35 @@ var Serializer = class {
|
|
|
198
197
|
};
|
|
199
198
|
__decorateClass([
|
|
200
199
|
checkNumberRange(0, MAX_U8_NUMBER)
|
|
201
|
-
], Serializer.prototype, "serializeU8"
|
|
200
|
+
], Serializer.prototype, "serializeU8");
|
|
202
201
|
__decorateClass([
|
|
203
202
|
checkNumberRange(0, MAX_U16_NUMBER)
|
|
204
|
-
], Serializer.prototype, "serializeU16"
|
|
203
|
+
], Serializer.prototype, "serializeU16");
|
|
205
204
|
__decorateClass([
|
|
206
205
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
207
|
-
], Serializer.prototype, "serializeU32"
|
|
206
|
+
], Serializer.prototype, "serializeU32");
|
|
208
207
|
__decorateClass([
|
|
209
208
|
checkNumberRange(BigInt(0), MAX_U64_BIG_INT)
|
|
210
|
-
], Serializer.prototype, "serializeU64"
|
|
209
|
+
], Serializer.prototype, "serializeU64");
|
|
211
210
|
__decorateClass([
|
|
212
211
|
checkNumberRange(BigInt(0), MAX_U128_BIG_INT)
|
|
213
|
-
], Serializer.prototype, "serializeU128"
|
|
212
|
+
], Serializer.prototype, "serializeU128");
|
|
214
213
|
__decorateClass([
|
|
215
214
|
checkNumberRange(BigInt(0), MAX_U256_BIG_INT)
|
|
216
|
-
], Serializer.prototype, "serializeU256"
|
|
215
|
+
], Serializer.prototype, "serializeU256");
|
|
217
216
|
__decorateClass([
|
|
218
217
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
219
|
-
], Serializer.prototype, "serializeU32AsUleb128"
|
|
218
|
+
], Serializer.prototype, "serializeU32AsUleb128");
|
|
220
219
|
__decorateClass([
|
|
221
220
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
222
|
-
], Serializer.prototype, "serializeU32AsUbeb128"
|
|
221
|
+
], Serializer.prototype, "serializeU32AsUbeb128");
|
|
223
222
|
function checkNumberRange(minValue, maxValue, message) {
|
|
224
223
|
return (target, propertyKey, descriptor) => {
|
|
225
224
|
const childFunction = descriptor.value;
|
|
226
225
|
descriptor.value = function deco(value) {
|
|
227
226
|
const valueBigInt = BigInt(value.toString());
|
|
228
227
|
if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {
|
|
229
|
-
throw new Error(
|
|
228
|
+
throw new Error("Value is out of range");
|
|
230
229
|
}
|
|
231
230
|
return childFunction.apply(this, [value]);
|
|
232
231
|
};
|
|
@@ -570,5 +569,5 @@ exports.bcsToBytes = bcsToBytes;
|
|
|
570
569
|
exports.deserializeVector = deserializeVector;
|
|
571
570
|
exports.serializeVector = serializeVector;
|
|
572
571
|
exports.serializeVectorWithFunc = serializeVectorWithFunc;
|
|
573
|
-
//# sourceMappingURL=
|
|
572
|
+
//# sourceMappingURL=index.cjs.map
|
|
574
573
|
//# sourceMappingURL=index.cjs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;AAClC,aAAW,cAAc,KAAK;AAC9B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,iBAAiB,OAAyB;AACtD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,cAAc,KAAK;AAC9B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,iBAAiB,OAAuB;AACpD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,cAAc,KAAK;AAC9B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,gBAAgB,OAAsB;AAClD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,aAAa,KAAK;AAC7B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,kBAAkB,OAAqB;AACnD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,eAAe,KAAK;AAC/B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,uBAAuB,OAAqB;AACxD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,oBAAoB,KAAK;AACpC,SAAO,WAAW,SAAS;AAC/B","sourcesContent":["// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Upper bound value for uint8.\n * @type {Uint8}\n */\nexport const MAX_U8_NUMBER: Uint8 = 255\n\n/**\n * Upper bound value for uint16.\n * @type {Uint16}\n */\nexport const MAX_U16_NUMBER: Uint16 = 65535\n\n/**\n * Upper bound value for uint32.\n * @type {Uint32}\n */\nexport const MAX_U32_NUMBER: Uint32 = 4294967295\n\n/**\n * Upper bound value for uint64.\n * @type {Uint64}\n */\nexport const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n\n\n/**\n * Upper bound value for uint128.\n * @type {Uint128}\n */\nexport const MAX_U128_BIG_INT: Uint128 = 340282366920938463463374607431768211455n\n\n/**\n * Upper bound value for uint256.\n * @type {Uint256}\n */\nexport const MAX_U256_BIG_INT: Uint256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U256_BIG_INT,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n} from './consts'\nimport { AnyNumber, Bytes, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Class representing a serializer for various data types.\n */\nexport class Serializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Serializer.\n *\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(littleEndian = true) {\n this.littleEndian = littleEndian\n this.buffer = new ArrayBuffer(64)\n this.offset = 0\n }\n\n /**\n * Ensures that the buffer has enough space to handle the specified number of bytes.\n * If the buffer is not large enough, it will be resized to accommodate the additional bytes.\n *\n * @param {number} bytes - The number of bytes to ensure space for.\n */\n private ensureBufferWillHandleSize(bytes: number): void {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2)\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer))\n this.buffer = newBuffer\n }\n }\n\n /**\n * Serializes the given byte values into the buffer.\n *\n * @param {Bytes} values - The byte values to serialize.\n */\n protected serialize(values: Bytes): void {\n this.ensureBufferWillHandleSize(values.length)\n new Uint8Array(this.buffer, this.offset).set(values)\n this.offset += values.length\n }\n\n /**\n * Serializes a value using the specified DataView function.\n *\n * @param {(byteOffset: number, value: number, littleEndian?: boolean) => void} fn - The DataView function to use for serialization.\n * @param {number} bytesLength - The length of the bytes to serialize.\n * @param {number} value - The value to serialize.\n */\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number\n ): void {\n this.ensureBufferWillHandleSize(bytesLength)\n const dv = new DataView(this.buffer, this.offset)\n fn.apply(dv, [0, value, this.littleEndian])\n this.offset += bytesLength\n }\n\n /**\n * Serializes a string. UTF8 string is supported. Serializes the string's bytes length \"l\" first,\n * and then serializes \"l\" bytes of the string content.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"çå∞≠¢õß∂ƒ∫\");\n * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));\n * ```\n */\n serializeStr(value: string): this {\n const textEncoder = new TextEncoder()\n this.serializeBytes(textEncoder.encode(value))\n return this\n }\n\n /**\n * Serializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n */\n serializeBytes(value: Bytes): this {\n if (this.littleEndian) {\n this.serializeU32AsUleb128(value.length)\n } else {\n this.serializeU32AsUbeb128(value.length)\n }\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore length doesn't need to be\n * serialized to help deserialization. When deserializing, the number of\n * bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Bytes): this {\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n */\n serializeBool(value: boolean): this {\n if (typeof value !== 'boolean') {\n throw new Error('Value needs to be a boolean')\n }\n const byteValue = value ? 1 : 0\n this.serialize(new Uint8Array([byteValue]))\n return this\n }\n\n /**\n * Serializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8): this {\n this.serialize(new Uint8Array([value]))\n return this\n }\n\n /**\n * Serializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value)\n return this\n }\n\n /**\n * Serializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value)\n return this\n }\n\n /**\n * Serializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber): this {\n const low = BigInt(value.toString()) & BigInt(MAX_U32_NUMBER)\n const high = BigInt(value.toString()) >> BigInt(32)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU32(Number(x))\n })\n return this\n }\n\n /**\n * Serializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U64_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(64)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU64(x)\n })\n return this\n }\n\n /**\n * Serializes a uint256 number.\n *\n * layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U128_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(128)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU128(x)\n })\n return this\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32): this {\n let value = val\n const valueArray = []\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80)\n value >>>= 7\n }\n valueArray.push(value)\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUbeb128(val: Uint32): this {\n let value = val\n const valueArray: Uint8[] = []\n\n valueArray.unshift(value & 0x7f)\n while (value >>> 7 !== 0) {\n value >>>= 7\n const byte = (value & 0x7f) | 0x80\n valueArray.unshift(byte)\n }\n\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Returns the buffered bytes\n *\n * @returns {Bytes} The buffered bytes.\n */\n getBytes(): Bytes {\n return new Uint8Array(this.buffer).slice(0, this.offset)\n }\n}\n\n/**\n * Creates a decorator to make sure the arg value of the decorated function is within a range.\n * @param minValue The arg value of decorated function must >= minValue\n * @param maxValue The arg value of decorated function must <= maxValue\n * @param message Error message\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T, message?: string) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {\n /* eslint-disable @typescript-eslint/no-unsafe-assignment */\n const childFunction = descriptor.value as (value: AnyNumber) => any\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber): void {\n const valueBigInt = BigInt(value.toString())\n if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {\n throw new Error(message ?? 'Value is out of range')\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return childFunction.apply(this, [value])\n }\n return descriptor\n /* eslint-enable @typescript-eslint/no-unsafe-assignment */\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport { MAX_U32_NUMBER } from './consts'\nimport { Bytes, Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Class representing a deserializer for various data types.\n */\nexport class Deserializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Deserializer.\n *\n * @param {Bytes} data - The data to deserialize.\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(data: Bytes, littleEndian = true) {\n this.littleEndian = littleEndian\n // copies data to prevent outside mutation of buffer.\n this.buffer = new ArrayBuffer(data.length)\n new Uint8Array(this.buffer).set(data, 0)\n this.offset = 0\n }\n\n /**\n * Reads a specified number of bytes from the buffer.\n *\n * @param {number} length - The number of bytes to read.\n * @returns {ArrayBuffer} The read bytes.\n * @throws {Error} If the end of the buffer is reached.\n */\n private read(length: number): ArrayBuffer {\n if (this.offset + length > this.buffer.byteLength) {\n throw new Error('Reached to the end of buffer')\n }\n\n const bytes = this.buffer.slice(this.offset, this.offset + length)\n this.offset += length\n return bytes\n }\n\n /**\n * Returns the number of remaining bytes in the buffer.\n *\n * @returns {number} The number of remaining bytes.\n */\n public remaining(): number {\n return this.buffer.byteLength - this.offset\n }\n\n /**\n * Rewinds the buffer by a specified number of bytes.\n *\n * @param {number} length - The number of bytes to rewind.\n */\n public rewind(length: number): void {\n this.offset -= length\n }\n\n /**\n * Deserializes a string. UTF8 string is supported. Reads the string's bytes length \"l\" first,\n * and then reads \"l\" bytes of content. Decodes the byte array into a string.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);\n * assert(deserializer.deserializeStr() === \"çå∞≠¢õß∂ƒ∫\");\n * ```\n * @returns {string} The deserialized string.\n */\n deserializeStr(): string {\n const value = this.deserializeBytes()\n const textDecoder = new TextDecoder()\n return textDecoder.decode(value)\n }\n\n /**\n * Deserializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n *\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeBytes(): Bytes {\n const len = this.littleEndian ? this.deserializeUleb128AsU32() : this.deserializeUbeb128AsU32()\n\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes an array of bytes. The number of bytes to read is already known.\n *\n * @param {number} len - The number of bytes to read.\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeFixedBytes(len: number): Bytes {\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n *\n * @returns {boolean} The deserialized boolean value.\n * @throws {Error} If the boolean value is invalid.\n */\n deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0]\n if (bool !== 1 && bool !== 0) {\n throw new Error('Invalid boolean value')\n }\n return bool === 1\n }\n\n /**\n * Deserializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n *\n * @returns {Uint8} The deserialized uint8 number.\n */\n deserializeU8(): Uint8 {\n return new DataView(this.read(1)).getUint8(0)\n }\n\n /**\n * Deserializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);\n * assert(deserializer.deserializeU16() === 4660);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);\n * assert(deserializer.deserializeU16() === 4660);\n * ```\n * @returns {Uint16} The deserialized uint16 number.\n */\n deserializeU16(): Uint16 {\n return new DataView(this.read(2)).getUint16(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU32() === 305419896);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);\n * assert(deserializer.deserializeU32() === 305419896);\n * ```\n * @returns {Uint32} The deserialized uint32 number.\n */\n deserializeU32(): Uint32 {\n return new DataView(this.read(4)).getUint32(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * ```\n * @returns {Uint64} The deserialized uint64 number.\n */\n deserializeU64(): Uint64 {\n const low = this.deserializeU32()\n const high = this.deserializeU32()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((BigInt(values[1]) << BigInt(32)) | BigInt(values[0]))\n }\n\n /**\n * Deserializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n *\n * @returns {Uint128} The deserialized uint128 number.\n */\n deserializeU128(): Uint128 {\n const low = this.deserializeU64()\n const high = this.deserializeU64()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(64)) | values[0])\n }\n\n /**\n * Deserializes a uint256 number.\n *\n * layout for \"uint256\": Thirty-two bytes. Binary format in little-endian representation.\n *\n * @returns {Uint256} The deserialized uint256 number.\n */\n deserializeU256(): Uint256 {\n const low = this.deserializeU128()\n const high = this.deserializeU128()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(128)) | values[0])\n }\n\n /**\n * Deserializes a uleb128 encoded uint32 number.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized uleb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUleb128AsU32(): Uint32 {\n let value = BigInt(0)\n let shift = 0\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f) << BigInt(shift)\n\n if ((byte & 0x80) === 0) {\n break\n }\n shift += 7\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing uleb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n\n /**\n * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized ubeb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUbeb128AsU32(): Uint32 {\n let value = BigInt(0)\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f)\n\n if ((byte & 0x80) === 0) {\n break\n }\n value = value << BigInt(7)\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing ubeb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer } from './deserializer'\nimport { Serializer } from './serializer'\nimport { AnyNumber, Bytes, Seq, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Interface representing a serializable object.\n */\ninterface Serializable {\n /**\n * Serializes the object using the provided serializer.\n *\n * @param {Serializer} serializer - The serializer to use.\n */\n serialize(serializer: Serializer): void\n}\n\n/**\n * Interface representing a deserializable object.\n */\ninterface Deserializable<T> {\n /**\n * Deserializes the object using the provided deserializer.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @returns {T} The deserialized object.\n */\n deserialize(deserializer: Deserializer): T\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\ninterface ISerializer {\n [key: string]: (item: unknown) => void\n}\n\n/**\n * Serializes a vector of values that are \"Serializable\".\n *\n * @param {Seq<T>} value - The vector of values to serialize.\n * @param {Serializer} serializer - The serializer to use.\n */\nexport function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void {\n serializer.serializeU32AsUleb128(value.length)\n value.forEach((item: T) => {\n item.serialize(serializer)\n })\n}\n\n/**\n * Serializes a vector with a specified item serialization function.\n * Very dynamic function and bypasses static typechecking.\n *\n * @param {unknown[]} value - The vector of values to serialize.\n * @param {string} func - The name of the serialization function to use.\n * @returns {Bytes} The serialized bytes.\n * @throws {Error} If the specified function does not exist on the serializer.\n */\nexport function serializeVectorWithFunc(value: unknown[], func: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32AsUleb128(value.length)\n\n const f = (serializer as unknown as ISerializer)[func]\n if (typeof f !== 'function') {\n throw new Error(`The function '${func}' does not exist on the serializer.`)\n }\n\n value.forEach((item) => {\n f.call(serializer, item)\n })\n return serializer.getBytes()\n}\n\n/**\n * Deserializes a vector of values.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @param {Deserializable<T>} cls - The class to use for deserialization.\n * @returns {T[]} The deserialized vector of values.\n */\nexport function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[] {\n const length = deserializer.deserializeUleb128AsU32()\n const list: T[] = []\n for (let i = 0; i < length; i += 1) {\n list.push(cls.deserialize(deserializer))\n }\n return list\n}\n\n/**\n * Serializes a value to bytes using BCS (Binary Canonical Serialization).\n *\n * @param {T} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsToBytes<T extends Serializable>(value: T): Bytes {\n const serializer = new Serializer()\n value.serialize(serializer)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint64 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeUint64(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU64(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint8 value to bytes using BCS.\n *\n * @param {Uint8} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU8(value: Uint8): Bytes {\n const serializer = new Serializer()\n serializer.serializeU8(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint16 value to bytes using BCS.\n *\n * @param {Uint16} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU16(value: Uint16): Bytes {\n const serializer = new Serializer()\n serializer.serializeU16(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint32 value to bytes using BCS.\n *\n * @param {Uint32} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU32(value: Uint32): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint128 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU128(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU128(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint256 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU256(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU256(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a boolean value to bytes using BCS.\n *\n * @param {boolean} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBool(value: boolean): Bytes {\n const serializer = new Serializer()\n serializer.serializeBool(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a string value to bytes using BCS.\n *\n * @param {string} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeStr(value: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeStr(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeBytes(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a fixed-length byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeFixedBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeFixedBytes(value)\n return serializer.getBytes()\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/consts.ts","../src/serializer.ts","../src/deserializer.ts","../src/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAUO,IAAM,aAAuB,GAAA,GAAA;AAM7B,IAAM,cAAyB,GAAA,KAAA;AAM/B,IAAM,cAAyB,GAAA,UAAA;AAM/B,IAAM,eAA0B,GAAA,qBAAA;AAMhC,IAAM,gBAA4B,GAAA,wCAAA;AAMlC,IAAM,gBAA4B,GAAA,+EAAA;;;ACtBlC,IAAM,aAAN,MAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWpB,WAAA,CAAY,eAAe,IAAM,EAAA;AAC7B,IAAA,IAAA,CAAK,YAAe,GAAA,YAAA;AACpB,IAAK,IAAA,CAAA,MAAA,GAAS,IAAI,WAAA,CAAY,EAAE,CAAA;AAChC,IAAA,IAAA,CAAK,MAAS,GAAA,CAAA;AAAA;AAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,2BAA2B,KAAqB,EAAA;AACpD,IAAA,OAAO,IAAK,CAAA,MAAA,CAAO,UAAa,GAAA,IAAA,CAAK,SAAS,KAAO,EAAA;AACjD,MAAA,MAAM,YAAY,IAAI,WAAA,CAAY,IAAK,CAAA,MAAA,CAAO,aAAa,CAAC,CAAA;AAC5D,MAAI,IAAA,UAAA,CAAW,SAAS,CAAE,CAAA,GAAA,CAAI,IAAI,UAAW,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA;AACzD,MAAA,IAAA,CAAK,MAAS,GAAA,SAAA;AAAA;AAClB;AACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,UAAU,MAAqB,EAAA;AACrC,IAAK,IAAA,CAAA,0BAAA,CAA2B,OAAO,MAAM,CAAA;AAC7C,IAAA,IAAI,WAAW,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;AAClD,EAAM,MAAA,UAAA,GAAa,IAAI,UAAW,EAAA;AAClC,EAAA,UAAA,CAAW,aAAa,KAAK,CAAA;AAC7B,EAAA,OAAO,WAAW,QAAS,EAAA;AAC/B;AAQO,SAAS,kBAAkB,KAAqB,EAAA;AACnD,EAAM,MAAA,UAAA,GAAa,IAAI,UAAW,EAAA;AAClC,EAAA,UAAA,CAAW,eAAe,KAAK,CAAA;AAC/B,EAAA,OAAO,WAAW,QAAS,EAAA;AAC/B;AAQO,SAAS,uBAAuB,KAAqB,EAAA;AACxD,EAAM,MAAA,UAAA,GAAa,IAAI,UAAW,EAAA;AAClC,EAAA,UAAA,CAAW,oBAAoB,KAAK,CAAA;AACpC,EAAA,OAAO,WAAW,QAAS,EAAA;AAC/B","file":"index.cjs","sourcesContent":["// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Upper bound value for uint8.\n * @type {Uint8}\n */\nexport const MAX_U8_NUMBER: Uint8 = 255\n\n/**\n * Upper bound value for uint16.\n * @type {Uint16}\n */\nexport const MAX_U16_NUMBER: Uint16 = 65535\n\n/**\n * Upper bound value for uint32.\n * @type {Uint32}\n */\nexport const MAX_U32_NUMBER: Uint32 = 4294967295\n\n/**\n * Upper bound value for uint64.\n * @type {Uint64}\n */\nexport const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n\n\n/**\n * Upper bound value for uint128.\n * @type {Uint128}\n */\nexport const MAX_U128_BIG_INT: Uint128 = 340282366920938463463374607431768211455n\n\n/**\n * Upper bound value for uint256.\n * @type {Uint256}\n */\nexport const MAX_U256_BIG_INT: Uint256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U256_BIG_INT,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n} from './consts'\nimport { AnyNumber, Bytes, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Class representing a serializer for various data types.\n */\nexport class Serializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Serializer.\n *\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(littleEndian = true) {\n this.littleEndian = littleEndian\n this.buffer = new ArrayBuffer(64)\n this.offset = 0\n }\n\n /**\n * Ensures that the buffer has enough space to handle the specified number of bytes.\n * If the buffer is not large enough, it will be resized to accommodate the additional bytes.\n *\n * @param {number} bytes - The number of bytes to ensure space for.\n */\n private ensureBufferWillHandleSize(bytes: number): void {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2)\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer))\n this.buffer = newBuffer\n }\n }\n\n /**\n * Serializes the given byte values into the buffer.\n *\n * @param {Bytes} values - The byte values to serialize.\n */\n protected serialize(values: Bytes): void {\n this.ensureBufferWillHandleSize(values.length)\n new Uint8Array(this.buffer, this.offset).set(values)\n this.offset += values.length\n }\n\n /**\n * Serializes a value using the specified DataView function.\n *\n * @param {(byteOffset: number, value: number, littleEndian?: boolean) => void} fn - The DataView function to use for serialization.\n * @param {number} bytesLength - The length of the bytes to serialize.\n * @param {number} value - The value to serialize.\n */\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number\n ): void {\n this.ensureBufferWillHandleSize(bytesLength)\n const dv = new DataView(this.buffer, this.offset)\n fn.apply(dv, [0, value, this.littleEndian])\n this.offset += bytesLength\n }\n\n /**\n * Serializes a string. UTF8 string is supported. Serializes the string's bytes length \"l\" first,\n * and then serializes \"l\" bytes of the string content.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"çå∞≠¢õß∂ƒ∫\");\n * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));\n * ```\n */\n serializeStr(value: string): this {\n const textEncoder = new TextEncoder()\n this.serializeBytes(textEncoder.encode(value))\n return this\n }\n\n /**\n * Serializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n */\n serializeBytes(value: Bytes): this {\n if (this.littleEndian) {\n this.serializeU32AsUleb128(value.length)\n } else {\n this.serializeU32AsUbeb128(value.length)\n }\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore length doesn't need to be\n * serialized to help deserialization. When deserializing, the number of\n * bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Bytes): this {\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n */\n serializeBool(value: boolean): this {\n if (typeof value !== 'boolean') {\n throw new Error('Value needs to be a boolean')\n }\n const byteValue = value ? 1 : 0\n this.serialize(new Uint8Array([byteValue]))\n return this\n }\n\n /**\n * Serializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8): this {\n this.serialize(new Uint8Array([value]))\n return this\n }\n\n /**\n * Serializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value)\n return this\n }\n\n /**\n * Serializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value)\n return this\n }\n\n /**\n * Serializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber): this {\n const low = BigInt(value.toString()) & BigInt(MAX_U32_NUMBER)\n const high = BigInt(value.toString()) >> BigInt(32)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU32(Number(x))\n })\n return this\n }\n\n /**\n * Serializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U64_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(64)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU64(x)\n })\n return this\n }\n\n /**\n * Serializes a uint256 number.\n *\n * layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U128_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(128)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU128(x)\n })\n return this\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32): this {\n let value = val\n const valueArray = []\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80)\n value >>>= 7\n }\n valueArray.push(value)\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUbeb128(val: Uint32): this {\n let value = val\n const valueArray: Uint8[] = []\n\n valueArray.unshift(value & 0x7f)\n while (value >>> 7 !== 0) {\n value >>>= 7\n const byte = (value & 0x7f) | 0x80\n valueArray.unshift(byte)\n }\n\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Returns the buffered bytes\n *\n * @returns {Bytes} The buffered bytes.\n */\n getBytes(): Bytes {\n return new Uint8Array(this.buffer).slice(0, this.offset)\n }\n}\n\n/**\n * Creates a decorator to make sure the arg value of the decorated function is within a range.\n * @param minValue The arg value of decorated function must >= minValue\n * @param maxValue The arg value of decorated function must <= maxValue\n * @param message Error message\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T, message?: string) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {\n /* eslint-disable @typescript-eslint/no-unsafe-assignment */\n const childFunction = descriptor.value as (value: AnyNumber) => any\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber): void {\n const valueBigInt = BigInt(value.toString())\n if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {\n throw new Error(message ?? 'Value is out of range')\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return childFunction.apply(this, [value])\n }\n return descriptor\n /* eslint-enable @typescript-eslint/no-unsafe-assignment */\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport { MAX_U32_NUMBER } from './consts'\nimport { Bytes, Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Class representing a deserializer for various data types.\n */\nexport class Deserializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Deserializer.\n *\n * @param {Bytes} data - The data to deserialize.\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(data: Bytes, littleEndian = true) {\n this.littleEndian = littleEndian\n // copies data to prevent outside mutation of buffer.\n this.buffer = new ArrayBuffer(data.length)\n new Uint8Array(this.buffer).set(data, 0)\n this.offset = 0\n }\n\n /**\n * Reads a specified number of bytes from the buffer.\n *\n * @param {number} length - The number of bytes to read.\n * @returns {ArrayBuffer} The read bytes.\n * @throws {Error} If the end of the buffer is reached.\n */\n private read(length: number): ArrayBuffer {\n if (this.offset + length > this.buffer.byteLength) {\n throw new Error('Reached to the end of buffer')\n }\n\n const bytes = this.buffer.slice(this.offset, this.offset + length)\n this.offset += length\n return bytes\n }\n\n /**\n * Returns the number of remaining bytes in the buffer.\n *\n * @returns {number} The number of remaining bytes.\n */\n public remaining(): number {\n return this.buffer.byteLength - this.offset\n }\n\n /**\n * Rewinds the buffer by a specified number of bytes.\n *\n * @param {number} length - The number of bytes to rewind.\n */\n public rewind(length: number): void {\n this.offset -= length\n }\n\n /**\n * Deserializes a string. UTF8 string is supported. Reads the string's bytes length \"l\" first,\n * and then reads \"l\" bytes of content. Decodes the byte array into a string.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);\n * assert(deserializer.deserializeStr() === \"çå∞≠¢õß∂ƒ∫\");\n * ```\n * @returns {string} The deserialized string.\n */\n deserializeStr(): string {\n const value = this.deserializeBytes()\n const textDecoder = new TextDecoder()\n return textDecoder.decode(value)\n }\n\n /**\n * Deserializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n *\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeBytes(): Bytes {\n const len = this.littleEndian ? this.deserializeUleb128AsU32() : this.deserializeUbeb128AsU32()\n\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes an array of bytes. The number of bytes to read is already known.\n *\n * @param {number} len - The number of bytes to read.\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeFixedBytes(len: number): Bytes {\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n *\n * @returns {boolean} The deserialized boolean value.\n * @throws {Error} If the boolean value is invalid.\n */\n deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0]\n if (bool !== 1 && bool !== 0) {\n throw new Error('Invalid boolean value')\n }\n return bool === 1\n }\n\n /**\n * Deserializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n *\n * @returns {Uint8} The deserialized uint8 number.\n */\n deserializeU8(): Uint8 {\n return new DataView(this.read(1)).getUint8(0)\n }\n\n /**\n * Deserializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);\n * assert(deserializer.deserializeU16() === 4660);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);\n * assert(deserializer.deserializeU16() === 4660);\n * ```\n * @returns {Uint16} The deserialized uint16 number.\n */\n deserializeU16(): Uint16 {\n return new DataView(this.read(2)).getUint16(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU32() === 305419896);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);\n * assert(deserializer.deserializeU32() === 305419896);\n * ```\n * @returns {Uint32} The deserialized uint32 number.\n */\n deserializeU32(): Uint32 {\n return new DataView(this.read(4)).getUint32(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * ```\n * @returns {Uint64} The deserialized uint64 number.\n */\n deserializeU64(): Uint64 {\n const low = this.deserializeU32()\n const high = this.deserializeU32()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((BigInt(values[1]) << BigInt(32)) | BigInt(values[0]))\n }\n\n /**\n * Deserializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n *\n * @returns {Uint128} The deserialized uint128 number.\n */\n deserializeU128(): Uint128 {\n const low = this.deserializeU64()\n const high = this.deserializeU64()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(64)) | values[0])\n }\n\n /**\n * Deserializes a uint256 number.\n *\n * layout for \"uint256\": Thirty-two bytes. Binary format in little-endian representation.\n *\n * @returns {Uint256} The deserialized uint256 number.\n */\n deserializeU256(): Uint256 {\n const low = this.deserializeU128()\n const high = this.deserializeU128()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(128)) | values[0])\n }\n\n /**\n * Deserializes a uleb128 encoded uint32 number.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized uleb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUleb128AsU32(): Uint32 {\n let value = BigInt(0)\n let shift = 0\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f) << BigInt(shift)\n\n if ((byte & 0x80) === 0) {\n break\n }\n shift += 7\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing uleb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n\n /**\n * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized ubeb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUbeb128AsU32(): Uint32 {\n let value = BigInt(0)\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f)\n\n if ((byte & 0x80) === 0) {\n break\n }\n value = value << BigInt(7)\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing ubeb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer } from './deserializer'\nimport { Serializer } from './serializer'\nimport { AnyNumber, Bytes, Seq, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Interface representing a serializable object.\n */\ninterface Serializable {\n /**\n * Serializes the object using the provided serializer.\n *\n * @param {Serializer} serializer - The serializer to use.\n */\n serialize(serializer: Serializer): void\n}\n\n/**\n * Interface representing a deserializable object.\n */\ninterface Deserializable<T> {\n /**\n * Deserializes the object using the provided deserializer.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @returns {T} The deserialized object.\n */\n deserialize(deserializer: Deserializer): T\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\ninterface ISerializer {\n [key: string]: (item: unknown) => void\n}\n\n/**\n * Serializes a vector of values that are \"Serializable\".\n *\n * @param {Seq<T>} value - The vector of values to serialize.\n * @param {Serializer} serializer - The serializer to use.\n */\nexport function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void {\n serializer.serializeU32AsUleb128(value.length)\n value.forEach((item: T) => {\n item.serialize(serializer)\n })\n}\n\n/**\n * Serializes a vector with a specified item serialization function.\n * Very dynamic function and bypasses static typechecking.\n *\n * @param {unknown[]} value - The vector of values to serialize.\n * @param {string} func - The name of the serialization function to use.\n * @returns {Bytes} The serialized bytes.\n * @throws {Error} If the specified function does not exist on the serializer.\n */\nexport function serializeVectorWithFunc(value: unknown[], func: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32AsUleb128(value.length)\n\n const f = (serializer as unknown as ISerializer)[func]\n if (typeof f !== 'function') {\n throw new Error(`The function '${func}' does not exist on the serializer.`)\n }\n\n value.forEach((item) => {\n f.call(serializer, item)\n })\n return serializer.getBytes()\n}\n\n/**\n * Deserializes a vector of values.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @param {Deserializable<T>} cls - The class to use for deserialization.\n * @returns {T[]} The deserialized vector of values.\n */\nexport function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[] {\n const length = deserializer.deserializeUleb128AsU32()\n const list: T[] = []\n for (let i = 0; i < length; i += 1) {\n list.push(cls.deserialize(deserializer))\n }\n return list\n}\n\n/**\n * Serializes a value to bytes using BCS (Binary Canonical Serialization).\n *\n * @param {T} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsToBytes<T extends Serializable>(value: T): Bytes {\n const serializer = new Serializer()\n value.serialize(serializer)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint64 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeUint64(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU64(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint8 value to bytes using BCS.\n *\n * @param {Uint8} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU8(value: Uint8): Bytes {\n const serializer = new Serializer()\n serializer.serializeU8(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint16 value to bytes using BCS.\n *\n * @param {Uint16} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU16(value: Uint16): Bytes {\n const serializer = new Serializer()\n serializer.serializeU16(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint32 value to bytes using BCS.\n *\n * @param {Uint32} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU32(value: Uint32): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint128 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU128(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU128(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint256 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU256(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU256(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a boolean value to bytes using BCS.\n *\n * @param {boolean} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBool(value: boolean): Bytes {\n const serializer = new Serializer()\n serializer.serializeBool(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a string value to bytes using BCS.\n *\n * @param {string} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeStr(value: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeStr(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeBytes(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a fixed-length byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeFixedBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeFixedBytes(value)\n return serializer.getBytes()\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result =
|
|
4
|
+
var result = __getOwnPropDesc(target, key) ;
|
|
5
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
6
|
if (decorator = decorators[i])
|
|
7
|
-
result = (
|
|
8
|
-
if (
|
|
9
|
-
__defProp(target, key, result);
|
|
7
|
+
result = (decorator(target, key, result) ) || result;
|
|
8
|
+
if (result) __defProp(target, key, result);
|
|
10
9
|
return result;
|
|
11
10
|
};
|
|
12
11
|
|
|
@@ -196,35 +195,35 @@ var Serializer = class {
|
|
|
196
195
|
};
|
|
197
196
|
__decorateClass([
|
|
198
197
|
checkNumberRange(0, MAX_U8_NUMBER)
|
|
199
|
-
], Serializer.prototype, "serializeU8"
|
|
198
|
+
], Serializer.prototype, "serializeU8");
|
|
200
199
|
__decorateClass([
|
|
201
200
|
checkNumberRange(0, MAX_U16_NUMBER)
|
|
202
|
-
], Serializer.prototype, "serializeU16"
|
|
201
|
+
], Serializer.prototype, "serializeU16");
|
|
203
202
|
__decorateClass([
|
|
204
203
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
205
|
-
], Serializer.prototype, "serializeU32"
|
|
204
|
+
], Serializer.prototype, "serializeU32");
|
|
206
205
|
__decorateClass([
|
|
207
206
|
checkNumberRange(BigInt(0), MAX_U64_BIG_INT)
|
|
208
|
-
], Serializer.prototype, "serializeU64"
|
|
207
|
+
], Serializer.prototype, "serializeU64");
|
|
209
208
|
__decorateClass([
|
|
210
209
|
checkNumberRange(BigInt(0), MAX_U128_BIG_INT)
|
|
211
|
-
], Serializer.prototype, "serializeU128"
|
|
210
|
+
], Serializer.prototype, "serializeU128");
|
|
212
211
|
__decorateClass([
|
|
213
212
|
checkNumberRange(BigInt(0), MAX_U256_BIG_INT)
|
|
214
|
-
], Serializer.prototype, "serializeU256"
|
|
213
|
+
], Serializer.prototype, "serializeU256");
|
|
215
214
|
__decorateClass([
|
|
216
215
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
217
|
-
], Serializer.prototype, "serializeU32AsUleb128"
|
|
216
|
+
], Serializer.prototype, "serializeU32AsUleb128");
|
|
218
217
|
__decorateClass([
|
|
219
218
|
checkNumberRange(0, MAX_U32_NUMBER)
|
|
220
|
-
], Serializer.prototype, "serializeU32AsUbeb128"
|
|
219
|
+
], Serializer.prototype, "serializeU32AsUbeb128");
|
|
221
220
|
function checkNumberRange(minValue, maxValue, message) {
|
|
222
221
|
return (target, propertyKey, descriptor) => {
|
|
223
222
|
const childFunction = descriptor.value;
|
|
224
223
|
descriptor.value = function deco(value) {
|
|
225
224
|
const valueBigInt = BigInt(value.toString());
|
|
226
225
|
if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {
|
|
227
|
-
throw new Error(
|
|
226
|
+
throw new Error("Value is out of range");
|
|
228
227
|
}
|
|
229
228
|
return childFunction.apply(this, [value]);
|
|
230
229
|
};
|
|
@@ -553,5 +552,5 @@ function bcsSerializeFixedBytes(value) {
|
|
|
553
552
|
}
|
|
554
553
|
|
|
555
554
|
export { Deserializer, Serializer, bcsSerializeBool, bcsSerializeBytes, bcsSerializeFixedBytes, bcsSerializeStr, bcsSerializeU128, bcsSerializeU16, bcsSerializeU256, bcsSerializeU32, bcsSerializeU8, bcsSerializeUint64, bcsToBytes, deserializeVector, serializeVector, serializeVectorWithFunc };
|
|
556
|
-
//# sourceMappingURL=
|
|
555
|
+
//# sourceMappingURL=index.mjs.map
|
|
557
556
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/consts.ts","../src/serializer.ts","../src/deserializer.ts","../src/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAUO,IAAM,gBAAuB;AAM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AQO,SAAS,iBAAiB,OAAuB;AACpD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,cAAc,KAAK;AAC9B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,gBAAgB,OAAsB;AAClD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,aAAa,KAAK;AAC7B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,kBAAkB,OAAqB;AACnD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,eAAe,KAAK;AAC/B,SAAO,WAAW,SAAS;AAC/B;AAQO,SAAS,uBAAuB,OAAqB;AACxD,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,oBAAoB,KAAK;AACpC,SAAO,WAAW,SAAS;AAC/B","sourcesContent":["// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Upper bound value for uint8.\n * @type {Uint8}\n */\nexport const MAX_U8_NUMBER: Uint8 = 255\n\n/**\n * Upper bound value for uint16.\n * @type {Uint16}\n */\nexport const MAX_U16_NUMBER: Uint16 = 65535\n\n/**\n * Upper bound value for uint32.\n * @type {Uint32}\n */\nexport const MAX_U32_NUMBER: Uint32 = 4294967295\n\n/**\n * Upper bound value for uint64.\n * @type {Uint64}\n */\nexport const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n\n\n/**\n * Upper bound value for uint128.\n * @type {Uint128}\n */\nexport const MAX_U128_BIG_INT: Uint128 = 340282366920938463463374607431768211455n\n\n/**\n * Upper bound value for uint256.\n * @type {Uint256}\n */\nexport const MAX_U256_BIG_INT: Uint256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U256_BIG_INT,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n} from './consts'\nimport { AnyNumber, Bytes, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Class representing a serializer for various data types.\n */\nexport class Serializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Serializer.\n *\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(littleEndian = true) {\n this.littleEndian = littleEndian\n this.buffer = new ArrayBuffer(64)\n this.offset = 0\n }\n\n /**\n * Ensures that the buffer has enough space to handle the specified number of bytes.\n * If the buffer is not large enough, it will be resized to accommodate the additional bytes.\n *\n * @param {number} bytes - The number of bytes to ensure space for.\n */\n private ensureBufferWillHandleSize(bytes: number): void {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2)\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer))\n this.buffer = newBuffer\n }\n }\n\n /**\n * Serializes the given byte values into the buffer.\n *\n * @param {Bytes} values - The byte values to serialize.\n */\n protected serialize(values: Bytes): void {\n this.ensureBufferWillHandleSize(values.length)\n new Uint8Array(this.buffer, this.offset).set(values)\n this.offset += values.length\n }\n\n /**\n * Serializes a value using the specified DataView function.\n *\n * @param {(byteOffset: number, value: number, littleEndian?: boolean) => void} fn - The DataView function to use for serialization.\n * @param {number} bytesLength - The length of the bytes to serialize.\n * @param {number} value - The value to serialize.\n */\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number\n ): void {\n this.ensureBufferWillHandleSize(bytesLength)\n const dv = new DataView(this.buffer, this.offset)\n fn.apply(dv, [0, value, this.littleEndian])\n this.offset += bytesLength\n }\n\n /**\n * Serializes a string. UTF8 string is supported. Serializes the string's bytes length \"l\" first,\n * and then serializes \"l\" bytes of the string content.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"çå∞≠¢õß∂ƒ∫\");\n * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));\n * ```\n */\n serializeStr(value: string): this {\n const textEncoder = new TextEncoder()\n this.serializeBytes(textEncoder.encode(value))\n return this\n }\n\n /**\n * Serializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n */\n serializeBytes(value: Bytes): this {\n if (this.littleEndian) {\n this.serializeU32AsUleb128(value.length)\n } else {\n this.serializeU32AsUbeb128(value.length)\n }\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore length doesn't need to be\n * serialized to help deserialization. When deserializing, the number of\n * bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Bytes): this {\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n */\n serializeBool(value: boolean): this {\n if (typeof value !== 'boolean') {\n throw new Error('Value needs to be a boolean')\n }\n const byteValue = value ? 1 : 0\n this.serialize(new Uint8Array([byteValue]))\n return this\n }\n\n /**\n * Serializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8): this {\n this.serialize(new Uint8Array([value]))\n return this\n }\n\n /**\n * Serializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value)\n return this\n }\n\n /**\n * Serializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value)\n return this\n }\n\n /**\n * Serializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber): this {\n const low = BigInt(value.toString()) & BigInt(MAX_U32_NUMBER)\n const high = BigInt(value.toString()) >> BigInt(32)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU32(Number(x))\n })\n return this\n }\n\n /**\n * Serializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U64_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(64)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU64(x)\n })\n return this\n }\n\n /**\n * Serializes a uint256 number.\n *\n * layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U128_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(128)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU128(x)\n })\n return this\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32): this {\n let value = val\n const valueArray = []\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80)\n value >>>= 7\n }\n valueArray.push(value)\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUbeb128(val: Uint32): this {\n let value = val\n const valueArray: Uint8[] = []\n\n valueArray.unshift(value & 0x7f)\n while (value >>> 7 !== 0) {\n value >>>= 7\n const byte = (value & 0x7f) | 0x80\n valueArray.unshift(byte)\n }\n\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Returns the buffered bytes\n *\n * @returns {Bytes} The buffered bytes.\n */\n getBytes(): Bytes {\n return new Uint8Array(this.buffer).slice(0, this.offset)\n }\n}\n\n/**\n * Creates a decorator to make sure the arg value of the decorated function is within a range.\n * @param minValue The arg value of decorated function must >= minValue\n * @param maxValue The arg value of decorated function must <= maxValue\n * @param message Error message\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T, message?: string) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {\n /* eslint-disable @typescript-eslint/no-unsafe-assignment */\n const childFunction = descriptor.value as (value: AnyNumber) => any\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber): void {\n const valueBigInt = BigInt(value.toString())\n if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {\n throw new Error(message ?? 'Value is out of range')\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return childFunction.apply(this, [value])\n }\n return descriptor\n /* eslint-enable @typescript-eslint/no-unsafe-assignment */\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport { MAX_U32_NUMBER } from './consts'\nimport { Bytes, Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Class representing a deserializer for various data types.\n */\nexport class Deserializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Deserializer.\n *\n * @param {Bytes} data - The data to deserialize.\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(data: Bytes, littleEndian = true) {\n this.littleEndian = littleEndian\n // copies data to prevent outside mutation of buffer.\n this.buffer = new ArrayBuffer(data.length)\n new Uint8Array(this.buffer).set(data, 0)\n this.offset = 0\n }\n\n /**\n * Reads a specified number of bytes from the buffer.\n *\n * @param {number} length - The number of bytes to read.\n * @returns {ArrayBuffer} The read bytes.\n * @throws {Error} If the end of the buffer is reached.\n */\n private read(length: number): ArrayBuffer {\n if (this.offset + length > this.buffer.byteLength) {\n throw new Error('Reached to the end of buffer')\n }\n\n const bytes = this.buffer.slice(this.offset, this.offset + length)\n this.offset += length\n return bytes\n }\n\n /**\n * Returns the number of remaining bytes in the buffer.\n *\n * @returns {number} The number of remaining bytes.\n */\n public remaining(): number {\n return this.buffer.byteLength - this.offset\n }\n\n /**\n * Rewinds the buffer by a specified number of bytes.\n *\n * @param {number} length - The number of bytes to rewind.\n */\n public rewind(length: number): void {\n this.offset -= length\n }\n\n /**\n * Deserializes a string. UTF8 string is supported. Reads the string's bytes length \"l\" first,\n * and then reads \"l\" bytes of content. Decodes the byte array into a string.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);\n * assert(deserializer.deserializeStr() === \"çå∞≠¢õß∂ƒ∫\");\n * ```\n * @returns {string} The deserialized string.\n */\n deserializeStr(): string {\n const value = this.deserializeBytes()\n const textDecoder = new TextDecoder()\n return textDecoder.decode(value)\n }\n\n /**\n * Deserializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n *\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeBytes(): Bytes {\n const len = this.littleEndian ? this.deserializeUleb128AsU32() : this.deserializeUbeb128AsU32()\n\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes an array of bytes. The number of bytes to read is already known.\n *\n * @param {number} len - The number of bytes to read.\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeFixedBytes(len: number): Bytes {\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n *\n * @returns {boolean} The deserialized boolean value.\n * @throws {Error} If the boolean value is invalid.\n */\n deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0]\n if (bool !== 1 && bool !== 0) {\n throw new Error('Invalid boolean value')\n }\n return bool === 1\n }\n\n /**\n * Deserializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n *\n * @returns {Uint8} The deserialized uint8 number.\n */\n deserializeU8(): Uint8 {\n return new DataView(this.read(1)).getUint8(0)\n }\n\n /**\n * Deserializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);\n * assert(deserializer.deserializeU16() === 4660);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);\n * assert(deserializer.deserializeU16() === 4660);\n * ```\n * @returns {Uint16} The deserialized uint16 number.\n */\n deserializeU16(): Uint16 {\n return new DataView(this.read(2)).getUint16(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU32() === 305419896);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);\n * assert(deserializer.deserializeU32() === 305419896);\n * ```\n * @returns {Uint32} The deserialized uint32 number.\n */\n deserializeU32(): Uint32 {\n return new DataView(this.read(4)).getUint32(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * ```\n * @returns {Uint64} The deserialized uint64 number.\n */\n deserializeU64(): Uint64 {\n const low = this.deserializeU32()\n const high = this.deserializeU32()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((BigInt(values[1]) << BigInt(32)) | BigInt(values[0]))\n }\n\n /**\n * Deserializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n *\n * @returns {Uint128} The deserialized uint128 number.\n */\n deserializeU128(): Uint128 {\n const low = this.deserializeU64()\n const high = this.deserializeU64()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(64)) | values[0])\n }\n\n /**\n * Deserializes a uint256 number.\n *\n * layout for \"uint256\": Thirty-two bytes. Binary format in little-endian representation.\n *\n * @returns {Uint256} The deserialized uint256 number.\n */\n deserializeU256(): Uint256 {\n const low = this.deserializeU128()\n const high = this.deserializeU128()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(128)) | values[0])\n }\n\n /**\n * Deserializes a uleb128 encoded uint32 number.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized uleb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUleb128AsU32(): Uint32 {\n let value = BigInt(0)\n let shift = 0\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f) << BigInt(shift)\n\n if ((byte & 0x80) === 0) {\n break\n }\n shift += 7\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing uleb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n\n /**\n * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized ubeb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUbeb128AsU32(): Uint32 {\n let value = BigInt(0)\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f)\n\n if ((byte & 0x80) === 0) {\n break\n }\n value = value << BigInt(7)\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing ubeb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer } from './deserializer'\nimport { Serializer } from './serializer'\nimport { AnyNumber, Bytes, Seq, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Interface representing a serializable object.\n */\ninterface Serializable {\n /**\n * Serializes the object using the provided serializer.\n *\n * @param {Serializer} serializer - The serializer to use.\n */\n serialize(serializer: Serializer): void\n}\n\n/**\n * Interface representing a deserializable object.\n */\ninterface Deserializable<T> {\n /**\n * Deserializes the object using the provided deserializer.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @returns {T} The deserialized object.\n */\n deserialize(deserializer: Deserializer): T\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\ninterface ISerializer {\n [key: string]: (item: unknown) => void\n}\n\n/**\n * Serializes a vector of values that are \"Serializable\".\n *\n * @param {Seq<T>} value - The vector of values to serialize.\n * @param {Serializer} serializer - The serializer to use.\n */\nexport function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void {\n serializer.serializeU32AsUleb128(value.length)\n value.forEach((item: T) => {\n item.serialize(serializer)\n })\n}\n\n/**\n * Serializes a vector with a specified item serialization function.\n * Very dynamic function and bypasses static typechecking.\n *\n * @param {unknown[]} value - The vector of values to serialize.\n * @param {string} func - The name of the serialization function to use.\n * @returns {Bytes} The serialized bytes.\n * @throws {Error} If the specified function does not exist on the serializer.\n */\nexport function serializeVectorWithFunc(value: unknown[], func: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32AsUleb128(value.length)\n\n const f = (serializer as unknown as ISerializer)[func]\n if (typeof f !== 'function') {\n throw new Error(`The function '${func}' does not exist on the serializer.`)\n }\n\n value.forEach((item) => {\n f.call(serializer, item)\n })\n return serializer.getBytes()\n}\n\n/**\n * Deserializes a vector of values.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @param {Deserializable<T>} cls - The class to use for deserialization.\n * @returns {T[]} The deserialized vector of values.\n */\nexport function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[] {\n const length = deserializer.deserializeUleb128AsU32()\n const list: T[] = []\n for (let i = 0; i < length; i += 1) {\n list.push(cls.deserialize(deserializer))\n }\n return list\n}\n\n/**\n * Serializes a value to bytes using BCS (Binary Canonical Serialization).\n *\n * @param {T} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsToBytes<T extends Serializable>(value: T): Bytes {\n const serializer = new Serializer()\n value.serialize(serializer)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint64 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeUint64(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU64(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint8 value to bytes using BCS.\n *\n * @param {Uint8} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU8(value: Uint8): Bytes {\n const serializer = new Serializer()\n serializer.serializeU8(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint16 value to bytes using BCS.\n *\n * @param {Uint16} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU16(value: Uint16): Bytes {\n const serializer = new Serializer()\n serializer.serializeU16(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint32 value to bytes using BCS.\n *\n * @param {Uint32} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU32(value: Uint32): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint128 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU128(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU128(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint256 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU256(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU256(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a boolean value to bytes using BCS.\n *\n * @param {boolean} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBool(value: boolean): Bytes {\n const serializer = new Serializer()\n serializer.serializeBool(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a string value to bytes using BCS.\n *\n * @param {string} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeStr(value: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeStr(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeBytes(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a fixed-length byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeFixedBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeFixedBytes(value)\n return serializer.getBytes()\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/consts.ts","../src/serializer.ts","../src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EAAM,MAAA,UAAA,GAAa,IAAI,UAAW,EAAA;AAClC,EAAA,UAAA,CAAW,eAAe,KAAK,CAAA;AAC/B,EAAA,OAAO,WAAW,QAAS,EAAA;AAC/B;AAQO,SAAS,uBAAuB,KAAqB,EAAA;AACxD,EAAM,MAAA,UAAA,GAAa,IAAI,UAAW,EAAA;AAClC,EAAA,UAAA,CAAW,oBAAoB,KAAK,CAAA;AACpC,EAAA,OAAO,WAAW,QAAS,EAAA;AAC/B","file":"index.mjs","sourcesContent":["// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Upper bound value for uint8.\n * @type {Uint8}\n */\nexport const MAX_U8_NUMBER: Uint8 = 255\n\n/**\n * Upper bound value for uint16.\n * @type {Uint16}\n */\nexport const MAX_U16_NUMBER: Uint16 = 65535\n\n/**\n * Upper bound value for uint32.\n * @type {Uint32}\n */\nexport const MAX_U32_NUMBER: Uint32 = 4294967295\n\n/**\n * Upper bound value for uint64.\n * @type {Uint64}\n */\nexport const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n\n\n/**\n * Upper bound value for uint128.\n * @type {Uint128}\n */\nexport const MAX_U128_BIG_INT: Uint128 = 340282366920938463463374607431768211455n\n\n/**\n * Upper bound value for uint256.\n * @type {Uint256}\n */\nexport const MAX_U256_BIG_INT: Uint256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport {\n MAX_U128_BIG_INT,\n MAX_U16_NUMBER,\n MAX_U256_BIG_INT,\n MAX_U32_NUMBER,\n MAX_U64_BIG_INT,\n MAX_U8_NUMBER,\n} from './consts'\nimport { AnyNumber, Bytes, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Class representing a serializer for various data types.\n */\nexport class Serializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Serializer.\n *\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(littleEndian = true) {\n this.littleEndian = littleEndian\n this.buffer = new ArrayBuffer(64)\n this.offset = 0\n }\n\n /**\n * Ensures that the buffer has enough space to handle the specified number of bytes.\n * If the buffer is not large enough, it will be resized to accommodate the additional bytes.\n *\n * @param {number} bytes - The number of bytes to ensure space for.\n */\n private ensureBufferWillHandleSize(bytes: number): void {\n while (this.buffer.byteLength < this.offset + bytes) {\n const newBuffer = new ArrayBuffer(this.buffer.byteLength * 2)\n new Uint8Array(newBuffer).set(new Uint8Array(this.buffer))\n this.buffer = newBuffer\n }\n }\n\n /**\n * Serializes the given byte values into the buffer.\n *\n * @param {Bytes} values - The byte values to serialize.\n */\n protected serialize(values: Bytes): void {\n this.ensureBufferWillHandleSize(values.length)\n new Uint8Array(this.buffer, this.offset).set(values)\n this.offset += values.length\n }\n\n /**\n * Serializes a value using the specified DataView function.\n *\n * @param {(byteOffset: number, value: number, littleEndian?: boolean) => void} fn - The DataView function to use for serialization.\n * @param {number} bytesLength - The length of the bytes to serialize.\n * @param {number} value - The value to serialize.\n */\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian?: boolean) => void,\n bytesLength: number,\n value: number\n ): void {\n this.ensureBufferWillHandleSize(bytesLength)\n const dv = new DataView(this.buffer, this.offset)\n fn.apply(dv, [0, value, this.littleEndian])\n this.offset += bytesLength\n }\n\n /**\n * Serializes a string. UTF8 string is supported. Serializes the string's bytes length \"l\" first,\n * and then serializes \"l\" bytes of the string content.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const serializer = new Serializer();\n * serializer.serializeStr(\"çå∞≠¢õß∂ƒ∫\");\n * assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));\n * ```\n */\n serializeStr(value: string): this {\n const textEncoder = new TextEncoder()\n this.serializeBytes(textEncoder.encode(value))\n return this\n }\n\n /**\n * Serializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n */\n serializeBytes(value: Bytes): this {\n if (this.littleEndian) {\n this.serializeU32AsUleb128(value.length)\n } else {\n this.serializeU32AsUbeb128(value.length)\n }\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes an array of bytes with known length. Therefore length doesn't need to be\n * serialized to help deserialization. When deserializing, the number of\n * bytes to deserialize needs to be passed in.\n */\n serializeFixedBytes(value: Bytes): this {\n this.serialize(value)\n return this\n }\n\n /**\n * Serializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n */\n serializeBool(value: boolean): this {\n if (typeof value !== 'boolean') {\n throw new Error('Value needs to be a boolean')\n }\n const byteValue = value ? 1 : 0\n this.serialize(new Uint8Array([byteValue]))\n return this\n }\n\n /**\n * Serializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n */\n @checkNumberRange(0, MAX_U8_NUMBER)\n serializeU8(value: Uint8): this {\n this.serialize(new Uint8Array([value]))\n return this\n }\n\n /**\n * Serializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU16(4660);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34]));\n * ```\n */\n @checkNumberRange(0, MAX_U16_NUMBER)\n serializeU16(value: Uint16): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value)\n return this\n }\n\n /**\n * Serializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU32(305419896);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78]));\n * ```\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32(value: Uint32): this {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value)\n return this\n }\n\n /**\n * Serializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const serializer = new Serializer(true);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));\n * const serializer = new Serializer(false);\n * serializer.serializeU64(1311768467750121216);\n * assert(serializer.getBytes() === new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]));\n * ```\n */\n @checkNumberRange(BigInt(0), MAX_U64_BIG_INT)\n serializeU64(value: AnyNumber): this {\n const low = BigInt(value.toString()) & BigInt(MAX_U32_NUMBER)\n const high = BigInt(value.toString()) >> BigInt(32)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU32(Number(x))\n })\n return this\n }\n\n /**\n * Serializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U128_BIG_INT)\n serializeU128(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U64_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(64)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU64(x)\n })\n return this\n }\n\n /**\n * Serializes a uint256 number.\n *\n * layout for \"uint256\": Sixteen bytes. Binary format in little-endian representation.\n */\n @checkNumberRange(BigInt(0), MAX_U256_BIG_INT)\n serializeU256(value: AnyNumber): this {\n const low = BigInt(value.toString()) & MAX_U128_BIG_INT\n const high = BigInt(value.toString()) >> BigInt(128)\n\n const array = this.littleEndian ? [low, high] : [high, low]\n array.forEach((x) => {\n this.serializeU128(x)\n })\n return this\n }\n\n /**\n * Serializes a uint32 number with uleb128.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUleb128(val: Uint32): this {\n let value = val\n const valueArray = []\n while (value >>> 7 !== 0) {\n valueArray.push((value & 0x7f) | 0x80)\n value >>>= 7\n }\n valueArray.push(value)\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Serializes a uint32 number with unsigned Variable-Length Big-Endian Encoding.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n */\n @checkNumberRange(0, MAX_U32_NUMBER)\n serializeU32AsUbeb128(val: Uint32): this {\n let value = val\n const valueArray: Uint8[] = []\n\n valueArray.unshift(value & 0x7f)\n while (value >>> 7 !== 0) {\n value >>>= 7\n const byte = (value & 0x7f) | 0x80\n valueArray.unshift(byte)\n }\n\n this.serialize(new Uint8Array(valueArray))\n return this\n }\n\n /**\n * Returns the buffered bytes\n *\n * @returns {Bytes} The buffered bytes.\n */\n getBytes(): Bytes {\n return new Uint8Array(this.buffer).slice(0, this.offset)\n }\n}\n\n/**\n * Creates a decorator to make sure the arg value of the decorated function is within a range.\n * @param minValue The arg value of decorated function must >= minValue\n * @param maxValue The arg value of decorated function must <= maxValue\n * @param message Error message\n */\nfunction checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T, message?: string) {\n return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {\n /* eslint-disable @typescript-eslint/no-unsafe-assignment */\n const childFunction = descriptor.value as (value: AnyNumber) => any\n // eslint-disable-next-line no-param-reassign\n descriptor.value = function deco(value: AnyNumber): void {\n const valueBigInt = BigInt(value.toString())\n if (valueBigInt > BigInt(maxValue.toString()) || valueBigInt < BigInt(minValue.toString())) {\n throw new Error(message ?? 'Value is out of range')\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return childFunction.apply(this, [value])\n }\n return descriptor\n /* eslint-enable @typescript-eslint/no-unsafe-assignment */\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable no-bitwise */\nimport { MAX_U32_NUMBER } from './consts'\nimport { Bytes, Uint128, Uint16, Uint256, Uint32, Uint64, Uint8 } from './types'\n\n/**\n * Class representing a deserializer for various data types.\n */\nexport class Deserializer {\n private buffer: ArrayBuffer\n\n private offset: number\n public readonly littleEndian: boolean\n\n /**\n * Creates an instance of Deserializer.\n *\n * @param {Bytes} data - The data to deserialize.\n * @param {boolean} [littleEndian=true] - Whether to use little-endian byte order.\n */\n constructor(data: Bytes, littleEndian = true) {\n this.littleEndian = littleEndian\n // copies data to prevent outside mutation of buffer.\n this.buffer = new ArrayBuffer(data.length)\n new Uint8Array(this.buffer).set(data, 0)\n this.offset = 0\n }\n\n /**\n * Reads a specified number of bytes from the buffer.\n *\n * @param {number} length - The number of bytes to read.\n * @returns {ArrayBuffer} The read bytes.\n * @throws {Error} If the end of the buffer is reached.\n */\n private read(length: number): ArrayBuffer {\n if (this.offset + length > this.buffer.byteLength) {\n throw new Error('Reached to the end of buffer')\n }\n\n const bytes = this.buffer.slice(this.offset, this.offset + length)\n this.offset += length\n return bytes\n }\n\n /**\n * Returns the number of remaining bytes in the buffer.\n *\n * @returns {number} The number of remaining bytes.\n */\n public remaining(): number {\n return this.buffer.byteLength - this.offset\n }\n\n /**\n * Rewinds the buffer by a specified number of bytes.\n *\n * @param {number} length - The number of bytes to rewind.\n */\n public rewind(length: number): void {\n this.offset -= length\n }\n\n /**\n * Deserializes a string. UTF8 string is supported. Reads the string's bytes length \"l\" first,\n * and then reads \"l\" bytes of content. Decodes the byte array into a string.\n *\n * layout for \"string\": string_length | string_content. string_length is the bytes length of\n * the string that is uleb128/ubeb128 encoded. string_length is a u32 integer.\n *\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,\n * 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]), true);\n * assert(deserializer.deserializeStr() === \"çå∞≠¢õß∂ƒ∫\");\n * ```\n * @returns {string} The deserialized string.\n */\n deserializeStr(): string {\n const value = this.deserializeBytes()\n const textDecoder = new TextDecoder()\n return textDecoder.decode(value)\n }\n\n /**\n * Deserializes an array of bytes.\n *\n * layout for \"bytes\": bytes_length | bytes. bytes_length is the length of the bytes array that is\n * uleb128/ubeb128 encoded. bytes_length is a u32 integer.\n *\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeBytes(): Bytes {\n const len = this.littleEndian ? this.deserializeUleb128AsU32() : this.deserializeUbeb128AsU32()\n\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes an array of bytes. The number of bytes to read is already known.\n *\n * @param {number} len - The number of bytes to read.\n * @returns {Bytes} The deserialized bytes.\n */\n deserializeFixedBytes(len: number): Bytes {\n return new Uint8Array(this.read(len))\n }\n\n /**\n * Deserializes a boolean value.\n *\n * layout for \"boolean\": One byte. \"0x01\" for True and \"0x00\" for False.\n *\n * @returns {boolean} The deserialized boolean value.\n * @throws {Error} If the boolean value is invalid.\n */\n deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0]\n if (bool !== 1 && bool !== 0) {\n throw new Error('Invalid boolean value')\n }\n return bool === 1\n }\n\n /**\n * Deserializes a uint8 number.\n *\n * layout for \"uint8\": One byte. Binary format in little-endian representation.\n *\n * @returns {Uint8} The deserialized uint8 number.\n */\n deserializeU8(): Uint8 {\n return new DataView(this.read(1)).getUint8(0)\n }\n\n /**\n * Deserializes a uint16 number.\n *\n * layout for \"uint16\": Two bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]), true);\n * assert(deserializer.deserializeU16() === 4660);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34]), false);\n * assert(deserializer.deserializeU16() === 4660);\n * ```\n * @returns {Uint16} The deserialized uint16 number.\n */\n deserializeU16(): Uint16 {\n return new DataView(this.read(2)).getUint16(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint32 number.\n *\n * layout for \"uint32\": Four bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU32() === 305419896);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78]), false);\n * assert(deserializer.deserializeU32() === 305419896);\n * ```\n * @returns {Uint32} The deserialized uint32 number.\n */\n deserializeU32(): Uint32 {\n return new DataView(this.read(4)).getUint32(0, this.littleEndian)\n }\n\n /**\n * Deserializes a uint64 number.\n *\n * layout for \"uint64\": Eight bytes. Binary format in little-endian representation.\n * @example\n * ```ts\n * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]), true);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * const deserializer = new Deserializer(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD, 0xEF, 0x00]), false);\n * assert(deserializer.deserializeU64() === 1311768467750121216);\n * ```\n * @returns {Uint64} The deserialized uint64 number.\n */\n deserializeU64(): Uint64 {\n const low = this.deserializeU32()\n const high = this.deserializeU32()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((BigInt(values[1]) << BigInt(32)) | BigInt(values[0]))\n }\n\n /**\n * Deserializes a uint128 number.\n *\n * layout for \"uint128\": Sixteen bytes. Binary format in little-endian representation.\n *\n * @returns {Uint128} The deserialized uint128 number.\n */\n deserializeU128(): Uint128 {\n const low = this.deserializeU64()\n const high = this.deserializeU64()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(64)) | values[0])\n }\n\n /**\n * Deserializes a uint256 number.\n *\n * layout for \"uint256\": Thirty-two bytes. Binary format in little-endian representation.\n *\n * @returns {Uint256} The deserialized uint256 number.\n */\n deserializeU256(): Uint256 {\n const low = this.deserializeU128()\n const high = this.deserializeU128()\n\n const values = this.littleEndian ? [low, high] : [high, low]\n return BigInt((values[1] << BigInt(128)) | values[0])\n }\n\n /**\n * Deserializes a uleb128 encoded uint32 number.\n *\n * use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized uleb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUleb128AsU32(): Uint32 {\n let value = BigInt(0)\n let shift = 0\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f) << BigInt(shift)\n\n if ((byte & 0x80) === 0) {\n break\n }\n shift += 7\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing uleb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n\n /**\n * Deserializes a unsigned Variable-Length Big-Endian Encoding encoded uint32 number.\n *\n * use ubeb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values\n *\n * @returns {Uint32} The deserialized ubeb128 encoded uint32 number.\n * @throws {Error} If there is an overflow while parsing the value.\n */\n deserializeUbeb128AsU32(): Uint32 {\n let value = BigInt(0)\n\n while (value < MAX_U32_NUMBER) {\n const byte = this.deserializeU8()\n value |= BigInt(byte & 0x7f)\n\n if ((byte & 0x80) === 0) {\n break\n }\n value = value << BigInt(7)\n }\n\n if (value > MAX_U32_NUMBER) {\n throw new Error('Overflow while parsing ubeb128-encoded uint32 value')\n }\n\n return Number(value)\n }\n}\n","// Copyright © Aptos Foundation\n// Copyright © LayerZero Labs\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Deserializer } from './deserializer'\nimport { Serializer } from './serializer'\nimport { AnyNumber, Bytes, Seq, Uint16, Uint32, Uint8 } from './types'\n\n/**\n * Interface representing a serializable object.\n */\ninterface Serializable {\n /**\n * Serializes the object using the provided serializer.\n *\n * @param {Serializer} serializer - The serializer to use.\n */\n serialize(serializer: Serializer): void\n}\n\n/**\n * Interface representing a deserializable object.\n */\ninterface Deserializable<T> {\n /**\n * Deserializes the object using the provided deserializer.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @returns {T} The deserialized object.\n */\n deserialize(deserializer: Deserializer): T\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\ninterface ISerializer {\n [key: string]: (item: unknown) => void\n}\n\n/**\n * Serializes a vector of values that are \"Serializable\".\n *\n * @param {Seq<T>} value - The vector of values to serialize.\n * @param {Serializer} serializer - The serializer to use.\n */\nexport function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void {\n serializer.serializeU32AsUleb128(value.length)\n value.forEach((item: T) => {\n item.serialize(serializer)\n })\n}\n\n/**\n * Serializes a vector with a specified item serialization function.\n * Very dynamic function and bypasses static typechecking.\n *\n * @param {unknown[]} value - The vector of values to serialize.\n * @param {string} func - The name of the serialization function to use.\n * @returns {Bytes} The serialized bytes.\n * @throws {Error} If the specified function does not exist on the serializer.\n */\nexport function serializeVectorWithFunc(value: unknown[], func: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32AsUleb128(value.length)\n\n const f = (serializer as unknown as ISerializer)[func]\n if (typeof f !== 'function') {\n throw new Error(`The function '${func}' does not exist on the serializer.`)\n }\n\n value.forEach((item) => {\n f.call(serializer, item)\n })\n return serializer.getBytes()\n}\n\n/**\n * Deserializes a vector of values.\n *\n * @param {Deserializer} deserializer - The deserializer to use.\n * @param {Deserializable<T>} cls - The class to use for deserialization.\n * @returns {T[]} The deserialized vector of values.\n */\nexport function deserializeVector<T>(deserializer: Deserializer, cls: Deserializable<T>): any[] {\n const length = deserializer.deserializeUleb128AsU32()\n const list: T[] = []\n for (let i = 0; i < length; i += 1) {\n list.push(cls.deserialize(deserializer))\n }\n return list\n}\n\n/**\n * Serializes a value to bytes using BCS (Binary Canonical Serialization).\n *\n * @param {T} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsToBytes<T extends Serializable>(value: T): Bytes {\n const serializer = new Serializer()\n value.serialize(serializer)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint64 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeUint64(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU64(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint8 value to bytes using BCS.\n *\n * @param {Uint8} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU8(value: Uint8): Bytes {\n const serializer = new Serializer()\n serializer.serializeU8(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint16 value to bytes using BCS.\n *\n * @param {Uint16} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU16(value: Uint16): Bytes {\n const serializer = new Serializer()\n serializer.serializeU16(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint32 value to bytes using BCS.\n *\n * @param {Uint32} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU32(value: Uint32): Bytes {\n const serializer = new Serializer()\n serializer.serializeU32(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint128 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU128(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU128(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a uint256 value to bytes using BCS.\n *\n * @param {AnyNumber} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeU256(value: AnyNumber): Bytes {\n const serializer = new Serializer()\n serializer.serializeU256(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a boolean value to bytes using BCS.\n *\n * @param {boolean} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBool(value: boolean): Bytes {\n const serializer = new Serializer()\n serializer.serializeBool(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a string value to bytes using BCS.\n *\n * @param {string} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeStr(value: string): Bytes {\n const serializer = new Serializer()\n serializer.serializeStr(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeBytes(value)\n return serializer.getBytes()\n}\n\n/**\n * Serializes a fixed-length byte array to bytes using BCS.\n *\n * @param {Bytes} value - The value to serialize.\n * @returns {Bytes} The serialized bytes.\n */\nexport function bcsSerializeFixedBytes(value: Bytes): Bytes {\n const serializer = new Serializer()\n serializer.serializeFixedBytes(value)\n return serializer.getBytes()\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/lz-serdes",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.17",
|
|
4
4
|
"description": "LayerZero Core Library",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"exports": {
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@jest/globals": "^29.7.0",
|
|
28
|
-
"@layerzerolabs/tsup-config-next": "^3.0.
|
|
29
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
28
|
+
"@layerzerolabs/tsup-config-next": "^3.0.17",
|
|
29
|
+
"@layerzerolabs/typescript-config-next": "^3.0.17",
|
|
30
30
|
"@types/jest": "^29.5.10",
|
|
31
31
|
"jest": "^29.7.0",
|
|
32
32
|
"jest-extended": "^4.0.2",
|
|
33
33
|
"rimraf": "^5.0.5",
|
|
34
34
|
"ts-jest": "^29.1.1",
|
|
35
|
-
"tsup": "^8.
|
|
35
|
+
"tsup": "^8.3.5",
|
|
36
36
|
"typescript": "~5.2.2"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|