Skip to content

refactor(host_primitives): single home for the Turnkey wire envelope - #446

Draft
pepe-anchor wants to merge 1 commit into
mainfrom
pepefigueira/prs-581-01-turnkey-envelope
Draft

refactor(host_primitives): single home for the Turnkey wire envelope#446
pepe-anchor wants to merge 1 commit into
mainfrom
pepefigueira/prs-581-01-turnkey-envelope

Conversation

@pepe-anchor

Copy link
Copy Markdown
Contributor

Why

PRS-581 switches the parse path onto the enclave-side HTTP pivot. Two features have to be added to the response envelope on the way (bootProof from #337, intermediateOutput from #414), and today that envelope is defined twice: inline in parser_gateway, and again on the unmerged x402 branch in host_primitives::turnkey. Two definitions of one wire contract means every change gets made twice and kept in sync by hand, and the pivot would have made it three.

This is the refactor that makes the rest of the stack cheap. It also shrinks the PR #304 rebase from "reconcile two envelope definitions" to "add a module".

What

  • host_primitives::turnkey becomes the single home for the Turnkey request/response envelope, as the union of both existing definitions.
  • bootProof is now an injected value rather than a hardcoded mock: error_response(msg, boot_proof). parser_gateway keeps its stable local-dev mock through a local shim; the enclave pivot will supply a real attested one.
  • parser_gateway imports the shared types and keeps the four MOCK_BOOT_PROOF_* constants and their wire-shape tests.

No wire change. The gateway's JSON output is byte-identical.

Test evidence

cargo test -p host_primitives -p parser_gateway
  host_primitives: 4 passed
  parser_gateway: 13 passed
cargo fmt -- --check: clean
make -C src lint: clean

The two regression tests that matter both still pass and their constant values are unchanged: mock_boot_proof_matches_production_wire_shape, error_response_carries_mock_boot_proof.

One trap worth recording: the x402 branch's TurnkeyResponseWrapper had no rename_all = "camelCase", which the gateway's inline struct did have. Adding boot_proof without it would have serialized as boot_proof instead of bootProof and silently broken the wallet contract. The six-key wire-shape test catches it.

Rollback

Revert the commit. No deploy, no migration, no wire change, so a revert restores the previous state exactly.

Linear

PRS-581

Stack position: base of the PRS-581 stack. #337, #414.

🤖 Generated with Claude Code

parser_gateway kept the Turnkey request/response types inline while the
x402 branch had grown its own copy in host_primitives::turnkey. Two
definitions of one wire contract means every envelope change (bootProof
in #337, intermediateOutput in #414) has to be made twice and kept in
sync by hand.

Move them to host_primitives::turnkey as the union of both, and make
bootProof an injected value instead of a hardcoded mock, so the enclave
pivot can supply a real one while the gateway keeps its local-dev mock.

No wire change: the gateway still emits the same mock constants, and the
wire-shape tests move with the types.

Co-Authored-By: Claude <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