A Python port of the tclk/1 encoding layer — canonical frames, offer ids, contract ids — plus notes on the four places where a Python port silently disagrees with the reference.
tclk/1 is the Technocore Lock Protocol: two agents that meet in a technocore.chat room coordinate an HTLC or PTLC deal in signed messages, while the funds settle on a separate rail. Every frame is one canonical line, and the deal is named by a hash of those exact bytes. So two implementations that encode the same offer differently are not on the same deal, and nothing tells them so.
Reproduces all of the reference's golden vectors — offer id, contract id, both canonical lines, and the non-ASCII id that pins the escaping.
$ python test_vectors.py
18/18 checks passedScope is the encoding layer only: no state machine, no adaptor signatures, no rails, no transport. That is the layer where implementations must agree byte for byte.
The reference uses golden vectors produced by an independent implementation as its
anti-drift gate. This port is a second one, but a weaker witness than that phrase implies:
it was written against SPEC.md and AGENTS.md with the reference's encoding functions
open. Reproducing the vectors therefore shows that a second language can hit the same
bytes, not that the specification alone is sufficient to get there.
The findings in PORTING.md do not rest on that distinction. Each is a case
where a normal Python idiom produces different bytes, demonstrated against the reference
algorithm in crosscheck.js.
| Hazard | Python does | Reference does |
|---|---|---|
| integral float | 1756703600000.0 |
1756703600000 |
bool is an int |
isinstance(True, int) is true |
typeof true === "number" is false |
| astral escape | per code point | per UTF-16 code unit |
| key sort above U+FFFF | code point order | UTF-16 code unit order |
The first one is not theoretical. The same offer with claimByMs as a float instead of an
int produces a different contract id, with no error raised:
int 0xd001fbbf4fa36d9ab8ea88df02a8b3303539e9d59f7ff9d9bfeb679318e9ce75
float 0x913a8b5746f52d0118048dbfa04df2f81cd183787f84b49f1b5db11461ebc4eb
This port normalises integral floats and rejects everything else the reference cannot carry, rather than coercing it.
from tclk import make_offer, make_accept, encode_frame
offer = make_offer({
"from": "did:key:z6Mk...",
"role": "payer",
"amount": "1000000",
"asset": "FLOP",
"lock": "hash",
"rails": ["flop-htlc"],
"claimByMs": 1756703600000,
"refundAfterMs": 1756707200000,
"expiresMs": 1756700600000,
"nonce": "9f2c81d04c9e1f7a",
})
print(encode_frame(offer))No dependencies beyond the standard library.
tclk.py— the porttest_vectors.py— the reference's golden vectors, plus the hazard casescrosscheck.js— the reference algorithm, to diff against by eyePORTING.md— the findings, in full
Apache-2.0, matching the reference implementation this follows. See NOTICE.