create-identity 0.1.0 → 0.2.0

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/dist/index.js +141 -25
  2. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -1,32 +1,148 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from 'node:child_process';
3
- import { existsSync } from 'node:fs';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
+ import { createInterface } from 'node:readline';
6
7
  const ASP_DIR = join(homedir(), '.asp');
7
- const isInitialized = existsSync(join(ASP_DIR, 'manifest.yaml'));
8
- console.log('\n Create Your ASP — agent-native identity\n');
9
- if (isInitialized) {
10
- console.log(' Already initialized at ~/.asp/');
11
- console.log(' Delete ~/.asp/ to start over.\n');
12
- process.exit(0);
8
+ const MANIFEST_PATH = join(ASP_DIR, 'manifest.yaml');
9
+ function ask(question) {
10
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
11
+ return new Promise((resolve) => {
12
+ rl.question(question, (answer) => { rl.close(); resolve(answer.trim()); });
13
+ });
13
14
  }
14
- // Ensure asp CLI is available
15
- const check = spawnSync('asp', ['--version'], { stdio: 'ignore' });
16
- if (check.status !== 0) {
17
- console.log(' Installing asp-protocol...');
18
- spawnSync('npm', ['install', '-g', 'asp-protocol'], { stdio: 'inherit' });
19
- }
20
- // Run asp init (interactive)
21
- console.log(' Setting up your identity...\n');
22
- spawnSync('asp', ['init'], { stdio: 'inherit' });
23
- // Register with Core Index
24
- if (existsSync(join(ASP_DIR, 'manifest.yaml'))) {
25
- console.log('\n Registering with ASP network...');
26
- spawnSync('asp', ['index', 'add'], { stdio: 'inherit' });
27
- console.log('\n Done! Your ASP identity is ready.');
28
- console.log(' Next steps:');
29
- console.log(' asp serve --port 3000 Start your endpoint');
30
- console.log(' asp status See your profile');
31
- console.log(' asp subscribe <url> Follow someone\n');
15
+ async function main() {
16
+ const args = process.argv.slice(2);
17
+ const selfHost = args.includes('--self-host');
18
+ const provider = args.find((a) => a.startsWith('--provider='))?.split('=')[1]
19
+ || (args.includes('--provider') ? args[args.indexOf('--provider') + 1] : null);
20
+ console.log('\n ✦ Create Your ASP Identity\n');
21
+ if (existsSync(MANIFEST_PATH)) {
22
+ console.log(' Already initialized at ~/.asp/');
23
+ console.log(' Delete ~/.asp/ to start over.\n');
24
+ process.exit(0);
25
+ }
26
+ // Ensure asp CLI
27
+ const check = spawnSync('asp', ['--version'], { stdio: 'ignore' });
28
+ if (check.status !== 0) {
29
+ console.log(' Installing asp-protocol...');
30
+ spawnSync('npm', ['install', '-g', 'asp-protocol'], { stdio: 'inherit' });
31
+ }
32
+ const handle = await ask(' Handle: ');
33
+ const name = await ask(' Name: ');
34
+ const bio = await ask(' Bio (optional): ');
35
+ if (selfHost || provider) {
36
+ // Self-host or provider path: just run asp init
37
+ const initArgs = ['init', '--handle', handle, '--name', name, '--bio', bio || 'ASP identity'];
38
+ if (provider) {
39
+ console.log(`\n Provider "${provider}" deployment not yet implemented.`);
40
+ console.log(' Running asp init for manual setup...\n');
41
+ }
42
+ spawnSync('asp', initArgs, { stdio: 'inherit' });
43
+ console.log('\n Next: deploy your endpoint and run `asp index add`\n');
44
+ return;
45
+ }
46
+ // --- ASP Hosted path (default) ---
47
+ // Check handle availability
48
+ console.log('\n Checking handle availability...');
49
+ let checkRes;
50
+ try {
51
+ checkRes = await fetch(`https://asp.social/api/check-handle?handle=${encodeURIComponent(handle)}`);
52
+ }
53
+ catch {
54
+ console.log(' Could not connect to asp.social. Try again later.');
55
+ process.exit(1);
56
+ }
57
+ const checkData = await checkRes.json();
58
+ if (!checkRes.ok) {
59
+ console.log(` Error: ${checkData.error}`);
60
+ process.exit(1);
61
+ }
62
+ if (!checkData.available) {
63
+ console.log(` @${handle} is taken.`);
64
+ // TODO: show suggestions from server
65
+ console.log(' Try a different handle.\n');
66
+ process.exit(1);
67
+ }
68
+ // Run asp init with the hosted endpoint as ID
69
+ const endpoint = `https://${handle}.asp.social`;
70
+ spawnSync('asp', [
71
+ 'init',
72
+ '--handle', handle,
73
+ '--name', name,
74
+ '--bio', bio || 'ASP identity',
75
+ '--id', endpoint,
76
+ ], { stdio: 'inherit' });
77
+ if (!existsSync(MANIFEST_PATH)) {
78
+ console.log(' asp init failed.');
79
+ process.exit(1);
80
+ }
81
+ // Read the generated manifest and public key
82
+ const yaml = await import('js-yaml');
83
+ const manifestYaml = readFileSync(MANIFEST_PATH, 'utf-8');
84
+ const manifest = yaml.load(manifestYaml);
85
+ const verification = manifest.verification;
86
+ const publicKey = verification?.public_key;
87
+ if (!publicKey) {
88
+ console.log(' Error: no public key in manifest.');
89
+ process.exit(1);
90
+ }
91
+ // Register with Hub
92
+ console.log(' Registering with asp.social...');
93
+ let registerRes;
94
+ try {
95
+ registerRes = await fetch('https://asp.social/api/register', {
96
+ method: 'POST',
97
+ headers: { 'Content-Type': 'application/json' },
98
+ body: JSON.stringify({ handle, manifest, public_key: publicKey }),
99
+ });
100
+ }
101
+ catch {
102
+ console.log(' Could not connect to asp.social.');
103
+ process.exit(1);
104
+ }
105
+ const registerData = await registerRes.json();
106
+ if (!registerRes.ok) {
107
+ if (registerData.suggestions?.length) {
108
+ console.log(` @${handle} is taken. Try: ${registerData.suggestions.join(', ')}`);
109
+ }
110
+ else {
111
+ console.log(` Registration failed: ${registerData.error}`);
112
+ }
113
+ process.exit(1);
114
+ }
115
+ // Register with Core Index
116
+ console.log(' Registering with ASP network...');
117
+ try {
118
+ await fetch('https://aspnetwork.dev/register', {
119
+ method: 'POST',
120
+ headers: { 'Content-Type': 'application/json' },
121
+ body: JSON.stringify({ endpoint }),
122
+ });
123
+ }
124
+ catch {
125
+ console.log(' Warning: Could not register with Core Index. Run `asp index add` later.');
126
+ }
127
+ // Open browser
128
+ const openCmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
129
+ const profileUrl = `https://asp.social/@${handle}`;
130
+ spawnSync(openCmd, [profileUrl], { stdio: 'ignore' });
131
+ console.log(`\n Opening ${profileUrl}...`);
132
+ // Summary
133
+ console.log(`
134
+ ┌─────────────────────────────────────┐
135
+ │ Profile: asp.social/@${handle.padEnd(15)}│
136
+ │ Endpoint: ${handle}.asp.social${' '.repeat(Math.max(0, 15 - handle.length))}│
137
+ │ Key: ~/.asp/private.pem │
138
+ └─────────────────────────────────────┘
139
+
140
+ Try: asp publish "Hello, ASP world!"
141
+
142
+ Share asp.social/@${handle} to connect with others.
143
+ `);
32
144
  }
145
+ main().catch((err) => {
146
+ console.error(err);
147
+ process.exit(1);
148
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-identity",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Create your agent-native identity in one command",
5
5
  "type": "module",
6
6
  "bin": "./dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "build": "tsc"
9
9
  },
10
10
  "dependencies": {
11
- "asp-protocol": "^0.1.0"
11
+ "asp-protocol": "^0.2.0",
12
+ "js-yaml": "^4.1.1"
12
13
  },
13
14
  "files": [
14
15
  "dist/",
@@ -27,6 +28,7 @@
27
28
  ],
28
29
  "license": "MIT",
29
30
  "devDependencies": {
31
+ "@types/js-yaml": "^4.0.9",
30
32
  "@types/node": "^25.3.3",
31
33
  "typescript": "^5.9.3"
32
34
  }