@reclaimprotocol/agent 0.1.1 → 0.1.2
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/cdp/launcher.js +4 -3
- package/lib/consts.d.ts +68 -0
- package/lib/consts.js +134 -0
- package/lib/logger.js +2 -1
- package/lib/mcp/api/operations.gen.d.ts +3 -7
- package/lib/mcp/api/operations.gen.js +264 -199
- package/lib/mcp/server.d.ts +0 -6
- package/lib/mcp/server.js +0 -30
- package/lib/mcp/start.js +7 -7
- package/lib/mcp/tools/agent/build.d.ts +5 -9
- package/lib/mcp/tools/agent/build.js +5 -9
- package/lib/mcp/tools/agent/proof.js +2 -1
- package/lib/mcp/tools/agent/publish.js +166 -77
- package/lib/mcp/tools/authenticate/decrypt-key.d.ts +10 -23
- package/lib/mcp/tools/authenticate/decrypt-key.js +23 -26
- package/lib/mcp/tools/authenticate/eth-key.d.ts +0 -7
- package/lib/mcp/tools/authenticate/eth-key.js +5 -19
- package/lib/mcp/tools/authenticate/issue.js +1 -1
- package/lib/mcp/tools/verification/build.d.ts +1 -1
- package/lib/mcp/tools/verification/build.js +1 -1
- package/lib/mcp/tools/verification/result.d.ts +4 -5
- package/lib/mcp/tools/verification/result.js +17 -17
- package/lib/old/flag.d.ts +4 -1
- package/lib/old/flag.js +4 -3
- package/lib/old/identity.d.ts +0 -10
- package/lib/old/identity.js +8 -7
- package/lib/old/login-cdp.d.ts +0 -3
- package/lib/old/login-cdp.js +2 -4
- package/lib/old/to-register.js +6 -9
- package/lib/old/tools/authenticate.js +2 -1
- package/lib/old/tools/publish.js +58 -9
- package/lib/paths.js +2 -2
- package/lib/proof/attestor.js +2 -1
- package/lib/proof/proof-core.js +13 -2
- package/lib/provider/injection-doc.d.ts +1 -0
- package/lib/provider/injection-doc.js +17 -0
- package/lib/provider/match-redaction-warning.d.ts +25 -0
- package/lib/provider/match-redaction-warning.js +35 -0
- package/lib/provider/schema.d.ts +16 -0
- package/lib/provider/schema.js +11 -1
- package/lib/provider/to-version.d.ts +59 -7
- package/lib/provider/to-version.js +79 -28
- package/package.json +1 -1
- package/skill/builder-mode.md +6 -2
- package/skill/injection-api.md +42 -0
- package/skill/old-mode.md +2 -0
- package/src/cdp/launcher.ts +5 -4
- package/src/consts.ts +164 -0
- package/src/logger.ts +2 -1
- package/src/mcp/api/operations.gen.ts +262 -203
- package/src/mcp/server.ts +0 -46
- package/src/mcp/start.ts +13 -7
- package/src/mcp/tools/agent/build.ts +5 -9
- package/src/mcp/tools/agent/proof.ts +2 -1
- package/src/mcp/tools/agent/publish.ts +212 -94
- package/src/mcp/tools/authenticate/decrypt-key.ts +24 -29
- package/src/mcp/tools/authenticate/eth-key.ts +5 -25
- package/src/mcp/tools/authenticate/issue.ts +1 -1
- package/src/mcp/tools/verification/build.ts +1 -1
- package/src/mcp/tools/verification/result.ts +16 -17
- package/src/old/flag.ts +4 -3
- package/src/old/identity.ts +8 -7
- package/src/old/login-cdp.ts +2 -5
- package/src/old/to-register.ts +7 -10
- package/src/old/tools/authenticate.ts +2 -1
- package/src/old/tools/publish.ts +75 -15
- package/src/paths.ts +2 -2
- package/src/proof/attestor.ts +2 -1
- package/src/proof/proof-core.ts +13 -3
- package/src/provider/injection-doc.ts +21 -0
- package/src/provider/match-redaction-warning.ts +53 -0
- package/src/provider/schema.ts +23 -0
- package/src/provider/to-version.ts +137 -31
|
@@ -3,7 +3,7 @@ import type { RegisteredTool } from '../../server.ts';
|
|
|
3
3
|
* Builder-mode verification tools: higher-level orchestrations over the
|
|
4
4
|
* generated API surface. `get_verification_result` authenticates with the org
|
|
5
5
|
* token, checks status, pulls the stored payload, and decrypts it locally with
|
|
6
|
-
* the optional
|
|
6
|
+
* the optional eth key — a flow the generated raw-API tools can't express
|
|
7
7
|
* (the decryption key never leaves the consumer). Diagnosis is left to the
|
|
8
8
|
* agent over the generated tools (`get_verification_session`,
|
|
9
9
|
* `list_verification_events`, `list_verification_deliveries`), whose
|
|
@@ -3,7 +3,7 @@ import { verificationResultTool } from "./result.js";
|
|
|
3
3
|
* Builder-mode verification tools: higher-level orchestrations over the
|
|
4
4
|
* generated API surface. `get_verification_result` authenticates with the org
|
|
5
5
|
* token, checks status, pulls the stored payload, and decrypts it locally with
|
|
6
|
-
* the optional
|
|
6
|
+
* the optional eth key — a flow the generated raw-API tools can't express
|
|
7
7
|
* (the decryption key never leaves the consumer). Diagnosis is left to the
|
|
8
8
|
* agent over the generated tools (`get_verification_session`,
|
|
9
9
|
* `list_verification_events`, `list_verification_deliveries`), whose
|
|
@@ -3,10 +3,9 @@ import { type RegisteredTool } from '../../server.ts';
|
|
|
3
3
|
* `get_verification_result` — check a session's status and, once a result has
|
|
4
4
|
* been submitted, pull the stored payload(s) and verify locally. Auth is the
|
|
5
5
|
* org token; delivery is org-scoped. Each stored payload is either the
|
|
6
|
-
* plaintext signed JWS (when the org
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* here.
|
|
6
|
+
* plaintext signed JWS (when the org's encryption is off) or an ECIES
|
|
7
|
+
* ciphertext that we decrypt here with the optional eth key
|
|
8
|
+
* (`RECLAIM_DECRYPT_KEY` or the `reclaim-decrypt.key` hex file). The Builder
|
|
9
|
+
* only ever relays the payload — decryption, when needed, happens here.
|
|
11
10
|
*/
|
|
12
11
|
export declare function verificationResultTool(): RegisteredTool;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createReclaim, decryptCallback,
|
|
1
|
+
import { createReclaim, decryptCallback, verifyResultFull, } from '@reclaimprotocol/client';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
|
+
import { apiUrl, orgSecret } from "../../../consts.js";
|
|
3
4
|
import { defineTool } from "../../server.js";
|
|
4
5
|
import { resolveDecryptionKey } from "../authenticate/decrypt-key.js";
|
|
5
6
|
/** Statuses that can carry a submitted (terminal) result. `expired`/`pending`
|
|
@@ -11,7 +12,7 @@ const TERMINAL = new Set(['success', 'rejected', 'error']);
|
|
|
11
12
|
* `RECLAIM_ORG_SECRET`.
|
|
12
13
|
*/
|
|
13
14
|
function resolveOrgSecret() {
|
|
14
|
-
const secret =
|
|
15
|
+
const secret = orgSecret()?.trim();
|
|
15
16
|
assert(secret, new Error('RECLAIM_ORG_SECRET is not set. Verification reads authenticate with ' +
|
|
16
17
|
'the org secret (rorg_…) — issue one from the dashboard ' +
|
|
17
18
|
'(POST /orgs/{orgId}/token) and export it as RECLAIM_ORG_SECRET.'));
|
|
@@ -21,11 +22,10 @@ function resolveOrgSecret() {
|
|
|
21
22
|
* `get_verification_result` — check a session's status and, once a result has
|
|
22
23
|
* been submitted, pull the stored payload(s) and verify locally. Auth is the
|
|
23
24
|
* org token; delivery is org-scoped. Each stored payload is either the
|
|
24
|
-
* plaintext signed JWS (when the org
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* here.
|
|
25
|
+
* plaintext signed JWS (when the org's encryption is off) or an ECIES
|
|
26
|
+
* ciphertext that we decrypt here with the optional eth key
|
|
27
|
+
* (`RECLAIM_DECRYPT_KEY` or the `reclaim-decrypt.key` hex file). The Builder
|
|
28
|
+
* only ever relays the payload — decryption, when needed, happens here.
|
|
29
29
|
*/
|
|
30
30
|
export function verificationResultTool() {
|
|
31
31
|
return defineTool({
|
|
@@ -34,9 +34,9 @@ export function verificationResultTool() {
|
|
|
34
34
|
'Authenticates with the org secret (RECLAIM_ORG_SECRET). Fetches the ' +
|
|
35
35
|
'session status; if it is terminal and a result has been submitted, ' +
|
|
36
36
|
'pulls the stored result(s) and verifies them locally. Encrypted ' +
|
|
37
|
-
'deliveries (
|
|
38
|
-
'
|
|
39
|
-
'
|
|
37
|
+
'deliveries (ECIES over secp256k1) are decrypted with your optional ' +
|
|
38
|
+
'eth key (RECLAIM_DECRYPT_KEY or reclaim-decrypt.key); plaintext ' +
|
|
39
|
+
'deliveries are read directly. Returns ' +
|
|
40
40
|
'`ready: false` while the session is still pending or no result has ' +
|
|
41
41
|
'been delivered yet. Use list_verification_events for the full ' +
|
|
42
42
|
'lifecycle log.',
|
|
@@ -51,12 +51,12 @@ export function verificationResultTool() {
|
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
53
|
}, async (args) => {
|
|
54
|
-
const
|
|
55
|
-
// Optional
|
|
54
|
+
const secret = resolveOrgSecret();
|
|
55
|
+
// Optional eth decryption key — absent ⇒ plaintext-only.
|
|
56
56
|
const decryptionKey = await resolveDecryptionKey();
|
|
57
57
|
const reclaim = createReclaim({
|
|
58
|
-
baseUrl:
|
|
59
|
-
orgSecret,
|
|
58
|
+
baseUrl: apiUrl(),
|
|
59
|
+
orgSecret: secret,
|
|
60
60
|
});
|
|
61
61
|
const sessionRes = await reclaim.api('GetVerificationSession', {
|
|
62
62
|
params: { sessionId: args.sessionId },
|
|
@@ -110,9 +110,9 @@ export function verificationResultTool() {
|
|
|
110
110
|
status,
|
|
111
111
|
ready: false,
|
|
112
112
|
note: 'A result was stored, but no payload could be read — it is ' +
|
|
113
|
-
'corrupt, or encrypted (
|
|
114
|
-
'hold.
|
|
115
|
-
'
|
|
113
|
+
'corrupt, or encrypted (ECIES) to a key this consumer does not ' +
|
|
114
|
+
'hold. Set RECLAIM_DECRYPT_KEY (or reclaim-decrypt.key) to the ' +
|
|
115
|
+
'eth private key matching the org keypair.',
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
return {
|
package/lib/old/flag.d.ts
CHANGED
|
@@ -7,5 +7,8 @@
|
|
|
7
7
|
* EXPLICITLY by setting `USE_OLD_DEVTOOLS=false`. Anything else — unset,
|
|
8
8
|
* empty, `true`, `1`, a typo — keeps old mode on, so a forgotten env var
|
|
9
9
|
* can never silently route a developer at the half-built builder backend.
|
|
10
|
+
*
|
|
11
|
+
* The actual env read lives in `../consts.ts` (the single env-access module);
|
|
12
|
+
* this widely-imported path re-exports it for back-compat.
|
|
10
13
|
*/
|
|
11
|
-
export
|
|
14
|
+
export { useOldDevtools } from '../consts.ts';
|
package/lib/old/flag.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* EXPLICITLY by setting `USE_OLD_DEVTOOLS=false`. Anything else — unset,
|
|
8
8
|
* empty, `true`, `1`, a typo — keeps old mode on, so a forgotten env var
|
|
9
9
|
* can never silently route a developer at the half-built builder backend.
|
|
10
|
+
*
|
|
11
|
+
* The actual env read lives in `../consts.ts` (the single env-access module);
|
|
12
|
+
* this widely-imported path re-exports it for back-compat.
|
|
10
13
|
*/
|
|
11
|
-
export
|
|
12
|
-
return (process.env.USE_OLD_DEVTOOLS ?? '').trim().toLowerCase() !== 'false';
|
|
13
|
-
}
|
|
14
|
+
export { useOldDevtools } from "../consts.js";
|
package/lib/old/identity.d.ts
CHANGED
|
@@ -2,16 +2,6 @@ import type { OldIdentity } from './client.ts';
|
|
|
2
2
|
/** Normalize an eth uid input to `eth:<lowercase-address>`. Accepts a bare
|
|
3
3
|
* `0x…` address or an already-prefixed `eth:0x…`. */
|
|
4
4
|
export declare function toEthUid(addressOrUid: string): OldIdentity;
|
|
5
|
-
/**
|
|
6
|
-
* Resolve a caller identity from the environment, in priority order:
|
|
7
|
-
* 1. `RECLAIM_OLD_API_TOKEN` — a dashboard Firebase bearer token.
|
|
8
|
-
* 2. `RECLAIM_OLD_ETH_UID` — an `eth:<addr>` (or bare `0x…`) uid.
|
|
9
|
-
* 3. `RECLAIM_PRIVATE_KEY` — derive the eth uid from the local app key.
|
|
10
|
-
* Returns undefined when none is set.
|
|
11
|
-
*/
|
|
12
|
-
export declare function resolveIdentityFromEnv(): OldIdentity | undefined;
|
|
13
|
-
/** Read the identity persisted by a prior `reclaim_authenticate` call. */
|
|
14
|
-
export declare function loadPersistedIdentity(): OldIdentity | undefined;
|
|
15
5
|
/** Persist the identity so it survives an MCP-server restart. */
|
|
16
6
|
export declare function persistIdentity(identity: OldIdentity): void;
|
|
17
7
|
/**
|
package/lib/old/identity.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deriveFromPrivateKey } from '@reclaimprotocol/client';
|
|
2
2
|
import { ConfigStore } from "../config/store.js";
|
|
3
|
+
import { oldApiToken, oldEthUid, privateKey } from "../consts.js";
|
|
3
4
|
/** Normalize an eth uid input to `eth:<lowercase-address>`. Accepts a bare
|
|
4
5
|
* `0x…` address or an already-prefixed `eth:0x…`. */
|
|
5
6
|
export function toEthUid(addressOrUid) {
|
|
@@ -14,23 +15,23 @@ export function toEthUid(addressOrUid) {
|
|
|
14
15
|
* 3. `RECLAIM_PRIVATE_KEY` — derive the eth uid from the local app key.
|
|
15
16
|
* Returns undefined when none is set.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
const token =
|
|
18
|
+
function resolveIdentityFromEnv() {
|
|
19
|
+
const token = oldApiToken()?.trim();
|
|
19
20
|
if (token) {
|
|
20
21
|
return { kind: 'bearer', token };
|
|
21
22
|
}
|
|
22
|
-
const ethUid =
|
|
23
|
+
const ethUid = oldEthUid()?.trim();
|
|
23
24
|
if (ethUid) {
|
|
24
25
|
return toEthUid(ethUid);
|
|
25
26
|
}
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
return toEthUid(deriveFromPrivateKey(
|
|
27
|
+
const key = privateKey()?.trim();
|
|
28
|
+
if (key) {
|
|
29
|
+
return toEthUid(deriveFromPrivateKey(key).address);
|
|
29
30
|
}
|
|
30
31
|
return undefined;
|
|
31
32
|
}
|
|
32
33
|
/** Read the identity persisted by a prior `reclaim_authenticate` call. */
|
|
33
|
-
|
|
34
|
+
function loadPersistedIdentity() {
|
|
34
35
|
return new ConfigStore().read()?.old_devtools;
|
|
35
36
|
}
|
|
36
37
|
/** Persist the identity so it survives an MCP-server restart. */
|
package/lib/old/login-cdp.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** The devtools dashboard login page. Override per-call or via
|
|
2
|
-
* `RECLAIM_OLD_LOGIN_URL`. */
|
|
3
|
-
export declare const DEFAULT_LOGIN_URL = "https://dev.reclaimprotocol.org";
|
|
4
1
|
export interface CdpLoginResult {
|
|
5
2
|
token: string;
|
|
6
3
|
/** True when we launched (and then closed) a dedicated Chrome just for
|
package/lib/old/login-cdp.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { connectCdp } from "../cdp/client.js";
|
|
2
2
|
import { defaultProfileDir, launchChrome, waitForCdpReady, } from "../cdp/launcher.js";
|
|
3
3
|
import { ConfigStore } from "../config/store.js";
|
|
4
|
-
|
|
5
|
-
* `RECLAIM_OLD_LOGIN_URL`. */
|
|
6
|
-
export const DEFAULT_LOGIN_URL = 'https://dev.reclaimprotocol.org';
|
|
4
|
+
import { DEFAULT_LOGIN_URL, oldLoginUrl } from "../consts.js";
|
|
7
5
|
/**
|
|
8
6
|
* Read the Firebase ID token the dashboard persisted after login.
|
|
9
7
|
*
|
|
@@ -64,7 +62,7 @@ const EXTRACT_TOKEN_JS = `(async () => {
|
|
|
64
62
|
* disrupt it.
|
|
65
63
|
*/
|
|
66
64
|
export async function captureFirebaseTokenViaCdp(opts) {
|
|
67
|
-
const loginUrl = opts.loginUrl ||
|
|
65
|
+
const loginUrl = opts.loginUrl || oldLoginUrl() || DEFAULT_LOGIN_URL;
|
|
68
66
|
const timeoutMs = opts.timeoutMs ?? 180_000;
|
|
69
67
|
const pollMs = opts.pollMs ?? 1000;
|
|
70
68
|
const cfg = new ConfigStore().read()?.browser_agent;
|
package/lib/old/to-register.js
CHANGED
|
@@ -29,15 +29,12 @@ function requestDataFromProvider(provider) {
|
|
|
29
29
|
order: i,
|
|
30
30
|
}));
|
|
31
31
|
// Old devtools wants `responseMatches` and `responseRedactions` as PARALLEL
|
|
32
|
-
// arrays
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const sourceRedactions = provider.responseRedactions?.length
|
|
39
|
-
? provider.responseRedactions
|
|
40
|
-
: nestedRedactions;
|
|
32
|
+
// arrays — same shape the builder uses, so pass them through directly. We do
|
|
33
|
+
// NOT enforce any match/redaction count relationship here (and never pad —
|
|
34
|
+
// empty placeholder matches break proof generation): the author keeps full
|
|
35
|
+
// control. The publish tool surfaces a non-blocking warning when matches <
|
|
36
|
+
// redactions (see `matchRedactionWarnings`), and the dev decides.
|
|
37
|
+
const sourceRedactions = provider.responseRedactions ?? [];
|
|
41
38
|
const responseRedactions = sourceRedactions.map((r, i) => {
|
|
42
39
|
const out = { order: i };
|
|
43
40
|
if (r.xPath !== undefined) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { agentDisabled } from "../../consts.js";
|
|
1
2
|
import { defineTool } from "../../mcp/server.js";
|
|
2
3
|
import { persistIdentity, toEthUid } from "../identity.js";
|
|
3
4
|
import { captureFirebaseTokenViaCdp } from "../login-cdp.js";
|
|
@@ -108,7 +109,7 @@ export function authenticateTool(client) {
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
// CDP browser login (the default headline flow).
|
|
111
|
-
if (
|
|
112
|
+
if (agentDisabled()) {
|
|
112
113
|
throw new Error('Browser login is unavailable (RECLAIM_AGENT_DISABLED=1). Pass a ' +
|
|
113
114
|
'`token` (Firebase ID token) or `ethAddress` instead.');
|
|
114
115
|
}
|
package/lib/old/tools/publish.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
import { Boom, isBoom } from '@hapi/boom';
|
|
1
2
|
import { defineTool } from "../../mcp/server.js";
|
|
3
|
+
import { countsFor, matchRedactionWarnings, } from "../../provider/match-redaction-warning.js";
|
|
2
4
|
import { bumpPatchString, extractVersions, providerToConfigBody, providerToRegisterBody, } from "../to-register.js";
|
|
3
5
|
const DEFAULT_VERSION_INFO = 'Updated from MCP browser capture';
|
|
6
|
+
/**
|
|
7
|
+
* The old backend lets you add a version only to a provider YOU own. A
|
|
8
|
+
* `providerId` for a public provider (or anyone else's) comes back as
|
|
9
|
+
* 401/403/404 — the dev's likely intent is to publish their OWN version of that
|
|
10
|
+
* site, which on this backend means registering a separate copy. Rethrow those
|
|
11
|
+
* failures with that actionable suggestion; leave other errors (e.g. a 400
|
|
12
|
+
* version collision) untouched so their real detail surfaces.
|
|
13
|
+
*/
|
|
14
|
+
function rethrowOwnershipError(err, providerId) {
|
|
15
|
+
const status = isBoom(err) ? err.output.statusCode : undefined;
|
|
16
|
+
if (status !== 401 && status !== 403 && status !== 404) {
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
const base = isBoom(err) ? err.message : String(err);
|
|
20
|
+
throw new Boom(`${base} — could not add a version to provider ${providerId}. You can ` +
|
|
21
|
+
'only publish new versions on providers you own. If this is a public ' +
|
|
22
|
+
"provider (or one you don't own), re-run " +
|
|
23
|
+
'create_provider_version_from_capture WITHOUT `providerId` to register ' +
|
|
24
|
+
"your own copy. If it IS yours, confirm you're authenticated " +
|
|
25
|
+
'(reclaim_authenticate) as the account that created it.', {
|
|
26
|
+
statusCode: status,
|
|
27
|
+
data: isBoom(err) ? err.data : { status, detail: base },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
4
30
|
/**
|
|
5
31
|
* Publish a drafted provider to the OLD devtools backend. Keeps the builder
|
|
6
32
|
* tool NAME (`create_provider_version_from_capture`) so the skill flow is
|
|
@@ -25,6 +51,10 @@ export function createVersionFromCaptureTool(client) {
|
|
|
25
51
|
'1.0.0; re-running creates a duplicate). Pass `providerId` (from ' +
|
|
26
52
|
'get_me_providers) to add a NEW VERSION to that existing provider ' +
|
|
27
53
|
'(the patch is auto-bumped). \n\n' +
|
|
54
|
+
'You can only add versions to a provider YOU own — the `providerId` ' +
|
|
55
|
+
'must come from get_me_providers. To publish your own version of a ' +
|
|
56
|
+
"PUBLIC provider you don't own, omit `providerId` to register your " +
|
|
57
|
+
'own copy (you cannot edit someone else\'s provider here). \n\n' +
|
|
28
58
|
'Captured requests must be GET/POST. OPRF redactions are supported.',
|
|
29
59
|
inputSchema: {
|
|
30
60
|
type: 'object',
|
|
@@ -91,19 +121,38 @@ export function createVersionFromCaptureTool(client) {
|
|
|
91
121
|
if (args.providerType !== undefined) {
|
|
92
122
|
opts.providerType = args.providerType;
|
|
93
123
|
}
|
|
124
|
+
// Non-blocking advisory — never alters or blocks the publish; the
|
|
125
|
+
// author keeps full control. Attaches under `_notes` when relevant.
|
|
126
|
+
const notes = matchRedactionWarnings([
|
|
127
|
+
countsFor('Request', args.provider),
|
|
128
|
+
]);
|
|
129
|
+
const withNotes = (result) => {
|
|
130
|
+
if (notes.length && result && typeof result === 'object') {
|
|
131
|
+
return { ...result, _notes: notes };
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
};
|
|
94
135
|
// New provider.
|
|
95
136
|
if (!args.providerId) {
|
|
96
137
|
const body = providerToRegisterBody(args.provider, opts);
|
|
97
|
-
return client.registerProvider(body);
|
|
138
|
+
return withNotes(await client.registerProvider(body));
|
|
98
139
|
}
|
|
99
140
|
// New version of an existing provider — pick the next patch above
|
|
100
|
-
// the highest existing version.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
141
|
+
// the highest existing version. A provider you don't own (e.g. a
|
|
142
|
+
// public one) fails here with 401/403/404; surface the register-a-copy
|
|
143
|
+
// workaround instead of a bare permission error.
|
|
144
|
+
const providerId = args.providerId;
|
|
145
|
+
try {
|
|
146
|
+
const versionsResp = await client.listVersions(providerId);
|
|
147
|
+
const version = bumpPatchString(extractVersions(versionsResp));
|
|
148
|
+
const versionInfo = args.notes && args.notes.trim().length >= 10
|
|
149
|
+
? args.notes.trim()
|
|
150
|
+
: DEFAULT_VERSION_INFO;
|
|
151
|
+
const body = providerToConfigBody(args.provider, opts, version, versionInfo);
|
|
152
|
+
return withNotes(await client.updateProviderConfig(providerId, body));
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
rethrowOwnershipError(err, providerId);
|
|
156
|
+
}
|
|
108
157
|
});
|
|
109
158
|
}
|
package/lib/paths.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
2
|
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { reclaimHome } from "./consts.js";
|
|
4
4
|
/**
|
|
5
5
|
* Resolve the Reclaim cache directory (`~/.reclaim`). Honours the
|
|
6
6
|
* `RECLAIM_HOME` env var as an override so tests can sandbox writes.
|
|
7
7
|
*/
|
|
8
8
|
export function reclaimHomeDirPath() {
|
|
9
|
-
return
|
|
9
|
+
return reclaimHome();
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Walk up from `start` until we find a directory containing one of
|
package/lib/proof/attestor.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// reveals), never on responseMatches.
|
|
8
8
|
import { bytesToHex } from '@noble/hashes/utils.js';
|
|
9
9
|
import { createClaimOnAttestor, } from '@reclaimprotocol/attestor-core';
|
|
10
|
+
import { agentTraceEnabled } from "../consts.js";
|
|
10
11
|
import { resolveEthKey } from "../mcp/tools/authenticate/eth-key.js";
|
|
11
12
|
import { buildHttpParams, ensureAttestorCrypto, parseClaim, resolveAttestorUrl, } from "./proof-core.js";
|
|
12
13
|
import { ensureZkFiles } from "./zk-files.js";
|
|
@@ -136,7 +137,7 @@ export async function runAttestorProof(provider, secrets, opts = {}) {
|
|
|
136
137
|
// trace/debug entries during ZK setup). Flip RECLAIM_AGENT_TRACE=1 to
|
|
137
138
|
// turn it back on when something's broken; logs flow into the proof
|
|
138
139
|
// response and into the on-disk proof-runs dump.
|
|
139
|
-
const traceEnabled =
|
|
140
|
+
const traceEnabled = agentTraceEnabled();
|
|
140
141
|
const capture = traceEnabled ? makeCaptureLogger() : undefined;
|
|
141
142
|
const attestorLogs = capture?.entries;
|
|
142
143
|
let claim;
|
package/lib/proof/proof-core.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setCryptoImplementation } from '@reclaimprotocol/tls';
|
|
2
2
|
import { webcryptoCrypto } from '@reclaimprotocol/tls/webcrypto';
|
|
3
|
-
|
|
3
|
+
import { attestorUrlOverride, FALLBACK_ATTESTOR_URL } from "../consts.js";
|
|
4
|
+
import { normalizeGeoLocation } from "../provider/schema.js";
|
|
4
5
|
let cryptoInitialized = false;
|
|
5
6
|
/** One-time crypto backend init for `@reclaimprotocol/tls` (idempotent). The
|
|
6
7
|
* package ships with an empty `crypto = {}` and defers the backend to the
|
|
@@ -18,11 +19,14 @@ export function ensureAttestorCrypto() {
|
|
|
18
19
|
* default. Resolved per-call so an env change or per-request override takes
|
|
19
20
|
* effect without restarting. */
|
|
20
21
|
export function resolveAttestorUrl(override) {
|
|
21
|
-
return (override ??
|
|
22
|
+
return (override ?? attestorUrlOverride() ?? FALLBACK_ATTESTOR_URL);
|
|
22
23
|
}
|
|
23
24
|
/** Map a verification's provider recipe straight to the attestor's HTTP
|
|
24
25
|
* params — never synthesized from captured traffic. */
|
|
25
26
|
export function buildHttpParams(provider) {
|
|
27
|
+
// A blank egress is treated as unset: omit it so the local proof uses the
|
|
28
|
+
// tester's own egress rather than shipping a blank or an unresolved template.
|
|
29
|
+
const geoLocation = normalizeGeoLocation(provider.geoLocation);
|
|
26
30
|
return {
|
|
27
31
|
url: provider.url,
|
|
28
32
|
method: provider.method,
|
|
@@ -33,6 +37,13 @@ export function buildHttpParams(provider) {
|
|
|
33
37
|
...(provider.paramValues !== undefined && {
|
|
34
38
|
paramValues: provider.paramValues,
|
|
35
39
|
}),
|
|
40
|
+
...(provider.writeRedactionMode !== undefined && {
|
|
41
|
+
writeRedactionMode: provider.writeRedactionMode,
|
|
42
|
+
}),
|
|
43
|
+
...(provider.additionalClientOptions !== undefined && {
|
|
44
|
+
additionalClientOptions: provider.additionalClientOptions,
|
|
45
|
+
}),
|
|
46
|
+
...(geoLocation !== undefined && { geoLocation }),
|
|
36
47
|
};
|
|
37
48
|
}
|
|
38
49
|
/** Pull claimData + decoded `context.extractedParameters` (plus identifier /
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const INJECTION_GUIDE: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guidance for authoring page-injection scripts (`webSettings.jsUserScripts` on
|
|
3
|
+
* the builder, `customInjection` on old-devtools), surfaced to the authoring
|
|
4
|
+
* model from the publish tool description. The prose lives in
|
|
5
|
+
* `skill/injection-api.md` so it can be edited as markdown without touching
|
|
6
|
+
* code — the same pattern as `mcp/instructions.ts`. The path resolves the same
|
|
7
|
+
* from `src/provider` (dev) and `lib/provider` (published): both are two levels
|
|
8
|
+
* below the package root.
|
|
9
|
+
*
|
|
10
|
+
* The guide leads with plain browser JavaScript (navigation/interaction via
|
|
11
|
+
* standard APIs; the client already intercepts page requests) and treats
|
|
12
|
+
* `window.Reclaim` as a rarely-needed edge-case bridge, pointing at the
|
|
13
|
+
* authoritative `src/support/env.d.ts` rather than reproducing its surface.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
export const INJECTION_GUIDE = readFileSync(fileURLToPath(new URL('../../skill/injection-api.md', import.meta.url)), 'utf8').trim();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-blocking advisory for a request whose `responseMatches` count is less
|
|
3
|
+
* than its `responseRedactions` count.
|
|
4
|
+
*
|
|
5
|
+
* Some verification clients (notably the InApp SDK) pair the two arrays by
|
|
6
|
+
* index and may not behave correctly when there are fewer matches than
|
|
7
|
+
* redactions. This is NOT enforced — the author keeps full control over what
|
|
8
|
+
* they publish in either old-devtools or builder mode. The tools surface these
|
|
9
|
+
* strings so the dev can make an informed decision (e.g. add a functional match
|
|
10
|
+
* per redaction) rather than being blocked.
|
|
11
|
+
*/
|
|
12
|
+
/** One request's match/redaction counts, with a human label for the message. */
|
|
13
|
+
export interface RequestCounts {
|
|
14
|
+
label: string;
|
|
15
|
+
matchCount: number;
|
|
16
|
+
redactionCount: number;
|
|
17
|
+
}
|
|
18
|
+
/** Build advisory warnings for any request with matchCount < redactionCount.
|
|
19
|
+
* Returns an empty array when everything is fine. */
|
|
20
|
+
export declare function matchRedactionWarnings(requests: RequestCounts[]): string[];
|
|
21
|
+
/** Counts for a single drafted request shape (provider or injected request). */
|
|
22
|
+
export declare function countsFor(label: string, req: {
|
|
23
|
+
responseMatches?: unknown[];
|
|
24
|
+
responseRedactions?: unknown[];
|
|
25
|
+
}): RequestCounts;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-blocking advisory for a request whose `responseMatches` count is less
|
|
3
|
+
* than its `responseRedactions` count.
|
|
4
|
+
*
|
|
5
|
+
* Some verification clients (notably the InApp SDK) pair the two arrays by
|
|
6
|
+
* index and may not behave correctly when there are fewer matches than
|
|
7
|
+
* redactions. This is NOT enforced — the author keeps full control over what
|
|
8
|
+
* they publish in either old-devtools or builder mode. The tools surface these
|
|
9
|
+
* strings so the dev can make an informed decision (e.g. add a functional match
|
|
10
|
+
* per redaction) rather than being blocked.
|
|
11
|
+
*/
|
|
12
|
+
/** Build advisory warnings for any request with matchCount < redactionCount.
|
|
13
|
+
* Returns an empty array when everything is fine. */
|
|
14
|
+
export function matchRedactionWarnings(requests) {
|
|
15
|
+
const warnings = [];
|
|
16
|
+
for (const req of requests) {
|
|
17
|
+
if (req.matchCount < req.redactionCount) {
|
|
18
|
+
warnings.push(`${req.label}: ${req.matchCount} response match(es) but ` +
|
|
19
|
+
`${req.redactionCount} response redaction(s). Some verification ` +
|
|
20
|
+
'clients (e.g. the InApp SDK) may not work correctly when ' +
|
|
21
|
+
'responseMatches is shorter than responseRedactions — they pair the ' +
|
|
22
|
+
'two by index. This is allowed; add a functional match per redaction ' +
|
|
23
|
+
'if you hit verification issues.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return warnings;
|
|
27
|
+
}
|
|
28
|
+
/** Counts for a single drafted request shape (provider or injected request). */
|
|
29
|
+
export function countsFor(label, req) {
|
|
30
|
+
return {
|
|
31
|
+
label,
|
|
32
|
+
matchCount: req.responseMatches?.length ?? 0,
|
|
33
|
+
redactionCount: req.responseRedactions?.length ?? 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
package/lib/provider/schema.d.ts
CHANGED
|
@@ -61,7 +61,23 @@ export interface ReclaimProvider {
|
|
|
61
61
|
responseRedactions?: ResponseRedaction[];
|
|
62
62
|
/** Public param refs (templated into URL/body), populated by draft layer. */
|
|
63
63
|
paramValues?: Record<string, string>;
|
|
64
|
+
/** Redaction mode for the transcript (attestor default: 'key-update'). */
|
|
65
|
+
writeRedactionMode?: HttpParams['writeRedactionMode'];
|
|
66
|
+
/** TLS client options applied to the attestor tunnel. */
|
|
67
|
+
additionalClientOptions?: HttpParams['additionalClientOptions'];
|
|
68
|
+
/** Proxy egress: 2-letter ISO country or `{{param}}`. Blank/omitted ⇒
|
|
69
|
+
* `{{DYNAMIC_GEO}}` on publish (resolved to the verifying user's country).
|
|
70
|
+
*/
|
|
71
|
+
geoLocation?: HttpParams['geoLocation'];
|
|
64
72
|
}
|
|
73
|
+
/** Egress placeholder resolved to the verifying user's country at
|
|
74
|
+
* verification time — the default when a provider declares no explicit egress.
|
|
75
|
+
*/
|
|
76
|
+
export declare const DYNAMIC_GEO = "{{DYNAMIC_GEO}}";
|
|
77
|
+
/** `geoLocation` must never be blank. Trims the input and treats an empty
|
|
78
|
+
* string as unset so callers apply their own default (publish → `DYNAMIC_GEO`;
|
|
79
|
+
* a local proof omits it and uses the tester's egress). */
|
|
80
|
+
export declare function normalizeGeoLocation(value: string | undefined): string | undefined;
|
|
65
81
|
/** A reference to a secret param. Raw value lives only in server memory. */
|
|
66
82
|
export interface SecretParamRef {
|
|
67
83
|
name: string;
|
package/lib/provider/schema.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/** Egress placeholder resolved to the verifying user's country at
|
|
2
|
+
* verification time — the default when a provider declares no explicit egress.
|
|
3
|
+
*/
|
|
4
|
+
export const DYNAMIC_GEO = '{{DYNAMIC_GEO}}';
|
|
5
|
+
/** `geoLocation` must never be blank. Trims the input and treats an empty
|
|
6
|
+
* string as unset so callers apply their own default (publish → `DYNAMIC_GEO`;
|
|
7
|
+
* a local proof omits it and uses the tester's egress). */
|
|
8
|
+
export function normalizeGeoLocation(value) {
|
|
9
|
+
const trimmed = value?.trim();
|
|
10
|
+
return trimmed ? trimmed : undefined;
|
|
11
|
+
}
|
|
@@ -1,15 +1,66 @@
|
|
|
1
1
|
import type { ReclaimClient } from '@reclaimprotocol/client';
|
|
2
2
|
import type { CreateProviderVersionRequest, ProviderVersionRef } from '@reclaimprotocol/client/openapi';
|
|
3
|
-
import type { ReclaimProvider } from './schema.ts';
|
|
3
|
+
import type { HttpMethod, ReclaimProvider, ResponseMatch, ResponseRedaction } from './schema.ts';
|
|
4
|
+
/** One entry of the version's `requests[]` (a `RequestSelection`), derived
|
|
5
|
+
* from the openapi type so it can't drift from what the server accepts. */
|
|
6
|
+
type RequestSelection = CreateProviderVersionRequest['requests'][number];
|
|
7
|
+
/** The subset of a draft a request selection is built from — the only fields
|
|
8
|
+
* `providerToRequestSelection` reads. A full `ReclaimProvider` satisfies it,
|
|
9
|
+
* as does a lighter injected-request draft (no `name`/`paramValues`). */
|
|
10
|
+
export interface DraftRequest {
|
|
11
|
+
url: string;
|
|
12
|
+
method: HttpMethod;
|
|
13
|
+
body?: string;
|
|
14
|
+
writeRedactionMode?: ReclaimProvider['writeRedactionMode'];
|
|
15
|
+
additionalClientOptions?: ReclaimProvider['additionalClientOptions'];
|
|
16
|
+
responseMatches?: ResponseMatch[];
|
|
17
|
+
responseRedactions?: ResponseRedaction[];
|
|
18
|
+
}
|
|
19
|
+
/** A request the page's injection script is allowed to fire, plus the
|
|
20
|
+
* pagination/optionality flags of `RequestSelectionTemplate`. Reuses the
|
|
21
|
+
* shared `DraftRequest` shape — no provider `name`/`paramValues` required. */
|
|
22
|
+
export interface AllowedJsRequest extends DraftRequest {
|
|
23
|
+
/** Allow the template to match many requests (e.g. pagination). Default
|
|
24
|
+
* true. */
|
|
25
|
+
multiple?: boolean;
|
|
26
|
+
/** Fail validation if no request matches this template. Default true. */
|
|
27
|
+
required?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Optional extras for a create-version body beyond the request list. */
|
|
30
|
+
export interface CreateVersionOptions {
|
|
31
|
+
notes?: string;
|
|
32
|
+
version?: ProviderVersionRef;
|
|
33
|
+
/** JS injected before every page load (`webSettings.jsUserScripts`). */
|
|
34
|
+
jsUserScripts?: string;
|
|
35
|
+
/** Requests the injection script may fire, as `RequestSelectionTemplate`s. */
|
|
36
|
+
allowedJsRequests?: AllowedJsRequest[];
|
|
37
|
+
}
|
|
4
38
|
/**
|
|
5
39
|
* Derive the version's `requiredContext` JSON Schema from the
|
|
6
|
-
* `{{context.<name>}}` placeholders
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
40
|
+
* `{{context.<name>}}` placeholders across EVERY request's url/body (plus any
|
|
41
|
+
* injected requests and the injection script) — mechanical, so a published
|
|
42
|
+
* recipe can never reference a context value the Builder doesn't require.
|
|
43
|
+
* Returns undefined when nothing references context (the field is optional).
|
|
44
|
+
* Authors can refine types/descriptions in the version editor.
|
|
10
45
|
*/
|
|
11
|
-
export declare function deriveRequiredContext(
|
|
12
|
-
|
|
46
|
+
export declare function deriveRequiredContext(providers: ReclaimProvider[], injection?: {
|
|
47
|
+
allowedJsRequests?: AllowedJsRequest[];
|
|
48
|
+
jsUserScripts?: string;
|
|
49
|
+
}): CreateProviderVersionRequest['requiredContext'];
|
|
50
|
+
/**
|
|
51
|
+
* Translate one drafted request into a `RequestSelection`. Shared by the
|
|
52
|
+
* top-level `requests` and by `allowedJsRequests`.
|
|
53
|
+
*
|
|
54
|
+
* `responseMatches`/`responseRedactions` are INDEPENDENT parallel arrays,
|
|
55
|
+
* isomorphic to the attestor's `ProviderParams<'http'>` (no nested fold).
|
|
56
|
+
* `responseRedactions` decide which portions of the response are revealed;
|
|
57
|
+
* `responseMatches` then run against the union of the revealed content. Neither
|
|
58
|
+
* depends on the other's length or order, so both pass through untouched.
|
|
59
|
+
* (The old-devtools translator has its own opt-in index-pairing concern; the
|
|
60
|
+
* builder deliberately does not.)
|
|
61
|
+
*/
|
|
62
|
+
export declare function providerToRequestSelection(provider: DraftRequest): RequestSelection;
|
|
63
|
+
export declare function providerToCreateVersionRequest(providers: ReclaimProvider[], initialUrl: string, opts?: CreateVersionOptions): CreateProviderVersionRequest;
|
|
13
64
|
/**
|
|
14
65
|
* Fetch the current versions for a provider and return the next version above
|
|
15
66
|
* the highest existing one (bumping the patch number), or 1.0.0 when the
|
|
@@ -17,3 +68,4 @@ export declare function providerToCreateVersionRequest(provider: ReclaimProvider
|
|
|
17
68
|
* resetting to 1.0.0 would re-publish a v3 provider as v1.0.0.
|
|
18
69
|
*/
|
|
19
70
|
export declare function nextVersion(client: ReclaimClient, providerId: string): Promise<ProviderVersionRef>;
|
|
71
|
+
export {};
|