Files
zeekayandGitHub 728fc1bd79 wallet: PQAccount + ML-DSA-65 HD derivation + SLH-DSA-192 recovery (#2)
* wallet: PQAccount + ML-DSA-65 HD derivation + SLH-DSA-192 recovery

ML-DSA-65 native wallet accounts with 48-byte SHAKE256-384 AccountID
derived via cSHAKE-256 domain separation. KMAC/cSHAKE child seeds use
"LUX/WALLET/{IDENTITY,TX,SESSION,RECOVERY}/V1" customization strings.
HD path: m/44'/9000'/<chain>'/0'/<role>'/<account>', mirroring the F35
hardening landed in genesis/pkg/genesis/keys.go.

Recovery accounts use SLH-DSA-SHAKE-192s (FIPS 205, NIST Cat 3) for
stateless cold-key recovery on a separate hardened branch
m/44'/9000'/<chain>'/2'/<account>' so a leaked wallet branch cannot
derive recovery keys.

Keystore at rest: Argon2id (RFC 9106) → AES-256-GCM with AAD bound to
(scheme, role, chain, path). Private keys never persisted in plaintext.

WalletSchemeID/RecoverySchemeID declared locally (consensus/config has
not committed its WalletSchemeID byte yet); byte values match the raw
ML-DSA block (0x40..) so wire compatibility is preserved when the
consensus type lands.

AccountID KAT cross-checked against @noble/hashes/sha3-addons cshake256
(JS) — Go and TS implementations produce identical 48-byte AccountIDs
for the canonical test vector.

37 unit tests in wallet/account/, 7 in wallet/ (PQWallet facade).
Patch-bump.

* wallet/account: drop unused branchClassical constant

staticcheck U1000 catches it. The comment on branchPQ already
documents that branches 1' (secp256k1) and 2' (recovery) live in
sibling derivations, so the unused constant is dead documentation.

Patch-bump.

* sdk/wallet/account: use luxfi/crypto/pq/mldsa/mldsa65 wrapper

Switches PQAccount ML-DSA-65 key derivation, signing, and verification
from the upstream cloudflare/circl entry points to the luxfi/crypto
wrapper exposed at github.com/luxfi/crypto/pq/mldsa/mldsa65 (v1.18.4
adds the canonical NewKeyFromSeed/[]byte entry point we want).

  - NewKeyFromSeed accepts []byte (any length) and internally cSHAKEs
    to the 32-byte ξ FIPS 204 §5.1 consumes. The wallet already pre-
    domain-separates by role through cSHAKE before handing the seed
    off; the wrapper's per-parameter-set "LUX/FIPS204/MLDSA65/seed"
    customization compounds with the wallet role customization without
    overlap.
  - Sign returns ([]byte, error) directly — replaces the SignTo(...)
    out-parameter form.
  - go.mod: bump luxfi/crypto v1.18.3 → v1.18.4.

Tests rebound to the luxfi/crypto package; sizes (PublicKeySize,
PrivateKeySize, SignatureSize) are re-exported aliases so existing
KAT and roundtrip tests continue to verify byte-identical values.
All 37 wallet/account tests pass under GOWORK=off.

* sdk/wallet/account: gofmt — unstuck CI lint job

Pure gofmt -w pass on four files flagged by golangci-lint in the
previous PR run. Doc-comment list indentation only — no code changes,
all tests green.

  - wallet/account/cshake.go
  - wallet/account/keystore.go
  - wallet/account/scheme.go
  - wallet/account/sign_tx_test.go

* sdk/wallet/keychain: hybrid AND-verifies (closes F112)

Adds VerifyHybridSecp256k1MLDSA and VerifyHybridSecp256k1SLHDSA — the
AND-verifying hybrid signature verifiers that close red-team F112.

Previously the hybrid signature format produced by PQSigner.Sign
(length-prefixed classical || PQ concatenation) had no verifier in
this package, leaving every consumer to interpret it. The implicit
"either half verifies" OR semantics is as strong as the WEAKER of the
two halves (ECDSA in the production hybrids) — a forged hybrid
carrying a valid ECDSA half plus random "PQ" bytes would pass any OR
verifier.

The new verifiers require BOTH halves to verify under their respective
public keys. Failure on either half returns a typed sentinel
(ErrHybridSigClassicalFailed / ErrHybridSigPQFailed) without short-
circuiting on the classical refusal — both halves are checked before
the AND result is computed so timing-side channels do not leak which
half failed.

SplitHybridSignature is exported so callers can dispatch verification
through their own keying setup without re-implementing the wire-format
parsing.

Adds 9 regression tests:
  - happy-path AND accepts (MLDSA + SLHDSA)
  - tampered classical → ErrHybridSigClassicalFailed
  - tampered PQ → ErrHybridSigPQFailed
  - ECDSA-valid || random PQ bytes → ErrHybridSigPQFailed (the
    canonical F112 attack)
  - wrong message → either-half-fail
  - truncated blob → ErrHybridSigTruncated
  - wire-format round-trip

Closes red-team F112.
2026-05-29 22:10:41 -07:00

66 lines
2.4 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package account
import "fmt"
// TxAuthEnvelope is the wallet-side view of a transaction-authorization
// envelope. Callers (typically protocol/tx assemblers) implement this
// interface to expose the canonical 48-byte signing digest and to attach
// the wallet's signature back to the envelope after Sign returns.
//
// Defined as an interface here rather than imported from a protocol
// package because the wallet account package is the canonical lowest
// layer — protocol/tx packages depend on account, not the other way
// around. Any envelope type that satisfies these two methods can be
// signed by SignTx.
//
// The 48-byte (SHAKE256-384) digest size is the strict-PQ
// MinHashOutputBits floor; envelopes that produce a different digest
// size must rehash before exposing it through SigningDigest.
type TxAuthEnvelope interface {
// SigningDigest returns the canonical 48-byte digest the wallet
// signs. Must be deterministic for a fixed envelope state.
SigningDigest() ([AccountIDSize]byte, error)
// AttachSignature wires (schemeID, pubkey, sig) back into the
// envelope. Implementations should store the triple verbatim; the
// consensus verifier reconstructs the AccountID and scheme from
// these bytes.
AttachSignature(scheme WalletSchemeID, pubkey, sig []byte) error
}
// SignTx is the high-level entry point: ask the envelope for its
// canonical digest, sign the digest with the account, attach the
// signature back to the envelope. Returns an error if any of the three
// steps fails.
//
// Wallet callers should prefer SignTx over calling account.Sign
// directly. Direct callers must also remember to AttachSignature, and
// errors at that step are silent failures (no signed envelope) which
// SignTx surfaces explicitly.
func SignTx(account *PQAccount, env TxAuthEnvelope) error {
if account == nil {
return fmt.Errorf("account: SignTx called with nil PQAccount")
}
if env == nil {
return fmt.Errorf("account: SignTx called with nil TxAuthEnvelope")
}
digest, err := env.SigningDigest()
if err != nil {
return fmt.Errorf("account: SigningDigest: %w", err)
}
sig, err := account.Sign(digest)
if err != nil {
return fmt.Errorf("account: Sign: %w", err)
}
if err := env.AttachSignature(account.SchemeID, account.PublicKey, sig); err != nil {
return fmt.Errorf("account: AttachSignature: %w", err)
}
return nil
}