feat: anchor snippet creation timestamps on Stellar blockchain#90
Open
AgilityB wants to merge 1 commit into
Open
feat: anchor snippet creation timestamps on Stellar blockchain#90AgilityB wants to merge 1 commit into
AgilityB wants to merge 1 commit into
Conversation
- 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
|
@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. |
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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