@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
|
@@ -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
|
-
}
|
package/tsconfig.tsbuildinfo
DELETED
|
@@ -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
|
-
});
|