@genesis-tech/genesispay-seller 0.13.1 → 1.3.0
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/CHANGELOG.md +206 -0
- package/README.md +670 -91
- package/dist/checkout-documents.d.ts +99 -0
- package/dist/checkout-documents.d.ts.map +1 -0
- package/dist/checkout-documents.js +155 -0
- package/dist/checkout-documents.js.map +1 -0
- package/dist/checkout-return.d.ts +41 -0
- package/dist/checkout-return.d.ts.map +1 -0
- package/dist/checkout-return.js +68 -0
- package/dist/checkout-return.js.map +1 -0
- package/dist/client.d.ts +318 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +718 -0
- package/dist/client.js.map +1 -0
- package/dist/contract-mandates.d.ts +39 -0
- package/dist/contract-mandates.d.ts.map +1 -0
- package/dist/contract-mandates.js +98 -0
- package/dist/contract-mandates.js.map +1 -0
- package/dist/contract-usage.d.ts +29 -0
- package/dist/contract-usage.d.ts.map +1 -0
- package/dist/contract-usage.js +92 -0
- package/dist/contract-usage.js.map +1 -0
- package/dist/customers.d.ts +41 -0
- package/dist/customers.d.ts.map +1 -0
- package/dist/customers.js +76 -0
- package/dist/customers.js.map +1 -0
- package/dist/entitlements.d.ts +19 -0
- package/dist/entitlements.d.ts.map +1 -0
- package/dist/entitlements.js +30 -0
- package/dist/entitlements.js.map +1 -0
- package/dist/errors.d.ts +129 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +273 -0
- package/dist/errors.js.map +1 -0
- package/dist/fulfillment-attempts.d.ts +29 -0
- package/dist/fulfillment-attempts.d.ts.map +1 -0
- package/dist/fulfillment-attempts.js +71 -0
- package/dist/fulfillment-attempts.js.map +1 -0
- package/dist/fulfillment.d.ts +152 -0
- package/dist/fulfillment.d.ts.map +1 -0
- package/dist/fulfillment.js +810 -0
- package/dist/fulfillment.js.map +1 -0
- package/dist/genesispay-settlement.d.ts +32 -0
- package/dist/genesispay-settlement.d.ts.map +1 -0
- package/dist/genesispay-settlement.js +500 -0
- package/dist/genesispay-settlement.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +111 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +192 -0
- package/dist/invoices.js.map +1 -0
- package/dist/item-tax.d.ts +15 -0
- package/dist/item-tax.d.ts.map +1 -0
- package/dist/item-tax.js +19 -0
- package/dist/item-tax.js.map +1 -0
- package/dist/mandate-gate.d.ts +54 -0
- package/dist/mandate-gate.d.ts.map +1 -0
- package/dist/mandate-gate.js +183 -0
- package/dist/mandate-gate.js.map +1 -0
- package/dist/mandates.d.ts +189 -0
- package/dist/mandates.d.ts.map +1 -0
- package/dist/mandates.js +234 -0
- package/dist/mandates.js.map +1 -0
- package/dist/networks.d.ts +10 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/networks.js +23 -0
- package/dist/networks.js.map +1 -0
- package/dist/payment-gate.d.ts +98 -0
- package/dist/payment-gate.d.ts.map +1 -0
- package/dist/payment-gate.js +370 -0
- package/dist/payment-gate.js.map +1 -0
- package/dist/plans.d.ts +68 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +127 -0
- package/dist/plans.js.map +1 -0
- package/dist/products.d.ts +170 -0
- package/dist/products.d.ts.map +1 -0
- package/dist/products.js +1317 -0
- package/dist/products.js.map +1 -0
- package/dist/resource.d.ts +47 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +71 -0
- package/dist/resource.js.map +1 -0
- package/dist/strict-response.d.ts +21 -0
- package/dist/strict-response.d.ts.map +1 -0
- package/dist/strict-response.js +68 -0
- package/dist/strict-response.js.map +1 -0
- package/dist/usdc-amount.d.ts +7 -0
- package/dist/usdc-amount.d.ts.map +1 -0
- package/dist/usdc-amount.js +21 -0
- package/dist/usdc-amount.js.map +1 -0
- package/dist/webhooks.d.ts +352 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +244 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandate gate — the signature-free metered path for humans and subscriptions.
|
|
3
|
+
*
|
|
4
|
+
* Instead of demanding a fresh signed payment per request (the x402 gate), the
|
|
5
|
+
* caller presents a standing payment mandate id via the `GENESISPAY-MANDATE`
|
|
6
|
+
* header. The gate debits the mandate through GenesisPay
|
|
7
|
+
* (`POST /api/v1/mandates/:id/charge`) — a non-custodial on-chain pull from
|
|
8
|
+
* the payer's wallet directly to yours — and only runs your handler once the
|
|
9
|
+
* charge settled. Combine with `createPaymentGate` to accept both per-call
|
|
10
|
+
* x402 payments and mandate-metered calls on one endpoint.
|
|
11
|
+
*/
|
|
12
|
+
import { parseUsdcAmountToMinorUnits } from "./usdc-amount.js";
|
|
13
|
+
export const MANDATE_HEADER = "GENESISPAY-MANDATE";
|
|
14
|
+
const MANDATE_IDEMPOTENCY_KEY = /^[A-Za-z0-9][A-Za-z0-9._:-]{7,199}$/;
|
|
15
|
+
const TRANSACTION_HASH = /^0x[0-9a-f]{64}$/i;
|
|
16
|
+
function validIdempotencyKey(value) {
|
|
17
|
+
const key = value?.trim();
|
|
18
|
+
return key &&
|
|
19
|
+
key.toLowerCase() !== "undefined" &&
|
|
20
|
+
MANDATE_IDEMPOTENCY_KEY.test(key)
|
|
21
|
+
? key
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
24
|
+
export function createMandateGate(options) {
|
|
25
|
+
const apiKey = options.apiKey?.trim();
|
|
26
|
+
if (!apiKey) {
|
|
27
|
+
throw new Error("createMandateGate requires a GenesisPay seller API key (gp_sk_...).");
|
|
28
|
+
}
|
|
29
|
+
const baseUrl = options.baseUrl?.trim().replace(/\/+$/, "");
|
|
30
|
+
if (!baseUrl) {
|
|
31
|
+
throw new Error("createMandateGate requires the GenesisPay base URL.");
|
|
32
|
+
}
|
|
33
|
+
if (!/^\d+(\.\d{1,6})?$/.test(options.amount)) {
|
|
34
|
+
throw new Error("createMandateGate requires a decimal amount with up to 6 decimals, e.g. \"0.08\".");
|
|
35
|
+
}
|
|
36
|
+
const expectedAmountMinor = parseUsdcAmountToMinorUnits(options.amount).toString();
|
|
37
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
38
|
+
async function charge(mandateId, resourceUrl, idempotencyKey) {
|
|
39
|
+
const stableKey = validIdempotencyKey(idempotencyKey);
|
|
40
|
+
if (!stableKey) {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
status: 400,
|
|
44
|
+
code: "invalid_idempotency_key",
|
|
45
|
+
error: "Idempotency-Key is required for mandate charges and must be reused after an outcome-unknown response.",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
let response;
|
|
49
|
+
try {
|
|
50
|
+
response = await fetchFn(`${baseUrl}/api/v1/mandates/${encodeURIComponent(mandateId)}/charge`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
Authorization: `Bearer ${apiKey}`,
|
|
55
|
+
"Idempotency-Key": stableKey,
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({
|
|
58
|
+
amount: options.amount,
|
|
59
|
+
resourceUrl,
|
|
60
|
+
description: options.description,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
status: 503,
|
|
68
|
+
error: `GenesisPay is unreachable: ${error instanceof Error ? error.message : String(error)}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
let body = null;
|
|
72
|
+
try {
|
|
73
|
+
body = await response.json();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Non-JSON error body; fall through with a generic message.
|
|
77
|
+
}
|
|
78
|
+
const record = (body ?? {});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
const chargeRecord = (record.charge ?? null);
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
status: response.status,
|
|
84
|
+
code: typeof record.code === "string" ? record.code : undefined,
|
|
85
|
+
error: typeof record.error === "string"
|
|
86
|
+
? record.error
|
|
87
|
+
: `GenesisPay rejected the mandate charge (${response.status}).`,
|
|
88
|
+
...(chargeRecord && typeof chargeRecord.id === "string"
|
|
89
|
+
? {
|
|
90
|
+
charge: {
|
|
91
|
+
id: chargeRecord.id,
|
|
92
|
+
amountMinor: String(chargeRecord.amountMinor ?? ""),
|
|
93
|
+
txHash: typeof chargeRecord.txHash === "string"
|
|
94
|
+
? chargeRecord.txHash
|
|
95
|
+
: null,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
: {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const chargeRecord = record.charge &&
|
|
102
|
+
typeof record.charge === "object" &&
|
|
103
|
+
!Array.isArray(record.charge)
|
|
104
|
+
? record.charge
|
|
105
|
+
: null;
|
|
106
|
+
const chargeId = typeof chargeRecord?.id === "string" ? chargeRecord.id : "";
|
|
107
|
+
const amountMinor = typeof chargeRecord?.amountMinor === "string"
|
|
108
|
+
? chargeRecord.amountMinor
|
|
109
|
+
: "";
|
|
110
|
+
const txHash = typeof chargeRecord?.txHash === "string" ? chargeRecord.txHash : "";
|
|
111
|
+
if (chargeRecord?.status !== "settled" ||
|
|
112
|
+
chargeId.trim().length === 0 ||
|
|
113
|
+
amountMinor !== expectedAmountMinor ||
|
|
114
|
+
!TRANSACTION_HASH.test(txHash)) {
|
|
115
|
+
return {
|
|
116
|
+
ok: false,
|
|
117
|
+
status: 503,
|
|
118
|
+
code: "charge_response_unverified",
|
|
119
|
+
error: "GenesisPay did not return a verified settled mandate charge. Do not retry with a new Idempotency-Key.",
|
|
120
|
+
...(chargeId.trim().length > 0
|
|
121
|
+
? {
|
|
122
|
+
charge: {
|
|
123
|
+
id: chargeId,
|
|
124
|
+
amountMinor,
|
|
125
|
+
txHash: TRANSACTION_HASH.test(txHash) ? txHash : null,
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
charge: {
|
|
134
|
+
id: chargeId,
|
|
135
|
+
amountMinor,
|
|
136
|
+
txHash,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function wrap(handler) {
|
|
141
|
+
return async (request) => {
|
|
142
|
+
const mandateId = request.headers.get(MANDATE_HEADER)?.trim();
|
|
143
|
+
if (!mandateId) {
|
|
144
|
+
return jsonResponse({
|
|
145
|
+
error: "Payment required.",
|
|
146
|
+
howToPay: `Attach an active GenesisPay mandate id via the ${MANDATE_HEADER} header, or pay per call via x402.`,
|
|
147
|
+
amount: options.amount,
|
|
148
|
+
}, 402);
|
|
149
|
+
}
|
|
150
|
+
const idempotencyKey = validIdempotencyKey(request.headers.get("Idempotency-Key"));
|
|
151
|
+
if (!idempotencyKey) {
|
|
152
|
+
return jsonResponse({
|
|
153
|
+
error: "Idempotency-Key is required for a mandate-metered request and must be reused after a timeout.",
|
|
154
|
+
code: "invalid_idempotency_key",
|
|
155
|
+
}, 400);
|
|
156
|
+
}
|
|
157
|
+
const outcome = await charge(mandateId, request.url, idempotencyKey);
|
|
158
|
+
if (!outcome.ok) {
|
|
159
|
+
return jsonResponse({
|
|
160
|
+
error: outcome.error,
|
|
161
|
+
code: outcome.code,
|
|
162
|
+
...(outcome.charge ? { charge: outcome.charge } : {}),
|
|
163
|
+
}, outcome.status);
|
|
164
|
+
}
|
|
165
|
+
const response = await handler(request);
|
|
166
|
+
const headers = new Headers(response.headers);
|
|
167
|
+
headers.set("GENESISPAY-MANDATE-CHARGE", outcome.charge.id);
|
|
168
|
+
return new Response(response.body, {
|
|
169
|
+
status: response.status,
|
|
170
|
+
statusText: response.statusText,
|
|
171
|
+
headers,
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return { charge, wrap };
|
|
176
|
+
}
|
|
177
|
+
function jsonResponse(body, status) {
|
|
178
|
+
return new Response(JSON.stringify(body), {
|
|
179
|
+
status,
|
|
180
|
+
headers: { "Content-Type": "application/json" },
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=mandate-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-gate.js","sourceRoot":"","sources":["../src/mandate-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,MAAM,uBAAuB,GAAG,qCAAqC,CAAC;AACtE,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAE7C,SAAS,mBAAmB,CAAC,KAAgC;IAC3D,MAAM,GAAG,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1B,OAAO,GAAG;QACR,GAAG,CAAC,WAAW,EAAE,KAAK,WAAW;QACjC,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC;QACjC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AA6CD,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE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CAAC,2BAA2B,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAE5D,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;gBACjC,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO;aACR,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC;AAED,SAAS,YAAY,CAAC,IAAa,EAAE,MAAc;IACjD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACxC,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAChD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { type GenesisPayRequest } from "./resource.js";
|
|
2
|
+
import { type ContractUsageCharge, type ContractUsageInput } from "./contract-usage.js";
|
|
3
|
+
import type { Hex } from "viem";
|
|
4
|
+
import { type ContractPerUseCreateInput, type ContractPerUseCreateResult, type ContractSubscriptionCreateInput, type ContractSubscriptionCreateResult } from "./contract-mandates.js";
|
|
5
|
+
export type MandateKind = "per_use" | "subscription";
|
|
6
|
+
export type MandateStatus = "pending_permit" | "active" | "past_due" | "revoked" | "expired" | "cancelled";
|
|
7
|
+
export type MandateChargeStatus = "pending" | "submitted" | "settled" | "failed";
|
|
8
|
+
export type Mandate = {
|
|
9
|
+
protocol?: "contract_mandate_v1";
|
|
10
|
+
activationStatus?: "proposed" | "submitted" | "confirmed";
|
|
11
|
+
revocationStatus?: "none" | "requested" | "confirmed";
|
|
12
|
+
executor?: string;
|
|
13
|
+
contractVersion?: string;
|
|
14
|
+
id: string;
|
|
15
|
+
kind: MandateKind;
|
|
16
|
+
status: MandateStatus;
|
|
17
|
+
asset: "USDC" | "EURC";
|
|
18
|
+
chainId: number;
|
|
19
|
+
payerWallet: string;
|
|
20
|
+
destinationWallet: string;
|
|
21
|
+
/**
|
|
22
|
+
* The subscription plan this mandate was signed from, or `null` when it was
|
|
23
|
+
* proposed directly via `mandates.create` — that path has no plan, and one
|
|
24
|
+
* supplied by the caller would let a mandate be attributed to a foreign plan.
|
|
25
|
+
* `null` is a valid state, not a missing value; older mandates have it too.
|
|
26
|
+
*/
|
|
27
|
+
subscriptionPlanId: string | null;
|
|
28
|
+
/** Total approved spend, in 6-decimal minor units (string — no precision loss). */
|
|
29
|
+
allowanceMinor: string;
|
|
30
|
+
/** Ceiling for any single charge, in minor units. */
|
|
31
|
+
capPerChargeMinor: string;
|
|
32
|
+
spentMinor: string;
|
|
33
|
+
/** `allowanceMinor - spentMinor`, as the server computes it. */
|
|
34
|
+
remainingMinor: string;
|
|
35
|
+
/** Subscription mandates only; null for `per_use`. */
|
|
36
|
+
amountPerPeriodMinor: string | null;
|
|
37
|
+
/** Subscription mandates only; null for `per_use`. */
|
|
38
|
+
periodDays: number | null;
|
|
39
|
+
nextChargeAt: string | null;
|
|
40
|
+
/** After this the unsubmitted permit is dead and the mandate needs re-signing. */
|
|
41
|
+
permitDeadline: string;
|
|
42
|
+
permitTxHash: string | null;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
/** Set after canonical activation confirmation. HTTP acceptance is not activation. */
|
|
45
|
+
activatedAt: string | null;
|
|
46
|
+
revokedAt: string | null;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The EIP-712 payload the payer's wallet signs (`eth_signTypedData_v4`).
|
|
50
|
+
*
|
|
51
|
+
* Passed through **verbatim** from the server rather than remapped: a signature
|
|
52
|
+
* covers the exact bytes of this structure, so normalizing a field would
|
|
53
|
+
* produce a signature over something other than what the contract verifies.
|
|
54
|
+
*/
|
|
55
|
+
export type PermitTypedData = {
|
|
56
|
+
domain: {
|
|
57
|
+
name: string;
|
|
58
|
+
version: string;
|
|
59
|
+
chainId: number;
|
|
60
|
+
verifyingContract: string;
|
|
61
|
+
};
|
|
62
|
+
types: Record<string, ReadonlyArray<{
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
}>>;
|
|
66
|
+
primaryType: string;
|
|
67
|
+
message: {
|
|
68
|
+
owner: string;
|
|
69
|
+
spender: string;
|
|
70
|
+
value: string;
|
|
71
|
+
nonce: string;
|
|
72
|
+
deadline: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export type MandateCreateInput = {
|
|
76
|
+
payerWallet: string;
|
|
77
|
+
kind: MandateKind;
|
|
78
|
+
/** Total spending approval as a decimal amount, e.g. "20". */
|
|
79
|
+
allowance: string;
|
|
80
|
+
/** Ceiling for a single charge as a decimal amount, e.g. "0.10". */
|
|
81
|
+
capPerCharge: string;
|
|
82
|
+
/** Required for `kind: "subscription"`. Decimal amount, e.g. "9". */
|
|
83
|
+
amountPerPeriod?: string;
|
|
84
|
+
/** Required for `kind: "subscription"`. Whole days, e.g. 30. */
|
|
85
|
+
periodDays?: number;
|
|
86
|
+
/** Defaults to USDC. */
|
|
87
|
+
asset?: "USDC" | "EURC";
|
|
88
|
+
/** Defaults to the account's receiving wallet. */
|
|
89
|
+
destinationWallet?: string;
|
|
90
|
+
};
|
|
91
|
+
export type MandateCreateResult = {
|
|
92
|
+
mandate: Mandate;
|
|
93
|
+
/** Give this to the payer's wallet to sign; then activate from the frontend. */
|
|
94
|
+
permitTypedData: PermitTypedData;
|
|
95
|
+
/** The facilitator address the permit approves as spender. */
|
|
96
|
+
spender: string;
|
|
97
|
+
};
|
|
98
|
+
export type MandateChargeInput = {
|
|
99
|
+
/** Decimal amount, e.g. "0.08". Must not exceed the mandate's cap per charge. */
|
|
100
|
+
amount: string;
|
|
101
|
+
/** Stable identity for this logical usage request; reuse it after timeouts. */
|
|
102
|
+
idempotencyKey: string;
|
|
103
|
+
/** What was paid for — surfaced to the payer in their mandate history. */
|
|
104
|
+
resourceUrl?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
};
|
|
107
|
+
export type MandateCharge = {
|
|
108
|
+
id: string;
|
|
109
|
+
status: MandateChargeStatus;
|
|
110
|
+
amountMinor: string;
|
|
111
|
+
/** Null while the pull is still pending, and for a failed charge. */
|
|
112
|
+
txHash: string | null;
|
|
113
|
+
};
|
|
114
|
+
export type MandateListOptions = {
|
|
115
|
+
/**
|
|
116
|
+
* A plan's **public** id (`plan.publicId`) — the identifier the routes take —
|
|
117
|
+
* not the internal uuid. An unknown or foreign plan id matches nothing and
|
|
118
|
+
* yields an empty page rather than an error, so it cannot be used to probe
|
|
119
|
+
* which plans exist.
|
|
120
|
+
*/
|
|
121
|
+
planId?: string;
|
|
122
|
+
status?: MandateStatus;
|
|
123
|
+
/** 1–100. The server defaults to 25 when omitted. */
|
|
124
|
+
limit?: number;
|
|
125
|
+
/** Id of the **last** mandate of the previous page — see `list`. */
|
|
126
|
+
startingAfter?: string;
|
|
127
|
+
};
|
|
128
|
+
export type MandateListPage = {
|
|
129
|
+
/** Newest first (`createdAt` descending), at most `limit` entries. */
|
|
130
|
+
mandates: Mandate[];
|
|
131
|
+
/** True when another page exists behind this one. */
|
|
132
|
+
hasMore: boolean;
|
|
133
|
+
};
|
|
134
|
+
export interface MandatesResource {
|
|
135
|
+
/**
|
|
136
|
+
* Proposes a mandate. The returned mandate is inert (`pending_permit`) until
|
|
137
|
+
* the payer signs `permitTypedData` and that signature is submitted from the
|
|
138
|
+
* payer's frontend — see the note at the top of this module on `activate`.
|
|
139
|
+
*/
|
|
140
|
+
create(input: MandateCreateInput): Promise<MandateCreateResult>;
|
|
141
|
+
/** Explicit two-signature contract protocol. New capabilities remain gated by the deployment. */
|
|
142
|
+
createContractSubscription(input: ContractSubscriptionCreateInput): Promise<ContractSubscriptionCreateResult>;
|
|
143
|
+
/** Bounded per-use consent; every later charge needs a separate payer signature. */
|
|
144
|
+
createContractPerUse(input: ContractPerUseCreateInput): Promise<ContractPerUseCreateResult>;
|
|
145
|
+
proposeContractUsage(input: ContractUsageInput): Promise<ContractUsageCharge>;
|
|
146
|
+
submitContractUsage(proposal: ContractUsageCharge, signature: Hex): Promise<ContractUsageCharge>;
|
|
147
|
+
getContractUsage(proposal: ContractUsageCharge): Promise<ContractUsageCharge>;
|
|
148
|
+
/**
|
|
149
|
+
* One page of this account's mandates, newest first.
|
|
150
|
+
*
|
|
151
|
+
* This is how you find a mandate id without having kept the `mandate.active`
|
|
152
|
+
* webhook: a customer who wants to cancel can be served by listing, matching
|
|
153
|
+
* on `payerWallet` (or `subscriptionPlanId`), and calling `revoke`.
|
|
154
|
+
*
|
|
155
|
+
* **Paging is keyset-based**, so pass the id of the *last* mandate you
|
|
156
|
+
* received as `startingAfter` and repeat while `hasMore` is true:
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const all: Mandate[] = [];
|
|
160
|
+
* let startingAfter: string | undefined;
|
|
161
|
+
* for (;;) {
|
|
162
|
+
* const page = await genesispay.mandates.list({
|
|
163
|
+
* planId: "plan_1",
|
|
164
|
+
* status: "active",
|
|
165
|
+
* limit: 100,
|
|
166
|
+
* startingAfter,
|
|
167
|
+
* });
|
|
168
|
+
* all.push(...page.mandates);
|
|
169
|
+
* if (!page.hasMore) break;
|
|
170
|
+
* startingAfter = page.mandates[page.mandates.length - 1]!.id;
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* Do **not** pass the id of an arbitrary mandate: the cursor is a position in
|
|
175
|
+
* `(createdAt desc, id desc)`, not a filter. A `startingAfter` that names no
|
|
176
|
+
* mandate of this account is refused by the server (as a `GenesisPayConfigError`
|
|
177
|
+
* — it carries no field-level detail to raise as a validation error).
|
|
178
|
+
*/
|
|
179
|
+
list(opts?: MandateListOptions): Promise<MandateListPage>;
|
|
180
|
+
/** Entitlement check: is it active, and how much approval is left? */
|
|
181
|
+
retrieve(id: string): Promise<Mandate>;
|
|
182
|
+
/** Pulls a single charge. Signature-free — this is the metered path. */
|
|
183
|
+
charge(id: string, input: MandateChargeInput): Promise<MandateCharge>;
|
|
184
|
+
/** Requests cancellation. Contract mandates require confirmed payer revocation before authority is extinguished. */
|
|
185
|
+
revoke(id: string): Promise<Mandate>;
|
|
186
|
+
}
|
|
187
|
+
export declare function createMandatesResource(request: GenesisPayRequest): MandatesResource;
|
|
188
|
+
export declare function toMandate(raw: Record<string, unknown>): Mandate;
|
|
189
|
+
//# sourceMappingURL=mandates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandates.d.ts","sourceRoot":"","sources":["../src/mandates.ts"],"names":[],"mappings":"AAmBA,OAAO,EASL,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAA+D,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACrJ,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAoD,KAAK,yBAAyB,EAAE,KAAK,0BAA0B,EACxH,KAAK,+BAA+B,EAAE,KAAK,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAE9G,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,cAAc,CAAC;AAErD,MAAM,MAAM,aAAa,GACrB,gBAAgB,GAChB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,SAAS,GACT,WAAW,CAAC;AAEhB,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEjF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,gBAAgB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;IAC1D,gBAAgB,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,WAAW,CAAC;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAA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CAAC,OAAO,CAAC,CAAC;CACtC;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAgLnF;AAyCD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAkC/D"}
|
package/dist/mandates.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// `genesispay.mandates.*` — payment mandates over `/api/v1/mandates`.
|
|
2
|
+
//
|
|
3
|
+
// A mandate is a bounded, revocable spending approval a payer signs once (an
|
|
4
|
+
// EIP-2612 permit); the seller then pulls individual charges against it with no
|
|
5
|
+
// further signature. Funds stay in the payer's wallet until each pull.
|
|
6
|
+
//
|
|
7
|
+
// Deliberately absent: `mandates.activate`. Activation submits the payer's
|
|
8
|
+
// *signature* over the permit typed data — it is authorized by the payer's
|
|
9
|
+
// wallet, not by a seller API key, and belongs in the payer-facing frontend
|
|
10
|
+
// (`POST /api/v1/mandates/:id/activate`). `mandates.create` returns the
|
|
11
|
+
// `permitTypedData` for exactly that purpose: hand it to the payer's wallet,
|
|
12
|
+
// and post the resulting signature from there. Offering activate here would
|
|
13
|
+
// suggest a seller can switch on a mandate by itself, which is the one thing
|
|
14
|
+
// the design does not allow.
|
|
15
|
+
import { GenesisPayConfigError, GenesisPayValidationError, } from "./errors.js";
|
|
16
|
+
import { asRecord, optionalAmountString, optionalCount, optionalString, requiredString, toAmountString, toCount, oneOf, } from "./resource.js";
|
|
17
|
+
import { proposeContractUsage, submitContractUsage, getContractUsage } from "./contract-usage.js";
|
|
18
|
+
import { createContractPerUse, createContractSubscription } from "./contract-mandates.js";
|
|
19
|
+
function requireMandateChargeIdempotencyKey(value) {
|
|
20
|
+
if (typeof value !== "string" ||
|
|
21
|
+
value.toLowerCase() === "undefined" ||
|
|
22
|
+
!/^[A-Za-z0-9][A-Za-z0-9._:-]{7,199}$/.test(value)) {
|
|
23
|
+
throw new GenesisPayValidationError("mandates.charge requires an idempotencyKey with 8–200 safe characters.", [{ path: "idempotencyKey", message: "invalid idempotency key" }]);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
export function createMandatesResource(request) {
|
|
28
|
+
return {
|
|
29
|
+
createContractSubscription: (input) => createContractSubscription(request, input),
|
|
30
|
+
createContractPerUse: (input) => createContractPerUse(request, input),
|
|
31
|
+
proposeContractUsage: (input) => proposeContractUsage(request, input),
|
|
32
|
+
submitContractUsage: (proposal, signature) => submitContractUsage(request, proposal, signature),
|
|
33
|
+
getContractUsage: (proposal) => getContractUsage(request, proposal),
|
|
34
|
+
create: async (input) => {
|
|
35
|
+
const body = await request({
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/api/v1/mandates",
|
|
38
|
+
operation: "POST /api/v1/mandates",
|
|
39
|
+
action: "create a mandate",
|
|
40
|
+
body: {
|
|
41
|
+
payerWallet: input.payerWallet,
|
|
42
|
+
kind: input.kind,
|
|
43
|
+
allowance: input.allowance,
|
|
44
|
+
capPerCharge: input.capPerCharge,
|
|
45
|
+
...(input.amountPerPeriod ? { amountPerPeriod: input.amountPerPeriod } : {}),
|
|
46
|
+
...(input.periodDays === undefined ? {} : { periodDays: input.periodDays }),
|
|
47
|
+
...(input.asset ? { asset: input.asset } : {}),
|
|
48
|
+
...(input.destinationWallet
|
|
49
|
+
? { destinationWallet: input.destinationWallet }
|
|
50
|
+
: {}),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const record = asRecord(body);
|
|
54
|
+
const mandate = requireMandate(body, "POST /api/v1/mandates");
|
|
55
|
+
const permitTypedData = asRecord(record?.permitTypedData);
|
|
56
|
+
if (!permitTypedData ||
|
|
57
|
+
!asRecord(permitTypedData.message) ||
|
|
58
|
+
!asRecord(permitTypedData.domain)) {
|
|
59
|
+
// Without the typed data the payer cannot sign, so the mandate can never
|
|
60
|
+
// leave `pending_permit` — better to fail loudly than hand back a stub.
|
|
61
|
+
throw new GenesisPayConfigError(`GenesisPay POST /api/v1/mandates returned a mandate without permitTypedData: ${JSON.stringify(body)}`);
|
|
62
|
+
}
|
|
63
|
+
const spender = requiredString(record?.spender);
|
|
64
|
+
if (!spender) {
|
|
65
|
+
// Degrading to "" would hand back an address-shaped empty string for the
|
|
66
|
+
// account the allowance approves. Same reasoning as permitTypedData:
|
|
67
|
+
// a missing contract field is a broken response, not an old backend.
|
|
68
|
+
throw new GenesisPayConfigError(`GenesisPay POST /api/v1/mandates returned a mandate without a spender: ${JSON.stringify(body)}`);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
mandate,
|
|
72
|
+
// Verbatim: see the PermitTypedData docs — a signature is over these bytes.
|
|
73
|
+
permitTypedData: permitTypedData,
|
|
74
|
+
spender,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
list: async (opts = {}) => {
|
|
78
|
+
const query = new URLSearchParams();
|
|
79
|
+
if (opts.planId !== undefined) {
|
|
80
|
+
// An explicitly empty filter is refused rather than dropped: silently
|
|
81
|
+
// omitting it would widen the page from "one plan's subscribers" to
|
|
82
|
+
// every mandate on the account — the opposite of what was asked for.
|
|
83
|
+
query.set("planId", requireFilterValue(opts.planId, "planId"));
|
|
84
|
+
}
|
|
85
|
+
if (opts.status !== undefined)
|
|
86
|
+
query.set("status", opts.status);
|
|
87
|
+
if (opts.limit !== undefined)
|
|
88
|
+
query.set("limit", String(opts.limit));
|
|
89
|
+
if (opts.startingAfter !== undefined) {
|
|
90
|
+
// Same reasoning, sharper failure mode: dropping an empty cursor
|
|
91
|
+
// restarts at page 1, which turns a paging loop into an endless one.
|
|
92
|
+
query.set("startingAfter", requireFilterValue(opts.startingAfter, "startingAfter"));
|
|
93
|
+
}
|
|
94
|
+
const search = query.toString();
|
|
95
|
+
const body = await request({
|
|
96
|
+
path: search ? `/api/v1/mandates?${search}` : "/api/v1/mandates",
|
|
97
|
+
// Label without the query string: the operation is what failed, the
|
|
98
|
+
// filter values are not error detail (and `planId` is caller data).
|
|
99
|
+
operation: "GET /api/v1/mandates",
|
|
100
|
+
action: "list mandates",
|
|
101
|
+
});
|
|
102
|
+
const record = asRecord(body);
|
|
103
|
+
const mandates = record?.mandates;
|
|
104
|
+
if (!Array.isArray(mandates)) {
|
|
105
|
+
// A list endpoint answering 200 without a list is a broken contract,
|
|
106
|
+
// not an old backend. Returning [] would hide it as "no mandates yet"
|
|
107
|
+
// — and "this customer has no subscription" is exactly the wrong thing
|
|
108
|
+
// to conclude from a malformed response.
|
|
109
|
+
throw new GenesisPayConfigError(`GenesisPay GET /api/v1/mandates returned no mandates array: ${JSON.stringify(body)}`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
// Individual entries stay tolerant: one unusable row must not lose the
|
|
113
|
+
// rest of the page. A row without an id is dropped — it could not be
|
|
114
|
+
// revoked or retrieved anyway.
|
|
115
|
+
mandates: mandates
|
|
116
|
+
.map(asRecord)
|
|
117
|
+
.filter((raw) => raw !== null)
|
|
118
|
+
.filter((raw) => typeof raw.id === "string" && raw.id.length > 0)
|
|
119
|
+
.map(toMandate),
|
|
120
|
+
// Only an explicit `true` means "there is more". Anything else stops
|
|
121
|
+
// the loop above rather than spinning it against a backend that does
|
|
122
|
+
// not report the flag.
|
|
123
|
+
hasMore: record?.hasMore === true,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
retrieve: async (id) => {
|
|
127
|
+
const mandateId = requireMandateId(id, "mandates.retrieve");
|
|
128
|
+
const body = await request({
|
|
129
|
+
path: `/api/v1/mandates/${encodeURIComponent(mandateId)}`,
|
|
130
|
+
operation: `GET /api/v1/mandates/${mandateId}`,
|
|
131
|
+
action: `retrieve mandate "${mandateId}"`,
|
|
132
|
+
notFoundMessage: notFoundMessage(mandateId),
|
|
133
|
+
});
|
|
134
|
+
return requireMandate(body, `GET /api/v1/mandates/${mandateId}`);
|
|
135
|
+
},
|
|
136
|
+
charge: async (id, input) => {
|
|
137
|
+
const mandateId = requireMandateId(id, "mandates.charge");
|
|
138
|
+
const idempotencyKey = requireMandateChargeIdempotencyKey(input?.idempotencyKey);
|
|
139
|
+
const body = await request({
|
|
140
|
+
method: "POST",
|
|
141
|
+
path: `/api/v1/mandates/${encodeURIComponent(mandateId)}/charge`,
|
|
142
|
+
operation: `POST /api/v1/mandates/${mandateId}/charge`,
|
|
143
|
+
action: `charge mandate "${mandateId}"`,
|
|
144
|
+
notFoundMessage: notFoundMessage(mandateId),
|
|
145
|
+
headers: { "Idempotency-Key": idempotencyKey },
|
|
146
|
+
body: {
|
|
147
|
+
amount: input.amount,
|
|
148
|
+
...(input.resourceUrl ? { resourceUrl: input.resourceUrl } : {}),
|
|
149
|
+
...(input.description ? { description: input.description } : {}),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
const raw = asRecord(asRecord(body)?.charge);
|
|
153
|
+
if (!raw || typeof raw.id !== "string" || !raw.id) {
|
|
154
|
+
throw new GenesisPayConfigError(`GenesisPay POST /api/v1/mandates/${mandateId}/charge returned no charge: ${JSON.stringify(body)}`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
id: raw.id,
|
|
158
|
+
status: oneOf(raw.status, ["pending", "submitted", "settled", "failed"], "pending"),
|
|
159
|
+
amountMinor: toAmountString(raw.amountMinor),
|
|
160
|
+
txHash: optionalString(raw.txHash),
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
revoke: async (id) => {
|
|
164
|
+
const mandateId = requireMandateId(id, "mandates.revoke");
|
|
165
|
+
const body = await request({
|
|
166
|
+
method: "POST",
|
|
167
|
+
path: `/api/v1/mandates/${encodeURIComponent(mandateId)}/revoke`,
|
|
168
|
+
operation: `POST /api/v1/mandates/${mandateId}/revoke`,
|
|
169
|
+
action: `revoke mandate "${mandateId}"`,
|
|
170
|
+
notFoundMessage: notFoundMessage(mandateId),
|
|
171
|
+
});
|
|
172
|
+
return requireMandate(body, `POST /api/v1/mandates/${mandateId}/revoke`);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function notFoundMessage(id) {
|
|
177
|
+
return (`No GenesisPay mandate with id "${id}". Check the id and that it belongs to ` +
|
|
178
|
+
`the account this API key authenticates.`);
|
|
179
|
+
}
|
|
180
|
+
function requireFilterValue(value, field) {
|
|
181
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
182
|
+
if (!trimmed) {
|
|
183
|
+
throw new GenesisPayConfigError(`mandates.list({ ${field} }) was given an empty value. Omit ${field} ` +
|
|
184
|
+
`entirely to list without it — an empty string would silently change ` +
|
|
185
|
+
`which mandates come back.`);
|
|
186
|
+
}
|
|
187
|
+
return trimmed;
|
|
188
|
+
}
|
|
189
|
+
function requireMandateId(id, method) {
|
|
190
|
+
const mandateId = id?.trim();
|
|
191
|
+
if (!mandateId) {
|
|
192
|
+
throw new GenesisPayConfigError(`${method}(id) requires the mandate id returned by mandates.create().`);
|
|
193
|
+
}
|
|
194
|
+
return mandateId;
|
|
195
|
+
}
|
|
196
|
+
function requireMandate(body, operation) {
|
|
197
|
+
const raw = asRecord(asRecord(body)?.mandate);
|
|
198
|
+
if (!raw || typeof raw.id !== "string" || !raw.id) {
|
|
199
|
+
throw new GenesisPayConfigError(`GenesisPay ${operation} returned no mandate: ${JSON.stringify(body)}`);
|
|
200
|
+
}
|
|
201
|
+
return toMandate(raw);
|
|
202
|
+
}
|
|
203
|
+
export function toMandate(raw) {
|
|
204
|
+
return {
|
|
205
|
+
...(raw.protocol === "contract_mandate_v1" ? { protocol: "contract_mandate_v1",
|
|
206
|
+
activationStatus: oneOf(raw.activationStatus, ["proposed", "submitted", "confirmed"], "proposed"),
|
|
207
|
+
revocationStatus: oneOf(raw.revocationStatus, ["none", "requested", "confirmed"], "none"),
|
|
208
|
+
executor: requiredString(raw.executor), contractVersion: requiredString(raw.contractVersion) } : {}),
|
|
209
|
+
id: requiredString(raw.id),
|
|
210
|
+
kind: oneOf(raw.kind, ["per_use", "subscription"], "per_use"),
|
|
211
|
+
// An unknown status degrades to `pending_permit`, the inert state: guessing
|
|
212
|
+
// "active" for a status this SDK version has never heard of would invite a
|
|
213
|
+
// caller to serve something it should not.
|
|
214
|
+
status: oneOf(raw.status, ["pending_permit", "active", "past_due", "revoked", "expired", "cancelled"], "pending_permit"),
|
|
215
|
+
asset: oneOf(raw.asset, ["USDC", "EURC"], "USDC"),
|
|
216
|
+
chainId: toCount(raw.chainId),
|
|
217
|
+
payerWallet: requiredString(raw.payerWallet),
|
|
218
|
+
destinationWallet: requiredString(raw.destinationWallet),
|
|
219
|
+
subscriptionPlanId: optionalString(raw.subscriptionPlanId),
|
|
220
|
+
allowanceMinor: toAmountString(raw.allowanceMinor),
|
|
221
|
+
capPerChargeMinor: toAmountString(raw.capPerChargeMinor),
|
|
222
|
+
spentMinor: toAmountString(raw.spentMinor),
|
|
223
|
+
remainingMinor: toAmountString(raw.remainingMinor),
|
|
224
|
+
amountPerPeriodMinor: optionalAmountString(raw.amountPerPeriodMinor),
|
|
225
|
+
periodDays: optionalCount(raw.periodDays),
|
|
226
|
+
nextChargeAt: optionalString(raw.nextChargeAt),
|
|
227
|
+
permitDeadline: requiredString(raw.permitDeadline),
|
|
228
|
+
permitTxHash: optionalString(raw.permitTxHash),
|
|
229
|
+
createdAt: requiredString(raw.createdAt),
|
|
230
|
+
activatedAt: optionalString(raw.activatedAt),
|
|
231
|
+
revokedAt: optionalString(raw.revokedAt),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=mandates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandates.js","sourceRoot":"","sources":["../src/mandates.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,uEAAuE;AACvE,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,wEAAwE;AACxE,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,6BAA6B;AAE7B,O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oB,EAAE,oBAAoB,CAAC,GAAG,CAAC,oBAAoB,CAAC;QACpE,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC;QACzC,YAAY,EAAE,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC;QAC9C,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC;QAClD,YAAY,EAAE,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC;QAC9C,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC;QACxC,WAAW,EAAE,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;QAC5C,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EvmAddress } from "@genesis-tech/genesispay-protocol";
|
|
2
|
+
/** Networks the payment gate supports out of the box. */
|
|
3
|
+
export type PaymentGateNetwork = "base" | "base-sepolia";
|
|
4
|
+
export type PaymentGateNetworkConfig = {
|
|
5
|
+
network: PaymentGateNetwork;
|
|
6
|
+
chainId: number;
|
|
7
|
+
usdcAddress: EvmAddress;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolvePaymentGateNetwork(network: PaymentGateNetwork): PaymentGateNetworkConfig;
|
|
10
|
+
//# sourceMappingURL=networks.d.ts.map
|