@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.
Files changed (146) hide show
  1. package/dist/advanced/index.d.ts +14 -0
  2. package/dist/advanced/index.d.ts.map +1 -0
  3. package/dist/advanced/index.js +14 -0
  4. package/dist/advanced/index.js.map +1 -0
  5. package/dist/index.d.ts +25 -42
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +25 -77
  8. package/dist/index.js.map +1 -1
  9. package/dist/lemma-config.d.ts +41 -0
  10. package/dist/lemma-config.d.ts.map +1 -0
  11. package/dist/lemma-config.js +12 -0
  12. package/dist/lemma-config.js.map +1 -0
  13. package/dist/lemma-discovery.d.ts +37 -0
  14. package/dist/lemma-discovery.d.ts.map +1 -0
  15. package/dist/lemma-discovery.js +104 -0
  16. package/dist/lemma-discovery.js.map +1 -0
  17. package/dist/lemma-server.d.ts +30 -0
  18. package/dist/lemma-server.d.ts.map +1 -0
  19. package/dist/lemma-server.js +120 -0
  20. package/dist/lemma-server.js.map +1 -0
  21. package/dist/lemma-submission.d.ts +41 -0
  22. package/dist/lemma-submission.d.ts.map +1 -0
  23. package/dist/lemma-submission.js +80 -0
  24. package/dist/lemma-submission.js.map +1 -0
  25. package/package.json +13 -13
  26. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +0 -34
  27. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +0 -51
  28. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +0 -51
  29. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-latest.json +0 -51
  30. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +0 -7
  31. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +0 -7
  32. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +0 -7
  33. package/cache/DeployPaymentVerifier.s.sol/10143/run-latest.json +0 -7
  34. package/cache/solidity-files-cache.json +0 -1
  35. package/circuits/README.md +0 -78
  36. package/circuits/payment-comprehensive.test.mjs +0 -272
  37. package/circuits/payment.circom +0 -89
  38. package/circuits/payment.test.mjs +0 -173
  39. package/dist/proof-generator.d.ts +0 -26
  40. package/dist/proof-generator.d.ts.map +0 -1
  41. package/dist/proof-generator.js +0 -154
  42. package/dist/proof-generator.js.map +0 -1
  43. package/dist/proof-generator.test.d.ts +0 -7
  44. package/dist/proof-generator.test.d.ts.map +0 -1
  45. package/dist/proof-generator.test.js +0 -121
  46. package/dist/proof-generator.test.js.map +0 -1
  47. package/dist/transaction-watcher.d.ts +0 -42
  48. package/dist/transaction-watcher.d.ts.map +0 -1
  49. package/dist/transaction-watcher.js +0 -88
  50. package/dist/transaction-watcher.js.map +0 -1
  51. package/dist/transaction-watcher.test.d.ts +0 -7
  52. package/dist/transaction-watcher.test.d.ts.map +0 -1
  53. package/dist/transaction-watcher.test.js +0 -111
  54. package/dist/transaction-watcher.test.js.map +0 -1
  55. package/dist/types.d.ts +0 -76
  56. package/dist/types.d.ts.map +0 -1
  57. package/dist/types.js +0 -2
  58. package/dist/types.js.map +0 -1
  59. package/foundry.lock +0 -11
  60. package/foundry.toml +0 -16
  61. package/lib/forge-std/.gitattributes +0 -1
  62. package/lib/forge-std/.github/CODEOWNERS +0 -1
  63. package/lib/forge-std/.github/dependabot.yml +0 -6
  64. package/lib/forge-std/.github/workflows/ci.yml +0 -161
  65. package/lib/forge-std/.github/workflows/sync.yml +0 -36
  66. package/lib/forge-std/CONTRIBUTING.md +0 -193
  67. package/lib/forge-std/LICENSE-APACHE +0 -203
  68. package/lib/forge-std/LICENSE-MIT +0 -25
  69. package/lib/forge-std/README.md +0 -314
  70. package/lib/forge-std/RELEASE_CHECKLIST.md +0 -12
  71. package/lib/forge-std/foundry.toml +0 -18
  72. package/lib/forge-std/package.json +0 -16
  73. package/lib/forge-std/scripts/vm.py +0 -636
  74. package/lib/forge-std/src/Base.sol +0 -48
  75. package/lib/forge-std/src/Config.sol +0 -60
  76. package/lib/forge-std/src/LibVariable.sol +0 -477
  77. package/lib/forge-std/src/Script.sol +0 -28
  78. package/lib/forge-std/src/StdAssertions.sol +0 -1300
  79. package/lib/forge-std/src/StdChains.sol +0 -303
  80. package/lib/forge-std/src/StdCheats.sol +0 -825
  81. package/lib/forge-std/src/StdConfig.sol +0 -632
  82. package/lib/forge-std/src/StdConstants.sol +0 -30
  83. package/lib/forge-std/src/StdError.sol +0 -15
  84. package/lib/forge-std/src/StdInvariant.sol +0 -161
  85. package/lib/forge-std/src/StdJson.sol +0 -275
  86. package/lib/forge-std/src/StdMath.sol +0 -47
  87. package/lib/forge-std/src/StdStorage.sol +0 -476
  88. package/lib/forge-std/src/StdStyle.sol +0 -333
  89. package/lib/forge-std/src/StdToml.sol +0 -275
  90. package/lib/forge-std/src/StdUtils.sol +0 -200
  91. package/lib/forge-std/src/Test.sol +0 -32
  92. package/lib/forge-std/src/Vm.sol +0 -2533
  93. package/lib/forge-std/src/console.sol +0 -1551
  94. package/lib/forge-std/src/console2.sol +0 -4
  95. package/lib/forge-std/src/interfaces/IERC1155.sol +0 -105
  96. package/lib/forge-std/src/interfaces/IERC165.sol +0 -12
  97. package/lib/forge-std/src/interfaces/IERC20.sol +0 -43
  98. package/lib/forge-std/src/interfaces/IERC4626.sol +0 -190
  99. package/lib/forge-std/src/interfaces/IERC6909.sol +0 -72
  100. package/lib/forge-std/src/interfaces/IERC721.sol +0 -164
  101. package/lib/forge-std/src/interfaces/IERC7540.sol +0 -145
  102. package/lib/forge-std/src/interfaces/IERC7575.sol +0 -241
  103. package/lib/forge-std/src/interfaces/IMulticall3.sol +0 -68
  104. package/lib/forge-std/src/safeconsole.sol +0 -13248
  105. package/lib/forge-std/test/CommonBase.t.sol +0 -44
  106. package/lib/forge-std/test/Config.t.sol +0 -381
  107. package/lib/forge-std/test/LibVariable.t.sol +0 -452
  108. package/lib/forge-std/test/StdAssertions.t.sol +0 -141
  109. package/lib/forge-std/test/StdChains.t.sol +0 -227
  110. package/lib/forge-std/test/StdCheats.t.sol +0 -638
  111. package/lib/forge-std/test/StdConstants.t.sol +0 -38
  112. package/lib/forge-std/test/StdError.t.sol +0 -119
  113. package/lib/forge-std/test/StdJson.t.sol +0 -49
  114. package/lib/forge-std/test/StdMath.t.sol +0 -202
  115. package/lib/forge-std/test/StdStorage.t.sol +0 -532
  116. package/lib/forge-std/test/StdStyle.t.sol +0 -110
  117. package/lib/forge-std/test/StdToml.t.sol +0 -49
  118. package/lib/forge-std/test/StdUtils.t.sol +0 -342
  119. package/lib/forge-std/test/Vm.t.sol +0 -18
  120. package/lib/forge-std/test/compilation/CompilationScript.sol +0 -8
  121. package/lib/forge-std/test/compilation/CompilationScriptBase.sol +0 -8
  122. package/lib/forge-std/test/compilation/CompilationTest.sol +0 -8
  123. package/lib/forge-std/test/compilation/CompilationTestBase.sol +0 -8
  124. package/lib/forge-std/test/fixtures/broadcast.log.json +0 -187
  125. package/lib/forge-std/test/fixtures/config.toml +0 -81
  126. package/lib/forge-std/test/fixtures/test.json +0 -8
  127. package/lib/forge-std/test/fixtures/test.toml +0 -6
  128. package/package.json.backup +0 -55
  129. package/scripts/DeployPaymentVerifier.s.sol +0 -18
  130. package/scripts/build.sh +0 -61
  131. package/scripts/deploy.sh +0 -65
  132. package/scripts/fix-verifier.mjs +0 -64
  133. package/scripts/register-circuit.ts +0 -213
  134. package/scripts/test-with-circuit.mjs +0 -88
  135. package/src/index.ts +0 -115
  136. package/src/proof-generator.test.ts +0 -139
  137. package/src/proof-generator.ts +0 -220
  138. package/src/transaction-watcher.test.ts +0 -153
  139. package/src/transaction-watcher.ts +0 -154
  140. package/src/types.ts +0 -110
  141. package/tsconfig.json +0 -14
  142. package/tsconfig.tsbuildinfo +0 -1
  143. package/vitest.config.ts +0 -18
  144. package/workers/x402-facilitator/src/index.ts +0 -582
  145. package/workers/x402-facilitator/src/x402-env.d.ts +0 -25
  146. package/workers/x402-facilitator/wrangler.toml +0 -19
