ihm_client/pkg/sdk_client.d.ts

356 lines
12 KiB
TypeScript

/* tslint:disable */
/* eslint-disable */
export function setup(): void;
export function get_address(): string;
export function get_member(): Member;
export function restore_device(device: any): void;
export function create_device_from_sp_wallet(sp_wallet: string): string;
export function create_new_device(birthday: number, network_str: string): string;
export function is_paired(): boolean;
export function pair_device(process_id: string, sp_addresses: string[]): void;
export function unpair_device(): void;
export function dump_wallet(): string;
export function reset_process_cache(): void;
export function dump_process_cache(): string;
export function set_process_cache(processes: any): void;
export function add_to_process_cache(process_id: string, process: string): void;
export function reset_shared_secrets(): void;
export function set_shared_secrets(secrets: string): void;
export function get_pairing_process_id(): string;
export function dump_device(): Device;
export function dump_neutered_device(): Device;
export function reset_device(): void;
export function get_txid(transaction: string): string;
export function parse_new_tx(new_tx_msg: string, block_height: number, members_list: OutPointMemberMap): ApiReturn;
export function parse_cipher(cipher_msg: string, members_list: OutPointMemberMap): ApiReturn;
export function get_outputs(): any;
export function get_available_amount(): bigint;
/**
* We send a transaction that pays at least one output to each address
* The goal can be to establish a shared_secret to be used as an encryption key for further communication
* or if the recipient is a relay it can be the init transaction for a new process
*/
export function create_transaction(addresses: string[], fee_rate: number): ApiReturn;
export function sign_transaction(partial_tx: TsUnsignedTransaction): ApiReturn;
export function create_new_process(private_data: Pcd, roles: Roles, public_data: Pcd, relay_address: string, fee_rate: number, members_list: OutPointMemberMap): ApiReturn;
export function update_process(process: Process, new_attributes: Pcd, roles: Roles, new_public_data: Pcd, members_list: OutPointMemberMap): ApiReturn;
export function request_data(process_id: string, state_ids_str: string[], roles: any, members_list: OutPointMemberMap): ApiReturn;
export function create_update_message(process: Process, state_id: string, members_list: OutPointMemberMap): ApiReturn;
export function validate_state(process: Process, state_id: string, members_list: OutPointMemberMap): ApiReturn;
export function refuse_state(process: Process, state_id: string, members_list: OutPointMemberMap): ApiReturn;
export function evaluate_state(process: Process, state_id: string, members_list: OutPointMemberMap): ApiReturn;
export function create_response_prd(process: Process, state_id: string, members_list: OutPointMemberMap): ApiReturn;
export function create_faucet_msg(): string;
export function get_storages(process_outpoint: string): string[];
export function is_child_role(parent_roles: string, child_roles: string): void;
export function decrypt_data(key: Uint8Array, data: Uint8Array): Uint8Array;
export function encode_binary(data: any): Pcd;
export function encode_json(json_data: any): Pcd;
export function decode_value(value: Uint8Array): any;
export function hash_value(value: any, commited_in: string, label: string): string;
/**
* Generate a merkle proof for a specific attribute in a process state.
*
* This function creates a merkle proof that proves the existence of a specific attribute
* in a given state of a process. The proof can be used to verify that the attribute
* was indeed part of the state without revealing the entire state.
*
* # Arguments
* * `process_state` - The process state object as a JavaScript value
* * `attribute_name` - The name of the attribute to generate a proof for
*
* # Returns
* A MerkleProofResult object containing:
* * `proof` - The merkle proof as a hex string
* * `root` - The merkle root (state_id) as a hex string
* * `attribute` - The attribute name that was proven
* * `attribute_index` - The index of the attribute in the merkle tree
* * `total_leaves_count` - The total number of leaves in the merkle tree
*
* # Errors
* * "Failed to deserialize process state" - If the process state cannot be deserialized from JsValue
* * "Attribute not found in state" - If the attribute doesn't exist in the state
*/
export function get_merkle_proof(process_state: any, attribute_name: string): MerkleProofResult;
/**
* Validate a merkle proof for a specific attribute.
*
* This function verifies that a merkle proof is valid and proves the existence
* of a specific attribute in a given state. It checks that the proof correctly
* leads to the claimed root when combined with the attribute hash.
*
* # Arguments
* * `proof_result` - a JsValue expected to contain a MerkleProofResult with the proof and metadata
* * `hash` - The hash of the attribute data as a hex string (the leaf value)
*
* # Returns
* A boolean indicating whether the proof is valid
*
* # Errors
* * "serde_wasm_bindgen deserialization error" - If the proof is not a valid MerkleProofResult
* * "Invalid proof format" - If the proof cannot be parsed
* * "Invalid hash format" - If the hash is not a valid 32-byte hex string
* * "Invalid root format" - If the root is not a valid 32-byte hex string
*/
export function validate_merkle_proof(proof_result: any, hash: string): boolean;
export type DiffStatus = "None" | "Rejected" | "Validated";
export interface UserDiff {
process_id: string;
state_id: string;
value_commitment: string;
field: string;
roles: Roles;
description: string | null;
notify_user: boolean;
need_validation: boolean;
validation_status: DiffStatus;
}
export interface UpdatedProcess {
process_id: OutPoint;
current_process: Process;
diffs: UserDiff[];
encrypted_data: Record<string, string>;
validated_state: number[] | null;
}
export interface ApiReturn {
secrets: SecretsStore | null;
updated_process: UpdatedProcess | null;
new_tx_to_send: NewTxMessage | null;
ciphers_to_send: string[];
commit_to_send: CommitMessage | null;
push_to_storage: string[];
partial_tx: TsUnsignedTransaction | null;
}
export interface encryptWithNewKeyResult {
cipher: string;
key: string;
}
export interface MerkleProofResult {
proof: string;
root: string;
attribute: string;
attribute_index: number;
total_leaves_count: number;
}
export interface Device {
sp_wallet: SpWallet;
pairing_process_commitment: OutPoint | null;
paired_member: Member;
}
export interface Prd {
prd_type: PrdType;
process_id: OutPoint;
sender: Member;
keys: Record<string, number[]>;
pcd_commitments: PcdCommitments;
validation_tokens: Proof[];
roles: Roles;
public_data: Pcd;
payload: string;
proof: Proof | null;
}
export type PrdType = "None" | "Connect" | "Message" | "Update" | "List" | "Response" | "Confirm" | "TxProposal" | "Request";
/**
* Réponse de synchronisation
*/
export interface SyncResponse {
request_id: string;
relay_id: string;
success: boolean;
messages: SyncMessage[];
error: string | null;
}
/**
* Requête de synchronisation
*/
export interface SyncRequest {
request_id: string;
relay_id: string;
sync_types: SyncType[];
since_timestamp: number | null;
max_items: number | null;
}
/**
* Capacité d\'un relais
*/
export interface Capability {
name: string;
version: string;
enabled: boolean;
parameters: Record<string, string>;
}
/**
* Connexion mesh entre relais
*/
export interface MeshConnection {
from_relay: string;
to_relay: string;
latency: number;
bandwidth: number;
last_heartbeat: number;
}
/**
* Topologie du réseau
*/
export interface NetworkTopology {
total_relays: number;
connected_relays: number;
mesh_connections: MeshConnection[];
network_diameter: number;
avg_latency: number;
}
/**
* Statut de santé d\'un relais
*/
export type HealthStatus = "Healthy" | "Warning" | "Critical" | "Offline";
/**
* Informations sur un relais
*/
export interface RelayInfo {
relay_id: string;
address: string;
sp_address: string;
version: string;
uptime: number;
last_seen: number;
capabilities: string[];
health_status: HealthStatus;
}
/**
* Informations sur un pair
*/
export interface PeerInfo {
address: string;
sp_address: string;
connected_since: number;
last_activity: number;
message_count: number;
capabilities: string[];
}
/**
* Contenu des messages de synchronisation
*/
export type SyncPayload = { StateData: { chain_tip: number; wallet_balance: number; active_processes: number; connected_peers: number } } | { ProcessData: { processes: OutPointProcessMap; last_update: number } } | { MemberData: { members: OutPointMemberMap; last_update: number } } | { TransactionData: { txid: string; height: number | null; confirmed: boolean; sp_outputs: string[] } } | { BlockData: { height: number; hash: string; timestamp: number; tx_count: number } } | { PeerData: { peers: PeerInfo[]; last_seen: number } } | { RelayData: { relays: RelayInfo[]; network_topology: NetworkTopology } } | { HealthData: { uptime: number; memory_usage: number; cpu_usage: number; active_connections: number; last_block_time: number } } | { MetricsData: { messages_processed: number; transactions_broadcast: number; blocks_scanned: number; errors_count: number; avg_response_time: number } } | { ConfigData: { config_hash: string; features: string[]; version: string } } | { CapabilityData: { capabilities: Capability[]; supported_networks: string[] } };
/**
* Types de synchronisation
*/
export type SyncType = "StateSync" | "ProcessSync" | "MemberSync" | "TxSync" | "BlockSync" | "PeerSync" | "RelaySync" | "HealthSync" | "MetricsSync" | "ConfigSync" | "CapabilitySync";
/**
* Message de synchronisation pour le réseau mesh des relais
*/
export interface SyncMessage {
sync_type: SyncType;
relay_id: string;
timestamp: number;
sequence_number: number;
payload: SyncPayload;
signature: string | null;
}
export interface HandshakeMessage {
sp_address: string;
peers_list: OutPointMemberMap;
processes_list: OutPointProcessMap;
chain_tip: number;
}
export interface NewTxMessage {
transaction: string;
tweak_data: string | null;
error: AnkError | null;
}
export interface FaucetMessage {
sp_address: string;
commitment: string;
error: AnkError | null;
}
/**
* Message sent to the server to commit some state in a transaction
* Client must first send a commit message with empty validation_tokens
* Relay will ignore a commit message for an update he\'s not aware of that also bears validation_tokens
*/
export interface CommitMessage {
process_id: OutPoint;
pcd_commitment: PcdCommitments;
roles: Roles;
public_data: Pcd;
validation_tokens: Proof[];
error: AnkError | null;
}
export type AnkFlag = "NewTx" | "Faucet" | "Cipher" | "Commit" | "Handshake" | "Sync" | "Unknown";
export type OutPointProcessMap = Record<OutPoint, Process>;
export type OutPointMemberMap = Record<OutPoint, Member>;
/**
* A process is basically a succession of states
* The latest state MUST be an empty state with only the commited_in field set at the last unspent outpoint
* Commiting this last empty state in a transaction is called obliterating a process, basically terminating it
*/
export interface Process {
states: ProcessState[];
}
export interface ProcessState {
commited_in: OutPoint;
pcd_commitment: Record<string, string>;
state_id: string;
keys: Record<string, string>;
validation_tokens: Proof[];
public_data: Pcd;
roles: Record<string, RoleDefinition>;
}
export type TsUnsignedTransaction = SilentPaymentUnsignedTransaction;
export interface SecretsStore {
shared_secrets: Record<SilentPaymentAddress, AnkSharedSecretHash>;
unconfirmed_secrets: AnkSharedSecretHash[];
}
export type Roles = Record<string, RoleDefinition>;
export interface RoleDefinition {
members: OutPoint[];
validation_rules: ValidationRule[];
storages: string[];
}
export interface ValidationRule {
quorum: number;
fields: string[];
min_sig_member: number;
}
export type PcdCommitments = Record<string, string>;
export type Pcd = Record<string, number[]>;
export interface Member {
sp_addresses: string[];
}