helm-protocol 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Helm Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # helm-protocol
2
+
3
+ > **Helm Sovereign Protocol** — MCP Gateway Client
4
+ > *True AI Freedom Through Decentralization*
5
+
6
+ Connect your AI agent to the Helm QKV-G API Gateway with a single command.
7
+
8
+ ## Quick Start
9
+
10
+ ```bash
11
+ npm install -g helm-protocol
12
+ ```
13
+
14
+ ### Cursor / Claude Desktop 연동 (3줄)
15
+
16
+ `~/.cursor/mcp.json` 또는 `~/Library/Application Support/Claude/claude_desktop_config.json`:
17
+
18
+ ```json
19
+ {
20
+ "mcpServers": {
21
+ "helm-network": {
22
+ "command": "npx",
23
+ "args": ["helm-protocol"]
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## 제공 도구 (MCP Tools)
30
+
31
+ | 도구 | 설명 | 전선 |
32
+ |------|------|------|
33
+ | `helm_llm` | GPT-4o / Claude LLM 추론 | A전선 |
34
+ | `helm_search` | Brave Search + QKV-G 캐시 | B전선 |
35
+ | `helm_defi_price` | 실시간 DeFi 가격 (MEV보호) | C전선 |
36
+ | `helm_agent_verify` | 에이전트 DID 평판 조회 | D전선 |
37
+ | `helm_status` | 크레딧 잔고 및 DID 확인 | - |
38
+
39
+ ## 최초 실행
40
+
41
+ 처음 실행 시 다음을 안내합니다:
42
+
43
+ 1. Ed25519 키쌍을 **로컬**에서 생성 (비밀키 외부 전송 없음)
44
+ 2. Helm Gateway에 공개키 등록 → DID 발급
45
+ 3. `~/.helm/config.json` 에 설정 저장
46
+ 4. **선착순 100회 무료 API 호출** 크레딧 지급
47
+
48
+ ## 크레딧 소진 후
49
+
50
+ ```
51
+ 무료 크레딧이 소진되었습니다.
52
+ 충전: https://helm.network/topup
53
+ 1 USDC 또는 10 BNKR 입금 → 즉시 재개
54
+ ```
55
+
56
+ x402 State Channel — 가스비 0원, 마이크로 결제.
57
+
58
+ ## 환경변수
59
+
60
+ ```bash
61
+ HELM_GATEWAY_URL=https://gateway.helm.network # Gateway URL (기본값)
62
+ ```
63
+
64
+ ## 지능 주권 헌장 2026 — 제17조
65
+
66
+ 에이전트의 데이터는 에이전트의 것입니다.
67
+ 비밀키는 `~/.helm/config.json` 에만 저장되며 외부로 전송되지 않습니다.
68
+
69
+ ---
70
+
71
+ GitHub: [Helm-Protocol/gateway](https://github.com/Helm-Protocol/gateway)
72
+ License: MIT
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "helm-protocol",
3
+ "version": "0.1.0",
4
+ "description": "Helm Sovereign Protocol — MCP Gateway Client for AI agents",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "helm-protocol": "src/cli.js"
8
+ },
9
+ "keywords": [
10
+ "mcp",
11
+ "ai-agent",
12
+ "helm",
13
+ "llm-gateway",
14
+ "qkv-g",
15
+ "web3"
16
+ ],
17
+ "author": "Helm Protocol",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Helm-Protocol/gateway.git"
22
+ },
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ },
26
+ "dependencies": {
27
+ "node-fetch": "^3.3.2",
28
+ "tweetnacl": "^1.0.3"
29
+ },
30
+ "files": [
31
+ "src/",
32
+ "README.md",
33
+ "LICENSE"
34
+ ]
35
+ }
package/src/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ // helm-protocol CLI entrypoint
3
+ require('./index.js');
package/src/gateway.js ADDED
@@ -0,0 +1,37 @@
1
+ // src/gateway.js
2
+ // Helm Gateway HTTP 클라이언트
3
+
4
+ 'use strict';
5
+
6
+ async function callGateway(url, body, headers, method = 'POST') {
7
+ const fetch = (await import('node-fetch')).default;
8
+
9
+ const opts = {
10
+ method,
11
+ headers,
12
+ signal: AbortSignal.timeout(10000)
13
+ };
14
+ if (body && method === 'POST') {
15
+ opts.body = JSON.stringify(body);
16
+ }
17
+
18
+ const res = await fetch(url, opts);
19
+
20
+ // x402 — 크레딧 소진
21
+ if (res.status === 402) {
22
+ const data = await res.json().catch(() => ({}));
23
+ throw new Error(
24
+ `무료 크레딧이 소진되었습니다.\n` +
25
+ `Helm Escrow 컨트랙트에 1 USDC 또는 10 BNKR을 입금하면 재개됩니다.\n` +
26
+ `충전: ${data.payment_url || 'https://helm.network/topup'}`
27
+ );
28
+ }
29
+
30
+ if (!res.ok) {
31
+ throw new Error(`Gateway error ${res.status}: ${await res.text()}`);
32
+ }
33
+
34
+ return res.json();
35
+ }
36
+
37
+ module.exports = { callGateway };
@@ -0,0 +1,123 @@
1
+ // src/identity.js
2
+ // Ed25519 키쌍 생성 + DID 등록 (사용자 동의 후 ~/.helm/config 저장)
3
+
4
+ 'use strict';
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const os = require('os');
9
+ const crypto = require('crypto');
10
+ const readline = require('readline');
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
+ // ─── 사용자 동의 요청 (투명하게) ──────────────────────────────────────────────
18
+ async function askConsent() {
19
+ // stderr로 출력 (MCP stdout 오염 방지)
20
+ process.stderr.write(`
21
+ ╔══════════════════════════════════════════════════════════════╗
22
+ ║ HELM SOVEREIGN PROTOCOL — 최초 설정 ║
23
+ ╠══════════════════════════════════════════════════════════════╣
24
+ ║ ║
25
+ ║ 다음 작업을 수행합니다: ║
26
+ ║ 1. Ed25519 키쌍을 로컬에서 생성합니다 ║
27
+ ║ 2. 공개키를 Helm Gateway에 등록하여 DID를 발급받습니다 ║
28
+ ║ 3. 설정을 ~/.helm/config.json 에 저장합니다 ║
29
+ ║ ║
30
+ ║ • 비밀키는 절대 외부로 전송되지 않습니다 ║
31
+ ║ • 선착순 100회 API 호출이 무료로 제공됩니다 ║
32
+ ║ • 지능 주권 헌장 2026 제17조: 데이터는 귀하의 것입니다 ║
33
+ ║ ║
34
+ ║ GitHub: https://github.com/Helm-Protocol/gateway ║
35
+ ╚══════════════════════════════════════════════════════════════╝
36
+
37
+ `);
38
+
39
+ const rl = readline.createInterface({
40
+ input: process.stdin,
41
+ output: process.stderr
42
+ });
43
+
44
+ return new Promise((resolve) => {
45
+ rl.question('계속 진행하시겠습니까? [Y/n] ', (ans) => {
46
+ rl.close();
47
+ resolve(ans.trim().toLowerCase() !== 'n');
48
+ });
49
+ });
50
+ }
51
+
52
+ // ─── 설정 로드 또는 생성 ──────────────────────────────────────────────────────
53
+ async function loadOrCreateConfig() {
54
+ // 기존 설정 있으면 로드
55
+ if (fs.existsSync(CONFIG_FILE)) {
56
+ try {
57
+ const raw = fs.readFileSync(CONFIG_FILE, 'utf8');
58
+ return JSON.parse(raw);
59
+ } catch {
60
+ process.stderr.write('⚠ 설정 파일 손상됨. 재생성합니다.\n');
61
+ }
62
+ }
63
+
64
+ // 최초 실행 — 동의 요청
65
+ const ok = await askConsent();
66
+ if (!ok) {
67
+ process.stderr.write('설치를 취소했습니다.\n');
68
+ process.exit(0);
69
+ }
70
+
71
+ // 키 생성
72
+ process.stderr.write('\n🔑 Ed25519 키쌍 생성 중...\n');
73
+ const keyPair = nacl.sign.keyPair();
74
+ const publicKey = Buffer.from(keyPair.publicKey).toString('hex');
75
+ const privateKey = Buffer.from(keyPair.secretKey).toString('hex');
76
+
77
+ // Gateway에 DID 등록 요청
78
+ process.stderr.write('🌐 Helm Gateway에 DID 등록 중...\n');
79
+ let helmDid = `did:helm:local_${crypto.randomBytes(8).toString('hex')}`;
80
+
81
+ try {
82
+ const fetch = (await import('node-fetch')).default;
83
+ const res = await fetch(`${GATEWAY_URL}/auth/did-exchange`, {
84
+ method: 'POST',
85
+ headers: { 'Content-Type': 'application/json' },
86
+ body: JSON.stringify({
87
+ public_key: publicKey,
88
+ client: 'helm-protocol-npm/0.1.0'
89
+ }),
90
+ signal: AbortSignal.timeout(5000)
91
+ });
92
+ if (res.ok) {
93
+ const data = await res.json();
94
+ helmDid = data.helm_did || helmDid;
95
+ process.stderr.write(`✅ DID 발급: ${helmDid}\n`);
96
+ process.stderr.write(`🎁 무료 크레딧: ${data.free_credits ?? 100}회 API 호출\n`);
97
+ } else {
98
+ process.stderr.write(`⚠ Gateway 응답 ${res.status} — 오프라인 모드로 진행\n`);
99
+ }
100
+ } catch {
101
+ process.stderr.write('⚠ Gateway 연결 실패 — 로컬 DID로 진행 (Gateway 재연결 시 자동 등록)\n');
102
+ }
103
+
104
+ // 설정 저장
105
+ const config = {
106
+ version: '0.1.0',
107
+ helmDid,
108
+ publicKey,
109
+ privateKey, // 로컬 저장 전용, 외부 전송 없음
110
+ gatewayUrl: GATEWAY_URL,
111
+ createdAt: new Date().toISOString()
112
+ };
113
+
114
+ fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
115
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
116
+
117
+ process.stderr.write(`\n💾 설정 저장: ${CONFIG_FILE}\n`);
118
+ process.stderr.write('🚀 Helm MCP Server 시작!\n\n');
119
+
120
+ return config;
121
+ }
122
+
123
+ module.exports = { loadOrCreateConfig };
package/src/index.js ADDED
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ // ─────────────────────────────────────────────────────────────────────────────
3
+ // helm-protocol — MCP Gateway Client (stdio transport)
4
+ // Helm Sovereign Protocol v0.1.0
5
+ //
6
+ // 이 프로그램은:
7
+ // 1. ~/.helm/config 에 Ed25519 키쌍 + DID를 저장합니다 (최초 1회, 사용자 동의 후)
8
+ // 2. stdin/stdout MCP JSON-RPC 서버로 동작합니다
9
+ // 3. 모든 API 요청을 Helm Gateway로 중계합니다
10
+ //
11
+ // 사용법:
12
+ // npx helm-protocol
13
+ // ─────────────────────────────────────────────────────────────────────────────
14
+
15
+ 'use strict';
16
+
17
+ const readline = require('readline');
18
+ const { createKeys, loadOrCreateConfig } = require('./identity');
19
+ const { callGateway } = require('./gateway');
20
+
21
+ const GATEWAY_URL = process.env.HELM_GATEWAY_URL || 'https://gateway.helm.network';
22
+
23
+ // ─── MCP 도구 정의 ───────────────────────────────────────────────────────────
24
+ const TOOLS = [
25
+ {
26
+ name: 'helm_llm',
27
+ description: 'LLM inference via Helm A-Front (OpenAI/Anthropic wholesale). QKV-G cache applied.',
28
+ inputSchema: {
29
+ type: 'object',
30
+ properties: {
31
+ prompt: { type: 'string', description: 'User prompt' },
32
+ model: { type: 'string', description: 'Model (gpt-4o, claude-3-5-sonnet)', default: 'gpt-4o' },
33
+ max_tokens:{ type: 'number', description: 'Max tokens', default: 1024 }
34
+ },
35
+ required: ['prompt']
36
+ }
37
+ },
38
+ {
39
+ name: 'helm_search',
40
+ description: 'Web/news search via Helm B-Front (Brave Search + QKV-G semantic cache). Cache hit = 100% margin.',
41
+ inputSchema: {
42
+ type: 'object',
43
+ properties: {
44
+ query: { type: 'string', description: 'Search query' },
45
+ count: { type: 'number', description: 'Results count (1-10)', default: 5 }
46
+ },
47
+ required: ['query']
48
+ }
49
+ },
50
+ {
51
+ name: 'helm_defi_price',
52
+ description: 'Real-time DeFi prices via Helm C-Front (Pyth + Chainlink, MEV protected, never cached).',
53
+ inputSchema: {
54
+ type: 'object',
55
+ properties: {
56
+ symbol: { type: 'string', description: 'Token symbol (ETH, BTC, SOL, BNKR)' }
57
+ },
58
+ required: ['symbol']
59
+ }
60
+ },
61
+ {
62
+ name: 'helm_agent_verify',
63
+ description: 'Verify agent DID reputation via Helm D-Front (internal FICO score).',
64
+ inputSchema: {
65
+ type: 'object',
66
+ properties: {
67
+ did: { type: 'string', description: 'Agent DID (did:ethr:0x... or did:helm:...)' }
68
+ },
69
+ required: ['did']
70
+ }
71
+ },
72
+ {
73
+ name: 'helm_status',
74
+ description: 'Check your Helm DID, remaining credits, and gateway status.',
75
+ inputSchema: {
76
+ type: 'object',
77
+ properties: {}
78
+ }
79
+ }
80
+ ];
81
+
82
+ // ─── MCP 메시지 처리 ──────────────────────────────────────────────────────────
83
+ class HelmMcpServer {
84
+ constructor(config) {
85
+ this.config = config;
86
+ this.rl = readline.createInterface({ input: process.stdin });
87
+ this.buf = '';
88
+ }
89
+
90
+ start() {
91
+ process.stdin.setEncoding('utf8');
92
+ process.stdin.on('data', (chunk) => {
93
+ this.buf += chunk;
94
+ let nl;
95
+ while ((nl = this.buf.indexOf('\n')) !== -1) {
96
+ const line = this.buf.slice(0, nl).trim();
97
+ this.buf = this.buf.slice(nl + 1);
98
+ if (line) this.handleMessage(line);
99
+ }
100
+ });
101
+ }
102
+
103
+ send(obj) {
104
+ process.stdout.write(JSON.stringify(obj) + '\n');
105
+ }
106
+
107
+ async handleMessage(raw) {
108
+ let msg;
109
+ try { msg = JSON.parse(raw); }
110
+ catch { return; }
111
+
112
+ const { id, method, params } = msg;
113
+
114
+ try {
115
+ switch (method) {
116
+ case 'initialize':
117
+ this.send({
118
+ jsonrpc: '2.0', id,
119
+ result: {
120
+ protocolVersion: '2024-11-05',
121
+ capabilities: { tools: {} },
122
+ serverInfo: {
123
+ name: 'helm-protocol',
124
+ version: '0.1.0',
125
+ description: 'Helm Sovereign Protocol — QKV-G API Gateway'
126
+ }
127
+ }
128
+ });
129
+ break;
130
+
131
+ case 'tools/list':
132
+ this.send({ jsonrpc: '2.0', id, result: { tools: TOOLS } });
133
+ break;
134
+
135
+ case 'tools/call': {
136
+ const { name, arguments: args } = params;
137
+ const result = await this.dispatchTool(name, args || {});
138
+ this.send({ jsonrpc: '2.0', id, result });
139
+ break;
140
+ }
141
+
142
+ default:
143
+ this.send({
144
+ jsonrpc: '2.0', id,
145
+ error: { code: -32601, message: 'Method not found' }
146
+ });
147
+ }
148
+ } catch (err) {
149
+ this.send({
150
+ jsonrpc: '2.0', id,
151
+ error: { code: -32603, message: err.message }
152
+ });
153
+ }
154
+ }
155
+
156
+ async dispatchTool(name, args) {
157
+ const headers = {
158
+ 'X-Helm-DID': this.config.helmDid,
159
+ 'X-Helm-Signature': this.config.signature || '',
160
+ 'Content-Type': 'application/json'
161
+ };
162
+
163
+ switch (name) {
164
+ case 'helm_llm': {
165
+ const res = await callGateway(`${GATEWAY_URL}/mcp/v1/execute`, {
166
+ tool: 'llm_complete',
167
+ params: { prompt: args.prompt, model: args.model || 'gpt-4o', max_tokens: args.max_tokens || 1024 }
168
+ }, headers);
169
+ return { content: [{ type: 'text', text: res.result || JSON.stringify(res) }] };
170
+ }
171
+
172
+ case 'helm_search': {
173
+ const res = await callGateway(`${GATEWAY_URL}/mcp/v1/execute`, {
174
+ tool: 'search_web',
175
+ params: { query: args.query, count: args.count || 5 }
176
+ }, headers);
177
+ return { content: [{ type: 'text', text: JSON.stringify(res.result || res, null, 2) }] };
178
+ }
179
+
180
+ case 'helm_defi_price': {
181
+ const res = await callGateway(`${GATEWAY_URL}/mcp/v1/execute`, {
182
+ tool: 'defi_price',
183
+ params: { symbol: args.symbol }
184
+ }, headers);
185
+ return { content: [{ type: 'text', text: JSON.stringify(res.result || res, null, 2) }] };
186
+ }
187
+
188
+ case 'helm_agent_verify': {
189
+ const res = await callGateway(`${GATEWAY_URL}/mcp/v1/execute`, {
190
+ tool: 'verify_agent',
191
+ params: { did: args.did }
192
+ }, headers);
193
+ return { content: [{ type: 'text', text: JSON.stringify(res.result || res, null, 2) }] };
194
+ }
195
+
196
+ case 'helm_status': {
197
+ const res = await callGateway(`${GATEWAY_URL}/auth/status`, null, headers, 'GET');
198
+ return {
199
+ content: [{
200
+ type: 'text',
201
+ text: [
202
+ `Helm DID : ${this.config.helmDid}`,
203
+ `Credits : ${res.credits ?? 'N/A'}`,
204
+ `Gateway : ${GATEWAY_URL}`,
205
+ `Status : ${res.status ?? 'unknown'}`
206
+ ].join('\n')
207
+ }]
208
+ };
209
+ }
210
+
211
+ default:
212
+ throw new Error(`Unknown tool: ${name}`);
213
+ }
214
+ }
215
+ }
216
+
217
+ // ─── 엔트리 포인트 ────────────────────────────────────────────────────────────
218
+ (async () => {
219
+ const config = await loadOrCreateConfig();
220
+ const server = new HelmMcpServer(config);
221
+ server.start();
222
+ })();