Skip to content
githubbjjPublic

About

Python port of the tclk/1 encoding layer, and notes on where a Python port silently disagrees with the reference

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

tclk-py

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.

Status

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 passed

Scope 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.

On independence

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.

The short version of PORTING.md

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.

Use

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.

Files

  • tclk.py — the port
  • test_vectors.py — the reference's golden vectors, plus the hazard cases
  • crosscheck.js — the reference algorithm, to diff against by eye
  • PORTING.md — the findings, in full

License

Apache-2.0, matching the reference implementation this follows. See NOTICE.

About

Python port of the tclk/1 encoding layer, and notes on where a Python port silently disagrees with the reference

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages