@zkp2p/sdk 0.4.0-rc.3 → 0.4.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/dist/index.cjs +121 -32
- 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 +121 -32
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{vaultUtils-CSwo6wIa.d.mts → vaultUtils-CyPf4QGT.d.mts} +48 -12
- package/dist/{vaultUtils-CSwo6wIa.d.ts → vaultUtils-CyPf4QGT.d.ts} +48 -12
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42284,15 +42284,19 @@ init_errors();
|
|
|
42284
42284
|
init_errors();
|
|
42285
42285
|
function parseAPIError(response, responseText) {
|
|
42286
42286
|
let message = `Request failed: ${response.statusText}`;
|
|
42287
|
+
let parsedBody;
|
|
42287
42288
|
try {
|
|
42288
|
-
|
|
42289
|
-
if (
|
|
42290
|
-
|
|
42289
|
+
parsedBody = responseText ? JSON.parse(responseText) : void 0;
|
|
42290
|
+
if (parsedBody && typeof parsedBody === "object") {
|
|
42291
|
+
const body = parsedBody;
|
|
42292
|
+
if (body.error || body.message) {
|
|
42293
|
+
message = body.error || body.message;
|
|
42294
|
+
}
|
|
42291
42295
|
}
|
|
42292
42296
|
} catch {
|
|
42293
42297
|
if (responseText && responseText.length < 200) message = responseText;
|
|
42294
42298
|
}
|
|
42295
|
-
return new exports.APIError(message, response.status, { url: response.url });
|
|
42299
|
+
return new exports.APIError(message, response.status, { url: response.url, responseBody: parsedBody });
|
|
42296
42300
|
}
|
|
42297
42301
|
async function withRetry(fn, maxRetries = 3, delayMs = 1e3, timeoutMs) {
|
|
42298
42302
|
let lastErr;
|
|
@@ -42370,6 +42374,47 @@ init_errors();
|
|
|
42370
42374
|
function headers() {
|
|
42371
42375
|
return { "Content-Type": "application/json" };
|
|
42372
42376
|
}
|
|
42377
|
+
function isPayeeBoundSellerCredentialUploadInput(payload) {
|
|
42378
|
+
return typeof payload.payeeId === "string";
|
|
42379
|
+
}
|
|
42380
|
+
function isWiseCredentialUploadInput(payload) {
|
|
42381
|
+
return typeof payload.sessionMaterial?.apiToken === "string";
|
|
42382
|
+
}
|
|
42383
|
+
async function createEncryptedSellerCredentialUploadForPlatform({
|
|
42384
|
+
attestationServiceUrl,
|
|
42385
|
+
attestationRuntime,
|
|
42386
|
+
payload,
|
|
42387
|
+
platform,
|
|
42388
|
+
timeoutMs
|
|
42389
|
+
}) {
|
|
42390
|
+
if (platform === "wise") {
|
|
42391
|
+
if (!isWiseCredentialUploadInput(payload)) {
|
|
42392
|
+
throw new Error("apiToken is required for wise seller credential uploads");
|
|
42393
|
+
}
|
|
42394
|
+
return zkp2pAttestation.createEncryptedSellerCredentialUpload({
|
|
42395
|
+
attestationServiceUrl,
|
|
42396
|
+
platform: "wise",
|
|
42397
|
+
sessionMaterial: payload.sessionMaterial,
|
|
42398
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
42399
|
+
...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
|
|
42400
|
+
...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
|
|
42401
|
+
...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
|
|
42402
|
+
});
|
|
42403
|
+
}
|
|
42404
|
+
if (!isPayeeBoundSellerCredentialUploadInput(payload)) {
|
|
42405
|
+
throw new Error(`payeeId is required for ${platform} seller credential uploads`);
|
|
42406
|
+
}
|
|
42407
|
+
return zkp2pAttestation.createEncryptedSellerCredentialUpload({
|
|
42408
|
+
attestationServiceUrl,
|
|
42409
|
+
platform,
|
|
42410
|
+
payeeId: payload.payeeId,
|
|
42411
|
+
sessionMaterial: payload.sessionMaterial,
|
|
42412
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
42413
|
+
...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
|
|
42414
|
+
...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
|
|
42415
|
+
...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
|
|
42416
|
+
});
|
|
42417
|
+
}
|
|
42373
42418
|
async function apiCreatePaymentAttestation(payload, attestationServiceUrl, platform, actionType) {
|
|
42374
42419
|
return withRetry(async () => {
|
|
42375
42420
|
let res;
|
|
@@ -42397,14 +42442,12 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
|
|
|
42397
42442
|
return withRetry(
|
|
42398
42443
|
async () => {
|
|
42399
42444
|
const requestFetch = attestationRuntime?.fetch ?? fetch;
|
|
42400
|
-
const encryptedUpload = await
|
|
42445
|
+
const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
|
|
42401
42446
|
attestationServiceUrl,
|
|
42402
|
-
|
|
42403
|
-
|
|
42404
|
-
|
|
42405
|
-
|
|
42406
|
-
...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
|
|
42407
|
-
...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
|
|
42447
|
+
attestationRuntime,
|
|
42448
|
+
payload,
|
|
42449
|
+
platform,
|
|
42450
|
+
timeoutMs
|
|
42408
42451
|
});
|
|
42409
42452
|
let res;
|
|
42410
42453
|
try {
|
|
@@ -47078,13 +47121,14 @@ async function apiGetTakerTier(req, apiKey, baseApiUrl, timeoutMs) {
|
|
|
47078
47121
|
timeoutMs
|
|
47079
47122
|
});
|
|
47080
47123
|
}
|
|
47081
|
-
async function apiUploadSellerCredential(
|
|
47124
|
+
async function apiUploadSellerCredential(processorName, payeeDetails, bundle, baseApiUrl, timeoutMs) {
|
|
47125
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
47126
|
+
payeeDetails
|
|
47127
|
+
)}/seller-credential`;
|
|
47082
47128
|
return apiFetch({
|
|
47083
|
-
url: `${withApiBase(baseApiUrl)}
|
|
47129
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
47084
47130
|
method: "POST",
|
|
47085
47131
|
body: bundle,
|
|
47086
|
-
apiKey,
|
|
47087
|
-
authToken,
|
|
47088
47132
|
timeoutMs
|
|
47089
47133
|
});
|
|
47090
47134
|
}
|
|
@@ -47099,10 +47143,16 @@ async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApi
|
|
|
47099
47143
|
});
|
|
47100
47144
|
}
|
|
47101
47145
|
async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey, authToken) {
|
|
47146
|
+
const body = {
|
|
47147
|
+
txId: req.txId,
|
|
47148
|
+
chainId: req.chainId,
|
|
47149
|
+
intent: req.intent,
|
|
47150
|
+
...req.metadata !== void 0 ? { metadata: req.metadata } : {}
|
|
47151
|
+
};
|
|
47102
47152
|
return apiFetch({
|
|
47103
47153
|
url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
|
|
47104
47154
|
method: "POST",
|
|
47105
|
-
body
|
|
47155
|
+
body,
|
|
47106
47156
|
apiKey,
|
|
47107
47157
|
authToken,
|
|
47108
47158
|
timeoutMs
|
|
@@ -49711,9 +49761,10 @@ var Zkp2pClient = class {
|
|
|
49711
49761
|
* seller-automated-release availability is governed by curator's probe/revalidation state
|
|
49712
49762
|
* rather than these timestamps.
|
|
49713
49763
|
*
|
|
49714
|
-
*
|
|
49715
|
-
*
|
|
49716
|
-
*
|
|
49764
|
+
* Create a signed seller credential bundle with attestation-service and store it via
|
|
49765
|
+
* curator's platform plus hashed payee-details route. Session-cookie platforms register
|
|
49766
|
+
* or recover the payee maker row before upload; Wise derives the payee hash inside the enclave
|
|
49767
|
+
* from the submitted Personal API Token.
|
|
49717
49768
|
*/
|
|
49718
49769
|
async uploadSellerCredential(params, opts) {
|
|
49719
49770
|
const baseApiUrl = this.stripTrailingSlash(
|
|
@@ -49723,32 +49774,69 @@ var Zkp2pClient = class {
|
|
|
49723
49774
|
const attestationServiceUrl = this.stripTrailingSlash(
|
|
49724
49775
|
opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
|
|
49725
49776
|
);
|
|
49726
|
-
const
|
|
49727
|
-
|
|
49728
|
-
sessionMaterial: params.sessionMaterial
|
|
49729
|
-
};
|
|
49730
|
-
const bundleResponse = opts?.attestationRuntime ? await apiCreateSellerCredentialBundle(
|
|
49731
|
-
uploadPayload,
|
|
49777
|
+
const createBundle = (uploadPayload2) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
|
|
49778
|
+
uploadPayload2,
|
|
49732
49779
|
attestationServiceUrl,
|
|
49733
49780
|
params.platform,
|
|
49734
49781
|
timeoutMs,
|
|
49735
49782
|
opts.attestationRuntime
|
|
49736
|
-
) :
|
|
49737
|
-
|
|
49783
|
+
) : apiCreateSellerCredentialBundle(
|
|
49784
|
+
uploadPayload2,
|
|
49738
49785
|
attestationServiceUrl,
|
|
49739
49786
|
params.platform,
|
|
49740
49787
|
timeoutMs
|
|
49741
49788
|
);
|
|
49789
|
+
if (params.platform === "wise") {
|
|
49790
|
+
const bundleResponse2 = await createBundle({
|
|
49791
|
+
sessionMaterial: params.sessionMaterial
|
|
49792
|
+
});
|
|
49793
|
+
if (!bundleResponse2.success || !bundleResponse2.responseObject) {
|
|
49794
|
+
throw new Error(bundleResponse2.message || "Failed to create seller credential bundle");
|
|
49795
|
+
}
|
|
49796
|
+
return apiUploadSellerCredential(
|
|
49797
|
+
params.platform,
|
|
49798
|
+
bundleResponse2.responseObject.payeeIdHash,
|
|
49799
|
+
bundleResponse2.responseObject,
|
|
49800
|
+
baseApiUrl,
|
|
49801
|
+
timeoutMs
|
|
49802
|
+
);
|
|
49803
|
+
}
|
|
49804
|
+
const registeredPayeePayload = {
|
|
49805
|
+
offchainId: params.offchainId,
|
|
49806
|
+
processorName: params.platform
|
|
49807
|
+
};
|
|
49808
|
+
if (params.telegramUsername !== void 0) {
|
|
49809
|
+
registeredPayeePayload.telegramUsername = params.telegramUsername;
|
|
49810
|
+
}
|
|
49811
|
+
if (params.metadata !== void 0) {
|
|
49812
|
+
registeredPayeePayload.metadata = params.metadata;
|
|
49813
|
+
}
|
|
49814
|
+
const registeredPayeeResponse = await apiPostDepositDetails(
|
|
49815
|
+
registeredPayeePayload,
|
|
49816
|
+
baseApiUrl,
|
|
49817
|
+
timeoutMs
|
|
49818
|
+
);
|
|
49819
|
+
if (!registeredPayeeResponse.success || !registeredPayeeResponse.responseObject) {
|
|
49820
|
+
throw new Error(registeredPayeeResponse.message || "Failed to register seller payee details");
|
|
49821
|
+
}
|
|
49822
|
+
const uploadPayload = {
|
|
49823
|
+
payeeId: params.payeeId,
|
|
49824
|
+
sessionMaterial: params.sessionMaterial
|
|
49825
|
+
};
|
|
49826
|
+
const bundleResponse = await createBundle(uploadPayload);
|
|
49742
49827
|
if (!bundleResponse.success || !bundleResponse.responseObject) {
|
|
49743
49828
|
throw new Error(bundleResponse.message || "Failed to create seller credential bundle");
|
|
49744
49829
|
}
|
|
49830
|
+
const registeredPayee = registeredPayeeResponse.responseObject;
|
|
49831
|
+
if (registeredPayee.hashedOnchainId.toLowerCase() !== bundleResponse.responseObject.payeeIdHash.toLowerCase()) {
|
|
49832
|
+
throw new Error("Seller credential payee hash does not match registered payee details");
|
|
49833
|
+
}
|
|
49745
49834
|
return apiUploadSellerCredential(
|
|
49746
|
-
params.
|
|
49835
|
+
params.platform,
|
|
49836
|
+
registeredPayee.hashedOnchainId,
|
|
49747
49837
|
bundleResponse.responseObject,
|
|
49748
49838
|
baseApiUrl,
|
|
49749
|
-
timeoutMs
|
|
49750
|
-
this.apiKey,
|
|
49751
|
-
this.authorizationToken
|
|
49839
|
+
timeoutMs
|
|
49752
49840
|
);
|
|
49753
49841
|
}
|
|
49754
49842
|
/**
|
|
@@ -49789,7 +49877,8 @@ var Zkp2pClient = class {
|
|
|
49789
49877
|
{
|
|
49790
49878
|
txId: params.txId,
|
|
49791
49879
|
chainId: params.chainId,
|
|
49792
|
-
intent: params.intent
|
|
49880
|
+
intent: params.intent,
|
|
49881
|
+
...params.metadata !== void 0 ? { metadata: params.metadata } : {}
|
|
49793
49882
|
},
|
|
49794
49883
|
baseApiUrl,
|
|
49795
49884
|
timeoutMs,
|