@queelabs/connectors-base 0.0.1
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/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +52 -0
- package/dist/index.test.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MppPaymentAdapter } from "@queelabs/core";
|
|
2
|
+
export declare function resolveBaseVerificationExpectation(input: {
|
|
3
|
+
challengePayload: Record<string, unknown>;
|
|
4
|
+
expectedAmountMinor: number;
|
|
5
|
+
recipientAddress: string;
|
|
6
|
+
usdcAddress: string;
|
|
7
|
+
}): {
|
|
8
|
+
recipientAddress: string;
|
|
9
|
+
usdcAddress: string;
|
|
10
|
+
expectedAmountAtomic: bigint;
|
|
11
|
+
};
|
|
12
|
+
export declare function assertBaseTransferredAmountMatchesExpectation(input: {
|
|
13
|
+
transferredAmount: bigint;
|
|
14
|
+
expectedAmountAtomic: bigint;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Base adapter (MPP-shaped): maps Base network / USDC flows
|
|
18
|
+
* to Quee payment challenges and receipts.
|
|
19
|
+
*
|
|
20
|
+
* createPurchaseChallenge returns the recipient address and amount so the
|
|
21
|
+
* buyer can send USDC on Base. verifyPurchase fetches the transaction
|
|
22
|
+
* receipt from the Base RPC and confirms that a USDC Transfer event was
|
|
23
|
+
* emitted to the expected recipient for at least the expected amount.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createBaseMppConnector(): MppPaymentAdapter;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,iBAAiB,EAGlB,MAAM,gBAAgB,CAAC;AAaxB,wBAAgB,kCAAkC,CAAC,KAAK,EAAE;IACxD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;;;;EAYA;AAED,wBAAgB,6CAA6C,CAAC,KAAK,EAAE;IACnE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC9B,QAIA;AAQD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,IAAI,iBAAiB,CAkI1D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createPublicClient, http } from "viem";
|
|
2
|
+
import { base, baseSepolia } from "viem/chains";
|
|
3
|
+
function readRecord(source, key) {
|
|
4
|
+
const value = source[key];
|
|
5
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
6
|
+
return null;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function readString(source, key) {
|
|
10
|
+
const value = source[key];
|
|
11
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
12
|
+
}
|
|
13
|
+
export function resolveBaseVerificationExpectation(input) {
|
|
14
|
+
const basePayload = readRecord(input.challengePayload, "base") ?? {};
|
|
15
|
+
const amountAtomicFromPayload = readString(basePayload, "amountAtomic");
|
|
16
|
+
return {
|
|
17
|
+
recipientAddress: readString(basePayload, "recipientAddress") ?? input.recipientAddress,
|
|
18
|
+
usdcAddress: readString(basePayload, "usdcAddress") ?? input.usdcAddress,
|
|
19
|
+
expectedAmountAtomic: amountAtomicFromPayload != null
|
|
20
|
+
? BigInt(amountAtomicFromPayload)
|
|
21
|
+
: BigInt(input.expectedAmountMinor) * 10000n,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function assertBaseTransferredAmountMatchesExpectation(input) {
|
|
25
|
+
if (input.transferredAmount < input.expectedAmountAtomic) {
|
|
26
|
+
throw new Error("Base transfer amount is below required amount");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function resolveChain() {
|
|
30
|
+
const network = process.env.QUEE_BASE_NETWORK?.toLowerCase();
|
|
31
|
+
if (network === "sepolia" || network === "testnet")
|
|
32
|
+
return baseSepolia;
|
|
33
|
+
return base;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Base adapter (MPP-shaped): maps Base network / USDC flows
|
|
37
|
+
* to Quee payment challenges and receipts.
|
|
38
|
+
*
|
|
39
|
+
* createPurchaseChallenge returns the recipient address and amount so the
|
|
40
|
+
* buyer can send USDC on Base. verifyPurchase fetches the transaction
|
|
41
|
+
* receipt from the Base RPC and confirms that a USDC Transfer event was
|
|
42
|
+
* emitted to the expected recipient for at least the expected amount.
|
|
43
|
+
*/
|
|
44
|
+
export function createBaseMppConnector() {
|
|
45
|
+
return {
|
|
46
|
+
async createPurchaseChallenge(input) {
|
|
47
|
+
const recipientAddress = process.env.QUEE_BASE_RECIPIENT_ADDRESS;
|
|
48
|
+
if (!recipientAddress) {
|
|
49
|
+
throw new Error("QUEE_BASE_RECIPIENT_ADDRESS is not set");
|
|
50
|
+
}
|
|
51
|
+
const rpcUrl = process.env.QUEE_BASE_RPC_URL;
|
|
52
|
+
if (!rpcUrl) {
|
|
53
|
+
throw new Error("QUEE_BASE_RPC_URL is not set");
|
|
54
|
+
}
|
|
55
|
+
const usdcAddress = process.env.QUEE_BASE_USDC_ADDRESS;
|
|
56
|
+
if (!usdcAddress) {
|
|
57
|
+
throw new Error("QUEE_BASE_USDC_ADDRESS is not set (e.g. 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 for Base mainnet USDC)");
|
|
58
|
+
}
|
|
59
|
+
const chain = resolveChain();
|
|
60
|
+
return {
|
|
61
|
+
challengeId: `base_ch_${input.orderId}`,
|
|
62
|
+
rail: "base",
|
|
63
|
+
payload: {
|
|
64
|
+
type: "base_payment_challenge",
|
|
65
|
+
version: "0.2",
|
|
66
|
+
orderId: input.orderId,
|
|
67
|
+
amountMinor: input.amountMinor,
|
|
68
|
+
currency: input.currency,
|
|
69
|
+
base: {
|
|
70
|
+
network: chain.name,
|
|
71
|
+
chainId: chain.id,
|
|
72
|
+
asset: "USDC",
|
|
73
|
+
usdcAddress,
|
|
74
|
+
recipientAddress,
|
|
75
|
+
/** USDC has 6 decimals; amountMinor is in cents (2 decimals) */
|
|
76
|
+
amountAtomic: (BigInt(input.amountMinor) * 10000n).toString(),
|
|
77
|
+
amountFormatted: (input.amountMinor / 100).toFixed(2),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
async verifyPurchase(input) {
|
|
83
|
+
const rpcUrl = process.env.QUEE_BASE_RPC_URL;
|
|
84
|
+
if (!rpcUrl) {
|
|
85
|
+
throw new Error("QUEE_BASE_RPC_URL is not set");
|
|
86
|
+
}
|
|
87
|
+
const recipientAddress = process.env.QUEE_BASE_RECIPIENT_ADDRESS;
|
|
88
|
+
if (!recipientAddress) {
|
|
89
|
+
throw new Error("QUEE_BASE_RECIPIENT_ADDRESS is not set");
|
|
90
|
+
}
|
|
91
|
+
const usdcAddress = process.env.QUEE_BASE_USDC_ADDRESS;
|
|
92
|
+
if (!usdcAddress) {
|
|
93
|
+
throw new Error("QUEE_BASE_USDC_ADDRESS is not set");
|
|
94
|
+
}
|
|
95
|
+
const expectation = resolveBaseVerificationExpectation({
|
|
96
|
+
challengePayload: input.challengePayload,
|
|
97
|
+
expectedAmountMinor: input.expectedAmountMinor,
|
|
98
|
+
recipientAddress,
|
|
99
|
+
usdcAddress,
|
|
100
|
+
});
|
|
101
|
+
const proof = input.proof;
|
|
102
|
+
if (!proof.txHash) {
|
|
103
|
+
throw new Error("Missing Base transaction hash in proof");
|
|
104
|
+
}
|
|
105
|
+
const txHash = proof.txHash;
|
|
106
|
+
const chain = resolveChain();
|
|
107
|
+
const client = createPublicClient({
|
|
108
|
+
chain,
|
|
109
|
+
transport: http(rpcUrl),
|
|
110
|
+
});
|
|
111
|
+
const receipt = await client.getTransactionReceipt({ hash: txHash });
|
|
112
|
+
if (receipt.status !== "success") {
|
|
113
|
+
throw new Error(`Base transaction ${txHash} did not succeed on-chain`);
|
|
114
|
+
}
|
|
115
|
+
// Look for a USDC Transfer event to the expected recipient
|
|
116
|
+
const normalizedRecipient = expectation.recipientAddress.toLowerCase();
|
|
117
|
+
const normalizedUsdc = expectation.usdcAddress.toLowerCase();
|
|
118
|
+
const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
119
|
+
const matchingLog = receipt.logs.find((log) => {
|
|
120
|
+
if (log.address.toLowerCase() !== normalizedUsdc)
|
|
121
|
+
return false;
|
|
122
|
+
if (!log.topics[0] || log.topics[0] !== transferTopic)
|
|
123
|
+
return false;
|
|
124
|
+
// topics[2] is the `to` address (zero-padded to 32 bytes)
|
|
125
|
+
const toTopic = log.topics[2];
|
|
126
|
+
if (!toTopic)
|
|
127
|
+
return false;
|
|
128
|
+
const toAddress = ("0x" + toTopic.slice(26)).toLowerCase();
|
|
129
|
+
return toAddress === normalizedRecipient;
|
|
130
|
+
});
|
|
131
|
+
if (!matchingLog) {
|
|
132
|
+
throw new Error(`Base transaction ${txHash} does not contain a USDC Transfer to ${expectation.recipientAddress}`);
|
|
133
|
+
}
|
|
134
|
+
const transferredAmount = BigInt(matchingLog.data);
|
|
135
|
+
assertBaseTransferredAmountMatchesExpectation({
|
|
136
|
+
transferredAmount,
|
|
137
|
+
expectedAmountAtomic: expectation.expectedAmountAtomic,
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
receiptPayload: {
|
|
141
|
+
verified: true,
|
|
142
|
+
challengeId: input.challengeId,
|
|
143
|
+
orderId: input.orderId,
|
|
144
|
+
settledVia: "base",
|
|
145
|
+
proof,
|
|
146
|
+
providerReference: txHash,
|
|
147
|
+
onChain: {
|
|
148
|
+
txHash,
|
|
149
|
+
blockNumber: receipt.blockNumber.toString(),
|
|
150
|
+
from: receipt.from,
|
|
151
|
+
usdcTransferAmount: transferredAmount.toString(),
|
|
152
|
+
expectedAmountAtomic: expectation.expectedAmountAtomic.toString(),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
verifiedAt: new Date(),
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAShD,SAAS,UAAU,CAAC,MAA+B,EAAE,GAAW;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7E,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,UAAU,CAAC,MAA+B,EAAE,GAAW;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,KAKlD;IACC,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACrE,MAAM,uBAAuB,G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E;qBAClE;iBACF;gBACD,UAAU,EAAE,IAAI,IAAI,EAAE;aACvB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { assertBaseTransferredAmountMatchesExpectation, resolveBaseVerificationExpectation, } from "./index.js";
|
|
3
|
+
describe("Base verification expectation", () => {
|
|
4
|
+
it("prefers stored challenge payload values for recipient, token, and amount", () => {
|
|
5
|
+
const expectation = resolveBaseVerificationExpectation({
|
|
6
|
+
challengePayload: {
|
|
7
|
+
base: {
|
|
8
|
+
recipientAddress: "0xchallengeRecipient",
|
|
9
|
+
usdcAddress: "0xchallengeUsdc",
|
|
10
|
+
amountAtomic: "5000000",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
expectedAmountMinor: 4200,
|
|
14
|
+
recipientAddress: "0xenvRecipient",
|
|
15
|
+
usdcAddress: "0xenvUsdc",
|
|
16
|
+
});
|
|
17
|
+
expect(expectation.recipientAddress).toBe("0xchallengeRecipient");
|
|
18
|
+
expect(expectation.usdcAddress).toBe("0xchallengeUsdc");
|
|
19
|
+
expect(expectation.expectedAmountAtomic).toBe(5000000n);
|
|
20
|
+
});
|
|
21
|
+
it("falls back to expected order amount when amountAtomic is not present", () => {
|
|
22
|
+
const expectation = resolveBaseVerificationExpectation({
|
|
23
|
+
challengePayload: {
|
|
24
|
+
base: {
|
|
25
|
+
recipientAddress: "0xchallengeRecipient",
|
|
26
|
+
usdcAddress: "0xchallengeUsdc",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
expectedAmountMinor: 4200,
|
|
30
|
+
recipientAddress: "0xenvRecipient",
|
|
31
|
+
usdcAddress: "0xenvUsdc",
|
|
32
|
+
});
|
|
33
|
+
expect(expectation.expectedAmountAtomic).toBe(42000000n);
|
|
34
|
+
});
|
|
35
|
+
it("rejects underpayment", () => {
|
|
36
|
+
expect(() => assertBaseTransferredAmountMatchesExpectation({
|
|
37
|
+
transferredAmount: 4999999n,
|
|
38
|
+
expectedAmountAtomic: 5000000n,
|
|
39
|
+
})).toThrow("Base transfer amount is below required amount");
|
|
40
|
+
});
|
|
41
|
+
it("accepts exact payment and overpayment", () => {
|
|
42
|
+
expect(() => assertBaseTransferredAmountMatchesExpectation({
|
|
43
|
+
transferredAmount: 5000000n,
|
|
44
|
+
expectedAmountAtomic: 5000000n,
|
|
45
|
+
})).not.toThrow();
|
|
46
|
+
expect(() => assertBaseTransferredAmountMatchesExpectation({
|
|
47
|
+
transferredAmount: 5000001n,
|
|
48
|
+
expectedAmountAtomic: 5000000n,
|
|
49
|
+
})).not.toThrow();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,6CAA6C,EAC7C,kCAAkC,GACnC,MAAM,YAAY,CAAC;AAEpB,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,EAAE,CAAC,0EAA0E,EAAE,GAAG,EAAE;QAClF,MAAM,WAAW,GAAG,kCAAkC,CAAC;YACrD,gBAAgB,EAAE;gBAChB,IAAI,EAAE;oBACJ,gBAAgB,EAAE,sBAAsB;oBACxC,WAAW,EAAE,iBAAiB;oBAC9B,YAAY,EAAE,SAAS;iBACxB;aACF;YACD,mBAAmB,EAAE,IAAI;YACzB,gBAAgB,EAAE,gBAAgB;YAClC,WAAW,EAAE,WAAW;SACzB,CAAC,CAAC;QAEH,MAAM,CAAC,WAAW,CAAC,gBAAgB,CA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AClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@queelabs/connectors-base",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"description": "Base network MPP connector for Quee",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/quee-protocol/quee.git",
|
|
18
|
+
"directory": "connectors/base"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"viem": "^2.30.2",
|
|
28
|
+
"@queelabs/core": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.10.2",
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^2.1.8"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"test": "vitest run --passWithNoTests",
|
|
38
|
+
"lint": "echo ok"
|
|
39
|
+
}
|
|
40
|
+
}
|