@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
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createReclaim,
|
|
3
3
|
decryptCallback,
|
|
4
4
|
type DecryptionKey,
|
|
5
|
-
DEFAULT_BASE_URL,
|
|
6
5
|
verifyResultFull,
|
|
7
6
|
} from '@reclaimprotocol/client'
|
|
8
7
|
import assert from 'node:assert'
|
|
8
|
+
import { apiUrl, orgSecret } from '../../../consts.ts'
|
|
9
9
|
import { defineTool, type RegisteredTool } from '../../server.ts'
|
|
10
10
|
import { resolveDecryptionKey } from '../authenticate/decrypt-key.ts'
|
|
11
11
|
|
|
@@ -19,7 +19,7 @@ const TERMINAL = new Set(['success', 'rejected', 'error'])
|
|
|
19
19
|
* `RECLAIM_ORG_SECRET`.
|
|
20
20
|
*/
|
|
21
21
|
function resolveOrgSecret(): string {
|
|
22
|
-
const secret =
|
|
22
|
+
const secret = orgSecret()?.trim()
|
|
23
23
|
assert(
|
|
24
24
|
secret,
|
|
25
25
|
new Error(
|
|
@@ -35,11 +35,10 @@ function resolveOrgSecret(): string {
|
|
|
35
35
|
* `get_verification_result` — check a session's status and, once a result has
|
|
36
36
|
* been submitted, pull the stored payload(s) and verify locally. Auth is the
|
|
37
37
|
* org token; delivery is org-scoped. Each stored payload is either the
|
|
38
|
-
* plaintext signed JWS (when the org
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* here.
|
|
38
|
+
* plaintext signed JWS (when the org's encryption is off) or an ECIES
|
|
39
|
+
* ciphertext that we decrypt here with the optional eth key
|
|
40
|
+
* (`RECLAIM_DECRYPT_KEY` or the `reclaim-decrypt.key` hex file). The Builder
|
|
41
|
+
* only ever relays the payload — decryption, when needed, happens here.
|
|
43
42
|
*/
|
|
44
43
|
export function verificationResultTool(): RegisteredTool {
|
|
45
44
|
return defineTool<{ sessionId: string }>(
|
|
@@ -50,9 +49,9 @@ export function verificationResultTool(): RegisteredTool {
|
|
|
50
49
|
'Authenticates with the org secret (RECLAIM_ORG_SECRET). Fetches the ' +
|
|
51
50
|
'session status; if it is terminal and a result has been submitted, ' +
|
|
52
51
|
'pulls the stored result(s) and verifies them locally. Encrypted ' +
|
|
53
|
-
'deliveries (
|
|
54
|
-
'
|
|
55
|
-
'
|
|
52
|
+
'deliveries (ECIES over secp256k1) are decrypted with your optional ' +
|
|
53
|
+
'eth key (RECLAIM_DECRYPT_KEY or reclaim-decrypt.key); plaintext ' +
|
|
54
|
+
'deliveries are read directly. Returns ' +
|
|
56
55
|
'`ready: false` while the session is still pending or no result has ' +
|
|
57
56
|
'been delivered yet. Use list_verification_events for the full ' +
|
|
58
57
|
'lifecycle log.',
|
|
@@ -69,14 +68,14 @@ export function verificationResultTool(): RegisteredTool {
|
|
|
69
68
|
},
|
|
70
69
|
},
|
|
71
70
|
async(args) => {
|
|
72
|
-
const
|
|
73
|
-
// Optional
|
|
71
|
+
const secret = resolveOrgSecret()
|
|
72
|
+
// Optional eth decryption key — absent ⇒ plaintext-only.
|
|
74
73
|
const decryptionKey: DecryptionKey | undefined =
|
|
75
74
|
await resolveDecryptionKey()
|
|
76
75
|
|
|
77
76
|
const reclaim = createReclaim({
|
|
78
|
-
baseUrl:
|
|
79
|
-
orgSecret,
|
|
77
|
+
baseUrl: apiUrl(),
|
|
78
|
+
orgSecret: secret,
|
|
80
79
|
})
|
|
81
80
|
|
|
82
81
|
const sessionRes = await reclaim.api('GetVerificationSession', {
|
|
@@ -137,9 +136,9 @@ export function verificationResultTool(): RegisteredTool {
|
|
|
137
136
|
ready: false,
|
|
138
137
|
note:
|
|
139
138
|
'A result was stored, but no payload could be read — it is ' +
|
|
140
|
-
'corrupt, or encrypted (
|
|
141
|
-
'hold.
|
|
142
|
-
'
|
|
139
|
+
'corrupt, or encrypted (ECIES) to a key this consumer does not ' +
|
|
140
|
+
'hold. Set RECLAIM_DECRYPT_KEY (or reclaim-decrypt.key) to the ' +
|
|
141
|
+
'eth private key matching the org keypair.',
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
|
package/src/old/flag.ts
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.ts'
|
package/src/old/identity.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deriveFromPrivateKey } from '@reclaimprotocol/client'
|
|
2
2
|
import { ConfigStore } from '../config/store.ts'
|
|
3
|
+
import { oldApiToken, oldEthUid, privateKey } from '../consts.ts'
|
|
3
4
|
import type { OldIdentity } from './client.ts'
|
|
4
5
|
|
|
5
6
|
/** Normalize an eth uid input to `eth:<lowercase-address>`. Accepts a bare
|
|
@@ -17,27 +18,27 @@ export function toEthUid(addressOrUid: string): OldIdentity {
|
|
|
17
18
|
* 3. `RECLAIM_PRIVATE_KEY` — derive the eth uid from the local app key.
|
|
18
19
|
* Returns undefined when none is set.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
const token =
|
|
21
|
+
function resolveIdentityFromEnv(): OldIdentity | undefined {
|
|
22
|
+
const token = oldApiToken()?.trim()
|
|
22
23
|
if(token) {
|
|
23
24
|
return { kind: 'bearer', token }
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const ethUid =
|
|
27
|
+
const ethUid = oldEthUid()?.trim()
|
|
27
28
|
if(ethUid) {
|
|
28
29
|
return toEthUid(ethUid)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const
|
|
32
|
-
if(
|
|
33
|
-
return toEthUid(deriveFromPrivateKey(
|
|
32
|
+
const key = privateKey()?.trim()
|
|
33
|
+
if(key) {
|
|
34
|
+
return toEthUid(deriveFromPrivateKey(key).address)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
return undefined
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/** Read the identity persisted by a prior `reclaim_authenticate` call. */
|
|
40
|
-
|
|
41
|
+
function loadPersistedIdentity(): OldIdentity | undefined {
|
|
41
42
|
return new ConfigStore().read()?.old_devtools
|
|
42
43
|
}
|
|
43
44
|
|
package/src/old/login-cdp.ts
CHANGED
|
@@ -5,10 +5,7 @@ import {
|
|
|
5
5
|
waitForCdpReady,
|
|
6
6
|
} from '../cdp/launcher.ts'
|
|
7
7
|
import { ConfigStore } from '../config/store.ts'
|
|
8
|
-
|
|
9
|
-
/** The devtools dashboard login page. Override per-call or via
|
|
10
|
-
* `RECLAIM_OLD_LOGIN_URL`. */
|
|
11
|
-
export const DEFAULT_LOGIN_URL = 'https://dev.reclaimprotocol.org'
|
|
8
|
+
import { DEFAULT_LOGIN_URL, oldLoginUrl } from '../consts.ts'
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Read the Firebase ID token the dashboard persisted after login.
|
|
@@ -84,7 +81,7 @@ export async function captureFirebaseTokenViaCdp(opts: {
|
|
|
84
81
|
pollMs?: number
|
|
85
82
|
}): Promise<CdpLoginResult> {
|
|
86
83
|
const loginUrl =
|
|
87
|
-
opts.loginUrl ||
|
|
84
|
+
opts.loginUrl || oldLoginUrl() || DEFAULT_LOGIN_URL
|
|
88
85
|
const timeoutMs = opts.timeoutMs ?? 180_000
|
|
89
86
|
const pollMs = opts.pollMs ?? 1000
|
|
90
87
|
|
package/src/old/to-register.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReclaimProvider
|
|
1
|
+
import type { ReclaimProvider } from '../provider/schema.ts'
|
|
2
2
|
import type {
|
|
3
3
|
RegisterProviderBody,
|
|
4
4
|
UpdateProviderConfigBody,
|
|
@@ -97,15 +97,12 @@ function requestDataFromProvider(provider: ReclaimProvider): OldRequestData {
|
|
|
97
97
|
)
|
|
98
98
|
|
|
99
99
|
// Old devtools wants `responseMatches` and `responseRedactions` as PARALLEL
|
|
100
|
-
// arrays
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const sourceRedactions = provider.responseRedactions?.length
|
|
107
|
-
? provider.responseRedactions
|
|
108
|
-
: nestedRedactions
|
|
100
|
+
// arrays — same shape the builder uses, so pass them through directly. We do
|
|
101
|
+
// NOT enforce any match/redaction count relationship here (and never pad —
|
|
102
|
+
// empty placeholder matches break proof generation): the author keeps full
|
|
103
|
+
// control. The publish tool surfaces a non-blocking warning when matches <
|
|
104
|
+
// redactions (see `matchRedactionWarnings`), and the dev decides.
|
|
105
|
+
const sourceRedactions = provider.responseRedactions ?? []
|
|
109
106
|
|
|
110
107
|
const responseRedactions: OldResponseRedaction[] = sourceRedactions.map(
|
|
111
108
|
(r, i) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { agentDisabled } from '../../consts.ts'
|
|
1
2
|
import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
|
|
2
3
|
import type { OldIdentity, ReclaimOldClient } from '../client.ts'
|
|
3
4
|
import { persistIdentity, toEthUid } from '../identity.ts'
|
|
@@ -128,7 +129,7 @@ export function authenticateTool(client: ReclaimOldClient): RegisteredTool {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
// CDP browser login (the default headline flow).
|
|
131
|
-
if(
|
|
132
|
+
if(agentDisabled()) {
|
|
132
133
|
throw new Error(
|
|
133
134
|
'Browser login is unavailable (RECLAIM_AGENT_DISABLED=1). Pass a ' +
|
|
134
135
|
'`token` (Firebase ID token) or `ethAddress` instead.',
|
package/src/old/tools/publish.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { Boom, isBoom } from '@hapi/boom'
|
|
1
2
|
import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
|
|
3
|
+
import {
|
|
4
|
+
countsFor,
|
|
5
|
+
matchRedactionWarnings,
|
|
6
|
+
} from '../../provider/match-redaction-warning.ts'
|
|
2
7
|
import type { ReclaimProvider } from '../../provider/schema.ts'
|
|
3
8
|
import type { ReclaimOldClient } from '../client.ts'
|
|
4
9
|
import {
|
|
@@ -11,6 +16,35 @@ import {
|
|
|
11
16
|
|
|
12
17
|
const DEFAULT_VERSION_INFO = 'Updated from MCP browser capture'
|
|
13
18
|
|
|
19
|
+
/**
|
|
20
|
+
* The old backend lets you add a version only to a provider YOU own. A
|
|
21
|
+
* `providerId` for a public provider (or anyone else's) comes back as
|
|
22
|
+
* 401/403/404 — the dev's likely intent is to publish their OWN version of that
|
|
23
|
+
* site, which on this backend means registering a separate copy. Rethrow those
|
|
24
|
+
* failures with that actionable suggestion; leave other errors (e.g. a 400
|
|
25
|
+
* version collision) untouched so their real detail surfaces.
|
|
26
|
+
*/
|
|
27
|
+
function rethrowOwnershipError(err: unknown, providerId: string): never {
|
|
28
|
+
const status = isBoom(err) ? err.output.statusCode : undefined
|
|
29
|
+
if(status !== 401 && status !== 403 && status !== 404) {
|
|
30
|
+
throw err
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const base = isBoom(err) ? err.message : String(err)
|
|
34
|
+
throw new Boom(
|
|
35
|
+
`${base} — could not add a version to provider ${providerId}. You can ` +
|
|
36
|
+
'only publish new versions on providers you own. If this is a public ' +
|
|
37
|
+
"provider (or one you don't own), re-run " +
|
|
38
|
+
'create_provider_version_from_capture WITHOUT `providerId` to register ' +
|
|
39
|
+
"your own copy. If it IS yours, confirm you're authenticated " +
|
|
40
|
+
'(reclaim_authenticate) as the account that created it.',
|
|
41
|
+
{
|
|
42
|
+
statusCode: status,
|
|
43
|
+
data: isBoom(err) ? err.data : { status, detail: base },
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
14
48
|
/**
|
|
15
49
|
* Publish a drafted provider to the OLD devtools backend. Keeps the builder
|
|
16
50
|
* tool NAME (`create_provider_version_from_capture`) so the skill flow is
|
|
@@ -48,6 +82,10 @@ export function createVersionFromCaptureTool(
|
|
|
48
82
|
'1.0.0; re-running creates a duplicate). Pass `providerId` (from ' +
|
|
49
83
|
'get_me_providers) to add a NEW VERSION to that existing provider ' +
|
|
50
84
|
'(the patch is auto-bumped). \n\n' +
|
|
85
|
+
'You can only add versions to a provider YOU own — the `providerId` ' +
|
|
86
|
+
'must come from get_me_providers. To publish your own version of a ' +
|
|
87
|
+
"PUBLIC provider you don't own, omit `providerId` to register your " +
|
|
88
|
+
'own copy (you cannot edit someone else\'s provider here). \n\n' +
|
|
51
89
|
'Captured requests must be GET/POST. OPRF redactions are supported.',
|
|
52
90
|
inputSchema: {
|
|
53
91
|
type: 'object',
|
|
@@ -125,27 +163,49 @@ export function createVersionFromCaptureTool(
|
|
|
125
163
|
opts.providerType = args.providerType
|
|
126
164
|
}
|
|
127
165
|
|
|
166
|
+
// Non-blocking advisory — never alters or blocks the publish; the
|
|
167
|
+
// author keeps full control. Attaches under `_notes` when relevant.
|
|
168
|
+
const notes = matchRedactionWarnings([
|
|
169
|
+
countsFor('Request', args.provider),
|
|
170
|
+
])
|
|
171
|
+
const withNotes = (result: unknown) => {
|
|
172
|
+
if(notes.length && result && typeof result === 'object') {
|
|
173
|
+
return { ...result, _notes: notes }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return result
|
|
177
|
+
}
|
|
178
|
+
|
|
128
179
|
// New provider.
|
|
129
180
|
if(!args.providerId) {
|
|
130
181
|
const body = providerToRegisterBody(args.provider, opts)
|
|
131
|
-
return client.registerProvider(body)
|
|
182
|
+
return withNotes(await client.registerProvider(body))
|
|
132
183
|
}
|
|
133
184
|
|
|
134
185
|
// New version of an existing provider — pick the next patch above
|
|
135
|
-
// the highest existing version.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
186
|
+
// the highest existing version. A provider you don't own (e.g. a
|
|
187
|
+
// public one) fails here with 401/403/404; surface the register-a-copy
|
|
188
|
+
// workaround instead of a bare permission error.
|
|
189
|
+
const providerId = args.providerId
|
|
190
|
+
try {
|
|
191
|
+
const versionsResp = await client.listVersions(providerId)
|
|
192
|
+
const version = bumpPatchString(extractVersions(versionsResp))
|
|
193
|
+
const versionInfo =
|
|
194
|
+
args.notes && args.notes.trim().length >= 10
|
|
195
|
+
? args.notes.trim()
|
|
196
|
+
: DEFAULT_VERSION_INFO
|
|
197
|
+
const body = providerToConfigBody(
|
|
198
|
+
args.provider,
|
|
199
|
+
opts,
|
|
200
|
+
version,
|
|
201
|
+
versionInfo,
|
|
202
|
+
)
|
|
203
|
+
return withNotes(
|
|
204
|
+
await client.updateProviderConfig(providerId, body),
|
|
205
|
+
)
|
|
206
|
+
} catch(err) {
|
|
207
|
+
rethrowOwnershipError(err, providerId)
|
|
208
|
+
}
|
|
149
209
|
},
|
|
150
210
|
)
|
|
151
211
|
}
|
package/src/paths.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolve the Reclaim cache directory (`~/.reclaim`). Honours the
|
|
7
7
|
* `RECLAIM_HOME` env var as an override so tests can sandbox writes.
|
|
8
8
|
*/
|
|
9
9
|
export function reclaimHomeDirPath() {
|
|
10
|
-
return
|
|
10
|
+
return reclaimHome()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
package/src/proof/attestor.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { bytesToHex } from '@noble/hashes/utils.js'
|
|
|
10
10
|
import {
|
|
11
11
|
createClaimOnAttestor, type Logger,
|
|
12
12
|
} from '@reclaimprotocol/attestor-core'
|
|
13
|
+
import { agentTraceEnabled } from '../consts.ts'
|
|
13
14
|
import { resolveEthKey } from '../mcp/tools/authenticate/eth-key.ts'
|
|
14
15
|
import type { ReclaimProvider } from '../provider/schema.ts'
|
|
15
16
|
import {
|
|
@@ -244,7 +245,7 @@ export async function runAttestorProof(
|
|
|
244
245
|
// trace/debug entries during ZK setup). Flip RECLAIM_AGENT_TRACE=1 to
|
|
245
246
|
// turn it back on when something's broken; logs flow into the proof
|
|
246
247
|
// response and into the on-disk proof-runs dump.
|
|
247
|
-
const traceEnabled =
|
|
248
|
+
const traceEnabled = agentTraceEnabled()
|
|
248
249
|
const capture = traceEnabled ? makeCaptureLogger() : undefined
|
|
249
250
|
const attestorLogs = capture?.entries
|
|
250
251
|
|
package/src/proof/proof-core.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
import type { ProviderParams } from '@reclaimprotocol/attestor-core'
|
|
10
10
|
import { setCryptoImplementation } from '@reclaimprotocol/tls'
|
|
11
11
|
import { webcryptoCrypto } from '@reclaimprotocol/tls/webcrypto'
|
|
12
|
+
import { attestorUrlOverride, FALLBACK_ATTESTOR_URL } from '../consts.ts'
|
|
12
13
|
import type { ReclaimProvider } from '../provider/schema.ts'
|
|
13
|
-
|
|
14
|
-
const FALLBACK_ATTESTOR_URL = 'wss://attestor.reclaimprotocol.org:444/ws'
|
|
14
|
+
import { normalizeGeoLocation } from '../provider/schema.ts'
|
|
15
15
|
|
|
16
16
|
let cryptoInitialized = false
|
|
17
17
|
|
|
@@ -34,7 +34,7 @@ export function ensureAttestorCrypto(): void {
|
|
|
34
34
|
* effect without restarting. */
|
|
35
35
|
export function resolveAttestorUrl(override?: string): string {
|
|
36
36
|
return (
|
|
37
|
-
override ??
|
|
37
|
+
override ?? attestorUrlOverride() ?? FALLBACK_ATTESTOR_URL
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -43,6 +43,9 @@ export function resolveAttestorUrl(override?: string): string {
|
|
|
43
43
|
export function buildHttpParams(
|
|
44
44
|
provider: ReclaimProvider,
|
|
45
45
|
): ProviderParams<'http'> {
|
|
46
|
+
// A blank egress is treated as unset: omit it so the local proof uses the
|
|
47
|
+
// tester's own egress rather than shipping a blank or an unresolved template.
|
|
48
|
+
const geoLocation = normalizeGeoLocation(provider.geoLocation)
|
|
46
49
|
return {
|
|
47
50
|
url: provider.url,
|
|
48
51
|
method: provider.method,
|
|
@@ -53,6 +56,13 @@ export function buildHttpParams(
|
|
|
53
56
|
...(provider.paramValues !== undefined && {
|
|
54
57
|
paramValues: provider.paramValues,
|
|
55
58
|
}),
|
|
59
|
+
...(provider.writeRedactionMode !== undefined && {
|
|
60
|
+
writeRedactionMode: provider.writeRedactionMode,
|
|
61
|
+
}),
|
|
62
|
+
...(provider.additionalClientOptions !== undefined && {
|
|
63
|
+
additionalClientOptions: provider.additionalClientOptions,
|
|
64
|
+
}),
|
|
65
|
+
...(geoLocation !== undefined && { geoLocation }),
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
68
|
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
|
|
18
|
+
export const INJECTION_GUIDE = readFileSync(
|
|
19
|
+
fileURLToPath(new URL('../../skill/injection-api.md', import.meta.url)),
|
|
20
|
+
'utf8',
|
|
21
|
+
).trim()
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
13
|
+
/** One request's match/redaction counts, with a human label for the message. */
|
|
14
|
+
export interface RequestCounts {
|
|
15
|
+
label: string
|
|
16
|
+
matchCount: number
|
|
17
|
+
redactionCount: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Build advisory warnings for any request with matchCount < redactionCount.
|
|
21
|
+
* Returns an empty array when everything is fine. */
|
|
22
|
+
export function matchRedactionWarnings(requests: RequestCounts[]): string[] {
|
|
23
|
+
const warnings: string[] = []
|
|
24
|
+
for(const req of requests) {
|
|
25
|
+
if(req.matchCount < req.redactionCount) {
|
|
26
|
+
warnings.push(
|
|
27
|
+
`${req.label}: ${req.matchCount} response match(es) but ` +
|
|
28
|
+
`${req.redactionCount} response redaction(s). Some verification ` +
|
|
29
|
+
'clients (e.g. the InApp SDK) may not work correctly when ' +
|
|
30
|
+
'responseMatches is shorter than responseRedactions — they pair the ' +
|
|
31
|
+
'two by index. This is allowed; add a functional match per redaction ' +
|
|
32
|
+
'if you hit verification issues.',
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return warnings
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Counts for a single drafted request shape (provider or injected request). */
|
|
41
|
+
export function countsFor(
|
|
42
|
+
label: string,
|
|
43
|
+
req: {
|
|
44
|
+
responseMatches?: unknown[]
|
|
45
|
+
responseRedactions?: unknown[]
|
|
46
|
+
},
|
|
47
|
+
): RequestCounts {
|
|
48
|
+
return {
|
|
49
|
+
label,
|
|
50
|
+
matchCount: req.responseMatches?.length ?? 0,
|
|
51
|
+
redactionCount: req.responseRedactions?.length ?? 0,
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/provider/schema.ts
CHANGED
|
@@ -69,6 +69,29 @@ export interface ReclaimProvider {
|
|
|
69
69
|
responseRedactions?: ResponseRedaction[]
|
|
70
70
|
/** Public param refs (templated into URL/body), populated by draft layer. */
|
|
71
71
|
paramValues?: Record<string, string>
|
|
72
|
+
/** Redaction mode for the transcript (attestor default: 'key-update'). */
|
|
73
|
+
writeRedactionMode?: HttpParams['writeRedactionMode']
|
|
74
|
+
/** TLS client options applied to the attestor tunnel. */
|
|
75
|
+
additionalClientOptions?: HttpParams['additionalClientOptions']
|
|
76
|
+
/** Proxy egress: 2-letter ISO country or `{{param}}`. Blank/omitted ⇒
|
|
77
|
+
* `{{DYNAMIC_GEO}}` on publish (resolved to the verifying user's country).
|
|
78
|
+
*/
|
|
79
|
+
geoLocation?: HttpParams['geoLocation']
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Egress placeholder resolved to the verifying user's country at
|
|
83
|
+
* verification time — the default when a provider declares no explicit egress.
|
|
84
|
+
*/
|
|
85
|
+
export const DYNAMIC_GEO = '{{DYNAMIC_GEO}}'
|
|
86
|
+
|
|
87
|
+
/** `geoLocation` must never be blank. Trims the input and treats an empty
|
|
88
|
+
* string as unset so callers apply their own default (publish → `DYNAMIC_GEO`;
|
|
89
|
+
* a local proof omits it and uses the tester's egress). */
|
|
90
|
+
export function normalizeGeoLocation(
|
|
91
|
+
value: string | undefined,
|
|
92
|
+
): string | undefined {
|
|
93
|
+
const trimmed = value?.trim()
|
|
94
|
+
return trimmed ? trimmed : undefined
|
|
72
95
|
}
|
|
73
96
|
|
|
74
97
|
/** A reference to a secret param. Raw value lives only in server memory. */
|