Allow others to spend your tokens using witness-derived keypair authentication.
This page uses the witness-derived keypair pattern from
Access Control. The caller authenticates by
proving knowledge of a witness secret whose hash matches the stored
UserPublicKey. ownPublicKey() is not used for authentication.
The caller proves knowledge of a witness secret whose hash equals their
UserPublicKey. The contract then writes an allowance entry at
_allowances[owner][spender] = amount.
A two-level map: the outer key is the owner’s authenticated public key; the
inner map records how much each spender may spend.Reading the nested map must be done inline — you cannot bind the inner map
to a const:
// ✅ inline lookup is allowed_allowances.lookup(disclose(owner)).lookup(disclose(spender));// ❌ binding the inner Map to a const fails to compile// const inner = _allowances.lookup(disclose(owner)); // ADT type error
Every approve call reveals the owner, the spender, and the amount on the
public ledger. This is appropriate for transparent tokens (game items,
public registries) but unsuitable for private finance. Midnight’s native
shielded primitives provide UTXO-based privacy that hides participants and
amounts.