Skip to main content
After you read this page, you can verify an inbox for an account, handle each outcome, and name the inbox in a rule document so that its notify actions send mail. A rule mails its account through a notify action on the email channel. Every notify of a document mails global.notification_email. The engine refuses a stage of a document whose notification_email is not the verified inbox of the account (NotificationEmailNotVerifiedError). So verify the inbox first, then put it in the document. See the notification email flow.
The Anafi API accepts the code request only when its sign-in message names the domain of the Anafi dapp, app.ana.fi. It refuses a sign-in for another domain with status 422. An integration on another domain cannot complete the code request today.

The flow

  1. requestNotificationEmailCode({ aa, adapter, email, eoa }). The owner signs one sign-in. The engine mails a six-digit code and returns a code_token.
  2. The owner reads the code in the mail.
  3. verifyNotificationEmailCode({ aa, codeToken, code }). No prompt.
  4. On verified, set the inbox in the document with documentWithNotificationEmail(yaml, canonicalEmail), then stage and commit.

requestNotificationEmailCode

Steps:
  1. canonicalNotificationEmail(email). A null result throws Error("notification email must be a bare ASCII address without whitespace or display-name syntax").
  2. Render the sign-in with notificationEmailCodeSiweMessage. It expires 300 seconds after Issued At.
  3. Prompt: walletClient.signMessage({ account: eoa, message }).
  4. Seal { "adapter", "email", "siwe_message", "signature" } to the engine key under notificationEmailSealInfo("request_code", network, aa). email is the text as typed.
  5. POST /api/wallets/:aa/notification_email/request_code with { sealed }.
  6. Open and read the reply. Throw when the reply names another account.
The sign-in message:

NotificationEmailCodeRequestReply

Throws: BackendRequestError for a failed request (for example 422 for a refused sign-in), Error for a reply of the wrong shape, and the error of the wallet when the owner rejects the prompt.

verifyNotificationEmailCode

Checks the code. No prompt: the code_token and the code from the mail prove the request. Steps: seal { "code_token", "code" } under notificationEmailSealInfo("verify_code", network, aa), then POST /api/wallets/:aa/notification_email/verify_code with { sealed }, then open and read the reply. It throws when the reply names another account.

NotificationEmailCodeVerifyReply

The verified inbox also comes back in recover as verified_notification_email.

Helpers

canonicalNotificationEmail

Removes ASCII whitespace at both ends and returns the lowercase text. Returns null for an empty text, any non-ASCII character, inner ASCII whitespace, and any of <, >, ,, ;, ". It does not check the mailbox syntax or whether the address can get mail.

notificationEmailCodeSiweMessage

Renders the code request sign-in. It throws Error("canonicalEmail must already be in notification-email canonical form") when canonicalEmail is not canonical. The statement is Verify <canonicalEmail> to receive notifications from wallet <aa lowercase>., and the one resource is notificationEmailCodeResourceUri(aa, canonicalEmail).

notificationEmailCodeResourceUri

Binds the sign-in to one account and to the hash of one inbox.

notificationEmailSealInfo

The HPKE info of a request: the UTF-8 text anafi/notification-email/request-code/<network>/ or anafi/notification-email/verify-code/<network>/, then the 20 raw bytes of the account. A request sealed for one route, network or account does not open for another.

Reply readers

Read an opened reply, and throw on any field of the wrong shape, an unknown kind, or an email that does not fit the outcome (for example invalid_email with an email).

NotificationEmailNotVerifiedError

The stage methods throw it when the document names a notification_email that is not the verified inbox of the account. It extends DslStageRefusedError. See errors.