@zadq/x402 0.0.0-stage → 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 +202 -0
- package/NOTICE +8 -0
- package/README.md +35 -2
- package/dist/brand.d.ts +1 -0
- package/dist/brand.js +3 -0
- package/dist/explorer.d.ts +47 -0
- package/dist/explorer.js +76 -0
- package/dist/extension.d.ts +169 -0
- package/dist/extension.js +182 -0
- package/dist/header.d.ts +30 -0
- package/dist/header.js +84 -0
- package/dist/holder/chain.d.ts +28 -0
- package/dist/holder/chain.js +167 -0
- package/dist/holder/cli.d.ts +42 -0
- package/dist/holder/cli.js +173 -0
- package/dist/holder/custody.d.ts +20 -0
- package/dist/holder/custody.js +112 -0
- package/dist/holder/errors.d.ts +22 -0
- package/dist/holder/errors.js +38 -0
- package/dist/holder/holder.d.ts +115 -0
- package/dist/holder/holder.js +381 -0
- package/dist/holder/index.d.ts +8 -0
- package/dist/holder/index.js +14 -0
- package/dist/holder/killswitch.d.ts +139 -0
- package/dist/holder/killswitch.js +257 -0
- package/dist/holder/process.d.ts +31 -0
- package/dist/holder/process.js +84 -0
- package/dist/holder/types.d.ts +108 -0
- package/dist/holder/types.js +5 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -0
- package/dist/keys.d.ts +17 -0
- package/dist/keys.js +45 -0
- package/dist/receipt.d.ts +50 -0
- package/dist/receipt.js +193 -0
- package/dist/verdict.d.ts +101 -0
- package/dist/verdict.js +179 -0
- package/dist/webhook.d.ts +29 -0
- package/dist/webhook.js +96 -0
- package/package.json +85 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
zadq-x402-tools — x402 extension helpers and explorer integration code
|
|
2
|
+
Copyright 2026 CONECTIA group
|
|
3
|
+
|
|
4
|
+
This product includes software developed for the ZadQ project.
|
|
5
|
+
Licensed under the Apache License, Version 2.0.
|
|
6
|
+
|
|
7
|
+
"x402" is used descriptively. This project is not affiliated with, sponsored
|
|
8
|
+
by or maintained by the x402 ecosystem's trademark holders.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zadq/x402
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Verifiable accountability for agent payments. Prove accountability. Keep identity private.**
|
|
4
|
+
|
|
5
|
+
Client helpers for the free seller-verification path of x402 endpoints, from
|
|
6
|
+
[ZadQ](https://zadq.info/docs): fetch the signed verdict for an endpoint and
|
|
7
|
+
check its freshness and Ed25519 signature locally; attach or read the HTTP 402
|
|
8
|
+
identity-policy extension and the `X-PAYMENT-IDENTITY` companion header; verify
|
|
9
|
+
the issuer's receipt; resolve an explorer signal with a TTL cache; verify
|
|
10
|
+
`verdict.updated` webhook deliveries; drive the seller's own credential holder
|
|
11
|
+
(Node only). Strict TypeScript, ES modules, zero runtime dependencies, no
|
|
12
|
+
default exports.
|
|
13
|
+
|
|
14
|
+
Every helper degrades gracefully: an unreachable service, a timeout, an absent
|
|
15
|
+
or stale verdict or a failed signature check resolve to `unknown` — never an
|
|
16
|
+
exception, never a blocked payment. Checking a verdict costs nothing for
|
|
17
|
+
whoever runs the check.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @zadq/x402
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { fetchVerdict, freshness, verifyVerdictSignature } from '@zadq/x402/verdict';
|
|
25
|
+
import { withIdentityPolicy } from '@zadq/x402/extension';
|
|
26
|
+
import { resolveSignal } from '@zadq/x402/explorer';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Subpath exports: `verdict`, `extension`, `header`, `receipt`, `explorer`,
|
|
30
|
+
`keys`, `webhook`, `holder` (Node only) — or everything from the root. The
|
|
31
|
+
contracts each module honours are documented at
|
|
32
|
+
<https://zadq.info/docs/sdk>; the modules are also available as copy-in files
|
|
33
|
+
in the repository's `snippets/` folder for integrators who prefer to vendor.
|
|
34
|
+
|
|
35
|
+
"x402" is used descriptively. About ZadQ and who operates it:
|
|
36
|
+
<https://zadq.info/about>. Apache-2.0 — see `LICENSE` and `NOTICE`.
|
package/dist/brand.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BRAND = "ZadQ";
|
package/dist/brand.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Freshness, type Verdict, type VerdictSubject } from './verdict.js';
|
|
2
|
+
/** Display signal for one endpoint row. Everything uncertain is "unknown". */
|
|
3
|
+
export type VerificationSignal = {
|
|
4
|
+
state: 'human-backed' | 'revoked' | 'unknown';
|
|
5
|
+
/** Assurance grade of the positive claim (e.g. "G"), when present. */
|
|
6
|
+
assuranceLevel?: string;
|
|
7
|
+
/** RFC 3339 time of the last re-check, when present. */
|
|
8
|
+
verifiedAt?: string;
|
|
9
|
+
/** The cadence promise the verdict carries ("re-checked every N hours"). */
|
|
10
|
+
recheckEveryHours?: number;
|
|
11
|
+
/** Local freshness of the verdict against its own cadence promise. */
|
|
12
|
+
freshness: Freshness;
|
|
13
|
+
};
|
|
14
|
+
/** The signal rendered when no verdict is available. Rendering never blocks on it. */
|
|
15
|
+
export declare const UNKNOWN_SIGNAL: VerificationSignal;
|
|
16
|
+
export type VerificationClientOptions = {
|
|
17
|
+
/** Base URL of the verification service (its free path is used). */
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional verification public key (base64, 32 raw bytes). When provided, a
|
|
21
|
+
* positive claim whose signature fails the local check is demoted to
|
|
22
|
+
* "unknown". When the runtime cannot check signatures, the verdict is used
|
|
23
|
+
* as delivered — the listing keeps working either way.
|
|
24
|
+
*/
|
|
25
|
+
publicKey?: string;
|
|
26
|
+
/** Fetch timeout in milliseconds (default 3000). */
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
/** In-memory cache TTL in milliseconds (default 5 minutes; 0 disables). */
|
|
29
|
+
cacheTtlMs?: number;
|
|
30
|
+
};
|
|
31
|
+
export type VerificationClient = {
|
|
32
|
+
/** Resolves the display signal for one endpoint. Never rejects. */
|
|
33
|
+
signalFor(subject: VerdictSubject): Promise<VerificationSignal>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Creates a small client for explorer listings: per-endpoint signal with an
|
|
37
|
+
* in-memory TTL cache (positive and "unknown" results alike, so an
|
|
38
|
+
* unreachable service is not re-queried on every row render).
|
|
39
|
+
*/
|
|
40
|
+
export declare function createVerificationClient(options: VerificationClientOptions): VerificationClient;
|
|
41
|
+
/**
|
|
42
|
+
* Maps a verdict (or its absence) to the display signal, optionally checking
|
|
43
|
+
* the signature of positive claims locally. Exported for callers that already
|
|
44
|
+
* hold a verdict — e.g. one delivered inline in a `PaymentRequired` extension
|
|
45
|
+
* (extension.ts) or by a webhook.
|
|
46
|
+
*/
|
|
47
|
+
export declare function toSignal(verdict: Verdict | undefined, publicKey?: string): Promise<VerificationSignal>;
|
package/dist/explorer.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Explorer-side integration: resolve the verification signal for x402
|
|
2
|
+
// endpoints a listing displays, next to the traffic metrics it already shows.
|
|
3
|
+
//
|
|
4
|
+
// The free verification path is consumed anonymously and is never charged
|
|
5
|
+
// for. Graceful degradation, by design: a listing keeps rendering exactly as
|
|
6
|
+
// before when no verification response is available — the signal degrades to
|
|
7
|
+
// "unknown", it never becomes an error state, a spinner or a blocked row.
|
|
8
|
+
import { canonicalPayTo, fetchVerdict, freshness, verifyVerdictSignature, } from "./verdict.js";
|
|
9
|
+
/** The signal rendered when no verdict is available. Rendering never blocks on it. */
|
|
10
|
+
export const UNKNOWN_SIGNAL = { state: 'unknown', freshness: 'unknown' };
|
|
11
|
+
/**
|
|
12
|
+
* Creates a small client for explorer listings: per-endpoint signal with an
|
|
13
|
+
* in-memory TTL cache (positive and "unknown" results alike, so an
|
|
14
|
+
* unreachable service is not re-queried on every row render).
|
|
15
|
+
*/
|
|
16
|
+
export function createVerificationClient(options) {
|
|
17
|
+
const ttl = options.cacheTtlMs ?? 300_000;
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
async function resolve(subject) {
|
|
20
|
+
const verdict = await fetchVerdict(options.baseUrl, subject, options.timeoutMs === undefined ? undefined : { timeoutMs: options.timeoutMs });
|
|
21
|
+
return toSignal(verdict, options.publicKey);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
async signalFor(subject) {
|
|
25
|
+
// One cache entry per endpoint, whatever spelling of an EVM address the
|
|
26
|
+
// listing passes (checksum and lowercase name the same account).
|
|
27
|
+
const key = [
|
|
28
|
+
subject.chain,
|
|
29
|
+
canonicalPayTo(subject.chain, subject.payTo),
|
|
30
|
+
subject.resourceUrl,
|
|
31
|
+
].join('\u0000');
|
|
32
|
+
const hit = cache.get(key);
|
|
33
|
+
if (hit !== undefined && Date.now() - hit.at <= ttl) {
|
|
34
|
+
return hit.signal;
|
|
35
|
+
}
|
|
36
|
+
const signal = await resolve(subject);
|
|
37
|
+
if (ttl > 0) {
|
|
38
|
+
cache.set(key, { at: Date.now(), signal });
|
|
39
|
+
}
|
|
40
|
+
return signal;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Maps a verdict (or its absence) to the display signal, optionally checking
|
|
46
|
+
* the signature of positive claims locally. Exported for callers that already
|
|
47
|
+
* hold a verdict — e.g. one delivered inline in a `PaymentRequired` extension
|
|
48
|
+
* (extension.ts) or by a webhook.
|
|
49
|
+
*/
|
|
50
|
+
export async function toSignal(verdict, publicKey) {
|
|
51
|
+
if (verdict === undefined) {
|
|
52
|
+
return UNKNOWN_SIGNAL;
|
|
53
|
+
}
|
|
54
|
+
if (verdict.outcome === 'human_backed' && publicKey !== undefined) {
|
|
55
|
+
const check = await verifyVerdictSignature(verdict, publicKey);
|
|
56
|
+
if (check === 'invalid') {
|
|
57
|
+
// An unverified positive claim is not displayed; the row still renders.
|
|
58
|
+
return UNKNOWN_SIGNAL;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
switch (verdict.outcome) {
|
|
62
|
+
case 'human_backed':
|
|
63
|
+
return {
|
|
64
|
+
state: 'human-backed',
|
|
65
|
+
...(verdict.assuranceLevel !== undefined && { assuranceLevel: verdict.assuranceLevel }),
|
|
66
|
+
...(verdict.verifiedAt !== undefined && { verifiedAt: verdict.verifiedAt }),
|
|
67
|
+
recheckEveryHours: verdict.recheckEveryHours,
|
|
68
|
+
freshness: freshness(verdict),
|
|
69
|
+
};
|
|
70
|
+
case 'revoked':
|
|
71
|
+
return { state: 'revoked', freshness: 'unknown' };
|
|
72
|
+
default:
|
|
73
|
+
// `stale` and `no_signal` both display as "unknown".
|
|
74
|
+
return UNKNOWN_SIGNAL;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Verdict } from './verdict.js';
|
|
2
|
+
/**
|
|
3
|
+
* The identity policy a seller advertises on its 402 response, following the
|
|
4
|
+
* bIP-0002 profile — sub-profile `bip-0002/0-seller`, the canonical v0 seller
|
|
5
|
+
* object (MintID canonical set `canonical-2026-09-24b`, restated in
|
|
6
|
+
* test/fixtures). It makes ONE claim and carries exactly these fields; the
|
|
7
|
+
* schema is closed, so anything else inside it fails the canonical check.
|
|
8
|
+
* v0 seller rail: the endpoint (chain-qualified `payTo` + resource URL) is
|
|
9
|
+
* bound to an accountable, verified operator — without revealing who.
|
|
10
|
+
*/
|
|
11
|
+
export type IdentityPolicy = {
|
|
12
|
+
/** What the signal claims. v0 ships seller-endpoint accountability only. */
|
|
13
|
+
claim: 'seller-endpoint-accountability';
|
|
14
|
+
/** Minimum assurance grade the attestation meets, e.g. "G". */
|
|
15
|
+
assuranceAtLeast: string;
|
|
16
|
+
/** Free verification path where any party can fetch the current signed verdict. */
|
|
17
|
+
verifyUrl: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional inline copy of the latest signed verdict, so counterparties can
|
|
20
|
+
* check the claim locally (verdict.ts#verifyVerdictSignature) without any
|
|
21
|
+
* round-trip. Refresh it on your side at the cadence the verdict itself
|
|
22
|
+
* promises; a missing or outdated copy simply degrades to "check later or
|
|
23
|
+
* show unknown".
|
|
24
|
+
*/
|
|
25
|
+
verdict?: Verdict;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The vendor's invitation to its counterparties — the trust perimeter
|
|
29
|
+
* . It is a vendor stance, not protocol, so it never rides inside
|
|
30
|
+
* `identityPolicy` (whose canonical object makes one claim only): it
|
|
31
|
+
* has its own extension key next to it. `welcome`: any agent pays as usual and
|
|
32
|
+
* attested ones are welcome; `preferred`: the vendor prefers attested
|
|
33
|
+
* counterparties — an agent's client may surface it. Neither changes the
|
|
34
|
+
* payment flow, and this snippet never enforces anything: an agent that
|
|
35
|
+
* ignores the block pays exactly as before. A vendor that REQUIRES attested
|
|
36
|
+
* agents does not express it here at all — that is the complete v1 policy
|
|
37
|
+
* (`extensions.mintid_identity`, profile `bip-0002/1`) declared by a vendor
|
|
38
|
+
* that runs its own verifier; until that line exists, required is not offered.
|
|
39
|
+
*/
|
|
40
|
+
export type PerimeterInvitation = {
|
|
41
|
+
attestation: 'welcome' | 'preferred';
|
|
42
|
+
/** Where an agent operator starts its own attestation (public page, https). */
|
|
43
|
+
attestUrl: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Minimal shape of an x402 `PaymentRequired` (HTTP 402) JSON body. The
|
|
47
|
+
* payment entries stay whatever your x402 stack produces; this snippet only
|
|
48
|
+
* touches `extensions`.
|
|
49
|
+
*/
|
|
50
|
+
export type PaymentRequiredBody = {
|
|
51
|
+
x402Version: number;
|
|
52
|
+
error?: string;
|
|
53
|
+
accepts: unknown[];
|
|
54
|
+
extensions?: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
/** Extension key defined by the bIP-0002 profile for the identity policy. */
|
|
57
|
+
export declare const IDENTITY_POLICY_EXTENSION = "identityPolicy";
|
|
58
|
+
/** The vendor-owned extension key the trust-perimeter invitation rides under. */
|
|
59
|
+
export declare const PERIMETER_EXTENSION = "trustPerimeter";
|
|
60
|
+
/**
|
|
61
|
+
* Seller side: returns a copy of the 402 body with the identity policy
|
|
62
|
+
* attached under `extensions.identityPolicy`. Existing extensions are
|
|
63
|
+
* preserved. Only the canonical fields are emitted, so the object always
|
|
64
|
+
* validates against the closed v0 seller schema whatever else the caller's
|
|
65
|
+
* policy value carried.
|
|
66
|
+
*/
|
|
67
|
+
export declare function withIdentityPolicy<T extends PaymentRequiredBody>(body: T, policy: IdentityPolicy): T;
|
|
68
|
+
/**
|
|
69
|
+
* Counterparty side: reads the identity policy from a 402 body, if present
|
|
70
|
+
* and well-formed. Returns `undefined` otherwise — an absent or malformed
|
|
71
|
+
* policy is a normal state, and the payment flow proceeds unchanged. Fields
|
|
72
|
+
* outside the canonical object are dropped, never fatal.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readIdentityPolicy(body: PaymentRequiredBody): IdentityPolicy | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Vendor side: returns a copy of the 402 body with the trust-perimeter
|
|
77
|
+
* invitation attached under its own key. `identityPolicy` is untouched.
|
|
78
|
+
*/
|
|
79
|
+
export declare function withPerimeterInvitation<T extends PaymentRequiredBody>(body: T, invitation: PerimeterInvitation): T;
|
|
80
|
+
/**
|
|
81
|
+
* Agent side: reads the vendor's invitation, if present and well-formed.
|
|
82
|
+
* Anything else — absent, malformed, or a value this line does not offer
|
|
83
|
+
* (such as "required") — reads as `undefined`, and the payment proceeds
|
|
84
|
+
* exactly as before.
|
|
85
|
+
*/
|
|
86
|
+
export declare function readPerimeterInvitation(body: PaymentRequiredBody): PerimeterInvitation | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* One entry of a v1 claim policy, byte-shaped as the frozen verifier
|
|
89
|
+
* contract's `ClaimPredicate`: a claim name, a value, an optional operator.
|
|
90
|
+
* The canonical v1 schema admits exactly the predicate family the proof core
|
|
91
|
+
* proves; nothing else validates.
|
|
92
|
+
*/
|
|
93
|
+
export type ClaimPolicyEntry = {
|
|
94
|
+
claim: string;
|
|
95
|
+
value: string | number | boolean;
|
|
96
|
+
operator?: '>=';
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The complete v1 object `extensions.mintid_identity` (profile `bip-0002/1`,
|
|
100
|
+
* MintID canonical set `canonical-2026-09-26`, restated in test/fixtures):
|
|
101
|
+
* the verifying party's challenge endpoint, the claim policy the paying
|
|
102
|
+
* party must prove, an optional issuer policy and the session mode. Policy
|
|
103
|
+
* only, never invariants — no lifetime, no nonce, no audience, no price —
|
|
104
|
+
* and closed: anything else inside it fails the canonical check.
|
|
105
|
+
*
|
|
106
|
+
* Meaning, exactly as the profile defines it: a party that pays here can
|
|
107
|
+
* prove, to the challenge endpoint's own verifier, that an accountable
|
|
108
|
+
* operator stands behind it, within the declared bounds. The seller's OWN
|
|
109
|
+
* credential is not carried on the 402 at all — the seller's holder
|
|
110
|
+
* presents it to the verification service's challenges (holder/), and the
|
|
111
|
+
* verdict on the endpoint stays readable at `identityPolicy.verifyUrl`.
|
|
112
|
+
*/
|
|
113
|
+
export type MintidIdentityPolicy = {
|
|
114
|
+
profile: 'bip-0002/1';
|
|
115
|
+
/** The verifying party's challenge front (https), resolving to its own verifier's `createChallenge`. */
|
|
116
|
+
challenge_endpoint: string;
|
|
117
|
+
claim_policy: ClaimPolicyEntry[];
|
|
118
|
+
issuer_policy?: {
|
|
119
|
+
accepted_issuer_ids?: string[];
|
|
120
|
+
issuer_state_minimum?: 'ACTIVE' | 'ENHANCED_MONITORING';
|
|
121
|
+
};
|
|
122
|
+
session_mode: 'token_exchange';
|
|
123
|
+
};
|
|
124
|
+
/** Extension key defined by the bIP-0002 profile for the complete v1 object. */
|
|
125
|
+
export declare const MINTID_IDENTITY_EXTENSION = "mintid_identity";
|
|
126
|
+
/**
|
|
127
|
+
* Returns a copy of the 402 body with the canonical v1 object attached under
|
|
128
|
+
* `extensions.mintid_identity`. Only the canonical fields are emitted (each
|
|
129
|
+
* claim entry reduced to `{claim, operator?, value}`), so the object always
|
|
130
|
+
* validates against the closed v1 schema whatever else the caller's value
|
|
131
|
+
* carried. `identityPolicy` and every other key are untouched.
|
|
132
|
+
*/
|
|
133
|
+
export declare function withMintidIdentity<T extends PaymentRequiredBody>(body: T, policy: MintidIdentityPolicy): T;
|
|
134
|
+
/**
|
|
135
|
+
* Counterparty side: reads the v1 object from a 402 body, if present and
|
|
136
|
+
* well-formed for this profile. Anything else — absent, another profile,
|
|
137
|
+
* a non-https challenge endpoint, an empty policy — reads as `undefined`,
|
|
138
|
+
* and the payment proceeds exactly as before.
|
|
139
|
+
*/
|
|
140
|
+
export declare function readMintidIdentity(body: PaymentRequiredBody): MintidIdentityPolicy | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* What a seller's middleware knows about the credential its holder keeps
|
|
143
|
+
* (holder/): the same states the operator's dashboard shows — never a key.
|
|
144
|
+
*/
|
|
145
|
+
export type CredentialState = 'none' | 'offered' | 'held' | 'expired' | 'revoked';
|
|
146
|
+
/**
|
|
147
|
+
* The seller's identity declaration during the coexistence window of the
|
|
148
|
+
* bIP-0002 profile (§3A.4): the v0 object `identityPolicy` always, and the
|
|
149
|
+
* v1 object `mintid_identity` next to it only while the seller's holder
|
|
150
|
+
* holds its credential and the seller declares a v1 policy. Both keys may
|
|
151
|
+
* coexist on one 402; a counterparty that understands v1 prefers it, one
|
|
152
|
+
* that does not pays exactly as before. A middleware without a credential
|
|
153
|
+
* emits v0 only: nothing blocks.
|
|
154
|
+
*/
|
|
155
|
+
export type SellerIdentity = {
|
|
156
|
+
/** The canonical v0 object: the verdict path on this endpoint (always emitted). */
|
|
157
|
+
policy: IdentityPolicy;
|
|
158
|
+
/** The canonical v1 object, emitted only while `credential` is `held`. */
|
|
159
|
+
v1?: MintidIdentityPolicy;
|
|
160
|
+
/** What the holder reports; anything but `held` keeps the 402 on v0 only. */
|
|
161
|
+
credential?: CredentialState;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Seller side: one call for the coexistence window. Returns a copy of the
|
|
165
|
+
* 402 body with `identityPolicy` attached and, when the credential is held
|
|
166
|
+
* and a v1 policy is declared, `mintid_identity` beside it. Neither object
|
|
167
|
+
* ever absorbs a field of the other; both stay canonical and closed.
|
|
168
|
+
*/
|
|
169
|
+
export declare function withSellerIdentity<T extends PaymentRequiredBody>(body: T, identity: SellerIdentity): T;
|