@rialo/ts-cdk 0.2.0-alpha.1 → 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
@@ -733,341 +733,6 @@ declare class RialoError extends Error {
733
733
  static serialization(message: string): RialoError;
734
734
  }
735
735
 
736
- /**
737
- * Error codes for HPKE encryption operations.
738
- */
739
- declare enum HpkeErrorCode {
740
- /** Key length does not match expected size */
741
- INVALID_KEY_LENGTH = "INVALID_KEY_LENGTH",
742
- /** Ciphertext is shorter than minimum required length */
743
- CIPHERTEXT_TOO_SHORT = "CIPHERTEXT_TOO_SHORT",
744
- /** HPKE encryption operation failed */
745
- ENCRYPTION_FAILED = "ENCRYPTION_FAILED",
746
- /** Failed to deserialize Borsh data */
747
- BORSH_DESERIALIZE_FAILED = "BORSH_DESERIALIZE_FAILED",
748
- /** RexValue has invalid variant byte */
749
- INVALID_ORACLE_VALUE = "INVALID_ORACLE_VALUE"
750
- }
751
- /**
752
- * Error class for HPKE encryption operations.
753
- *
754
- * Provides detailed error information for encryption failures,
755
- * including error codes and contextual details.
756
- */
757
- declare class HpkeError extends Error {
758
- readonly code: HpkeErrorCode;
759
- readonly cause?: Error;
760
- constructor(code: HpkeErrorCode, message: string, cause?: Error);
761
- /**
762
- * Create an error for invalid key length.
763
- *
764
- * @param expected - Expected key length in bytes
765
- * @param actual - Actual key length in bytes
766
- * @param keyType - Description of the key type (e.g., "REX public key")
767
- */
768
- static invalidKeyLength(expected: number, actual: number, keyType: string): HpkeError;
769
- /**
770
- * Create an error for ciphertext that is too short.
771
- *
772
- * @param minLength - Minimum required length
773
- * @param actual - Actual length
774
- */
775
- static ciphertextTooShort(minLength: number, actual: number): HpkeError;
776
- /**
777
- * Create an error for encryption failure.
778
- *
779
- * @param cause - The underlying error
780
- */
781
- static encryptionFailed(cause: Error): HpkeError;
782
- /**
783
- * Create an error for Borsh deserialization failure.
784
- *
785
- * @param cause - The underlying error
786
- */
787
- static borshDeserializeFailed(cause: Error): HpkeError;
788
- /**
789
- * Create an error for invalid RexValue variant.
790
- *
791
- * @param variant - The invalid variant byte
792
- */
793
- static invalidRexValue(variant: number): HpkeError;
794
- }
795
-
796
- /**
797
- * Constants for REX HPKE encryption.
798
- *
799
- * These constants MUST match the Rust implementation exactly:
800
- * - `crates/tee/secret-sharing/src/constants.rs`
801
- *
802
- * @module
803
- */
804
- /**
805
- * Additional Authenticated Data (AAD) prefix for user secrets.
806
- *
807
- * This 13-byte string is prepended to the sender's public key to form
808
- * the complete AAD for HPKE encryption. It provides domain separation
809
- * to prevent cross-protocol attacks.
810
- *
811
- * Format: `USER_SECRET_AAD || senderPubkey` = 45 bytes total AAD
812
- *
813
- * @remarks
814
- * Must match Rust: `pub const USER_SECRET_AAD: &[u8] = b"rex-secret-v1";`
815
- */
816
- declare const USER_SECRET_AAD: Uint8Array<ArrayBuffer>;
817
- /**
818
- * HPKE info string for secret sharing context.
819
- *
820
- * This 32-byte string is used as the `info` parameter in HPKE encryption,
821
- * providing domain separation for secret sharing operations.
822
- *
823
- * @remarks
824
- * Must match Rust: `pub const SECRET_SHARING_HPKE_INFO: &[u8; 32] = b"rialo/tee/secret-sharing-hpke/v1";`
825
- */
826
- declare const SECRET_SHARING_HPKE_INFO: Uint8Array<ArrayBuffer>;
827
- /**
828
- * Length of an X25519 public key in bytes.
829
- *
830
- * Used for the REX encryption public key (secret sharing key).
831
- */
832
- declare const X25519_PUBLIC_KEY_LENGTH = 32;
833
- /**
834
- * Length of an Ed25519 public key in bytes.
835
- *
836
- * Used for sender identity binding in AAD construction.
837
- */
838
- declare const ED25519_PUBLIC_KEY_LENGTH = 32;
839
- /**
840
- * Length of the HPKE encapsulated key (enc) in bytes.
841
- *
842
- * For X25519, this is always 32 bytes.
843
- */
844
- declare const HPKE_ENC_LENGTH = 32;
845
- /**
846
- * Length of the ChaCha20-Poly1305 authentication tag in bytes.
847
- */
848
- declare const CHACHA20_POLY1305_TAG_LENGTH = 16;
849
- /**
850
- * Total overhead added by HPKE encryption.
851
- *
852
- * This is the additional bytes beyond the plaintext:
853
- * - enc (32 bytes): Encapsulated ephemeral public key
854
- * - tag (16 bytes): ChaCha20-Poly1305 authentication tag
855
- *
856
- * Ciphertext length = plaintext length + 48 bytes
857
- */
858
- declare const HPKE_OVERHEAD_LENGTH: number;
859
-
860
- /**
861
- * Variant discriminator for RexValue Borsh serialization.
862
- */
863
- declare enum RexValueVariant {
864
- /** Plain (unencrypted) data variant */
865
- Plain = 0,
866
- /** Encrypted data variant */
867
- Encrypted = 1
868
- }
869
- /**
870
- * Represents an rex value that can be plain or encrypted.
871
- *
872
- * This class provides Borsh-compatible serialization that matches
873
- * the Rust `RexValue` enum:
874
- *
875
- * ```rust
876
- * pub enum RexValue {
877
- * Plain(Vec<u8>),
878
- * Encrypted(Vec<u8>),
879
- * }
880
- * ```
881
- *
882
- * ## Borsh Format
883
- *
884
- * - Plain: `[0x00] [length: u32 LE] [data bytes]`
885
- * - Encrypted: `[0x01] [length: u32 LE] [ciphertext bytes]`
886
- *
887
- * @example
888
- * ```typescript
889
- * // Plain value (unencrypted)
890
- * const plain = RexValue.plain(new TextEncoder().encode("hello"));
891
- *
892
- * // Encrypted value (via HPKE)
893
- * const encrypted = RexValue.encrypted(ciphertextBytes);
894
- *
895
- * // Serialize to Borsh
896
- * const borsh = plain.toBorsh();
897
- *
898
- * // Deserialize from Borsh
899
- * const restored = RexValue.fromBorsh(borsh);
900
- * ```
901
- */
902
- declare class RexValue {
903
- private readonly variant;
904
- private readonly data;
905
- private constructor();
906
- /**
907
- * Create a plain (unencrypted) RexValue from raw bytes.
908
- *
909
- * @param data - The raw byte data
910
- * @returns A new RexValue with Plain variant
911
- */
912
- static plain(data: Uint8Array): RexValue;
913
- /**
914
- * Create a plain (unencrypted) RexValue from a UTF-8 string.
915
- *
916
- * @param s - The string to encode
917
- * @returns A new RexValue with Plain variant
918
- */
919
- static plainString(s: string): RexValue;
920
- /**
921
- * Create an encrypted RexValue from HPKE ciphertext.
922
- *
923
- * @param ciphertext - The HPKE-encrypted ciphertext (enc || ct || tag)
924
- * @returns A new RexValue with Encrypted variant
925
- */
926
- static encrypted(ciphertext: Uint8Array): RexValue;
927
- /**
928
- * Check if this is a plain (unencrypted) value.
929
- */
930
- isPlain(): boolean;
931
- /**
932
- * Check if this is an encrypted value.
933
- */
934
- isEncrypted(): boolean;
935
- /**
936
- * Get the variant type.
937
- */
938
- getVariant(): RexValueVariant;
939
- /**
940
- * Get the raw bytes (plaintext or ciphertext).
941
- *
942
- * For Plain values, returns the plaintext.
943
- * For Encrypted values, returns the ciphertext.
944
- */
945
- asBytes(): Uint8Array;
946
- /**
947
- * Try to decode the plain value as a UTF-8 string.
948
- *
949
- * @returns The decoded string, or null if encrypted or not valid UTF-8
950
- */
951
- asString(): string | null;
952
- /**
953
- * Serialize to Borsh format.
954
- *
955
- * Format: `[variant: u8] [length: u32 LE] [data bytes]`
956
- *
957
- * @returns The Borsh-serialized bytes
958
- */
959
- toBorsh(): Uint8Array;
960
- /**
961
- * Deserialize from Borsh format.
962
- *
963
- * @param data - The Borsh-serialized bytes
964
- * @returns A new RexValue
965
- * @throws {HpkeError} If deserialization fails
966
- */
967
- static fromBorsh(data: Uint8Array): RexValue;
968
- }
969
-
970
- /**
971
- * Encrypt data using HPKE for REX secret sharing.
972
- *
973
- * This function performs HPKE encryption using the Base mode with:
974
- * - X25519 for key encapsulation
975
- * - HKDF-SHA256 for key derivation
976
- * - ChaCha20-Poly1305 for authenticated encryption
977
- *
978
- * The output format is: `enc (32 bytes) || ciphertext || tag (16 bytes)`
979
- *
980
- * @param rexPubkey - The REX X25519 public key (32 bytes)
981
- * @param data - The plaintext data to encrypt
982
- * @param senderPubkey - The sender's Ed25519 public key (32 bytes) for AAD construction
983
- * @returns The encrypted ciphertext including enc and tag
984
- * @throws {HpkeError} If key lengths are invalid or encryption fails
985
- *
986
- * @example
987
- * ```typescript
988
- * const rexPubkey = await client.getSecretSharingPubkey();
989
- * const ciphertext = await hpkeEncrypt(
990
- * rexPubkey,
991
- * new TextEncoder().encode("secret data"),
992
- * keypair.publicKey.toBytes()
993
- * );
994
- * ```
995
- */
996
- declare function hpkeEncrypt(rexPubkey: Uint8Array, data: Uint8Array, senderPubkey: Uint8Array): Promise<Uint8Array>;
997
- /**
998
- * Encrypt data for REX and wrap it in an RexValue.
999
- *
1000
- * This is a convenience function that combines:
1001
- * 1. HPKE encryption using `hpkeEncrypt`
1002
- * 2. Wrapping the ciphertext in an `RexValue.encrypted`
1003
- *
1004
- * The resulting RexValue can be serialized to Borsh and sent to the network.
1005
- *
1006
- * @param rexPubkey - The REX X25519 public key (32 bytes)
1007
- * @param data - The plaintext data to encrypt
1008
- * @param senderPubkey - The sender's Ed25519 public key (32 bytes)
1009
- * @returns An RexValue containing the encrypted ciphertext
1010
- * @throws {HpkeError} If key lengths are invalid or encryption fails
1011
- *
1012
- * @example
1013
- * ```typescript
1014
- * import { RpcClient, Keypair } from "@rialo/ts-cdk";
1015
- * import { encryptForRex, RexValue } from "@rialo/ts-cdk/rex";
1016
- *
1017
- * // Get REX public key from the network
1018
- * const client = new RpcClient("https://rpc.rialo.xyz");
1019
- * const rexPubkey = await client.getSecretSharingPubkey();
1020
- *
1021
- * // Create keypair for signing
1022
- * const keypair = Keypair.generate();
1023
- *
1024
- * // Encrypt secret data
1025
- * const oracleValue = await encryptForRex(
1026
- * rexPubkey,
1027
- * new TextEncoder().encode("my secret API key"),
1028
- * keypair.publicKey.toBytes()
1029
- * );
1030
- *
1031
- * // The RexValue can now be serialized and used in transactions
1032
- * const borshBytes = oracleValue.toBorsh();
1033
- * ```
1034
- */
1035
- declare function encryptForRex(rexPubkey: Uint8Array, data: Uint8Array, senderPubkey: Uint8Array): Promise<RexValue>;
1036
- /**
1037
- * Calculate the expected ciphertext length for a given plaintext length.
1038
- *
1039
- * The ciphertext consists of:
1040
- * - enc (32 bytes): Encapsulated ephemeral public key
1041
- * - ciphertext (plaintext.length bytes): Encrypted data
1042
- * - tag (16 bytes): ChaCha20-Poly1305 authentication tag
1043
- *
1044
- * @param plaintextLength - Length of the plaintext in bytes
1045
- * @returns Expected ciphertext length
1046
- *
1047
- * @example
1048
- * ```typescript
1049
- * const ciphertextLen = getCiphertextLength(100);
1050
- * console.log(ciphertextLen); // 148 (32 + 100 + 16)
1051
- * ```
1052
- */
1053
- declare function getCiphertextLength(plaintextLength: number): number;
1054
- /**
1055
- * Validate that a ciphertext has a valid length.
1056
- *
1057
- * A valid HPKE ciphertext must be at least 48 bytes (32 enc + 16 tag).
1058
- *
1059
- * @param ciphertext - The ciphertext to validate
1060
- * @returns true if the ciphertext length is valid
1061
- *
1062
- * @example
1063
- * ```typescript
1064
- * if (!isValidCiphertextLength(ciphertext)) {
1065
- * throw new Error("Ciphertext too short");
1066
- * }
1067
- * ```
1068
- */
1069
- declare function isValidCiphertextLength(ciphertext: Uint8Array): boolean;
1070
-
1071
736
  /**
1072
737
  * Base client with JSON-RPC protocol handling.
1073
738
  *
@@ -1399,15 +1064,6 @@ interface GetAccountsByOwnerResponse {
1399
1064
  /** Pagination information */
