v0.0.45 - Display qrexec service name (qubes.NsignerRpc) in signer connection info; use human-readable timestamps in activity log; fix static release build by adding miner.c to Dockerfile.alpine-musl
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
* 2. sign_event — sign a Nostr event (kind 1 text note)
|
||||
* 3. nip44_encrypt — encrypt a message to a peer (and decrypt it back)
|
||||
*
|
||||
* Note: mine_event (NIP-13 PoW) is also available via the JSON-RPC interface.
|
||||
* See demo_javascript.js and demo_python.py for mine_event usage examples.
|
||||
* The high-level nostr_signer API does not yet wrap mine_event.
|
||||
*
|
||||
* This uses the high-level nostr_signer API from nostr_core_lib:
|
||||
* - nostr_signer_nsigner_qrexec() — qrexec transport (no network)
|
||||
* - nostr_signer_nsigner_set_nostr_index() — select key by NIP-06 index
|
||||
|
||||
@@ -198,6 +198,48 @@ async function demoNip44(targetQube, nostrIndex, pubkeyHex) {
|
||||
}
|
||||
}
|
||||
|
||||
async function demoMineEvent(targetQube, nostrIndex) {
|
||||
console.log("\n--- Demo 4: mine_event (NIP-13 Proof-of-Work) ---");
|
||||
|
||||
const event = {
|
||||
kind: 1,
|
||||
content: "Hello Nostr with PoW!",
|
||||
tags: [],
|
||||
};
|
||||
|
||||
console.log(" Mining with difficulty=4, threads=4, timeout_sec=30...");
|
||||
const response = await callNsigner(targetQube, {
|
||||
id: "5",
|
||||
method: "mine_event",
|
||||
params: [JSON.stringify(event), {
|
||||
difficulty: 4,
|
||||
threads: 4,
|
||||
timeout_sec: 30,
|
||||
nostr_index: nostrIndex,
|
||||
}],
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
throw new Error(`mine_event failed: ${JSON.stringify(response.error)}`);
|
||||
}
|
||||
|
||||
const result = JSON.parse(response.result);
|
||||
console.log(` achieved_difficulty: ${result.achieved_difficulty}`);
|
||||
console.log(` target_reached: ${result.target_reached}`);
|
||||
console.log(` elapsed_sec: ${result.elapsed_sec}`);
|
||||
console.log(` attempts: ${result.attempts}`);
|
||||
|
||||
const minedEvent = JSON.parse(result.event);
|
||||
console.log(` event id: ${minedEvent.id}`);
|
||||
console.log(` nonce tag: ${JSON.stringify(minedEvent.tags[0])}`);
|
||||
|
||||
if (result.target_reached) {
|
||||
console.log(" ✓ Target difficulty reached!");
|
||||
} else {
|
||||
console.log(` (Target not reached, best effort: ${result.achieved_difficulty} bits)`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const targetQube = process.argv[2] || "nostr_signer";
|
||||
const nostrIndex = parseInt(process.argv[3] || "0", 10);
|
||||
@@ -212,6 +254,7 @@ async function main() {
|
||||
const pubkeyHex = await demoGetPublicKey(targetQube, nostrIndex);
|
||||
await demoSignEvent(targetQube, nostrIndex, pubkeyHex);
|
||||
await demoNip44(targetQube, nostrIndex, pubkeyHex);
|
||||
await demoMineEvent(targetQube, nostrIndex);
|
||||
|
||||
console.log("\n=== Summary ===");
|
||||
console.log("All demos completed successfully.");
|
||||
|
||||
@@ -227,6 +227,45 @@ def demo_nip44(target_qube, nostr_index, pubkey_hex):
|
||||
raise RuntimeError("Round-trip FAILED: plaintext does not match decrypted")
|
||||
|
||||
|
||||
def demo_mine_event(target_qube, nostr_index):
|
||||
print("\n--- Demo 4: mine_event (NIP-13 Proof-of-Work) ---")
|
||||
|
||||
event = {"kind": 1, "content": "Hello Nostr with PoW!", "tags": []}
|
||||
|
||||
print(" Mining with difficulty=4, threads=4, timeout_sec=30...")
|
||||
response = call_nsigner(
|
||||
target_qube,
|
||||
{
|
||||
"id": "5",
|
||||
"method": "mine_event",
|
||||
"params": [json.dumps(event), {
|
||||
"difficulty": 4,
|
||||
"threads": 4,
|
||||
"timeout_sec": 30,
|
||||
"nostr_index": nostr_index,
|
||||
}],
|
||||
},
|
||||
)
|
||||
|
||||
if "error" in response:
|
||||
raise RuntimeError(f"mine_event failed: {json.dumps(response['error'])}")
|
||||
|
||||
result = json.loads(response["result"])
|
||||
print(f" achieved_difficulty: {result['achieved_difficulty']}")
|
||||
print(f" target_reached: {result['target_reached']}")
|
||||
print(f" elapsed_sec: {result['elapsed_sec']}")
|
||||
print(f" attempts: {result['attempts']}")
|
||||
|
||||
mined_event = json.loads(result["event"])
|
||||
print(f" event id: {mined_event['id']}")
|
||||
print(f" nonce tag: {mined_event['tags'][0]}")
|
||||
|
||||
if result["target_reached"]:
|
||||
print(" ✓ Target difficulty reached!")
|
||||
else:
|
||||
print(f" (Target not reached, best effort: {result['achieved_difficulty']} bits)")
|
||||
|
||||
|
||||
# --- Main ---
|
||||
|
||||
def main():
|
||||
@@ -243,6 +282,7 @@ def main():
|
||||
pubkey_hex = demo_get_public_key(target_qube, nostr_index)
|
||||
demo_sign_event(target_qube, nostr_index, pubkey_hex)
|
||||
demo_nip44(target_qube, nostr_index, pubkey_hex)
|
||||
demo_mine_event(target_qube, nostr_index)
|
||||
|
||||
print("\n=== Summary ===")
|
||||
print("All demos completed successfully.")
|
||||
|
||||
Reference in New Issue
Block a user