AnafiRegistry.engineEncKey() publishes on chain. The Anafi API carries the sealed bytes and cannot read them. See security and sealed requests.
Cipher suite
The engine uses the same suite. A change of any part makes every envelope unreadable.
One-way seal
seal
payload to the engine key under info. Each call uses a new ephemeral key, so two seals of one payload differ. enginePubkey must be 32 bytes, else it throws Error("enginePubkey must be 32 bytes, got N").
Both fields are JSON arrays of numbers, not hex strings. The key name is kem_pk in snake case.
dslSealInfo
info of a rule document: the UTF-8 text anafi/dsl-seal/<network>/, then the 20 raw bytes of the account address. The engine derives the same info from the account in the request path. So a document sealed for one account and network does not open for another account or network. It throws for an unknown network or an invalid address.
Request and response channel
A seal alone gives the engine no private way to answer. The channel keeps the HPKE context of the request and exports a 32-byte response key from it. The engine derives the same key and seals its reply with it. Only the caller that sealed the request can open the reply.sealRequest
seal does, and keeps the response key, exported with the context anafi/confidential-call/resp/v1. The envelope has the same wire form as a seal envelope. Keep secret in memory only, and only until you open the reply.
openResponse
Request tags
Each route takes the body
{ "sealed": SealedEnvelope }. A sealed reply has the form SealedResponse.
recover
Steps
- Make a 16-byte random nonce, as 32 hex characters with no
0x. - Render the sign-in with
renderSiweMessage: the domainsiweDomain(orwindow.location.host), the addresseoa, the statementSign in to Anafi to recover your wallet state., the URIhttps://<domain>, thechainId, the nonce andIssued At. No expiry line. - Prompt:
walletClient.signMessage({ account: eoa, message }). - Read
engineEncKey()and seal{ "aa", "siwe_message", "signature" }withCONFIDENTIAL_CALL_REQUEST_INFO. POST /api/wallets/:aa/recoverwith{ sealed }.- Open the reply, and parse it as
RecoverResponsePayload. - Read
AnafiRegistry.engineSigKey(). Check thatengine_sigrecovers to that address overrecoverResponseDigest(nonce, state). Else throw. - Check the
tenantfield (assertRecoveredTenantValid). Else throw. - Return
state.
BackendRequestError for a failed request (for example 422 for a refused sign-in), an Error for a reply that does not open, a bad signature, or a bad tenant, and the error of the wallet when the owner rejects the prompt.
RecoveredUserState
TenantLifecycle
ParkedReason
parked_token names the token that caused the stop, when one token did. It is present only on a parked account.
Example reply
The engine signature check
engineSigKey(), wrote this exact state for this exact request.
recoverResponseDigest(nonce, state) is keccak256(utf8(nonce + canonicalStateJson)):
nonceis the nonce of the sign-in. It binds the reply to this request, so an old reply cannot answer a new prompt.- The state JSON is compact, with no spaces. The fields come in this order:
dsl(withstatus,yaml,version,commitment), thengrant_hashandgrant_jsonwhen present, thentenant(withstate,adapter,since_block,reason, thenparked_tokenwhen present), thenverified_notification_emailwhen present. Keys of any map insidegrant_jsonare sorted by code point. - An absent field is left out. A
nullfield printsnull. - A non-integer number makes the function throw.
assertRecoverResponseSignedByEngine checks that engineSig is 65 bytes of hex, recovers the signer of the raw digest (no EIP-191 prefix), and throws unless the signer is engineSigKey.
assertRecoveredTenantValid checks the tenant field after the signature check: a known state; parked_token only on a parked account and only as an address; for none, all of adapter, since_block, reason are null; for active and parked, an address and a block of 0 or more; for active, a null reason; for parked, a known reason. An absent tenant passes.
Sign-in messages
renderSiweMessage
\n, and the address is checksummed:
The sign-ins of the SDK
The notification-email sign-in is on notification email. The rule generation sign-in is on rule builders.