1400
1065
  pagination?: PaginationInfo;
1401
1066
  }
1402
- /**
1403
- * Get secret sharing public key response.
1404
- *
1405
- * Contains the TEE's X25519 public key for HPKE encryption.
1406
- */
1407
- interface GetSecretSharingPubkeyResponse {
1408
- /** The TEE's X25519 public key as a hex-encoded string */
1409
- public_key: string;
1410
- }
1411
1067
 
1412
1068
  /**
1413
1069
  * Main Rialo RPC client for blockchain interactions.
@@ -1889,50 +1545,6 @@ declare class QueryRpcClient extends BaseRpcClient {
1889
1545
  * ```
1890
1546
  */
1891
1547
  getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
1892
- /**
1893
- * Retrieve the REX X25519 public key for secret sharing encryption.
1894
- *
1895
- * This key is used for HPKE encryption when sending encrypted data
1896
- * that should only be decryptable within the REX execution environment.
1897
- *
1898
- * @returns The REX X25519 public key as a 32-byte Uint8Array
1899
- *
1900
- * @example
1901
- * ```typescript
1902
- * import { encryptForRex } from "@rialo/ts-cdk";
1903
- *
1904
- * // Get the REX public key
1905
- * const rexPubkey = await client.getSecretSharingPubkey();
1906
- *
1907
- * // Use it for HPKE encryption
1908
- * const encrypted = await encryptForRex(
1909
- * rexPubkey,
1910
- * new TextEncoder().encode("secret data"),
1911
- * keypair.publicKey.toBytes()
1912
- * );
1913
- * ```
1914
- */
1915
- getSecretSharingPubkey(): Promise<Uint8Array>;
1916
- /**
1917
- * Get the config hash prefix for replay protection.
1918
- *
1919
- * Returns the first 64 bits of the config hash, which is used
1920
- * for transaction replay protection across chains.
1921
- *
1922
- * @returns The config hash prefix as a bigint
1923
- *
1924
- * @example
1925
- * ```typescript
1926
- * const configHashPrefix = await client.getConfigHashPrefix();
1927
- * const tx = TransactionBuilder.create()
1928
- * .setPayer(payer)
1929
- * .setValidFrom(validFrom)
1930
- * .setConfigHashPrefix(configHashPrefix)
1931
- * .addInstruction(instruction)
1932
- * .build();
1933
- * ```
1934
- */
1935
- getConfigHashPrefix(): Promise<bigint>;
1936
1548
  }
