14typedef enum { LX_IDLE, LX_AWAITING_REQ, LX_AWAITING_VAL, LX_AWAITING_ACK }
litex_state;
17enum { LX_OK = 0, LX_ERR_STATE = -1, LX_DECLINED = -2, LX_BAD_SIG = -3 };
41 const char *ac1,
const char *payee_id,
const char *payee_seq,
const char *ac2,
42 char *out,
size_t cap);
102 char *out_json,
size_t cap);
The injected runtime environment (crypto, keystore, store, clock, RNG) the wallet runs against.
int litex_assert_identity(litex_purse *p, const litex_identity *id, const char *remote_challenge, char *out_json, size_t cap)
Asserts this purse's identity, signing the fields + remote_challenge; writes an identity doc....
int litex_start_debit(litex_purse *p, const litex_xfer *x)
Payer: IDLE -> AWAITING_REQ; declines on insufficient balance (PVR bit 7,8). Fills txn_id....
void litex_pvr_hex(const litex_pvr *p, char out[17])
Writes the 16-char lowercase-hex rendering of the PVR into out (17 bytes incl. NUL).
litex_state
Offline-purse state-machine states.
Definition litex.h:14
int litex_verify_pub(lite_env *env, const char *pub_b64, const char *data, const char *sig_b64)
Verifies a base64 ECDSA-SHA256 signature over data with the base64 SPKI pub_b64. 1/0/<0.
int litex_acknowledge_value(litex_purse *p, const char *reqs, const char *tras, const char *acks)
Payer: AWAITING_ACK -> IDLE; verifies ACKS over payload+REQS+TRAS. LX_OK/LX_BAD_SIG/LX_ERR_STATE.
int litex_transfer_value(litex_purse *p, const char *reqs, const char *tras, char *acks_out, size_t cap)
Payee: AWAITING_VAL -> IDLE; verifies TRAS over payload+REQS, signs ACKS into acks_out....
int litex_request_value(litex_purse *p, const char *reqs, char *tras_out, size_t cap)
Payer: AWAITING_REQ -> AWAITING_ACK; verifies REQS, signs TRAS into tras_out. LX_OK/LX_BAD_SIG/LX_ERR...
long litex_txn_id(const lite_crypto *c, const char *payer_id, const char *payer_seq, const char *ac1, const char *payee_id, const char *payee_seq, const char *ac2, char *out, size_t cap)
txnId = hex(SHA1(payerId.payerSeq.ac1.payeeId.payeeSeq.ac2))[0:35]. Returns 35 or -1.
int litex_pac_applies(uint8_t code, int is_debit)
Purse-action-code predicate: the code's top two bits select applicability to debit/credit.
double litex_counter_update(uint8_t code, double cur, double amount)
Counter step: bit5 of code selects increment-by-one (0) vs add-amount (1). Returns the new value.
void litex_pvr_set(litex_pvr *p, int index, int bit, int on)
Sets (on!=0) or clears bit bit (1..8) of byte index (1..8).
long litex_get_purse_info(litex_purse *p, double balance, char *challenge_out, size_t cap)
Bootstrap: generate the LOCAC challenge, record balance, arm the purse. Writes challenge hex; length ...
int litex_purse_start(litex_purse *p, lite_env *env, const char *alias, double balance)
Initializes a purse with its alias and balance, generating its offline key. 0 on success.
int litex_verify_identity(litex_purse *p, const char *remote_json, const char *our_challenge)
Verifies a remote identity doc against our_challenge; on success adopts its key as remote_pub....
long litex_offline_pubkey(lite_env *env, const char *alias, char *out_b64, size_t cap)
Exports the offline EC public key (alias + "-OFFLINE") as base64 SPKI. Length or -1.
int litex_start_credit(litex_purse *p, const litex_xfer *x, char *reqs_out, size_t cap)
Payee: IDLE -> AWAITING_VAL; signs REQS over the payload into reqs_out. Fills txn_id....
int litex_enable(lite_env *env, const char *alias)
Generates the offline EC key (alias + "-OFFLINE") used to sign transfer values. 0 on success.
int lite_pvr_get(const litex_pvr *p, int index, int bit)
Returns bit bit of byte index (0/1).
int litex_verify(lite_env *env, const char *alias, const char *data, const char *sig_b64)
Verifies a base64 ECDSA-SHA256 signature over data with this purse's own offline key....
void litex_purse_set_remote(litex_purse *p, const char *remote_pub_b64)
Sets the counterparty's offline public key (base64 SPKI) for verification.
void litex_pvr_init(litex_pvr *p)
Clears all PVR bits.
long litex_sign(lite_env *env, const char *alias, const char *data, char *out_b64, size_t cap)
Signs data with the offline EC key (ECDSA-SHA256); writes base64 signature. Length or -1.
Vtable of stateless crypto primitives; obtain a concrete one from lite_crypto_openssl().
Definition crypto.h:12
Everything the wallet needs, injected so tests can pin the clock, RNG and keys.
Definition env.h:26
Purse identity fields (assert/verifyIdentity).
Definition litex.h:88
const char * product
Product type (PPT).
Definition litex.h:90
const char * country
Country (PCOU).
Definition litex.h:92
const char * type
Purse type (PT).
Definition litex.h:93
const char * id
Purse id (PID).
Definition litex.h:89
const char * mcc
Merchant category code (PMCC), or NULL.
Definition litex.h:94
const char * currency
Currency (PCUR).
Definition litex.h:91
A purse party in the offline transfer handshake.
Definition litex.h:71
double balance
Spendable offline balance.
Definition litex.h:76
litex_state state
Current handshake state.
Definition litex.h:75
lite_env * env
Runtime environment.
Definition litex.h:72
8-byte Purse Verification Result bitmap. Index/bit are 1-based, as in the CL's setPVR.
Definition litex.h:20
One leg of an offline P2P transfer. Field order matches the CL's generateSignaturePayload.
Definition litex.h:58
const char * payee_id
Payee purse id.
Definition litex.h:62
const char * payee_vpa
Payee VPA/address.
Definition litex.h:64
const char * payer_id
Payer purse id.
Definition litex.h:59
const char * payee_seq
Payee sequence number.
Definition litex.h:63
const char * currency
Currency code.
Definition litex.h:66
const char * payer_vpa
Payer VPA/address.
Definition litex.h:61
const char * amount
Transfer amount (decimal string).
Definition litex.h:67
const char * timestamp
Transfer timestamp.
Definition litex.h:65
const char * payer_seq
Payer sequence number.
Definition litex.h:60