W3C WebAuthn / FIDO2 Passkey registration & assertion verifier (CBOR COSE P-256 & Ed25519) plus homoiconic RBAC/ABAC policy engine.
Pure-Veko Zero-C FIDO2 / WebAuthn Level 2 Relying Party ceremony engine (Ed25519 and ECDSA P-256 passkeys) and homoiconic RBAC/ABAC authorization policy engine (webauthn/policy).
webauthn delivers hardware-backed passwordless authentication and fine-grained authorization in pure Veko with zero external C or OpenSSL dependencies:
webauthn (FIDO2 / WebAuthn Level 2 Relying Party):begin-registration) and assertion (begin-authentication) challenges (PublicKeyCredentialCreationOptions / PublicKeyCredentialRequestOptions).attestationObject and integer-keyed RFC 8152 COSE_Key public keys (alg = -8 EdDSA Ed25519 via crypto/x25519 and alg = -7 ES256 ECDSA P-256 via crypto/sig), tolerating trailing WebAuthn ED extension blocks.clientDataJSON (type, constant-time challenge, exact origin, non-crossOrigin), rpIdHash (SHA-256(rp_id)), UP/UV/AT authenticator flags, cryptographic signatures over authenticatorData || SHA-256(clientDataJSON), and monotonic signCount clone detection.webauthn/policy (Homoiconic RBAC/ABAC Engine):quote [...] authorization blocks supporting transitive role hierarchies (.role-inherits), wildcard/glob action and resource patterns (lib/glob), cross-attribute ABAC predicates (when [mfa == true and subject.id == resource.owner_id]), default-deny, and explicit .forbid-overrides-.allow semantics.veko pkg add webauthn@1.0.0Import in .vk modules:
use [
wa = webauthn
pol = webauthn/policy
]expected_challenge and rpIdHash (SHA-256(rp.rp_id)) are verified using crypto/sha256/ct-eq, preventing timing side-channels and cross-origin phishing relays.signCount Clone Detection: In accordance with WebAuthn Level 2 Section 7.2 Step 21, when either the stored credential or incoming assertion carries a non-zero signCount, finish-authentication enforces new_sign_count > cred.sign_count and rejects replayed or cloned hardware tokens.crypto/x25519/ed25519-verify) rejects all 8 small-order torsion points and non-canonical scalars, while P-256 verification (crypto/sig/ecdsa-p256-verify) validates that extracted (X, Y) coordinates lie strictly on secp256r1.webauthn/policy/evaluate evaluates every matching rule and guarantees that any matching .forbid rule unconditionally overrides any .allow rule, falling back to .deny_default when no .allow rule matches.webauthn| Type / Signature | Description |
|---|---|
RelyingParty = struct { rp_id str, rp_name str, origin str } | Relying Party domain and expected origin configuration. |
StoredCredential | Verified credential record (credential_id, public_key, alg, sign_count, aaguid, user_verified, backup_eligible, backup_state). |
cose-alg-eddsa = fn [] i64 / cose-alg-es256 = fn [] i64 | COSE algorithm constants (-8 EdDSA, -7 ES256). |
base64url-encode = fn [data bytes] str / base64url-decode = fn [s str] bytes | Unpadded RFC 4648 URL-safe Base64 codec. |
encode-cose-ed25519 = fn [pubkey32 bytes] bytes / encode-cose-p256 = fn [pubkey65 bytes] bytes | Encodes RFC 8152 integer-keyed CBOR COSE_Key maps. |
decode-cose-public-key = fn [raw_tail bytes] map | Decodes a CBOR COSE_Key from authData into { alg, public_key }. |
begin-registration = fn [rp RelyingParty, user_id bytes, user_name str, display_name str /challenge custom_challenge bytes = ... /exclude exclude_credential_ids block[str] = []] map | Generates registration challenge and browser PublicKeyCredentialCreationOptions. |
finish-registration = fn [rp RelyingParty, expected_challenge str, response map /require-uv require_uv bool = false] StoredCredential | Verifies attestationObject + clientDataJSON and returns a StoredCredential. |
begin-authentication = fn [rp RelyingParty, allowed_cred_ids block[str] /challenge custom_challenge bytes = ...] map | Generates login challenge and browser PublicKeyCredentialRequestOptions. |
finish-authentication = fn [rp RelyingParty, expected_challenge str, cred StoredCredential, assertion map /require-uv require_uv bool = false] StoredCredential | Verifies assertion signature + monotonic signCount and returns updated StoredCredential. |
simulate-registration / simulate-authentication | Hardware authenticator ceremony simulators for integration testing. |
webauthn/policy| Type / Signature | Description |
|---|---|
CompiledPolicy, PolicyRule, AbacCond, AccessRequest, PolicyDecision | Policy AST, request envelope, and structured decision (allowed, effect, matched_rule, reason). |
compile-policy = fn [dsl block] CompiledPolicy | Compiles a homoiconic quote [...] policy block. |
expand-roles = fn [role_parents map, initial_roles block[str]] block[str] | Transitively expands roles across .role-inherits edges. |
evaluate = fn [policy CompiledPolicy, req AccessRequest] PolicyDecision | Evaluates req with .forbid-overrides-.allow and default-deny semantics. |
use [wa = webauthn, pol = webauthn/policy]
rp = wa/RelyingParty {
rp_id = 'app.veko-lang.org'
rp_name = 'Veko Cloud'
origin = 'https://app.veko-lang.org'
}
// 1. Start registration and persist `reg.challenge` in user session
reg = wa/begin-registration rp (bytes/from-str 'u_1001') 'ada@veko-lang.org' 'Ada'
// 2. Verify authenticator response in POST /webauthn/register/finish
// cred = wa/finish-registration/require-uv rp saved_challenge client_body true
// 3. Enforce homoiconic RBAC/ABAC policy after passkey login (`mfa = cred.user_verified`)
policy = pol/compile-policy (quote [
.role-inherits 'admin' ['developer']
.allow role 'developer' action 'deploy' resource 'envs/staging/*' when [mfa == true]
.allow role 'admin' action '*' resource 'envs/**' when [mfa == true]
.forbid role '*' action 'delete' resource 'envs/prod/**'
])
decision = pol/evaluate policy (pol/AccessRequest {
principal = 'u_1001'
roles = ['developer']
action = 'deploy'
resource = 'envs/staging/api'
attrs = { mfa = true }
})
println `Allowed: {decision.allowed} ({decision.reason})`veko check --strict-types packages/webauthn/src/policy.vk
veko check packages/webauthn/src/mod.vk
veko check packages/webauthn/examples/demo.vk
veko run -C all packages/webauthn/examples/demo.vkhttps://veko-lang.org/pkg/webauthn/1.0.0.vkpb07ee1055be4111b54949dca7aa112395e94a3ffa9bbbeafbfb14b13a50275ab73ebed13f66863c0f8f4005c6fab1941596ed734e468749ff7dad6a6cba74ddced25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"webauthn","version":"1.0.0","tier":1.0,"tier_label":"Tier 1: Backend Essentials","category":"Passkeys & RBAC/ABAC","description":"W3C WebAuthn / FIDO2 Passkey registration & assertion verifier (CBOR COSE P-256 & Ed25519) plus homoiconic RBAC/ABAC policy engine.","modules":["webauthn","webauthn/policy"],"homepage":"https://veko-lang.org/packages/webauthn"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 6 KB | 271aad9fb33497e3f939c806a8738c729fe085a0d2fa69176f53a02c19cd38f5 |
| examples/demo.vk | 8 KB | c2c7c16dc1dee3b6ad02b1524c6f7d49ef7d120c631d4368f39aceb5f87fee05 |
| mod.vk | 19 KB | bcfd6a9fd246ba7e1dcc27ffadb7da8ad2e849f465c4d3c7a09ef786b5b38a80 |
| policy.vk | 10 KB | 03292a81785f8942224080e2d92385e0ab1b14607dc1d70eafde8773cfa023e8 |