1937
1549
 
1938
1550
  /**
@@ -2941,13 +2553,11 @@ declare class Message {
2941
2553
  readonly accountKeys: readonly PublicKey[];
2942
2554
  /** Transaction valid from (milliseconds since Unix epoch) */
2943
2555
  validFrom?: bigint;
2944
- /** Config hash prefix for replay protection across chains */
2945
- readonly configHashPrefix: bigint;
2946
2556
  /** Compiled instructions with account indices */
2947
2557
  readonly instructions: readonly CompiledInstruction[];
2948
2558
  /** Cached serialized bytes */
2949
2559
  private serializedCache?;
2950
- constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, configHashPrefix: bigint, instructions: readonly CompiledInstruction[]);
2560
+ constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, instructions: readonly CompiledInstruction[]);
2951
2561
  /**
2952
2562
  * Serialize message to bytes for signing.
2953
2563
  * Result is cached for performance.
@@ -3177,7 +2787,6 @@ declare class Transaction {
3177
2787
  declare class TransactionBuilder {
3178
2788
  private payer?;
3179
2789
  private validFrom?;
3180
- private configHashPrefix?;
3181
2790
  private readonly instructions;
3182
2791
  private constructor();
3183
2792
  /**
@@ -3202,15 +2811,6 @@ declare class TransactionBuilder {
3202
2811
  * @param validFrom - Transaction valid from in milliseconds since Unix epoch
3203
2812
  */
