DEV Community

Malek
Malek

Posted on Originally published at janzeer.org on

Five SDKs, one conformance kit: keeping five languages byte for byte the same

The last article ended on a risk: Janzeer keys and signatures are made in the user's own software, never by the node, so that software has to get every byte right. There are five official SDKs, a web wallet, a mobile wallet, a game and a command-line client. That is nine places where the same cryptography is written again in another language.

This article is about the small public repository that keeps those nine in step: janzeer-sdk-conformance.

Why "almost the same" is not good enough

A Janzeer transaction is signed over an exact sequence of bytes: the network id, the timestamp, the fee, the nonce, the sender, then the payload. The node rebuilds that sequence from the fields it receives, hashes it twice with SHA-256 and checks the signature. One byte of difference and the transaction is rejected.

The places where languages quietly disagree are well known:

  • Rounding. An amount has eight decimals and is signed as a whole number of units. 0.123456785 must become 12345679, rounded half up. A language that rounds half to even, or goes through a floating-point number, signs a different amount.
  • Integer width and byte order. Every number in the signed bytes is eight bytes, big-endian. JavaScript has no 64-bit integer by default; Dart on the web has none either.
  • Signatures. The node expects a deterministic signature (RFC 6979), in its low-S form, DER-encoded, then Base64. Most libraries can produce four or five variants of "an ECDSA signature".
  • Key derivation. As the last article showed, the derivation looks like the Bitcoin and Ethereum one but uses the chain's own constants, so a standard library produces a valid-looking but wrong address.

None of these fail loudly. They produce a transaction that looks fine and is refused, or an address that looks fine and belongs to nobody.

One file of vectors, made by the node

The answer is one JSON file, 6.7 KB, generated by a test in the node itself from the node's own cryptography. The node is the only judge of what is valid on the network, so it is also the only author of the expected values. It holds:

  • one recovery phrase with its seed, private key, public key and address, so the whole derivation path is pinned;
  • one raw private key with its address;
  • three addresses in lowercase and in their mixed-case display form;
  • six amounts with their scaled values, including the rounding case above and the smallest unit, 0.00000001;
  • six signed transactions, one for every kind a client can send: a transfer with a memo, a transfer without one, a validator registration, a validator exit, a token creation and a token transfer. Each comes with its fields, the exact signed bytes in hex, the hash and the signature.

A second, smaller file is an encrypted wallet blob with its password, so that a wallet saved by one SDK opens in the other four.

Every SDK carries a copy of both files in its tests and must reproduce every value exactly: the same 136 signed bytes for the first transfer, the same hash, the same signature. Nothing is compared "approximately".

Stopping the copies from drifting

Nine copies of a file is nine chances for one to go stale. Two things prevent it:

  • The kit publishes a SHA256SUMS file. Each SDK checks its copy against those checksums in CI, so an edited or outdated vector file fails the build.
  • When the node's cryptography or a transaction layout changes, one script regenerates the vectors from the node, copies them to all nine consumers and refreshes the checksums. A change that reaches only some of them cannot be committed quietly, because the check fails in the rest.

You can run the same check yourself. The jz command-line client ships the vectors inside its binary:

$ jz vectors check
  ...
  ok scaled amounts
  ok transferTx
  ok transferNoMemoTx
  ...
  ok tokenTransferTx
  ok vault fixture decrypts

14 of 14 checks passed (vendored vectors v2)

Enter fullscreen mode Exit fullscreen mode

The second half: one flow against a real network

Vectors prove that an SDK can produce the right bytes. They do not prove that it can talk to a node. So the kit also defines a flow of 14 steps that every SDK implements as a test against a real four-validator network on a developer machine. In short:

  1. Derive the test wallet and check its address.
  2. Read the node's version and network id, and sign for that network.
  3. Read the balance and the next nonce.
  4. Open a WebSocket to a different node than the one the transaction will be sent to, and subscribe to the recipient's address.
  5. Build and sign a transfer, submit it, then submit the same transaction again by the other API and check that it is accepted once, not twice.
  6. Wait until it is final, then check the sender's balance to the last unit: the old balance minus the amount minus the fee, compared as exact decimals.
  7. Check that the notification arrived over the WebSocket, which proves the block travelled between nodes.
  8. Three deliberate failures: a nonce that skips ahead, a signature copied from another transaction, a malformed address. Each must be refused with the specific error the SDK documents.

Each SDK's README quickstart is the same flow, trimmed. The documentation is therefore code that runs before every release. A release goes out only when the vectors and all 14 steps pass in that language.

What the kit did not catch

It would be easy to stop here and call the SDKs proven. Three bugs from the past weeks say otherwise, and each one was outside what the kit measures.

Digits that were not digits. The Python SDK's amount check used a pattern that, in Python, also matches Arabic-Indic and other Unicode digits. An amount typed as ١٠ was accepted, normalised and signed as 10. The vectors only contain ASCII digits, so they passed. A code review found it; the fix accepts ASCII digits only.

A method nobody called. The TypeScript SDK's getGenesis() threw on every call against a real node from the day it was added, because it expected a different answer shape. The 14 steps never call that method, so the flow stayed green. It was found when an outside contributor's pull request made us run the call against mainnet. The Dart SDK now has a test for every typed method.

Behaviour over time. After a dropped connection, a WebSocket subscription asked the node to replay blocks from its original starting height instead of resuming where it stopped. No vector and no single clean run shows that; it took a review of the reconnect code in all five SDKs.

The lesson we took is narrow: the kit proves the bytes and one honest path through the API. It does not replace tests for each method, reviews, or running real code against the live network. It only makes sure that when those find a problem, the problem is not in the cryptography.

Using it for your own client

The kit is public under Apache-2.0 and contains no node code. If you are writing a Janzeer client in a language we do not cover, copy the two vector files into your tests, reproduce every value, and implement the 14 steps. When all of that is green, your client signs exactly what the node expects.

Today the chain is past block 270,000 with seven validators. Next: jz, the command-line client that fits in a 38 MB native binary.


Every number here is from the live chain and the public repositories, and the text is mine. JNZ is the network's unit, it is not listed anywhere, and nothing here is financial advice.

Top comments (0)