mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
hanzo.ai asks IAM at api.hanzo.ai, so the EIP-4361 domain was "api.hanzo.ai" and a wallet that checks it against the page warned the person the sign-in was for another site. A nonce asked with a clientId, from an Origin that one of that application's redirect URIs registers (oidc.Landing, the rule the emailed link already uses), now names that origin; otherwise the Host, as before. Verify derives the site by the same function, accepts the burned row when it names the site or the Host, and VerifyProof still expects the burned row's domain. A forged Origin picks only among the application's own origins. The nonce's address is bounded as verify's is, and every mint sweeps expired challenges, 100 rows at most, once per ttl per process. Purge existed and nothing called it, so every anonymous GET left a row. Claude-Session: https://claude.ai/code/session_017vrVus6PPBgP5YRzKV1iqW
41 lines
1.8 KiB
Go
41 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package schema
|
|
|
|
import "github.com/hanzoai/orm"
|
|
|
|
// Challenge is a single-use, expiring wallet login challenge (v1 the legacy surface
|
|
// `web3_nonce`, v2 kind "challenges") — the anti-replay half of CAIP-122 wallet
|
|
// sign-in (HIP-0111). GET /v1/iam/web3/nonce mints one; POST /v1/iam/web3/verify
|
|
// burns it before any crypto runs, so a captured proof can never be redeemed
|
|
// twice even when its signature is valid.
|
|
//
|
|
// Owner is always "built-in": a challenge is minted before any application or
|
|
// tenant is known, so the challenge store is global, not org-scoped. Name IS the
|
|
// nonce string, so (Owner, Name) is the natural key the burn locks.
|
|
//
|
|
// Domain is the site the wallet signed for — the asking page's origin when its
|
|
// application registers it, else the brand host (internal/wallet site) —
|
|
// re-checked against this row at verify. The whole phishing defense rides on that binding,
|
|
// which is why the host is stored at mint rather than re-derived from the client
|
|
// at verify.
|
|
type Challenge struct {
|
|
orm.Model[Challenge]
|
|
|
|
Owner string `json:"owner" orm:"index"` // "built-in" — the challenge store is global
|
|
Name string `json:"name" orm:"index"` // the nonce string itself (the lookup key)
|
|
|
|
// Chain and Address are the advisory scoping hints the mint was asked for.
|
|
// Chain is re-checked at verify so a nonce minted for one chain cannot be
|
|
// redeemed with a valid proof on another; Address is a hint only — identity
|
|
// comes from the VERIFIED address, never from this row.
|
|
Chain string `json:"chain"`
|
|
Address string `json:"address"`
|
|
|
|
Domain string `json:"domain"`
|
|
CreatedTime string `json:"createdTime"`
|
|
ExpireTime string `json:"expireTime"` // RFC3339
|
|
Used bool `json:"used"`
|
|
}
|