@vallum/standards 0.0.0-prerelease

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/dist/x402.js ADDED
@@ -0,0 +1,76 @@
1
+ import { mapX402PaymentRequiredToManifest, } from "@vallum/manifest";
2
+ import { evaluateAgentActionPolicy, } from "@vallum/policy-gateway";
3
+ import { createX402ExternalPaymentReceiptState, redactX402PaymentMetadata, } from "@vallum/receipts";
4
+ export function redactX402PaymentLogMetadata(input) {
5
+ return redactX402PaymentMetadata(input);
6
+ }
7
+ export async function runX402MockFacilitatorFlow(options) {
8
+ const manifest = mapX402PaymentRequiredToManifest(options.paymentRequired, {
9
+ ...options.manifestContext,
10
+ now: options.now ?? options.manifestContext.now,
11
+ });
12
+ const policyDecision = evaluateAgentActionPolicy(options.policy, manifest, { now: options.now });
13
+ if (!policyDecision.allowed)
14
+ return { approved: false, manifest, denial: policyDecision, stage: "policy" };
15
+ const accepted = options.paymentRequired.accepts.at(options.manifestContext.acceptedIndex ?? 0);
16
+ if (!accepted) {
17
+ throw new Error("x402 flow cannot start without an accepted payment requirement.");
18
+ }
19
+ const paymentId = manifest.idempotencyKey;
20
+ const paymentPayload = {
21
+ x402Version: 2,
22
+ resource: options.paymentRequired.resource,
23
+ accepted,
24
+ payload: options.paymentPayload ?? {
25
+ paymentId,
26
+ paymentSignature: "0xpayment-signature",
27
+ },
28
+ extensions: {
29
+ "payment-identifier": {
30
+ id: paymentId,
31
+ },
32
+ },
33
+ };
34
+ const facilitatorRequest = {
35
+ x402Version: 2,
36
+ paymentPayload,
37
+ paymentRequirements: accepted,
38
+ };
39
+ const verify = await options.facilitator.verify(facilitatorRequest);
40
+ if (!verify.isValid) {
41
+ const receipt = createX402ExternalPaymentReceiptState({ paymentId, verify });
42
+ return {
43
+ approved: false,
44
+ manifest,
45
+ receipt,
46
+ paymentFailure: {
47
+ stage: "verify",
48
+ reasonCode: "X402_VERIFY_FAILED",
49
+ message: verify.invalidMessage ?? verify.invalidReason ?? "x402 verification failed.",
50
+ },
51
+ logSafePaymentMetadata: redactX402PaymentLogMetadata({ paymentId, paymentPayload, verify }),
52
+ };
53
+ }
54
+ const settle = await options.facilitator.settle(facilitatorRequest);
55
+ const receipt = createX402ExternalPaymentReceiptState({ paymentId, verify, settle });
56
+ if (!settle.success) {
57
+ return {
58
+ approved: false,
59
+ manifest,
60
+ receipt,
61
+ paymentFailure: {
62
+ stage: "settle",
63
+ reasonCode: "X402_SETTLE_FAILED",
64
+ message: settle.errorMessage ?? settle.errorReason ?? "x402 settlement failed.",
65
+ },
66
+ logSafePaymentMetadata: redactX402PaymentLogMetadata({ paymentId, paymentPayload, verify, settle }),
67
+ };
68
+ }
69
+ return {
70
+ approved: true,
71
+ manifest,
72
+ receipt,
73
+ toolResult: await options.invokeTool(),
74
+ logSafePaymentMetadata: redactX402PaymentLogMetadata({ paymentId, paymentPayload, verify, settle }),
75
+ };
76
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@vallum/standards",
3
+ "version": "0.0.0-prerelease",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "license": "Apache-2.0",
14
+ "dependencies": {
15
+ "@vallum/manifest": "0.0.0-prerelease",
16
+ "@vallum/policy-gateway": "0.0.0-prerelease",
17
+ "@vallum/receipts": "0.0.0-prerelease",
18
+ "@vallum/registry": "0.0.0-prerelease"
19
+ },
20
+ "description": "Standards bridge adapters for Vallum.",
21
+ "files": [
22
+ "dist/**/*.js",
23
+ "dist/**/*.d.ts",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "sideEffects": false,
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.build.json"
30
+ },
31
+ "engines": {
32
+ "node": ">=20"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "tag": "next"
37
+ }
38
+ }