Skip to content

feat: anchor snippet creation timestamps on Stellar blockchain#90

Open
AgilityB wants to merge 1 commit into
SudiptaPaul-31:mainfrom
AgilityB:On-Chain-Snippet-Timestamp-Verification
Open

feat: anchor snippet creation timestamps on Stellar blockchain#90
AgilityB wants to merge 1 commit into
SudiptaPaul-31:mainfrom
AgilityB:On-Chain-Snippet-Timestamp-Verification

Conversation

@AgilityB
Copy link
Copy Markdown

On-Chain Snippet Timestamp Verification
Anchors snippet creation timestamps to the Stellar blockchain, providing immutable proof-of-existence for ownership and originality verification.

What changed
stellar.ts
Replaced the mock stub with real Stellar SDK integration.

submitHashToStellar — builds a Stellar transaction with a manageData operation storing the content hash and a Memo.text encoding the snippet ID + hash. Accepts createdAt so the snippet's original creation timestamp is permanently embedded on-chain.
submitBatchHashToStellar — submits up to 64 snippets in a single transaction using one manageData op per snippet.
Both functions fall back to a deterministic mock when STELLAR_SECRET_KEY is not configured, so local dev works without a funded account.
db.ts
Added four functions to support the verification flow:

getSnippetWithHash — fetches a snippet including the new verification columns.
storeSnippetHash — persists on_chain_hash, transaction_hash, and verified_at. Rejects any attempt to overwrite an existing record, enforcing immutability at the DB layer.
verifySnippetIntegrity — recomputes the current content hash and compares it against the stored on-chain hash to detect tampering.
getVerifiedSnippets — returns all snippets that have been anchored on-chain.
app/api/snippets/[id]/verify/route.ts

POST now passes snippet.created_at into submitHashToStellar, anchoring the original creation timestamp (not just the content hash) on-chain. Returns 409 if the snippet is already verified.
GET response now includes createdAt alongside the existing verification fields.
add-verification-columns.sql
Migration script adding on_chain_hash, transaction_hash, and verified_at columns to the snippets table, with partial indexes for efficient querying of verified snippets.

How to deploy
Run the migration against your NeonDB instance:
psql $DATABASE_URL -f scripts/add-verification-columns.sql
Set STELLAR_SECRET_KEY in your environment (testnet or mainnet key depending on NEXT_PUBLIC_STELLAR_NETWORK).
Testing

Anchor a snippet on-chain

curl -X POST http://localhost:3000/api/snippets//verify

Check integrity

curl http://localhost:3000/api/snippets//verify

List all verified snippets

curl http://localhost:3000/api/snippets/verify

Closes #76

- Implement real Stellar SDK integration (submitHashToStellar,
  submitBatchHashToStellar) replacing mock stubs; embeds snippet
  created_at timestamp in on-chain memo for proof-of-existence
- Add DB functions: getSnippetWithHash, storeSnippetHash (immutable,
  rejects overwrites), verifySnippetIntegrity, getVerifiedSnippets
- Update POST /api/snippets/[id]/verify to anchor creation timestamp
  on-chain; return 409 if already verified
- Add migration script for on_chain_hash, transaction_hash, verified_at
  columns with indexes
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@AgilityB is attempting to deploy a commit to the Sudipta 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@AgilityB Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

On-Chain Snippet Timestamp Verification

1 participant