@agentbadge/circle-payments 0.1.4 → 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.
|
@@ -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;
|
|
@@ -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,
|
|
@@ -64,6 +77,7 @@ export function createArcSelfSettleHandle(config) {
|
|
|
64
77
|
transport: http(config.rpcUrl ?? chain.rpcUrl),
|
|
65
78
|
});
|
|
66
79
|
const seenTxHashes = config.seenTxHashes ?? new Set();
|
|
80
|
+
const txHashStore = config.txHashStore ?? new InMemoryTxHashStore(seenTxHashes);
|
|
67
81
|
async function inspectReceipt(payload, requirements, phase) {
|
|
68
82
|
const txHash = extractTxHash(payload);
|
|
69
83
|
if (!txHash)
|
|
@@ -91,14 +105,12 @@ export function createArcSelfSettleHandle(config) {
|
|
|
91
105
|
seenTxHashes,
|
|
92
106
|
network: chain.caip2,
|
|
93
107
|
async verify(payload, requirements) {
|
|
94
|
-
const txHash = extractTxHash(payload);
|
|
95
|
-
if (txHash && seenTxHashes.has(txHash.toLowerCase())) {
|
|
96
|
-
return { isValid: false, invalidReason: "tx_replayed" };
|
|
97
|
-
}
|
|
98
108
|
const r = await inspectReceipt(payload, requirements, "verify");
|
|
99
109
|
if (!r.ok)
|
|
100
110
|
return { isValid: false, invalidReason: r.reason };
|
|
101
|
-
|
|
111
|
+
if (!(await txHashStore.claim(r.txHash))) {
|
|
112
|
+
return { isValid: false, invalidReason: "tx_replayed" };
|
|
113
|
+
}
|
|
102
114
|
return { isValid: true, payer: r.payer };
|
|
103
115
|
},
|
|
104
116
|
async settle(payload, requirements) {
|
package/package.json
CHANGED