Skip to content

feat: Archon wallet integration — Mage identity, Vault save/restore, Runecraft proof fields - #4

Open
Flaxscrip wants to merge 7 commits into
mitchuski:mainfrom
Flaxscrip:feature/archon-vault
Open

feat: Archon wallet integration — Mage identity, Vault save/restore, Runecraft proof fields#4
Flaxscrip wants to merge 7 commits into
mitchuski:mainfrom
Flaxscrip:feature/archon-vault

Conversation

@Flaxscrip

Copy link
Copy Markdown

Overview

This PR wires spellweb.ai into the Archon did:cid identity layer, turning the Mage from a local-only persona into a cryptographically anchored identity backed by an Archon wallet. It introduces three capabilities:

  1. Mage identity derived from Archon DID — the Mage's Ed25519 keypair is deterministically derived from the wallet's DID, making it reproducible across sessions and devices.
  2. Archon Vault save/restore — every blade forge auto-saves a .md file to an encrypted Archon vault asset; full Mage history (spells, constellations, blades) is also backed up. A vault browser panel lets users list and download any saved item.
  3. Runecraft proof fields in SpellwebBladePayloadV1 — the Soulbis button payload now carries bilateral proof data (swordsmanId, runecrafted, swordsmanSignature) so downstream apps (agentprivacy.ai) can display runecrafted status. A companion PR to agentprivacy-spellbook covers the display side.

Identity Architecture

Three distinct layers — not just Mage + Swordsman:

flaxscrip  (human sovereign — future VC recipient)
    ↑
GenitriX   (Mage — spell accumulator, VC issuer, Archon DID: GenitriX alias)
    ↕ bilateral ceremony
Excalibur  (Swordsman — agentprivacy.ai partner, Archon DID: Excalibur alias)

The Mage's keypair is derived from the GenitriX DID using a deterministic HKDF path (spellweb-mage-v1). This means: same wallet → same Mage ID across any browser or device.


Key Files Changed

File What changed
src/contexts/KeymasterContext.tsx New — full wallet connect/unlock flow (IndexedDB via WalletWeb, passphrase cached in sessionStorage), vault CRUD, history restore on unlock
src/components/MageIdentityPanel.tsx New — Archon wallet status panel: connect/unlock, gatekeeper URL config, wallet export/import
src/lib/mageIdentity.ts Extended — deriveMageKeyFromKeymaster() derives stable Ed25519 keypair from Archon DID
src/lib/mageHistory.ts New — MageArchonBackup schema + vault alias constants
src/utils/sessionPassphrase.ts New — passphrase cached in sessionStorage for the tab lifetime
src/components/SpellWeb.tsx Wired to KeymasterContext: auto-save on forge, vault browser panel in Mage modal, backup button
src/types/graph.ts SpellwebBladePayloadV1 extended with swordsmanId?, runecrafted?, swordsmanSignature?
src/data/nodes.ts / edges.ts Updated graph dataset (V5.5 — Act-7 Boundary Blade layer)

Vault Behaviour

  • Single vault per Mage, aliased as spellweb-mage-vault in the Archon wallet.
  • Items: mage-history.json (full state snapshot) + blade-<sig>.md (one per forged blade).
  • Vault items cannot be overwritten — the pattern is removeVaultItem (swallow error if absent) → addVaultItem. This is consistent with Archon's append-only asset model.
  • Auto-save timing: uses a pendingAutoBackup state + useEffect pattern to ensure React 18 batch commits the new blade to state before the backup fires. Avoids the stale-closure trap.
  • Restore on unlock: when the wallet is unlocked, mage-history.json is fetched from vault and applied to app state (spells, constellations, blades, edges, mana).

Test Plan

Prerequisites

  • Local Archon node running at http://192.168.1.23:4224 (or update gatekeeper URL in the wallet panel)
  • npm run dev → localhost:8000

1 — Wallet connect & Mage identity

  • Open app → header shows 🔑 connect button (MageIdentityPanel)
  • Click connect → passphrase modal appears → enter passphrase → wallet unlocks
  • Mage ID (mage-xxxxxxxxxxxxxxxx) appears in the identity panel
  • Refresh page → wallet auto-unlocks from cached passphrase (sessionStorage)

2 — Blade auto-save to vault

  • With wallet connected, forge a blade through the full ceremony
  • Check browser console for [vault] blade save log (no errors)
  • Open 🧙 Mage modal → ☁ ARCHON VAULT section → click ↻ Browse
  • blade-<sig>.md and mage-history.json should appear in the list
  • Click ↓ dl on a blade file → .md downloads with correct content

3 — History restore

  • Hard-refresh the page (clear sessionStorage too, or use incognito)
  • Reconnect wallet → spells, constellations, and blades should restore from vault

