Skip to content

feat(contract): implement POST /submit — anchor document hash to Stellar [CT-01]#957

Merged
mftee merged 3 commits into
CodeGirlsInc:mainfrom
kike-alt:feature/implement-post-submit
Jul 21, 2026
Merged

feat(contract): implement POST /submit — anchor document hash to Stellar [CT-01]#957
mftee merged 3 commits into
CodeGirlsInc:mainfrom
kike-alt:feature/implement-post-submit

Conversation

@kike-alt

Copy link
Copy Markdown
Contributor

Summary

Implements the POST /submit endpoint in the Rust verifier microservice, which was previously returning 400 Bad Request with "submit endpoint not yet implemented".

Changes

contract/src/stellar.rs

  • Added AnchorResult struct (tx_hash, ledger, anchored_at)
  • Implemented StellarClient::anchor_hash(hash, public_key, secret_key):
    • Fetches the signing account's current sequence number from Horizon
    • Builds a ManageData transaction using stellar-base:
      • Key: "doc_" + &hash[..58] — matches NestJS buildDataKey() exactly
      • Value: the full hash as bytes
    • Signs with STELLAR_SECRET_KEY
    • Encodes as XDR base64 and submits via POST /transactions
    • Returns AnchorResult on success; propagates Horizon error detail on failure
  • Added build_data_key() and build_revocation_key() helper functions

contract/src/lib.rs

  • submit_document() now takes State<AppState> and calls stellar.anchor_hash()
  • Idempotency: checks Redis cache (stellar:verify:{hash}) before submitting — duplicate submissions return the cached result with 200
  • On success: caches result with 1-year TTL and returns { success, transaction_id, anchored_at }
  • On Horizon failure: returns 502 with error detail from Horizon
  • Returns 400 for missing/malformed hash (unchanged)
  • Added Deserialize to SubmitResponse to support cache round-trip

contract/Cargo.toml

  • Added stellar-base = "0.5" for XDR transaction building

Testing

  • cargo build — clean ✓
  • Endpoint logic follows the same State/cache/metrics pattern as the existing verify_document and record_transfer handlers
  • Integration tests require a live Horizon testnet instance; unit-testable paths (hash validation, cache hit) follow existing test patterns

Closes #854

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@kike-alt is attempting to deploy a commit to the Mftee's projects Team on Vercel.

A member of the Team first needs to authorize it.

…lar [CT-01]

Implements the previously stubbed submit_document handler in
contract/src/lib.rs and adds anchor_hash() to StellarClient in
contract/src/stellar.rs.

Changes:
- contract/src/stellar.rs:
  - Added AnchorResult struct (tx_hash, ledger, anchored_at)
  - Implemented StellarClient::anchor_hash() using stellar-base:
    - Fetches account sequence number from Horizon
    - Builds a ManageData operation with key 'doc_' + hash[:58]
      (matches NestJS buildDataKey() exactly)
    - Signs the transaction with the service's STELLAR_SECRET_KEY
    - Submits to Horizon via application/x-www-form-urlencoded
    - Returns AnchorResult on success; propagates Horizon error detail on failure
  - Added build_data_key() and build_revocation_key() helpers
  - Added stellar-base = "0.5" dependency for XDR/transaction building

- contract/src/lib.rs:
  - submit_document() now takes State<AppState> and calls stellar.anchor_hash()
  - Idempotency: checks Redis cache (stellar:verify:{hash}) before submitting;
    returns existing result with 200 if already anchored
  - On success: caches result with 1-year TTL, returns SubmitResponse
  - On Horizon failure: returns 502 with error detail
  - Returns 400 for missing/malformed hash (unchanged)
  - Added Deserialize to SubmitResponse to support cache round-trip

Closes CodeGirlsInc#854
@kike-alt
kike-alt force-pushed the feature/implement-post-submit branch from 14bed41 to 740959b Compare July 21, 2026 13:10
Kiro added 2 commits July 21, 2026 15:30
Contracts (Rust):
- Run cargo fmt --all to fix formatting in contract/src/lib.rs and
  contract/src/stellar.rs; long lines in info!/warn! macros and
  method chains were not wrapped to rustfmt's column limit

Frontend (Next.js):
- Move misplaced pages from app/(protected)/ to app/[locale]/(protected)/
  so they are covered by the root layout at app/[locale]/layout.tsx.
  Affected pages: admin/providers, profile, reports, settings/api-keys.
  Without a root layout Next.js 15 refuses to build the page.
…bility

stellar-base 0.5.0 calls sodiumoxide::crypto::sign::Signature::from_slice()
which does not exist in newer sodiumoxide versions. Pinning to =0.2.6
(the version stellar-base 0.5 was built against) resolves the compile error:

  error[E0599]: no associated function or constant named 'from_slice' found
  for struct 'sodiumoxide::crypto::sign::Signature'
@mftee
mftee merged commit d8fcedb into CodeGirlsInc:main Jul 21, 2026
4 of 5 checks passed
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.

[CT-01] Implement POST /submit in Rust verifier — anchor document hash to Stellar

2 participants