nostr-bray 1.29.2 → 1.29.3

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':
@@ -36,7 +36,12 @@ export class HeartwoodContext extends BunkerContext {
36
36
  /** Derive a named persona on the Heartwood device. */
37
37
  async derivePersona(name, index) {
38
38
  const result = await this.signer.sendRequest('heartwood_derive_persona', [name, String(index)]);
39
- return JSON.parse(result);
39
+ const identity = JSON.parse(result);
40
+ // Log purpose so we can verify it matches nostr:persona:{name} convention
41
+ if (identity.purpose && identity.purpose !== `nostr:persona:${name}`) {
42
+ console.error(`[heartwood] note: device returned purpose "${identity.purpose}", bray uses "nostr:persona:${name}"`);
43
+ }
44
+ return identity;
40
45
  }
41
46
  /** List all known identities on the Heartwood device. */
42
47
  async listIdentities() {
@@ -49,10 +54,30 @@ export class HeartwoodContext extends BunkerContext {
49
54
  ? [purposeOrName, String(index)]
50
55
  : [purposeOrName];
51
56
  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');
57
+ // Parse response — device may return { npub } object or a bare npub string
58
+ const { decode, npubEncode } = await import('nostr-tools/nip19');
59
+ let npub;
60
+ try {
61
+ const parsed = JSON.parse(raw);
62
+ if (typeof parsed === 'string') {
63
+ npub = parsed;
64
+ }
65
+ else if (parsed && typeof parsed.npub === 'string') {
66
+ npub = parsed.npub;
67
+ }
68
+ else if (parsed && typeof parsed.pubkey === 'string') {
69
+ // Some devices return { pubkey: hex }
70
+ npub = npubEncode(parsed.pubkey);
71
+ }
72
+ }
73
+ catch {
74
+ // raw may itself be a bare npub (no JSON wrapping)
75
+ if (typeof raw === 'string' && raw.startsWith('npub1'))
76
+ npub = raw;
77
+ }
78
+ if (!npub) {
79
+ throw new Error(`heartwood_switch returned unexpected response: ${JSON.stringify(raw)}`);
80
+ }
56
81
  const decoded = decode(npub);
57
82
  if (decoded.type === 'npub') {
58
83
  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.3",
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",