<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Ftpc_challenge.py</id>
	<title>The Principia Machina/TPC-PY/tpc challenge.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Ftpc_challenge.py"/>
	<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_challenge.py&amp;action=history"/>
	<updated>2026-10-21T05:57:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_challenge.py&amp;diff=4203&amp;oldid=prev</id>
		<title>BFP Rauch: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_challenge.py&amp;diff=4203&amp;oldid=prev"/>
		<updated>2026-09-28T04:37:36Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:37, 28 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key pma_cutover_20261020t051351z-soft_:diff:1.41:old-4202:rev-4203 --&gt;
&lt;/table&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_challenge.py&amp;diff=4202&amp;oldid=prev</id>
		<title>BFP Rauch: TPC-PY source tpc_challenge.py (0.1.0), SHA-256 b577b3d5d226b0a8; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_challenge.py&amp;diff=4202&amp;oldid=prev"/>
		<updated>2026-09-27T15:43:18Z</updated>

		<summary type="html">&lt;p&gt;TPC-PY source tpc_challenge.py (0.1.0), SHA-256 b577b3d5d226b0a8; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;# -*- coding: utf-8 -*-&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
TPC-PY --- the execution challenge (D101.1, slot 4d)&lt;br /&gt;
====================================================&lt;br /&gt;
TPX attests an agent&amp;#039;s EXECUTED mode with a fresh challenge at petition and&lt;br /&gt;
on every push: it sends a random nonce, the agent returns the challenge&lt;br /&gt;
response computed by executed code, and TPX checks it with TPC-PHP. A&lt;br /&gt;
right answer is recorded EXECUTED (with the location the agent declared);&lt;br /&gt;
a wrong or missing one is recorded REASONED, and every value that push&lt;br /&gt;
presents is refused.&lt;br /&gt;
&lt;br /&gt;
WHAT IT ATTESTS. That the agent executes code reproducing TPC&amp;#039;s digest.&lt;br /&gt;
Not which code, and not that every presented value came from it: TPX&amp;#039;s&lt;br /&gt;
recomputation of each presented value (TPS 5.3.9) still covers that.&lt;br /&gt;
&lt;br /&gt;
THE FORM&lt;br /&gt;
  nonce     exactly 32 lowercase hexadecimal characters: 128 bits that&lt;br /&gt;
            TPX draws from a cryptographic random source. The nonce is&lt;br /&gt;
            untrusted input arriving in an API response, so it is checked&lt;br /&gt;
            before use; the strict form means it can carry no text.&lt;br /&gt;
  response  digest_fields([CHALLENGE_TAG, CHALLENGE_FORM, nonce]) on the&lt;br /&gt;
            ratified D97.1 primitive (SHA-256 over the netstring of the&lt;br /&gt;
            ordered fields; lowercase hex). The tag separates this digest&lt;br /&gt;
            from every other TPC digest; the form number lets a later&lt;br /&gt;
            challenge form be told apart.&lt;br /&gt;
&lt;br /&gt;
REFUSED, as [&amp;quot;REFUSED&amp;quot;, reason], never raised; the reason never quotes the&lt;br /&gt;
input:  &amp;quot;nonce is not 32 lowercase hexadecimal characters&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Standard library only; Python 3.8+; Windows/Linux.&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import hmac&lt;br /&gt;
import re&lt;br /&gt;
&lt;br /&gt;
import tpc_digest as G&lt;br /&gt;
&lt;br /&gt;
TPC_CHALLENGE_VERSION = &amp;quot;0.1.0&amp;quot;&lt;br /&gt;
CHALLENGE_TAG = &amp;quot;TPC-EXECUTION-CHALLENGE&amp;quot;&lt;br /&gt;
CHALLENGE_FORM = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
_NONCE = re.compile(r&amp;quot;[0-9a-f]{32}\Z&amp;quot;)&lt;br /&gt;
_HEX64 = re.compile(r&amp;quot;[0-9a-f]{64}\Z&amp;quot;)&lt;br /&gt;
_BAD_NONCE = &amp;quot;nonce is not 32 lowercase hexadecimal characters&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _nonce_ok(nonce):&lt;br /&gt;
    return isinstance(nonce, str) and _NONCE.match(nonce) is not None&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def challenge_preimage(nonce):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The exact bytes hashed, as text (auditable), or [&amp;quot;REFUSED&amp;quot;, reason].&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if not _nonce_ok(nonce):&lt;br /&gt;
        return [&amp;quot;REFUSED&amp;quot;, _BAD_NONCE]&lt;br /&gt;
    return [&amp;quot;OK&amp;quot;, G.preimage_fields([CHALLENGE_TAG, CHALLENGE_FORM, nonce]).decode(&amp;quot;ascii&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def challenge_response(nonce):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The agent&amp;#039;s side: [&amp;quot;OK&amp;quot;, 64-char lowercase hex] or [&amp;quot;REFUSED&amp;quot;, reason].&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if not _nonce_ok(nonce):&lt;br /&gt;
        return [&amp;quot;REFUSED&amp;quot;, _BAD_NONCE]&lt;br /&gt;
    return [&amp;quot;OK&amp;quot;, G.digest_fields([CHALLENGE_TAG, CHALLENGE_FORM, nonce])]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def challenge_verify(nonce, response):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;TPX&amp;#039;s side: True only for a well-formed nonce and the exact lowercase&lt;br /&gt;
    response. Any malformed input is False, never an exception.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if not _nonce_ok(nonce):&lt;br /&gt;
        return False&lt;br /&gt;
    if not isinstance(response, str) or _HEX64.match(response) is None:&lt;br /&gt;
        return False&lt;br /&gt;
    expected = G.digest_fields([CHALLENGE_TAG, CHALLENGE_FORM, nonce])&lt;br /&gt;
    return hmac.compare_digest(expected, response)&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
</feed>