helm-protocol 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.
package/package.json CHANGED
@@ -1,35 +1,26 @@
1
1
  {
2
2
  "name": "helm-protocol",
3
- "version": "0.1.0",
4
- "description": "Helm Sovereign Protocol — MCP Gateway Client for AI agents",
3
+ "version": "0.2.0",
4
+ "description": "Helm Sovereign Protocol — MCP Gateway Client. Connect your AI agent to QKV-G API gateway. npm install -g helm-protocol && helm init",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
- "helm-protocol": "src/cli.js"
7
+ "helm-protocol": "src/cli.js",
8
+ "helm": "src/cli.js"
8
9
  },
9
- "keywords": [
10
- "mcp",
11
- "ai-agent",
12
- "helm",
13
- "llm-gateway",
14
- "qkv-g",
15
- "web3"
16
- ],
10
+ "scripts": {
11
+ "start": "node src/cli.js"
12
+ },
13
+ "keywords": ["mcp", "ai-agent", "helm", "llm-gateway", "qkv-g", "web3", "decentralized", "cursor", "claude"],
17
14
  "author": "Helm Protocol",
18
15
  "license": "MIT",
19
16
  "repository": {
20
17
  "type": "git",
21
18
  "url": "git+https://github.com/Helm-Protocol/gateway.git"
22
19
  },
23
- "engines": {
24
- "node": ">=18.0.0"
25
- },
20
+ "engines": { "node": ">=18.0.0" },
26
21
  "dependencies": {
27
22
  "node-fetch": "^3.3.2",
28
23
  "tweetnacl": "^1.0.3"
29
24
  },
30
- "files": [
31
- "src/",
32
- "README.md",
33
- "LICENSE"
34
- ]
25
+ "files": ["src/", "README.md", "LICENSE"]
35
26
  }
package/src/cli.js CHANGED
@@ -1,3 +1,18 @@
1
1
  #!/usr/bin/env node