3204
2813
  setValidFrom(validFrom: bigint): this;
3205
- /**
3206
- * Set the config hash prefix for replay protection.
3207
- *
3208
- * This is the first 64 bits of the config hash, used to ensure
3209
- * transactions cannot be replayed on different chains.
3210
- *
3211
- * @param configHashPrefix - config hash prefix as a u64
3212
- */
3213
- setConfigHashPrefix(configHashPrefix: bigint): this;
3214
2814
  /**
3215
2815
  * Add an instruction to the transaction.
3216
2816
  *
@@ -3284,4 +2884,4 @@ declare function getMainnetUrl(): string;
3284
2884
  */
3285
2885
  declare function getLocalnetUrl(): string;
3286
2886
 
3287
- export { type AccountFilter, type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, BincodeReader, type BincodeSchema, BincodeWriter, type Bump, CHACHA20_POLY1305_TAG_LENGTH, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, ED25519_PUBLIC_KEY_LENGTH, type EnumVariant, type EpochInfoResponse, type EventData, type GetAccountsByOwnerConfig, type GetAccountsByOwnerResponse, type GetHealthResponse, type GetSecretSharingPubkeyResponse, type GetSignaturesForAddressConfig, type GetTransactionsResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HPKE_ENC_LENGTH, HPKE_OVERHEAD_LENGTH, HpkeError, HpkeErrorCode, 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, RexValue, RexValueVariant, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SECRET_SHARING_HPKE_INFO, 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, USER_SECRET_AAD, type WorkflowLineage, type WorkflowNode, X25519_PUBLIC_KEY_LENGTH, allocateInstruction, assignInstruction, calculateBackoff, concatBytes, createAccount, createBorshInstruction, createRialoClient, deserialize, deserializeBorsh, deserializeCompactU16, deserializeStrict, encodeBorshData, encryptForRex, fromBase64, getCiphertextLength, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, hpkeEncrypt, isOnCurve, isValidCiphertextLength, seedToBytes, serialize, serializeBorsh, serializeCompactU16, sleep, toBase64, transferInstruction, writeCompactU16 };
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 };