@agentbadge/circle-payments 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -222,3 +222,7 @@ const verdict = await evaluator.evaluate(jobId); // → complete / reject / expi
222
222
  ## License
223
223
 
224
224
  MIT
225
+
226
+ ---
227
+
228
+ Part of [AgentBadge](https://agentbadge.xyz) — support@agentbadge.xyz
@@ -11,12 +11,21 @@ export interface ReceiptClient {
11
11
  hash: `0x${string}`;
12
12
  }): Promise<unknown>;
13
13
  }
14
+ export interface TxHashStore {
15
+ claim(txHash: string): Promise<boolean>;
16
+ }
17
+ export declare class InMemoryTxHashStore implements TxHashStore {
18
+ private readonly seen;
19
+ constructor(seen?: Set<string>);
20
+ claim(txHash: string): Promise<boolean>;
21
+ }
14
22
  export interface ArcSelfSettleConfig {
15
23
  sellerAddress: string;
16
24
  chain?: SupportedChain;
17
25
  rpcUrl?: string;
18
26
  publicClient?: ReceiptClient;
19
27
  seenTxHashes?: Set<string>;
28
+ txHashStore?: TxHashStore;
20
29
  }
21
30
  export interface ArcSelfSettleHandle {
22
31
  readonly publicClient: ReceiptClient;
@@ -26,4 +35,5 @@ export interface ArcSelfSettleHandle {
26
35
  settle(payload: unknown, requirements: PaymentRequirements): Promise<SettleResult>;
27
36
  }
28
37
  export declare function buildArcSelfSettleRequirements(chain: SupportedChain, amount: string, payTo: string): PaymentRequirements;
38
+ export declare function createArcSelfSettleHandle(config: ArcSelfSettleConfig): ArcSelfSettleHandle;
29
39
  export declare function registerArcSelfSettleScheme(server: x402ResourceServer, config: ArcSelfSettleConfig): ArcSelfSettleHandle;
@@ -12,6 +12,19 @@ export class ArcSelfSettleError extends Error {
12
12
  this.name = "ArcSelfSettleError";
13
13
  }
14
14
  }
15
+ export class InMemoryTxHashStore {
16
+ seen;
17
+ constructor(seen = new Set()) {
18
+ this.seen = seen;
19
+ }
20
+ async claim(txHash) {
21
+ const key = txHash.toLowerCase();
22
+ if (this.seen.has(key))
23
+ return false;
24
+ this.seen.add(key);
25
+ return true;
26
+ }
27
+ }
15
28
  export function buildArcSelfSettleRequirements(chain, amount, payTo) {
16
29
  return {
17
30
  scheme: ARC_SELF_SETTLE_SCHEME,
@@ -57,16 +70,14 @@ function findPaymentTransfer(receipt, usdc, payTo, amount) {
57
70
  }
58
71
  return undefined;
59
72
  }
60
- export function registerArcSelfSettleScheme(server, config) {
73
+ export function createArcSelfSettleHandle(config) {
61
74
  const chain = config.chain ?? ARC_TESTNET;
62
75
  const publicClient = config.publicClient ??
63
76
  createPublicClient({
64
77
  transport: http(config.rpcUrl ?? chain.rpcUrl),
65
78
  });
66
79
  const seenTxHashes = config.seenTxHashes ?? new Set();
67
- server.register(chain.caip2, {
68
- scheme: ARC_SELF_SETTLE_SCHEME,
69
- });
80
+ const txHashStore = config.txHashStore ?? new InMemoryTxHashStore(seenTxHashes);
70
81
  async function inspectReceipt(payload, requirements, phase) {
71
82
  const txHash = extractTxHash(payload);
72
83
  if (!txHash)
@@ -94,14 +105,12 @@ export function registerArcSelfSettleScheme(server, config) {
94
105
  seenTxHashes,
95
106
  network: chain.caip2,
96
107
  async verify(payload, requirements) {
97
- const txHash = extractTxHash(payload);
98
- if (txHash && seenTxHashes.has(txHash.toLowerCase())) {
99
- return { isValid: false, invalidReason: "tx_replayed" };
100
- }
101
108
  const r = await inspectReceipt(payload, requirements, "verify");
102
109
  if (!r.ok)
103
110
  return { isValid: false, invalidReason: r.reason };
104
- seenTxHashes.add(r.txHash.toLowerCase());
111
+ if (!(await txHashStore.claim(r.txHash))) {
112
+ return { isValid: false, invalidReason: "tx_replayed" };
113
+ }
105
114
  return { isValid: true, payer: r.payer };
106
115
  },
107
116
  async settle(payload, requirements) {
@@ -112,3 +121,10 @@ export function registerArcSelfSettleScheme(server, config) {
112
121
  },
113
122
  };
114
123
  }
124
+ export function registerArcSelfSettleScheme(server, config) {
125
+ const handle = createArcSelfSettleHandle(config);
126
+ server.register(handle.network, {
127
+ scheme: ARC_SELF_SETTLE_SCHEME,
128
+ });
129
+ return handle;
130
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentbadge/circle-payments",
3
- "version": "0.1.3",
4
- "description": "Circle Gateway nanopayments + x402 payment rails (Base Sepolia, Arc) for AgentBadge \u2014 trusted agent payments",
3
+ "version": "0.1.5",
4
+ "description": "Circle Gateway nanopayments + x402 payment rails (Base Sepolia, Arc) for AgentBadge — trusted agent payments",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -49,4 +49,4 @@
49
49
  "peerDependencies": {
50
50
  "hono": "^4.7.0"
51
51
  }
52
- }
52
+ }