Skip to content

feat(dedup): add generateIdempotencyKey and canonical key registry (closes #612) - #808

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-issue-612
Draft

feat(dedup): add generateIdempotencyKey and canonical key registry (closes #612)#808
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-issue-612

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Description

Closes #612.

This PR implements canonical payment idempotency key generation and in-memory key registration in src/dedup.ts, exported via src/index.ts.

Changes

  • Implemented generateIdempotencyKey(params: { invoiceId: string; payer: string; amount: bigint; nonce?: string }): string using Node.js built-in crypto.createHash('sha256').
  • Implemented isKnownKey(key: string): boolean, registerKey(key: string): void, and clearKeys(): void backed by an in-memory Set.
  • Exported all new functions and types from src/index.ts.
  • Added comprehensive unit tests in test/dedup.test.ts covering determinism, collision resistance across parameter variations, nonce handling, key registration, teardown reset, and root exports.

Acceptance Criteria Checklist

  • generateIdempotencyKey(params: { invoiceId: string; payer: string; amount: bigint; nonce?: string }): string exported from src/dedup.ts
  • Key is a deterministic hex string: SHA-256 of "{invoiceId}:{payer}:{amount}" (with optional :{nonce} suffix when provided)
  • Same inputs always produce the same key (deterministic); different inputs produce different keys with high probability
  • isKnownKey(key: string): boolean and registerKey(key: string): void exported — backed by an in-memory Set within the module
  • clearKeys(): void exported for test teardown
  • All exported from src/index.ts
  • Unit tests: same params → same key, different amount → different key, nonce changes key, isKnownKey after registerKey, clearKeys resets state

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

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.

Add generateIdempotencyKey for canonical payment deduplication

1 participant