{"id":452,"date":"2026-11-29T17:37:28","date_gmt":"2026-11-29T17:37:28","guid":{"rendered":"https:\/\/ethertrust.com\/?page_id=452"},"modified":"2026-11-29T20:55:36","modified_gmt":"2026-11-29T20:55:36","slug":"ethereum","status":"publish","type":"page","link":"https:\/\/ethertrust.com\/index.php\/ethereum\/","title":{"rendered":"Ethereum"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">About the Ethereum pNHSM Demo<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This live demonstration shows how an Ethereum transaction can be constructed and signed using an ECDSA secp256k1 private key held inside an EtherTrust Personal Network HSM (pNHSM) Secure Element. The WordPress application prepares the transaction; the Secure Element performs the signature through an end-to-end TLS 1.3 PSK-ECDHE connection. The private key never leaves the Secure Element.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How the demonstration works<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Reserve a Secure Element.<\/strong> Select an available keyx.com (or automatic selection) and click &quot;Reserve Secure Element&quot;. The shared pool prevents another EtherTrust demonstration from reserving the same device simultaneously. The console displays the allocated session time and the remaining reservation time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Generate a test key (optional).<\/strong> &quot;Replace Key 03&quot; sends c03 (erase the existing key), g03 (generate a new secp256k1 key) and p03 (read its public key). The resulting Ethereum address is calculated from that public key. If the selected key already exists, you can skip this step. Warning: c03 permanently destroys the previous key at index 03.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Configure the Ethereum transaction.<\/strong> Select EIP-1559 (Type 2) or legacy EIP-155. Enter the Chain ID, account nonce, recipient address, value in Wei, gas limit and fees. Transaction data can be entered as hexadecimal or UTF-8 text. &quot;Use address of signing key&quot; copies the address derived from p03 into the recipient field. The Network ID is informational; the Chain ID is used for signing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Prepare the transaction.<\/strong> &quot;Read Public Key &amp; Prepare&quot; reads p03 (or pXX for the selected index), encodes the unsigned transaction and computes its Keccak-256 signing digest. This 32-byte digest is the message to be signed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Sign inside the pNHSM.<\/strong> &quot;Sign with pNHSM&quot; sends s03 (or sXX) with the digest. The Secure Element returns an ECDSA signature. The plugin checks it against the public key and assembles the signed Ethereum transaction, including r, s and yParity (or v for legacy transactions).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6. Inspect and save the result.<\/strong> &quot;Inspect signed transaction&quot; decodes the transaction fields for visual review. &quot;Copy&quot; and &quot;Save&quot; preserve the raw signed transaction for use with another Ethereum client. Finally, click &quot;Release&quot; to return the Secure Element to the shared pool.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Understanding the execution trace<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The &quot;pNHSM Execution Trace&quot; lists each command (c03, g03, p03, s03, etc.), its result, and its duration in milliseconds. Each command establishes a new TLS 1.3 connection, so the trace distinguishes the handshake time (&quot;Connected in&quot;), the time after TLS, DNS lookup and total operation time. The reservation timer shows how long the Secure Element remains available to the visitor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Important: this demo constructs and signs transactions but does not broadcast them to an Ethereum network. It does not retrieve the account nonce, balance or gas fees automatically. Use test networks and disposable demonstration keys only; never use funded accounts, because visitors can replace key 03 on a reserved demo Secure Element.<\/p>\n\n\n\n\n    <div id=\"eteth-96556\" class=\"eteth-ui\">\n      <h3>Ethereum Transaction \u2014 pNHSM secp256k1<\/h3>\n      <p><small>EtherTrust Ethereum pNHSM Demo v0.1.7<\/small><\/p>\n      <p>Construct and sign an Ethereum transaction with a non-exportable Secure Element key. Signing uses TLS 1.3 PSK-ECDHE and the shared EtherTrust reservation pool. <strong>No transaction is broadcast.<\/strong><\/p>\n      <p><strong>Start here:<\/strong> select a Secure Element from the shared pool and click <strong>Reserve Secure Element<\/strong>. Optionally generate a new demo key at index 03, then enter the recipient, click <strong>Read Public Key &amp; Prepare<\/strong>, and finally <strong>Sign with pNHSM<\/strong>.<\/p>\n      <fieldset><legend>1 \u00b7 Reserve Secure Element<\/legend>\n        <label>Secure Element <select class=\"eteth-se\"><option value=\"auto\">Automatic \u2014 first available<\/option><option value=\"7\">key7.com<\/option><option value=\"8\">key8.com<\/option><option value=\"9\">key9.com<\/option><option value=\"20\">key20.com<\/option><option value=\"30\">key30.com<\/option><option value=\"31\">key31.com<\/option><option value=\"32\">key32.com<\/option><option value=\"33\">key33.com<\/option><option value=\"34\">key34.com<\/option><option value=\"35\">key35.com<\/option><option value=\"36\">key36.com<\/option><option value=\"37\">key37.com<\/option><option value=\"38\">key38.com<\/option><option value=\"39\">key39.com<\/option><option value=\"40\">key40.com<\/option><option value=\"41\">key41.com<\/option><\/select><\/label>\n        <button type=\"button\" class=\"eteth-reserve\">Reserve Secure Element<\/button> <button type=\"button\" class=\"eteth-release\" disabled>Release<\/button>\n        <div class=\"eteth-lease\" aria-live=\"polite\">No Secure Element reserved.<\/div>\n        <p><small>The session allocation comes from TLS-SE Demo settings. The shared-pool lock is refreshed during each pNHSM operation and can expire sooner when idle.<\/small><\/p>\n      <\/fieldset>\n      <fieldset><legend>2 \u00b7 Generate a key (optional)<\/legend>\n        <p><small><strong>Destructive operation:<\/strong> after reserving any Secure Element in the shared pool, this button runs <code>c03<\/code> (permanently erase the previous key 03), <code>g03<\/code> (generate a new secp256k1 key) and <code>p03<\/code> (read the public key) on <strong>that reserved SE only<\/strong>. Use disposable demo keys without funds. Key generation is limited to slot 03.<\/small><\/p>\n        <button type=\"button\" class=\"eteth-generate\" disabled>Replace Key 03 (c03 \u2192 g03)<\/button>\n        <p><small class=\"eteth-keygen-hint\" aria-live=\"polite\">Reserve a Secure Element to enable key generation for slot 03.<\/small><\/p>\n      <\/fieldset>\n      <fieldset><legend>3 \u00b7 Build unsigned transaction<\/legend>\n        <div class=\"eteth-grid\">\n          <label>pNHSM key index (hex)<input name=\"slot\" value=\"03\" maxlength=\"2\" pattern=\"[0-3][a-fA-F0-9]\" required><\/label>\n          <label>Transaction format<select name=\"type\"><option value=\"2\">EIP-1559 (Type 2)<\/option><option value=\"0\">Legacy (EIP-155)<\/option><\/select><\/label>\n          <label>Chain ID (decimal, signing)<input name=\"chain_id\" value=\"11155111\" required inputmode=\"numeric\"><\/label>\n          <label>Network ID (informational)<input name=\"network_id\" value=\"11155111\" inputmode=\"numeric\"><\/label>\n          <label>Account nonce (decimal)<input name=\"nonce\" value=\"0\" required inputmode=\"numeric\"><\/label>\n          <label>Gas limit<input name=\"gas_limit\" value=\"21000\" required inputmode=\"numeric\"><\/label>\n          <label class=\"eteth-wide\">Recipient (40 hex characters, optional 0x prefix)<input name=\"to\" value=\"\" placeholder=\"0123\u2026 or 0x0123\u2026\" maxlength=\"42\" required spellcheck=\"false\" autocomplete=\"off\"><small class=\"eteth-address-hint\" aria-live=\"polite\">Enter a 20-byte Ethereum destination address (40 hex characters).<\/small><\/label>\n          <div class=\"eteth-wide\"><button type=\"button\" class=\"eteth-use-address\" disabled>Use address of signing key (p03)<\/button> <small>Reads the selected key's public key from the reserved Secure Element and fills the Recipient field (self-transfer).<\/small><\/div>\n          <label>Value in Wei<input name=\"value_wei\" value=\"0\" required inputmode=\"numeric\"><\/label>\n          <label class=\"eteth-fee2\">Max priority fee (Gwei, integer)<input name=\"priority_gwei\" value=\"1\" inputmode=\"numeric\"><\/label>\n          <label class=\"eteth-fee2\">Max fee (Gwei, integer)<input name=\"max_fee_gwei\" value=\"2\" inputmode=\"numeric\"><\/label>\n          <label class=\"eteth-fee0\" hidden>Gas price (Gwei, integer)<input name=\"gas_price_gwei\" value=\"2\" inputmode=\"numeric\"><\/label>\n          <label class=\"eteth-wide\">Transaction data format<select name=\"data_mode\"><option value=\"hex\">Hexadecimal (0x...)<\/option><option value=\"text\">Text (UTF-8)<\/option><\/select><\/label>\n          <label class=\"eteth-wide\">Transaction data<textarea name=\"data\" rows=\"2\" spellcheck=\"false\">0x<\/textarea><small class=\"eteth-data-hint\" aria-live=\"polite\">Enter 0x followed by pairs of hexadecimal characters, or leave 0x for empty data.<\/small><\/label>\n        <\/div>\n        <p><small>The Chain ID is part of the signed Ethereum transaction. <code>net_version<\/code> (Network ID) and <code>eth_chainId<\/code> may differ. Verify nonce and fees against your actual chain; nothing is fetched automatically.<\/small><\/p>\n        <button type=\"button\" class=\"eteth-prepare\" disabled>Read Public Key &amp; Prepare<\/button> <button type=\"button\" class=\"eteth-sign\" disabled>Sign with pNHSM<\/button>\n      <\/fieldset>\n      <fieldset><legend>4 \u00b7 Results<\/legend>\n        <label>From address<input class=\"eteth-address\" readonly><\/label>\n        <label>Public key<textarea class=\"eteth-pub\" readonly rows=\"3\"><\/textarea><\/label>\n        <label>Keccak-256 signing digest<input class=\"eteth-digest\" readonly><\/label>\n        <label>Signed raw transaction (hex)<textarea class=\"eteth-raw\" readonly rows=\"5\"><\/textarea><\/label>\n        <label>Transaction hash<input class=\"eteth-txhash\" readonly><\/label>\n        <button type=\"button\" class=\"eteth-copy\" disabled>Copy signed transaction<\/button>\n        <button type=\"button\" class=\"eteth-save\" disabled>Save signed transaction<\/button>\n        <button type=\"button\" class=\"eteth-inspect\" disabled>Inspect signed transaction<\/button>\n        <section class=\"eteth-inspection\" aria-label=\"Decoded signed transaction\" hidden>\n          <h4>Decoded Ethereum transaction<\/h4>\n          <p><small>Read-only RLP decoding of the raw signed bytes, performed in your browser. The Network ID is not encoded in an Ethereum transaction; the Chain ID is. No blockchain submission or RPC verification is performed.<\/small><\/p>\n          <div class=\"eteth-inspection-fields\"><\/div>\n        <\/section>\n      <\/fieldset>\n      <fieldset><legend>5 \u00b7 pNHSM Execution Trace<\/legend>\n        <p><small>Measured at the WordPress server. Each command opens a new TLS 1.3 PSK-ECDHE connection. <strong>Connected in<\/strong> is shown only when OpenSSL reports handshake completion; otherwise \u2014 is displayed. The after-connection time includes command response and process cleanup. DNS lookup is measured separately and included in Total. No PSK, private key or signing digest is logged.<\/small><\/p>\n        <div class=\"eteth-trace-scroll\"><table class=\"eteth-trace-table\"><thead><tr><th>Time<\/th><th>Operation<\/th><th>Secure Element<\/th><th>Connected in<\/th><th>After TLS<\/th><th>DNS<\/th><th>Total<\/th><th>Result<\/th><\/tr><\/thead><tbody class=\"eteth-trace-body\"><tr><td colspan=\"8\">No operations yet.<\/td><\/tr><\/tbody><\/table><\/div>\n        <p><button type=\"button\" class=\"eteth-trace-clear\">Clear trace<\/button><\/p>\n        <div class=\"eteth-trace-summary\" aria-live=\"polite\"><\/div>\n      <\/fieldset>\n      <p class=\"eteth-status\" role=\"status\" aria-live=\"polite\">Step 1: select a Secure Element and click Reserve Secure Element.<\/p>\n      <p><small><strong>Public demonstration:<\/strong> any visitor who reserves an available Secure Element can request a signature from its selected key. Use disposable test-only keys with no real assets. <strong>Security:<\/strong> anonymous visitors may erase and regenerate key index <code>03<\/code> on any Secure Element they exclusively reserve. Do not keep funded or reusable keys in slot 03 on any publicly reservable SE. Test on a private chain or testnet before real funds. Requires PHP GMP. Signature recovery validates the Secure Element's returned signature and converts high-S to canonical low-S.<\/small><\/p>\n    <\/div>\n    <style>\n      #eteth-96556{color:inherit;max-width:980px}\n      #eteth-96556 fieldset{border:1px solid #6f7a82;border-radius:8px;padding:14px;margin:14px 0}\n      #eteth-96556 legend{font-weight:700;padding:0 6px}\n      #eteth-96556 label{display:block;margin:7px 0;font-size:.95em}\n      #eteth-96556 input,#eteth-96556 textarea,#eteth-96556 select{box-sizing:border-box;width:100%;margin-top:5px;color:#eff4f7;background:#171d24;border:1px solid #69737f;border-radius:5px;padding:8px;font:inherit}\n      #eteth-96556 input[readonly],#eteth-96556 textarea[readonly]{color:#a7d7f0;word-break:break-all}\n      #eteth-96556 button{padding:9px 13px;margin:7px 5px 7px 0;border-radius:5px;cursor:pointer;background:#dab640;color:#151515;font-weight:650;border:1px solid #d5ab36}\n      #eteth-96556 button:disabled{background:#353b41;color:#a0a5aa;border-color:#485059;cursor:default;opacity:.65}\n      #eteth-96556 .eteth-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px 14px}\n      #eteth-96556 .eteth-wide{grid-column:1\/-1}\n      #eteth-96556 .eteth-status{overflow-wrap:anywhere}\n      #eteth-96556 .eteth-trace-scroll{max-width:100%;overflow-x:auto}\n      #eteth-96556 .eteth-trace-table{width:100%;border-collapse:collapse;font-size:.84em;min-width:650px}\n      #eteth-96556 .eteth-trace-table th,#eteth-96556 .eteth-trace-table td{border-bottom:1px solid #536474;padding:6px 8px;text-align:left;white-space:nowrap}\n      #eteth-96556 .eteth-trace-summary{font-size:.9em;color:#a7d7f0}\n      #eteth-96556 .eteth-address-hint{display:block;color:#b8c5cf;margin-top:3px}\n      #eteth-96556 .eteth-inspection{margin:14px 0;padding:12px;border:1px solid #536474;border-radius:6px;max-width:100%;overflow-x:auto}\n      #eteth-96556 .eteth-inspection[hidden]{display:none!important}\n      #eteth-96556 .eteth-inspection dl{display:grid;grid-template-columns:minmax(135px,1fr) minmax(0,2fr);gap:8px 14px;margin:12px 0}\n      #eteth-96556 .eteth-inspection dt{font-weight:700;color:#b9dbe9}\n      #eteth-96556 .eteth-inspection dd{margin:0;overflow-wrap:anywhere;white-space:pre-wrap;font-family:ui-monospace,monospace;font-size:.88em}\n      @media(max-width:620px){#eteth-96556 .eteth-inspection dl{grid-template-columns:1fr;gap:3px}}\n      @media(max-width:620px){#eteth-96556 .eteth-grid{grid-template-columns:1fr}}\n    <\/style>\n    <script>\n    (()=>{\n      const root=document.getElementById(\"eteth-96556\"),ajax=\"https:\\\/\\\/ethertrust.com\\\/wp-admin\\\/admin-ajax.php\",securityNonce=\"171d12db0f\";\n      if(!root)return;\n      const $=sel=>root.querySelector(sel),get=name=>root.querySelector('[name=\"'+name+'\"]');\n      let reserved=false,prepared=false,busy=false,reservedSni='';\n      let allocatedSeconds=0, hardDeadline=0, idleDeadline=0, traceEvents=[];\n      const traceBody=$('.eteth-trace-body'), traceSummary=$('.eteth-trace-summary');\n      const formatDuration=s=>{s=Math.max(0,Math.ceil(s));return String(Math.floor(s\/60)).padStart(2,'0')+':'+String(s%60).padStart(2,'0');};\n      const nowSeconds=()=>performance.now()\/1000;\n      function resetReservation(){allocatedSeconds=0;hardDeadline=0;idleDeadline=0;}\n      function setReservation(info){\n        if(!info)return;\n        allocatedSeconds=Number(info.allocated_seconds)||0;\n        hardDeadline=nowSeconds()+(Number(info.remaining_seconds)||0);\n        idleDeadline=nowSeconds()+(Number(info.pool_lease_seconds)||0);\n      }\n      function renderReservation(){\n        if(!reserved)return;\n        const remaining=Math.max(0,Math.ceil(hardDeadline-nowSeconds()));\n        const idle=Math.max(0,Math.ceil(idleDeadline-nowSeconds()));\n        $('.eteth-lease').textContent=reservedSni+' \u00b7 Allocated '+formatDuration(allocatedSeconds)+\n          ' \u00b7 Session remaining '+formatDuration(remaining)+' \u00b7 Idle pool lease '+formatDuration(idle);\n        if((remaining===0||idle===0)&&!busy){\n          reserved=false;prepared=false;reservedSni='';resetReservation();\n          $('.eteth-lease').textContent='Reservation expired. Reserve a Secure Element again.';\n          log.textContent='Secure Element reservation expired.';\n          state();\n        }\n      }\n      function appendTraceRow(row){\n        if(traceEvents.length===0)traceBody.replaceChildren();\n        traceEvents.push(row);\n        if(traceEvents.length>120)traceEvents.shift();\n        const tr=document.createElement('tr');\n        const cells=[row.at,row.operation,row.sni,row.connected,row.after,row.dns,row.total,row.status];\n        cells.forEach(value=>{const td=document.createElement('td');td.textContent=String(value);tr.append(td);});\n        traceBody.append(tr);\n        while(traceBody.children.length>120)traceBody.firstChild.remove();\n        const totalMs=traceEvents.reduce((sum,e)=>sum+(e.elapsed||0),0);\n        traceSummary.textContent=traceEvents.length+' trace entries \u00b7 Measured total '+totalMs.toFixed(0)+' ms (includes reservation operations).';\n      }\n      function traceResponse(op,data,ok){\n        const stamp=new Date().toLocaleTimeString();\n        const name=(op==='reserve'?'Reserve SE':op==='release'?'Release SE':op);\n        const sni=(data?.sni||reservedSni||'\u2014');\n        appendTraceRow({at:stamp,operation:name,sni,connected:'\u2014',after:'\u2014',dns:'\u2014',total:(data?.elapsed_ms??'\u2014')+' ms',status:ok?'OK':'ERROR',elapsed:Number(data?.elapsed_ms)||0});\n        for(const entry of (Array.isArray(data?.trace)?data.trace:[])){\n          appendTraceRow({at:stamp,operation:entry.command,sni:entry.sni||sni,\n            connected:entry.connect_ms===null?'\u2014':entry.connect_ms+' ms',\n            after:entry.after_connect_ms===null?'\u2014':entry.after_connect_ms+' ms',\n            dns:entry.dns_ms===null?'\u2014':entry.dns_ms+' ms',\n            total:entry.total_ms+' ms',status:entry.status==='OK'?'OK \u00b7 '+(entry.reply||'Response'):('ERROR \u00b7 '+(entry.detail||'Command failed')),\n            elapsed:0});\n        }\n      }\n      setInterval(renderReservation,1000);\n      const log=$('.eteth-status');\n      const addressHint=$('.eteth-address-hint');\n      const keygenHint=$('.eteth-keygen-hint');\n      const dataHint=$('.eteth-data-hint');\n      const editable=['slot','type','chain_id','network_id','nonce','gas_limit','to','value_wei','priority_gwei','max_fee_gwei','gas_price_gwei','data_mode','data'];\n      let previousDataMode='hex';\n      function cleanAddress(value){\n        const v=value.trim();\n        if (\/^(?:0x)?[0-9a-fA-F]{40}$\/.test(v))return '0x'+v.replace(\/^0x\/i,'').toLowerCase();\n        return null;\n      }\n      function addressFeedback(){\n        const value=get('to').value.trim(),address=cleanAddress(value);\n        if (!value)addressHint.textContent='Enter a 20-byte Ethereum destination address (40 hex characters).';\n        else if (address)addressHint.textContent='Address format valid. '+(reserved?'Next: click Read Public Key & Prepare.':'First reserve your Secure Element.');\n        else addressHint.textContent='Invalid destination: enter exactly 40 hexadecimal characters (0\u20139, A\u2013F), with or without 0x.';\n      }\n      function state(){\n        $('.eteth-reserve').disabled=busy||reserved;\n        $('.eteth-release').disabled=busy||!reserved;\n        const canGenerate=reserved&&get('slot').value.trim().toUpperCase()==='03';\n        $('.eteth-generate').disabled=busy||!canGenerate;\n        $('.eteth-use-address').disabled=busy||!reserved;\n        $('.eteth-use-address').textContent='Use address of signing key (p'+get('slot').value.trim().toUpperCase()+')';\n        keygenHint.textContent=!reserved ? 'Reserve a Secure Element first.' :\n          get('slot').value.trim().toUpperCase()!=='03' ? 'Set the key index to 03 to enable generation.' :\n          'Ready on '+reservedSni+': this permanently erases and replaces key 03 and changes its Ethereum address.';\n        $('.eteth-prepare').disabled=busy||!reserved;\n        $('.eteth-sign').disabled=busy||!reserved||!prepared;\n        $('.eteth-copy').disabled=!$('.eteth-raw').value;\n        $('.eteth-save').disabled=!$('.eteth-raw').value;\n        $('.eteth-inspect').disabled=!$('.eteth-raw').value;\n      }\n      async function request(op,extra={}){\n        let body=new URLSearchParams({action:'eteth_action',security:securityNonce,op,...extra});\n        const res=await fetch(ajax,{method:'POST',credentials:'same-origin',body,headers:{'Content-Type':'application\/x-www-form-urlencoded','X-Requested-With':'XMLHttpRequest'},cache:'no-store'});\n        let json;try{json=await res.json();}catch(e){throw Error('Server did not return valid JSON.');}\n        if(!json.success){const e=new Error(json.data?.message || 'Operation failed.');e.detail=json.data||{};throw e;}\n        return json.data;\n      }\n      async function run(op,payload,success){busy=true;state();log.textContent='Working: '+op+'\u2026';\n        try{const d=await request(op,payload);traceResponse(op,d,true);if(d.reservation){setReservation(d.reservation);}success(d);log.textContent=d.message||'Completed.';renderReservation();}\n        catch(e){\n          traceResponse(op,e.detail||{},false);\n          if(e.detail?.reservation)setReservation(e.detail.reservation);\n          else if(\/reservation.*expired|session expired\/i.test(e.message)){\n            reserved=false;prepared=false;reservedSni='';resetReservation();\n            $('.eteth-lease').textContent='Reservation expired. Reserve a Secure Element again.';\n          }\n          log.textContent=e.message;renderReservation();\n        }\n        finally{busy=false;state();}\n      }\n      get('type').addEventListener('change',()=>{\n        const legacy=get('type').value==='0';\n        $('.eteth-fee0').hidden=!legacy;\n        root.querySelectorAll('.eteth-fee2').forEach(x=>x.hidden=legacy);\n      });\n      function clearInspection(){\n        $('.eteth-inspection').hidden=true;\n        $('.eteth-inspection-fields').replaceChildren();\n        $('.eteth-inspect').textContent='Inspect signed transaction';\n      }\n      function invalidatePrepared(){\n        prepared=false;$('.eteth-raw').value='';$('.eteth-txhash').value='';$('.eteth-digest').value='';\n        clearInspection();\n      }\n      function dataFeedback(){\n        const mode=get('data_mode').value, value=get('data').value;\n        if(mode==='text'){\n          const bytes=new TextEncoder().encode(value);\n          dataHint.textContent='UTF-8 text: '+bytes.length+' \/ 1024 bytes. The exact UTF-8 bytes are included in the signed transaction'+(bytes.length>1024?' (too long).':'.');\n        }else{\n          const hex=value.trim();\n          if(!\/^0x(?:[0-9a-fA-F]{2})*$\/.test(hex)){\n            dataHint.textContent='Invalid hex: use 0x followed by pairs of hex digits (e.g. 0x48656c6c6f).';\n          }else{\n            const length=(hex.length-2)\/2;\n            dataHint.textContent='Hexadecimal payload: '+length+' \/ 1024 bytes'+(length>1024?' (too long).':'.');\n          }\n        }\n      }\n      editable.forEach(name=>get(name).addEventListener('input',()=>{\n        invalidatePrepared();\n        if(name==='slot'){$('.eteth-address').value='';$('.eteth-pub').value='';}\n        addressFeedback();dataFeedback();state();\n      }));\n      get('data_mode').addEventListener('change',()=>{\n        const next=get('data_mode').value, input=get('data');\n        if(next===previousDataMode)return;\n        if(next==='hex'){\n          input.value='0x'+Array.from(new TextEncoder().encode(input.value),b=>b.toString(16).padStart(2,'0')).join('');\n        }else{\n          const hex=input.value.trim();\n          if(!\/^0x(?:[0-9a-fA-F]{2})*$\/.test(hex)){\n            get('data_mode').value=previousDataMode;\n            log.textContent='Correct the hexadecimal data before switching to text.';\n            dataFeedback();return;\n          }\n          try{\n            const bytes=new Uint8Array((hex.slice(2).match(\/.{2}\/g)||[]).map(h=>parseInt(h,16)));\n            input.value=new TextDecoder('utf-8',{fatal:true}).decode(bytes);\n          }catch(e){\n            get('data_mode').value=previousDataMode;\n            log.textContent='These bytes are not valid UTF-8. Keep Hex mode for arbitrary binary data.';\n            dataFeedback();return;\n          }\n        }\n        previousDataMode=next;\n        invalidatePrepared();dataFeedback();state();\n      });\n      get('to').addEventListener('blur',()=>{\n        const address=cleanAddress(get('to').value);\n        if(address)get('to').value=address;\n        addressFeedback();\n      });\n      function clearTransactionResults(){\n        prepared=false;\n        $('.eteth-address').value='';$('.eteth-pub').value='';\n        $('.eteth-digest').value='';$('.eteth-raw').value='';$('.eteth-txhash').value='';\n        clearInspection();\n      }\n      $('.eteth-reserve').onclick=()=>run('reserve',{se:$('.eteth-se').value},d=>{reserved=true;reservedSni=d.sni;clearTransactionResults();addressFeedback();});\n      $('.eteth-release').onclick=()=>run('release',{},d=>{reserved=false;reservedSni='';resetReservation();clearTransactionResults();$('.eteth-lease').textContent='No Secure Element reserved.';addressFeedback();});\n      $('.eteth-generate').onclick=()=>{\n        if(!reserved || get('slot').value.trim().toUpperCase()!=='03')return;\n        \/\/ A public key in slot 03 may belong to another application\/user.\n        \/\/ Require an explicit action before irreversible erasure.\n        if(!window.confirm('Replace key 03 on '+reservedSni+'? This permanently erases the previous private key and its Ethereum address cannot be recovered.'))return;\n        \/\/ Clear displayed signed artifacts immediately: the key is about to be replaced.\n        clearTransactionResults();state();\n        run('generate',{slot:get('slot').value.trim()},d=>{\n          $('.eteth-address').value=d.address;\n          $('.eteth-pub').value=d.public_key;\n        });\n      };\n      $('.eteth-use-address').onclick=()=>run('read_address',{slot:get('slot').value.trim()},d=>{\n        invalidatePrepared();\n        get('to').value=d.address;\n        $('.eteth-address').value=d.address;\n        $('.eteth-pub').value=d.public_key;\n        addressFeedback();\n      });\n      $('.eteth-prepare').onclick=()=>{\n        const address=cleanAddress(get('to').value);\n        if(!address){log.textContent='Invalid recipient: use 40 hexadecimal characters, optionally prefixed with 0x.';get('to').focus();addressFeedback();return;}\n        get('to').value=address;\n        const fields={};editable.forEach(n=>fields[n]=get(n).value);\n        run('prepare',fields,d=>{clearInspection();prepared=true;$('.eteth-address').value=d.address;$('.eteth-pub').value=d.public_key;$('.eteth-digest').value=d.digest;$('.eteth-raw').value='';$('.eteth-txhash').value='';});\n      };\n      $('.eteth-sign').onclick=()=>run('sign',{},d=>{prepared=false;clearInspection();$('.eteth-raw').value=d.signed_transaction;$('.eteth-txhash').value=d.transaction_hash;});\n      $('.eteth-trace-clear').onclick=()=>{\n        traceEvents=[];traceBody.replaceChildren();\n        const tr=document.createElement('tr'),td=document.createElement('td');\n        td.colSpan=8;td.textContent='No operations yet.';tr.append(td);traceBody.append(tr);\n        traceSummary.textContent='';\n      };\n      \/\/ Browser-only Ethereum RLP decoder for visual inspection of transactions\n      \/\/ produced by this demo. Does not verify blockchain state or rebroadcast.\n      function etethDecodeSignedRlp(raw){\n        if(!\/^0x(?:[\\da-fA-F]{2})+$\/.test(raw)||raw.length>16386)\n          throw Error('Expected a 0x-prefixed even-length hexadecimal transaction (max 8192 bytes).');\n        const bytes=Uint8Array.from(raw.slice(2).match(\/.{2}\/g),h=>parseInt(h,16));\n        let type='Legacy (EIP-155)', start=0;\n        if(bytes[0]===2){type='EIP-1559 (Type 2)';start=1;}\n        else if(bytes[0]<0xc0)throw Error('Unsupported or invalid transaction type; expected Type 2 or legacy RLP.');\n        function getLength(at,count){\n          if(count<1||count>4||at+count>bytes.length||bytes[at]===0)\n            throw Error('Malformed RLP length.');\n          let n=0;\n          for(let i=0;i<count;i++)n=n*256+bytes[at+i];\n          if(!Number.isSafeInteger(n)||n>8192)throw Error('RLP length too large.');\n          return n;\n        }\n        function readItem(at,depth){\n          if(at>=bytes.length||depth>5)throw Error('Truncated or nested RLP payload.');\n          const prefix=bytes[at];\n          let off=at+1,len=0,list=false;\n          if(prefix<0x80)return [bytes.slice(at,at+1),at+1];\n          if(prefix<=0xb7)len=prefix-0x80;\n          else if(prefix<=0xbf){const n=prefix-0xb7;len=getLength(off,n);off+=n;if(len<56)throw Error('Noncanonical RLP string length.');}\n          else if(prefix<=0xf7){len=prefix-0xc0;list=true;}\n          else{const n=prefix-0xf7;len=getLength(off,n);off+=n;list=true;if(len<56)throw Error('Noncanonical RLP list length.');}\n          const end=off+len;\n          if(end>bytes.length)throw Error('Truncated RLP field.');\n          if(!list){\n            if(len===1&&bytes[off]<0x80)throw Error('Noncanonical RLP single byte.');\n            return [bytes.slice(off,end),end];\n          }\n          const values=[];\n          while(off<end){const [child,next]=readItem(off,depth+1);if(next>end)throw Error('RLP list overflow.');values.push(child);off=next;}\n          return [values,end];\n        }\n        const [fields,end]=readItem(start,0);\n        if(end!==bytes.length||!Array.isArray(fields))throw Error('RLP outer list is malformed.');\n        const toHex=b=>'0x'+Array.from(b,v=>v.toString(16).padStart(2,'0')).join('');\n        const strInt=b=>{\n          if(!(b instanceof Uint8Array))throw Error('Expected a numeric RLP scalar.');\n          if(b.length>0&&b[0]===0)throw Error('Noncanonical Ethereum integer.');\n          return b.length?BigInt(toHex(b)):0n;\n        };\n        const asInt=b=>strInt(b).toString();\n        const hex32=b=>{\n          if(!(b instanceof Uint8Array)||b.length<1||b.length>32)throw Error('Invalid ECDSA scalar length.');\n          return '0x'+toHex(b).slice(2).padStart(64,'0');\n        };\n        const fmtUnits=(x,places)=>{\n          const unit=10n**BigInt(places),whole=x\/unit,frac=x%unit;\n          if(frac===0n)return whole.toString();\n          return whole.toString()+'.'+frac.toString().padStart(places,'0').replace(\/0+$\/,'');\n        };\n        const recipient=b=>{\n          if(!(b instanceof Uint8Array)||![0,20].includes(b.length))throw Error('Invalid destination length.');\n          return b.length===0?'(contract creation)':toHex(b);\n        };\n        const payload=b=>{\n          if(!(b instanceof Uint8Array))throw Error('Invalid transaction input data.');\n          return toHex(b);\n        };\n        const inputText=b=>{\n          if(!b.length)return '(empty)';\n          try{\n            const txt=new TextDecoder('utf-8',{fatal:true}).decode(b);\n            return \/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]\/.test(txt)?'(binary data \u2014 not printable UTF-8)':txt;\n          }catch(e){return '(binary data \u2014 not valid UTF-8)';}\n        };\n        const output=[['Transaction type',type],['Length',bytes.length+' bytes']];\n        const put=(label,value)=>output.push([label,String(value)]);\n        let data;\n        if(start===1){\n          if(fields.length!==12)throw Error('A signed EIP-1559 transaction must have exactly 12 fields.');\n          const [chain,nonce,priority,maxFee,gas,to,value,input,access,parity,r,s]=fields;\n          if(!Array.isArray(access))throw Error('Invalid EIP-1559 access list.');\n          const y=strInt(parity);\n          if(y!==0n&&y!==1n)throw Error('Invalid EIP-1559 yParity.');\n          put('Chain ID',asInt(chain));\n          put('Account nonce',asInt(nonce));\n          put('Max priority fee (Wei)',asInt(priority));\n          put('Max priority fee (Gwei)',fmtUnits(strInt(priority),9));\n          put('Max fee per gas (Wei)',asInt(maxFee));\n          put('Max fee per gas (Gwei)',fmtUnits(strInt(maxFee),9));\n          put('Gas limit',asInt(gas));\n          put('Recipient (to)',recipient(to));\n          put('Value (Wei)',asInt(value));\n          put('Value (ETH)',fmtUnits(strInt(value),18));\n          data=input;\n          put('Access list entries',access.length);\n          put('Signature yParity',y);\n          put('Signature r',hex32(r));\n          put('Signature s',hex32(s));\n        }else{\n          if(fields.length!==9)throw Error('A signed legacy Ethereum transaction must have exactly 9 fields.');\n          const [nonce,price,gas,to,value,input,v,r,s]=fields;\n          const V=strInt(v);\n          if(V<35n)throw Error('This viewer expects an EIP-155 replay-protected legacy signature.');\n          put('Chain ID',((V-35n)\/2n).toString());\n          put('Account nonce',asInt(nonce));\n          put('Gas price (Wei)',asInt(price));\n          put('Gas price (Gwei)',fmtUnits(strInt(price),9));\n          put('Gas limit',asInt(gas));\n          put('Recipient (to)',recipient(to));\n          put('Value (Wei)',asInt(value));\n          put('Value (ETH)',fmtUnits(strInt(value),18));\n          data=input;\n          put('Signature v (EIP-155)',V);\n          put('Signature yParity',((V-35n)%2n).toString());\n          put('Signature r',hex32(r));\n          put('Signature s',hex32(s));\n        }\n        put('Data length',data.length+' bytes');\n        put('Data (hex)',payload(data));\n        put('Data (UTF-8 preview)',inputText(data));\n        put('Network ID','Not stored in the signed transaction');\n        return output;\n      }\n      $('.eteth-inspect').onclick=()=>{\n        const pane=$('.eteth-inspection'),fields=$('.eteth-inspection-fields');\n        if(!pane.hidden){clearInspection();return;}\n        try{\n          const items=etethDecodeSignedRlp($('.eteth-raw').value);\n          const dl=document.createElement('dl');\n          for(const [label,value] of items){\n            const dt=document.createElement('dt'),dd=document.createElement('dd');\n            dt.textContent=label;dd.textContent=value;\n            dl.append(dt,dd);\n          }\n          fields.replaceChildren(dl);\n          pane.hidden=false;\n          $('.eteth-inspect').textContent='Hide decoded transaction';\n          pane.scrollIntoView({block:'nearest',behavior:'smooth'});\n        }catch(e){clearInspection();log.textContent='Cannot decode signed transaction: '+e.message;}\n      };\n\n      $('.eteth-copy').onclick=async()=>{try{await navigator.clipboard.writeText($('.eteth-raw').value);log.textContent='Signed raw transaction copied.';}catch(e){log.textContent='Clipboard unavailable; select and copy the signed transaction.';}};\n      $('.eteth-save').onclick=()=>{const data=$('.eteth-raw').value;if(!data)return;const url=URL.createObjectURL(new Blob([data+'\\n'],{type:'text\/plain'}));const a=document.createElement('a');a.href=url;a.download='pnhsm-ethereum-signed-transaction.txt';root.append(a);a.click();a.remove();setTimeout(()=>URL.revokeObjectURL(url),2000);};\n      state();addressFeedback();dataFeedback();\n    })();\n    <\/script>\n    \n","protected":false},"excerpt":{"rendered":"<p>About the Ethereum pNHSM Demo This live demonstration shows how an Ethereum transaction can be constructed and signed using an ECDSA secp256k1 private key held inside an EtherTrust Personal Network HSM (pNHSM) Secure Element. The WordPress application prepares the transaction; the Secure Element performs the signature through an end-to-end TLS 1.3 PSK-ECDHE connection. The private [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-452","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/pages\/452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/comments?post=452"}],"version-history":[{"count":2,"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/pages\/452\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/pages\/452\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/ethertrust.com\/index.php\/wp-json\/wp\/v2\/media?parent=452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}