nostr-bray 1.29.2 → 1.29.4

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.
package/dist/cli.js CHANGED
@@ -377,6 +377,7 @@ async function run(cmdArgs) {
377
377
  break;
378
378
  case 'switch':
379
379
  await ctx.switch(req(1, 'switch <target> [index]'), cmdArgs[2] ? parseInt(cmdArgs[2], 10) : undefined);
380
+ console.error(`Now signing as ${ctx.activeNpub}`);
380
381
  console.log(ctx.activeNpub);
381
382
  break;
382
383
  case 'prove':
@@ -49,10 +49,30 @@ export class HeartwoodContext extends BunkerContext {
49
49
  ? [purposeOrName, String(index)]
50
50
  : [purposeOrName];
51
51
  const raw = await this.signer.sendRequest('heartwood_switch', params);
52
- // The server returns { npub } — decode it to refresh the local pubkey cache
53
- // (BunkerSigner caches getPublicKey() so we cannot rely on it after a switch)
54
- const { npub } = JSON.parse(raw);
55
- const { decode } = await import('nostr-tools/nip19');
52
+ // Parse response — device may return { npub } object or a bare npub string
53
+ const { decode, npubEncode } = await import('nostr-tools/nip19');
54
+ let npub;
55
+ try {
56
+ const parsed = JSON.parse(raw);
57
+ if (typeof parsed === 'string') {
58
+ npub = parsed;
59
+ }
60
+ else if (parsed && typeof parsed.npub === 'string') {
61
+ npub = parsed.npub;
62
+ }
63
+ else if (parsed && typeof parsed.pubkey === 'string') {
64
+ // Some devices return { pubkey: hex }
65
+ npub = npubEncode(parsed.pubkey);
66
+ }
67
+ }
68
+ catch {
69
+ // raw may itself be a bare npub (no JSON wrapping)
70
+ if (typeof raw === 'string' && raw.startsWith('npub1'))
71
+ npub = raw;
72
+ }
73
+ if (!npub) {
74
+ throw new Error(`heartwood_switch returned unexpected response: ${JSON.stringify(raw)}`);
75
+ }
56
76
  const decoded = decode(npub);
57
77
  if (decoded.type === 'npub') {
58
78
  this.pubkeyHex = decoded.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-bray",
3
- "version": "1.29.2",
3
+ "version": "1.29.4",
4
4
  "mcpName": "dev.forgesworn/bray",
5
5
  "description": "Trust-aware Nostr for AI and humans. Three dimensions of trust -- verification, proximity, and access -- woven into every interaction.",
6
6
  "type": "module",