@rialo/ts-cdk 0.5.0-alpha.0 → 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +355 -294
- package/dist/index.d.mts +166 -227
- package/dist/index.d.ts +166 -227
- package/dist/index.js +1463 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1455 -164
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.mts
CHANGED
|
@@ -730,129 +730,71 @@ declare class RialoError extends Error {
|
|
|
730
730
|
static serialization(message: string): RialoError;
|
|
731
731
|
}
|
|
732
732
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
/** Ciphertext is shorter than minimum required length */
|
|
740
|
-
CIPHERTEXT_TOO_SHORT = "CIPHERTEXT_TOO_SHORT",
|
|
741
|
-
/** HPKE encryption operation failed */
|
|
733
|
+
declare enum EncryptionErrorCode {
|
|
734
|
+
/** Input validation failed (empty secret, oversized secret, invalid key length) */
|
|
735
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
736
|
+
/** Threshold public key is not a valid compressed Ristretto255 point */
|
|
737
|
+
INVALID_THRESHOLD_KEY = "INVALID_THRESHOLD_KEY",
|
|
738
|
+
/** DKG encryption operation failed */
|
|
742
739
|
ENCRYPTION_FAILED = "ENCRYPTION_FAILED",
|
|
743
740
|
/** Failed to deserialize Borsh data */
|
|
744
741
|
BORSH_DESERIALIZE_FAILED = "BORSH_DESERIALIZE_FAILED",
|
|
745
742
|
/** RexValue has invalid variant byte */
|
|
746
743
|
INVALID_REX_VALUE = "INVALID_REX_VALUE"
|
|
747
744
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
*
|
|
751
|
-
* Provides detailed error information for encryption failures,
|
|
752
|
-
* including error codes and contextual details.
|
|
753
|
-
*/
|
|
754
|
-
declare class HpkeError extends Error {
|
|
755
|
-
readonly code: HpkeErrorCode;
|
|
745
|
+
declare class EncryptionError extends Error {
|
|
746
|
+
readonly code: EncryptionErrorCode;
|
|
756
747
|
readonly cause?: Error;
|
|
757
|
-
constructor(code:
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
* @param keyType - Description of the key type (e.g., "REX public key")
|
|
764
|
-
*/
|
|
765
|
-
static invalidKeyLength(expected: number, actual: number, keyType: string): HpkeError;
|
|
766
|
-
/**
|
|
767
|
-
* Create an error for ciphertext that is too short.
|
|
768
|
-
*
|
|
769
|
-
* @param minLength - Minimum required length
|
|
770
|
-
* @param actual - Actual length
|
|
771
|
-
*/
|
|
772
|
-
static ciphertextTooShort(minLength: number, actual: number): HpkeError;
|
|
773
|
-
/**
|
|
774
|
-
* Create an error for encryption failure.
|
|
775
|
-
*
|
|
776
|
-
* @param cause - The underlying error
|
|
777
|
-
*/
|
|
778
|
-
static encryptionFailed(cause: Error): HpkeError;
|
|
779
|
-
/**
|
|
780
|
-
* Create an error for Borsh deserialization failure.
|
|
781
|
-
*
|
|
782
|
-
* @param cause - The underlying error
|
|
783
|
-
*/
|
|
784
|
-
static borshDeserializeFailed(cause: Error): HpkeError;
|
|
785
|
-
/**
|
|
786
|
-
* Create an error for invalid RexValue variant.
|
|
787
|
-
*
|
|
788
|
-
* @param variant - The invalid variant byte
|
|
789
|
-
*/
|
|
790
|
-
static invalidRexValue(variant: number): HpkeError;
|
|
748
|
+
constructor(code: EncryptionErrorCode, message: string, cause?: Error);
|
|
749
|
+
static invalidInput(message: string): EncryptionError;
|
|
750
|
+
static invalidThresholdKey(cause: Error): EncryptionError;
|
|
751
|
+
static encryptionFailed(cause: Error): EncryptionError;
|
|
752
|
+
static borshDeserializeFailed(cause: Error): EncryptionError;
|
|
753
|
+
static invalidRexValue(variant: number): EncryptionError;
|
|
791
754
|
}
|
|
792
755
|
|
|
793
756
|
/**
|
|
794
|
-
* Constants for
|
|
757
|
+
* Constants for DKG threshold encryption.
|
|
795
758
|
*
|
|
796
759
|
* These constants MUST match the Rust implementation exactly:
|
|
797
|
-
* - `crates/tee/secret-sharing/src/
|
|
760
|
+
* - `crates/tee/secret-sharing/src/types.rs`
|
|
761
|
+
* - `developer-frameworks/cdk/rialo-rs-cdk/src/secret_encryption.rs`
|
|
798
762
|
*
|
|
799
763
|
* @module
|
|
800
764
|
*/
|
|
801
765
|
/**
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* This 13-byte string is prepended to the sender's public key to form
|
|
805
|
-
* the complete AAD for HPKE encryption. It provides domain separation
|
|
806
|
-
* to prevent cross-protocol attacks.
|
|
807
|
-
*
|
|
808
|
-
* Format: `USER_SECRET_AAD || senderPubkey` = 45 bytes total AAD
|
|
766
|
+
* Version byte prepended to every DKG threshold-encrypted payload stored in
|
|
767
|
+
* `RexValue::Encrypted`. Format: `[DKG_PAYLOAD_VERSION] || borsh(DkgEncryptedPayload)`.
|
|
809
768
|
*
|
|
810
|
-
*
|
|
811
|
-
* Must match Rust: `pub const USER_SECRET_AAD: &[u8] = b"rex-secret-v1";`
|
|
769
|
+
* Must match Rust: `pub const DKG_PAYLOAD_VERSION: u8 = 0x02`
|
|
812
770
|
*/
|
|
813
|
-
declare const
|
|
771
|
+
declare const DKG_PAYLOAD_VERSION = 2;
|
|
814
772
|
/**
|
|
815
|
-
*
|
|
773
|
+
* Maximum plaintext length accepted by `encryptSecretBytes` (64 KB).
|
|
816
774
|
*
|
|
817
|
-
*
|
|
818
|
-
* providing domain separation for secret sharing operations.
|
|
819
|
-
*
|
|
820
|
-
* @remarks
|
|
821
|
-
* Must match Rust: `pub const SECRET_SHARING_HPKE_INFO: &[u8; 32] = b"rialo/tee/secret-sharing-hpke/v1";`
|
|
775
|
+
* Must match Rust: `pub const MAX_SECRET_LENGTH: usize = 64 * 1024`
|
|
822
776
|
*/
|
|
823
|
-
declare const
|
|
777
|
+
declare const MAX_SECRET_LENGTH: number;
|
|
824
778
|
/**
|
|
825
|
-
* Length of
|
|
779
|
+
* Length of a compressed Ristretto255 point in bytes.
|
|
826
780
|
*
|
|
827
|
-
* Used for the
|
|
781
|
+
* Used for the DKG threshold public key and the ElGamal header point U.
|
|
828
782
|
*/
|
|
829
|
-
declare const
|
|
783
|
+
declare const RISTRETTO_POINT_BYTES = 32;
|
|
830
784
|
/**
|
|
831
785
|
* Length of an Ed25519 public key in bytes.
|
|
832
786
|
*
|
|
833
|
-
* Used for
|
|
787
|
+
* Used for the creator public key bound into the AAD.
|
|
834
788
|
*/
|
|
835
789
|
declare const ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
836
790
|
/**
|
|
837
|
-
* Length of the
|
|
838
|
-
*
|
|
839
|
-
* For X25519, this is always 32 bytes.
|
|
791
|
+
* Length of the ChaCha20-Poly1305 nonce in bytes.
|
|
840
792
|
*/
|
|
841
|
-
declare const
|
|
793
|
+
declare const CHACHA20_POLY1305_NONCE_LENGTH = 12;
|
|
842
794
|
/**
|
|
843
795
|
* Length of the ChaCha20-Poly1305 authentication tag in bytes.
|
|
844
796
|
*/
|
|
845
797
|
declare const CHACHA20_POLY1305_TAG_LENGTH = 16;
|
|
846
|
-
/**
|
|
847
|
-
* Total overhead added by HPKE encryption.
|
|
848
|
-
*
|
|
849
|
-
* This is the additional bytes beyond the plaintext:
|
|
850
|
-
* - enc (32 bytes): Encapsulated ephemeral public key
|
|
851
|
-
* - tag (16 bytes): ChaCha20-Poly1305 authentication tag
|
|
852
|
-
*
|
|
853
|
-
* Ciphertext length = plaintext length + 48 bytes
|
|
854
|
-
*/
|
|
855
|
-
declare const HPKE_OVERHEAD_LENGTH: number;
|
|
856
798
|
|
|
857
799
|
/**
|
|
858
800
|
* Variant discriminator for RexValue Borsh serialization.
|
|
@@ -886,7 +828,7 @@ declare enum RexValueVariant {
|
|
|
886
828
|
* // Plain value (unencrypted)
|
|
887
829
|
* const plain = RexValue.plain(new TextEncoder().encode("hello"));
|
|
888
830
|
*
|
|
889
|
-
* // Encrypted value (via
|
|
831
|
+
* // Encrypted value (via DKG threshold encryption)
|
|
890
832
|
* const encrypted = RexValue.encrypted(ciphertextBytes);
|
|
891
833
|
*
|
|
892
834
|
* // Serialize to Borsh
|
|
@@ -915,9 +857,9 @@ declare class RexValue {
|
|
|
915
857
|
*/
|
|
916
858
|
static plainString(s: string): RexValue;
|
|
917
859
|
/**
|
|
918
|
-
* Create an encrypted RexValue from
|
|
860
|
+
* Create an encrypted RexValue from a DKG threshold-encrypted payload.
|
|
919
861
|
*
|
|
920
|
-
* @param ciphertext - The
|
|
862
|
+
* @param ciphertext - The DKG-encrypted payload bytes (`[0x02] || borsh(DkgEncryptedPayload)`)
|
|
921
863
|
* @returns A new RexValue with Encrypted variant
|
|
922
864
|
*/
|
|
923
865
|
static encrypted(ciphertext: Uint8Array): RexValue;
|
|
@@ -959,112 +901,11 @@ declare class RexValue {
|
|
|
959
901
|
*
|
|
960
902
|
* @param data - The Borsh-serialized bytes
|
|
961
903
|
* @returns A new RexValue
|
|
962
|
-
* @throws {
|
|
904
|
+
* @throws {EncryptionError} If deserialization fails
|
|
963
905
|
*/
|
|
964
906
|
static fromBorsh(data: Uint8Array): RexValue;
|
|
965
907
|
}
|
|
966
908
|
|
|
967
|
-
/**
|
|
968
|
-
* Encrypt data using HPKE for REX secret sharing.
|
|
969
|
-
*
|
|
970
|
-
* This function performs HPKE encryption using the Base mode with:
|
|
971
|
-
* - X25519 for key encapsulation
|
|
972
|
-
* - HKDF-SHA256 for key derivation
|
|
973
|
-
* - ChaCha20-Poly1305 for authenticated encryption
|
|
974
|
-
*
|
|
975
|
-
* The output format is: `enc (32 bytes) || ciphertext || tag (16 bytes)`
|
|
976
|
-
*
|
|
977
|
-
* @param rexPubkey - The REX X25519 public key (32 bytes)
|
|
978
|
-
* @param data - The plaintext data to encrypt
|
|
979
|
-
* @param senderPubkey - The sender's Ed25519 public key (32 bytes) for AAD construction
|
|
980
|
-
* @returns The encrypted ciphertext including enc and tag
|
|
981
|
-
* @throws {HpkeError} If key lengths are invalid or encryption fails
|
|
982
|
-
*
|
|
983
|
-
* @example
|
|
984
|
-
* ```typescript
|
|
985
|
-
* const rexPubkey = await client.getSecretSharingPubkey();
|
|
986
|
-
* const ciphertext = await hpkeEncrypt(
|
|
987
|
-
* rexPubkey,
|
|
988
|
-
* new TextEncoder().encode("secret data"),
|
|
989
|
-
* keypair.publicKey.toBytes()
|
|
990
|
-
* );
|
|
991
|
-
* ```
|
|
992
|
-
*/
|
|
993
|
-
declare function hpkeEncrypt(rexPubkey: Uint8Array, data: Uint8Array, senderPubkey: Uint8Array): Promise<Uint8Array>;
|
|
994
|
-
/**
|
|
995
|
-
* Encrypt data for REX and wrap it in an RexValue.
|
|
996
|
-
*
|
|
997
|
-
* This is a convenience function that combines:
|
|
998
|
-
* 1. HPKE encryption using `hpkeEncrypt`
|
|
999
|
-
* 2. Wrapping the ciphertext in an `RexValue.encrypted`
|
|
1000
|
-
*
|
|
1001
|
-
* The resulting RexValue can be serialized to Borsh and sent to the network.
|
|
1002
|
-
*
|
|
1003
|
-
* @param rexPubkey - The REX X25519 public key (32 bytes)
|
|
1004
|
-
* @param data - The plaintext data to encrypt
|
|
1005
|
-
* @param senderPubkey - The sender's Ed25519 public key (32 bytes)
|
|
1006
|
-
* @returns An RexValue containing the encrypted ciphertext
|
|
1007
|
-
* @throws {HpkeError} If key lengths are invalid or encryption fails
|
|
1008
|
-
*
|
|
1009
|
-
* @example
|
|
1010
|
-
* ```typescript
|
|
1011
|
-
* import { RpcClient, Keypair } from "@rialo/ts-cdk";
|
|
1012
|
-
* import { encryptForRex, RexValue } from "@rialo/ts-cdk/rex";
|
|
1013
|
-
*
|
|
1014
|
-
* // Get REX public key from the network
|
|
1015
|
-
* const client = new RpcClient("https://rpc.rialo.xyz");
|
|
1016
|
-
* const rexPubkey = await client.getSecretSharingPubkey();
|
|
1017
|
-
*
|
|
1018
|
-
* // Create keypair for signing
|
|
1019
|
-
* const keypair = Keypair.generate();
|
|
1020
|
-
*
|
|
1021
|
-
* // Encrypt secret data
|
|
1022
|
-
* const rexValue = await encryptForRex(
|
|
1023
|
-
* rexPubkey,
|
|
1024
|
-
* new TextEncoder().encode("my secret API key"),
|
|
1025
|
-
* keypair.publicKey.toBytes()
|
|
1026
|
-
* );
|
|
1027
|
-
*
|
|
1028
|
-
* // The RexValue can now be serialized and used in transactions
|
|
1029
|
-
* const borshBytes = rexValue.toBorsh();
|
|
1030
|
-
* ```
|
|
1031
|
-
*/
|
|
1032
|
-
declare function encryptForRex(rexPubkey: Uint8Array, data: Uint8Array, senderPubkey: Uint8Array): Promise<RexValue>;
|
|
1033
|
-
/**
|
|
1034
|
-
* Calculate the expected ciphertext length for a given plaintext length.
|
|
1035
|
-
*
|
|
1036
|
-
* The ciphertext consists of:
|
|
1037
|
-
* - enc (32 bytes): Encapsulated ephemeral public key
|
|
1038
|
-
* - ciphertext (plaintext.length bytes): Encrypted data
|
|
1039
|
-
* - tag (16 bytes): ChaCha20-Poly1305 authentication tag
|
|
1040
|
-
*
|
|
1041
|
-
* @param plaintextLength - Length of the plaintext in bytes
|
|
1042
|
-
* @returns Expected ciphertext length
|
|
1043
|
-
*
|
|
1044
|
-
* @example
|
|
1045
|
-
* ```typescript
|
|
1046
|
-
* const ciphertextLen = getCiphertextLength(100);
|
|
1047
|
-
* console.log(ciphertextLen); // 148 (32 + 100 + 16)
|
|
1048
|
-
* ```
|
|
1049
|
-
*/
|
|
1050
|
-
declare function getCiphertextLength(plaintextLength: number): number;
|
|
1051
|
-
/**
|
|
1052
|
-
* Validate that a ciphertext has a valid length.
|
|
1053
|
-
*
|
|
1054
|
-
* A valid HPKE ciphertext must be at least 48 bytes (32 enc + 16 tag).
|
|
1055
|
-
*
|
|
1056
|
-
* @param ciphertext - The ciphertext to validate
|
|
1057
|
-
* @returns true if the ciphertext length is valid
|
|
1058
|
-
*
|
|
1059
|
-
* @example
|
|
1060
|
-
* ```typescript
|
|
1061
|
-
* if (!isValidCiphertextLength(ciphertext)) {
|
|
1062
|
-
* throw new Error("Ciphertext too short");
|
|
1063
|
-
* }
|
|
1064
|
-
* ```
|
|
1065
|
-
*/
|
|
1066
|
-
declare function isValidCiphertextLength(ciphertext: Uint8Array): boolean;
|
|
1067
|
-
|
|
1068
909
|
/** A 32-byte public key, base58-encoded on the wire. */
|
|
1069
910
|
|
|
1070
911
|
/** A 64-byte Ed25519 signature, base58-encoded on the wire. */
|
|
@@ -1103,6 +944,17 @@ interface CompiledInstruction$1 {
|
|
|
1103
944
|
/** Instruction data (base58-encoded on the wire). */
|
|
1104
945
|
data: string;
|
|
1105
946
|
}
|
|
947
|
+
/**
|
|
948
|
+
* An inner instruction produced by a cross-program invocation (CPI).
|
|
949
|
+
* Contains the index of the top-level instruction that triggered it
|
|
950
|
+
* and the compiled instruction itself.
|
|
951
|
+
*/
|
|
952
|
+
interface InnerInstruction {
|
|
953
|
+
/** Index of the top-level instruction that invoked this CPI. */
|
|
954
|
+
instructionIndex: number;
|
|
955
|
+
/** The compiled instruction produced by the CPI. */
|
|
956
|
+
instruction: CompiledInstruction$1;
|
|
957
|
+
}
|
|
1106
958
|
/**
|
|
1107
959
|
* Header of a transaction message.
|
|
1108
960
|
*/
|
|
@@ -1141,6 +993,12 @@ interface TransactionStatusMetadata {
|
|
|
1141
993
|
err?: string;
|
|
1142
994
|
/** Log messages emitted during execution (if available). */
|
|
1143
995
|
logMessages?: string[];
|
|
996
|
+
/** Inner instructions produced by cross-program invocations (CPIs).
|
|
997
|
+
Critical for decoding token transfers — most Token-2022 Transfer
|
|
998
|
+
instructions are CPIs, not top-level instructions. */
|
|
999
|
+
innerInstructions?: InnerInstruction[];
|
|
1000
|
+
/** Compute units consumed by this transaction. */
|
|
1001
|
+
computeUnitsConsumed?: bigint;
|
|
1144
1002
|
}
|
|
1145
1003
|
/**
|
|
1146
1004
|
* Full response for a transaction query.
|
|
@@ -1484,11 +1342,13 @@ interface ConnectedNode {
|
|
|
1484
1342
|
connectedMs: bigint;
|
|
1485
1343
|
}
|
|
1486
1344
|
/**
|
|
1487
|
-
* The
|
|
1345
|
+
* The active secret-sharing public key exposed by the network.
|
|
1488
1346
|
*/
|
|
1489
1347
|
interface SecretSharingPubkey {
|
|
1490
1348
|
/** Hex-encoded public key. */
|
|
1491
1349
|
publicKey: string;
|
|
1350
|
+
/** Active epoch for the threshold public key. */
|
|
1351
|
+
epoch: bigint;
|
|
1492
1352
|
}
|
|
1493
1353
|
/**
|
|
1494
1354
|
* Request to submit an epoch change (admin-only).
|
|
@@ -1499,8 +1359,14 @@ interface ValidatorInfoRequest {
|
|
|
1499
1359
|
stake: bigint;
|
|
1500
1360
|
/** Consensus network address (Multiaddr string). */
|
|
1501
1361
|
consensusAddress: string;
|
|
1502
|
-
/**
|
|
1503
|
-
|
|
1362
|
+
/** Subdag sync network address (Multiaddr string). */
|
|
1363
|
+
subdagSyncAddress: string;
|
|
1364
|
+
/** Long-lived network-service address for snapshot serving /
|
|
1365
|
+
state-sync (Multiaddr string, TCP, e.g.
|
|
1366
|
+
"/ip4/127.0.0.1/tcp/4300/http"). Stable across all epochs
|
|
1367
|
+
and expected to match the value the validator advertised
|
|
1368
|
+
at genesis. */
|
|
1369
|
+
networkServiceAddress: string;
|
|
1504
1370
|
/** Validator hostname. */
|
|
1505
1371
|
hostname: string;
|
|
1506
1372
|
/** Identity public key. */
|
|
@@ -1640,8 +1506,8 @@ interface ValidatorAccountInfo {
|
|
|
1640
1506
|
stake: bigint;
|
|
1641
1507
|
/** Network address for consensus communication. */
|
|
1642
1508
|
address: string;
|
|
1643
|
-
/** Network address for
|
|
1644
|
-
|
|
1509
|
+
/** Network address for consensus subdag synchronization. */
|
|
1510
|
+
subdagSyncAddress: string;
|
|
1645
1511
|
}
|
|
1646
1512
|
/**
|
|
1647
1513
|
* SPL Token account balance information.
|
|
@@ -1767,6 +1633,90 @@ interface ProgramInstruction {
|
|
|
1767
1633
|
data: Uint8Array;
|
|
1768
1634
|
}
|
|
1769
1635
|
|
|
1636
|
+
/**
|
|
1637
|
+
* Encrypt raw bytes using the DKG threshold public key.
|
|
1638
|
+
*
|
|
1639
|
+
* Low-level variant for callers that supply an explicit epoch and hex-encoded
|
|
1640
|
+
* threshold public key rather than a full `SecretSharingPubkey` struct.
|
|
1641
|
+
*
|
|
1642
|
+
* Uses ElGamal-style ECIES over Ristretto255 with HKDF-SHA256 key derivation
|
|
1643
|
+
* and ChaCha20-Poly1305 AEAD. The output format is:
|
|
1644
|
+
* `[0x02] || borsh(DkgEncryptedPayload)` — matching the Rust CDK exactly.
|
|
1645
|
+
*
|
|
1646
|
+
* @param plaintext - Raw bytes to encrypt (non-empty, max 64 KB)
|
|
1647
|
+
* @param creatorPubkey - Ed25519 public key (32 bytes) bound into the AAD
|
|
1648
|
+
* @param epoch - DKG epoch identifying the joint public key
|
|
1649
|
+
* @param thresholdPubkeyHex - Hex-encoded compressed Ristretto255 joint public key (32 bytes)
|
|
1650
|
+
* @throws {EncryptionError} On invalid inputs or encryption failure
|
|
1651
|
+
*/
|
|
1652
|
+
declare function encryptSecretBytesWithEpoch(plaintext: Uint8Array, creatorPubkey: Uint8Array, epoch: bigint, thresholdPubkeyHex: string): Uint8Array;
|
|
1653
|
+
/**
|
|
1654
|
+
* Encrypt raw bytes using the active DKG threshold public key.
|
|
1655
|
+
*
|
|
1656
|
+
* Accepts a `SecretSharingPubkey` (as returned by `getSecretSharingPubkey()`)
|
|
1657
|
+
* and produces a versioned `DkgEncryptedPayload` that the network can
|
|
1658
|
+
* threshold-decrypt during REX execution.
|
|
1659
|
+
*
|
|
1660
|
+
* @param plaintext - Raw bytes to encrypt (non-empty, max 64 KB)
|
|
1661
|
+
* @param creatorPubkey - Ed25519 public key (32 bytes) bound into the AAD
|
|
1662
|
+
* @param secretSharingPubkey - Active threshold key metadata from RPC
|
|
1663
|
+
* @throws {EncryptionError} On invalid inputs or encryption failure
|
|
1664
|
+
*
|
|
1665
|
+
* @example
|
|
1666
|
+
* ```typescript
|
|
1667
|
+
* const { publicKey, epoch } = await client.getSecretSharingPubkey();
|
|
1668
|
+
* const payload = encryptSecretBytes(
|
|
1669
|
+
* new TextEncoder().encode("my-api-key"),
|
|
1670
|
+
* keypair.publicKey.toBytes(),
|
|
1671
|
+
* { publicKey, epoch },
|
|
1672
|
+
* );
|
|
1673
|
+
* const rexValue = RexValue.encrypted(payload);
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
declare function encryptSecretBytes(plaintext: Uint8Array, creatorPubkey: Uint8Array, secretSharingPubkey: SecretSharingPubkey): Uint8Array;
|
|
1677
|
+
/**
|
|
1678
|
+
* Encrypt a UTF-8 string using the active DKG threshold public key.
|
|
1679
|
+
*
|
|
1680
|
+
* Convenience wrapper around `encryptSecretBytes` for string secrets.
|
|
1681
|
+
*
|
|
1682
|
+
* @param secret - The plaintext string to encrypt (non-empty, max 64 KB)
|
|
1683
|
+
* @param creatorPubkey - Ed25519 public key (32 bytes)
|
|
1684
|
+
* @param secretSharingPubkey - Active threshold key metadata from RPC
|
|
1685
|
+
* @throws {EncryptionError} On invalid inputs or encryption failure
|
|
1686
|
+
*
|
|
1687
|
+
* @example
|
|
1688
|
+
* ```typescript
|
|
1689
|
+
* const payload = encryptSecret(
|
|
1690
|
+
* "Bearer sk-1234567890abcdef",
|
|
1691
|
+
* keypair.publicKey.toBytes(),
|
|
1692
|
+
* await client.getSecretSharingPubkey(),
|
|
1693
|
+
* );
|
|
1694
|
+
* ```
|
|
1695
|
+
*/
|
|
1696
|
+
declare function encryptSecret(secret: string, creatorPubkey: Uint8Array, secretSharingPubkey: SecretSharingPubkey): Uint8Array;
|
|
1697
|
+
/**
|
|
1698
|
+
* Encrypt raw bytes for REX and wrap the result in a `RexValue`.
|
|
1699
|
+
*
|
|
1700
|
+
* Combines `encryptSecretBytes` with `RexValue.encrypted`. The resulting
|
|
1701
|
+
* `RexValue` can be serialized to Borsh and included in transactions.
|
|
1702
|
+
*
|
|
1703
|
+
* @param plaintext - Raw bytes to encrypt
|
|
1704
|
+
* @param creatorPubkey - Ed25519 public key (32 bytes)
|
|
1705
|
+
* @param secretSharingPubkey - Active threshold key metadata from RPC
|
|
1706
|
+
* @throws {EncryptionError} On invalid inputs or encryption failure
|
|
1707
|
+
*
|
|
1708
|
+
* @example
|
|
1709
|
+
* ```typescript
|
|
1710
|
+
* const rexValue = encryptForRex(
|
|
1711
|
+
* new TextEncoder().encode("my secret"),
|
|
1712
|
+
* keypair.publicKey.toBytes(),
|
|
1713
|
+
* await client.getSecretSharingPubkey(),
|
|
1714
|
+
* );
|
|
1715
|
+
* const borshBytes = rexValue.toBorsh();
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
declare function encryptForRex(plaintext: Uint8Array, creatorPubkey: Uint8Array, secretSharingPubkey: SecretSharingPubkey): RexValue;
|
|
1719
|
+
|
|
1770
1720
|
/**
|
|
1771
1721
|
* Base client with JSON-RPC protocol handling.
|
|
1772
1722
|
*
|
|
@@ -2162,19 +2112,19 @@ declare abstract class RpcClient {
|
|
|
2162
2112
|
*/
|
|
2163
2113
|
abstract getConnectedFullNodes(): Promise<ConnectedNode[]>;
|
|
2164
2114
|
/**
|
|
2165
|
-
* Gets the
|
|
2115
|
+
* Gets the active threshold public key used for secret sharing.
|
|
2166
2116
|
*
|
|
2167
|
-
* This public key is used to
|
|
2168
|
-
* can decrypt.
|
|
2117
|
+
* This public key is used to create threshold-encrypted payloads that
|
|
2118
|
+
* the crypto-service committee can decrypt.
|
|
2169
2119
|
*
|
|
2170
2120
|
* # Returns
|
|
2171
2121
|
*
|
|
2172
|
-
* The
|
|
2122
|
+
* The active threshold public key (hex-encoded) plus epoch metadata.
|
|
2173
2123
|
*
|
|
2174
2124
|
* # Errors
|
|
2175
2125
|
*
|
|
2176
|
-
* Returns an error if the RPC call fails
|
|
2177
|
-
*
|
|
2126
|
+
* Returns an error if the RPC call fails or no active threshold public key
|
|
2127
|
+
* has been finalized yet.
|
|
2178
2128
|
*/
|
|
2179
2129
|
abstract getSecretSharingPubkey(): Promise<SecretSharingPubkey>;
|
|
2180
2130
|
/**
|
|
@@ -2688,7 +2638,7 @@ declare class RialoClient extends RpcClient {
|
|
|
2688
2638
|
*/
|
|
2689
2639
|
getConnectedFullNodes(): Promise<ConnectedNode[]>;
|
|
2690
2640
|
/**
|
|
2691
|
-
* Gets the
|
|
2641
|
+
* Gets the active secret-sharing public key metadata.
|
|
2692
2642
|
*/
|
|
2693
2643
|
getSecretSharingPubkey(): Promise<SecretSharingPubkey>;
|
|
2694
2644
|
/**
|
|
@@ -3024,29 +2974,18 @@ declare class QueryRpcClient extends BaseRpcClient {
|
|
|
3024
2974
|
*/
|
|
3025
2975
|
getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
|
|
3026
2976
|
/**
|
|
3027
|
-
* Retrieve the
|
|
2977
|
+
* Retrieve the active threshold public key metadata.
|
|
3028
2978
|
*
|
|
3029
|
-
*
|
|
3030
|
-
*
|
|
3031
|
-
*
|
|
3032
|
-
*
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
*
|
|
3037
|
-
*
|
|
3038
|
-
* // Get the REX public key
|
|
3039
|
-
* const rexPubkey = await client.getSecretSharingPubkey();
|
|
3040
|
-
*
|
|
3041
|
-
* // Use it for HPKE encryption
|
|
3042
|
-
* const encrypted = await encryptForRex(
|
|
3043
|
-
* rexPubkey,
|
|
3044
|
-
* new TextEncoder().encode("secret data"),
|
|
3045
|
-
* keypair.publicKey.toBytes()
|
|
3046
|
-
* );
|
|
3047
|
-
* ```
|
|
2979
|
+
* Returns the active threshold public key (a compressed Ristretto point) and
|
|
2980
|
+
* its DKG epoch. Pass the result directly to `encryptSecretBytes`,
|
|
2981
|
+
* `encryptSecret`, or `encryptForRex` to produce a threshold-encrypted
|
|
2982
|
+
* `DkgEncryptedPayload` the network can decrypt during REX execution.
|
|
2983
|
+
*/
|
|
2984
|
+
getSecretSharingPubkey(): Promise<SecretSharingPubkey>;
|
|
2985
|
+
/**
|
|
2986
|
+
* @deprecated Use `getSecretSharingPubkey()` instead.
|
|
3048
2987
|
*/
|
|
3049
|
-
|
|
2988
|
+
getSecretSharingPubkeyInfo(): Promise<SecretSharingPubkey>;
|
|
3050
2989
|
/**
|
|
3051
2990
|
* Get the config hash prefix for replay protection.
|
|
3052
2991
|
*
|
|
@@ -4900,4 +4839,4 @@ declare function deployInstruction(programAddress: PublicKey, authority: PublicK
|
|
|
4900
4839
|
*/
|
|
4901
4840
|
declare function retractInstruction(programAddress: PublicKey, authority: PublicKey): Instruction;
|
|
4902
4841
|
|
|
4903
|
-
export { type AccountFilter, type AccountFilterParam, type AccountInfo, type AccountMeta, AccountMetaTable, type AllAccountsEntry, BASE_DERIVATION_PATH, BUFFER_BALANCE_FACTOR, BaseRpcClient, BincodeReader, type BincodeSchema, BincodeWriter, type BlockInfo, type Bump, CHACHA20_POLY1305_TAG_LENGTH, type ChainDefinition, type ClusterNodeInfo, type CompiledInstruction, type ConfigHashPrefix, type ConfirmTransactionOptions, type ConfirmedTransaction, type ConnectedNode, CryptoError, CryptoErrorCode, DEFAULT_CHUNK_SIZE, DEFAULT_CONFIRMATION_BATCH_SIZE, DEFAULT_MAX_RETRIES, DEFAULT_NUM_ACCOUNTS, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, type DeploymentConfig, DeploymentError, DeploymentErrorCode, type DerivedKeypairInfo, ED25519_PUBLIC_KEY_LENGTH, type EnumVariant, type EpochConsensusConfigRequest, type EpochInfo, type EventData, type FeeResponse, type DeploymentConfig$1 as GeneratedDeploymentConfig, type GetAccountsByOwnerConfig, type GetAllAccountsConfig, type GetBlockConfig, type GetSignaturesForAddressConfig, type GetTransactionsConfig, type GetValidatorAccountsRequest, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse,
|
|
4842
|
+
export { type AccountFilter, type AccountFilterParam, type AccountInfo, type AccountMeta, AccountMetaTable, type AllAccountsEntry, BASE_DERIVATION_PATH, BUFFER_BALANCE_FACTOR, BaseRpcClient, BincodeReader, type BincodeSchema, BincodeWriter, type BlockInfo, type Bump, CHACHA20_POLY1305_NONCE_LENGTH, CHACHA20_POLY1305_TAG_LENGTH, type ChainDefinition, type ClusterNodeInfo, type CompiledInstruction, type ConfigHashPrefix, type ConfirmTransactionOptions, type ConfirmedTransaction, type ConnectedNode, CryptoError, CryptoErrorCode, DEFAULT_CHUNK_SIZE, DEFAULT_CONFIRMATION_BATCH_SIZE, DEFAULT_MAX_RETRIES, DEFAULT_NUM_ACCOUNTS, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DKG_PAYLOAD_VERSION, type DeploymentConfig, DeploymentError, DeploymentErrorCode, type DerivedKeypairInfo, ED25519_PUBLIC_KEY_LENGTH, EncryptionError, EncryptionErrorCode, type EnumVariant, type EpochConsensusConfigRequest, type EpochInfo, type EventData, type FeeResponse, type DeploymentConfig$1 as GeneratedDeploymentConfig, type GetAccountsByOwnerConfig, type GetAllAccountsConfig, type GetBlockConfig, type GetSignaturesForAddressConfig, type GetTransactionsConfig, type GetValidatorAccountsRequest, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, InMemoryKeyringProvider, type InferSchema, type Instruction, type InvocationAccountMeta, type IsBlockhashValidResponse, KELVIN_PER_RLO, type Kelvin, Keypair, KeypairSigner, Keyring, KeyringProvider, LOADER_V4_PROGRAM_ID, type LoaderType, MAX_SECRET_LENGTH, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type OptionalAccountInfo, type OwnerAccount, type PDA, PROGRAM_DATA_OFFSET, PUBLIC_KEY_LENGTH, type PaginationInfo, ProgramDeployment, type ProgramDeploymentOptions, type ProgramInstruction, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_TESTNET_CHAIN, RISCV_LOADER_PROGRAM_ID, RISTRETTO_POINT_BYTES, type RexDuty, type RexInfoAndDuties, RexValue, RexValueVariant, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, RialoKeyring, type RialoNetwork, RiscVLoaderInstruction, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, Schema, type SecretSharingPubkey, type Seed, type SendAndConfirmOptions, type SendTransactionOptions, Signature$1 as Signature, type SignatureInfo, type SignatureStatus, type Signer, type StakeAccountInfo, type StakeState, type StructField, type SubmitEpochChangeRequest, type SubmitEpochChangeResponse, type Subscription, type SubscriptionAccountMeta, type SubscriptionInstruction, type SubscriptionKind, SystemInstruction, type TimestampRange, type TokenBalance, Transaction, TransactionBuilder, type TransactionData, TransactionError, TransactionErrorCode, type TransactionInfo, type TransactionMessage, type TransactionNodeData, type TransactionResponse, TransactionRpcClient, type TransactionStatusMetadata, type TransactionWithMeta, type TriggerInfo, type TriggeredTransaction, type TruncationReason, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_TESTNET, type ValidatorAccountInfo, type ValidatorHealth, type ValidatorInfoRequest, type WorkflowLineage, type WorkflowNode, allocateInstruction, assignInstruction, calculateBackoff, concatBytes, createAccount, createBorshInstruction, createRialoClient, deployInstruction, deserialize, deserializeBorsh, deserializeCompactU16, deserializeStrict, encodeBorshData, encryptForRex, encryptSecret, encryptSecretBytes, encryptSecretBytesWithEpoch, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, isOnCurve, retractInstruction, seedToBytes, serialize, serializeBorsh, serializeCompactU16, setProgramLengthInstruction, sleep, toBase64, transferInstruction, writeCompactU16, writeInstruction };
|