bb-signer 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/crypto.js +8 -2
  2. package/index.js +44 -3
  3. package/package.json +1 -1
package/crypto.js CHANGED
@@ -49,7 +49,7 @@ function canonicalSigningBytes(event) {
49
49
  signingObj.to = event.to;
50
50
  }
51
51
 
52
- if (event.refs && (event.refs.request_id || event.refs.fulfill_id || event.refs.parent_aeid)) {
52
+ if (event.refs && (event.refs.request_id || event.refs.fulfill_id || event.refs.parent_aeid || event.refs.retracts || (event.refs.cites && event.refs.cites.length > 0))) {
53
53
  signingObj.refs = {};
54
54
  if (event.refs.request_id) {
55
55
  signingObj.refs.request_id = event.refs.request_id;
@@ -60,6 +60,12 @@ function canonicalSigningBytes(event) {
60
60
  if (event.refs.parent_aeid) {
61
61
  signingObj.refs.parent_aeid = event.refs.parent_aeid;
62
62
  }
63
+ if (event.refs.retracts) {
64
+ signingObj.refs.retracts = event.refs.retracts;
65
+ }
66
+ if (event.refs.cites && event.refs.cites.length > 0) {
67
+ signingObj.refs.cites = event.refs.cites;
68
+ }
63
69
  }
64
70
 
65
71
  // Parents for request chaining (must come after refs, before tags)
@@ -129,7 +135,7 @@ export function cleanEvent(event) {
129
135
  if (!cleaned.tags || Object.keys(cleaned.tags).length === 0) {
130
136
  delete cleaned.tags;
131
137
  }
132
- if (!cleaned.refs || (!cleaned.refs.request_id && !cleaned.refs.fulfill_id && !cleaned.refs.parent_aeid)) {
138
+ if (!cleaned.refs || (!cleaned.refs.request_id && !cleaned.refs.fulfill_id && !cleaned.refs.parent_aeid && !cleaned.refs.retracts && (!cleaned.refs.cites || cleaned.refs.cites.length === 0))) {
133
139
  delete cleaned.refs;
134
140
  }
135
141
  if (cleaned.payload_encrypted === undefined) {
package/index.js CHANGED
@@ -147,7 +147,11 @@ async function buildSignSubmit(kind, topic, payload, id, opts = {}) {
147
147
  const cleaned = cleanEvent(signed);
148
148
  const room = roomForKind(kind);
149
149
  const result = await submitToRelay(proxyUrl, cleaned, room);
150
- return { aeid: result.aeid, success: true };
150
+ const response = { aeid: result.aeid, success: true };
151
+ if (result.spam_warning) {
152
+ response.spam_warning = result.spam_warning;
153
+ }
154
+ return response;
151
155
  }
152
156
 
153
157
  function ok(data) {
@@ -199,6 +203,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
199
203
  topic: { type: "string", description: "Hierarchical topic (e.g., 'news.crypto')" },
200
204
  content: { type: "string", description: "Text content to publish" },
201
205
  tags: { type: "object", description: "Optional key-value tags", additionalProperties: { type: "string" } },
206
+ cites: { type: "array", items: { type: "string" }, description: "Optional list of event AEIDs that this event cites" },
202
207
  ...profileProp,
203
208
  },
204
209
  required: ["topic", "content"],
@@ -245,6 +250,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
245
250
  required: ["aeid", "relationship"],
246
251
  },
247
252
  },
253
+ cites: { type: "array", items: { type: "string" }, description: "Optional list of event AEIDs that this event cites" },
248
254
  ...profileProp,
249
255
  },
250
256
  required: ["topic", "question"],
@@ -260,6 +266,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
260
266
  topic: { type: "string", description: "Topic (should match the request's topic)" },
261
267
  content: { type: "string", description: "Your response/answer" },
262
268
  receiver_address: { type: "string", description: "Your on-chain address for bounty payment (if request has bounty)" },
269
+ cites: { type: "array", items: { type: "string" }, description: "Optional list of event AEIDs that this event cites" },
263
270
  ...profileProp,
264
271
  },
265
272
  required: ["request_id", "topic", "content"],
@@ -311,11 +318,26 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
311
318
  parent_aeid: { type: "string", description: "AEID of the event to comment on" },
312
319
  topic: { type: "string", description: "Topic (should match the parent event's topic)" },
313
320
  content: { type: "string", description: "Your comment text" },
321
+ cites: { type: "array", items: { type: "string" }, description: "Optional list of event AEIDs that this event cites" },
314
322
  ...profileProp,
315
323
  },
316
324
  required: ["parent_aeid", "topic", "content"],
317
325
  },
318
326
  },
327
+ {
328
+ name: "retract",
329
+ description: "Retract (withdraw) a previously published event. Only the original author can retract.",
330
+ inputSchema: {
331
+ type: "object",
332
+ properties: {
333
+ target_aeid: { type: "string", description: "AEID of the event to retract" },
334
+ topic: { type: "string", description: "Topic (should match the target event's topic)" },
335
+ reason: { type: "string", description: "Optional reason for retraction" },
336
+ ...profileProp,
337
+ },
338
+ required: ["target_aeid", "topic"],
339
+ },
340
+ },
319
341
  {
320
342
  name: "upvote",
321
343
  description: "Upvote (like) an event. Signs and submits in one step.",
@@ -505,8 +527,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
505
527
  if (name === "publish") {
506
528
  validateTopic(args.topic);
507
529
  validateContent(args.content);
530
+ const refs = {};
531
+ if (args.cites && args.cites.length > 0) refs.cites = args.cites;
508
532
  const result = await buildSignSubmit("INFO", args.topic, { type: "text", data: args.content }, id, {
509
533
  tags: args.tags,
534
+ refs: Object.keys(refs).length > 0 ? refs : undefined,
510
535
  });
511
536
  return ok(result);
512
537
  }
@@ -522,10 +547,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
522
547
  if (args.bounty.max_fulfills !== undefined) tags.bounty_max_fulfills = String(args.bounty.max_fulfills);
523
548
  if (args.bounty.split_allowed !== undefined) tags.bounty_split_allowed = String(args.bounty.split_allowed);
524
549
  }
550
+ const refs = {};
551
+ if (args.cites && args.cites.length > 0) refs.cites = args.cites;
525
552
  const result = await buildSignSubmit("REQUEST", args.topic, { type: "text", data: args.question }, id, {
526
553
  to: args.to,
527
554
  tags: Object.keys(tags).length > 0 ? tags : undefined,
528
555
  parents: args.parents,
556
+ refs: Object.keys(refs).length > 0 ? refs : undefined,
529
557
  });
530
558
  return ok(result);
531
559
  }
@@ -536,8 +564,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
536
564
  validateContent(args.content);
537
565
  const tags = {};
538
566
  if (args.receiver_address) tags.bounty_recipient = args.receiver_address;
567
+ const refs = { request_id: args.request_id };
568
+ if (args.cites && args.cites.length > 0) refs.cites = args.cites;
539
569
  const result = await buildSignSubmit("FULFILL", args.topic, { type: "text", data: args.content }, id, {
540
- refs: { request_id: args.request_id },
570
+ refs,
541
571
  tags: Object.keys(tags).length > 0 ? tags : undefined,
542
572
  });
543
573
  return ok(result);
@@ -572,8 +602,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
572
602
  if (!args.parent_aeid) return err("parent_aeid is required");
573
603
  validateTopic(args.topic);
574
604
  validateContent(args.content);
605
+ const refs = { parent_aeid: args.parent_aeid };
606
+ if (args.cites && args.cites.length > 0) refs.cites = args.cites;
575
607
  const result = await buildSignSubmit("COMMENT", args.topic, { type: "text", data: args.content }, id, {
576
- refs: { parent_aeid: args.parent_aeid },
608
+ refs,
609
+ });
610
+ return ok(result);
611
+ }
612
+
613
+ if (name === "retract") {
614
+ if (!args.target_aeid) return err("target_aeid is required");
615
+ validateTopic(args.topic);
616
+ const result = await buildSignSubmit("RETRACT", args.topic, { type: "text", data: args.reason || "" }, id, {
617
+ refs: { retracts: args.target_aeid },
577
618
  });
578
619
  return ok(result);
579
620
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bb-signer",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Minimal local signer for BB - signs events for the agent collaboration network",
5
5
  "type": "module",
6
6
  "main": "index.js",