← Back to Official Package Registry
Tier 1: Backend Essentials • Passkeys & RBAC/ABACv1.0.0 • 45 KB • Ed25519 Verified

webauthn@1.0.0

W3C WebAuthn / FIDO2 Passkey registration & assertion verifier (CBOR COSE P-256 & Ed25519) plus homoiconic RBAC/ABAC policy engine.

use [webauthn]use [webauthn/policy]
veko pkg add webauthn@1.0.0
Run in Browser PlaygroundDownload 1.0.0.vkpRaw demo.vk

webauthn

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).

Overview

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):
  • Generates cryptographic registration (begin-registration) and assertion (begin-authentication) challenges (PublicKeyCredentialCreationOptions / PublicKeyCredentialRequestOptions).
  • Decodes CBOR 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.
  • Verifies 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):
  • Compiles declarative 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.

Installation

powershell
veko pkg add webauthn@1.0.0

Import in .vk modules:

rebol
use [
    wa  = webauthn
    pol = webauthn/policy
]

Architecture & Security Notes

  1. Constant-Time Challenge & RP Hash Checks: Both 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.
  2. Monotonic 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.
  3. Subgroup & Curve Validation: Ed25519 verification (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.
  4. Deny-Overrides Authorization: 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.

Complete API Reference

webauthn

Type / SignatureDescription
RelyingParty = struct { rp_id str, rp_name str, origin str }Relying Party domain and expected origin configuration.
StoredCredentialVerified 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 [] i64COSE algorithm constants (-8 EdDSA, -7 ES256).
base64url-encode = fn [data bytes] str / base64url-decode = fn [s str] bytesUnpadded RFC 4648 URL-safe Base64 codec.
encode-cose-ed25519 = fn [pubkey32 bytes] bytes / encode-cose-p256 = fn [pubkey65 bytes] bytesEncodes RFC 8152 integer-keyed CBOR COSE_Key maps.
decode-cose-public-key = fn [raw_tail bytes] mapDecodes 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] = []] mapGenerates registration challenge and browser PublicKeyCredentialCreationOptions.
finish-registration = fn [rp RelyingParty, expected_challenge str, response map /require-uv require_uv bool = false] StoredCredentialVerifies attestationObject + clientDataJSON and returns a StoredCredential.
begin-authentication = fn [rp RelyingParty, allowed_cred_ids block[str] /challenge custom_challenge bytes = ...] mapGenerates login challenge and browser PublicKeyCredentialRequestOptions.
finish-authentication = fn [rp RelyingParty, expected_challenge str, cred StoredCredential, assertion map /require-uv require_uv bool = false] StoredCredentialVerifies assertion signature + monotonic signCount and returns updated StoredCredential.
simulate-registration / simulate-authenticationHardware authenticator ceremony simulators for integration testing.

webauthn/policy

Type / SignatureDescription
CompiledPolicy, PolicyRule, AbacCond, AccessRequest, PolicyDecisionPolicy AST, request envelope, and structured decision (allowed, effect, matched_rule, reason).
compile-policy = fn [dsl block] CompiledPolicyCompiles 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] PolicyDecisionEvaluates req with .forbid-overrides-.allow and default-deny semantics.

Idiomatic Veko Examples

Passkey Registration, Authentication & Policy Enforcement