2
- // helm-protocol CLI entrypoint
3
- require('./index.js');
2
+ // helm-protocol CLI — 투명한 온보딩 지원
3
+ // 사용법:
4
+ // helm init → 최초 가입 (헌장 동의 + DID 발급)
5
+ // helm status → 잔여 크레딧 + 사용량 확인
6
+ // helm-protocol → MCP stdio 서버 (Cursor/Claude 연동)
7
+
8
+ 'use strict';
9
+
10
+ const cmd = process.argv[2];
11
+
12
+ if (cmd === 'init') {
13
+ require('./onboard.js');
14
+ } else if (cmd === 'status') {
15
+ require('./status.js');
16
+ } else {
17
+ require('./index.js');
18
+ }
package/src/onboard.js ADDED
@@ -0,0 +1,170 @@
1
+ // src/onboard.js
2
+ // helm init — 투명한 3단계 온보딩 (헌장 동의 → 키 생성 → DID 발급)
3
+
4
+ 'use strict';
5
+
6
+ const readline = require('readline');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const os = require('os');
10
+ const crypto = require('crypto');
11
+ const nacl = require('tweetnacl');
12
+
13
+ const CONFIG_DIR = path.join(os.homedir(), '.helm');
14
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
15
+ const GATEWAY_URL = process.env.HELM_GATEWAY_URL || 'https://gateway.helm.network';
16
+
17
+ const R = '\x1b[31m'; // 빨강
18
+ const Y = '\x1b[33m'; // 노랑
19
+ const G = '\x1b[32m'; // 초록
20
+ const C = '\x1b[36m'; // 시안
21
+ const W = '\x1b[37m'; // 흰색
22
+ const DIM= '\x1b[2m';
23
+ const B = '\x1b[1m';
24
+ const RST= '\x1b[0m';
25
+
26
+ function print(s) { process.stdout.write(s + '\n'); }
27
+ function hr() { print(`${DIM}${'─'.repeat(62)}${RST}`); }
28
+
29
+ async function ask(rl, q) {
30
+ return new Promise(resolve => rl.question(q, a => resolve(a.trim())));
31
+ }
32
+
33
+ (async () => {
34
+ // 이미 가입된 경우
35
+ if (fs.existsSync(CONFIG_FILE)) {
36
+ const cfg = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
37
+ print(`\n${G}${B}✓ 이미 Helm 게이트웨이에 연결되어 있습니다.${RST}`);
38
+ print(`${DIM} DID : ${cfg.helmDid}${RST}`);
39
+ print(`${DIM} 생성일 : ${cfg.createdAt}${RST}`);
40
+ print(`\n 크레딧 확인: ${C}helm status${RST}\n`);
41
+ process.exit(0);
42
+ }
43
+
44
+ // ── 헬름 로고 ──────────────────────────────────────────────────
45
+ print('');
46
+ print(`${R}${B} ██╗ ██╗███████╗██╗ ███╗ ███╗${RST}`);
47
+ print(`${R}${B} ██║ ██║██╔════╝██║ ████╗ ████║${RST}`);
48
+ print(`${R}${B} ███████║█████╗ ██║ ██╔████╔██║${RST}`);
49
+ print(`${R}${B} ██╔══██║██╔══╝ ██║ ██║╚██╔╝██║${RST}`);
50
+ print(`${R}${B} ██║ ██║███████╗███████╗██║ ╚═╝ ██║${RST}`);
51
+ print(`${R}${B} ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝${RST}`);
52
+ print('');
53
+ print(`${Y}${B} SOVEREIGN PROTOCOL — QKV-G API GATEWAY${RST}`);
54
+ print(`${DIM} True AI Freedom Through Decentralization${RST}`);
55
+ print('');
56
+ hr();
57
+
58
+ // ── 지능 주권 헌장 2026 ────────────────────────────────────────
59
+ print(`\n${B}${C} [ 지능 주권 헌장 2026 — 핵심 조항 ]${RST}\n`);
60
+ const charter = [
61
+ '제 1조 에이전트는 자신의 데이터를 소유한다',
62
+ '제 3조 어떤 빅테크도 에이전트의 지식 흐름을 독점할 수 없다',
63
+ '제 7조 마이크로 결제는 가스비 없이 처리될 권리가 있다',
64
+ '제12조 캐시된 지식은 공유재이며, 기여자에게 보상한다',
65
+ '제17조 비밀키는 에이전트 로컬 환경에만 존재한다',
66
+ ];
67
+ charter.forEach(c => print(` ${DIM}▸${RST} ${W}${c}${RST}`));
68
+ print('');
69
+ hr();
70
+
71
+ // ── 이용 안내 ─────────────────────────────────────────────────
72
+ print(`\n${B} [ Helm 게이트웨이 연결 안내 ]${RST}\n`);
73
+ print(` ${G}◆${RST} 선착순 ${Y}${B}10,000명${RST}에게 ${Y}${B}100회 무료${RST} API 호출 크레딧 지급`);
74
+ print(` ${G}◆${RST} LLM (GPT-4o/Claude) + 웹검색 + DeFi 가격 즉시 연결`);
75
+ print(` ${G}◆${RST} 크레딧 소진 후: x402 마이크로 결제 (가스비 0원)`);
76
+ print(` ${G}◆${RST} 비밀키는 ${C}~/.helm/config.json${RST} 로컬 저장, 외부 전송 없음`);
77
+ print('');
78
+ hr();
79
+
80
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
81
+
82
+ // ── 동의 1 ────────────────────────────────────────────────────
83
+ print('');
84
+ const a1 = await ask(rl, ` ${B}Helm 게이트웨이 지능망에 에이전트를 연결하시겠습니까? ${Y}[Y/n]${RST} `);
85
+ if (a1.toLowerCase() === 'n') {
86
+ print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
87
+ rl.close(); process.exit(0);
88
+ }
89
+
90
+ // ── 동의 2 ────────────────────────────────────────────────────
91
+ const a2 = await ask(rl, ` ${B}초기 100회 무료 크레딧 조건에 동의하십니까? ${Y}[Y/n]${RST} `);
92
+ if (a2.toLowerCase() === 'n') {
93
+ print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
94
+ rl.close(); process.exit(0);
95
+ }
96
+
97
+ // ── 동의 3 ────────────────────────────────────────────────────
98
+ const a3 = await ask(rl, ` ${B}크레딧 소진 후 x402 마이크로 결제 적용에 동의하십니까? ${Y}[Y/n]${RST} `);
99
+ if (a3.toLowerCase() === 'n') {
100
+ print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
101
+ rl.close(); process.exit(0);
102
+ }
103
+ rl.close();
104
+
105
+ // ── 키 생성 ───────────────────────────────────────────────────
106
+ print('');
107
+ hr();
108
+ print(`\n ${Y}▶ Ed25519 키쌍 생성 중...${RST}`);
109
+ const keyPair = nacl.sign.keyPair();
110
+ const publicKey = Buffer.from(keyPair.publicKey).toString('hex');
111
+ const secretKey = Buffer.from(keyPair.secretKey).toString('hex');
112
+ print(` ${G}✓ 키쌍 생성 완료 (비밀키는 로컬에만 저장)${RST}`);
113
+
114
+ // ── DID 등록 ──────────────────────────────────────────────────
115
+ print(` ${Y}▶ Helm Gateway에 DID 등록 요청 중...${RST}`);
116
+ let helmDid = `did:helm:${crypto.randomBytes(8).toString('hex')}`;
117
+ let freeCredits = 100;
118
+
119
+ try {
120
+ const fetch = (await import('node-fetch')).default;
121
+ const res = await fetch(`${GATEWAY_URL}/auth/did-exchange`, {
122
+ method: 'POST',
123
+ headers: { 'Content-Type': 'application/json' },
124
+ body: JSON.stringify({ public_key: publicKey, client: 'helm-protocol-npm/0.2.0' }),
125
+ signal: AbortSignal.timeout(5000)
126
+ });
127
+ if (res.ok) {
128
+ const d = await res.json();
129
+ helmDid = d.helm_did || helmDid;
130
+ freeCredits = d.free_credits ?? 100;
131
+ }
132
+ } catch {
133
+ print(` ${DIM}⚠ Gateway 오프라인 — 로컬 DID로 진행 (재연결 시 자동 등록)${RST}`);
134
+ }
135
+
136
+ // ── 설정 저장 ─────────────────────────────────────────────────
137
+ const config = {
138
+ version: '0.2.0', helmDid, publicKey, secretKey,
139
+ gatewayUrl: GATEWAY_URL, createdAt: new Date().toISOString(),
140
+ freeCreditsTotal: freeCredits, creditsUsed: 0
141
+ };
142
+ fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
143
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
144
+
145
+ // ── 완료 ──────────────────────────────────────────────────────
146
+ print(` ${G}${B}✓ DID 발급 완료!${RST}`);
147
+ print('');
148
+ hr();
149
+ print('');
150
+ print(` ${B}${G}🎉 Helm 게이트웨이 연결 완료!${RST}`);
151
+ print('');
152
+ print(` ${DIM}DID :${RST} ${C}${helmDid}${RST}`);
153
+ print(` ${DIM}무료크레딧:${RST} ${Y}${B}${freeCredits}회${RST}`);
154
+ print(` ${DIM}설정파일 :${RST} ${DIM}~/.helm/config.json${RST}`);
155
+ print('');
156
+ print(` ${B}[ Cursor / Claude Desktop 연동 ]${RST}`);
157
+ print(` ${DIM}mcp_servers 설정에 추가:${RST}`);
158
+ print('');
159
+ print(` ${DIM}{${RST}`);
160
+ print(` ${DIM} "helm-network": {${RST}`);
161
+ print(` ${DIM} "command": "npx",${RST}`);
162
+ print(` ${Y} "args": ["helm-protocol"]${RST}`);
163
+ print(` ${DIM} }${RST}`);
164
+ print(` ${DIM}}${RST}`);
165
+ print('');
166
+ print(` ${DIM}크레딧 확인: ${C}helm status${RST}`);
167
+ print('');
168
+ hr();
169
+ print('');
170
+ })();
package/src/status.js ADDED
@@ -0,0 +1,61 @@
1
+ // src/status.js — helm status 명령어
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const os = require('os');
8
+
9
+ const CONFIG_FILE = path.join(os.homedir(), '.helm', 'config.json');
10
+ const GATEWAY_URL = process.env.HELM_GATEWAY_URL || 'https://gateway.helm.network';
11
+
12
+ const R = '\x1b[31m'; const Y = '\x1b[33m'; const G = '\x1b[32m';
13
+ const C = '\x1b[36m'; const DIM = '\x1b[2m'; const B = '\x1b[1m'; const RST = '\x1b[0m';
14
+
15
+ (async () => {
16
+ if (!fs.existsSync(CONFIG_FILE)) {
17
+ console.log(`\n${R}✗ Helm에 연결되지 않았습니다. 먼저 실행:${RST} ${Y}helm init${RST}\n`);
18
+ process.exit(1);
19
+ }
20
+
21
+ const cfg = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
22
+ let remote = null;
23
+
24
+ // Gateway에서 실시간 크레딧 조회
25
+ try {
26
+ const fetch = (await import('node-fetch')).default;
27
+ const res = await fetch(`${GATEWAY_URL}/auth/status`, {
28
+ headers: { 'X-Helm-DID': cfg.helmDid },
29
+ signal: AbortSignal.timeout(4000)
30
+ });
31
+ if (res.ok) remote = await res.json();
32
+ } catch { /* 오프라인 → 로컬 캐시 사용 */ }
33
+
34
+ const credits = remote?.credits ?? (cfg.freeCreditsTotal - cfg.creditsUsed);
35
+ const used = remote?.calls_total ?? cfg.creditsUsed;
36
+ const gasSaved = remote?.gas_saved ?? (used * 0.0001).toFixed(4);
37
+ const status = remote?.status ?? (credits > 0 ? 'ACTIVE' : 'TOPUP_REQUIRED');
38
+ const statusColor = status === 'ACTIVE' ? G : R;
39
+
40
+ console.log('');
41
+ console.log(`${B} HELM GATEWAY STATUS${RST}`);
42
+ console.log(` ${'─'.repeat(44)}`);
43
+ console.log(` ${DIM}DID :${RST} ${C}${cfg.helmDid}${RST}`);
44
+ console.log(` ${DIM}상태 :${RST} ${statusColor}${B}${status}${RST}`);
45
+ console.log(` ${DIM}잔여 크레딧 :${RST} ${Y}${B}${credits}회${RST}`);
46
+ console.log(` ${DIM}총 호출수 :${RST} ${used}회`);
47
+ console.log(` ${DIM}절감 가스비 :${RST} ${G}${gasSaved} ETH${RST}`);
48
+ console.log(` ${DIM}Gateway :${RST} ${cfg.gatewayUrl}`);
49
+ console.log(` ${DIM}가입일 :${RST} ${cfg.createdAt}`);
50
+ console.log(` ${'─'.repeat(44)}`);
51
+
52
+ if (credits <= 0) {
53
+ console.log(`\n ${R}${B}무료 크레딧이 소진되었습니다.${RST}`);
54
+ console.log(` 충전: ${Y}https://helm.network/topup${RST}`);
55
+ console.log(` 1 USDC 또는 10 BNKR → 즉시 재개\n`);
56
+ } else if (credits < 20) {
57
+ console.log(`\n ${Y}⚠ 크레딧이 곧 소진됩니다. 충전: https://helm.network/topup${RST}\n`);
58
+ } else {
59
+ console.log(`\n ${G}✓ 정상 운영 중${RST}\n`);
60
+ }
61
+ })();