@zkp2p/sdk 0.3.0 → 0.3.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/README.md +6 -6
- package/dist/index.cjs +137 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +137 -41
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +4 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +4 -10
- package/dist/react.d.ts +4 -10
- package/dist/react.mjs +4 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{vaultUtils-sodi4Xx-.d.mts → vaultUtils-DATqc35J.d.mts} +52 -35
- package/dist/{vaultUtils-sodi4Xx-.d.ts → vaultUtils-DATqc35J.d.ts} +52 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Stable TypeScript SDK for trustless fiat-to-crypto on Base. ZKP2P combines escrowed on-chain settlement, TLS attestations for payment verification, and API/indexer helpers so makers, takers, wallets, and embedded ramps can ship production-grade fiat liquidity flows without building their own contract or indexing stack.
|
|
8
8
|
|
|
9
|
-
Current version: `0.
|
|
9
|
+
Current version: `0.3.1`
|
|
10
10
|
|
|
11
11
|
## Why This SDK
|
|
12
12
|
|
|
@@ -73,13 +73,13 @@ const client = new Zkp2pClient({
|
|
|
73
73
|
- Supported runtime environments: `'production'`, `'preproduction'`, `'staging'`
|
|
74
74
|
- `runtimeEnv` default: `'production'`
|
|
75
75
|
- `rpcUrl`: optional RPC URL override (defaults to wallet's chain RPC)
|
|
76
|
-
- `apiKey`: optional curator-issued API key — used when the SDK auto-fetches `signalIntent()` gating signatures and enables richer authenticated `getQuote()` responses with maker
|
|
76
|
+
- `apiKey`: optional curator-issued API key — used when the SDK auto-fetches `signalIntent()` gating signatures and enables richer authenticated `getQuote()` responses with resolved maker payee details (`offchainId`, `telegramUsername`, `metadata`)
|
|
77
77
|
- `authorizationToken` / `getAuthorizationToken`: optional bearer auth for hybrid client and indexer flows
|
|
78
78
|
- `indexerApiKey`: optional `x-api-key` for indexer proxy auth
|
|
79
79
|
- `indexerUrl` and `baseApiUrl`: override defaults when you are targeting custom deployments
|
|
80
80
|
- `timeouts`: `{ api?: number }` — API timeout in milliseconds (default 15000)
|
|
81
81
|
|
|
82
|
-
**No API key is required to get started.** `createDeposit`, `registerPayeeDetails`, `getQuote`, `getTakerTier`, and the rest of the SDK work without `apiKey` or `authorizationToken`. The main tradeoff is that `signalIntent()` only auto-fetches a gating service signature from curator `/v3/intent` when `apiKey` or `authorizationToken` is available; otherwise provide both `gatingServiceSignature` and `signatureExpiration` manually if your integration needs one. Authenticated quotes also include
|
|
82
|
+
**No API key is required to get started.** `createDeposit`, `registerPayeeDetails`, `getQuote`, `getTakerTier`, and the rest of the SDK work without `apiKey` or `authorizationToken`. The main tradeoff is that `signalIntent()` only auto-fetches a gating service signature from curator `/v3/intent/sign` when `apiKey` or `authorizationToken` is available; otherwise provide both `gatingServiceSignature` and `signatureExpiration` manually if your integration needs one. Authenticated quotes also include resolved maker payee details (`offchainId`, `telegramUsername`, `metadata`).
|
|
83
83
|
|
|
84
84
|
Indexer defaults by environment:
|
|
85
85
|
|
|
@@ -95,7 +95,7 @@ Indexer defaults by environment:
|
|
|
95
95
|
| Payment methods and currencies | `addPaymentMethods`, `removePaymentMethod`, `setPaymentMethodActive`, `addCurrencies`, `removeCurrency`, `deactivateCurrency`, `pruneExpiredIntents` |
|
|
96
96
|
| Intents | `signalIntent`, `fulfillIntent`, `cancelIntent`, `releaseFundsToPayer`, `getFulfillIntentInputs` |
|
|
97
97
|
| Prepared transactions | `client.prepareCreateDeposit(...)`, `client.signalIntent.prepare(...)`, `client.fulfillIntent.prepare(...)`, `client.setVaultFee.prepare(...)`, and equivalent prepare flows across the rest of the prepareable write surface |
|
|
98
|
-
| Payee and quote APIs | `registerPayeeDetails`, `resolvePayeeHash`, `getQuote`, `getTakerTier`
|
|
98
|
+
| Payee and quote APIs | `registerPayeeDetails`, `resolvePayeeHash`, `getQuote`, `getQuotesBestByPlatform`, `getTakerTier` |
|
|
99
99
|
| Delegation and hooks | `setDelegate`, `removeDelegate`, `setRateManager`, `clearRateManager`, `setDepositRateManager`, `clearDepositRateManager`, `setDepositPreIntentHook`, `setDepositWhitelistHook` |
|
|
100
100
|
| Vault / DRM | `createRateManager`, `setVaultMinRate`, `setVaultMinRatesBatch`, `setVaultFee`, `setVaultConfig`, `getDepositRateManager`, `getManagerFee`, `getEffectiveRate` |
|
|
101
101
|
| Oracle config | `setOracleRateConfig`, `setOracleRateConfigBatch`, `removeOracleRateConfig`, `updateCurrencyConfigBatch`, `deactivateCurrenciesBatch`, `supportsInlineOracleRateConfig`, `validateOracleFeedsOnChain` |
|
|
@@ -156,7 +156,7 @@ const payeeHash = await client.resolvePayeeHash(
|
|
|
156
156
|
);
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
`getQuote()` returns available liquidity plus payee details when authenticated. `getTakerTier()` returns limits and cooldown data for taker UX.
|
|
159
|
+
`getQuote()` returns available liquidity plus payee details when authenticated. Use `getQuotesBestByPlatform()` to fetch the best quote per supported payment platform in a single call (handy for cross-platform comparison UIs). `getTakerTier()` returns limits and cooldown data for taker UX.
|
|
160
160
|
|
|
161
161
|
## Signal, Fulfill, and Release Intents
|
|
162
162
|
|
|
@@ -519,7 +519,7 @@ The SDK ships currency metadata for 34 fiat currencies:
|
|
|
519
519
|
|
|
520
520
|
## Supported Payment Platforms
|
|
521
521
|
|
|
522
|
-
`wise`, `venmo`, `revolut`, `cashapp`, `mercadopago`, `zelle`, `paypal`, `monzo`, `chime`, `luxon`, `n26`
|
|
522
|
+
`wise`, `venmo`, `revolut`, `cashapp`, `mercadopago`, `zelle`, `paypal`, `monzo`, `chime`, `luxon`, `n26`, `alipay`
|
|
523
523
|
|
|
524
524
|
## Attribution (ERC-8021)
|
|
525
525
|
|
package/dist/index.cjs
CHANGED
|
@@ -1460,7 +1460,7 @@ function createHeaders(apiKey, authorizationToken) {
|
|
|
1460
1460
|
return headers2;
|
|
1461
1461
|
}
|
|
1462
1462
|
async function apiSignIntentV3(request, opts) {
|
|
1463
|
-
const url = `${opts.baseApiUrl.replace(/\/$/, "")}/v3/intent`;
|
|
1463
|
+
const url = `${opts.baseApiUrl.replace(/\/$/, "")}/v3/intent/sign`;
|
|
1464
1464
|
const json = await withRetry(
|
|
1465
1465
|
async () => {
|
|
1466
1466
|
let res;
|
|
@@ -1472,7 +1472,7 @@ async function apiSignIntentV3(request, opts) {
|
|
|
1472
1472
|
});
|
|
1473
1473
|
} catch (error) {
|
|
1474
1474
|
throw new exports.NetworkError("Failed to connect to API server", {
|
|
1475
|
-
endpoint: "/v3/intent",
|
|
1475
|
+
endpoint: "/v3/intent/sign",
|
|
1476
1476
|
error
|
|
1477
1477
|
});
|
|
1478
1478
|
}
|
|
@@ -1490,7 +1490,7 @@ async function apiSignIntentV3(request, opts) {
|
|
|
1490
1490
|
const expStr = json?.responseObject?.intentData?.signatureExpiration ?? json?.responseObject?.signatureExpiration;
|
|
1491
1491
|
const preIntentHookData = json?.responseObject?.intentData?.preIntentHookData ?? json?.responseObject?.preIntentHookData;
|
|
1492
1492
|
const referralFees = json?.responseObject?.intentData?.referralFees ?? json?.responseObject?.referralFees;
|
|
1493
|
-
if (!sig || !expStr) throw new Error("v3/intent missing signature or expiration");
|
|
1493
|
+
if (!sig || !expStr) throw new Error("v3/intent/sign missing signature or expiration");
|
|
1494
1494
|
return {
|
|
1495
1495
|
signature: sig,
|
|
1496
1496
|
signatureExpiration: BigInt(expStr),
|
|
@@ -1967,13 +1967,13 @@ var IntentOperations = class {
|
|
|
1967
1967
|
if (response.referralFees !== void 0) {
|
|
1968
1968
|
referralFees = response.referralFees.map((referralFee) => {
|
|
1969
1969
|
if (!isValidReferrerFeeRecipient(referralFee.recipient)) {
|
|
1970
|
-
throw new Error("v3/intent returned invalid referral fee recipient");
|
|
1970
|
+
throw new Error("v3/intent/sign returned invalid referral fee recipient");
|
|
1971
1971
|
}
|
|
1972
1972
|
let fee;
|
|
1973
1973
|
try {
|
|
1974
1974
|
fee = BigInt(referralFee.fee);
|
|
1975
1975
|
} catch {
|
|
1976
|
-
throw new Error("v3/intent returned non-integer referral fee value");
|
|
1976
|
+
throw new Error("v3/intent/sign returned non-integer referral fee value");
|
|
1977
1977
|
}
|
|
1978
1978
|
return {
|
|
1979
1979
|
recipient: referralFee.recipient,
|
|
@@ -5950,7 +5950,7 @@ function convertIndexerDepositToLegacyApiDeposit(deposit) {
|
|
|
5950
5950
|
}
|
|
5951
5951
|
async function apiPostDepositDetails(req, baseApiUrl, timeoutMs, _apiKey, _authToken) {
|
|
5952
5952
|
return apiFetch({
|
|
5953
|
-
url: `${withApiBase(baseApiUrl)}/
|
|
5953
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/create`,
|
|
5954
5954
|
method: "POST",
|
|
5955
5955
|
body: req,
|
|
5956
5956
|
timeoutMs
|
|
@@ -5983,7 +5983,8 @@ async function apiGetQuote(req, baseApiUrl, timeoutMs, apiKey, authToken) {
|
|
|
5983
5983
|
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
5984
5984
|
amount: void 0,
|
|
5985
5985
|
isExactFiat: void 0,
|
|
5986
|
-
quotesToReturn: void 0
|
|
5986
|
+
quotesToReturn: void 0,
|
|
5987
|
+
includePrivateOrderbooks: req.includePrivateOrderbooks
|
|
5987
5988
|
};
|
|
5988
5989
|
Object.keys(requestBody).forEach((k) => requestBody[k] === void 0 && delete requestBody[k]);
|
|
5989
5990
|
return apiFetch({
|
|
@@ -6020,7 +6021,7 @@ async function apiGetQuotesBestByPlatform(req, baseApiUrl, timeoutMs, apiKey, au
|
|
|
6020
6021
|
}
|
|
6021
6022
|
async function apiGetPayeeDetails(req, apiKey, baseApiUrl, authToken, timeoutMs) {
|
|
6022
6023
|
return apiFetch({
|
|
6023
|
-
url: `${baseApiUrl.replace(/\/$/, "")}/
|
|
6024
|
+
url: `${baseApiUrl.replace(/\/$/, "")}/v2/makers/${req.processorName}/${req.hashedOnchainId}`,
|
|
6024
6025
|
method: "GET",
|
|
6025
6026
|
apiKey,
|
|
6026
6027
|
authToken,
|
|
@@ -6029,7 +6030,7 @@ async function apiGetPayeeDetails(req, apiKey, baseApiUrl, authToken, timeoutMs)
|
|
|
6029
6030
|
}
|
|
6030
6031
|
async function apiValidatePayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
6031
6032
|
const data = await apiFetch({
|
|
6032
|
-
url: `${baseApiUrl.replace(/\/$/, "")}/
|
|
6033
|
+
url: `${baseApiUrl.replace(/\/$/, "")}/v2/makers/validate`,
|
|
6033
6034
|
method: "POST",
|
|
6034
6035
|
body: req,
|
|
6035
6036
|
timeoutMs
|
|
@@ -6228,6 +6229,95 @@ var ERC20_ABI = [
|
|
|
6228
6229
|
];
|
|
6229
6230
|
|
|
6230
6231
|
// src/client/Zkp2pClient.ts
|
|
6232
|
+
function isStringRecord(value) {
|
|
6233
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
6234
|
+
return false;
|
|
6235
|
+
}
|
|
6236
|
+
return Object.values(value).every((entry) => typeof entry === "string");
|
|
6237
|
+
}
|
|
6238
|
+
function normalizeTelegramUsername(value) {
|
|
6239
|
+
if (typeof value !== "string") {
|
|
6240
|
+
return value === null ? null : null;
|
|
6241
|
+
}
|
|
6242
|
+
const normalized = value.trim();
|
|
6243
|
+
return normalized.length > 0 ? normalized : null;
|
|
6244
|
+
}
|
|
6245
|
+
function extractLegacyQuotePayeeData(depositData) {
|
|
6246
|
+
if (!depositData || typeof depositData !== "object" || Array.isArray(depositData)) {
|
|
6247
|
+
return void 0;
|
|
6248
|
+
}
|
|
6249
|
+
const stringEntries = Object.entries(depositData).filter(
|
|
6250
|
+
(entry) => typeof entry[1] === "string" && entry[1].trim().length > 0
|
|
6251
|
+
);
|
|
6252
|
+
const telegramUsername = stringEntries.find(([key]) => key === "telegramUsername")?.[1] ?? null;
|
|
6253
|
+
const identifierEntries = stringEntries.filter(([key]) => key !== "telegramUsername");
|
|
6254
|
+
const [primaryEntry, ...metadataEntries] = identifierEntries;
|
|
6255
|
+
if (!primaryEntry) {
|
|
6256
|
+
return void 0;
|
|
6257
|
+
}
|
|
6258
|
+
return {
|
|
6259
|
+
offchainId: primaryEntry[1],
|
|
6260
|
+
telegramUsername,
|
|
6261
|
+
metadata: metadataEntries.length > 0 ? Object.fromEntries(metadataEntries) : null
|
|
6262
|
+
};
|
|
6263
|
+
}
|
|
6264
|
+
function normalizeQuotePayeeData(maker) {
|
|
6265
|
+
const legacy = extractLegacyQuotePayeeData(maker?.depositData);
|
|
6266
|
+
const offchainId = typeof maker?.offchainId === "string" && maker.offchainId.trim().length > 0 ? maker.offchainId : legacy?.offchainId;
|
|
6267
|
+
if (!offchainId) {
|
|
6268
|
+
return void 0;
|
|
6269
|
+
}
|
|
6270
|
+
return {
|
|
6271
|
+
offchainId,
|
|
6272
|
+
telegramUsername: normalizeTelegramUsername(maker?.telegramUsername) ?? legacy?.telegramUsername ?? null,
|
|
6273
|
+
metadata: isStringRecord(maker?.metadata) ? maker.metadata : legacy?.metadata ?? null
|
|
6274
|
+
};
|
|
6275
|
+
}
|
|
6276
|
+
function normalizePayeeDataInputItem(raw) {
|
|
6277
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
6278
|
+
return null;
|
|
6279
|
+
}
|
|
6280
|
+
const candidate = raw;
|
|
6281
|
+
if (typeof candidate.offchainId === "string" && candidate.offchainId.trim().length > 0) {
|
|
6282
|
+
return candidate;
|
|
6283
|
+
}
|
|
6284
|
+
const legacy = extractLegacyQuotePayeeData(raw);
|
|
6285
|
+
if (!legacy) {
|
|
6286
|
+
return null;
|
|
6287
|
+
}
|
|
6288
|
+
return {
|
|
6289
|
+
offchainId: legacy.offchainId,
|
|
6290
|
+
telegramUsername: legacy.telegramUsername,
|
|
6291
|
+
metadata: legacy.metadata
|
|
6292
|
+
};
|
|
6293
|
+
}
|
|
6294
|
+
function resolvePayeeDataInput(params, methodName) {
|
|
6295
|
+
const payeeData = params.payeeData ?? params.depositData;
|
|
6296
|
+
if (!Array.isArray(payeeData)) {
|
|
6297
|
+
throw new Error(`${methodName} requires payeeData`);
|
|
6298
|
+
}
|
|
6299
|
+
const normalized = payeeData.map((item, index) => {
|
|
6300
|
+
const result = normalizePayeeDataInputItem(item);
|
|
6301
|
+
if (!result) {
|
|
6302
|
+
throw new Error(
|
|
6303
|
+
`${methodName}: payeeData[${index}] must include a non-empty offchainId or a recognizable legacy identifier`
|
|
6304
|
+
);
|
|
6305
|
+
}
|
|
6306
|
+
return result;
|
|
6307
|
+
});
|
|
6308
|
+
return normalized;
|
|
6309
|
+
}
|
|
6310
|
+
function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
6311
|
+
if (!payeeData || typeof payeeData.offchainId !== "string" || payeeData.offchainId.length === 0) {
|
|
6312
|
+
throw new Error(`payeeData[${index}] must include a non-empty offchainId`);
|
|
6313
|
+
}
|
|
6314
|
+
return {
|
|
6315
|
+
processorName,
|
|
6316
|
+
offchainId: payeeData.offchainId,
|
|
6317
|
+
telegramUsername: payeeData.telegramUsername,
|
|
6318
|
+
metadata: payeeData.metadata
|
|
6319
|
+
};
|
|
6320
|
+
}
|
|
6231
6321
|
var Zkp2pClient = class {
|
|
6232
6322
|
/**
|
|
6233
6323
|
* Creates a new Zkp2pClient instance.
|
|
@@ -6774,7 +6864,7 @@ var Zkp2pClient = class {
|
|
|
6774
6864
|
* sending fiat payment to the deposit's payee.
|
|
6775
6865
|
*
|
|
6776
6866
|
* If `gatingServiceSignature` is not provided, the SDK will automatically
|
|
6777
|
-
* fetch one from curator `/v3/intent` when `apiKey` or `authorizationToken`
|
|
6867
|
+
* fetch one from curator `/v3/intent/sign` when `apiKey` or `authorizationToken`
|
|
6778
6868
|
* is available. Otherwise you must provide `gatingServiceSignature` and
|
|
6779
6869
|
* `signatureExpiration` yourself.
|
|
6780
6870
|
*
|
|
@@ -8088,31 +8178,29 @@ var Zkp2pClient = class {
|
|
|
8088
8178
|
* register maker payment details with the curator service.
|
|
8089
8179
|
*
|
|
8090
8180
|
* @param params.processorNames - Payment platforms (e.g., ['wise', 'revolut'])
|
|
8091
|
-
* @param params.
|
|
8181
|
+
* @param params.payeeData - Payee details per processor (e.g., [{ offchainId: 'you@example.com' }]). Required when the SDK needs to register payee details with the curator.
|
|
8092
8182
|
* @returns The posted deposit details and their corresponding hashed on-chain IDs
|
|
8093
8183
|
*
|
|
8094
8184
|
* @example
|
|
8095
8185
|
* ```typescript
|
|
8096
8186
|
* const { hashedOnchainIds } = await client.registerPayeeDetails({
|
|
8097
8187
|
* processorNames: ['wise'],
|
|
8098
|
-
*
|
|
8188
|
+
* payeeData: [{ offchainId: 'you@example.com' }],
|
|
8099
8189
|
* });
|
|
8100
8190
|
* // Then pass hashedOnchainIds to createDeposit
|
|
8101
8191
|
* ```
|
|
8102
8192
|
*/
|
|
8103
8193
|
async registerPayeeDetails(params) {
|
|
8194
|
+
const payeeData = resolvePayeeDataInput(params, "registerPayeeDetails");
|
|
8104
8195
|
if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
|
|
8105
8196
|
throw new Error("processorNames must be a non-empty array");
|
|
8106
8197
|
}
|
|
8107
|
-
if (params.processorNames.length !==
|
|
8108
|
-
throw new Error("processorNames and
|
|
8198
|
+
if (params.processorNames.length !== payeeData.length) {
|
|
8199
|
+
throw new Error("processorNames and payeeData length mismatch");
|
|
8109
8200
|
}
|
|
8110
8201
|
const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
|
|
8111
8202
|
const depositDetails = params.processorNames.map(
|
|
8112
|
-
(processorName, index) => (
|
|
8113
|
-
processorName,
|
|
8114
|
-
depositData: params.depositData[index] || {}
|
|
8115
|
-
})
|
|
8203
|
+
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
8116
8204
|
);
|
|
8117
8205
|
const apiResponses = await Promise.all(
|
|
8118
8206
|
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
@@ -8139,16 +8227,17 @@ var Zkp2pClient = class {
|
|
|
8139
8227
|
* @param params.amount - Total deposit amount in token units (6 decimals for USDC)
|
|
8140
8228
|
* @param params.intentAmountRange - Min/max amount per intent
|
|
8141
8229
|
* @param params.processorNames - Payment platforms to accept (e.g., ['wise', 'revolut'])
|
|
8142
|
-
* @param params.
|
|
8230
|
+
* @param params.payeeData - Payee details per processor (e.g., [{ offchainId: 'you@example.com' }])
|
|
8143
8231
|
* @param params.conversionRates - Conversion rates per processor, grouped by currency
|
|
8144
8232
|
* @param params.payeeDetailsHashes - Pre-computed hashed on-chain IDs (from registerPayeeDetails). When provided, skips the curator API call entirely.
|
|
8145
8233
|
* @param params.delegate - Optional delegate address that can manage the deposit
|
|
8146
8234
|
* @param params.intentGuardian - Optional guardian for intent approval
|
|
8147
8235
|
* @param params.retainOnEmpty - Keep deposit active when balance reaches zero
|
|
8148
8236
|
* @param params.txOverrides - Optional viem transaction overrides
|
|
8149
|
-
* @returns The deposit details posted to API and the transaction hash
|
|
8237
|
+
* @returns The deposit details posted to API (empty when payee registration is skipped) and the transaction hash
|
|
8150
8238
|
*
|
|
8151
|
-
* @throws Error if processorNames,
|
|
8239
|
+
* @throws Error if processorNames, payeeData, and conversionRates lengths don't match
|
|
8240
|
+
* @throws Error if payeeData is missing and neither payeeDetailsHashes nor full payment method overrides are provided
|
|
8152
8241
|
* @throws Error if a currency is not supported by the specified processor
|
|
8153
8242
|
*
|
|
8154
8243
|
* @example
|
|
@@ -8159,7 +8248,7 @@ var Zkp2pClient = class {
|
|
|
8159
8248
|
* amount: 1000_000000n,
|
|
8160
8249
|
* intentAmountRange: { min: 10_000000n, max: 500_000000n },
|
|
8161
8250
|
* processorNames: ['wise'],
|
|
8162
|
-
*
|
|
8251
|
+
* payeeData: [{ offchainId: 'you@example.com' }],
|
|
8163
8252
|
* conversionRates: [[
|
|
8164
8253
|
* { currency: 'USD', conversionRate: '1020000000000000000' }, // 1.02
|
|
8165
8254
|
* { currency: 'EUR', conversionRate: '1100000000000000000' }, // 1.10
|
|
@@ -8192,24 +8281,30 @@ var Zkp2pClient = class {
|
|
|
8192
8281
|
};
|
|
8193
8282
|
}
|
|
8194
8283
|
async prepareCreateDepositInternal(params) {
|
|
8284
|
+
const hasOverrides = Boolean(
|
|
8285
|
+
params.paymentMethodsOverride || params.paymentMethodDataOverride || params.currenciesOverride
|
|
8286
|
+
);
|
|
8287
|
+
const payeeDetailsHashes = params.payeeDetailsHashes;
|
|
8288
|
+
const hasPayeeHashes = payeeDetailsHashes !== void 0;
|
|
8289
|
+
const shouldResolvePayeeData = params.payeeData !== void 0 || params.depositData !== void 0;
|
|
8290
|
+
const payeeData = shouldResolvePayeeData ? resolvePayeeDataInput(params, "createDeposit") : null;
|
|
8195
8291
|
if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
|
|
8196
8292
|
throw new Error("processorNames must be a non-empty array");
|
|
8197
8293
|
}
|
|
8198
8294
|
if (params.processorNames.length !== params.conversionRates.length) {
|
|
8199
8295
|
throw new Error("processorNames and conversionRates length mismatch");
|
|
8200
8296
|
}
|
|
8201
|
-
if (params.processorNames.length !==
|
|
8202
|
-
throw new Error("processorNames and
|
|
8297
|
+
if (payeeData && params.processorNames.length !== payeeData.length) {
|
|
8298
|
+
throw new Error("processorNames and payeeData length mismatch");
|
|
8203
8299
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
);
|
|
8300
|
+
if (!hasOverrides && !hasPayeeHashes && !payeeData) {
|
|
8301
|
+
throw new Error(
|
|
8302
|
+
"createDeposit requires payeeData unless payeeDetailsHashes or full payment method overrides are provided"
|
|
8303
|
+
);
|
|
8304
|
+
}
|
|
8305
|
+
const depositDetails = payeeData ? params.processorNames.map(
|
|
8306
|
+
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
8307
|
+
) : [];
|
|
8213
8308
|
let paymentMethods;
|
|
8214
8309
|
let paymentMethodData;
|
|
8215
8310
|
let currencies;
|
|
@@ -8234,11 +8329,11 @@ var Zkp2pClient = class {
|
|
|
8234
8329
|
);
|
|
8235
8330
|
const intentGatingService = getGatingServiceAddress(this.chainId, this.runtimeEnv);
|
|
8236
8331
|
let hashedOnchainIds;
|
|
8237
|
-
if (
|
|
8238
|
-
if (
|
|
8332
|
+
if (payeeDetailsHashes !== void 0) {
|
|
8333
|
+
if (payeeDetailsHashes.length !== params.processorNames.length) {
|
|
8239
8334
|
throw new Error("payeeDetailsHashes length must match processorNames length");
|
|
8240
8335
|
}
|
|
8241
|
-
hashedOnchainIds =
|
|
8336
|
+
hashedOnchainIds = payeeDetailsHashes;
|
|
8242
8337
|
} else {
|
|
8243
8338
|
const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
|
|
8244
8339
|
const apiResponses = await Promise.all(
|
|
@@ -8439,8 +8534,9 @@ var Zkp2pClient = class {
|
|
|
8439
8534
|
const quotes = quote?.responseObject?.quotes ?? [];
|
|
8440
8535
|
for (const q of quotes) {
|
|
8441
8536
|
const maker = q?.maker;
|
|
8442
|
-
|
|
8443
|
-
|
|
8537
|
+
const payeeData = normalizeQuotePayeeData(maker);
|
|
8538
|
+
if (payeeData && typeof q === "object") {
|
|
8539
|
+
q.payeeData = payeeData;
|
|
8444
8540
|
}
|
|
8445
8541
|
}
|
|
8446
8542
|
return appendReferrerFeeDisplayFields(quote, referrerFeeConfig);
|
|
@@ -8485,11 +8581,11 @@ var Zkp2pClient = class {
|
|
|
8485
8581
|
...quote.responseObject,
|
|
8486
8582
|
platformQuotes: (quote.responseObject?.platformQuotes ?? []).map((platformQuote) => {
|
|
8487
8583
|
const bestQuote = platformQuote?.bestQuote;
|
|
8488
|
-
const
|
|
8489
|
-
if (!bestQuote || !
|
|
8584
|
+
const payeeData = normalizeQuotePayeeData(bestQuote?.maker);
|
|
8585
|
+
if (!bestQuote || !payeeData) return platformQuote;
|
|
8490
8586
|
return {
|
|
8491
8587
|
...platformQuote,
|
|
8492
|
-
bestQuote: { ...bestQuote, payeeData
|
|
8588
|
+
bestQuote: { ...bestQuote, payeeData }
|
|
8493
8589
|
};
|
|
8494
8590
|
})
|
|
8495
8591
|
}
|