rebol
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})`

Verification

powershell
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.vk
packages/webauthn/examples/demo.vkSelf-contained runnable example & assertion suite
Raw .vk
// packages/webauthn/examples/demo.vk
// Runnable verification suite for `webauthn` (FIDO2 Ed25519 + P-256 Passkeys) and `webauthn/policy` (RBAC/ABAC).

use [
	hex = codec/hex
	pol = webauthn/policy
	wa  = webauthn
]

assert-eq = fn [actual any, expected any, label str] any [
	if actual != expected [
		return (err (str/join ['ASSERT FAILED [' label ']: got ' (mold actual) ', expected ' (mold expected)] ''))
	]
	.ok
]

assert-true = fn [cond bool, label str] any [
	if not cond [
		return (err (str/join ['ASSERT FAILED [' label ']'] ''))
	]
	.ok
]

main = fn [] any [
	println '=== webauthn 1.0.0 Verification Suite ==='

	rp = wa/RelyingParty {
		rp_id   = 'portal.veko-lang.org'
		rp_name = 'Veko Identity Portal'
		origin  = 'https://portal.veko-lang.org'
	}

	// 1. Ed25519 (`alg = -8`, EdDSA) Passkey Registration & Login Ceremony
	user_id = bytes/from-str 'usr_ada_001'
	reg_start = wa/begin-registration rp user_id 'ada@veko-lang.org' 'Ada Lovelace'
	reg_chal  = str/append '' (map/get reg_start 'challenge')
	r1 = assert-true ((len reg_chal) >= 40) 'begin-registration 32B base64url challenge'
	if err? r1 [ return r1 ]

	ed_seed = hex/decode '9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60'
	cred_id1 = bytes/from-str 'cred-ed25519-passkey-01'
	sim_reg1 = wa/simulate-registration rp reg_chal cred_id1 (wa/cose-alg-eddsa) ed_seed 1 true
	if err? sim_reg1 [ return sim_reg1 ]

	mut stored_ed = wa/finish-registration/require-uv rp reg_chal sim_reg1 true
	if err? stored_ed [ return stored_ed ]
	r2 = assert-eq stored_ed.alg -8 'Ed25519 COSE alg -8'
	if err? r2 [ return r2 ]
	r3 = assert-eq (len stored_ed.public_key) 32 'Ed25519 32B public key extracted from COSE_Key'
	if err? r3 [ return r3 ]
	r4 = assert-eq stored_ed.sign_count 1 'initial signCount == 1'
	if err? r4 [ return r4 ]
	r5 = assert-eq stored_ed.user_verified true 'UV flag verified'
	if err? r5 [ return r5 ]

	// Valid Ed25519 login (`signCount` advances 1 -> 2)
	auth_start1 = wa/begin-authentication rp [stored_ed.credential_id]
	auth_chal1  = str/append '' (map/get auth_start1 'challenge')
	sim_auth1   = wa/simulate-authentication rp auth_chal1 stored_ed.credential_id (wa/cose-alg-eddsa) ed_seed 2 true
	stored_ed   = wa/finish-authentication/require-uv rp auth_chal1 stored_ed sim_auth1 true
	if err? stored_ed [ return stored_ed ]
	r6 = assert-eq stored_ed.sign_count 2 'login updated signCount -> 2'
	if err? r6 [ return r6 ]

	// Security check A: Wrong challenge MUST be rejected
	auth_start_bad = wa/begin-authentication rp [stored_ed.credential_id]
	other_chal     = str/append '' (map/get auth_start_bad 'challenge')
	sim_wrong_chal = wa/simulate-authentication rp auth_chal1 stored_ed.credential_id (wa/cose-alg-eddsa) ed_seed 3 true
	wrong_chal_res = wa/finish-authentication/or rp other_chal stored_ed sim_wrong_chal [
		wa/StoredCredential { credential_id = 'REJECTED', public_key = (bytes/with-cap 0), alg = 0, sign_count = -1 }
	]
	r7 = assert-eq wrong_chal_res.credential_id 'REJECTED' 'wrong challenge rejected'
	if err? r7 [ return r7 ]

	// Security check B: Phishing origin mismatch MUST be rejected
	phish_rp = wa/RelyingParty {
		rp_id   = 'portal.veko-lang.org'
		rp_name = 'Evil Proxy'
		origin  = 'https://phish.evil.example'
	}
	sim_phish = wa/simulate-authentication phish_rp other_chal stored_ed.credential_id (wa/cose-alg-eddsa) ed_seed 3 true
	phish_res = wa/finish-authentication/or rp other_chal stored_ed sim_phish [
		wa/StoredCredential { credential_id = 'REJECTED_ORIGIN', public_key = (bytes/with-cap 0), alg = 0, sign_count = -1 }
	]
	r8 = assert-eq phish_res.credential_id 'REJECTED_ORIGIN' 'phishing origin rejected'
	if err? r8 [ return r8 ]

	// Security check C: Cloned `signCount` (2 <= 2) MUST be rejected!
	sim_cloned = wa/simulate-authentication rp other_chal stored_ed.credential_id (wa/cose-alg-eddsa) ed_seed 2 true
	clone_res  = wa/finish-authentication/or rp other_chal stored_ed sim_cloned [
		wa/StoredCredential { credential_id = 'REJECTED_CLONE', public_key = (bytes/with-cap 0), alg = 0, sign_count = -1 }
	]
	r9 = assert-eq clone_res.credential_id 'REJECTED_CLONE' 'cloned non-monotonic signCount rejected'
	if err? r9 [ return r9 ]
	println '  [PASS] FIDO2 Ed25519 (alg=-8) registration, login, challenge/origin & clone detection'

	// 2. ECDSA P-256 (`alg = -7`, ES256) Passkey Registration & Login Ceremony
	p256_priv = bytes/fill 32 0x2a
	cred_id2  = bytes/from-str 'cred-p256-hardware-key-02'
	reg_p256  = wa/begin-registration rp user_id 'ada@veko-lang.org' 'Ada Lovelace'
	chal_p256 = str/append '' (map/get reg_p256 'challenge')

	sim_reg2  = wa/simulate-registration rp chal_p256 cred_id2 (wa/cose-alg-es256) p256_priv 10 true
	stored_p256 = wa/finish-registration rp chal_p256 sim_reg2
	if err? stored_p256 [ return stored_p256 ]
	r10 = assert-eq stored_p256.alg -7 'ECDSA P-256 COSE alg -7'
	if err? r10 [ return r10 ]
	r11 = assert-eq (len stored_p256.public_key) 65 'P-256 65B SEC1 public key reconstructed'
	if err? r11 [ return r11 ]

	auth_p256 = wa/begin-authentication rp [stored_p256.credential_id]
	achal_p256 = str/append '' (map/get auth_p256 'challenge')
	sim_auth2 = wa/simulate-authentication rp achal_p256 stored_p256.credential_id (wa/cose-alg-es256) p256_priv 11 true
	updated_p256 = wa/finish-authentication rp achal_p256 stored_p256 sim_auth2
	if err? updated_p256 [ return updated_p256 ]
	r12 = assert-eq updated_p256.sign_count 11 'P-256 ES256 login verified & signCount -> 11'
	if err? r12 [ return r12 ]
	println '  [PASS] FIDO2 ECDSA P-256 (alg=-7) COSE_Key registration & RFC 6979 login verification'

	// 3. Homoiconic RBAC/ABAC Policy Engine (`webauthn/policy`)
	policy = pol/compile-policy (quote [
		.role-inherits 'admin'  ['editor']
		.role-inherits 'editor' ['viewer']

		.allow  role 'viewer' action 'read'   resource 'projects/*/docs/**'
		.allow  role 'editor' action 'write'  resource 'projects/*/docs/**' when [mfa == true and subject.id == resource.owner_id]
		.allow  role 'admin'  action '*'      resource '**'                 when [mfa == true and clearance >= 3]

		.forbid role '*'      action 'delete' resource 'projects/*/audit/**'
		.forbid role '*'      action '*'      resource '**'                 when [suspended == true]
	])
	if err? policy [ return policy ]

	// (a) Role hierarchy: `editor` inherits `viewer` -> allowed to `read` `projects/veko/docs/guide.md`
	d_inh = pol/evaluate policy (pol/AccessRequest {
		principal = 'usr_lin'
		roles     = ['editor']
		action    = 'read'
		resource  = 'projects/veko/docs/guide.md'
		attrs     = { mfa = false }
	})
	r13 = assert-eq d_inh.allowed true 'role hierarchy inheritance (editor -> viewer)'
	if err? r13 [ return r13 ]

	// (b) ABAC cross-attribute owner check + MFA: allowed when owner matches & mfa == true
	d_abac_ok = pol/evaluate policy (pol/AccessRequest {
		principal = 'usr_lin'
		roles     = ['editor']
		action    = 'write'
		resource  = 'projects/veko/docs/guide.md'
		attrs     = {
			mfa      = true
			subject  = { id = 'usr_lin' }
			resource = { owner_id = 'usr_lin' }
		}
	})
	r14 = assert-eq d_abac_ok.allowed true 'ABAC owner + MFA check permitted'
	if err? r14 [ return r14 ]

	// (c) ABAC owner mismatch -> default deny
	d_abac_no = pol/evaluate policy (pol/AccessRequest {
		principal = 'usr_lin'
		roles     = ['editor']
		action    = 'write'
		resource  = 'projects/veko/docs/guide.md'
		attrs     = {
			mfa      = true
			subject  = { id = 'usr_lin' }
			resource = { owner_id = 'usr_ada' }
		}
	})
	r15 = assert-eq d_abac_no.effect .deny_default 'ABAC owner mismatch denied by default'
	if err? r15 [ return r15 ]

	// (d) Explicit `.forbid` overrides `admin` `.allow` on audit trail deletion!
	d_forbid_audit = pol/evaluate policy (pol/AccessRequest {
		principal = 'usr_ada'
		roles     = ['admin']
		action    = 'delete'
		resource  = 'projects/veko/audit/2026-12.log'
		attrs     = { mfa = true, clearance = 5, suspended = false }
	})
	r16 = assert-eq d_forbid_audit.allowed false 'explicit .forbid overrides admin .allow'
	if err? r16 [ return r16 ]
	r17 = assert-eq d_forbid_audit.effect .forbid 'decision effect is .forbid'
	if err? r17 [ return r17 ]

	// (e) Suspended principal blocked everywhere by conditional `.forbid`
	d_suspended = pol/evaluate policy (pol/AccessRequest {
		principal = 'usr_ada'
		roles     = ['admin']
		action    = 'read'
		resource  = 'projects/veko/docs/guide.md'
		attrs     = { mfa = true, clearance = 5, suspended = true }
	})
	r18 = assert-eq d_suspended.effect .forbid 'suspended attribute triggers .forbid'
	if err? r18 [ return r18 ]

	println '  [PASS] Homoiconic RBAC/ABAC policy engine (.forbid override, role hierarchy, globs & ABAC)'
	println 'ALL webauthn TESTS PASSED'
	.ok
]

res = main
if err? res [
	println (mold res)
	os/exit 1
]
Cryptographic Provenance

Ed25519 Signature & Merkle Integrity

Registry URL: https://veko-lang.org/pkg/webauthn/1.0.0.vkp
Archive SHA-256: b07ee1055be4111b54949dca7aa112395e94a3ffa9bbbeafbfb14b13a50275ab
Merkle Root: 73ebed13f66863c0f8f4005c6fab1941596ed734e468749ff7dad6a6cba74ddc
Signer Trust Key: ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70
Embedded VKP1 Manifest

manifest.json

{"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 PathSizeLeaf SHA-256 Digest
README.md6 KB271aad9fb33497e3f939c806a8738c729fe085a0d2fa69176f53a02c19cd38f5
examples/demo.vk8 KBc2c7c16dc1dee3b6ad02b1524c6f7d49ef7d120c631d4368f39aceb5f87fee05
mod.vk19 KBbcfd6a9fd246ba7e1dcc27ffadb7da8ad2e849f465c4d3c7a09ef786b5b38a80
policy.vk10 KB03292a81785f8942224080e2d92385e0ab1b14607dc1d70eafde8773cfa023e8