v0.1.24 - Migrate Teensy 4.1 signer to role+path authorization model (deprecate nostr_index)

This commit is contained in:
Laan Tungir
2026-08-08 13:55:02 -04:00
parent fd895db0c9
commit 0b1c3ea382
19 changed files with 2493 additions and 74 deletions
+39 -24
View File
@@ -388,8 +388,10 @@
<!-- Nostr Get Public Key -->
<section class="divPostItem section">
<h2>nostr_get_public_key</h2>
<label for="ngpkIdx">nostr_index</label>
<input id="ngpkIdx" type="number" value="0" min="0" class="inpStyle" />
<label for="ngpkRole">role</label>
<input id="ngpkRole" value="main" class="inpStyle" />
<label for="ngpkPath">role_path</label>
<input id="ngpkPath" value="m/44'/1237'/0'/0/0" class="inpStyle" />
<label for="ngpkFmt">format</label>
<select id="ngpkFmt" class="inpStyle"><option>bare</option><option>structured</option></select>
<div class="row">
@@ -465,8 +467,10 @@
<h2>nostr_sign_event</h2>
<label for="nseContent">content</label>
<textarea id="nseContent" class="inpStyle">hello from usb test</textarea>
<label for="nseIdx">nostr_index</label>
<input id="nseIdx" type="number" value="0" min="0" class="inpStyle" />
<label for="nseRole">role</label>
<input id="nseRole" value="main" class="inpStyle" />
<label for="nsePath">role_path</label>
<input id="nsePath" value="m/44'/1237'/0'/0/0" class="inpStyle" />
<div class="row">
<button id="nseBtn" class="btn" disabled>nostr_sign_event</button>
</div>
@@ -479,8 +483,10 @@
<p class="warn">Slow on ESP32 — uses single-threaded PoW. Keep difficulty low.</p>
<label for="nmeContent">content</label>
<textarea id="nmeContent" class="inpStyle">mined by usb test</textarea>
<label for="nmeIdx">nostr_index</label>
<input id="nmeIdx" type="number" value="0" min="0" class="inpStyle" />
<label for="nmeRole">role</label>
<input id="nmeRole" value="main" class="inpStyle" />
<label for="nmePath">role_path</label>
<input id="nmePath" value="m/44'/1237'/0'/0/0" class="inpStyle" />
<label for="nmeDiff">difficulty (leading zero bits)</label>
<input id="nmeDiff" type="number" value="4" min="1" max="16" class="inpStyle" />
<label for="nmeTimeout">timeout (sec)</label>
@@ -500,8 +506,10 @@
<textarea id="nip04Msg" class="inpStyle">hello via nip04</textarea>
<label for="nip04Cipher">ciphertext (for decrypt)</label>
<textarea id="nip04Cipher" class="inpStyle" placeholder="ciphertext?iv=..."></textarea>
<label for="nip04Idx">nostr_index</label>
<input id="nip04Idx" type="number" value="0" min="0" class="inpStyle" />
<label for="nip04Role">role</label>
<input id="nip04Role" value="main" class="inpStyle" />
<label for="nip04Path">role_path</label>
<input id="nip04Path" value="m/44'/1237'/0'/0/0" class="inpStyle" />
<div class="row">
<button id="nip04EncBtn" class="btn" disabled>encrypt</button>
<button id="nip04DecBtn" class="btn" disabled>decrypt</button>
@@ -518,8 +526,10 @@
<textarea id="nip44Msg" class="inpStyle">hello via nip44</textarea>
<label for="nip44Cipher">ciphertext (for decrypt)</label>
<textarea id="nip44Cipher" class="inpStyle" placeholder="base64 payload"></textarea>
<label for="nip44Idx">nostr_index</label>
<input id="nip44Idx" type="number" value="0" min="0" class="inpStyle" />
<label for="nip44Role">role</label>
<input id="nip44Role" value="main" class="inpStyle" />
<label for="nip44Path">role_path</label>
<input id="nip44Path" value="m/44'/1237'/0'/0/0" class="inpStyle" />
<div class="row">
<button id="nip44EncBtn" class="btn" disabled>encrypt</button>
<button id="nip44DecBtn" class="btn" disabled>decrypt</button>
@@ -788,8 +798,9 @@
callVerb("get_public_key", [{ algorithm: alg, index: idx }], $("gpkOut"));
});
$("ngpkBtn").addEventListener("click", () => {
const idx = Number($("ngpkIdx").value || 0), fmt = $("ngpkFmt").value;
const opts = { nostr_index: idx };
const role = $("ngpkRole").value.trim(), path = $("ngpkPath").value.trim();
const fmt = $("ngpkFmt").value;
const opts = { role, role_path: path };
if (fmt === "structured") opts.format = "structured";
callVerb("nostr_get_public_key", [opts], $("ngpkOut"));
});
@@ -846,24 +857,25 @@
$("nseBtn").addEventListener("click", () => {
const content = $("nseContent").value;
const idx = Number($("nseIdx").value || 0);
const role = $("nseRole").value.trim(), path = $("nsePath").value.trim();
const event = { kind: 1, created_at: Math.floor(Date.now()/1000), tags: [], content };
callVerb("nostr_sign_event", [event, { nostr_index: idx }], $("nseOut"));
callVerb("nostr_sign_event", [event, { role, role_path: path }], $("nseOut"));
});
$("nmeBtn").addEventListener("click", () => {
const content = $("nmeContent").value;
const idx = Number($("nmeIdx").value || 0);
const role = $("nmeRole").value.trim(), path = $("nmePath").value.trim();
const diff = Number($("nmeDiff").value || 4);
const timeout = Number($("nmeTimeout").value || 30);
const event = { kind: 1, created_at: Math.floor(Date.now()/1000), tags: [], content };
callVerb("nostr_mine_event", [event, { nostr_index: idx, difficulty: diff, timeout_sec: timeout }], $("nmeOut"));
callVerb("nostr_mine_event", [event, { role, role_path: path, difficulty: diff, timeout_sec: timeout }], $("nmeOut"));
});
const nip04Enc = async () => {
const peer = $("nip04Peer").value.trim(), msg = $("nip04Msg").value, idx = Number($("nip04Idx").value || 0);
const peer = $("nip04Peer").value.trim(), msg = $("nip04Msg").value;
const role = $("nip04Role").value.trim(), path = $("nip04Path").value.trim();
if (!peer) { $("nip04Out").textContent = "✗ enter peer pubkey"; return; }
const params = [peer, msg, { nostr_index: idx }];
const params = [peer, msg, { role, role_path: path }];
$("nip04Out").textContent = "→ nostr_nip04_encrypt " + JSON.stringify(params);
try {
const auth = await buildAuth("nostr_nip04_encrypt", params);
@@ -877,17 +889,19 @@
}
};
const nip04Dec = () => {
const peer = $("nip04Peer").value.trim(), ct = $("nip04Cipher").value, idx = Number($("nip04Idx").value || 0);
const peer = $("nip04Peer").value.trim(), ct = $("nip04Cipher").value;
const role = $("nip04Role").value.trim(), path = $("nip04Path").value.trim();
if (!peer || !ct) { $("nip04Out").textContent = "✗ enter peer pubkey + ciphertext"; return; }
callVerb("nostr_nip04_decrypt", [peer, ct, { nostr_index: idx }], $("nip04Out"));
callVerb("nostr_nip04_decrypt", [peer, ct, { role, role_path: path }], $("nip04Out"));
};
$("nip04EncBtn").addEventListener("click", nip04Enc);
$("nip04DecBtn").addEventListener("click", nip04Dec);
const nip44Enc = async () => {
const peer = $("nip44Peer").value.trim(), msg = $("nip44Msg").value, idx = Number($("nip44Idx").value || 0);
const peer = $("nip44Peer").value.trim(), msg = $("nip44Msg").value;
const role = $("nip44Role").value.trim(), path = $("nip44Path").value.trim();
if (!peer) { $("nip44Out").textContent = "✗ enter peer pubkey"; return; }
const params = [peer, msg, { nostr_index: idx }];
const params = [peer, msg, { role, role_path: path }];
$("nip44Out").textContent = "→ nostr_nip44_encrypt " + JSON.stringify(params);
try {
const auth = await buildAuth("nostr_nip44_encrypt", params);
@@ -901,9 +915,10 @@
}
};
const nip44Dec = () => {
const peer = $("nip44Peer").value.trim(), ct = $("nip44Cipher").value, idx = Number($("nip44Idx").value || 0);
const peer = $("nip44Peer").value.trim(), ct = $("nip44Cipher").value;
const role = $("nip44Role").value.trim(), path = $("nip44Path").value.trim();
if (!peer || !ct) { $("nip44Out").textContent = "✗ enter peer pubkey + ciphertext"; return; }
callVerb("nostr_nip44_decrypt", [peer, ct, { nostr_index: idx }], $("nip44Out"));
callVerb("nostr_nip44_decrypt", [peer, ct, { role, role_path: path }], $("nip44Out"));
};
$("nip44EncBtn").addEventListener("click", nip44Enc);
$("nip44DecBtn").addEventListener("click", nip44Dec);