Sergio Chouhy 08feadbdf7 update
2026-06-29 10:10:38 -03:00

325 lines
12 KiB
C

// Stub header for wallet_ffi — provides the same declarations as the real
// lssa-generated header so that logos_execution_zone_wallet_module sources
// compile in unit tests (the real library is NOT linked; mocks supply symbols).
//
// Only the subset of the FFI surface used by the module is declared here.
#ifndef WALLET_FFI_H
#define WALLET_FFI_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// Error codes returned by most wallet_ffi_* functions (0 == SUCCESS).
typedef enum WalletFfiError {
SUCCESS = 0,
INTERNAL_ERROR = 1,
INVALID_INPUT = 2,
NOT_FOUND = 3,
} WalletFfiError;
// Opaque wallet handle.
typedef struct WalletHandle WalletHandle;
// 32-byte value (account id, key, hash).
typedef struct FfiBytes32 {
uint8_t data[32];
} FfiBytes32;
// Program ID - 8 u32 values (32 bytes total).
typedef struct FfiProgramId {
uint32_t data[8];
} FfiProgramId;
// 16-byte value (balance / nonce, little-endian u128).
typedef struct FfiBytes16 {
uint8_t data[16];
} FfiBytes16;
// 16-byte little-endian u128 (e.g. a private account identifier).
typedef struct FfiU128 {
uint8_t data[16];
} FfiU128;
// Full account record.
typedef struct FfiAccount {
FfiProgramId program_owner;
FfiBytes16 balance;
FfiBytes16 nonce;
uint8_t* data;
uintptr_t data_len;
} FfiAccount;
// One entry in a listing of accounts.
typedef struct FfiAccountListEntry {
FfiBytes32 account_id;
bool is_public;
} FfiAccountListEntry;
// A list of accounts (heap-owned by the library).
typedef struct FfiAccountList {
FfiAccountListEntry* entries;
uintptr_t count;
} FfiAccountList;
// Public account key.
typedef struct FfiPublicAccountKey {
FfiBytes32 public_key;
} FfiPublicAccountKey;
// Private account keys (viewing key is heap-owned).
typedef struct FfiPrivateAccountKeys {
FfiBytes32 nullifier_public_key;
uint8_t* viewing_public_key;
uintptr_t viewing_public_key_len;
} FfiPrivateAccountKeys;
// Result of a transfer / claim / register operation.
typedef struct FfiTransferResult {
bool success;
char* tx_hash;
} FfiTransferResult;
/**
* Enumeration to represent kinds of `FfiAccountIdentity`.
*/
typedef enum FfiAccountIdentityKind {
PUBLIC = 0,
PUBLIC_NO_SIGN = 1,
PUBLIC_KEYCARD = 2,
PRIVATE_OWNED = 3,
PRIVATE_FOREIGN = 4,
PRIVATE_PDA_OWNED = 5,
PRIVATE_PDA_FOREIGN = 6,
PRIVATE_SHARED = 7,
PRIVATE_PDA_SHARED = 8,
} FfiAccountIdentityKind;
typedef struct FfiInstructionWords {
uint32_t *instruction_words;
uintptr_t instruction_words_size;
enum WalletFfiError error;
} FfiInstructionWords;
/**
* Struct representing an account identity, given to `AccountManager` at intialization.
*/
typedef struct FfiAccountIdentity {
enum FfiAccountIdentityKind kind;
struct FfiBytes32 account_id;
/**
* C-compatible string.
*/
char *key_path;
struct FfiBytes32 nullifier_secret_key;
struct FfiBytes32 nullifier_public_key;
const uint8_t *viewing_public_key;
uintptr_t viewing_public_key_len;
struct FfiU128 identifier;
} FfiAccountIdentity;
/**
* Intended to be created manually.
*/
typedef struct FfiProgram {
const uint8_t *elf_data;
uintptr_t elf_size;
} FfiProgram;
/**
* Intended to be created manually.
*/
typedef struct FfiProgramWithDependencies {
struct FfiProgram program;
const struct FfiProgram *deps;
uintptr_t deps_size;
} FfiProgramWithDependencies;
/**
* Result of a generic transaction operation.
*/
typedef struct FfiTransactionResult {
/**
* Transaction hash (null-terminated string, or null on failure).
*/
char *tx_hash;
/**
* Whether the transaction succeeded.
*/
bool success;
const struct FfiBytes32 *secrets_data;
/**
* Public transactions have 0 secrets.
*/
uintptr_t secrets_size;
} FfiTransactionResult;
typedef struct FfiCreateWalletOutput {
struct WalletHandle *wallet;
/**
* C compatible(null terminated) string.
*/
char *mnemonic;
} FfiCreateWalletOutput;
// === Lifecycle ===
FfiCreateWalletOutput wallet_ffi_create_new(const char* config_path, const char* storage_path, const char* password);
WalletHandle* wallet_ffi_open(const char* config_path, const char* storage_path);
int wallet_ffi_save(WalletHandle* handle);
void wallet_ffi_destroy(WalletHandle* handle);
WalletFfiError wallet_ffi_restore_data(WalletHandle *handle, const char *mnemonic, const char *password, uint32_t depth);
// === Account management ===
WalletFfiError wallet_ffi_create_account_public(WalletHandle* handle, FfiBytes32* out_id);
WalletFfiError wallet_ffi_create_account_private(WalletHandle* handle, FfiBytes32* out_id);
WalletFfiError wallet_ffi_list_accounts(WalletHandle* handle, FfiAccountList* out_list);
void wallet_ffi_free_account_list(FfiAccountList* list);
// === Account queries ===
WalletFfiError wallet_ffi_get_balance(WalletHandle* handle, const FfiBytes32* account_id, bool is_public, uint8_t (*out_balance)[16]);
WalletFfiError wallet_ffi_get_account_public(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account);
WalletFfiError wallet_ffi_get_account_private(WalletHandle* handle, const FfiBytes32* account_id, FfiAccount* out_account);
void wallet_ffi_free_account_data(FfiAccount* account);
WalletFfiError wallet_ffi_get_public_account_key(WalletHandle* handle, const FfiBytes32* account_id, FfiPublicAccountKey* out_key);
WalletFfiError wallet_ffi_get_private_account_keys(WalletHandle* handle, const FfiBytes32* account_id, FfiPrivateAccountKeys* out_keys);
void wallet_ffi_free_private_account_keys(FfiPrivateAccountKeys* keys);
// === Account encoding ===
char* wallet_ffi_account_id_to_base58(const FfiBytes32* account_id);
WalletFfiError wallet_ffi_account_id_from_base58(const char* base58, FfiBytes32* out_id);
void wallet_ffi_free_string(char* s);
// === Blockchain synchronisation ===
int wallet_ffi_sync_to_block(WalletHandle* handle, uint64_t block_id);
WalletFfiError wallet_ffi_get_last_synced_block(WalletHandle* handle, uint64_t* out_block_id);
WalletFfiError wallet_ffi_get_current_block_height(WalletHandle* handle, uint64_t* out_block_height);
// === Pinata claiming ===
WalletFfiError wallet_ffi_claim_pinata(
WalletHandle* handle,
const FfiBytes32* pinata_account_id,
const FfiBytes32* winner_account_id,
const uint8_t (*solution)[16],
FfiTransferResult* out_result);
WalletFfiError wallet_ffi_claim_pinata_private_owned_already_initialized(
WalletHandle* handle,
const FfiBytes32* pinata_account_id,
const FfiBytes32* winner_account_id,
const uint8_t (*solution)[16],
uintptr_t winner_proof_index,
const uint8_t (*winner_proof_siblings)[32],
uintptr_t winner_proof_siblings_len,
FfiTransferResult* out_result);
WalletFfiError wallet_ffi_claim_pinata_private_owned_not_initialized(
WalletHandle* handle,
const FfiBytes32* pinata_account_id,
const FfiBytes32* winner_account_id,
const uint8_t (*solution)[16],
FfiTransferResult* out_result);
// === Transfers / registration ===
WalletFfiError wallet_ffi_transfer_public(
WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to,
const uint8_t (*amount)[16], FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_shielded(
WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys,
const FfiU128 *to_identifier,
const uint8_t (*amount)[16],
const char *key_path,
FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_deshielded(
WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to,
const uint8_t (*amount)[16], FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_private(
WalletHandle* handle, const FfiBytes32* from, const FfiPrivateAccountKeys* to_keys,
const FfiU128 *to_identifier,
const uint8_t (*amount)[16], FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_shielded_owned(
WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to,
const uint8_t (*amount)[16],
const char *key_path,
FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_private_owned(
WalletHandle* handle, const FfiBytes32* from, const FfiBytes32* to,
const uint8_t (*amount)[16], FfiTransferResult* out_result);
WalletFfiError wallet_ffi_register_public_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result);
WalletFfiError wallet_ffi_register_private_account(WalletHandle* handle, const FfiBytes32* account_id, FfiTransferResult* out_result);
WalletFfiError wallet_ffi_transfer_elf(FfiProgram *ffi_program);
WalletFfiError wallet_ffi_token_elf(FfiProgram *ffi_program);
WalletFfiError wallet_ffi_ata_elf(FfiProgram *ffi_program);
WalletFfiError wallet_ffi_amm_elf(FfiProgram *ffi_program);
WalletFfiError wallet_ffi_send_generic_public_transaction(WalletHandle *handle,
const FfiAccountIdentity *account_identities,
uintptr_t account_identities_size,
const uint32_t *instruction_words,
uintptr_t instruction_words_size,
FfiProgramId program_id,
FfiTransactionResult *out_result);
WalletFfiError wallet_ffi_send_generic_private_transaction(WalletHandle *handle,
const FfiAccountIdentity *account_identities,
uintptr_t account_identities_size,
const uint32_t *instruction_words,
uintptr_t instruction_words_size,
const FfiProgramWithDependencies *program_with_dependencies,
FfiTransactionResult *out_result);
WalletFfiError wallet_ffi_program_deployment(WalletHandle *handle,
const uint8_t *elf_data,
uintptr_t elf_size,
FfiTransactionResult *out_result);
WalletFfiError wallet_ffi_resolve_public_account(FfiBytes32 account_id,
bool needs_sign,
FfiAccountIdentity *out_account_identity);
WalletFfiError wallet_ffi_resolve_private_account(WalletHandle *handle,
FfiBytes32 account_id,
FfiAccountIdentity *out_account_identity);
void wallet_ffi_free_instruction_words(FfiInstructionWords *words);
void wallet_ffi_free_account_identity(FfiAccountIdentity *account_identity);
void wallet_ffi_free_transfer_result(FfiTransferResult* result);
void wallet_ffi_free_transaction_result(FfiTransactionResult *result);
void wallet_ffi_free_ffi_program(FfiProgram *ffi_program);
// === Bridge (L1 Bedrock <-> L2) ===
WalletFfiError wallet_ffi_bridge_withdraw(
WalletHandle* handle, const FfiBytes32* from, uint64_t amount,
const FfiBytes32* bedrock_account_pk, FfiTransferResult* out_result);
// === Vault claiming ===
WalletFfiError wallet_ffi_get_vault_balance(WalletHandle* handle, const FfiBytes32* owner, uint8_t (*out_balance)[16]);
WalletFfiError wallet_ffi_vault_claim(
WalletHandle* handle, const FfiBytes32* owner, const uint8_t (*amount)[16], FfiTransferResult* out_result);
WalletFfiError wallet_ffi_vault_claim_private(
WalletHandle* handle, const FfiBytes32* owner, const uint8_t (*amount)[16], FfiTransferResult* out_result);
// === Configuration ===
char* wallet_ffi_get_sequencer_addr(WalletHandle* handle);
#ifdef __cplusplus
}
#endif
#endif // WALLET_FFI_H