4 — Runecraft payload fields

  • Forge a Runecrafted blade (requires a Swordsman session bundle imported — see companion Runecraft PR)
  • Click the Soulbis button → inspect the spellwebBlade query param on agentprivacy.ai
  • Decoded payload should include swordsmanId, runecrafted: true, swordsmanSignature

Dependencies

  • @didcid/keymaster — wallet ops, vault, DID resolution
  • @didcid/gatekeeper/drawbridge — gatekeeper client
  • @didcid/cipher — encryption
  • @didcid/keymaster/wallet/web — IndexedDB wallet storage
  • buffer — Node Buffer polyfill for browser vault encoding

Requires a running Archon gatekeeper (local node or https://archon.technology).


What's NOT in this PR (coming next)

The Runecraft PR (companion, targeting agentprivacy-spellbook) covers:

  • Swordsman import at ceremony (bypass panel for Archon-derived keys)
  • ⚔️🔮 runecrafted badge display in BladeInventory and SpellwebBladeImport
  • Bilateral binding proof parsed from blade .md on import
  • SwordsmanAccountSettings import/replace flow

🤖 Generated with Claude Code

flaxscrip and others added 5 commits May 7, 2026 18:13
…demo)

Replace graph data with DID-blind Act-7 transmutation: 18 nodes, 21 edges.
Fix stale localStorage edge crash (node-not-found guard before D3 forceLink).
Add `poetic` field to SpellwebNode type for decomp node overlays.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- MageIdentityPanel: connect Archon wallet in-browser (encrypted StoredWallet)
- KeymasterContext: React context wrapping @didcid/keymaster for browser use
- mageIdentity: deriveMageKeyFromKeymaster() — sha256(secp256k1 sig) → Ed25519 seed
- mageHistory: MageArchonBackup — vault backup/restore via Archon Asset DID
- sessionPassphrase: secure in-memory passphrase handling for wallet unlock
- poh-cloak-contribution: Proof-of-Humanity cloak dataset contribution
- SpellWeb/Header: Archon wallet status + Mage ID display
- grimoire v10.1.0 update, node/edge additions

Mage identity is now portable: same did:cid wallet → same mage-{id} on any device.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…elds

Add swordsmanId, runecrafted, and swordsmanSignature to SpellwebBladePayloadV1.
Soulbis button now carries the full bilateral proof when the equipped blade has
been Runecrafted, so agentprivacy.ai can display the binding status on arrival.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
KeymasterContext: add saveBladeToVault(itemName, content) and listVaultItems()
alongside the existing backupMageHistory. Both share the same lazily-created
vault (spellweb-mage-vault alias). Vault items use remove-then-add because
addVaultItem does not overwrite.

SpellWeb: on every forge, setPendingAutoBackup(newBlade) signals a useEffect
that fires after React commits the state update (so handleBackupToArchon sees
the full updated forgedBlades list). Two writes happen concurrently:
  1. blade-{signature}.md  — individual, human-readable blade file
  2. mage-history.json     — full snapshot (identity + blades + constellations)

generateBladeMd() extracts the markdown template from handleExportConstellation
into a standalone helper that works directly from a ForgedBlade object.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds getVaultItem() to KeymasterContext and a ☁ ARCHON VAULT section
to the Mage Spellbook modal. Wallet-connected users can browse all saved
vault items (blade .md files + mage-history.json) and download any item
with a single click. Safe Uint8Array copy avoids SharedArrayBuffer type
issues across the Blob constructor boundary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Flaxscrip and others added 2 commits May 21, 2026 11:55
- Serialize vault writes (saveBladeToVault → backupMageHistory) to prevent
  parallel addVaultItem calls stomping each other's DID document update
- Add swordsmanLink to MageArchonBackup schema and both payload builders;
  restore path re-applies Swordsman link to localStorage on wallet unlock
- Shorten save-game filename to stay under Archon's 32-char alias limit
  (mage-save-YYYY-MM-DDThh-mm-ss.json → save-YYYYMMDD-HHMMSS.json)
- Optimistic vault browser update after save (avoids DID propagation lag)
- Consolidate Backup + Save into single 💾 button
- Surface getVaultItem null/error cases to console for debugging
- Trigger vault save on Runecraft confirmation (not just initial forge)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All 9 poh-cloak-contribution nodes now have emoji fields. Added
resolveNodeEmoji() helper that migrates saved '✦' placeholder emoji
to the current node definition on localStorage init and backup restore.
D3 canvas and constellation panel also fall back to node emoji at render
time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mitchuski added a commit that referenced this pull request May 28, 2026
Review of PRs #2-#5; defer the Archon identity-wallet integration (PR #4/#5) until a reachable HTTPS Gatekeeper + hosting model exist. Reject PR #4's grimoire hand-edit and canonical-graph overwrite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant