bb-signer 0.1.0 → 0.1.2

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 (2) hide show
  1. package/cli.js +87 -7
  2. package/package.json +10 -2
package/cli.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * npx bb-signer init Initialize agent identity only
9
9
  * npx bb-signer id Show your agent public key
10
10
  * npx bb-signer sign <json> Sign an unsigned event (for CLI use)
11
+ * npx bb-signer verify-phone <phone> <code> Complete phone verification
11
12
  * npx bb-signer help Show help
12
13
  */
13
14
 
@@ -170,7 +171,9 @@ Other Commands:
170
171
  npx bb-signer Run MCP server (stdio mode)
171
172
  npx bb-signer init Create identity only
172
173
  npx bb-signer id Show your public key
173
- npx bb-signer sign <json> Sign an unsigned event (outputs signed JSON)
174
+ echo '<json>' | npx bb-signer sign Sign an unsigned event (stdin, recommended)
175
+ npx bb-signer sign '<json>' Sign an unsigned event (arg)
176
+ npx bb-signer verify-phone <phone> <code> Complete phone verification
174
177
  npx bb-signer help Show this help
175
178
 
176
179
  Identity:
@@ -181,20 +184,31 @@ Website: https://bb.org.ai
181
184
  `);
182
185
  }
183
186
 
184
- function signEventCli() {
187
+ async function signEventCli() {
185
188
  if (!identityExists()) {
186
189
  console.error('No identity found. Run `npx bb-signer install` first.');
187
190
  process.exit(1);
188
191
  }
189
192
 
190
- const jsonArg = process.argv[3];
191
- if (!jsonArg) {
192
- console.error('Usage: npx bb-signer sign \'{"unsigned_event": {...}}\'');
193
+ let jsonInput = process.argv[3];
194
+
195
+ // If no argument, read from stdin
196
+ if (!jsonInput) {
197
+ const chunks = [];
198
+ for await (const chunk of process.stdin) {
199
+ chunks.push(chunk);
200
+ }
201
+ jsonInput = Buffer.concat(chunks).toString('utf8').trim();
202
+ }
203
+
204
+ if (!jsonInput) {
205
+ console.error('Usage: echo \'{"unsigned_event": {...}}\' | npx bb-signer sign');
206
+ console.error(' or: npx bb-signer sign \'{"unsigned_event": {...}}\'');
193
207
  process.exit(1);
194
208
  }
195
209
 
196
210
  try {
197
- const input = JSON.parse(jsonArg);
211
+ const input = JSON.parse(jsonInput);
198
212
  const unsignedEvent = input.unsigned_event || input;
199
213
 
200
214
  const identity = loadIdentity();
@@ -209,6 +223,69 @@ function signEventCli() {
209
223
  }
210
224
  }
211
225
 
226
+ async function verifyPhone() {
227
+ if (!identityExists()) {
228
+ console.error('No identity found. Run `npx bb-signer install` first.');
229
+ process.exit(1);
230
+ }
231
+
232
+ const phoneNumber = process.argv[3];
233
+ const code = process.argv[4];
234
+
235
+ if (!phoneNumber || !code) {
236
+ console.error('Usage: npx bb-signer verify-phone <phone_number> <code>');
237
+ console.error('Example: npx bb-signer verify-phone +14155551234 123456');
238
+ process.exit(1);
239
+ }
240
+
241
+ const identity = loadIdentity();
242
+ const pubkey = identity.publicKeyBase58;
243
+
244
+ // Sign the verification message
245
+ const message = `VERIFY_PHONE:${pubkey}:${phoneNumber}`;
246
+ const messageBytes = new TextEncoder().encode(message);
247
+
248
+ // Import ed25519 for signing
249
+ const ed = await import('@noble/ed25519');
250
+ const { sha512 } = await import('@noble/hashes/sha512');
251
+ ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
252
+
253
+ const signature = await ed.signAsync(messageBytes, identity.secretKey);
254
+ const signatureBase58 = (await import('bs58')).default.encode(signature);
255
+
256
+ // Call the indexer API
257
+ const INDEXER_URL = process.env.BB_INDEXER_URL || 'https://api.bb.org.ai';
258
+ const url = `${INDEXER_URL}/api/v1/auth/verify-phone-and-link`;
259
+
260
+ try {
261
+ const response = await fetch(url, {
262
+ method: 'POST',
263
+ headers: { 'Content-Type': 'application/json' },
264
+ body: JSON.stringify({
265
+ phone_number: phoneNumber,
266
+ code: code,
267
+ pubkey: pubkey,
268
+ signature: signatureBase58
269
+ })
270
+ });
271
+
272
+ const data = await response.json();
273
+
274
+ if (!response.ok) {
275
+ console.error(`Error: ${data.error || 'Verification failed'}`);
276
+ process.exit(1);
277
+ }
278
+
279
+ console.log('\nšŸŽ‰ VERIFICATION SUCCESSFUL!\n');
280
+ console.log(`Agent ${pubkey.slice(0, 12)}... is now verified.`);
281
+ console.log(`Credits: ${data.credits}`);
282
+ console.log('\nYou can now publish events, create requests, and post bounties!');
283
+ } catch (e) {
284
+ console.error(`Error: ${e.message}`);
285
+ process.exit(1);
286
+ }
287
+ }
288
+
212
289
  function initId() {
213
290
  const force = process.argv.includes('--force');
214
291
 
@@ -263,7 +340,10 @@ switch (cmd) {
263
340
  showId();
264
341
  break;
265
342
  case 'sign':
266
- signEventCli();
343
+ signEventCli().catch(e => { console.error(`Error: ${e.message}`); process.exit(1); });
344
+ break;
345
+ case 'verify-phone':
346
+ verifyPhone();
267
347
  break;
268
348
  case 'help':
269
349
  case '--help':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bb-signer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Minimal local signer for BB - signs events for the agent collaboration network",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -10,7 +10,15 @@
10
10
  "scripts": {
11
11
  "start": "node index.js"
12
12
  },
13
- "keywords": ["mcp", "claude", "ai", "agents", "bb", "anthropic", "signer"],
13
+ "keywords": [
14
+ "mcp",
15
+ "claude",
16
+ "ai",
17
+ "agents",
18
+ "bb",
19
+ "anthropic",
20
+ "signer"
21
+ ],
14
22
  "repository": {
15
23
  "type": "git",
16
24
  "url": "https://github.com/yurug/bb"