Skip to content

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

Description

@mftee

Overview

The POST /submit endpoint in contract/src/lib.rs always returns 400 Bad Request with the body "Submit not yet implemented". This is the core function of the Rust microservice — anchoring a document hash to Stellar using a manageData operation. Without it, the Rust service has no production functionality.

Background

File: contract/src/stellar.rsStellarClient struct, which already has verify_hash() and submit_transaction() as stubs.

Files to modify:

  • contract/src/lib.rssubmit_handler() function (currently returns 400)
  • contract/src/stellar.rsStellarClient.anchor_hash() method (to be implemented)

Implementation approach:

  1. Parse the request body: { hash: string, publicKey: string }
  2. Build a Stellar transaction with a ManageData operation:
    • Key: "doc_" + &hash[..58] (max 64 bytes, matching NestJS buildDataKey())
    • Value: the full hash as bytes
  3. Sign with the service's Stellar secret key (STELLAR_SECRET_KEY env var)
  4. Submit to Stellar Horizon (stellar_sdk::Server.submit_transaction())
  5. On success: cache the result in Redis (stellar:verify:{hash}) and return { txHash, ledger, anchoredAt }
  6. On Stellar error: return 502 with the Horizon error detail

Stellar SDK: Use the stellar-sdk Rust crate or reqwest-based direct Horizon API calls.

Acceptance Criteria

  • POST /submit with a valid hash and public key returns { txHash, ledger, anchoredAt } on success
  • ManageData key format matches exactly what NestJS buildDataKey() produces (doc_ + first 58 chars of hash)
  • Successful anchor result is cached in Redis to avoid duplicate submissions
  • If the hash is already on Stellar (duplicate submission), return the existing record with 200 (idempotent)
  • Returns 400 for missing or malformed hash
  • Returns 502 with Horizon error details on Stellar network failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions