@lemmaoracle/x402 0.1.1 → 0.1.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/dist/advanced/index.d.ts +14 -0
- package/dist/advanced/index.d.ts.map +1 -0
- package/dist/advanced/index.js +14 -0
- package/dist/advanced/index.js.map +1 -0
- package/dist/index.d.ts +25 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -77
- package/dist/index.js.map +1 -1
- package/dist/lemma-config.d.ts +41 -0
- package/dist/lemma-config.d.ts.map +1 -0
- package/dist/lemma-config.js +12 -0
- package/dist/lemma-config.js.map +1 -0
- package/dist/lemma-discovery.d.ts +37 -0
- package/dist/lemma-discovery.d.ts.map +1 -0
- package/dist/lemma-discovery.js +104 -0
- package/dist/lemma-discovery.js.map +1 -0
- package/dist/lemma-server.d.ts +30 -0
- package/dist/lemma-server.d.ts.map +1 -0
- package/dist/lemma-server.js +120 -0
- package/dist/lemma-server.js.map +1 -0
- package/dist/lemma-submission.d.ts +41 -0
- package/dist/lemma-submission.d.ts.map +1 -0
- package/dist/lemma-submission.js +80 -0
- package/dist/lemma-submission.js.map +1 -0
- package/package.json +13 -13
- package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +0 -34
- package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +0 -51
- package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +0 -51
- package/broadcast/DeployPaymentVerifier.s.sol/10143/run-latest.json +0 -51
- package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +0 -7
- package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +0 -7
- package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +0 -7
- package/cache/DeployPaymentVerifier.s.sol/10143/run-latest.json +0 -7
- package/cache/solidity-files-cache.json +0 -1
- package/circuits/README.md +0 -78
- package/circuits/payment-comprehensive.test.mjs +0 -272
- package/circuits/payment.circom +0 -89
- package/circuits/payment.test.mjs +0 -173
- package/dist/proof-generator.d.ts +0 -26
- package/dist/proof-generator.d.ts.map +0 -1
- package/dist/proof-generator.js +0 -154
- package/dist/proof-generator.js.map +0 -1
- package/dist/proof-generator.test.d.ts +0 -7
- package/dist/proof-generator.test.d.ts.map +0 -1
- package/dist/proof-generator.test.js +0 -121
- package/dist/proof-generator.test.js.map +0 -1
- package/dist/transaction-watcher.d.ts +0 -42
- package/dist/transaction-watcher.d.ts.map +0 -1
- package/dist/transaction-watcher.js +0 -88
- package/dist/transaction-watcher.js.map +0 -1
- package/dist/transaction-watcher.test.d.ts +0 -7
- package/dist/transaction-watcher.test.d.ts.map +0 -1
- package/dist/transaction-watcher.test.js +0 -111
- package/dist/transaction-watcher.test.js.map +0 -1
- package/dist/types.d.ts +0 -76
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/foundry.lock +0 -11
- package/foundry.toml +0 -16
- package/lib/forge-std/.gitattributes +0 -1
- package/lib/forge-std/.github/CODEOWNERS +0 -1
- package/lib/forge-std/.github/dependabot.yml +0 -6
- package/lib/forge-std/.github/workflows/ci.yml +0 -161
- package/lib/forge-std/.github/workflows/sync.yml +0 -36
- package/lib/forge-std/CONTRIBUTING.md +0 -193
- package/lib/forge-std/LICENSE-APACHE +0 -203
- package/lib/forge-std/LICENSE-MIT +0 -25
- package/lib/forge-std/README.md +0 -314
- package/lib/forge-std/RELEASE_CHECKLIST.md +0 -12
- package/lib/forge-std/foundry.toml +0 -18
- package/lib/forge-std/package.json +0 -16
- package/lib/forge-std/scripts/vm.py +0 -636
- package/lib/forge-std/src/Base.sol +0 -48
- package/lib/forge-std/src/Config.sol +0 -60
- package/lib/forge-std/src/LibVariable.sol +0 -477
- package/lib/forge-std/src/Script.sol +0 -28
- package/lib/forge-std/src/StdAssertions.sol +0 -1300
- package/lib/forge-std/src/StdChains.sol +0 -303
- package/lib/forge-std/src/StdCheats.sol +0 -825
- package/lib/forge-std/src/StdConfig.sol +0 -632
- package/lib/forge-std/src/StdConstants.sol +0 -30
- package/lib/forge-std/src/StdError.sol +0 -15
- package/lib/forge-std/src/StdInvariant.sol +0 -161
- package/lib/forge-std/src/StdJson.sol +0 -275
- package/lib/forge-std/src/StdMath.sol +0 -47
- package/lib/forge-std/src/StdStorage.sol +0 -476
- package/lib/forge-std/src/StdStyle.sol +0 -333
- package/lib/forge-std/src/StdToml.sol +0 -275
- package/lib/forge-std/src/StdUtils.sol +0 -200
- package/lib/forge-std/src/Test.sol +0 -32
- package/lib/forge-std/src/Vm.sol +0 -2533
- package/lib/forge-std/src/console.sol +0 -1551
- package/lib/forge-std/src/console2.sol +0 -4
- package/lib/forge-std/src/interfaces/IERC1155.sol +0 -105
- package/lib/forge-std/src/interfaces/IERC165.sol +0 -12
- package/lib/forge-std/src/interfaces/IERC20.sol +0 -43
- package/lib/forge-std/src/interfaces/IERC4626.sol +0 -190
- package/lib/forge-std/src/interfaces/IERC6909.sol +0 -72
- package/lib/forge-std/src/interfaces/IERC721.sol +0 -164
- package/lib/forge-std/src/interfaces/IERC7540.sol +0 -145
- package/lib/forge-std/src/interfaces/IERC7575.sol +0 -241
- package/lib/forge-std/src/interfaces/IMulticall3.sol +0 -68
- package/lib/forge-std/src/safeconsole.sol +0 -13248
- package/lib/forge-std/test/CommonBase.t.sol +0 -44
- package/lib/forge-std/test/Config.t.sol +0 -381
- package/lib/forge-std/test/LibVariable.t.sol +0 -452
- package/lib/forge-std/test/StdAssertions.t.sol +0 -141
- package/lib/forge-std/test/StdChains.t.sol +0 -227
- package/lib/forge-std/test/StdCheats.t.sol +0 -638
- package/lib/forge-std/test/StdConstants.t.sol +0 -38
- package/lib/forge-std/test/StdError.t.sol +0 -119
- package/lib/forge-std/test/StdJson.t.sol +0 -49
- package/lib/forge-std/test/StdMath.t.sol +0 -202
- package/lib/forge-std/test/StdStorage.t.sol +0 -532
- package/lib/forge-std/test/StdStyle.t.sol +0 -110
- package/lib/forge-std/test/StdToml.t.sol +0 -49
- package/lib/forge-std/test/StdUtils.t.sol +0 -342
- package/lib/forge-std/test/Vm.t.sol +0 -18
- package/lib/forge-std/test/compilation/CompilationScript.sol +0 -8
- package/lib/forge-std/test/compilation/CompilationScriptBase.sol +0 -8
- package/lib/forge-std/test/compilation/CompilationTest.sol +0 -8
- package/lib/forge-std/test/compilation/CompilationTestBase.sol +0 -8
- package/lib/forge-std/test/fixtures/broadcast.log.json +0 -187
- package/lib/forge-std/test/fixtures/config.toml +0 -81
- package/lib/forge-std/test/fixtures/test.json +0 -8
- package/lib/forge-std/test/fixtures/test.toml +0 -6
- package/package.json.backup +0 -55
- package/scripts/DeployPaymentVerifier.s.sol +0 -18
- package/scripts/build.sh +0 -61
- package/scripts/deploy.sh +0 -65
- package/scripts/fix-verifier.mjs +0 -64
- package/scripts/register-circuit.ts +0 -213
- package/scripts/test-with-circuit.mjs +0 -88
- package/src/index.ts +0 -115
- package/src/proof-generator.test.ts +0 -139
- package/src/proof-generator.ts +0 -220
- package/src/transaction-watcher.test.ts +0 -153
- package/src/transaction-watcher.ts +0 -154
- package/src/types.ts +0 -110
- package/tsconfig.json +0 -14
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -18
- package/workers/x402-facilitator/src/index.ts +0 -582
- package/workers/x402-facilitator/src/x402-env.d.ts +0 -25
- package/workers/x402-facilitator/wrangler.toml +0 -19
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lemmaoracle/x402/advanced -- optional override hooks.
|
|
3
|
+
*
|
|
4
|
+
* Import from this path only if you need fine-grained control over:
|
|
5
|
+
* - Discovery metadata injection (configureLemmaDiscovery)
|
|
6
|
+
* - Lemma submission orchestration (createLemmaSubmissionHandler)
|
|
7
|
+
*
|
|
8
|
+
* For normal usage, import from "@lemmaoracle/x402" directly.
|
|
9
|
+
*/
|
|
10
|
+
export { resolveDiscoveryConfig } from "../lemma-discovery.js";
|
|
11
|
+
export { createLemmaSubmissionHandler } from "../lemma-submission.js";
|
|
12
|
+
export type { SubmissionContext } from "../lemma-submission.js";
|
|
13
|
+
export type { LemmaConfig, LemmaDiscoveryConfig, LemmaRouteDiscovery, } from "../lemma-config.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/advanced/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lemmaoracle/x402/advanced -- optional override hooks.
|
|
3
|
+
*
|
|
4
|
+
* Import from this path only if you need fine-grained control over:
|
|
5
|
+
* - Discovery metadata injection (configureLemmaDiscovery)
|
|
6
|
+
* - Lemma submission orchestration (createLemmaSubmissionHandler)
|
|
7
|
+
*
|
|
8
|
+
* For normal usage, import from "@lemmaoracle/x402" directly.
|
|
9
|
+
*/
|
|
10
|
+
// Discovery configuration override
|
|
11
|
+
export { resolveDiscoveryConfig } from "../lemma-discovery.js";
|
|
12
|
+
// Submission handler factory (for custom orchestration)
|
|
13
|
+
export { createLemmaSubmissionHandler } from "../lemma-submission.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/advanced/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,mCAAmC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,wDAAwD;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
import { type LemmaClient } from "@lemmaoracle/sdk";
|
|
2
|
-
import type { Config, Disclosure, Proof, Transaction, ProofResult } from "./types.js";
|
|
3
|
-
import { createProofGenerator } from "./proof-generator.js";
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
declare const disclosure: (proof: Proof) => Disclosure;
|
|
8
|
-
/**
|
|
9
|
-
* Build disclosure with empty proof for initial query (will be filled by facilitator).
|
|
10
|
-
*/
|
|
11
|
-
declare const emptyDisclosure: (circuitId: string) => Disclosure;
|
|
12
|
-
/**
|
|
13
|
-
* Create a configured facilitator client with proof generation capabilities.
|
|
2
|
+
* @lemmaoracle/x402 -- drop-in replacement for @x402/* on the resource server side.
|
|
14
3
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
4
|
+
* Re-exports the standard x402 integration surface (HTTPFacilitatorClient,
|
|
5
|
+
* x402ResourceServer, paymentMiddleware, ExactEvmScheme, x402Client), with
|
|
6
|
+
* automatic Lemma capability wired internally:
|
|
17
7
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
8
|
+
* - x402ResourceServer is subclassed: auto-attaches Lemma onAfterSettle hook
|
|
9
|
+
* that orchestrates documents.register -> prover.prove -> proofs.submit.
|
|
20
10
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
getEmptyDisclosure: (_?: undefined) => Disclosure;
|
|
33
|
-
/**
|
|
34
|
-
* Get the configuration.
|
|
35
|
-
*/
|
|
36
|
-
getConfig: (_?: undefined) => Config;
|
|
37
|
-
/**
|
|
38
|
-
* Get the Lemma client.
|
|
39
|
-
*/
|
|
40
|
-
getLemmaClient: (_?: undefined) => LemmaClient;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Default x402 facilitator configuration for Base Sepolia.
|
|
11
|
+
* - paymentMiddleware is decorated: auto-enriches routes with Lemma discovery
|
|
12
|
+
* metadata from LEMMA_DISCOVERY_CONFIG env var.
|
|
13
|
+
*
|
|
14
|
+
* Usage is identical to @x402/* -- just change the import source:
|
|
15
|
+
*
|
|
16
|
+
* import { HTTPFacilitatorClient, x402ResourceServer,
|
|
17
|
+
* paymentMiddleware, ExactEvmScheme }
|
|
18
|
+
* from "@lemmaoracle/x402";
|
|
19
|
+
*
|
|
20
|
+
* For advanced tuning (custom discovery, custom submission handler), import
|
|
21
|
+
* from "@lemmaoracle/x402/advanced".
|
|
44
22
|
*/
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
export
|
|
23
|
+
export { HTTPFacilitatorClient } from "@x402/core/server";
|
|
24
|
+
export { x402ResourceServer } from "./lemma-server.js";
|
|
25
|
+
export { paymentMiddleware } from "./lemma-discovery.js";
|
|
26
|
+
export { ExactEvmScheme } from "@x402/evm/exact/server";
|
|
27
|
+
export { x402Client } from "@x402/core/client";
|
|
28
|
+
export type { Network, PaymentRequirements, PaymentPayload } from "@x402/core/types";
|
|
29
|
+
export type { FacilitatorConfig } from "@x402/core/server";
|
|
30
|
+
export type { LemmaConfig } from "./lemma-config.js";
|
|
48
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrF,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,83 +1,31 @@
|
|
|
1
|
-
import { create } from "@lemmaoracle/sdk";
|
|
2
|
-
import * as R from "ramda";
|
|
3
|
-
import { createProofGenerator } from "./proof-generator.js";
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
const createLemmaClient = (config) => create({
|
|
8
|
-
apiBase: config.lemmaApiBase,
|
|
9
|
-
apiKey: config.lemmaApiKey,
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Build a disclosure object from a proof.
|
|
13
|
-
*/
|
|
14
|
-
const disclosure = (proof) => ({
|
|
15
|
-
condition: { circuitId: proof.circuitId },
|
|
16
|
-
proof: proof.proof,
|
|
17
|
-
inputs: proof.inputs,
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Build disclosure with empty proof for initial query (will be filled by facilitator).
|
|
21
|
-
*/
|
|
22
|
-
const emptyDisclosure = (circuitId) => ({
|
|
23
|
-
condition: { circuitId },
|
|
24
|
-
proof: "",
|
|
25
|
-
inputs: [],
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Create a configured facilitator client with proof generation capabilities.
|
|
2
|
+
* @lemmaoracle/x402 -- drop-in replacement for @x402/* on the resource server side.
|
|
29
3
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
4
|
+
* Re-exports the standard x402 integration surface (HTTPFacilitatorClient,
|
|
5
|
+
* x402ResourceServer, paymentMiddleware, ExactEvmScheme, x402Client), with
|
|
6
|
+
* automatic Lemma capability wired internally:
|
|
32
7
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
8
|
+
* - x402ResourceServer is subclassed: auto-attaches Lemma onAfterSettle hook
|
|
9
|
+
* that orchestrates documents.register -> prover.prove -> proofs.submit.
|
|
35
10
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const { proof } = await proofGenerator.generateProof(txHash);
|
|
48
|
-
return disclosure(proof);
|
|
49
|
-
},
|
|
50
|
-
/**
|
|
51
|
-
* Get an empty disclosure template with condition for the configured circuit.
|
|
52
|
-
*/
|
|
53
|
-
getEmptyDisclosure: (_) => emptyDisclosure(config.circuitId),
|
|
54
|
-
/**
|
|
55
|
-
* Get the configuration.
|
|
56
|
-
*/
|
|
57
|
-
getConfig: (_) => config,
|
|
58
|
-
/**
|
|
59
|
-
* Get the Lemma client.
|
|
60
|
-
*/
|
|
61
|
-
getLemmaClient: (_) => lemmaClient,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Default x402 facilitator configuration for Base Sepolia.
|
|
11
|
+
* - paymentMiddleware is decorated: auto-enriches routes with Lemma discovery
|
|
12
|
+
* metadata from LEMMA_DISCOVERY_CONFIG env var.
|
|
13
|
+
*
|
|
14
|
+
* Usage is identical to @x402/* -- just change the import source:
|
|
15
|
+
*
|
|
16
|
+
* import { HTTPFacilitatorClient, x402ResourceServer,
|
|
17
|
+
* paymentMiddleware, ExactEvmScheme }
|
|
18
|
+
* from "@lemmaoracle/x402";
|
|
19
|
+
*
|
|
20
|
+
* For advanced tuning (custom discovery, custom submission handler), import
|
|
21
|
+
* from "@lemmaoracle/x402/advanced".
|
|
66
22
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
minAmount: 1000n, // $0.001 USDC in smallest units (6 decimals)
|
|
76
|
-
requiredConfirmations: 6,
|
|
77
|
-
maxProofAge: 3600, // 1 hour
|
|
78
|
-
ipfsGateway: "https://ipfs.io/ipfs/",
|
|
79
|
-
}, overrides);
|
|
80
|
-
export { facilitator, createProofGenerator, disclosure, emptyDisclosure, defaultConfig,
|
|
81
|
-
// createLemmaClient is not exported
|
|
82
|
-
};
|
|
23
|
+
// Re-exports from @x402 (x402-compatible surface)
|
|
24
|
+
export { HTTPFacilitatorClient } from "@x402/core/server";
|
|
25
|
+
// Augmented versions (identical public API, internal Lemma wiring)
|
|
26
|
+
export { x402ResourceServer } from "./lemma-server.js";
|
|
27
|
+
export { paymentMiddleware } from "./lemma-discovery.js";
|
|
28
|
+
// Additional x402 re-exports
|
|
29
|
+
export { ExactEvmScheme } from "@x402/evm/exact/server";
|
|
30
|
+
export { x402Client } from "@x402/core/client";
|
|
83
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kDAAkD;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,mEAAmE;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,6BAA6B;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LemmaConfig -- configuration types for Lemma-x402 integration.
|
|
3
|
+
*
|
|
4
|
+
* Supports two injection paths:
|
|
5
|
+
* 1. Env-based: LEMMA_CONFIG env var (JSON string)
|
|
6
|
+
* 2. Explicit: passed directly to augmented x402ResourceServer constructor
|
|
7
|
+
*
|
|
8
|
+
* The augmented x402ResourceServer reads from explicit config first,
|
|
9
|
+
* falling back to LEMMA_CONFIG env var if no explicit config is provided.
|
|
10
|
+
*/
|
|
11
|
+
/** Per-route discovery metadata applied to x402 route accepts[].extra. */
|
|
12
|
+
type LemmaRouteDiscovery = Readonly<{
|
|
13
|
+
/** Schemas this route exposes for discovery */
|
|
14
|
+
schemas?: ReadonlyArray<string>;
|
|
15
|
+
/** Hints passed in the discovery extension (e.g. verifiable attributes) */
|
|
16
|
+
hints?: Readonly<Record<string, unknown>>;
|
|
17
|
+
}>;
|
|
18
|
+
/** Global + per-route discovery configuration for auto-enrichment. */
|
|
19
|
+
type LemmaDiscoveryConfig = Readonly<{
|
|
20
|
+
/** Global schema info applied to all routes */
|
|
21
|
+
schemas?: ReadonlyArray<string>;
|
|
22
|
+
/** Global hints applied to all routes */
|
|
23
|
+
hints?: Readonly<Record<string, unknown>>;
|
|
24
|
+
/** Per-route overrides (keyed by route path pattern, e.g. "GET /verify/:hash") */
|
|
25
|
+
routes?: Readonly<Record<string, LemmaRouteDiscovery>>;
|
|
26
|
+
}>;
|
|
27
|
+
/** Configuration for Lemma-x402 integration. */
|
|
28
|
+
type LemmaConfig = Readonly<{
|
|
29
|
+
/** Lemma API base URL (e.g. "https://workers.lemma.workers.dev") */
|
|
30
|
+
apiBase: string;
|
|
31
|
+
/** Lemma API key (optional) */
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
/** Circuit ID used for proof generation */
|
|
34
|
+
circuitId: string;
|
|
35
|
+
/** Relay URL for prover.prove (runs on Node.js, not Workers) */
|
|
36
|
+
relayUrl?: string;
|
|
37
|
+
/** Discovery configuration for auto-enriching x402 routes */
|
|
38
|
+
discovery?: LemmaDiscoveryConfig;
|
|
39
|
+
}>;
|
|
40
|
+
export type { LemmaConfig, LemmaDiscoveryConfig, LemmaRouteDiscovery, };
|
|
41
|
+
//# sourceMappingURL=lemma-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-config.d.ts","sourceRoot":"","sources":["../src/lemma-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,0EAA0E;AAC1E,KAAK,mBAAmB,GAAG,QAAQ,CAAC;IAClC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChC,2EAA2E;IAC3E,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC3C,CAAC,CAAC;AAEH,sEAAsE;AACtE,KAAK,oBAAoB,GAAG,QAAQ,CAAC;IACnC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChC,yCAAyC;IACzC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,kFAAkF;IAClF,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;CACxD,CAAC,CAAC;AAEH,gDAAgD;AAChD,KAAK,WAAW,GAAG,QAAQ,CAAC;IAC1B,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC,CAAC,CAAC;AAEH,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LemmaConfig -- configuration types for Lemma-x402 integration.
|
|
3
|
+
*
|
|
4
|
+
* Supports two injection paths:
|
|
5
|
+
* 1. Env-based: LEMMA_CONFIG env var (JSON string)
|
|
6
|
+
* 2. Explicit: passed directly to augmented x402ResourceServer constructor
|
|
7
|
+
*
|
|
8
|
+
* The augmented x402ResourceServer reads from explicit config first,
|
|
9
|
+
* falling back to LEMMA_CONFIG env var if no explicit config is provided.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=lemma-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-config.js","sourceRoot":"","sources":["../src/lemma-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmented paymentMiddleware -- decorates the original middleware with
|
|
3
|
+
* automatic Lemma discovery metadata enrichment.
|
|
4
|
+
*
|
|
5
|
+
* Re-exported from root as paymentMiddleware. Same function signature as
|
|
6
|
+
* the original from @x402/hono. Before delegating to the real middleware,
|
|
7
|
+
* it enriches each route's .accepts[].extra with Lemma discovery metadata.
|
|
8
|
+
*
|
|
9
|
+
* Discovery metadata is resolved from:
|
|
10
|
+
* 1. LEMMA_DISCOVERY_CONFIG env var (JSON string)
|
|
11
|
+
* 2. LEMMA_CONFIG env var (JSON string) -- discovery field
|
|
12
|
+
* 3. Explicit discovery config (if provided)
|
|
13
|
+
*/
|
|
14
|
+
import type { PaywallConfig, PaywallProvider } from "@x402/hono";
|
|
15
|
+
import type { x402ResourceServer, RoutesConfig } from "@x402/core/server";
|
|
16
|
+
import type { MiddlewareHandler } from "hono";
|
|
17
|
+
import type { LemmaDiscoveryConfig } from "./lemma-config.js";
|
|
18
|
+
/** Resolve discovery config from env. */
|
|
19
|
+
declare const resolveDiscoveryConfig: () => LemmaDiscoveryConfig | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Augmented paymentMiddleware.
|
|
22
|
+
*
|
|
23
|
+
* Enriches routes with Lemma discovery metadata before delegating to the
|
|
24
|
+
* real middleware. Signature is identical to the original:
|
|
25
|
+
*
|
|
26
|
+
* paymentMiddleware(
|
|
27
|
+
* routes: RoutesConfig,
|
|
28
|
+
* server: x402ResourceServer,
|
|
29
|
+
* paywallConfig?: PaywallConfig,
|
|
30
|
+
* paywall?: PaywallProvider,
|
|
31
|
+
* syncFacilitatorOnStart?: boolean,
|
|
32
|
+
* ): MiddlewareHandler
|
|
33
|
+
*/
|
|
34
|
+
declare const paymentMiddleware: (routes: RoutesConfig, server: x402ResourceServer, paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean) => MiddlewareHandler;
|
|
35
|
+
export { paymentMiddleware };
|
|
36
|
+
export { resolveDiscoveryConfig };
|
|
37
|
+
//# sourceMappingURL=lemma-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-discovery.d.ts","sourceRoot":"","sources":["../src/lemma-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EACV,oBAAoB,EAErB,MAAM,mBAAmB,CAAC;AAE3B,yCAAyC;AACzC,QAAA,MAAM,sBAAsB,QAAO,oBAAoB,GAAG,SAgCzD,CAAC;AAyBF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,iBAAiB,GACrB,QAAQ,YAAY,EACpB,QAAQ,kBAAkB,EAC1B,gBAAgB,aAAa,EAC7B,UAAU,eAAe,EACzB,yBAAyB,OAAO,KAC/B,iBAuDF,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmented paymentMiddleware -- decorates the original middleware with
|
|
3
|
+
* automatic Lemma discovery metadata enrichment.
|
|
4
|
+
*
|
|
5
|
+
* Re-exported from root as paymentMiddleware. Same function signature as
|
|
6
|
+
* the original from @x402/hono. Before delegating to the real middleware,
|
|
7
|
+
* it enriches each route's .accepts[].extra with Lemma discovery metadata.
|
|
8
|
+
*
|
|
9
|
+
* Discovery metadata is resolved from:
|
|
10
|
+
* 1. LEMMA_DISCOVERY_CONFIG env var (JSON string)
|
|
11
|
+
* 2. LEMMA_CONFIG env var (JSON string) -- discovery field
|
|
12
|
+
* 3. Explicit discovery config (if provided)
|
|
13
|
+
*/
|
|
14
|
+
import { paymentMiddleware as basePaymentMiddleware } from "@x402/hono";
|
|
15
|
+
/** Resolve discovery config from env. */
|
|
16
|
+
const resolveDiscoveryConfig = () => {
|
|
17
|
+
const raw = typeof process !== "undefined"
|
|
18
|
+
? (process.env.LEMMA_DISCOVERY_CONFIG ?? process.env.LEMMA_CONFIG)
|
|
19
|
+
: undefined;
|
|
20
|
+
return !raw
|
|
21
|
+
? undefined
|
|
22
|
+
: (() => {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(raw);
|
|
25
|
+
// If LEMMA_CONFIG, extract discovery sub-object; otherwise use root
|
|
26
|
+
const discovery = (parsed.discovery ?? parsed);
|
|
27
|
+
return discovery.schemas || discovery.hints || discovery.routes
|
|
28
|
+
? ({
|
|
29
|
+
schemas: discovery.schemas,
|
|
30
|
+
hints: discovery.hints,
|
|
31
|
+
routes: discovery.routes,
|
|
32
|
+
})
|
|
33
|
+
: undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
};
|
|
40
|
+
/** Merge global discovery config with per-route overrides. */
|
|
41
|
+
const discoveryForRoute = (routePattern, config) => {
|
|
42
|
+
if (!config)
|
|
43
|
+
return undefined;
|
|
44
|
+
const global = {
|
|
45
|
+
...(config.schemas ? { schemas: config.schemas } : {}),
|
|
46
|
+
...(config.hints ?? {}),
|
|
47
|
+
};
|
|
48
|
+
const perRoute = config.routes?.[routePattern];
|
|
49
|
+
const merged = {
|
|
50
|
+
...global,
|
|
51
|
+
...(perRoute?.schemas ? { schemas: perRoute.schemas } : {}),
|
|
52
|
+
...(perRoute?.hints ?? {}),
|
|
53
|
+
};
|
|
54
|
+
return Object.keys(merged).length > 0 ? merged : undefined;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Augmented paymentMiddleware.
|
|
58
|
+
*
|
|
59
|
+
* Enriches routes with Lemma discovery metadata before delegating to the
|
|
60
|
+
* real middleware. Signature is identical to the original:
|
|
61
|
+
*
|
|
62
|
+
* paymentMiddleware(
|
|
63
|
+
* routes: RoutesConfig,
|
|
64
|
+
* server: x402ResourceServer,
|
|
65
|
+
* paywallConfig?: PaywallConfig,
|
|
66
|
+
* paywall?: PaywallProvider,
|
|
67
|
+
* syncFacilitatorOnStart?: boolean,
|
|
68
|
+
* ): MiddlewareHandler
|
|
69
|
+
*/
|
|
70
|
+
const paymentMiddleware = (routes, server, paywallConfig, paywall, syncFacilitatorOnStart) => {
|
|
71
|
+
const discoveryConfig = resolveDiscoveryConfig();
|
|
72
|
+
// If no discovery config, delegate directly (no enrichment)
|
|
73
|
+
if (!discoveryConfig) {
|
|
74
|
+
return basePaymentMiddleware(routes, server, paywallConfig, paywall, syncFacilitatorOnStart);
|
|
75
|
+
}
|
|
76
|
+
// Enrich each route with discovery metadata
|
|
77
|
+
const enrichedRoutes = {};
|
|
78
|
+
const routeKeys = Object.keys(routes);
|
|
79
|
+
for (const routePattern of routeKeys) {
|
|
80
|
+
const routeConfig = routes[routePattern];
|
|
81
|
+
const discovery = discoveryForRoute(routePattern, discoveryConfig);
|
|
82
|
+
const enrichedRouteConfig = discovery
|
|
83
|
+
? {
|
|
84
|
+
...routeConfig,
|
|
85
|
+
accepts: (routeConfig?.accepts ??
|
|
86
|
+
[]).map((accept) => ({
|
|
87
|
+
...accept,
|
|
88
|
+
extra: {
|
|
89
|
+
...(accept?.extra ?? {}),
|
|
90
|
+
lemma: {
|
|
91
|
+
...(accept?.extra?.lemma ?? {}),
|
|
92
|
+
...discovery,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
})),
|
|
96
|
+
}
|
|
97
|
+
: routeConfig;
|
|
98
|
+
enrichedRoutes[routePattern] = enrichedRouteConfig;
|
|
99
|
+
}
|
|
100
|
+
return basePaymentMiddleware(enrichedRoutes, server, paywallConfig, paywall, syncFacilitatorOnStart);
|
|
101
|
+
};
|
|
102
|
+
export { paymentMiddleware };
|
|
103
|
+
export { resolveDiscoveryConfig };
|
|
104
|
+
//# sourceMappingURL=lemma-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-discovery.js","sourceRoot":"","sources":["../src/lemma-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAC;AASxE,yCAAyC;AACzC,MAAM,sBAAsB,GAAG,GAAqC,EAAE;IACpE,MAAM,GAAG,GACP,OAAO,OAAO,KAAK,WAAW;QAC5B,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;QAClE,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO,CAAC,GAAG;QACT,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,IAAI,CAAC;gBACH,MAA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ED,OAAO,qBAAqB,CAC1B,cAA8B,EAC9B,MAAM,EACN,aAAa,EACb,OAAO,EACP,sBAAsB,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmented x402ResourceServer -- subclass of the original with automatic
|
|
3
|
+
* Lemma hook wiring.
|
|
4
|
+
*
|
|
5
|
+
* Re-exported from root as x402ResourceServer. Users instantiate it identically
|
|
6
|
+
* to the original: new x402ResourceServer(facilitatorClient). The Lemma
|
|
7
|
+
* onAfterSettle hook is auto-attached in the constructor.
|
|
8
|
+
*
|
|
9
|
+
* Config is resolved from:
|
|
10
|
+
* 1. Explicit LemmaConfig passed as second constructor argument
|
|
11
|
+
* 2. LEMMA_CONFIG env var (JSON string)
|
|
12
|
+
* 3. Individual env vars: LEMMA_API_BASE, LEMMA_API_KEY, LEMMA_CIRCUIT_ID, LEMMA_RELAY_URL
|
|
13
|
+
*/
|
|
14
|
+
import { x402ResourceServer as BaseResourceServer } from "@x402/core/server";
|
|
15
|
+
import type { FacilitatorClient } from "@x402/core/server";
|
|
16
|
+
import type { LemmaConfig } from "./lemma-config.js";
|
|
17
|
+
/**
|
|
18
|
+
* Augmented version of x402ResourceServer.
|
|
19
|
+
*
|
|
20
|
+
* Subclasses the original to auto-attach Lemma hooks. The subclass does NOT
|
|
21
|
+
* change the public API -- it only adds internal wiring in the constructor.
|
|
22
|
+
*
|
|
23
|
+
* @param facilitatorClient - x402 facilitator client(s)
|
|
24
|
+
* @param lemmaConfig - Optional explicit Lemma configuration
|
|
25
|
+
*/
|
|
26
|
+
declare class LemmaResourceServer extends BaseResourceServer {
|
|
27
|
+
constructor(facilitatorClient?: FacilitatorClient | FacilitatorClient[], lemmaConfig?: LemmaConfig);
|
|
28
|
+
}
|
|
29
|
+
export { LemmaResourceServer as x402ResourceServer };
|
|
30
|
+
//# sourceMappingURL=lemma-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-server.d.ts","sourceRoot":"","sources":["../src/lemma-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,IAAI,kBAAkB,EACzC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8DrD;;;;;;;;GAQG;AACH,cAAM,mBAAoB,SAAQ,kBAAkB;gBAEhD,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,EAC3D,WAAW,CAAC,EAAE,WAAW;CAqD5B;AAED,OAAO,EAAE,mBAAmB,IAAI,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmented x402ResourceServer -- subclass of the original with automatic
|
|
3
|
+
* Lemma hook wiring.
|
|
4
|
+
*
|
|
5
|
+
* Re-exported from root as x402ResourceServer. Users instantiate it identically
|
|
6
|
+
* to the original: new x402ResourceServer(facilitatorClient). The Lemma
|
|
7
|
+
* onAfterSettle hook is auto-attached in the constructor.
|
|
8
|
+
*
|
|
9
|
+
* Config is resolved from:
|
|
10
|
+
* 1. Explicit LemmaConfig passed as second constructor argument
|
|
11
|
+
* 2. LEMMA_CONFIG env var (JSON string)
|
|
12
|
+
* 3. Individual env vars: LEMMA_API_BASE, LEMMA_API_KEY, LEMMA_CIRCUIT_ID, LEMMA_RELAY_URL
|
|
13
|
+
*/
|
|
14
|
+
import { x402ResourceServer as BaseResourceServer, } from "@x402/core/server";
|
|
15
|
+
import { createLemmaSubmissionHandler } from "./lemma-submission.js";
|
|
16
|
+
/**
|
|
17
|
+
* Resolve LemmaConfig from available sources.
|
|
18
|
+
*
|
|
19
|
+
* Priority: explicit config -> LEMMA_CONFIG env JSON -> individual env vars.
|
|
20
|
+
*/
|
|
21
|
+
const resolveLemmaConfig = (explicit) => {
|
|
22
|
+
const fromExplicit = explicit;
|
|
23
|
+
const fromEnv = resolveFromEnv();
|
|
24
|
+
return fromExplicit ?? fromEnv;
|
|
25
|
+
};
|
|
26
|
+
/** Read LEMMA_CONFIG env var as JSON and parse it. */
|
|
27
|
+
const resolveFromEnv = () => {
|
|
28
|
+
const raw = typeof process !== "undefined"
|
|
29
|
+
? process.env.LEMMA_CONFIG
|
|
30
|
+
: undefined;
|
|
31
|
+
const jsonStr = raw;
|
|
32
|
+
return !jsonStr
|
|
33
|
+
? resolveFromIndividualEnvVars()
|
|
34
|
+
: (() => {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(jsonStr);
|
|
37
|
+
const apiBase = parsed.apiBase;
|
|
38
|
+
return apiBase
|
|
39
|
+
? ({
|
|
40
|
+
apiBase,
|
|
41
|
+
apiKey: parsed.apiKey,
|
|
42
|
+
circuitId: parsed.circuitId ?? "x402-payment-v1",
|
|
43
|
+
relayUrl: parsed.relayUrl,
|
|
44
|
+
discovery: parsed.discovery,
|
|
45
|
+
})
|
|
46
|
+
: resolveFromIndividualEnvVars();
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return resolveFromIndividualEnvVars();
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
};
|
|
53
|
+
/** Fallback to individual env vars. */
|
|
54
|
+
const resolveFromIndividualEnvVars = () => {
|
|
55
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
56
|
+
const apiBase = env.LEMMA_API_BASE;
|
|
57
|
+
return apiBase
|
|
58
|
+
? {
|
|
59
|
+
apiBase,
|
|
60
|
+
apiKey: env.LEMMA_API_KEY,
|
|
61
|
+
circuitId: env.LEMMA_CIRCUIT_ID ?? "x402-payment-v1",
|
|
62
|
+
relayUrl: env.LEMMA_RELAY_URL,
|
|
63
|
+
}
|
|
64
|
+
: undefined;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Augmented version of x402ResourceServer.
|
|
68
|
+
*
|
|
69
|
+
* Subclasses the original to auto-attach Lemma hooks. The subclass does NOT
|
|
70
|
+
* change the public API -- it only adds internal wiring in the constructor.
|
|
71
|
+
*
|
|
72
|
+
* @param facilitatorClient - x402 facilitator client(s)
|
|
73
|
+
* @param lemmaConfig - Optional explicit Lemma configuration
|
|
74
|
+
*/
|
|
75
|
+
class LemmaResourceServer extends BaseResourceServer {
|
|
76
|
+
constructor(facilitatorClient, lemmaConfig) {
|
|
77
|
+
super(facilitatorClient);
|
|
78
|
+
const config = resolveLemmaConfig(lemmaConfig);
|
|
79
|
+
// No Lemma config available -- skip wiring (fallback: delegate to base class only)
|
|
80
|
+
if (!config)
|
|
81
|
+
return;
|
|
82
|
+
const submissionHandler = createLemmaSubmissionHandler(config);
|
|
83
|
+
// Auto-attach the Lemma submission hook via onAfterSettle
|
|
84
|
+
const lemmaAfterSettle = async (context) => {
|
|
85
|
+
try {
|
|
86
|
+
const settlementResult = context.result;
|
|
87
|
+
// Build submission context from settlement data
|
|
88
|
+
const docHash = context.requirements.extra?.docHash ??
|
|
89
|
+
settlementResult.transaction ??
|
|
90
|
+
"unknown";
|
|
91
|
+
const schema = context.requirements.extra?.schema ??
|
|
92
|
+
"default";
|
|
93
|
+
// Extract payment details for proof witness
|
|
94
|
+
const witness = {
|
|
95
|
+
amount: context.requirements.amount ?? "1000",
|
|
96
|
+
docHash,
|
|
97
|
+
transaction: settlementResult.transaction,
|
|
98
|
+
};
|
|
99
|
+
await submissionHandler({
|
|
100
|
+
docHash,
|
|
101
|
+
schema: String(schema),
|
|
102
|
+
issuerId: "lemma-x402",
|
|
103
|
+
witness,
|
|
104
|
+
metadata: {
|
|
105
|
+
payer: settlementResult.payer,
|
|
106
|
+
transaction: settlementResult.transaction,
|
|
107
|
+
network: settlementResult.network,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
// Submission errors are non-fatal -- the settlement succeeded.
|
|
113
|
+
console.error("[Lemma] Submission handler error:", err);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
this.onAfterSettle(lemmaAfterSettle);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export { LemmaResourceServer as x402ResourceServer };
|
|
120
|
+
//# sourceMappingURL=lemma-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemma-server.js","sourceRoot":"","sources":["../src/lemma-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,IAAI,kBAAkB,GACzC,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CACzB,QAAsB,EACG,EAAE;IAC3B,MAAM,YAAY,GAAG,QAAQ,CAAC;IAC9B,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,OAAO,YAAY,IAAI,OAAO,CAAC;AACjC,CAAC,CAAC;AAEF,sDAAsD;AACtD,MAAM,cAAc,GAAG,GAA4B,EAAE;IACnD,MAAM,GAAG,GACP,OAAO,OAAO,KAAK,WAAW;QAC5B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY;QAC1B,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,OAAO,GAAG,GAAG,CAAC;IAEpB,OAAO,CAAC,OAAO;QACb,CAAC,CAAC,4BAA4B,EAAE;QAChC,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAA4B,CAAC;gBAC9D,MAAM,OAAO,GAAG,MAAM,CAAC,OAA6B,CAAC;gBACrD,OAAO,OAAO;oBACZ,CAAC,CAAC,CAAC;wBACC,OAAO;wBACP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