@peac/adapter-core 0.10.0 → 0.10.6

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/README.md CHANGED
@@ -89,4 +89,6 @@ Apache-2.0
89
89
 
90
90
  ---
91
91
 
92
- Part of the [PEAC Protocol](https://peacprotocol.org).
92
+ PEAC Protocol is an open source project stewarded by Originary and community contributors.
93
+
94
+ [Docs](https://www.peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac) | [Originary](https://www.originary.xyz)
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export type { JsonPrimitive, JsonValue, JsonArray, JsonObject } from '@peac/kern
10
10
  export { type Result, ok, err, adapterErr, isOk, isErr, map, mapErr, chain, unwrap, unwrapOr, } from './result.js';
11
11
  export type { AdapterError, AdapterErrorCode } from './types.js';
12
12
  export { requireString, optionalString, requireNumber, requireAmount, requireCurrency, optionalNetwork, requireObject, optionalTimestamp, optionalBoolean, requireEnum, optionalEnum, } from './validators.js';
13
+ export type { NormalizedTerms, NormalizedSettlement, TermsVerification, SettlementVerification, VerificationError, PaymentProofRecord, VerificationContext, PaymentProofAdapter, CryptoVerifier, } from './payment-proof.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGpF,OAAO,EACL,KAAK,MAAM,EACX,EAAE,EACF,GAAG,EACH,UAAU,EACV,IAAI,EACJ,KAAK,EACL,GAAG,EACH,MAAM,EACN,KAAK,EACL,MAAM,EACN,QAAQ,GACT,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGjE,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,YAAY,GACb,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGpF,OAAO,EACL,KAAK,MAAM,EACX,EAAE,EACF,GAAG,EACH,UAAU,EACV,IAAI,EACJ,KAAK,EACL,GAAG,EACH,MAAM,EACN,KAAK,EACL,MAAM,EACN,QAAQ,GACT,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGjE,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,YAAY,GACb,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,GACf,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Payment Proof Adapter Interface
3
+ *
4
+ * Defines the contract that all payment proof adapters must implement.
5
+ * This interface ensures consistency across different payment protocols
6
+ * (x402, Stripe, UPI, Lightning, etc.) while allowing protocol-specific
7
+ * implementations.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import type { Result } from './result.js';
12
+ import type { AdapterError } from './types.js';
13
+ /**
14
+ * Normalized payment terms extracted from proof artifacts
15
+ *
16
+ * This is the common denominator across all payment protocols.
17
+ * Protocol-specific fields belong in the raw proofs, not here.
18
+ */
19
+ export interface NormalizedTerms {
20
+ /** Payment asset (e.g., "USDC", "USD", "BTC") */
21
+ asset: string;
22
+ /** Payment amount in minor units as string (to avoid precision loss) */
23
+ amount: string;
24
+ /** Payment recipient identifier (address, account, etc.) */
25
+ payee: string;
26
+ /** Network identifier (CAIP-2 preferred, but protocol-specific allowed) */
27
+ network?: string;
28
+ /** Terms validity window */
29
+ timebounds?: {
30
+ /** Not valid before (epoch seconds) */
31
+ notBefore?: number;
32
+ /** Not valid after (epoch seconds) */
33
+ notAfter?: number;
34
+ };
35
+ }
36
+ /**
37
+ * Normalized settlement evidence extracted from proof artifacts
38
+ */
39
+ export interface NormalizedSettlement {
40
+ /** Settlement reference (tx hash, payment intent ID, etc.) */
41
+ reference: string;
42
+ /** Settlement network (may differ from terms network) */
43
+ network?: string;
44
+ /** Settlement status */
45
+ status: 'confirmed' | 'pending' | 'failed';
46
+ /** Settlement timestamp (epoch seconds) */
47
+ settledAt?: number;
48
+ }
49
+ /**
50
+ * Result of terms verification
51
+ */
52
+ export interface TermsVerification<TRaw = unknown> {
53
+ /** Whether verification passed */
54
+ valid: boolean;
55
+ /** Normalized terms (if valid) */
56
+ terms?: NormalizedTerms;
57
+ /** Raw proof artifact (preserved for audit) */
58
+ raw: TRaw;
59
+ /** Verification errors (if invalid) */
60
+ errors: VerificationError[];
61
+ /** Whether a hint was used for binding (protocol-specific) */
62
+ usedHint?: boolean;
63
+ }
64
+ /**
65
+ * Result of settlement verification
66
+ */
67
+ export interface SettlementVerification<TRaw = unknown> {
68
+ /** Whether verification passed */
69
+ valid: boolean;
70
+ /** Normalized settlement (if valid) */
71
+ settlement?: NormalizedSettlement;
72
+ /** Raw proof artifact (preserved for audit) */
73
+ raw: TRaw;
74
+ /** Verification errors (if invalid) */
75
+ errors: VerificationError[];
76
+ }
77
+ /**
78
+ * Structured verification error
79
+ */
80
+ export interface VerificationError {
81
+ /** Machine-readable error code */
82
+ code: string;
83
+ /** Human-readable message */
84
+ message: string;
85
+ /** Field that caused the error */
86
+ field?: string;
87
+ }
88
+ /**
89
+ * Base PEAC record structure for payment proofs
90
+ *
91
+ * Adapters extend this with protocol-specific fields in `proofs` and `hints`.
92
+ */
93
+ export interface PaymentProofRecord<TProofs = unknown, THints = unknown> {
94
+ /** Profile identifier (e.g., "peac-x402-offer-receipt/0.1") */
95
+ version: string;
96
+ /** Raw proof artifacts (preserved for audit) */
97
+ proofs: TProofs;
98
+ /** Normalized evidence fields */
99
+ evidence: {
100
+ /** From terms */
101
+ asset: string;
102
+ amount: string;
103
+ payee: string;
104
+ network?: string;
105
+ validUntil?: number;
106
+ /** From settlement */
107
+ reference?: string;
108
+ settledAt?: number;
109
+ };
110
+ /** Protocol-specific hints (marked as untrusted where appropriate) */
111
+ hints: THints;
112
+ /** RFC 8785 JCS + SHA-256 digest */
113
+ digest?: string;
114
+ /** ISO 8601 timestamp of record creation */
115
+ createdAt: string;
116
+ }
117
+ /**
118
+ * Verification context provided to adapter methods
119
+ */
120
+ export interface VerificationContext {
121
+ /** Current time override (epoch seconds, for testing) */
122
+ nowSeconds?: number;
123
+ /** Clock skew tolerance in seconds */
124
+ clockSkewSeconds?: number;
125
+ /** Mismatch policy for hint-based binding */
126
+ mismatchPolicy?: 'fail' | 'warn_and_scan' | 'ignore_and_scan';
127
+ }
128
+ /**
129
+ * Payment Proof Adapter Interface
130
+ *
131
+ * All payment proof adapters must implement this interface.
132
+ * This ensures a consistent API surface across different payment protocols.
133
+ *
134
+ * @typeParam TTermsInput - Protocol-specific terms input type
135
+ * @typeParam TSettlementInput - Protocol-specific settlement input type
136
+ * @typeParam TTermsRaw - Protocol-specific raw terms artifact type
137
+ * @typeParam TSettlementRaw - Protocol-specific raw settlement artifact type
138
+ * @typeParam TRecord - Protocol-specific PEAC record type
139
+ *
140
+ * @example
141
+ * // x402 adapter implements this interface
142
+ * const adapter: PaymentProofAdapter<
143
+ * X402PaymentRequired,
144
+ * X402SettlementResponse,
145
+ * SignedOffer,
146
+ * SignedReceipt,
147
+ * X402PeacRecord
148
+ * > = {
149
+ * profileId: 'peac-x402-offer-receipt/0.1',
150
+ * verifyTerms: (input, ctx) => { ... },
151
+ * verifySettlement: (input, ctx) => { ... },
152
+ * toRecord: (terms, settlement) => { ... },
153
+ * };
154
+ */
155
+ export interface PaymentProofAdapter<TTermsInput = unknown, TSettlementInput = unknown, TTermsRaw = unknown, TSettlementRaw = unknown, TRecord extends PaymentProofRecord = PaymentProofRecord> {
156
+ /**
157
+ * Profile identifier for this adapter
158
+ *
159
+ * Format: "peac-{protocol}/{version}" (e.g., "peac-x402-offer-receipt/0.1")
160
+ */
161
+ readonly profileId: string;
162
+ /**
163
+ * Verify payment terms
164
+ *
165
+ * Performs structural validation, expiry checks, and protocol-specific
166
+ * binding verification (e.g., term-matching for x402).
167
+ *
168
+ * Does NOT perform cryptographic signature verification unless
169
+ * a crypto verifier is injected via context.
170
+ *
171
+ * @param input - Protocol-specific terms input
172
+ * @param context - Verification context (optional)
173
+ * @returns Verification result with normalized terms
174
+ */
175
+ verifyTerms(input: TTermsInput, context?: VerificationContext): Result<TermsVerification<TTermsRaw>, AdapterError>;
176
+ /**
177
+ * Verify settlement proof
178
+ *
179
+ * Performs structural validation of the settlement artifact.
180
+ *
181
+ * Does NOT verify on-chain settlement status - that is the caller's
182
+ * responsibility via chain RPC.
183
+ *
184
+ * @param input - Protocol-specific settlement input
185
+ * @param context - Verification context (optional)
186
+ * @returns Verification result with normalized settlement
187
+ */
188
+ verifySettlement(input: TSettlementInput, context?: VerificationContext): Result<SettlementVerification<TSettlementRaw>, AdapterError>;
189
+ /**
190
+ * Map verified proofs to a PEAC record
191
+ *
192
+ * @param terms - Verified terms result
193
+ * @param settlement - Verified settlement result
194
+ * @returns PEAC record with normalized evidence and raw proofs
195
+ */
196
+ toRecord(terms: TermsVerification<TTermsRaw>, settlement: SettlementVerification<TSettlementRaw>): Result<TRecord, AdapterError>;
197
+ }
198
+ /**
199
+ * Optional cryptographic verifier interface
200
+ *
201
+ * Adapters may accept an injected crypto verifier for signature validation.
202
+ * This allows callers to provide protocol-specific verification (EIP-712,
203
+ * JWS, etc.) without the adapter depending on crypto libraries.
204
+ */
205
+ export interface CryptoVerifier<TInput = unknown> {
206
+ /**
207
+ * Verify cryptographic signature
208
+ *
209
+ * @param input - Input to verify (protocol-specific)
210
+ * @returns true if signature is valid, false otherwise
211
+ */
212
+ verify(input: TInput): Promise<boolean>;
213
+ /**
214
+ * Get signer identity from verified input
215
+ *
216
+ * @param input - Verified input
217
+ * @returns Signer identifier (address, key ID, etc.)
218
+ */
219
+ getSigner?(input: TInput): Promise<string>;
220
+ }
221
+ //# sourceMappingURL=payment-proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-proof.d.ts","sourceRoot":"","sources":["../src/payment-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM/C;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,UAAU,CAAC,EAAE;QACX,uCAAuC;QACvC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,sCAAsC;QACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC3C,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MA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O;IAC9C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAExC;;;;;OAKG;IACH,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Payment Proof Adapter Interface
4
+ *
5
+ * Defines the contract that all payment proof adapters must implement.
6
+ * This interface ensures consistency across different payment protocols
7
+ * (x402, Stripe, UPI, Lightning, etc.) while allowing protocol-specific
8
+ * implementations.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ //# sourceMappingURL=payment-proof.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-proof.js","sourceRoot":"","sources":["../src/payment-proof.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peac/adapter-core",
3
- "version": "0.10.0",
3
+ "version": "0.10.6",
4
4
  "description": "Shared utilities for PEAC payment rail adapters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@peac/kernel": "0.10.0"
30
+ "@peac/kernel": "0.10.6"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^20.10.0",