Skip to content

test(crypto): cross-SDK canonical JSON + signature parity#6

Merged
sirambrosio merged 1 commit into
mainfrom
test/canonical-roundtrip
Apr 20, 2026
Merged

test(crypto): cross-SDK canonical JSON + signature parity#6
sirambrosio merged 1 commit into
mainfrom
test/canonical-roundtrip

Conversation

@sirambrosio
Copy link
Copy Markdown
Contributor

Context

Paired with bsp-sdk-typescript#12. The TS SDK was using JSON.stringify(sortedObj) while Python uses json.dumps(..., separators=(",", ":")) — risk of silent signature drift between SDKs.

Changes

  • Expose CryptoUtils.canonical_stringify() as a public helper (mirror of the TS SDK's canonicalStringify). Keep _stringify_deterministic as an alias for backward compatibility.
  • New tests/test_canonical.py:
    • 11+ test vectors byte-identical to bsp-sdk-typescript/tests/canonical-stringify.test.ts.
    • Reads the TS-generated fixture (canonical-sig.json) and verifies the signature in Python.
    • Signature parity test: Python signs the same payload with the same seed and must produce byte-identical signature bytes to the TS fixture (Ed25519 is deterministic, so drift in canonical bytes surfaces immediately).

Test plan

  • pytest tests/ — 70 tests pass locally (including all new canonical tests and cross-SDK fixture verification)
  • Vectors match TS SDK byte-for-byte
  • TS-generated signature verifies in Python
  • Python-generated signature matches TS fixture byte-for-byte

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Adds `canonical_stringify()` as a public helper on CryptoUtils so both
SDKs can produce byte-identical canonical JSON for the same input. The
existing `_stringify_deterministic` is kept as a thin alias for
backward compatibility.

Adds tests/test_canonical.py with:
- Shared test vectors (byte-identical to TS SDK)
- Cross-SDK fixture verification: reads canonical-sig.json produced by
  the TS SDK and confirms the signature verifies in Python
- Signature parity check: Python signs with the same seed and must
  produce byte-identical signature bytes to TS (proves canonical drift
  would surface immediately)

This closes the signature mismatch between TS and Python SDKs.
@sirambrosio sirambrosio merged commit 5043866 into main Apr 20, 2026
4 of 5 checks passed
@sirambrosio sirambrosio deleted the test/canonical-roundtrip branch April 20, 2026 15:34
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.

1 participant