@roochnetwork/sdk
Version:
1 lines • 123 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts","../src/constants/address.ts","../src/constants/gas.ts","../src/constants/chain.ts","../src/types/hex.ts","../src/types/bcs/index.ts","../src/utils/b64.ts","../src/generated/runtime/serde/binarySerializer.ts","../src/generated/runtime/bcs/bcsSerializer.ts","../src/generated/runtime/serde/binaryDeserializer.ts","../src/generated/runtime/bcs/bcsDeserializer.ts","../src/generated/runtime/rooch_types/mod.ts","../src/types/bcs/move_string.ts","../src/types/bcs/move_ascii_string.ts","../src/types/bcs/u256.ts","../src/utils/mixin.ts","../src/utils/hex.ts","../src/utils/encode.ts","../src/utils/tx.ts","../src/utils/bytes.ts","../src/utils/crypto/signature.ts","../src/utils/crypto/mnemonics.ts","../src/utils/crypto/publickey.ts","../src/utils/crypto/keypair.ts","../src/utils/keypairs/ed25519/keypair.ts","../src/utils/keypairs/ed25519/publickey.ts","../src/utils/keypairs/ed25519/ed25519-hd-key.ts","../src/provider/json-rpc-provider.ts","../src/generated/client/client.ts","../src/auth/private-key-auth.ts","../src/account/account.ts"],"sourcesContent":["// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nexport * from './constants'\nexport * from './types'\nexport * from './utils'\nexport * from './utils/crypto'\nexport * from './utils/keypairs'\nexport * from './provider'\nexport * from './auth'\nexport * from './account'\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nexport const ROOCH_ADDRESS_LENGTH = 64\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nexport const DEFAULT_MAX_GAS_AMOUNT = 1000000\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nconst LocalNetworkURL = 'http://127.0.0.1:50051'\nconst DevNetworkURL = 'https://dev-seed.rooch.network'\nconst TestNetworkURL = 'https://test-seed.rooch.network'\n\nconst LOCAL_CHAIN_ID = 0x134afd8\nconst DEV_CHAIN_ID = 0x134afd7\nconst TEST_CHAIN_ID = 0x134afd6\n// const MAIN_CHIAN_ID = 0x134afd5\n\nexport interface ChainInfo {\n chainId: string\n blockExplorerUrls?: string[]\n chainName?: string\n iconUrls?: string[]\n nativeCurrency?: {\n name: string\n symbol: string\n decimals: number\n }\n rpcUrls?: string[]\n}\n\ninterface ConnectionOptions {\n url: string\n websocket?: string\n}\n\nexport class Chain {\n id: number\n name: string\n options: ConnectionOptions\n\n constructor(id: number, name: string, options: ConnectionOptions) {\n this.id = id\n this.name = name\n this.options = options\n }\n\n get url() {\n return this.options.url\n }\n\n get websocket() {\n return this.options.websocket || this.options.url\n }\n\n get info(): ChainInfo {\n return {\n chainId: `0x${this.id.toString(16)}`,\n chainName: this.name,\n iconUrls: [\n 'https://github.com/rooch-network/rooch/blob/main/docs/website/public/logo/rooch_black_text.png',\n ],\n nativeCurrency: {\n name: 'ROH',\n symbol: 'ROH',\n decimals: 18,\n },\n rpcUrls: [this.options.url],\n }\n }\n}\n\nexport const LocalChain = new Chain(LOCAL_CHAIN_ID, 'local', {\n url: LocalNetworkURL,\n})\n\nexport const DevChain = new Chain(DEV_CHAIN_ID, 'dev', {\n url: DevNetworkURL,\n})\n\nexport const TestChain = new Chain(TEST_CHAIN_ID, 'test', {\n url: TestNetworkURL,\n})\n\nexport const AllChain = [LocalChain, DevChain, TestChain]\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils'\n\n/**\n * TODO:\n *\n * All bytes (Vec<u8>) data is represented as hex-encoded string prefixed with `0x` and fulfilled with\n * two hex digits per byte.\n *\n * Unlike the `Address` type, HexEncodedBytes will not trim any zeros.\n *\n */\nexport type HexEncodedBytes = string\n\nexport type MaybeHexString = HexString | string\n\n/**\n * A util class for working with hex strings.\n * Hex strings are strings that are prefixed with `0x`\n */\nexport class HexString {\n /// We want to make sure this hexString has the `0x` hex prefix\n private readonly hexString: string\n\n /**\n * Creates new hex string from Buffer\n * @param buffer A buffer to convert\n * @returns New HexString\n */\n static fromBuffer(buffer: Uint8Array): HexString {\n return HexString.fromUint8Array(buffer)\n }\n\n /**\n * Creates new hex string from Uint8Array\n * @param arr Uint8Array to convert\n * @returns New HexString\n */\n static fromUint8Array(arr: Uint8Array): HexString {\n return new HexString(bytesToHex(arr))\n }\n\n /**\n * Ensures `hexString` is instance of `HexString` class\n * @param hexString String to check\n * @returns New HexString if `hexString` is regular string or `hexString` if it is HexString instance\n * @example\n * ```\n * const regularString = \"string\";\n * const hexString = new HexString(\"string\"); // \"0xstring\"\n * HexString.ensure(regularString); // \"0xstring\"\n * HexString.ensure(hexString); // \"0xstring\"\n * ```\n */\n static ensure(hexString: MaybeHexString): HexString {\n if (typeof hexString === 'string') {\n return new HexString(hexString)\n }\n return hexString\n }\n\n /**\n * Creates new HexString instance from regular string. If specified string already starts with \"0x\" prefix,\n * it will not add another one\n * @param hexString String to convert\n * @example\n * ```\n * const string = \"string\";\n * new HexString(string); // \"0xstring\"\n * ```\n */\n constructor(hexString: string | HexEncodedBytes) {\n if (hexString.startsWith('0x')) {\n this.hexString = hexString\n } else {\n this.hexString = `0x${hexString}`\n }\n }\n\n /**\n * Getter for inner hexString\n * @returns Inner hex string\n */\n hex(): string {\n return this.hexString\n }\n\n /**\n * Getter for inner hexString without prefix\n * @returns Inner hex string without prefix\n * @example\n * ```\n * const hexString = new HexString(\"string\"); // \"0xstring\"\n * hexString.noPrefix(); // \"string\"\n * ```\n */\n noPrefix(): string {\n return this.hexString.slice(2)\n }\n\n /**\n * Overrides default `toString` method\n * @returns Inner hex string\n */\n toString(): string {\n return this.hex()\n }\n\n /**\n * Trimmes extra zeroes in the begining of a string\n * @returns Inner hexString without leading zeroes\n * @example\n * ```\n * new HexString(\"0x000000string\").toShortString(); // result = \"0xstring\"\n * ```\n */\n toShortString(): string {\n const trimmed = this.hexString.replace(/^0x0*/, '')\n return `0x${trimmed}`\n }\n\n /**\n * Converts hex string to a Uint8Array\n * @returns Uint8Array from inner hexString without prefix\n */\n toUint8Array(): Uint8Array {\n return Uint8Array.from(hexToBytes(this.noPrefix()))\n }\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nexport * from '../../utils/b64'\nexport * from '../../generated/runtime/bcs/mod'\nexport * from '../../generated/runtime/serde/mod'\nexport * from '../../generated/runtime/rooch_types/mod'\nexport * from './move_string'\nexport * from './move_ascii_string'\nexport * from './u256'\n","// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable */\n\n/*\n|* Base64 / binary data / UTF-8 strings utilities\n|* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding\n\\*\n\n/* Array of bytes to Base64 string decoding */\n\nfunction b64ToUint6(nChr: number) {\n return nChr > 64 && nChr < 91\n ? nChr - 65\n : nChr > 96 && nChr < 123\n ? nChr - 71\n : nChr > 47 && nChr < 58\n ? nChr + 4\n : nChr === 43\n ? 62\n : nChr === 47\n ? 63\n : 0\n}\n\nexport function fromB64(sBase64: string, nBlocksSize?: number): Uint8Array {\n var sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ''),\n nInLen = sB64Enc.length,\n nOutLen = nBlocksSize\n ? Math.ceil(((nInLen * 3 + 1) >> 2) / nBlocksSize) * nBlocksSize\n : (nInLen * 3 + 1) >> 2,\n taBytes = new Uint8Array(nOutLen)\n\n for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {\n nMod4 = nInIdx & 3\n nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (6 * (3 - nMod4))\n if (nMod4 === 3 || nInLen - nInIdx === 1) {\n for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {\n taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255\n }\n nUint24 = 0\n }\n }\n\n return taBytes\n}\n\n/* Base64 string to array encoding */\n\nfunction uint6ToB64(nUint6: number) {\n return nUint6 < 26\n ? nUint6 + 65\n : nUint6 < 52\n ? nUint6 + 71\n : nUint6 < 62\n ? nUint6 - 4\n : nUint6 === 62\n ? 43\n : nUint6 === 63\n ? 47\n : 65\n}\n\nexport function toB64(aBytes: Uint8Array): string {\n var nMod3 = 2,\n sB64Enc = ''\n\n for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {\n nMod3 = nIdx % 3\n nUint24 |= aBytes[nIdx] << ((16 >>> nMod3) & 24)\n if (nMod3 === 2 || aBytes.length - nIdx === 1) {\n sB64Enc += String.fromCodePoint(\n uint6ToB64((nUint24 >>> 18) & 63),\n uint6ToB64((nUint24 >>> 12) & 63),\n uint6ToB64((nUint24 >>> 6) & 63),\n uint6ToB64(nUint24 & 63),\n )\n nUint24 = 0\n }\n }\n\n return (\n sB64Enc.slice(0, sB64Enc.length - 2 + nMod3) + (nMod3 === 2 ? '' : nMod3 === 1 ? '=' : '==')\n )\n}\n","/**\n * Copyright (c) Facebook, Inc. and its affiliates\n * SPDX-License-Identifier: MIT OR Apache-2.0\n */\n\nimport { Serializer } from \"./serializer.ts\";\nimport * as util from \"@kayahr/text-encoding\";\n\nexport abstract class BinarySerializer implements Serializer {\n private static readonly BIG_32: bigint = BigInt(32);\n private static readonly BIG_64: bigint = BigInt(64);\n\n private static readonly BIG_32Fs: bigint = BigInt(\"4294967295\");\n private static readonly BIG_64Fs: bigint = BigInt(\"18446744073709551615\");\n\n private static readonly textEncoder = typeof window === \"undefined\"\n ? new util.TextEncoder()\n : new TextEncoder();\n\n private buffer: ArrayBuffer;\n private offset: number;\n\n constructor() {\n this.buffer = new ArrayBuffer(64);\n this.offset = 0;\n }\n\n private ensureBufferWillHandleSize(bytes: number) {\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 protected serialize(values: Uint8Array) {\n this.ensureBufferWillHandleSize(values.length);\n new Uint8Array(this.buffer, this.offset).set(values);\n this.offset += values.length;\n }\n\n abstract serializeLen(value: number): void;\n\n abstract serializeVariantIndex(value: number): void;\n\n abstract sortMapEntries(offsets: number[]): void;\n\n public serializeStr(value: string): void {\n this.serializeBytes(BinarySerializer.textEncoder.encode(value));\n }\n\n public serializeBytes(value: Uint8Array): void {\n this.serializeLen(value.length);\n this.serialize(value);\n }\n\n public serializeBool(value: boolean): void {\n const byteValue = value ? 1 : 0;\n this.serialize(new Uint8Array([byteValue]));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/explicit-module-boundary-types\n public serializeUnit(_value: null): void {\n return;\n }\n\n private serializeWithFunction(\n fn: (byteOffset: number, value: number, littleEndian: boolean) => void,\n bytesLength: number,\n value: number,\n ) {\n this.ensureBufferWillHandleSize(bytesLength);\n const dv = new DataView(this.buffer, this.offset);\n fn.apply(dv, [0, value, true]);\n this.offset += bytesLength;\n }\n\n public serializeU8(value: number): void {\n this.serialize(new Uint8Array([value]));\n }\n\n public serializeU16(value: number): void {\n this.serializeWithFunction(DataView.prototype.setUint16, 2, value);\n }\n\n public serializeU32(value: number): void {\n this.serializeWithFunction(DataView.prototype.setUint32, 4, value);\n }\n\n public serializeU64(value: BigInt | number): void {\n const low = BigInt(value.toString()) & BinarySerializer.BIG_32Fs;\n const high = BigInt(value.toString()) >> BinarySerializer.BIG_32;\n\n // write little endian number\n this.serializeU32(Number(low));\n this.serializeU32(Number(high));\n }\n\n public serializeU128(value: BigInt | number): void {\n const low = BigInt(value.toString()) & BinarySerializer.BIG_64Fs;\n const high = BigInt(value.toString()) >> BinarySerializer.BIG_64;\n\n // write little endian number\n this.serializeU64(low);\n this.serializeU64(high);\n }\n\n public serializeI8(value: number): void {\n const bytes = 1;\n this.ensureBufferWillHandleSize(bytes);\n new DataView(this.buffer, this.offset).setInt8(0, value);\n this.offset += bytes;\n }\n\n public serializeI16(value: number): void {\n const bytes = 2;\n this.ensureBufferWillHandleSize(bytes);\n new DataView(this.buffer, this.offset).setInt16(0, value, true);\n this.offset += bytes;\n }\n\n public serializeI32(value: number): void {\n const bytes = 4;\n this.ensureBufferWillHandleSize(bytes);\n new DataView(this.buffer, this.offset).setInt32(0, value, true);\n this.offset += bytes;\n }\n\n public serializeI64(value: bigint | number): void {\n const low = BigInt(value) & BinarySerializer.BIG_32Fs;\n const high = BigInt(value) >> BinarySerializer.BIG_32;\n\n // write little endian number\n this.serializeI32(Number(low));\n this.serializeI32(Number(high));\n }\n\n public serializeI128(value: bigint | number): void {\n const low = BigInt(value) & BinarySerializer.BIG_64Fs;\n const high = BigInt(value) >> BinarySerializer.BIG_64;\n\n // write little endian number\n this.serializeI64(low);\n this.serializeI64(high);\n }\n\n public serializeOptionTag(value: boolean): void {\n this.serializeBool(value);\n }\n\n public getBufferOffset(): number {\n return this.offset;\n }\n\n public getBytes(): Uint8Array {\n return new Uint8Array(this.buffer).slice(0, this.offset);\n }\n\n public serializeChar(_value: string): void {\n throw new Error(\"Method serializeChar not implemented.\");\n }\n\n public serializeF32(value: number): void {\n const bytes = 4;\n this.ensureBufferWillHandleSize(bytes);\n new DataView(this.buffer, this.offset).setFloat32(0, value, true);\n this.offset += bytes;\n }\n\n public serializeF64(value: number): void {\n const bytes = 8;\n this.ensureBufferWillHandleSize(bytes);\n new DataView(this.buffer, this.offset).setFloat64(0, value, true);\n this.offset += bytes;\n }\n}\n","/**\n * Copyright (c) Facebook, Inc. and its affiliates\n * SPDX-License-Identifier: MIT OR Apache-2.0\n */\n\nimport { BinarySerializer } from \"../serde/binarySerializer.ts\";\n\nexport class BcsSerializer extends BinarySerializer {\n public serializeU32AsUleb128(value: number): void {\n const valueArray = [];\n while (value >>> 7 != 0) {\n valueArray.push((value & 0x7f) | 0x80);\n value = value >>> 7;\n }\n valueArray.push(value);\n this.serialize(new Uint8Array(valueArray));\n }\n\n serializeLen(value: number): void {\n this.serializeU32AsUleb128(value);\n }\n\n public serializeVariantIndex(value: number): void {\n this.serializeU32AsUleb128(value);\n }\n\n public sortMapEntries(_offsets: number[]) {\n // TODO(#119)\n }\n}\n","/**\n * Copyright (c) Facebook, Inc. and its affiliates\n * SPDX-License-Identifier: MIT OR Apache-2.0\n */\n\nimport { Deserializer } from \"./deserializer.ts\";\nimport * as util from \"@kayahr/text-encoding\";\n\nexport abstract class BinaryDeserializer implements Deserializer {\n private static readonly BIG_32: bigint = BigInt(32);\n private static readonly BIG_64: bigint = BigInt(64);\n private static readonly textDecoder = typeof window === \"undefined\"\n ? new util.TextDecoder()\n : new TextDecoder();\n public buffer: ArrayBuffer;\n public offset: number;\n\n constructor(data: Uint8Array) {\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 private read(length: number): ArrayBuffer {\n const bytes = this.buffer.slice(this.offset, this.offset + length);\n this.offset += length;\n return bytes;\n }\n\n abstract deserializeLen(): number;\n\n abstract deserializeVariantIndex(): number;\n\n abstract checkThatKeySlicesAreIncreasing(\n key1: [number, number],\n key2: [number, number],\n ): void;\n\n public deserializeStr(): string {\n const value = this.deserializeBytes();\n return BinaryDeserializer.textDecoder.decode(value);\n }\n\n public deserializeBytes(): Uint8Array {\n const len = this.deserializeLen();\n if (len < 0) {\n throw new Error(\"Length of a bytes array can't be negative\");\n }\n return new Uint8Array(this.read(len));\n }\n\n public deserializeBool(): boolean {\n const bool = new Uint8Array(this.read(1))[0];\n return bool == 1;\n }\n\n public deserializeUnit(): null {\n return null;\n }\n\n public deserializeU8(): number {\n return new DataView(this.read(1)).getUint8(0);\n }\n\n public deserializeU16(): number {\n return new DataView(this.read(2)).getUint16(0, true);\n }\n\n public deserializeU32(): number {\n return new DataView(this.read(4)).getUint32(0, true);\n }\n\n public deserializeU64(): bigint {\n const low = this.deserializeU32();\n const high = this.deserializeU32();\n\n // combine the two 32-bit values and return (little endian)\n return BigInt(\n (BigInt(high.toString()) << BinaryDeserializer.BIG_32) |\n BigInt(low.toString()),\n );\n }\n\n public deserializeU128(): bigint {\n const low = this.deserializeU64();\n const high = this.deserializeU64();\n\n // combine the two 64-bit values and return (little endian)\n return BigInt(\n (BigInt(high.toString()) << BinaryDeserializer.BIG_64) |\n BigInt(low.toString()),\n );\n }\n\n public deserializeI8(): number {\n return new DataView(this.read(1)).getInt8(0);\n }\n\n public deserializeI16(): number {\n return new DataView(this.read(2)).getInt16(0, true);\n }\n\n public deserializeI32(): number {\n return new DataView(this.read(4)).getInt32(0, true);\n }\n\n public deserializeI64(): bigint {\n const low = this.deserializeI32();\n const high = this.deserializeI32();\n\n // combine the two 32-bit values and return (little endian)\n return (BigInt(high.toString()) << BinaryDeserializer.BIG_32) |\n BigInt(low.toString());\n }\n\n public deserializeI128(): bigint {\n const low = this.deserializeI64();\n const high = this.deserializeI64();\n\n // combine the two 64-bit values and return (little endian)\n return (BigInt(high.toString()) << BinaryDeserializer.BIG_64) |\n BigInt(low.toString());\n }\n\n public deserializeOptionTag(): boolean {\n return this.deserializeBool();\n }\n\n public getBufferOffset(): number {\n return this.offset;\n }\n\n public deserializeChar(): string {\n throw new Error(\"Method deserializeChar not implemented.\");\n }\n\n public deserializeF32(): number {\n return new DataView(this.read(4)).getFloat32(0, true);\n }\n\n public deserializeF64(): number {\n return new DataView(this.read(8)).getFloat64(0, true);\n }\n}\n","/**\n * Copyright (c) Facebook, Inc. and its affiliates\n * SPDX-License-Identifier: MIT OR Apache-2.0\n */\n\nimport { BinaryDeserializer } from \"../serde/binaryDeserializer.ts\";\n\nexport class BcsDeserializer extends BinaryDeserializer {\n private static readonly MAX_UINT_32 = 2 ** 32 - 1;\n\n public deserializeUleb128AsU32(): number {\n let value = 0;\n for (let shift = 0; shift < 32; shift += 7) {\n const x = this.deserializeU8();\n const digit = x & 0x7f;\n value = value | (digit << shift);\n if (value < 0 || value > BcsDeserializer.MAX_UINT_32) {\n throw new Error(\"Overflow while parsing uleb128-encoded uint32 value\");\n }\n if (digit == x) {\n if (shift > 0 && digit == 0) {\n throw new Error(\"Invalid uleb128 number (unexpected zero digit)\");\n }\n return value;\n }\n }\n throw new Error(\"Overflow while parsing uleb128-encoded uint32 value\");\n }\n\n deserializeLen(): number {\n return this.deserializeUleb128AsU32();\n }\n\n public deserializeVariantIndex(): number {\n return this.deserializeUleb128AsU32();\n }\n\n public checkThatKeySlicesAreIncreasing(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _key1: [number, number],\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _key2: [number, number],\n ): void {\n // TODO(#119)\n return;\n }\n}\n","\nimport { Serializer, Deserializer } from '../serde/mod.ts';\nimport { BcsSerializer, BcsDeserializer } from '../bcs/mod.ts';\nimport { Optional, Seq, Tuple, ListTuple, unit, bool, int8, int16, int32, int64, int128, uint8, uint16, uint32, uint64, uint128, float32, float64, char, str, bytes } from '../serde/mod.ts';\n\nexport class AccountAddress {\n\nconstructor (public value: ListTuple<[uint8]>) {\n}\n\npublic serialize(serializer: Serializer): void {\n Helpers.serializeArray32U8Array(this.value, serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): AccountAddress {\n const value = Helpers.deserializeArray32U8Array(deserializer);\n return new AccountAddress(value);\n}\n\n}\nexport class Authenticator {\n\nconstructor (public auth_validator_id: uint64, public payload: Seq<uint8>) {\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeU64(this.auth_validator_id);\n Helpers.serializeVectorU8(this.payload, serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): Authenticator {\n const auth_validator_id = deserializer.deserializeU64();\n const payload = Helpers.deserializeVectorU8(deserializer);\n return new Authenticator(auth_validator_id,payload);\n}\n\n}\nexport class FunctionCall {\n\nconstructor (public function_id: FunctionId, public ty_args: Seq<TypeTag>, public args: Seq<Seq<uint8>>) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.function_id.serialize(serializer);\n Helpers.serializeVectorTypeTag(this.ty_args, serializer);\n Helpers.serializeVectorVectorU8(this.args, serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): FunctionCall {\n const function_id = FunctionId.deserialize(deserializer);\n const ty_args = Helpers.deserializeVectorTypeTag(deserializer);\n const args = Helpers.deserializeVectorVectorU8(deserializer);\n return new FunctionCall(function_id,ty_args,args);\n}\n\n}\nexport class FunctionId {\n\nconstructor (public module_id: ModuleId, public function_name: Identifier) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.module_id.serialize(serializer);\n this.function_name.serialize(serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): FunctionId {\n const module_id = ModuleId.deserialize(deserializer);\n const function_name = Identifier.deserialize(deserializer);\n return new FunctionId(module_id,function_name);\n}\n\n}\nexport class Identifier {\n\nconstructor (public value: str) {\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeStr(this.value);\n}\n\nstatic deserialize(deserializer: Deserializer): Identifier {\n const value = deserializer.deserializeStr();\n return new Identifier(value);\n}\n\n}\nexport class ModuleId {\n\nconstructor (public address: AccountAddress, public name: Identifier) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.address.serialize(serializer);\n this.name.serialize(serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): ModuleId {\n const address = AccountAddress.deserialize(deserializer);\n const name = Identifier.deserialize(deserializer);\n return new ModuleId(address,name);\n}\n\n}\nexport abstract class MoveAction {\nabstract serialize(serializer: Serializer): void;\n\nstatic deserialize(deserializer: Deserializer): MoveAction {\n const index = deserializer.deserializeVariantIndex();\n switch (index) {\n case 0: return MoveActionVariantScript.load(deserializer);\n case 1: return MoveActionVariantFunction.load(deserializer);\n case 2: return MoveActionVariantModuleBundle.load(deserializer);\n default: throw new Error(\"Unknown variant index for MoveAction: \" + index);\n }\n}\n}\n\n\nexport class MoveActionVariantScript extends MoveAction {\n\nconstructor (public value: ScriptCall) {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(0);\n this.value.serialize(serializer);\n}\n\nstatic load(deserializer: Deserializer): MoveActionVariantScript {\n const value = ScriptCall.deserialize(deserializer);\n return new MoveActionVariantScript(value);\n}\n\n}\n\nexport class MoveActionVariantFunction extends MoveAction {\n\nconstructor (public value: FunctionCall) {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(1);\n this.value.serialize(serializer);\n}\n\nstatic load(deserializer: Deserializer): MoveActionVariantFunction {\n const value = FunctionCall.deserialize(deserializer);\n return new MoveActionVariantFunction(value);\n}\n\n}\n\nexport class MoveActionVariantModuleBundle extends MoveAction {\n\nconstructor (public value: Seq<Seq<uint8>>) {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(2);\n Helpers.serializeVectorVectorU8(this.value, serializer);\n}\n\nstatic load(deserializer: Deserializer): MoveActionVariantModuleBundle {\n const value = Helpers.deserializeVectorVectorU8(deserializer);\n return new MoveActionVariantModuleBundle(value);\n}\n\n}\nexport class RoochTransaction {\n\nconstructor (public data: RoochTransactionData, public authenticator: Authenticator) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.data.serialize(serializer);\n this.authenticator.serialize(serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): RoochTransaction {\n const data = RoochTransactionData.deserialize(deserializer);\n const authenticator = Authenticator.deserialize(deserializer);\n return new RoochTransaction(data,authenticator);\n}\n\n}\nexport class RoochTransactionData {\n\nconstructor (public sender: AccountAddress, public sequence_number: uint64, public chain_id: uint64, public max_gas_amount: uint64, public action: MoveAction) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.sender.serialize(serializer);\n serializer.serializeU64(this.sequence_number);\n serializer.serializeU64(this.chain_id);\n serializer.serializeU64(this.max_gas_amount);\n this.action.serialize(serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): RoochTransactionData {\n const sender = AccountAddress.deserialize(deserializer);\n const sequence_number = deserializer.deserializeU64();\n const chain_id = deserializer.deserializeU64();\n const max_gas_amount = deserializer.deserializeU64();\n const action = MoveAction.deserialize(deserializer);\n return new RoochTransactionData(sender,sequence_number,chain_id,max_gas_amount,action);\n}\n\n}\nexport class ScriptCall {\n\nconstructor (public code: bytes, public ty_args: Seq<TypeTag>, public args: Seq<Seq<uint8>>) {\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeBytes(this.code);\n Helpers.serializeVectorTypeTag(this.ty_args, serializer);\n Helpers.serializeVectorVectorU8(this.args, serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): ScriptCall {\n const code = deserializer.deserializeBytes();\n const ty_args = Helpers.deserializeVectorTypeTag(deserializer);\n const args = Helpers.deserializeVectorVectorU8(deserializer);\n return new ScriptCall(code,ty_args,args);\n}\n\n}\nexport class StructTag {\n\nconstructor (public address: AccountAddress, public module: Identifier, public name: Identifier, public type_args: Seq<TypeTag>) {\n}\n\npublic serialize(serializer: Serializer): void {\n this.address.serialize(serializer);\n this.module.serialize(serializer);\n this.name.serialize(serializer);\n Helpers.serializeVectorTypeTag(this.type_args, serializer);\n}\n\nstatic deserialize(deserializer: Deserializer): StructTag {\n const address = AccountAddress.deserialize(deserializer);\n const module = Identifier.deserialize(deserializer);\n const name = Identifier.deserialize(deserializer);\n const type_args = Helpers.deserializeVectorTypeTag(deserializer);\n return new StructTag(address,module,name,type_args);\n}\n\n}\nexport abstract class TypeTag {\nabstract serialize(serializer: Serializer): void;\n\nstatic deserialize(deserializer: Deserializer): TypeTag {\n const index = deserializer.deserializeVariantIndex();\n switch (index) {\n case 0: return TypeTagVariantbool.load(deserializer);\n case 1: return TypeTagVariantu8.load(deserializer);\n case 2: return TypeTagVariantu64.load(deserializer);\n case 3: return TypeTagVariantu128.load(deserializer);\n case 4: return TypeTagVariantaddress.load(deserializer);\n case 5: return TypeTagVariantsigner.load(deserializer);\n case 6: return TypeTagVariantvector.load(deserializer);\n case 7: return TypeTagVariantstruct.load(deserializer);\n case 8: return TypeTagVariantu16.load(deserializer);\n case 9: return TypeTagVariantu32.load(deserializer);\n case 10: return TypeTagVariantu256.load(deserializer);\n default: throw new Error(\"Unknown variant index for TypeTag: \" + index);\n }\n}\n}\n\n\nexport class TypeTagVariantbool extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(0);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantbool {\n return new TypeTagVariantbool();\n}\n\n}\n\nexport class TypeTagVariantu8 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(1);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu8 {\n return new TypeTagVariantu8();\n}\n\n}\n\nexport class TypeTagVariantu64 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(2);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu64 {\n return new TypeTagVariantu64();\n}\n\n}\n\nexport class TypeTagVariantu128 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(3);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu128 {\n return new TypeTagVariantu128();\n}\n\n}\n\nexport class TypeTagVariantaddress extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(4);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantaddress {\n return new TypeTagVariantaddress();\n}\n\n}\n\nexport class TypeTagVariantsigner extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(5);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantsigner {\n return new TypeTagVariantsigner();\n}\n\n}\n\nexport class TypeTagVariantvector extends TypeTag {\n\nconstructor (public value: TypeTag) {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(6);\n this.value.serialize(serializer);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantvector {\n const value = TypeTag.deserialize(deserializer);\n return new TypeTagVariantvector(value);\n}\n\n}\n\nexport class TypeTagVariantstruct extends TypeTag {\n\nconstructor (public value: StructTag) {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(7);\n this.value.serialize(serializer);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantstruct {\n const value = StructTag.deserialize(deserializer);\n return new TypeTagVariantstruct(value);\n}\n\n}\n\nexport class TypeTagVariantu16 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(8);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu16 {\n return new TypeTagVariantu16();\n}\n\n}\n\nexport class TypeTagVariantu32 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(9);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu32 {\n return new TypeTagVariantu32();\n}\n\n}\n\nexport class TypeTagVariantu256 extends TypeTag {\nconstructor () {\n super();\n}\n\npublic serialize(serializer: Serializer): void {\n serializer.serializeVariantIndex(10);\n}\n\nstatic load(deserializer: Deserializer): TypeTagVariantu256 {\n return new TypeTagVariantu256();\n}\n\n}\nexport class Helpers {\n static serializeArray32U8Array(value: ListTuple<[uint8]>, serializer: Serializer): void {\n value.forEach((item) =>{\n serializer.serializeU8(item[0]);\n });\n }\n\n static deserializeArray32U8Array(deserializer: Deserializer): ListTuple<[uint8]> {\n const list: ListTuple<[uint8]> = [];\n for (let i = 0; i < 32; i++) {\n list.push([deserializer.deserializeU8()]);\n }\n return list;\n }\n\n static serializeVectorTypeTag(value: Seq<TypeTag>, serializer: Serializer): void {\n serializer.serializeLen(value.length);\n value.forEach((item: TypeTag) => {\n item.serialize(serializer);\n });\n }\n\n static deserializeVectorTypeTag(deserializer: Deserializer): Seq<TypeTag> {\n const length = deserializer.deserializeLen();\n const list: Seq<TypeTag> = [];\n for (let i = 0; i < length; i++) {\n list.push(TypeTag.deserialize(deserializer));\n }\n return list;\n }\n\n static serializeVectorU8(value: Seq<uint8>, serializer: Serializer): void {\n serializer.serializeLen(value.length);\n value.forEach((item: uint8) => {\n serializer.serializeU8(item);\n });\n }\n\n static deserializeVectorU8(deserializer: Deserializer): Seq<uint8> {\n const length = deserializer.deserializeLen();\n const list: Seq<uint8> = [];\n for (let i = 0; i < length; i++) {\n list.push(deserializer.deserializeU8());\n }\n return list;\n }\n\n static serializeVectorVectorU8(value: Seq<Seq<uint8>>, serializer: Serializer): void {\n serializer.serializeLen(value.length);\n value.forEach((item: Seq<uint8>) => {\n Helpers.serializeVectorU8(item, serializer);\n });\n }\n\n static deserializeVectorVectorU8(deserializer: Deserializer): Seq<Seq<uint8>> {\n const length = deserializer.deserializeLen();\n const list: Seq<Seq<uint8>> = [];\n for (let i = 0; i < length; i++) {\n list.push(Helpers.deserializeVectorU8(deserializer));\n }\n return list;\n }\n\n}\n\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Serializer, Deserializer } from '../../generated/runtime/serde/mod'\nimport { Seq, uint8 } from '../../generated/runtime/serde/mod'\nimport { Helpers } from '../../generated/runtime/rooch_types/mod'\n\nexport class MoveString {\n private bytes: Seq<uint8>\n\n constructor(bytes: Seq<uint8>) {\n this.bytes = bytes\n }\n\n public serialize(serializer: Serializer): void {\n Helpers.serializeVectorU8(this.bytes, serializer)\n }\n\n static deserialize(deserializer: Deserializer): MoveString {\n const bytes = Helpers.deserializeVectorU8(deserializer)\n return new MoveString(bytes)\n }\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Serializer, Deserializer } from '../../generated/runtime/serde/mod'\nimport { Seq, uint8 } from '../../generated/runtime/serde/mod'\nimport { Helpers } from '../../generated/runtime/rooch_types/mod'\n\nexport class MoveAsciiString {\n private bytes: Seq<uint8>\n\n constructor(bytes: Seq<uint8>) {\n this.bytes = bytes\n }\n\n public serialize(serializer: Serializer): void {\n Helpers.serializeVectorU8(this.bytes, serializer)\n }\n\n static deserialize(deserializer: Deserializer): MoveAsciiString {\n const bytes = Helpers.deserializeVectorU8(deserializer)\n return new MoveAsciiString(bytes)\n }\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BcsSerializer } from '../../generated/runtime/bcs/mod'\n\nconst BIG_128Fs = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')\nconst BIG_128 = BigInt(128)\n\nexport function serializeU256(se: BcsSerializer, value: bigint | number) {\n const low = BigInt(value.toString()) & BIG_128Fs\n const high = BigInt(value.toString()) >> BIG_128\n\n // write little endian number\n se.serializeU128(low)\n se.serializeU128(high)\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\n\n/**\nIn TypeScript, we can’t inherit or extend from more than one class,\nMixins helps us to get around that by creating a partial classes \nthat we can combine to form a single class that contains all the methods and properties from the partial classes.\n{@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern}\n*/\nexport function applyMixin(targetClass: any, baseClass: any, baseClassProp: string) {\n // Mixin instance methods\n Object.getOwnPropertyNames(baseClass.prototype).forEach((propertyName) => {\n const propertyDescriptor = Object.getOwnPropertyDescriptor(baseClass.prototype, propertyName)\n if (!propertyDescriptor) return\n // eslint-disable-next-line func-names\n propertyDescriptor.value = function (...args: any) {\n return (this as any)[baseClassProp][propertyName](...args)\n }\n Object.defineProperty(targetClass.prototype, propertyName, propertyDescriptor)\n })\n // Mixin static methods\n Object.getOwnPropertyNames(baseClass).forEach((propertyName) => {\n const propertyDescriptor = Object.getOwnPropertyDescriptor(baseClass, propertyName)\n if (!propertyDescriptor) return\n // eslint-disable-next-line func-names\n propertyDescriptor.value = function (...args: any) {\n return (this as any)[baseClassProp][propertyName](...args)\n }\n if (targetClass.hasOwnProperty.call(targetClass, propertyName)) {\n // The mixin has already been applied, so skip applying it again\n return\n }\n Object.defineProperty(targetClass, propertyName, propertyDescriptor)\n })\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\nimport { Buffer } from 'buffer'\n\nexport function toHexString(byteArray: Iterable<number>): string {\n return `0x${Buffer.from(new Uint8Array(byteArray)).toString('hex')}`\n}\n\nexport function fromHexString(hex: string, padding?: number): Uint8Array {\n let hexWithoutPrefix = hex.startsWith('0x') ? hex.substring(2) : hex\n\n if (padding && hexWithoutPrefix.length < padding) {\n hexWithoutPrefix = padLeft(hexWithoutPrefix, padding)\n } else if (!padding && hexWithoutPrefix.length % 2 !== 0) {\n hexWithoutPrefix = `0${hexWithoutPrefix}`\n }\n\n const buf = Buffer.from(hexWithoutPrefix, 'hex')\n return new Uint8Array(buf)\n}\n\n/**\n * @public\n * Should be called to pad string to expected length\n */\nexport function padLeft(str: string, chars: number, sign: string = '0') {\n return new Array(chars - str.length + 1).join(sign) + str\n}\n\n/**\n * @public\n * Should be called to pad string to expected length\n */\nexport function padRight(str: string, chars: number, sign: string = '0') {\n return str + new Array(chars - str.length + 1).join(sign)\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\nimport { ROOCH_ADDRESS_LENGTH } from '../constants'\nimport { FunctionId, AccountAddress, Identifier, TypeTag } from '../types'\n\nexport function functionIdToStirng(functionId: FunctionId): string {\n if (typeof functionId !== 'string') {\n if (functionId instanceof Object) {\n return `${functionId.address}::${functionId.module}::${functionId.functionName}`\n }\n }\n return functionId\n}\n\nexport function parseFunctionId(functionId: FunctionId): {\n address: AccountAddress\n module: Identifier\n functionName: Identifier\n} {\n if (typeof functionId !== 'string') {\n return functionId\n }\n const parts = functionId.split('::', 3)\n\n if (parts.length !== 3) {\n throw new Error(`cannot parse ${functionId} into FunctionId`)\n }\n\n return {\n address: normalizeRoochAddress(parts[0]),\n module: parts[1],\n functionName: parts[2],\n }\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `Rooch_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeRoochAddress(value: string, forceAdd0x: boolean = false): string {\n let address = value.toLowerCase()\n if (!forceAdd0x && address.startsWith('0x')) {\n address = address.slice(2)\n }\n return `0x${address.padStart(ROOCH_ADDRESS_LENGTH, '0')}`\n}\n\nexport function typeTagToString(type_tag: TypeTag): string {\n if (typeof type_tag === 'string') {\n return type_tag\n }\n\n if ('Vector' in type_tag) {\n return `Vector<${typeTagToString(type_tag.Vector)}>`\n }\n\n if ('Struct' in type_tag) {\n const struct = type_tag.Struct\n let result = `${struct.address}::${struct.module}::${struct.name}`\n if (struct.type_params) {\n const params = struct.type_params.map(typeTagToString).join(', ')\n result += `<${params}>`\n }\n return result\n }\n\n throw new Error(`Unknown type tag: ${JSON.stringify(type_tag)}`)\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\nimport { fromHexString } from './hex'\nimport { ROOCH_ADDRESS_LENGTH } from '../constants'\nimport { AccountAddress, FunctionId, TypeTag, StructTag, Arg } from '../types'\nimport * as rooch_types from '../types/bcs'\nimport {\n bytes as Bytes,\n Seq,\n Tuple,\n ListTuple,\n uint8,\n BcsSerializer,\n serializeU256,\n} from '../types/bcs'\nimport { parseFunctionId, normalizeRoochAddress } from './encode'\n\nexport function encodeFunctionCall(\n functionId: FunctionId,\n tyArgs: TypeTag[],\n args: Bytes[],\n): rooch_types.MoveActionVariantFunction {\n const funcId = parseFunctionId(functionId)\n\n const functionCall = new rooch_types.FunctionCall(\n new rooch_types.FunctionId(\n new rooch_types.ModuleId(\n addressToSCS(funcId.address),\n new rooch_types.Identifier(funcId.module),\n ),\n new rooch_types.Identifier(funcId.functionName),\n ),\n tyArgs.map((t) => typeTagToSCS(t)),\n bytesArrayToSeqSeq(args),\n )\n\n return new rooch_types.MoveActionVariantFunction(functionCall)\n}\n\nexport function typeTagToSCS(ty: TypeTag): rooch_types.TypeTag {\n if (ty === 'Bool') {\n return new rooch_types.TypeTagVariantbool()\n }\n if (ty === 'U8') {\n return new rooch_types.TypeTagVariantu8()\n }\n if (ty === 'U16') {\n return new rooch_types.TypeTagVariantu16()\n }\n if (ty === 'U32') {\n return new rooch_types.TypeTagVariantu32()\n }\n if (ty === 'U64') {\n return new rooch_types.TypeTagVariantu64()\n }\n if (ty === 'U128') {\n return new rooch_types.TypeTagVariantu128()\n }\n if (ty === 'U256') {\n return new rooch_types.TypeTagVariantu256()\n }\n if (ty === 'Address') {\n return new rooch_types.TypeTagVariantaddress()\n }\n if (ty === 'Signer') {\n return new rooch_types.TypeTagVariantsigner()\n }\n if ((ty as { Vector: TypeTag }).Vector) {\n return new rooch_types.TypeTagVariantvector(typeTagToSCS((ty as { Vector: TypeTag }).Vector))\n }\n if ((ty as { Struct: StructTag }).Struct) {\n return new rooch_types.TypeTagVariantstruct(\n structTagToSCS((ty as { Struct: StructTag }).Struct),\n )\n }\n throw new Error(`invalid type tag: ${ty}`)\n}\n\nexport function structTagToSCS(data: StructTag): rooch_types.StructTag {\n return new rooch_types.StructTag(\n addressToSCS(data.address),\n new rooch_types.Identifier(data.module),\n new rooch_types.Identifier(data.name),\n data.type_params ? data.type_params.map((t) => typeTagToSCS(t)) : [],\n )\n}\n\nexport function addressToSCS(addr: AccountAddress): rooch_types.AccountAddress {\n // AccountAddress should be 16 bytes, in hex, it's 16 * 2.\n const bytes = fromHexString(addr, 16 * 2)\n const data: [number][] = []\n for (let i = 0; i < bytes.length; i++) {\n data.push([bytes[i]])\n }\n return new rooch_types.AccountAddress(data)\n}\n\nexport function encodeStructTypeTags(typeArgsString: string[]): TypeTag[] {\n return typeArgsString.map((str) => encodeStructTypeTag(str))\n}\n\nfunction encodeStructTypeTag(str: string): TypeTag {\n const arr = str.split('<')\n const arr1 = arr[0].split('::')\n const address = arr1[0]\n const module = arr1[1]\n const name = arr1[2]\n\n const params = arr[1] ? arr[1].replace('>', '').split(',') : []\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const type_params: TypeTag[] = []\n if (params.length > 0) {\n params.forEach((param: string) => {\n type_params.push(encodeStructTypeTag(param.trim()))\n })\n }\n\n const result: TypeTag = {\n Struct: {\n address,\n module,\n name,\n type_params,\n },\n }\n return result\n}\n\nfunction bytesToSeq(byteArray: Bytes): Seq<number> {\n return Array.from(byteArray)\n}\n\nfunction stringToSeq(str: string): Seq<number> {\n const seq = new Array<number>()\n for (let i = 0; i < str.length; i++) {\n seq.push(str.charCodeAt(i))\n }\n return seq\n}\n\nfunction bytesArrayToSeqSeq(input: Bytes[]): Seq<Seq<number>> {\n return input.map((byteArray) => bytesToSeq(byteArray))\n}\n\nexport function addressToListTuple(ethAddress: string): ListTuple<[uint8]> {\n // Remove '0x' prefix\n const cleanedEthAddress = ethAddress.startsWith('0x') ? ethAddress.slice(2) : ethAddress\n\n // Check if the address is valid\n if (cleanedEthAddress.length !== ROOCH_ADDRESS_LENGTH) {\n throw new Error('Invalid Rooch address')\n }\n\n // Convert to list of tuples\n const listTuple: ListTuple<[uint8]> = []\n for (let i = 0; i < cleanedEthAddress.length; i += 2) {\n const byte = parseInt(cleanedEthAddress.slice(i, i + 2), 16)\n listTuple.push([byte] as Tuple<[uint8]>)\n }\n\n return listTuple\n}\n\nexport function addressToSeqNumber(ethAddress: string): Seq<number> {\n // Remove '0x' prefix\n const cleanedEthAddress = ethAddress.startsWith('0x') ? ethAddress.slice(2) : ethAddress\n\n // Check if the address is valid\n if (cleanedEthAddress.length !== ROOCH_ADDRESS_LENGTH) {\n throw new Error('Invalid Ethereum address')\n }\n\n // Convert to list of tuples\n const seqNumber: Seq<number> = []\n for (let i = 0; i < cleanedEthAddress.length; i += 2) {\n const byte = parseInt(cleanedEthAddress.slice(i, i + 2), 16)\n seqNumber.push(byte)\n }\n\n return seqNumber\n}\n\nfunction serializeValue(value: any, type: TypeTag, se: BcsSerializer) {\n if (type === 'Bool') {\n se.serializeBool(value)\n } else if (type === 'U8') {\n se.serializeU8(value)\n } else if (type === 'U16') {\n se.serializeU16(value)\n } else if (type === 'U32') {\n se.serializeU32(value)\n } else if (type === 'U64') {\n se.serializeU64(value)\n } else if (type === 'U128') {\n se.serializeU128(value)\n } else if (type === 'U256') {\n serializeU256(se, value)\n } else if (type === 'Address') {\n const list = addressToListTuple(normalizeRoochAddress(value as string))\n const accountAddress = new rooch_types.AccountAddress(list)\n accountAddress.serialize(se)\n } else if (type === 'Ascii') {\n const bytes = stringToSeq(value as string)\n const moveAsciiString = new rooch_types.MoveAsciiString(bytes)\n moveAsciiString.serialize(se)\n } else if (type === 'String') {\n const bytes = stringToSeq(value as string)\n const moveString = new rooch_types.MoveString(bytes)\n moveString.serialize(se)\n } else if ((type as { Vector: TypeTag }).Vector) {\n const vectorValues = value as any[]\n se.serializeLen(vectorValues.length)\n\n for (let item of vectorValues) {\n serializeValue(item, (type as { Vector: TypeTag }).Vector, se)\n }\n }\n}\n\nexport function encodeArg(arg: Arg): Bytes {\n const se = new BcsSerializer()\n serializeValue(arg.value, arg.type, se)\n return se.getBytes()\n}\n\nexport const encodeMoveCallData = (funcId: FunctionId, tyArgs: TypeTag[], args: Arg[]) => {\n const bcsArgs = args?.map((arg) => encodeArg(arg))\n const scriptFunction = encodeFunctionCall(funcId, tyArgs, bcsArgs)\n\n const payloadInHex = (() => {\n const se = new BcsSerializer()\n scriptFunction.serialize(se)\n return se.getBytes()\n })()\n\n return payloadInHex\n}\n","// Copyright (c) RoochNetwork\n// SPDX-License-Identifier: Apache-2.0\nimport { Seq } from '../generated/runtime/serde/