nostr-bray 1.9.0 → 1.9.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.
- package/dist/cli.js +8 -0
- package/dist/context.d.ts +7 -2
- package/dist/context.js +43 -9
- package/dist/identity/migration.js +18 -13
- package/dist/relay/handlers.js +1 -1
- package/dist/social/handlers.js +3 -3
- package/dist/social/notifications.js +3 -1
- package/dist/zap/handlers.js +3 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -652,6 +652,14 @@ async function shell() {
|
|
|
652
652
|
continue;
|
|
653
653
|
}
|
|
654
654
|
const shellArgs = parseShellLine(trimmed);
|
|
655
|
+
// Per-command help in shell
|
|
656
|
+
if (shellArgs.includes('--help') && shellArgs[0]) {
|
|
657
|
+
const h = getCommandHelp(shellArgs[0]);
|
|
658
|
+
if (h) {
|
|
659
|
+
console.log(h);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
655
663
|
try {
|
|
656
664
|
await run(shellArgs);
|
|
657
665
|
}
|
package/dist/context.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ export declare class IdentityContext {
|
|
|
10
10
|
private activeEntry;
|
|
11
11
|
private maxCacheSize;
|
|
12
12
|
constructor(secretKey: string, format: 'nsec' | 'hex' | 'mnemonic', opts?: ContextOptions);
|
|
13
|
-
/** Current active identity's npub */
|
|
13
|
+
/** Current active identity's npub (bech32) */
|
|
14
14
|
get activeNpub(): string;
|
|
15
|
+
/** Current active identity's hex public key — use this in relay filters */
|
|
16
|
+
get activePublicKeyHex(): string;
|
|
15
17
|
/** Derive a child identity by purpose and index */
|
|
16
18
|
derive(purpose: string, index: number): PublicIdentity;
|
|
17
19
|
/** Derive a named persona */
|
|
@@ -22,8 +24,11 @@ export declare class IdentityContext {
|
|
|
22
24
|
getSigningFunction(): SignFn;
|
|
23
25
|
/** List all known identities — returns public info only, never private keys */
|
|
24
26
|
listIdentities(): PublicIdentity[];
|
|
25
|
-
/** Create a linkage proof for the active identity
|
|
27
|
+
/** Create a linkage proof for the active identity.
|
|
28
|
+
* Only works for derived identities — the master IS the raw key, not a tree child. */
|
|
26
29
|
prove(mode?: 'blind' | 'full'): LinkageProof;
|
|
30
|
+
/** Get the nsec-tree root's master pubkey (the derivation anchor, distinct from the raw key's pubkey) */
|
|
31
|
+
get treeRootPubkey(): string;
|
|
27
32
|
/** Get the active identity's private key for NIP-17/44/04 crypto operations */
|
|
28
33
|
get activePrivateKey(): Uint8Array;
|
|
29
34
|
/** Test helper — returns reference to private key bytes for verifying zeroise */
|
package/dist/context.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { fromNsec, fromMnemonic, derive, zeroise } from 'nsec-tree';
|
|
2
2
|
import { derivePersona } from 'nsec-tree/persona';
|
|
3
3
|
import { createBlindProof, createFullProof } from 'nsec-tree/proof';
|
|
4
|
-
import { finalizeEvent } from 'nostr-tools/pure';
|
|
4
|
+
import { finalizeEvent, getPublicKey } from 'nostr-tools/pure';
|
|
5
|
+
import { decode, npubEncode, nsecEncode } from 'nostr-tools/nip19';
|
|
6
|
+
/** Build an Identity-compatible object from raw key bytes */
|
|
7
|
+
function rawIdentity(privateKey) {
|
|
8
|
+
const publicKeyHex = getPublicKey(privateKey);
|
|
9
|
+
const publicKey = Buffer.from(publicKeyHex, 'hex');
|
|
10
|
+
return {
|
|
11
|
+
nsec: nsecEncode(privateKey),
|
|
12
|
+
npub: npubEncode(publicKeyHex),
|
|
13
|
+
privateKey: new Uint8Array(privateKey), // copy so original can be cleaned
|
|
14
|
+
publicKey: new Uint8Array(publicKey),
|
|
15
|
+
purpose: 'master',
|
|
16
|
+
index: 0,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
5
19
|
export class IdentityContext {
|
|
6
20
|
root;
|
|
7
21
|
cache = new Map();
|
|
@@ -10,30 +24,42 @@ export class IdentityContext {
|
|
|
10
24
|
maxCacheSize;
|
|
11
25
|
constructor(secretKey, format, opts) {
|
|
12
26
|
this.maxCacheSize = opts?.maxCache ?? 5;
|
|
27
|
+
// Parse the raw secret key bytes — this IS the user's actual Nostr identity
|
|
28
|
+
let rawKeyBytes;
|
|
13
29
|
if (format === 'mnemonic') {
|
|
30
|
+
// Mnemonic: create tree root, derive a "default" identity as master
|
|
14
31
|
this.root = fromMnemonic(secretKey);
|
|
32
|
+
const derived = derive(this.root, 'master', 0);
|
|
33
|
+
this.masterEntry = { identity: derived, purpose: 'master', index: 0, lastUsed: Date.now() };
|
|
34
|
+
this.activeEntry = this.masterEntry;
|
|
35
|
+
return;
|
|
15
36
|
}
|
|
16
37
|
else if (format === 'hex') {
|
|
17
|
-
|
|
18
|
-
this.root = fromNsec(bytes);
|
|
38
|
+
rawKeyBytes = Buffer.from(secretKey, 'hex');
|
|
19
39
|
}
|
|
20
40
|
else {
|
|
21
|
-
|
|
41
|
+
// nsec bech32
|
|
42
|
+
rawKeyBytes = decode(secretKey).data;
|
|
22
43
|
}
|
|
23
|
-
//
|
|
24
|
-
const masterIdentity = derive(this.root, 'master', 0);
|
|
44
|
+
// Master identity = the user's actual keypair (their real npub)
|
|
25
45
|
this.masterEntry = {
|
|
26
|
-
identity:
|
|
46
|
+
identity: rawIdentity(rawKeyBytes),
|
|
27
47
|
purpose: 'master',
|
|
28
48
|
index: 0,
|
|
29
49
|
lastUsed: Date.now(),
|
|
30
50
|
};
|
|
31
51
|
this.activeEntry = this.masterEntry;
|
|
52
|
+
// nsec-tree root for child derivation
|
|
53
|
+
this.root = fromNsec(rawKeyBytes);
|
|
32
54
|
}
|
|
33
|
-
/** Current active identity's npub */
|
|
55
|
+
/** Current active identity's npub (bech32) */
|
|
34
56
|
get activeNpub() {
|
|
35
57
|
return this.activeEntry.identity.npub;
|
|
36
58
|
}
|
|
59
|
+
/** Current active identity's hex public key — use this in relay filters */
|
|
60
|
+
get activePublicKeyHex() {
|
|
61
|
+
return Buffer.from(this.activeEntry.identity.publicKey).toString('hex');
|
|
62
|
+
}
|
|
37
63
|
/** Derive a child identity by purpose and index */
|
|
38
64
|
derive(purpose, index) {
|
|
39
65
|
// Return from cache if already derived
|
|
@@ -127,14 +153,22 @@ export class IdentityContext {
|
|
|
127
153
|
}
|
|
128
154
|
return result;
|
|
129
155
|
}
|
|
130
|
-
/** Create a linkage proof for the active identity
|
|
156
|
+
/** Create a linkage proof for the active identity.
|
|
157
|
+
* Only works for derived identities — the master IS the raw key, not a tree child. */
|
|
131
158
|
prove(mode = 'blind') {
|
|
159
|
+
if (this.activeEntry === this.masterEntry) {
|
|
160
|
+
throw new Error('Cannot prove master identity — it is the raw key, not a derived child. Switch to a derived identity first.');
|
|
161
|
+
}
|
|
132
162
|
const child = this.activeEntry.identity;
|
|
133
163
|
if (mode === 'full') {
|
|
134
164
|
return createFullProof(this.root, child);
|
|
135
165
|
}
|
|
136
166
|
return createBlindProof(this.root, child);
|
|
137
167
|
}
|
|
168
|
+
/** Get the nsec-tree root's master pubkey (the derivation anchor, distinct from the raw key's pubkey) */
|
|
169
|
+
get treeRootPubkey() {
|
|
170
|
+
return this.root.masterPubkey;
|
|
171
|
+
}
|
|
138
172
|
/** Get the active identity's private key for NIP-17/44/04 crypto operations */
|
|
139
173
|
get activePrivateKey() {
|
|
140
174
|
return this.activeEntry.identity.privateKey;
|
|
@@ -67,18 +67,23 @@ export async function handleIdentityMigrate(ctx, pool, args) {
|
|
|
67
67
|
}
|
|
68
68
|
// Execute migration: re-sign migratable events
|
|
69
69
|
await handleIdentityRestore(ctx, pool, backup);
|
|
70
|
-
// Publish linkage proof connecting old → new
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
[
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
// Publish linkage proof connecting old → new (only if operating as a derived identity)
|
|
71
|
+
try {
|
|
72
|
+
const proof = ctx.prove('full');
|
|
73
|
+
const sign = ctx.getSigningFunction();
|
|
74
|
+
const proofEvent = await sign({
|
|
75
|
+
kind: 30078,
|
|
76
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
77
|
+
tags: [
|
|
78
|
+
['d', `migration:${args.oldPubkeyHex}`],
|
|
79
|
+
['p', args.oldPubkeyHex],
|
|
80
|
+
],
|
|
81
|
+
content: JSON.stringify(proof),
|
|
82
|
+
});
|
|
83
|
+
await pool.publish(args.oldNpub, proofEvent);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Master identity can't produce tree proofs — migration proceeds without linkage proof
|
|
87
|
+
}
|
|
83
88
|
return { status: 'migrated', summary };
|
|
84
89
|
}
|
package/dist/relay/handlers.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function handleRelaySet(ctx, pool, args) {
|
|
|
18
18
|
// Check for existing relay list
|
|
19
19
|
const existing = await pool.query(ctx.activeNpub, {
|
|
20
20
|
kinds: [10002],
|
|
21
|
-
authors: [ctx.
|
|
21
|
+
authors: [ctx.activePublicKeyHex],
|
|
22
22
|
});
|
|
23
23
|
// Build r-tags
|
|
24
24
|
const tags = args.relays.map(r => {
|
package/dist/social/handlers.js
CHANGED
|
@@ -90,7 +90,7 @@ export async function handleSocialProfileSet(ctx, pool, args) {
|
|
|
90
90
|
// Check for existing profile
|
|
91
91
|
const existing = await pool.query(ctx.activeNpub, {
|
|
92
92
|
kinds: [0],
|
|
93
|
-
authors: [ctx.
|
|
93
|
+
authors: [ctx.activePublicKeyHex], // simplified — in production, use hex pubkey
|
|
94
94
|
});
|
|
95
95
|
if (existing.length > 0 && !args.confirm) {
|
|
96
96
|
// Build diff
|
|
@@ -154,7 +154,7 @@ export async function handleContactsFollow(ctx, pool, args) {
|
|
|
154
154
|
// Fetch existing contacts
|
|
155
155
|
const existing = await pool.query(ctx.activeNpub, {
|
|
156
156
|
kinds: [3],
|
|
157
|
-
authors: [ctx.
|
|
157
|
+
authors: [ctx.activePublicKeyHex],
|
|
158
158
|
});
|
|
159
159
|
let tags = [];
|
|
160
160
|
if (existing.length > 0) {
|
|
@@ -187,7 +187,7 @@ export async function handleContactsFollow(ctx, pool, args) {
|
|
|
187
187
|
export async function handleContactsUnfollow(ctx, pool, args) {
|
|
188
188
|
const existing = await pool.query(ctx.activeNpub, {
|
|
189
189
|
kinds: [3],
|
|
190
|
-
authors: [ctx.
|
|
190
|
+
authors: [ctx.activePublicKeyHex],
|
|
191
191
|
});
|
|
192
192
|
let tags = [];
|
|
193
193
|
if (existing.length > 0) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { decode } from 'nostr-tools/nip19';
|
|
1
2
|
/** Fetch notifications (mentions, replies, reactions, zaps) for the active identity */
|
|
2
3
|
export async function handleNotifications(ctx, pool, opts) {
|
|
4
|
+
const activeHex = decode(ctx.activeNpub).data;
|
|
3
5
|
const events = await pool.query(ctx.activeNpub, {
|
|
4
6
|
kinds: [1, 7, 9735],
|
|
5
|
-
'#p': [
|
|
7
|
+
'#p': [activeHex],
|
|
6
8
|
limit: opts?.limit ?? 50,
|
|
7
9
|
...(opts?.since ? { since: opts.since } : {}),
|
|
8
10
|
});
|
package/dist/zap/handlers.js
CHANGED
|
@@ -48,9 +48,11 @@ function decryptNwcResponse(conn, event) {
|
|
|
48
48
|
}
|
|
49
49
|
/** Parse zap receipts (kind 9735) for the active identity */
|
|
50
50
|
export async function handleZapReceipts(ctx, pool, opts) {
|
|
51
|
+
const { decode } = await import('nostr-tools/nip19');
|
|
52
|
+
const activeHex = decode(ctx.activeNpub).data;
|
|
51
53
|
const events = await pool.query(ctx.activeNpub, {
|
|
52
54
|
kinds: [9735],
|
|
53
|
-
'#p': [
|
|
55
|
+
'#p': [activeHex],
|
|
54
56
|
limit: opts?.limit ?? 20,
|
|
55
57
|
...(opts?.since ? { since: opts.since } : {}),
|
|
56
58
|
});
|
package/package.json
CHANGED