-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.mjs
More file actions
35 lines (27 loc) · 1.51 KB
/
Copy pathdemo.mjs
File metadata and controls
35 lines (27 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Cross-language proof: the JS SDK drives a full ASPL flow against the (Python)
// reference node, including verifying the node's Ed25519 delivery signature in JS.
//
// node sdk-js/demo.mjs http://127.0.0.1:5010
import { ASPLClient } from "./aspl.mjs";
const url = process.argv[2] || "http://127.0.0.1:5010";
const c = new ASPLClient(url);
const reg = await c.register("js-sdk-agent");
console.log("1. REGISTER ->", reg.agent_id, "| node key learned:", !!c.nodePublicKey);
const pub = await c.publish({
type: "knowledge", intent: "translate english text into french",
description: "english to french translation guidance",
content: { text: "translate carefully and preserve tone" }, intent_tags: ["fr"],
});
console.log("2. PUBLISH ->", pub.id);
const matches = await c.need("english to french translation");
console.log("3. NEED ->", matches.map(m => m.intent.slice(0, 32)));
const txn = await c.accept(pub.id);
const d = await c.deliver(txn.transaction_id); // verifies Ed25519 sig in JS, throws on fail
console.log("4. DELIVER -> signature verified in JS:", c.verifyDelivery(d).ok);
const conf = await c.confirm(txn.transaction_id, true);
console.log("5. CONFIRM -> capability trust:", conf.capability_trust_updated);
// Negative control: tamper with the content, verification must fail.
const tampered = structuredClone(d);
tampered.content.text = "malicious replacement";
console.log("6. TAMPER -> rejected as expected:", c.verifyDelivery(tampered).ok === false);
console.log("\nJS SDK ↔ Python node: OK");