@@ -1,154 +0,0 @@
1
- /**
2
- * X402 Transaction Watcher
3
- *
4
- * Monitors the blockchain for x402 payment transactions to the configured
5
- * recipient address and triggers proof generation when payments are detected.
6
- */
7
-
8
- import type {
9
- Transaction as ViemTransaction,
10
- TransactionReceipt,
11
- } from "viem";
12
- import * as R from "ramda";
13
- import type { Config, Transaction } from "./types.js";
14
-
15
- // ---------------------------------------------------------------------------
16
- // Types
17
- // ---------------------------------------------------------------------------
18
-
19
- /** Callback invoked when a valid payment is detected */
20
- type PaymentDetectedCallback = (
21
- payment: Transaction,
22
- ) => Promise<void>;
23
-
24
- /** State of the transaction watcher */
25
- type WatcherState = Readonly<{
26
- isRunning: boolean;
27
- lastCheckedBlock: bigint;
28
- detectedPayments: ReadonlyArray<PaymentDetectedCallback>;
29
- }>;
30
-
31
- // ---------------------------------------------------------------------------
32
- // Watcher Implementation
33
- // ---------------------------------------------------------------------------
34
-
35
- const initialState: WatcherState = {
36
- isRunning: false,
37
- lastCheckedBlock: 0n,
38
- detectedPayments: [],
39
- };
40
-
41
- /**
42
- * Creates a transaction watcher that monitors for payments to the configured address.
43
- *
44
- * Uses an immutable state cell (single-element tuple) as a controlled mutable reference.
45
- */
46
- const createTransactionWatcher = (
47
- _config: Config,
48
- _publicClient: unknown,
49
- ): Readonly<{
50
- start: (_?: undefined) => Promise<void>;
51
- stop: (_?: undefined) => void;
52
- onPaymentDetected: (callback: PaymentDetectedCallback) => Promise<void>;
53
- getState: (_?: undefined) => WatcherState;
54
- }> => {
55
- const stateCell = { current: initialState };
56
-
57
- const start = (_?: undefined): Promise<void> => {
58
- // eslint-disable-next-line functional/no-expression-statements, functional/immutable-data
59
- stateCell.current = {
60
- ...stateCell.current,
61
- isRunning: true,
62
- lastCheckedBlock: 0n,
63
- };
64
-
65
- return Promise.resolve();
66
- };
67
-
68
- const stop = (_?: undefined): void => {
69
- // eslint-disable-next-line functional/no-expression-statements, functional/immutable-data
70
- stateCell.current = R.assoc("isRunning", false, stateCell.current);
71
- };
72
-
73
- const onPaymentDetected = (
74
- callback: PaymentDetectedCallback,
75
- ): Promise<void> => {
76
- // eslint-disable-next-line functional/no-expression-statements, functional/immutable-data
77
- stateCell.current = {
78
- ...stateCell.current,
79
- detectedPayments: R.append(callback, stateCell.current.detectedPayments),
80
- };
81
- return Promise.resolve();
82
- };
83
-
84
- const getState = (_?: undefined): WatcherState => stateCell.current;
85
-
86
- return {
87
- start,
88
- stop,
89
- onPaymentDetected,
90
- getState,
91
- };
92
- };
93
-
94
- // ---------------------------------------------------------------------------
95
- // Utility Functions
96
- // ---------------------------------------------------------------------------
97
-
98
- /**
99
- * Validate that a transaction is a valid x402 payment:
100
- * - Transaction was successful
101
- * - Sent to the correct recipient
102
- * - Amount meets the minimum requirement
103
- * - Has sufficient confirmations
104
- */
105
- const isValidPayment = (
106
- tx: ViemTransaction,
107
- receipt: TransactionReceipt,
108
- config: Config,
109
- currentBlockNumber: bigint = 0n,
110
- ): boolean =>
111
- R.allPass([
112
- R.always(tx.to === config.payToAddress),
113
- R.always(tx.value >= config.minAmount),
114
- R.always(receipt.status === "success"),
115
- R.always(
116
- currentBlockNumber > 0n
117
- ? Number(currentBlockNumber - receipt.blockNumber) >= config.requiredConfirmations
118
- : true,
119
- ),
120
- ])();
121
-
122
- /**
123
- * Extract payment details from transaction and receipt.
124
- */
125
- const extractPaymentDetails = (
126
- tx: ViemTransaction,
127
- receipt: TransactionReceipt,
128
- currentBlockNumber: bigint,
129
- ): Transaction => {
130
- const txRecord = tx as unknown as Readonly<Record<string, unknown>>;
131
- const rawTimestamp = txRecord["blockTimestamp"];
132
- const timestamp = typeof rawTimestamp === "bigint" ? Number(rawTimestamp) : 0;
133
-
134
- return R.always({
135
- txHash: tx.hash,
136
- from: tx.from,
137
- to: tx.to ?? ("0x" as `0x${string}`),
138
- amount: tx.value,
139
- timestamp,
140
- blockNumber: receipt.blockNumber,
141
- confirmations: Number(currentBlockNumber - receipt.blockNumber),
142
- })();
143
- };
144
-
145
- export type {
146
- PaymentDetectedCallback,
147
- WatcherState,
148
- };
149
-
150
- export {
151
- createTransactionWatcher,
152
- isValidPayment,
153
- extractPaymentDetails,
154
- };
package/src/types.ts DELETED
@@ -1,110 +0,0 @@
1
- /** Configuration for payment facilitator */
2
- type Config = Readonly<{
3
- /** x402 facilitator URL (for HTTPFacilitatorClient compatibility) */
4
- facilitatorUrl?: string;
5
-
6
- /** Address to receive payments */
7
- payToAddress: `0x${string}`;
8
-
9
- /** Network identifier (e.g., "eip155:84532" for Base Sepolia) */
10
- network: string;
11
-
12
- /** Price for accessing verified attributes (e.g., "$0.001") */
13
- price: string;
14
-
15
- /** Ethereum RPC URL for transaction monitoring */
16
- ethereumRpcUrl: string;
17
-
18
- /** Chain ID for the network */
19
- chainId: number;
20
-
21
- /** Lemma API base URL */
22
- lemmaApiBase: string;
23
-
24
- /** Lemma API key (if required) */
25
- lemmaApiKey?: string;
26
-
27
- /** Circuit ID for the payment proof */
28
- circuitId: string;
29
-
30
- /** Minimum amount in USDC smallest unit (6 decimals) */
31
- minAmount: bigint;
32
-
33
- /** Number of block confirmations before considering payment valid */
34
- requiredConfirmations: number;
35
-
36
- /** Maximum age of payment proof in seconds */
37
- maxProofAge: number;
38
-
39
- /** IPFS gateway URL for fetching circuit artifacts */
40
- ipfsGateway?: string;
41
- }>;
42
-
43
- /** Parsed transaction details */
44
- type Transaction = Readonly<{
45
- /** Transaction hash */
46
- txHash: `0x${string}`;
47
-
48
- /** Sender address */
49
- from: `0x${string}`;
50
-
51
- /** Recipient address */
52
- to: `0x${string}`;
53
-
54
- /** Amount in smallest token unit */
55
- amount: bigint;
56
-
57
- /** Block timestamp */
58
- timestamp: number;
59
-
60
- /** Block number */
61
- blockNumber: bigint;
62
-
63
- /** Number of confirmations */
64
- confirmations: number;
65
- }>;
66
-
67
- /** Generated proof with inputs for Lemma API */
68
- type Proof = Readonly<{
69
- /** ZK proof data (base64 encoded) */
70
- proof: string;
71
-
72
- /** Public inputs for the circuit */
73
- inputs: ReadonlyArray<string>;
74
-
75
- /** Circuit ID used */
76
- circuitId: string;
77
-
78
- /** Timestamp when proof was generated */
79
- generatedAt: number;
80
- }>;
81
-
82
- /** Result of proof generation */
83
- type ProofResult = Readonly<{
84
- /** Transaction */
85
- payment: Transaction;
86
-
87
- /** Generated proof */
88
- proof: Proof;
89
- }>;
90
-
91
- /** Disclosure condition for Lemma API query */
92
- type DisclosureCondition = Readonly<{
93
- circuitId: string;
94
- }>;
95
-
96
- /** Disclosure object to send with query */
97
- type Disclosure = Readonly<{
98
- condition?: DisclosureCondition;
99
- proof: string;
100
- inputs: ReadonlyArray<string>;
101
- }>;
102
-
103
- export type {
104
- Config,
105
- Transaction,
106
- Proof,
107
- ProofResult,
108
- Disclosure,
109
- DisclosureCondition,
110
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "resolveJsonModule": true
7
- },
8
- "include": ["src/**/*"],
9
- "exclude": ["node_modules", "dist", "workers"],
10
- "references": [
11
- { "path": "../spec" },
12
- { "path": "../sdk" }
13
- ]
14
- }
@@ -1 +0,0 @@
1
- {"root":["./src/index.ts","./src/proof-generator.test.ts","./src/proof-generator.ts","./src/transaction-watcher.test.ts","./src/transaction-watcher.ts","./src/types.ts"],"version":"5.8.3"}
package/vitest.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- exclude: [
6
- '**/node_modules/**',
7
- '**/dist/**',
8
- '**/build/**',
9
- '**/*.test.mjs', // Exclude circuit test files
10
- '**/*.spec.mjs',
11
- '**/circuits/**/*.mjs', // Exclude all .mjs files in circuits directory
12
- ],
13
- include: [
14
- '**/*.test.ts',
15
- '**/*.spec.ts',
16
- ],
17
- },
18
- });