create-agent 0.0.7 → 0.0.8
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/bin/create-agent.js +59 -18
- package/package.json +1 -1
package/bin/create-agent.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// NOSTR KEY GENERATION
|
|
5
|
+
// =============================================================================
|
|
4
6
|
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure';
|
|
5
7
|
import { nip19 } from 'nostr-tools';
|
|
6
8
|
|
|
7
9
|
// Generate cryptographically secure private key (32 bytes)
|
|
8
10
|
const privkey = generateSecretKey();
|
|
9
|
-
|
|
10
|
-
// Convert Uint8Array to hex string
|
|
11
11
|
const privkeyHex = Array.from(privkey)
|
|
12
12
|
.map(b => b.toString(16).padStart(2, '0'))
|
|
13
13
|
.join('');
|
|
@@ -15,21 +15,62 @@ const privkeyHex = Array.from(privkey)
|
|
|
15
15
|
// Derive public key using Schnorr signatures (32 bytes, hex encoded)
|
|
16
16
|
const pubkey = getPublicKey(privkey);
|
|
17
17
|
|
|
18
|
-
// Encode
|
|
18
|
+
// Encode keys in Nostr formats
|
|
19
19
|
const nsec = nip19.nsecEncode(privkey);
|
|
20
|
-
|
|
21
|
-
// Encode the public key as npub
|
|
22
20
|
const npub = nip19.npubEncode(pubkey);
|
|
23
21
|
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// DID DOCUMENT CREATION
|
|
24
|
+
// =============================================================================
|
|
25
|
+
const didDocument = {
|
|
26
|
+
"@context": [
|
|
27
|
+
"https://www.w3.org/ns/did/v1",
|
|
28
|
+
"https://w3id.org/nostr/context"
|
|
29
|
+
],
|
|
30
|
+
"id": `did:nostr:${pubkey}`,
|
|
31
|
+
"verificationMethod": [
|
|
32
|
+
{
|
|
33
|
+
"id": `did:nostr:${pubkey}#key1`,
|
|
34
|
+
"controller": `did:nostr:${pubkey}`,
|
|
35
|
+
"type": "SchnorrVerification2025"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"authentication": [
|
|
39
|
+
"#key1"
|
|
40
|
+
],
|
|
41
|
+
"assertionMethod": [
|
|
42
|
+
"#key1"
|
|
43
|
+
],
|
|
44
|
+
"service": [] // Empty services array
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// =============================================================================
|
|
48
|
+
// CONSOLE OUTPUT
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// First output the initial warning message to stderr
|
|
51
|
+
process.stderr.write('\x1b[36m🤖 Creating new Nostr agent identity...\x1b[0m\n');
|
|
52
|
+
process.stderr.write('\x1b[36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n');
|
|
53
|
+
process.stderr.write('\x1b[33m⚠️ IMPORTANT: Keep your private key (nsec/privkey) secret!\x1b[0m\n');
|
|
54
|
+
process.stderr.write('\x1b[33m Never share it with anyone or input it on websites.\x1b[0m\n');
|
|
55
|
+
process.stderr.write('\n');
|
|
56
|
+
|
|
57
|
+
// Then output the Nostr identity information to stderr
|
|
58
|
+
process.stderr.write('\n\x1b[32m📋 Your Nostr Identity:\x1b[0m\n');
|
|
59
|
+
process.stderr.write('\x1b[32m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n');
|
|
60
|
+
process.stderr.write(`\x1b[0mPublic Key (hex) : \x1b[33m${pubkey}\x1b[0m\n`);
|
|
61
|
+
process.stderr.write(`\x1b[0mNostr Public Key : \x1b[33m${npub}\x1b[0m\n`);
|
|
62
|
+
process.stderr.write(`\x1b[0mPrivate Key (hex): \x1b[31m${privkeyHex}\x1b[0m\n`);
|
|
63
|
+
process.stderr.write(`\x1b[0mNostr Secret Key : \x1b[31m${nsec}\x1b[0m\n`);
|
|
64
|
+
process.stderr.write('\n');
|
|
65
|
+
process.stderr.write('\x1b[36m🔍 Usage:\x1b[0m\n');
|
|
66
|
+
process.stderr.write('\x1b[0m- Use your npub to identify yourself to others\x1b[0m\n');
|
|
67
|
+
process.stderr.write('\x1b[0m- Add relays to the services array for discovery\x1b[0m\n');
|
|
68
|
+
process.stderr.write('\x1b[0m- Use nsec to sign into Nostr clients (handle with extreme care!)\x1b[0m\n');
|
|
69
|
+
process.stderr.write('\n');
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// Then output the DID document to stdout with a clear header in the output
|
|
73
|
+
process.stderr.write('\x1b[36m📄 DID Nostr Document:\x1b[0m\n');
|
|
74
|
+
process.stderr.write('\x1b[36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n');
|
|
75
|
+
console.log(JSON.stringify(didDocument, null, 2));
|
|
76
|
+
process.stderr.write('\x1b[36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n');
|