@rialo/ts-cdk 0.2.0-alpha.0 → 0.2.0-alpha.2

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/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ export { field, fixedArray, option, vec } from '@dao-xyz/borsh';
2
+
1
3
  interface HttpTransportConfig {
2
4
  /** Request timeout in milliseconds */
3
5
  timeout?: number;
@@ -973,15 +975,6 @@ interface SignatureInfo {
973
975
  * Get health response.
974
976
  */
975
977
  type GetHealthResponse = "ok" | string;
976
- /**
977
- * Get transactions configuration.
978
- */
979
- interface GetTransactionsConfig {
980
- /** Maximum number of transactions to return */
981
- limit?: number;
982
- /** Encoding format */
983
- encoding?: "json" | "base58" | "base64";
984
- }
985
978
  /**
986
979
  * Get transactions response.
987
980
  */
@@ -1029,8 +1022,6 @@ interface ConfirmedTransaction {
1029
1022
  * Configuration for getAccountsByOwner.
1030
1023
  */
1031
1024
  interface GetAccountsByOwnerConfig {
1032
- /** Encoding format for account data */
1033
- encoding?: "base64" | "base58" | "json" | "jsonParsed";
1034
1025
  /** Maximum number of accounts to return */
1035
1026
  limit?: number;
1036
1027
  /** Cursor for pagination (base58 pubkey) */
@@ -1805,6 +1796,387 @@ declare function createRialoClient(config: RialoClientConfig): RialoClient;
1805
1796
  */
1806
1797
  declare function getDefaultRialoClientConfig(network: RialoNetwork): RialoClientConfig;
1807
1798
 
1799
+ /**
1800
+ * Bincode deserialization reader
1801
+ *
1802
+ * Matches Rust's bincode crate with default configuration:
1803
+ * - Little-endian byte order
1804
+ * - Fixed-size integer encoding (no varint)
1805
+ * - u64 length prefixes for dynamic collections
1806
+ * - u32 enum variant indices
1807
+ */
1808
+ declare class BincodeReader {
1809
+ private view;
1810
+ private offset;
1811
+ private bytes;
1812
+ constructor(data: Uint8Array);
1813
+ getOffset(): number;
1814
+ remaining(): number;
1815
+ isExhausted(): boolean;
1816
+ skip(bytes: number): this;
1817
+ /**
1818
+ * Peek at bytes without advancing the offset
1819
+ */
1820
+ peek(length: number): Uint8Array;
1821
+ /**
1822
+ * Reset reader to beginning
1823
+ */
1824
+ reset(): this;
1825
+ /**
1826
+ * Seek to specific offset
1827
+ */
1828
+ seek(offset: number): this;
1829
+ readU8(): number;
1830
+ readU16(): number;
1831
+ readU32(): number;
1832
+ readU64(): bigint;
1833
+ readU128(): bigint;
1834
+ readI8(): number;
1835
+ readI16(): number;
1836
+ readI32(): number;
1837
+ readI64(): bigint;
1838
+ readI128(): bigint;
1839
+ readF32(): number;
1840
+ readF64(): number;
1841
+ readBool(): boolean;
1842
+ readBytes(length: number): Uint8Array;
1843
+ readFixedArray(length: number): Uint8Array;
1844
+ readVecBytes(): Uint8Array;
1845
+ readString(): string;
1846
+ readVariant(): number;
1847
+ readOption<T>(readValue: () => T): T | null;
1848
+ readVec<T>(readElement: () => T): T[];
1849
+ /**
1850
+ * Read a tuple of fixed size with heterogeneous types
1851
+ */
1852
+ readTuple<T extends unknown[]>(readers: {
1853
+ [K in keyof T]: () => T[K];
1854
+ }): T;
1855
+ readMap<K, V>(readKey: () => K, readValue: () => V): Map<K, V>;
1856
+ /**
1857
+ * Read length as u64 but validate it's within safe integer range
1858
+ */
1859
+ private readLength;
1860
+ private ensureAvailable;
1861
+ }
1862
+
1863
+ /**
1864
+ * Type definitions for bincode schemas
1865
+ *
1866
+ * IMPORTANT: For structs and enums, field/variant order MUST match Rust definition order.
1867
+ * Use arrays of tuples instead of objects to guarantee order preservation.
1868
+ */
1869
+ type BincodeSchema = {
1870
+ type: "u8";
1871
+ } | {
1872
+ type: "u16";
1873
+ } | {
1874
+ type: "u32";
1875
+ } | {
1876
+ type: "u64";
1877
+ } | {
1878
+ type: "u128";
1879
+ } | {
1880
+ type: "i8";
1881
+ } | {
1882
+ type: "i16";
1883
+ } | {
1884
+ type: "i32";
1885
+ } | {
1886
+ type: "i64";
1887
+ } | {
1888
+ type: "i128";
1889
+ } | {
1890
+ type: "f32";
1891
+ } | {
1892
+ type: "f64";
1893
+ } | {
1894
+ type: "bool";
1895
+ } | {
1896
+ type: "string";
1897
+ } | {
1898
+ type: "bytes";
1899
+ } | {
1900
+ type: "unit";
1901
+ } | {
1902
+ type: "fixedArray";
1903
+ length: number;
1904
+ } | {
1905
+ type: "vec";
1906
+ element: BincodeSchema;
1907
+ } | {
1908
+ type: "option";
1909
+ inner: BincodeSchema;
1910
+ } | {
1911
+ type: "tuple";
1912
+ elements: BincodeSchema[];
1913
+ } | {
1914
+ type: "struct";
1915
+ fields: StructField[];
1916
+ } | {
1917
+ type: "enum";
1918
+ variants: EnumVariant[];
1919
+ } | {
1920
+ type: "map";
1921
+ key: BincodeSchema;
1922
+ value: BincodeSchema;
1923
+ } | {
1924
+ type: "pubkey";
1925
+ };
1926
+ /**
1927
+ * Struct field definition - order matters!
1928
+ */
1929
+ interface StructField {
1930
+ name: string;
1931
+ schema: BincodeSchema;
1932
+ }
1933
+ /**
1934
+ * Enum variant definition - order matters!
1935
+ */
1936
+ interface EnumVariant {
1937
+ name: string;
1938
+ schema: BincodeSchema | null;
1939
+ }
1940
+ declare const Schema: {
1941
+ readonly u8: () => BincodeSchema;
1942
+ readonly u16: () => BincodeSchema;
1943
+ readonly u32: () => BincodeSchema;
1944
+ readonly u64: () => BincodeSchema;
1945
+ readonly u128: () => BincodeSchema;
1946
+ readonly i8: () => BincodeSchema;
1947
+ readonly i16: () => BincodeSchema;
1948
+ readonly i32: () => BincodeSchema;
1949
+ readonly i64: () => BincodeSchema;
1950
+ readonly i128: () => BincodeSchema;
1951
+ readonly f32: () => BincodeSchema;
1952
+ readonly f64: () => BincodeSchema;
1953
+ readonly bool: () => BincodeSchema;
1954
+ readonly string: () => BincodeSchema;
1955
+ readonly bytes: () => BincodeSchema;
1956
+ readonly unit: () => BincodeSchema;
1957
+ readonly fixedArray: (length: number) => BincodeSchema;
1958
+ readonly vec: (element: BincodeSchema) => BincodeSchema;
1959
+ readonly option: (inner: BincodeSchema) => BincodeSchema;
1960
+ readonly tuple: (...elements: BincodeSchema[]) => BincodeSchema;
1961
+ /**
1962
+ * Define a struct with ordered fields
1963
+ * @example
1964
+ * Schema.struct([
1965
+ * ["id", Schema.u64()],
1966
+ * ["name", Schema.string()],
1967
+ * ["active", Schema.bool()],
1968
+ * ])
1969
+ */
1970
+ readonly struct: (fields: [string, BincodeSchema][]) => BincodeSchema;
1971
+ /**
1972
+ * Define an enum with ordered variants
1973
+ * @example
1974
+ * Schema.enum([
1975
+ * ["None", null],
1976
+ * ["Some", Schema.u64()],
1977
+ * ["Error", Schema.string()],
1978
+ * ])
1979
+ */
1980
+ readonly enum: (variants: [string, BincodeSchema | null][]) => BincodeSchema;
1981
+ readonly map: (key: BincodeSchema, value: BincodeSchema) => BincodeSchema;
1982
+ readonly pubkey: () => BincodeSchema;
1983
+ };
1984
+ /**
1985
+ * Serialize a value according to a schema
1986
+ */
1987
+ declare function serialize(schema: BincodeSchema, value: unknown): Uint8Array;
1988
+ /**
1989
+ * Deserialize bytes according to a schema
1990
+ */
1991
+ declare function deserialize<T>(schema: BincodeSchema, data: Uint8Array): T;
1992
+ /**
1993
+ * Deserialize bytes with strict validation
1994
+ */
1995
+ declare function deserializeStrict<T>(schema: BincodeSchema, data: Uint8Array): T;
1996
+ /**
1997
+ * Infer TypeScript type from schema (for documentation purposes)
1998
+ *
1999
+ * Usage:
2000
+ * const mySchema = Schema.struct([...]);
2001
+ * type MyType = InferSchema<typeof mySchema>;
2002
+ */
2003
+ type InferSchema<S extends BincodeSchema> = S extends {
2004
+ type: "u8";
2005
+ } ? number : S extends {
2006
+ type: "u16";
2007
+ } ? number : S extends {
2008
+ type: "u32";
2009
+ } ? number : S extends {
2010
+ type: "u64";
2011
+ } ? bigint : S extends {
2012
+ type: "u128";
2013
+ } ? bigint : S extends {
2014
+ type: "i8";
2015
+ } ? number : S extends {
2016
+ type: "i16";
2017
+ } ? number : S extends {
2018
+ type: "i32";
2019
+ } ? number : S extends {
2020
+ type: "i64";
2021
+ } ? bigint : S extends {
2022
+ type: "i128";
2023
+ } ? bigint : S extends {
2024
+ type: "f32";
2025
+ } ? number : S extends {
2026
+ type: "f64";
2027
+ } ? number : S extends {
2028
+ type: "bool";
2029
+ } ? boolean : S extends {
2030
+ type: "string";
2031
+ } ? string : S extends {
2032
+ type: "bytes";
2033
+ } ? Uint8Array : S extends {
2034
+ type: "unit";
2035
+ } ? undefined : S extends {
2036
+ type: "fixedArray";
2037
+ } ? Uint8Array : S extends {
2038
+ type: "pubkey";
2039
+ } ? Uint8Array : S extends {
2040
+ type: "vec";
2041
+ element: infer E;
2042
+ } ? E extends BincodeSchema ? InferSchema<E>[] : never : S extends {
2043
+ type: "option";
2044
+ inner: infer I;
2045
+ } ? I extends BincodeSchema ? InferSchema<I> | null : never : unknown;
2046
+
2047
+ /**
2048
+ * Bincode serialization writer
2049
+ *
2050
+ * Matches Rust's bincode crate with default configuration:
2051
+ * - Little-endian byte order
2052
+ * - Fixed-size integer encoding (no varint)
2053
+ * - u64 length prefixes for dynamic collections
2054
+ * - u32 enum variant indices
2055
+ */
2056
+ declare class BincodeWriter {
2057
+ private buffer;
2058
+ private offset;
2059
+ private view;
2060
+ constructor(initialCapacity?: number);
2061
+ writeU8(value: number): this;
2062
+ writeU16(value: number): this;
2063
+ writeU32(value: number): this;
2064
+ writeU64(value: bigint | number): this;
2065
+ writeU128(value: bigint): this;
2066
+ writeI8(value: number): this;
2067
+ writeI16(value: number): this;
2068
+ writeI32(value: number): this;
2069
+ writeI64(value: bigint): this;
2070
+ writeI128(value: bigint): this;
2071
+ writeF32(value: number): this;
2072
+ writeF64(value: number): this;
2073
+ writeBool(value: boolean): this;
2074
+ writeBytes(bytes: Uint8Array): this;
2075
+ writeFixedArray(bytes: Uint8Array, expectedLength?: number): this;
2076
+ writeVecBytes(bytes: Uint8Array): this;
2077
+ writeString(str: string): this;
2078
+ writeVariant(index: number): this;
2079
+ writeOption<T>(value: T | null | undefined, writeValue: (writer: BincodeWriter, val: T) => void): this;
2080
+ writeVec<T>(items: T[], writeItem: (writer: BincodeWriter, item: T) => void): this;
2081
+ /**
2082
+ * Write a tuple (fixed-size heterogeneous collection)
2083
+ */
2084
+ writeTuple<T extends unknown[]>(items: T, writers: {
2085
+ [K in keyof T]: (writer: BincodeWriter, val: T[K]) => void;
2086
+ }): this;
2087
+ writeMap<K, V>(map: Map<K, V>, writeKey: (writer: BincodeWriter, key: K) => void, writeValue: (writer: BincodeWriter, value: V) => void): this;
2088
+ toBytes(): Uint8Array;
2089
+ /**
2090
+ * Get a view of the written bytes WITHOUT copying.
2091
+ *
2092
+ * ⚠️ WARNING: This returns a view into the internal buffer.
2093
+ * The view becomes INVALID if:
2094
+ * - The writer continues writing (may trigger resize)
2095
+ * - The writer is cleared via clear()
2096
+ *
2097
+ * Use toBytes() for a safe copy, or use this only for immediate
2098
+ * read-only access when performance is critical.
2099
+ */
2100
+ toView(): Uint8Array;
2101
+ length(): number;
2102
+ clear(): this;
2103
+ /**
2104
+ * Reserve additional capacity
2105
+ */
2106
+ reserve(additionalBytes: number): this;
2107
+ private ensureCapacity;
2108
+ }
2109
+
2110
+ /**
2111
+ * Serializes data using Borsh (Binary Object Representation Serializer for Hashing) encoding.
2112
+ *
2113
+ * Borsh is efficient for complex types like enums, Options, vectors, and nested structs.
2114
+ * Use the exported decorators (@field, @option, @vec) to define your data structures.
2115
+ *
2116
+ * @param data - Data object to serialize
2117
+ * @returns Serialized bytes
2118
+ *
2119
+ * @example
2120
+ * ```typescript
2121
+ * import { serializeBorsh, field, option } from '@rialo/ts-cdk';
2122
+ *
2123
+ * class SwapInstruction {
2124
+ * @field({ type: 'u8' })
2125
+ * instruction: number;
2126
+ *
2127
+ * @field({ type: 'u64' })
2128
+ * amountIn: bigint;
2129
+ *
2130
+ * @field({ type: option('u64') })
2131
+ * minAmountOut?: bigint;
2132
+ * }
2133
+ *
2134
+ * const data = serializeBorsh(new SwapInstruction({
2135
+ * instruction: 1,
2136
+ * amountIn: 1000n,
2137
+ * minAmountOut: 900n,
2138
+ * }));
2139
+ * ```
2140
+ */
2141
+ declare function serializeBorsh<T>(data: T): Uint8Array;
2142
+ /**
2143
+ * Deserializes Borsh-encoded data into a typed object.
2144
+ *
2145
+ * @param data - Borsh-encoded bytes
2146
+ * @param type - Class constructor for the target type
2147
+ * @returns Deserialized object instance
2148
+ */
2149
+ declare function deserializeBorsh<T>(data: Uint8Array, type: new () => T): T;
2150
+
2151
+ /**
2152
+ * Serializes a u16 value into compact encoding.
2153
+ *
2154
+ * @param buffer - Output buffer to append bytes to
2155
+ * @param value - Value to encode (0-65535)
2156
+ * @throws {TransactionError} If value is out of range
2157
+ */
2158
+ declare function serializeCompactU16(buffer: number[], value: number): void;
2159
+ /**
2160
+ * Deserializes a compact-u16 value from bytes.
2161
+ *
2162
+ * @param data - Input byte array
2163
+ * @param currentCursor - Starting position in the array
2164
+ * @returns Tuple of [decoded value, new cursor position]
2165
+ * @throws {TransactionError} If data is insufficient or malformed
2166
+ */
2167
+ declare function deserializeCompactU16(data: Uint8Array, currentCursor: number): [number, number];
2168
+ /**
2169
+ * Writes a compact-u16 value directly to a buffer (zero-copy).
2170
+ *
2171
+ * Optimized version for in-place writing without intermediate allocations.
2172
+ *
2173
+ * @param buffer - Target buffer
2174
+ * @param offset - Starting position to write at
2175
+ * @param value - Value to encode (0-127 only, uses 1-2 bytes)
2176
+ * @returns New offset after writing
2177
+ */
2178
+ declare function writeCompactU16(buffer: Uint8Array, offset: number, value: number): number;
2179
+
1808
2180
  /**
1809
2181
  * Interface for signing messages and transactions.
1810
2182
  *
@@ -2512,4 +2884,4 @@ declare function getMainnetUrl(): string;
2512
2884
  */
2513
2885
  declare function getLocalnetUrl(): string;
2514
2886
 
2515
- export { type AccountFilter, type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, type Bump, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EpochInfoResponse, type EventData, type GetAccountsByOwnerConfig, type GetAccountsByOwnerResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetTransactionsConfig, type GetTransactionsResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type Instruction, KELVIN_PER_RLO, Keypair, KeypairSigner, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type OwnerAccount, type PDA, PUBLIC_KEY_LENGTH, type PaginationInfo, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_SHITNET_CHAIN, RIALO_TESTNET_CHAIN, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, type Seed, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureInfo, type SignatureStatus, type Signer, type Subscription, type SubscriptionKind, SystemInstruction, type TimestampRange, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, type TransactionNodeData, type TransactionResponse, TransactionRpcClient, type TriggerInfo, type TriggeredTransaction, type TruncationReason, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_SHITNET, URL_TESTNET, type WorkflowLineage, type WorkflowNode, allocateInstruction, assignInstruction, calculateBackoff, concatBytes, createAccount, createBorshInstruction, createRialoClient, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, isOnCurve, seedToBytes, sleep, toBase64, transferInstruction };
2887
+ export { type AccountFilter, type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, BincodeReader, type BincodeSchema, BincodeWriter, type Bump, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EnumVariant, type EpochInfoResponse, type EventData, type GetAccountsByOwnerConfig, type GetAccountsByOwnerResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetTransactionsResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type InferSchema, type Instruction, KELVIN_PER_RLO, Keypair, KeypairSigner, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type OwnerAccount, type PDA, PUBLIC_KEY_LENGTH, type PaginationInfo, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_SHITNET_CHAIN, RIALO_TESTNET_CHAIN, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, Schema, type Seed, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureInfo, type SignatureStatus, type Signer, type StructField, type Subscription, type SubscriptionKind, SystemInstruction, type TimestampRange, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, type TransactionNodeData, type TransactionResponse, TransactionRpcClient, type TriggerInfo, type TriggeredTransaction, type TruncationReason, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_SHITNET, URL_TESTNET, type WorkflowLineage, type WorkflowNode, allocateInstruction, assignInstruction, calculateBackoff, concatBytes, createAccount, createBorshInstruction, createRialoClient, deserialize, deserializeBorsh, deserializeCompactU16, deserializeStrict, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, isOnCurve, seedToBytes, serialize, serializeBorsh, serializeCompactU16, sleep, toBase64, transferInstruction, writeCompactU16 };