@fiderail/core 0.0.0-stage → 2.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FideRail Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # @fiderail/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Protocol-agnostic [FideRail](https://fiderail.com) Payment Control Plane kernel: `trust-v2` anti-sybil scoring engine, pre-flight payment firewall policy engine, offline Attenuated Capability Mandate validator, outbound secret scrubber, Merkle trust inclusion proofs, and `RemoteTrustClient` with TTL cache and outage fallback.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @fiderail/core
9
+ ```
10
+
11
+ ## Quick Usage
12
+
13
+ ```ts
14
+ import { createRemoteTrustClient } from "@fiderail/core";
15
+
16
+ const engine = createRemoteTrustClient({
17
+ apiBaseUrl: "https://api.fiderail.com",
18
+ onOutage: "fail-closed",
19
+ });
20
+
21
+ const verdict = await engine.preflightPaymentGuard({
22
+ chain: "base",
23
+ counterparty: "0x7284d41b5b852f2bd4c99bdf95043d84452d299c",
24
+ amountUsdc: 0.05,
25
+ policy: { maxSingleTxUsdc: 1.0, maxDailyUsdc: 10.0, minTrustScore: 40 },
26
+ });
27
+
28
+ console.log(verdict.decision, verdict.reasons);
29
+ ```
30
+
31
+ ## Key Exports
32
+
33
+ - **Engine & Remote Client**: `createTrustEngine`, `createRemoteTrustClient`, `createEmptyBaselineSnapshots` (`TrustEngine`, `RemoteOutagePolicy`)
34
+ - **Firewall & Mandates**: `DEFAULT_FIREWALL_POLICY`, `clampPolicy`, `validateMandateChain`, `createMandateSigningPayload`, `scanOutboundSecrets`, `isAssetAllowed`, `computeQuoteDigest`, `computePaymentFingerprint`, `computeDeliveryReceipt`
35
+ - **Anti-Sybil Scoring (`trust-v2`)**: `createTrustScorerV2`, `DEFAULT_TRUST_SCORER`, `DEFAULT_TRUST_V2_CONFIG`, `computeCreditProfilesFromPayments`, `computeActiveModelHash`, `detectDirectedCycles2And3`, `evaluateAssociatedCredit`
36
+ - **Merkle State Roots & Proofs**: `buildTrustStateRootCommitment`, `buildTrustMerkleProof`, `hashTrustProfileLeaf`, `buildMerkleInclusionProof`, `verifyMerkleInclusionProof`
37
+
38
+ ## Important Integration Semantics
39
+
40
+ - **Strict blocking of unknown / low-trust addresses (including micro-payments)**: By default, `DEFAULT_FIREWALL_POLICY` sets `allowUnknownMaxUsdc: 0.05` so unknown or low-score addresses are permitted up to `$0.05 USDC` with `WARN`. **If you need to hard-block all unknown or low-trust counterparties regardless of amount, set `allowUnknownMaxUsdc: 0` alongside `minTrustScore`.**
41
+ - **`onOutage` applies only to firewall decisions**: **`onOutage` (`"fail-closed"` / `"fail-open-micro"`) is enforced only inside `preflightPaymentGuard` (and `@fiderail/guard`'s `guardedX402Fetch`); `getAgentTrust` always throws when the cloud oracle is unreachable and no stale cache entry exists.**
42
+ - **`RemoteTrustClient.getPayerActivity` returns `null` remotely**: **In `RemoteTrustClient`, `getPayerActivity` returns `null` by default (only direct repository engines query local indexed outgoing flows); for remote seller-side buyer screening, call `POST /v1/trust-provider/before-settle`.**
43
+
44
+ ## Runtime Requirements
45
+
46
+ Runtime-agnostic ESM with **zero `node:*` imports** (depends only on `@fiderail/spec` and `@fiderail/zk-types`). Works in Node.js, Bun, Deno, Cloudflare Workers, and browsers.
47
+
48
+ ## Links
49
+
50
+ - Portal: [https://fiderail.com](https://fiderail.com)
51
+ - Documentation: [https://fiderail.com/docs](https://fiderail.com/docs)
52
+ - Source (GitLab): [https://gitlab.com/fiderail/fiderail](https://gitlab.com/fiderail/fiderail)
53
+ - Mirror (GitHub — pending reinstatement): [https://github.com/fiderail/fiderail](https://github.com/fiderail/fiderail)
54
+
55
+ ## License
56
+
57
+ [MIT](./LICENSE)
@@ -0,0 +1,99 @@
1
+ import { type AssetSymbol, type ChainKey } from "@fiderail/spec";
2
+ import { type MerkleInclusionProof, type TrustStateRootCommitment } from "@fiderail/zk-types";
3
+ import type { AgentTrustLookupResult, AgentTrustProfile, AssociatedCreditEndorsement, AttenuatedMandate, BaselineSnapshots, ControlPlaneVerdict, FideRailRepository, FirewallPolicy, OpenBazaarRegistrationItem, PayerActivitySummary, PaymentIntent, PreflightGuardResult, RecordDeliveryTelemetryInput, ServiceSummary, TrustScoreHistoryEntry } from "./types.js";
4
+ export declare function createEmptyBaselineSnapshots(): BaselineSnapshots;
5
+ export interface TrustEngineOptions {
6
+ repo?: FideRailRepository | null;
7
+ baseline?: BaselineSnapshots;
8
+ }
9
+ export interface TrustHistoryLookupResult {
10
+ chain: ChainKey;
11
+ address: string;
12
+ currentProfile: AgentTrustLookupResult;
13
+ history: TrustScoreHistoryEntry[];
14
+ latestStateRoot: TrustStateRootCommitment | null;
15
+ merkleProof?: MerkleInclusionProof | null;
16
+ }
17
+ export interface TrustEngine {
18
+ getIndexerHealth(): Promise<Record<string, unknown>>;
19
+ getDatasetSummary(): Promise<Record<string, unknown>>;
20
+ getAgentTrust(chain: string, address: string): Promise<AgentTrustLookupResult>;
21
+ getPayerActivity?(chain: string, address: string): Promise<PayerActivitySummary | null>;
22
+ getAgentHistory(chain: string, address: string, limit?: number): Promise<TrustHistoryLookupResult>;
23
+ listAuditedAgents(opts?: {
24
+ chain?: string;
25
+ minScore?: number;
26
+ excludeFlagged?: boolean;
27
+ tier?: string;
28
+ channel?: string;
29
+ sort?: string;
30
+ offset?: number;
31
+ limit?: number;
32
+ query?: string;
33
+ }): Promise<{
34
+ count: number;
35
+ totalMatched: number;
36
+ offset: number;
37
+ limit: number;
38
+ hasMore: boolean;
39
+ agents: Array<AgentTrustProfile & {
40
+ bazaarListed: boolean;
41
+ serviceSummary: ServiceSummary | null;
42
+ livenessSummary: Record<string, unknown> | null;
43
+ }>;
44
+ }>;
45
+ discoverTrustedServices(opts?: {
46
+ query?: string;
47
+ chain?: string;
48
+ maxPriceUsdc?: number | null;
49
+ minTrustScore?: number;
50
+ excludeFlagged?: boolean;
51
+ offset?: number;
52
+ limit?: number;
53
+ }): Promise<{
54
+ count: number;
55
+ totalMatched: number;
56
+ offset: number;
57
+ limit: number;
58
+ hasMore: boolean;
59
+ services: Array<Record<string, unknown>>;
60
+ }>;
61
+ preflightPaymentGuard(params: {
62
+ chain: string;
63
+ counterparty: string;
64
+ amountUsdc: number;
65
+ assetSymbol?: AssetSymbol;
66
+ spentTodayUsdc?: number;
67
+ policy?: FirewallPolicy;
68
+ }): Promise<PreflightGuardResult>;
69
+ evaluatePaymentIntent(params: {
70
+ intent: PaymentIntent;
71
+ mandateChain?: readonly AttenuatedMandate[];
72
+ spentTodayUsd?: number;
73
+ spentUnderMandateUsd?: number;
74
+ revokedMandateIds?: ReadonlySet<string>;
75
+ policy?: FirewallPolicy;
76
+ }): Promise<ControlPlaneVerdict>;
77
+ registerAssociatedCredit(endorsement: AssociatedCreditEndorsement): Promise<{
78
+ ok: boolean;
79
+ }>;
80
+ revokeAssociatedCredit(endorsementId: string): Promise<{
81
+ ok: boolean;
82
+ }>;
83
+ registerOpenBazaarServices(items: readonly OpenBazaarRegistrationItem[]): Promise<{
84
+ ok: boolean;
85
+ registeredCount: number;
86
+ reason?: string;
87
+ }>;
88
+ recordDeliveryTelemetry(input: RecordDeliveryTelemetryInput): Promise<{
89
+ ok: boolean;
90
+ persisted: boolean;
91
+ duplicate?: boolean;
92
+ reason?: string;
93
+ chain?: ChainKey;
94
+ address?: string;
95
+ }>;
96
+ close(): Promise<void>;
97
+ }
98
+ export declare function createTrustEngine(options?: TrustEngineOptions): TrustEngine;
99
+ //# sourceMappingURL=engine.d.ts.map