@reclaimprotocol/agent 0.1.11 → 0.1.13
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/lib/mcp/tools/agent/shared.js +30 -1
- package/lib/mcp/tools/authenticate/decrypt-key.js +1 -1
- package/lib/old/client.d.ts +31 -0
- package/lib/old/client.js +33 -0
- package/lib/old/tools/build.js +12 -0
- package/lib/old/tools/check-app-status.d.ts +8 -0
- package/lib/old/tools/check-app-status.js +27 -0
- package/lib/old/tools/issue-app-credentials.d.ts +11 -0
- package/lib/old/tools/issue-app-credentials.js +35 -0
- package/lib/old/tools/js-sdk-integration-guide.d.ts +2 -0
- package/lib/old/tools/js-sdk-integration-guide.js +27 -0
- package/lib/old/tools/link-app.d.ts +10 -0
- package/lib/old/tools/link-app.js +73 -0
- package/lib/old/tools/publish.js +26 -11
- package/lib/old/tools/scaffold-demo-server.d.ts +2 -0
- package/lib/old/tools/scaffold-demo-server.js +94 -0
- package/lib/old/tools/verify-sdk-setup.d.ts +9 -0
- package/lib/old/tools/verify-sdk-setup.js +132 -0
- package/lib/proof/attestor.js +2 -2
- package/lib/provider/draft.js +51 -1
- package/package.json +3 -1
- package/samples/demo-server/.env.example +12 -0
- package/samples/demo-server/README.md +24 -0
- package/samples/demo-server/package.json +13 -0
- package/samples/demo-server/server.js +156 -0
- package/skill/js-sdk-integration.md +119 -0
- package/src/cdp/launcher.ts +33 -33
- package/src/mcp/api/tools.ts +3 -4
- package/src/mcp/remap_errors.ts +1 -1
- package/src/mcp/tools/agent/shared.ts +35 -1
- package/src/mcp/tools/authenticate/authenticate.ts +1 -3
- package/src/mcp/tools/authenticate/decrypt-key.ts +1 -4
- package/src/old/client.ts +60 -0
- package/src/old/tools/build.ts +12 -0
- package/src/old/tools/check-app-status.ts +33 -0
- package/src/old/tools/issue-app-credentials.ts +44 -0
- package/src/old/tools/js-sdk-integration-guide.ts +38 -0
- package/src/old/tools/link-app.ts +93 -0
- package/src/old/tools/publish.ts +26 -12
- package/src/old/tools/scaffold-demo-server.ts +120 -0
- package/src/old/tools/verify-sdk-setup.ts +162 -0
- package/src/proof/attestor.ts +7 -3
- package/src/provider/draft.ts +59 -1
|
@@ -11,6 +11,33 @@ import { authoringTools, extendTool, } from "../../../authoring/index.js";
|
|
|
11
11
|
import { runAttestorProof } from "../../../proof/attestor.js";
|
|
12
12
|
import { replayProvider } from "../../../proof/replay.js";
|
|
13
13
|
import { shapeRichProofResult } from "./proof.js";
|
|
14
|
+
/**
|
|
15
|
+
* OPRF mode this LOCAL (non-TEE) attestor can actually run. Recipes carry
|
|
16
|
+
* `oprf-mpc` — the canonical/publish mode a TEE expects — but the local dev
|
|
17
|
+
* attestor can't do MPC. gnark `oprf` (Linux/Mac, needs ZK circuits) is the
|
|
18
|
+
* strongest it supports; Windows falls back to server-side `oprf-raw` (no
|
|
19
|
+
* circuits). Proving with the wrong mode fails, which is what pushed the agent
|
|
20
|
+
* to hand-craft a plaintext workaround.
|
|
21
|
+
*/
|
|
22
|
+
const LOCAL_OPRF_MODE = process.platform === 'win32' ? 'oprf-raw' : 'oprf';
|
|
23
|
+
/**
|
|
24
|
+
* Clone `provider` with every `oprf-mpc` redaction remapped to the mode this
|
|
25
|
+
* local attestor can run, so the PROOF validates locally. The draft itself is
|
|
26
|
+
* untouched — it keeps `oprf-mpc`, so the PUBLISHED recipe is always the
|
|
27
|
+
* TEE-canonical mode regardless of where it was proved.
|
|
28
|
+
*/
|
|
29
|
+
function withLocalOprfMode(provider) {
|
|
30
|
+
const reds = provider.responseRedactions;
|
|
31
|
+
if (!reds?.some((r) => r.hash === 'oprf-mpc')) {
|
|
32
|
+
return provider;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
...provider,
|
|
36
|
+
responseRedactions: reds.map((r) => {
|
|
37
|
+
return r.hash === 'oprf-mpc' ? { ...r, hash: LOCAL_OPRF_MODE } : r;
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
14
41
|
/** The local backend for one capture: drive its tab over CDP, read its
|
|
15
42
|
* captured requests, prove via the in-process attestor, replay by re-fetch. */
|
|
16
43
|
function localBackend(entry) {
|
|
@@ -50,7 +77,9 @@ function localBackend(entry) {
|
|
|
50
77
|
};
|
|
51
78
|
},
|
|
52
79
|
prove: async (draft, opts) => {
|
|
53
|
-
|
|
80
|
+
// Prove with the locally-runnable OPRF mode; the draft (→ published
|
|
81
|
+
// recipe) keeps oprf-mpc.
|
|
82
|
+
const result = await runAttestorProof(withLocalOprfMode(draft.provider), draft.secrets, {
|
|
54
83
|
...(opts?.ownerAddress ? { ownerAddress: opts.ownerAddress } : {}),
|
|
55
84
|
...(opts?.attestorUrl ? { attestorUrl: opts.attestorUrl } : {}),
|
|
56
85
|
});
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* The hex is loaded via the client's `loadDecryptionKey` and passed straight
|
|
12
12
|
* through as `ReclaimConfig.credential` / to `decryptCallback`.
|
|
13
13
|
*/
|
|
14
|
-
import { loadDecryptionKey
|
|
14
|
+
import { loadDecryptionKey } from '@reclaimprotocol/client';
|
|
15
15
|
import { existsSync, readFileSync } from 'node:fs';
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { findProjectRoot } from "../../../paths.js";
|
package/lib/old/client.d.ts
CHANGED
|
@@ -71,6 +71,20 @@ export interface MyProvidersQuery {
|
|
|
71
71
|
pageSize?: number;
|
|
72
72
|
searchQuery?: string;
|
|
73
73
|
}
|
|
74
|
+
/** `POST /api/applications/issue-credentials` response — a brand-new,
|
|
75
|
+
* unassociated (sandboxed) app. `appSecret` is the raw eth private key;
|
|
76
|
+
* it's returned once and never stored server-side in recoverable form. */
|
|
77
|
+
export interface IssuedAppCredentials {
|
|
78
|
+
appId: string;
|
|
79
|
+
appSecret: string;
|
|
80
|
+
}
|
|
81
|
+
/** `GET /api/applications/link/nonce` response — a one-time, 5-minute-TTL
|
|
82
|
+
* challenge the caller signs with the app's private key to prove ownership
|
|
83
|
+
* in `linkAppToAccount`. */
|
|
84
|
+
export interface LinkNonce {
|
|
85
|
+
nonce: string;
|
|
86
|
+
expiresInSeconds: number;
|
|
87
|
+
}
|
|
74
88
|
/**
|
|
75
89
|
* Minimal REST client for the OLD devtools Express backend (base `/api`).
|
|
76
90
|
* Deliberately NOT a clone of `@reclaimprotocol/client`'s operationId
|
|
@@ -110,5 +124,22 @@ export declare class ReclaimOldClient {
|
|
|
110
124
|
* `#request`). Attaches the caller identity when one is set; queried
|
|
111
125
|
* anonymously otherwise. */
|
|
112
126
|
getSessionAnalyticsLogs(sessionId: string): Promise<unknown>;
|
|
127
|
+
/** Mint a brand-new, unassociated (sandboxed) app — no auth required. Link
|
|
128
|
+
* it to an account afterwards with `getLinkNonce` + `linkAppToAccount`, or
|
|
129
|
+
* use it as-is within the sandbox session limit. */
|
|
130
|
+
issueCredentials(): Promise<IssuedAppCredentials>;
|
|
131
|
+
/** One-time, 5-minute challenge for `linkAppToAccount`. Requires auth —
|
|
132
|
+
* the nonce is scoped to the authenticated user's uid. */
|
|
133
|
+
getLinkNonce(): Promise<LinkNonce>;
|
|
134
|
+
/** Link an unassociated (`issueCredentials`-minted) app to the
|
|
135
|
+
* authenticated account. `signature` must be an EIP-191 signature, made
|
|
136
|
+
* with the app's private key, over the exact string
|
|
137
|
+
* `` `Link ${appId} to account ${userId} | nonce: ${nonce}` `` — see
|
|
138
|
+
* `buildLinkMessage` in the backend's `application.controller.ts`. Fails
|
|
139
|
+
* with `APP_ALREADY_LINKED` (400) if the app already belongs to someone. */
|
|
140
|
+
linkAppToAccount(appId: string, signature: string, nonce: string): Promise<unknown>;
|
|
141
|
+
/** Public, unauthenticated app status — `isLinked`, sandbox/quota info.
|
|
142
|
+
* Works for any appId, owned or not. */
|
|
143
|
+
getApplicationStatus(appId: string): Promise<unknown>;
|
|
113
144
|
getMyProviders(query?: MyProvidersQuery): Promise<unknown>;
|
|
114
145
|
}
|
package/lib/old/client.js
CHANGED
|
@@ -89,6 +89,39 @@ export class ReclaimOldClient {
|
|
|
89
89
|
}
|
|
90
90
|
return json;
|
|
91
91
|
}
|
|
92
|
+
/** Mint a brand-new, unassociated (sandboxed) app — no auth required. Link
|
|
93
|
+
* it to an account afterwards with `getLinkNonce` + `linkAppToAccount`, or
|
|
94
|
+
* use it as-is within the sandbox session limit. */
|
|
95
|
+
async issueCredentials() {
|
|
96
|
+
const res = await __classPrivateFieldGet(this, _ReclaimOldClient_instances, "m", _ReclaimOldClient_request).call(this, 'POST', '/applications/issue-credentials');
|
|
97
|
+
return res.data;
|
|
98
|
+
}
|
|
99
|
+
/** One-time, 5-minute challenge for `linkAppToAccount`. Requires auth —
|
|
100
|
+
* the nonce is scoped to the authenticated user's uid. */
|
|
101
|
+
async getLinkNonce() {
|
|
102
|
+
const res = await __classPrivateFieldGet(this, _ReclaimOldClient_instances, "m", _ReclaimOldClient_request).call(this, 'GET', '/applications/link/nonce', {
|
|
103
|
+
auth: true,
|
|
104
|
+
});
|
|
105
|
+
return res.data;
|
|
106
|
+
}
|
|
107
|
+
/** Link an unassociated (`issueCredentials`-minted) app to the
|
|
108
|
+
* authenticated account. `signature` must be an EIP-191 signature, made
|
|
109
|
+
* with the app's private key, over the exact string
|
|
110
|
+
* `` `Link ${appId} to account ${userId} | nonce: ${nonce}` `` — see
|
|
111
|
+
* `buildLinkMessage` in the backend's `application.controller.ts`. Fails
|
|
112
|
+
* with `APP_ALREADY_LINKED` (400) if the app already belongs to someone. */
|
|
113
|
+
linkAppToAccount(appId, signature, nonce) {
|
|
114
|
+
return __classPrivateFieldGet(this, _ReclaimOldClient_instances, "m", _ReclaimOldClient_request).call(this, 'POST', '/applications/link', {
|
|
115
|
+
body: { appId, signature, nonce },
|
|
116
|
+
auth: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** Public, unauthenticated app status — `isLinked`, sandbox/quota info.
|
|
120
|
+
* Works for any appId, owned or not. */
|
|
121
|
+
async getApplicationStatus(appId) {
|
|
122
|
+
const res = await __classPrivateFieldGet(this, _ReclaimOldClient_instances, "m", _ReclaimOldClient_request).call(this, 'GET', `/applications/status/${encodeURIComponent(appId)}`);
|
|
123
|
+
return res.data;
|
|
124
|
+
}
|
|
92
125
|
getMyProviders(query = {}) {
|
|
93
126
|
// Every one of these query params is REQUIRED by the backend
|
|
94
127
|
// validator (missing/invalid → 400), so default them all here.
|
package/lib/old/tools/build.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { authenticateTool } from "./authenticate.js";
|
|
2
|
+
import { checkAppStatusTool } from "./check-app-status.js";
|
|
2
3
|
import { getProviderInfoTool } from "./get-provider-info.js";
|
|
4
|
+
import { issueAppCredentialsTool } from "./issue-app-credentials.js";
|
|
5
|
+
import { getJsSdkIntegrationGuideTool } from "./js-sdk-integration-guide.js";
|
|
6
|
+
import { linkAppTool } from "./link-app.js";
|
|
3
7
|
import { getMeProvidersTool } from "./me-providers.js";
|
|
4
8
|
import { createVersionFromCaptureTool } from "./publish.js";
|
|
9
|
+
import { scaffoldDemoServerTool } from "./scaffold-demo-server.js";
|
|
5
10
|
import { sessionAnalyticsLogsTool } from "./session-analytics-logs.js";
|
|
6
11
|
import { updateProviderMetadataTool } from "./update-provider-metadata.js";
|
|
12
|
+
import { verifySdkSetupTool } from "./verify-sdk-setup.js";
|
|
7
13
|
/**
|
|
8
14
|
* The backend-facing tools for OLD-devtools mode. Mirrors
|
|
9
15
|
* `buildCredentialTools` / `buildAgentTools`: returns a flat `RegisteredTool`
|
|
@@ -22,5 +28,11 @@ export function buildOldBackendTools(client, sdkClient) {
|
|
|
22
28
|
getProviderInfoTool(sdkClient),
|
|
23
29
|
updateProviderMetadataTool(client),
|
|
24
30
|
sessionAnalyticsLogsTool(client),
|
|
31
|
+
issueAppCredentialsTool(client),
|
|
32
|
+
linkAppTool(client),
|
|
33
|
+
checkAppStatusTool(client),
|
|
34
|
+
getJsSdkIntegrationGuideTool(),
|
|
35
|
+
scaffoldDemoServerTool(),
|
|
36
|
+
verifySdkSetupTool(client),
|
|
25
37
|
];
|
|
26
38
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../mcp/server.ts';
|
|
2
|
+
import type { ReclaimOldClient } from '../client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Public, unauthenticated app status lookup — works for any `appId`, owned
|
|
5
|
+
* or not, linked or sandboxed. Mirrors the backend's
|
|
6
|
+
* `GET /api/applications/status/:appId`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkAppStatusTool(client: ReclaimOldClient): RegisteredTool;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineTool } from "../../mcp/server.js";
|
|
2
|
+
/**
|
|
3
|
+
* Public, unauthenticated app status lookup — works for any `appId`, owned
|
|
4
|
+
* or not, linked or sandboxed. Mirrors the backend's
|
|
5
|
+
* `GET /api/applications/status/:appId`.
|
|
6
|
+
*/
|
|
7
|
+
export function checkAppStatusTool(client) {
|
|
8
|
+
return defineTool({
|
|
9
|
+
name: 'check_app_status',
|
|
10
|
+
description: 'Check a Reclaim app\'s link/sandbox status by appId — no ' +
|
|
11
|
+
'authentication required. Returns whether the app is linked to a ' +
|
|
12
|
+
'dashboard account (`isLinked`), and for linked apps, remaining ' +
|
|
13
|
+
'session quota. A 404 means the appId has never been used yet — ' +
|
|
14
|
+
'it is created lazily on the first ReclaimProofRequest.init() call ' +
|
|
15
|
+
'or via issue_app_credentials.',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
appId: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'The eth-address appId to check.',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ['appId'],
|
|
25
|
+
},
|
|
26
|
+
}, async ({ appId }) => client.getApplicationStatus(appId));
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../mcp/server.ts';
|
|
2
|
+
import type { ReclaimOldClient } from '../client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Mint a brand-new eth-keypair APP (as opposed to authenticating as a
|
|
5
|
+
* dashboard user). `appId` is the eth address, `appSecret` the raw private
|
|
6
|
+
* key — this is the pair `@reclaimprotocol/js-sdk`'s `ReclaimProofRequest.init`
|
|
7
|
+
* expects. No auth required: the app starts unassociated (`creatorUid: null`)
|
|
8
|
+
* and sandboxed (`sandboxLimit: 100` sessions). Use `link_app_to_account` to
|
|
9
|
+
* attach it to your dashboard account, or `check_app_status` to inspect it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function issueAppCredentialsTool(client: ReclaimOldClient): RegisteredTool;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineTool } from "../../mcp/server.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mint a brand-new eth-keypair APP (as opposed to authenticating as a
|
|
4
|
+
* dashboard user). `appId` is the eth address, `appSecret` the raw private
|
|
5
|
+
* key — this is the pair `@reclaimprotocol/js-sdk`'s `ReclaimProofRequest.init`
|
|
6
|
+
* expects. No auth required: the app starts unassociated (`creatorUid: null`)
|
|
7
|
+
* and sandboxed (`sandboxLimit: 100` sessions). Use `link_app_to_account` to
|
|
8
|
+
* attach it to your dashboard account, or `check_app_status` to inspect it.
|
|
9
|
+
*/
|
|
10
|
+
export function issueAppCredentialsTool(client) {
|
|
11
|
+
return defineTool({
|
|
12
|
+
name: 'issue_app_credentials',
|
|
13
|
+
description: 'Mint a new Reclaim APP (eth keypair) on the old devtools backend — ' +
|
|
14
|
+
'no authentication required. Returns `{ appId, appSecret }`: ' +
|
|
15
|
+
'`appId` is the eth address, `appSecret` the raw private key. This ' +
|
|
16
|
+
'is the appId/appSecret pair for @reclaimprotocol/js-sdk ' +
|
|
17
|
+
'(`ReclaimProofRequest.init(appId, appSecret, providerId)`). The app ' +
|
|
18
|
+
'starts UNLINKED and sandboxed (100 sessions) — call ' +
|
|
19
|
+
'link_app_to_account to attach it to your dashboard account and ' +
|
|
20
|
+
'check_app_status to check its state. Store `appSecret` like a ' +
|
|
21
|
+
'password (e.g. in a gitignored .env as RECLAIM_APP_SECRET) — it ' +
|
|
22
|
+
'is returned once and cannot be recovered from the server.',
|
|
23
|
+
inputSchema: { type: 'object', properties: {} },
|
|
24
|
+
}, async () => {
|
|
25
|
+
const { appId, appSecret } = await client.issueCredentials();
|
|
26
|
+
return {
|
|
27
|
+
appId,
|
|
28
|
+
appSecret,
|
|
29
|
+
note: 'Unlinked, sandboxed app (100 session limit). Set RECLAIM_APP_ID ' +
|
|
30
|
+
'and RECLAIM_APP_SECRET in your .env (gitignored). Run ' +
|
|
31
|
+
'link_app_to_account to attach it to your dashboard account and ' +
|
|
32
|
+
'lift the sandbox limit.',
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { defineTool } from "../../mcp/server.js";
|
|
4
|
+
/**
|
|
5
|
+
* Verified against `@reclaimprotocol/js-sdk` v5.8.1 source
|
|
6
|
+
* (`reclaim-js-sdk/src/Reclaim.ts`) — NOT copied unchecked from the archived
|
|
7
|
+
* `reclaim-mcp-server`'s guide, which predates several of these signatures.
|
|
8
|
+
* The prose lives in `skill/js-sdk-integration.md` so it can be edited as
|
|
9
|
+
* markdown without touching code — same pattern as `provider/injection-doc.ts`.
|
|
10
|
+
* The path resolves the same from `src/old/tools` (dev) and `lib/old/tools`
|
|
11
|
+
* (published): both are three levels below the package root.
|
|
12
|
+
*/
|
|
13
|
+
const GUIDE = readFileSync(fileURLToPath(new URL('../../../skill/js-sdk-integration.md', import.meta.url)), 'utf8').trim();
|
|
14
|
+
export function getJsSdkIntegrationGuideTool() {
|
|
15
|
+
return defineTool({
|
|
16
|
+
name: 'get_js_sdk_integration_guide',
|
|
17
|
+
description: 'Return a verified, copy-pasteable guide for integrating ' +
|
|
18
|
+
'@reclaimprotocol/js-sdk (backend proof request + callback ' +
|
|
19
|
+
'verification), checked against the current SDK source rather than ' +
|
|
20
|
+
'assumed from older docs. Covers testing locally without deploying: ' +
|
|
21
|
+
'the built-in "example" providerId for a quick smoke test, and using ' +
|
|
22
|
+
'ngrok to get a callback URL Reclaim\'s servers can actually reach. ' +
|
|
23
|
+
'Use scaffold_reclaim_demo_server to generate a runnable local demo ' +
|
|
24
|
+
'instead of copy-pasting by hand.',
|
|
25
|
+
inputSchema: { type: 'object', properties: {} },
|
|
26
|
+
}, async () => ({ guide: GUIDE }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../mcp/server.ts';
|
|
2
|
+
import type { ReclaimOldClient } from '../client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Link an unassociated app (minted via `issue_app_credentials`, or any
|
|
5
|
+
* eth-keypair app you already hold the private key for) to the currently
|
|
6
|
+
* authenticated dashboard account. Proves ownership by signing a one-time
|
|
7
|
+
* challenge with the app's private key — the private key itself is only
|
|
8
|
+
* ever used locally to sign, never sent to the server.
|
|
9
|
+
*/
|
|
10
|
+
export declare function linkAppTool(client: ReclaimOldClient): RegisteredTool;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { signEip191 } from '@reclaimprotocol/client';
|
|
2
|
+
import { defineTool } from "../../mcp/server.js";
|
|
3
|
+
/** Byte-for-byte the same format as the backend's `buildLinkMessage` in
|
|
4
|
+
* `application.controller.ts` — MUST stay in lockstep with it. */
|
|
5
|
+
function buildLinkMessage(appId, userId, nonce) {
|
|
6
|
+
return `Link ${appId} to account ${userId} | nonce: ${nonce}`;
|
|
7
|
+
}
|
|
8
|
+
/** The uid the backend binds into the signed message — `req.user.uid` there.
|
|
9
|
+
* For a bearer identity this comes back from `POST /users/login`; for an eth
|
|
10
|
+
* identity, `OldIdentity.uid` (already `eth:<address>`) IS that uid. */
|
|
11
|
+
async function resolveUserId(client) {
|
|
12
|
+
const identity = client.getIdentity();
|
|
13
|
+
if (!identity) {
|
|
14
|
+
throw new Error('Not authenticated against old devtools. Call reclaim_authenticate ' +
|
|
15
|
+
'first.');
|
|
16
|
+
}
|
|
17
|
+
if (identity.kind === 'eth') {
|
|
18
|
+
return identity.uid;
|
|
19
|
+
}
|
|
20
|
+
const res = await client.loginWithToken();
|
|
21
|
+
const uid = res?.user?.uid;
|
|
22
|
+
if (!uid) {
|
|
23
|
+
throw new Error('Could not resolve your account uid from POST /users/login — ' +
|
|
24
|
+
'unexpected response shape.');
|
|
25
|
+
}
|
|
26
|
+
return uid;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Link an unassociated app (minted via `issue_app_credentials`, or any
|
|
30
|
+
* eth-keypair app you already hold the private key for) to the currently
|
|
31
|
+
* authenticated dashboard account. Proves ownership by signing a one-time
|
|
32
|
+
* challenge with the app's private key — the private key itself is only
|
|
33
|
+
* ever used locally to sign, never sent to the server.
|
|
34
|
+
*/
|
|
35
|
+
export function linkAppTool(client) {
|
|
36
|
+
return defineTool({
|
|
37
|
+
name: 'link_app_to_account',
|
|
38
|
+
description: 'Link an eth-keypair app to your authenticated dashboard account — ' +
|
|
39
|
+
'use this to keep using an appId/appSecret you already have ' +
|
|
40
|
+
'(instead of minting a fresh one via issue_app_credentials). ' +
|
|
41
|
+
'Requires reclaim_authenticate first. Fetches a one-time nonce, ' +
|
|
42
|
+
'signs `Link <appId> to account <userId> | nonce: <nonce>` locally ' +
|
|
43
|
+
'with `appSecret` (EIP-191, never transmitted), and submits the ' +
|
|
44
|
+
'signature. Fails with APP_ALREADY_LINKED if the app is already ' +
|
|
45
|
+
'linked to a (possibly different) account.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
appId: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'The eth-address appId to link.',
|
|
52
|
+
},
|
|
53
|
+
appSecret: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'The app\'s raw eth private key — used only locally to sign ' +
|
|
56
|
+
'the link challenge, never sent to the server.',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
required: ['appId', 'appSecret'],
|
|
60
|
+
},
|
|
61
|
+
}, async ({ appId, appSecret }) => {
|
|
62
|
+
const userId = await resolveUserId(client);
|
|
63
|
+
const { nonce } = await client.getLinkNonce();
|
|
64
|
+
const message = buildLinkMessage(appId, userId, nonce);
|
|
65
|
+
const signature = signEip191(message, appSecret);
|
|
66
|
+
await client.linkAppToAccount(appId, signature, nonce);
|
|
67
|
+
return {
|
|
68
|
+
linked: true,
|
|
69
|
+
appId,
|
|
70
|
+
note: 'App linked to your account. Run check_app_status to confirm.',
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
package/lib/old/tools/publish.js
CHANGED
|
@@ -104,9 +104,16 @@ export function createVersionFromCaptureTool(client) {
|
|
|
104
104
|
type: 'array',
|
|
105
105
|
description: 'Multiple proven drafts → one multi-request version (each ' +
|
|
106
106
|
'becomes a parallel `requestData` entry, all verified ' +
|
|
107
|
-
'together). Each item has the same shape as `provider
|
|
108
|
-
'
|
|
109
|
-
|
|
107
|
+
'together). Each item has the same shape as `provider` (if ' +
|
|
108
|
+
'both are passed, they are combined). May be omitted (or ' +
|
|
109
|
+
'empty) together with `provider` ONLY when adding a version ' +
|
|
110
|
+
'to an EXISTING provider (`providerId` set) — publishes with ' +
|
|
111
|
+
'zero `requestData` entries, for a pure customInjection/' +
|
|
112
|
+
'HAWKEYE provider that relies entirely on ' +
|
|
113
|
+
'`allowedInjectedRequestData` for validation instead of a ' +
|
|
114
|
+
'static requestData stub. Registering a brand-new provider ' +
|
|
115
|
+
'always needs at least one draft (its name comes from the ' +
|
|
116
|
+
'first one).',
|
|
110
117
|
items: {
|
|
111
118
|
type: 'object',
|
|
112
119
|
properties: {
|
|
@@ -241,15 +248,23 @@ export function createVersionFromCaptureTool(client) {
|
|
|
241
248
|
required: ['initialUrl'],
|
|
242
249
|
},
|
|
243
250
|
}, async (args) => {
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
+
// `provider` / `providers` are just two spellings of the same input —
|
|
252
|
+
// fold them into one array. Zero drafts is allowed ONLY when adding a
|
|
253
|
+
// version to an EXISTING provider (`providerId` set): that publishes
|
|
254
|
+
// with zero `requestData` entries, for a pure customInjection/HAWKEYE
|
|
255
|
+
// provider whose claims are validated entirely via
|
|
256
|
+
// `allowedInjectedRequestData`. Registering a brand-new provider still
|
|
257
|
+
// needs at least one draft — its name comes from the first one.
|
|
258
|
+
const providers = [
|
|
259
|
+
...(args.provider ? [args.provider] : []),
|
|
260
|
+
...(args.providers ?? []),
|
|
261
|
+
];
|
|
262
|
+
if (!providers.length && !args.providerId) {
|
|
263
|
+
throw new Boom('Pass at least one of `provider`/`providers` when registering a ' +
|
|
264
|
+
'new provider (its name comes from the first draft). Omitting ' +
|
|
265
|
+
'both is only allowed when adding a version to an EXISTING ' +
|
|
266
|
+
'provider via `providerId`.', { statusCode: 400 });
|
|
251
267
|
}
|
|
252
|
-
const providers = hasMany ? args.providers : [args.provider];
|
|
253
268
|
const opts = {
|
|
254
269
|
initialUrl: args.initialUrl,
|
|
255
270
|
description: args.description,
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { defineTool } from "../../mcp/server.js";
|
|
5
|
+
import { findProjectRoot } from "../../paths.js";
|
|
6
|
+
/** The demo's source files live in `samples/demo-server/` so they can be
|
|
7
|
+
* edited (and even run) as plain files without touching code — same pattern
|
|
8
|
+
* as `skill/*.md`. The path resolves the same from `src/old/tools` (dev) and
|
|
9
|
+
* `lib/old/tools` (published): both are three levels below the package root.
|
|
10
|
+
*
|
|
11
|
+
* `server.js` there is corrected against `@reclaimprotocol/js-sdk` v5.8.1
|
|
12
|
+
* (`Reclaim.ts`): awaits `getRequestUrl()`, uses `setContext` (not deprecated
|
|
13
|
+
* `addContext`), JSON-parses the raw webhook body before `verifyProof`,
|
|
14
|
+
* passes the required `{ providerId, providerVersion }` config, and reads
|
|
15
|
+
* `result.isVerified` (not `is_verified`). `providerVersion` is left unpinned
|
|
16
|
+
* by default — the built-in "example" providerId isn't versioned, so pinning
|
|
17
|
+
* one is only meaningful once you swap in your own provider. */
|
|
18
|
+
const SAMPLE_DIR = fileURLToPath(new URL('../../../samples/demo-server', import.meta.url));
|
|
19
|
+
function readSample(name) {
|
|
20
|
+
return readFileSync(join(SAMPLE_DIR, name), 'utf8');
|
|
21
|
+
}
|
|
22
|
+
/** `server.js` with its `__PROVIDER_ID__` / `__PROVIDER_VERSION__` tokens
|
|
23
|
+
* substituted with JS literals. */
|
|
24
|
+
function serverJs(providerId, providerVersion) {
|
|
25
|
+
return readSample('server.js')
|
|
26
|
+
.replace('__PROVIDER_ID__', JSON.stringify(providerId))
|
|
27
|
+
.replace('__PROVIDER_VERSION__', providerVersion ? JSON.stringify(providerVersion) : 'undefined');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scaffold a small, runnable Express demo that exercises the full
|
|
31
|
+
* @reclaimprotocol/js-sdk flow end-to-end: request a proof (backend), open it
|
|
32
|
+
* (frontend), and verify the async webhook callback (backend). Corrected
|
|
33
|
+
* against the CURRENT SDK API (see js-sdk-integration-guide) rather than
|
|
34
|
+
* older examples that predate several signature changes.
|
|
35
|
+
*/
|
|
36
|
+
const DEFAULT_PROVIDER_ID = 'example';
|
|
37
|
+
export function scaffoldDemoServerTool() {
|
|
38
|
+
return defineTool({
|
|
39
|
+
name: 'scaffold_reclaim_demo_server',
|
|
40
|
+
description: 'Write a small runnable Express demo (server.js, package.json, ' +
|
|
41
|
+
'.env.example, README.md) that requests a Reclaim proof and ' +
|
|
42
|
+
'verifies the async webhook callback, using the CURRENT ' +
|
|
43
|
+
'@reclaimprotocol/js-sdk API. Defaults `providerId` to the built-in ' +
|
|
44
|
+
'"example" smoke-test provider so you can confirm the whole loop ' +
|
|
45
|
+
'without authoring one first. The webhook callback needs a URL ' +
|
|
46
|
+
'Reclaim\'s servers can reach — localhost never works — via EITHER ' +
|
|
47
|
+
'a tunnel (ngrok or similar) OR quickly deploying this demo to a ' +
|
|
48
|
+
'dev/staging server the user already has; ASK THE USER which they\'d ' +
|
|
49
|
+
'rather use before assuming ngrok, since either sets `PUBLIC_URL` in ' +
|
|
50
|
+
'.env (the generated README covers both). Use ' +
|
|
51
|
+
'get_js_sdk_integration_guide for the annotated write-up of the ' +
|
|
52
|
+
'same flow.',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
targetDir: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Directory to write the demo into (created if missing). ' +
|
|
59
|
+
'Relative paths resolve against the project root.',
|
|
60
|
+
},
|
|
61
|
+
providerId: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Provider id the demo requests a proof for (default ' +
|
|
64
|
+
'"example", a built-in smoke-test provider — good for ' +
|
|
65
|
+
'confirming the flow works before wiring in a real one).',
|
|
66
|
+
},
|
|
67
|
+
providerVersion: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
description: 'Provider version to pin (default: unpinned — "example" ' +
|
|
70
|
+
'isn\'t versioned, so only set this once you swap in your ' +
|
|
71
|
+
'own provider).',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
required: ['targetDir'],
|
|
75
|
+
},
|
|
76
|
+
}, async ({ targetDir, providerId, providerVersion }) => {
|
|
77
|
+
const dir = isAbsolute(targetDir)
|
|
78
|
+
? targetDir
|
|
79
|
+
: join(findProjectRoot(process.cwd()), targetDir);
|
|
80
|
+
mkdirSync(dir, { recursive: true });
|
|
81
|
+
const id = providerId ?? DEFAULT_PROVIDER_ID;
|
|
82
|
+
writeFileSync(join(dir, 'server.js'), serverJs(id, providerVersion));
|
|
83
|
+
writeFileSync(join(dir, 'package.json'), readSample('package.json'));
|
|
84
|
+
writeFileSync(join(dir, '.env.example'), readSample('.env.example'));
|
|
85
|
+
writeFileSync(join(dir, 'README.md'), readSample('README.md'));
|
|
86
|
+
return {
|
|
87
|
+
dir,
|
|
88
|
+
providerId: id,
|
|
89
|
+
files: ['server.js', 'package.json', '.env.example', 'README.md'],
|
|
90
|
+
next: 'cd into the directory, npm install, copy .env.example to .env ' +
|
|
91
|
+
'and fill it in (including PUBLIC_URL from ngrok), then npm start.',
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../mcp/server.ts';
|
|
2
|
+
import type { ReclaimOldClient } from '../client.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Health-check a project's @reclaimprotocol/js-sdk setup: SDK installed,
|
|
5
|
+
* RECLAIM_APP_ID/RECLAIM_APP_SECRET present (env or .env), and (if an appId
|
|
6
|
+
* is found) whether that app is actually linked/has quota, via the real
|
|
7
|
+
* check_app_status endpoint — not just static file checks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function verifySdkSetupTool(client: ReclaimOldClient): RegisteredTool;
|