@fidacy/mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +131 -0
- package/dist/assess.d.ts +78 -0
- package/dist/assess.js +139 -0
- package/dist/assess.js.map +1 -0
- package/dist/audit-store.d.ts +11 -0
- package/dist/audit-store.js +51 -0
- package/dist/audit-store.js.map +1 -0
- package/dist/core.d.ts +33 -0
- package/dist/core.js +143 -0
- package/dist/core.js.map +1 -0
- package/dist/executor.d.ts +30 -0
- package/dist/executor.js +56 -0
- package/dist/executor.js.map +1 -0
- package/dist/grant.d.ts +18 -0
- package/dist/grant.js +39 -0
- package/dist/grant.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +135 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +4 -0
- package/dist/lib.js +5 -0
- package/dist/lib.js.map +1 -0
- package/dist/signing.d.ts +10 -0
- package/dist/signing.js +32 -0
- package/dist/signing.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +9 -0
- package/dist/util.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 ZEEPCODE GROUP LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @fidacy/mcp
|
|
2
|
+
|
|
3
|
+
The action firewall for AI agents. A drop-in MCP server that gates payment
|
|
4
|
+
actions against a cryptographically signed mandate **before** money can move.
|
|
5
|
+
Non-custodial: Fidacy authorizes and proves, it never holds funds.
|
|
6
|
+
|
|
7
|
+
Install once, works in any MCP-compatible agent: Claude Code, Claude Desktop,
|
|
8
|
+
Hermes, OpenClaw, and anything else that speaks MCP.
|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
An agent can hallucinate or be prompt-injected into a payment: wrong payee,
|
|
13
|
+
wrong amount, fabricated invoice. Prompt-level guardrails are probabilistic and
|
|
14
|
+
bypassable. `@fidacy/mcp` is a deterministic gate between the agent's intent and
|
|
15
|
+
the executor: the action is dead on arrival unless it validates against a signed
|
|
16
|
+
mandate, and every decision lands in an immutable hash-chained audit trail.
|
|
17
|
+
|
|
18
|
+
## Enforcement model
|
|
19
|
+
|
|
20
|
+
1. Register `@fidacy/mcp` as the agent's **only** payment-capable tool. Do not
|
|
21
|
+
give the agent a raw payment tool. Tool inventory is the runtime firewall.
|
|
22
|
+
2. The agent calls `request_payment`. Fidacy checks it against the mandate
|
|
23
|
+
(payee allowlist, per-tx cap, total cap, currency, time window, revocation).
|
|
24
|
+
3. ALLOW returns a short-lived Ed25519 **grant**. DENY returns no grant and the
|
|
25
|
+
violated rule. The downstream executor MUST require the grant, so a denied
|
|
26
|
+
action cannot proceed.
|
|
27
|
+
4. Every decision is appended to a hash-chained log. `get_audit_proof` returns
|
|
28
|
+
the portable, verifiable proof.
|
|
29
|
+
|
|
30
|
+
## One install, two backends
|
|
31
|
+
|
|
32
|
+
`@fidacy/mcp` ships two complementary capabilities in a single install:
|
|
33
|
+
|
|
34
|
+
- **Verdict layer (advisory)**: `assess_action` calls the live Fidacy engine and
|
|
35
|
+
returns a **signed trust verdict**. It moves no money; it returns a judgment
|
|
36
|
+
whose proof (`riskPayloadJws` + `signingKeyId`) is verifiable by anyone via
|
|
37
|
+
`@fidacy/verify` against the engine JWKS at `/.well-known/jwks.json`.
|
|
38
|
+
- **Payment firewall (enforcement)**: `request_payment` / `verify_mandate` /
|
|
39
|
+
`get_audit_proof` gate and prove a payment against a signed mandate through the
|
|
40
|
+
core, returning short-lived Ed25519 grants.
|
|
41
|
+
|
|
42
|
+
Mental model: `assess_action` -> **engine** (signed verdict);
|
|
43
|
+
`request_payment` and friends -> **core** (payment firewall).
|
|
44
|
+
|
|
45
|
+
## Tools
|
|
46
|
+
|
|
47
|
+
| Tool | Backend | Purpose |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `assess_action` | engine | Signed Fidacy trust verdict for a proposed action. Advisory. |
|
|
50
|
+
| `request_payment` | core | Authorize a payment action. ALLOW + grant, or DENY + rule. |
|
|
51
|
+
| `verify_mandate` | core | Read the mandate envelope + Fidacy public key. |
|
|
52
|
+
| `get_audit_proof` | core | Hash-chained proof for a decision id. |
|
|
53
|
+
|
|
54
|
+
### `assess_action`
|
|
55
|
+
|
|
56
|
+
Returns a signed Fidacy trust verdict from the live engine for a proposed
|
|
57
|
+
action. The signed proof is `riskPayloadJws` + `signingKeyId`, verifiable by
|
|
58
|
+
anyone via `@fidacy/verify` against `{engineUrl}/.well-known/jwks.json`.
|
|
59
|
+
|
|
60
|
+
Inputs:
|
|
61
|
+
|
|
62
|
+
- `kind` (optional, default `ap2_payment`): one of `ap2_payment`,
|
|
63
|
+
`message_send`, `voice_call`, `custom`, `claim_document`.
|
|
64
|
+
- `mandate` (required): the action/mandate object for that `kind`.
|
|
65
|
+
- `mandateType`, `spendingMandate`, `idempotencyKey`, `a2a.task_id` (optional).
|
|
66
|
+
|
|
67
|
+
Environment:
|
|
68
|
+
|
|
69
|
+
| Var | Default | Purpose |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `FIDACY_ENGINE_URL` | `https://api.fidacy.com` | Base URL of the Fidacy engine. |
|
|
72
|
+
| `FIDACY_ENGINE_API_KEY` | (none) | An `fky_live_` / `fky_test_` key with scope `assess:write`. |
|
|
73
|
+
|
|
74
|
+
The server boots without `FIDACY_ENGINE_API_KEY`; the tool is always registered.
|
|
75
|
+
Only **calling** `assess_action` without the key returns a helpful error telling
|
|
76
|
+
you to set it. The key is never logged, echoed, or attached to any error.
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install -g @fidacy/mcp # or run via npx, no install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Claude Code
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
claude mcp add fidacy -- npx -y @fidacy/mcp
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Claude Desktop (`claude_desktop_config.json`)
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"fidacy": { "command": "npx", "args": ["-y", "@fidacy/mcp"] }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Hermes (`config.yaml`)
|
|
101
|
+
|
|
102
|
+
```yaml
|
|
103
|
+
mcp_servers:
|
|
104
|
+
fidacy:
|
|
105
|
+
command: npx
|
|
106
|
+
args: ["-y", "@fidacy/mcp"]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### OpenClaw
|
|
110
|
+
|
|
111
|
+
Add the same server via the Tools panel, or the `mcpServers` block in your
|
|
112
|
+
agent config. Any MCP-compatible host uses the same command.
|
|
113
|
+
|
|
114
|
+
## Wiring the real core (production)
|
|
115
|
+
|
|
116
|
+
The MCP layer talks to your core through one interface (`FidacyCore`). Your
|
|
117
|
+
repository stays private. Set `FIDACY_MODE=http` and implement three endpoints:
|
|
118
|
+
|
|
119
|
+
- `POST /v1/mandate/get` -> `Mandate`
|
|
120
|
+
- `POST /v1/decide` -> `Decision` (runs your Ed25519/AP2 verification + audit append)
|
|
121
|
+
- `POST /v1/audit/proof` -> `AuditProof`
|
|
122
|
+
|
|
123
|
+
No change to the MCP layer is needed.
|
|
124
|
+
|
|
125
|
+
## Dev
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm install
|
|
129
|
+
npm run build
|
|
130
|
+
npm start # stdio server, in-memory demo mandate
|
|
131
|
+
```
|
package/dist/assess.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type AssessKind = "ap2_payment" | "message_send" | "voice_call" | "custom" | "claim_document";
|
|
2
|
+
export interface AssessParams {
|
|
3
|
+
/** Action kind. Defaults to `ap2_payment`. */
|
|
4
|
+
kind?: AssessKind;
|
|
5
|
+
/** The action/mandate object for this kind. */
|
|
6
|
+
mandate: unknown;
|
|
7
|
+
/** Optional explicit mandate type. The engine derives it otherwise. */
|
|
8
|
+
mandateType?: string;
|
|
9
|
+
/** Optional A2A correlation block. Adds the `A2A-Version` header when present. */
|
|
10
|
+
a2a?: {
|
|
11
|
+
task_id: string;
|
|
12
|
+
};
|
|
13
|
+
/** Optional spending mandate. Sent as snake_case `spending_mandate`. */
|
|
14
|
+
spendingMandate?: unknown;
|
|
15
|
+
/** Optional idempotency key. Sent as snake_case `idempotency_key`. Enables retry. */
|
|
16
|
+
idempotencyKey?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AssessResult {
|
|
19
|
+
decision: "approve" | "review" | "deny";
|
|
20
|
+
score: number;
|
|
21
|
+
assessmentId: string;
|
|
22
|
+
mandateId: string;
|
|
23
|
+
riskPayloadJws: string;
|
|
24
|
+
riskPayload: Record<string, unknown>;
|
|
25
|
+
signingKeyId: string;
|
|
26
|
+
signals: Record<string, unknown>;
|
|
27
|
+
mandate: Record<string, unknown>;
|
|
28
|
+
outcome: Record<string, unknown>;
|
|
29
|
+
billing?: Record<string, unknown>;
|
|
30
|
+
spend_guard?: Record<string, unknown>;
|
|
31
|
+
a2a?: Record<string, unknown>;
|
|
32
|
+
[k: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface RejectionReason {
|
|
35
|
+
key: string;
|
|
36
|
+
category?: string;
|
|
37
|
+
message?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Typed error from the engine. `message` is STATIC and never contains the key or
|
|
42
|
+
* request body. `type` is the stable engine error code (or a client code), and
|
|
43
|
+
* `status` is the HTTP status (0 for network/timeout).
|
|
44
|
+
*/
|
|
45
|
+
export declare class AssessError extends Error {
|
|
46
|
+
readonly type: string;
|
|
47
|
+
readonly status: number;
|
|
48
|
+
readonly details?: unknown;
|
|
49
|
+
readonly rejection_reasons?: RejectionReason[];
|
|
50
|
+
constructor(opts: {
|
|
51
|
+
type: string;
|
|
52
|
+
status: number;
|
|
53
|
+
details?: unknown;
|
|
54
|
+
rejection_reasons?: RejectionReason[];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export interface AssessConfig {
|
|
58
|
+
/** Base URL of the engine, e.g. `https://api.fidacy.com`. Trailing slashes stripped. */
|
|
59
|
+
engineUrl: string;
|
|
60
|
+
/** API key (`fky_live_…`/`fky_test_…`) with scope `assess:write`. Never logged. */
|
|
61
|
+
apiKey: string;
|
|
62
|
+
/** Custom fetch (tests, edge runtimes). Default: `globalThis.fetch`. */
|
|
63
|
+
fetchImpl?: typeof fetch;
|
|
64
|
+
/** Per-request timeout in ms. Default 10000. */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
/** Max retries on transient failures (only when an idempotency key is set). Default 2. */
|
|
67
|
+
maxRetries?: number;
|
|
68
|
+
/** Backoff (ms) for attempt n. Default exponential base 200ms cap 2000ms. */
|
|
69
|
+
backoffMs?: (n: number) => number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Call the live engine's POST /v1/assess and return the signed trust verdict.
|
|
73
|
+
*
|
|
74
|
+
* Retries ONLY when an idempotency key was supplied, on 5xx/429/network/timeout,
|
|
75
|
+
* with small exponential backoff and a per-request AbortController timeout. This
|
|
76
|
+
* mirrors the @fidacy/sdk request() behavior. Self-contained; no sdk import.
|
|
77
|
+
*/
|
|
78
|
+
export declare function assessAction(params: AssessParams, cfg: AssessConfig): Promise<AssessResult>;
|
package/dist/assess.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Self-contained client for the LIVE Fidacy engine POST /v1/assess.
|
|
2
|
+
//
|
|
3
|
+
// This mirrors the request/response shape of the OSS @fidacy/sdk client EXACTLY
|
|
4
|
+
// but does NOT depend on it: the MCP package stays self-contained so a single
|
|
5
|
+
// install ships both the signed verdict layer (this) and the payment firewall.
|
|
6
|
+
//
|
|
7
|
+
// The returned signed proof is `riskPayloadJws` + `signingKeyId`, verifiable by
|
|
8
|
+
// anyone via @fidacy/verify against {engineUrl}/.well-known/jwks.json.
|
|
9
|
+
//
|
|
10
|
+
// Secret safety: the API key, request body, and any secret are NEVER logged,
|
|
11
|
+
// echoed, or attached to an error. Errors carry only stable type/status.
|
|
12
|
+
/**
|
|
13
|
+
* Typed error from the engine. `message` is STATIC and never contains the key or
|
|
14
|
+
* request body. `type` is the stable engine error code (or a client code), and
|
|
15
|
+
* `status` is the HTTP status (0 for network/timeout).
|
|
16
|
+
*/
|
|
17
|
+
export class AssessError extends Error {
|
|
18
|
+
type;
|
|
19
|
+
status;
|
|
20
|
+
details;
|
|
21
|
+
rejection_reasons;
|
|
22
|
+
constructor(opts) {
|
|
23
|
+
super(`Fidacy assess error (${opts.type}, HTTP ${opts.status})`);
|
|
24
|
+
this.name = "AssessError";
|
|
25
|
+
this.type = opts.type;
|
|
26
|
+
this.status = opts.status;
|
|
27
|
+
this.details = opts.details;
|
|
28
|
+
this.rejection_reasons = opts.rejection_reasons;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const DEFAULT_TIMEOUT = 10_000;
|
|
32
|
+
const DEFAULT_RETRIES = 2;
|
|
33
|
+
const defaultBackoff = (n) => Math.min(200 * 2 ** n, 2_000);
|
|
34
|
+
function isRecord(v) {
|
|
35
|
+
return typeof v === "object" && v !== null;
|
|
36
|
+
}
|
|
37
|
+
function sleep(ms) {
|
|
38
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Call the live engine's POST /v1/assess and return the signed trust verdict.
|
|
42
|
+
*
|
|
43
|
+
* Retries ONLY when an idempotency key was supplied, on 5xx/429/network/timeout,
|
|
44
|
+
* with small exponential backoff and a per-request AbortController timeout. This
|
|
45
|
+
* mirrors the @fidacy/sdk request() behavior. Self-contained; no sdk import.
|
|
46
|
+
*/
|
|
47
|
+
export async function assessAction(params, cfg) {
|
|
48
|
+
const fetchImpl = cfg.fetchImpl ?? globalThis.fetch;
|
|
49
|
+
if (typeof fetchImpl !== "function") {
|
|
50
|
+
throw new AssessError({ type: "config_error", status: 0 });
|
|
51
|
+
}
|
|
52
|
+
const baseUrl = cfg.engineUrl.replace(/\/+$/, "");
|
|
53
|
+
const url = `${baseUrl}/v1/assess`;
|
|
54
|
+
const timeoutMs = cfg.timeoutMs ?? DEFAULT_TIMEOUT;
|
|
55
|
+
const maxRetries = cfg.maxRetries ?? DEFAULT_RETRIES;
|
|
56
|
+
const backoffMs = cfg.backoffMs ?? defaultBackoff;
|
|
57
|
+
// Build the body with snake_case wire keys, omitting unset keys entirely.
|
|
58
|
+
const body = {
|
|
59
|
+
kind: params.kind ?? "ap2_payment",
|
|
60
|
+
mandate: params.mandate,
|
|
61
|
+
};
|
|
62
|
+
if (params.mandateType !== undefined)
|
|
63
|
+
body.mandateType = params.mandateType;
|
|
64
|
+
if (params.a2a !== undefined)
|
|
65
|
+
body.a2a = params.a2a;
|
|
66
|
+
if (params.spendingMandate !== undefined)
|
|
67
|
+
body.spending_mandate = params.spendingMandate;
|
|
68
|
+
if (params.idempotencyKey !== undefined)
|
|
69
|
+
body.idempotency_key = params.idempotencyKey;
|
|
70
|
+
const payload = JSON.stringify(body);
|
|
71
|
+
const headers = {
|
|
72
|
+
"content-type": "application/json",
|
|
73
|
+
authorization: `Bearer ${cfg.apiKey}`,
|
|
74
|
+
};
|
|
75
|
+
if (params.a2a !== undefined)
|
|
76
|
+
headers["A2A-Version"] = "0.1.0";
|
|
77
|
+
// Retry is only safe when the caller supplied an idempotency key.
|
|
78
|
+
const canRetryTransient = params.idempotencyKey !== undefined;
|
|
79
|
+
let attempt = 0;
|
|
80
|
+
for (;;) {
|
|
81
|
+
try {
|
|
82
|
+
return await postOnce(fetchImpl, url, headers, payload, timeoutMs);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
const isTransient = err instanceof AssessError &&
|
|
86
|
+
(err.status === 0 || err.status === 429 || err.status >= 500);
|
|
87
|
+
const canRetry = isTransient && canRetryTransient && attempt < maxRetries;
|
|
88
|
+
if (!canRetry)
|
|
89
|
+
throw err;
|
|
90
|
+
await sleep(backoffMs(attempt));
|
|
91
|
+
attempt += 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function postOnce(fetchImpl, url, headers, payload, timeoutMs) {
|
|
96
|
+
const controller = new AbortController();
|
|
97
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
98
|
+
let res;
|
|
99
|
+
try {
|
|
100
|
+
res = await fetchImpl(url, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers,
|
|
103
|
+
body: payload,
|
|
104
|
+
signal: controller.signal,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
const aborted = controller.signal.aborted;
|
|
109
|
+
// Never attach the key/body/err message that could leak a secret.
|
|
110
|
+
throw new AssessError({ type: aborted ? "timeout" : "network_error", status: 0 });
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
}
|
|
115
|
+
const text = await res.text();
|
|
116
|
+
let parsed = undefined;
|
|
117
|
+
if (text) {
|
|
118
|
+
try {
|
|
119
|
+
parsed = JSON.parse(text);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// non-JSON response: handled below by status
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
const type = (isRecord(parsed) && typeof parsed.error === "string" && parsed.error) ||
|
|
127
|
+
`http_${res.status}`;
|
|
128
|
+
const details = isRecord(parsed) ? parsed.details : undefined;
|
|
129
|
+
const rejection_reasons = isRecord(parsed) && Array.isArray(parsed.rejection_reasons)
|
|
130
|
+
? parsed.rejection_reasons
|
|
131
|
+
: undefined;
|
|
132
|
+
throw new AssessError({ type, status: res.status, details, rejection_reasons });
|
|
133
|
+
}
|
|
134
|
+
if (!isRecord(parsed)) {
|
|
135
|
+
throw new AssessError({ type: "invalid_response", status: res.status });
|
|
136
|
+
}
|
|
137
|
+
return parsed;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=assess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assess.js","sourceRoot":"","sources":["../src/assess.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,+EAA+E;AAC/E,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AAgDzE;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAW;IAClB,iBAAiB,CAAqB;IAE/C,YAAY,IAKX;QACC,KAAK,CAAC,wBAAwB,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;IAClD,CAAC;CACF;AAiBD,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,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,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC;YACtE,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9D,MAAM,iBAAiB,GACrB,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACzD,CAAC,CAAE,MAAM,CAAC,iBAAuC;YACjD,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,MAAsB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuditRecord, Decision } from "./types.js";
|
|
2
|
+
export declare class FileAuditStore {
|
|
3
|
+
private path;
|
|
4
|
+
private chain;
|
|
5
|
+
constructor(path: string);
|
|
6
|
+
private load;
|
|
7
|
+
private head;
|
|
8
|
+
append(decision: Decision): AuditRecord;
|
|
9
|
+
find(decisionId: string): AuditRecord | undefined;
|
|
10
|
+
intact(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { sha256 } from "./signing.js";
|
|
3
|
+
import { stableStringify } from "./util.js";
|
|
4
|
+
// Durable append-only, hash-chained audit log. One JSON record per line.
|
|
5
|
+
// Real persistence (survives restart). Production swaps this for the Supabase
|
|
6
|
+
// append-only table behind HttpFidacyCore; the shape is identical.
|
|
7
|
+
export class FileAuditStore {
|
|
8
|
+
path;
|
|
9
|
+
chain = [];
|
|
10
|
+
constructor(path) {
|
|
11
|
+
this.path = path;
|
|
12
|
+
this.load();
|
|
13
|
+
}
|
|
14
|
+
load() {
|
|
15
|
+
if (!fs.existsSync(this.path))
|
|
16
|
+
return;
|
|
17
|
+
const lines = fs.readFileSync(this.path, "utf8").split("\n").filter((l) => l.trim());
|
|
18
|
+
for (const line of lines)
|
|
19
|
+
this.chain.push(JSON.parse(line));
|
|
20
|
+
if (!this.intact())
|
|
21
|
+
throw new Error(`audit chain integrity broken at ${this.path}`);
|
|
22
|
+
}
|
|
23
|
+
head() {
|
|
24
|
+
return this.chain.length ? this.chain[this.chain.length - 1].hash : "GENESIS";
|
|
25
|
+
}
|
|
26
|
+
append(decision) {
|
|
27
|
+
const prevHash = this.head();
|
|
28
|
+
const seq = this.chain.length;
|
|
29
|
+
const ts = decision.ts;
|
|
30
|
+
const digest = sha256(stableStringify({ decisionId: decision.decisionId, status: decision.status, request: decision.request, violatedRule: decision.violatedRule ?? null }));
|
|
31
|
+
const hash = sha256(`${prevHash}|${digest}|${seq}|${ts}`);
|
|
32
|
+
const record = { seq, decisionId: decision.decisionId, status: decision.status, subject: decision.subject, digest, prevHash, hash, ts };
|
|
33
|
+
fs.appendFileSync(this.path, JSON.stringify(record) + "\n");
|
|
34
|
+
this.chain.push(record);
|
|
35
|
+
return record;
|
|
36
|
+
}
|
|
37
|
+
find(decisionId) {
|
|
38
|
+
return this.chain.find((r) => r.decisionId === decisionId);
|
|
39
|
+
}
|
|
40
|
+
intact() {
|
|
41
|
+
let prev = "GENESIS";
|
|
42
|
+
for (const r of this.chain) {
|
|
43
|
+
const expected = sha256(`${prev}|${r.digest}|${r.seq}|${r.ts}`);
|
|
44
|
+
if (expected !== r.hash || r.prevHash !== prev)
|
|
45
|
+
return false;
|
|
46
|
+
prev = r.hash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,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAChE,IAAI,QAAQ,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC;YAC7D,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Mandate, PaymentRequest, Decision, AuditProof } from "./types.js";
|
|
2
|
+
export interface FidacyCore {
|
|
3
|
+
getMandate(subject: string): Promise<Mandate>;
|
|
4
|
+
decide(req: PaymentRequest, subject: string): Promise<Decision>;
|
|
5
|
+
getProof(decisionId: string): Promise<AuditProof | null>;
|
|
6
|
+
publicKey(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare function evaluate(mandate: Mandate, req: PaymentRequest, spentSoFar: number): string | null;
|
|
9
|
+
export declare class DevFidacyCore implements FidacyCore {
|
|
10
|
+
private priv;
|
|
11
|
+
private pubPem;
|
|
12
|
+
private mandate;
|
|
13
|
+
private store;
|
|
14
|
+
private spent;
|
|
15
|
+
constructor();
|
|
16
|
+
private loadMandate;
|
|
17
|
+
getMandate(): Promise<Mandate>;
|
|
18
|
+
decide(req: PaymentRequest, subject: string): Promise<Decision>;
|
|
19
|
+
getProof(decisionId: string): Promise<AuditProof | null>;
|
|
20
|
+
publicKey(): string;
|
|
21
|
+
}
|
|
22
|
+
export declare class HttpFidacyCore implements FidacyCore {
|
|
23
|
+
private baseUrl;
|
|
24
|
+
private apiKey;
|
|
25
|
+
private subjectPub;
|
|
26
|
+
constructor(baseUrl: string, apiKey: string, subjectPub?: string);
|
|
27
|
+
private call;
|
|
28
|
+
getMandate(subject: string): Promise<Mandate>;
|
|
29
|
+
decide(req: PaymentRequest, subject: string): Promise<Decision>;
|
|
30
|
+
getProof(decisionId: string): Promise<AuditProof | null>;
|
|
31
|
+
publicKey(): string;
|
|
32
|
+
}
|
|
33
|
+
export declare function makeCore(): FidacyCore;
|