Skip to content

Add vault and P2 singleton puzzle types and a Cloud Wallet–compatible vault layout #948

Open

Description

@Rigidity

Parent: #945
Phase: 1

Summary

Add the storage and puzzle building blocks that every later vault issue depends on:

  • vault assets
  • P2Singleton and P2ConditionsOrSingleton p2 puzzle kinds
  • vault custody configs
  • a builder and memo decoder that match Chia Cloud Wallet's vault layout exactly

Scope

  • Migration 0011_vaults.sql (0010 is taken by 0010_synced_p2_puzzles.sql from Import addresses as watch-only wallets #964):
    • AssetKind::Vault plus a vaults table with:
      • asset ID and launcher ID
      • current custody hash and amount (read from chain; don't assume 1 mojo)
      • puzzle version (Legacy / ForceSingletonRecreation)
      • state (active, recovery pending, melted)
    • Vault config tables:
      • custody and recovery thresholds, and the recovery timelock
      • members, each with: kind (BLS, secp256r1, secp256k1, passkey, singleton, custom), public key or launcher ID, and fast-forward flag
      • a source: decoded from a verified memo, imported from a config file, or unknown
    • P2PuzzleKind::P2Singleton (launcher_id, nonce). Kinds 0–4 are taken; External (4) came with Import addresses as watch-only wallets #964.
    • P2PuzzleKind::P2ConditionsOrSingleton (launcher_id, nonce, fixed_conditions_hash, version, revealed conditions), used for offer pre-split coins in Make, take, and cancel offers from a vault #955.
    • CoinKind::Vault.
    • Recreate the coin views, as 0006_clawback_v1.sql does.
    • Update the hardcoded kind IN (...) lists and subscription_coin_ids. Import addresses as watch-only wallets #964 already keeps arbor and external puzzles out of coin-ID subscriptions; P2Singleton puzzles are custody and should be handled the same way.
    • New P2Singleton rows start with is_synced = 0 (from Import addresses as watch-only wallets #964), so new vault nonces sync from the start of the chain.
    • Refresh the sqlx offline cache.
  • Match arms. Handle the new P2Puzzle variants everywhere they're matched: Wallet::complete_spends (return a clear error until Spend from a vault: spend pipeline, signing, and XCH/CAT transactions #952), Sage::get_asset_coins, sage_wallet::database::insert_puzzle, and similar.
  • Vault layout module:
    • A builder VaultConfig → (custody_hash, CHIP-0043 memo) that matches ent-wallet's getVaultInternals and getVaultMipsMemoListBytes byte for byte:
      • member hashes sorted by bytes
      • R1, K1 and passkey members fast-forward; BLS not
      • nonce 0
      • the recovery restriction stack for each VaultVersion
    • A recovery-state builder: original custody plus the timelocked finish member.
    • A memo decoder built on MipsMemo::from_clvm_bounded + verify(expected_hash). It rejects any memo that doesn't rebuild the expected hash.
    • P2Singleton address helpers for each nonce.
  • Test vectors. Port the vectors from chia-wallet-sdk primitives/mips/memo/vault_tests.rs and from ent-wallet, so the implementations agree. The SDK's builder is test-only today; consider upstreaming this one.
  • Feature flag. Add VITE_DISABLE_VAULTS, following the options and XCHandles flags.

Acceptance criteria

  • The migration applies to existing databases without data loss.
  • The builder reproduces the SDK and ent-wallet custody hashes and memo bytes for single-signer, M-of-N, Legacy and ForceSingletonRecreation layouts.
  • The decoder rejects tampered, oversized and hash-mismatched memos.
  • Both versions round-trip: config → memo → config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseRelates to the database schema or queriesenhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions