@branta-ops/branta 0.0.4 → 0.0.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.
- package/dist/v2/client.d.ts +2 -0
- package/dist/v2/client.js +17 -0
- package/package.json +1 -1
package/dist/v2/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface Payment {
|
|
|
8
8
|
ttl?: number;
|
|
9
9
|
description?: string;
|
|
10
10
|
metadata?: Record<string, string>;
|
|
11
|
+
verify_url?: string;
|
|
11
12
|
}
|
|
12
13
|
interface PaymentResponse extends Payment {
|
|
13
14
|
createdAt: Date;
|
|
@@ -30,6 +31,7 @@ export declare class V2BrantaClient {
|
|
|
30
31
|
addZKPayment(payment: Payment, options?: BrantaClientOptions | null): Promise<ZKPaymentResult>;
|
|
31
32
|
getPaymentsByQRCode(qrText: string, options?: BrantaClientOptions | null): Promise<Payment[]>;
|
|
32
33
|
isApiKeyValid(options?: BrantaClientOptions | null): Promise<boolean>;
|
|
34
|
+
private _buildVerifyUrl;
|
|
33
35
|
private _resolveBaseUrl;
|
|
34
36
|
private _normalizeAddress;
|
|
35
37
|
private _createClient;
|
package/dist/v2/client.js
CHANGED
|
@@ -11,6 +11,10 @@ export class V2BrantaClient {
|
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
13
13
|
const data = await response.json();
|
|
14
|
+
const baseUrl = this._resolveBaseUrl(options);
|
|
15
|
+
for (const payment of data) {
|
|
16
|
+
payment.verify_url = this._buildVerifyUrl(baseUrl, address);
|
|
17
|
+
}
|
|
14
18
|
return data;
|
|
15
19
|
}
|
|
16
20
|
async getZKPayment(address, secret, options = null) {
|
|
@@ -22,6 +26,10 @@ export class V2BrantaClient {
|
|
|
22
26
|
destination.value = await AesEncryption.decrypt(destination.value, secret);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
29
|
+
const baseUrl = this._resolveBaseUrl(options);
|
|
30
|
+
for (const payment of payments) {
|
|
31
|
+
payment.verify_url = this._buildVerifyUrl(baseUrl, address, secret);
|
|
32
|
+
}
|
|
25
33
|
return payments;
|
|
26
34
|
}
|
|
27
35
|
async addPayment(payment, options = null) {
|
|
@@ -34,6 +42,7 @@ export class V2BrantaClient {
|
|
|
34
42
|
}
|
|
35
43
|
const responseBody = await response.text();
|
|
36
44
|
const paymentResponse = JSON.parse(responseBody);
|
|
45
|
+
paymentResponse.verify_url = this._buildVerifyUrl(httpClient.baseURL, payment.destinations[0].value);
|
|
37
46
|
const verifyLink = httpClient.baseURL + "/v2/verify/" + encodeURIComponent(payment.destinations[0].value);
|
|
38
47
|
return { payment: paymentResponse, verifyLink };
|
|
39
48
|
}
|
|
@@ -47,6 +56,7 @@ export class V2BrantaClient {
|
|
|
47
56
|
const responsePayment = (await this.addPayment(payment, options));
|
|
48
57
|
responsePayment.secret = secret;
|
|
49
58
|
responsePayment.verifyLink = responsePayment.verifyLink.replace('verify', 'zk-verify') + "#secret=" + secret;
|
|
59
|
+
responsePayment.payment.verify_url = this._buildVerifyUrl(this._resolveBaseUrl(options), payment.destinations[0].value, secret);
|
|
50
60
|
return responsePayment;
|
|
51
61
|
}
|
|
52
62
|
async getPaymentsByQRCode(qrText, options = null) {
|
|
@@ -91,6 +101,13 @@ export class V2BrantaClient {
|
|
|
91
101
|
const response = await httpClient.get("/v2/api-keys/health-check");
|
|
92
102
|
return response.ok;
|
|
93
103
|
}
|
|
104
|
+
_buildVerifyUrl(baseUrl, address, secret) {
|
|
105
|
+
const encoded = encodeURIComponent(address);
|
|
106
|
+
if (secret) {
|
|
107
|
+
return `${baseUrl}/v2/zk-verify/${encoded}#secret=${secret}`;
|
|
108
|
+
}
|
|
109
|
+
return `${baseUrl}/v2/verify/${encoded}`;
|
|
110
|
+
}
|
|
94
111
|
_resolveBaseUrl(options) {
|
|
95
112
|
const baseUrl = options?.baseUrl ?? this._defaultOptions?.baseUrl;
|
|
96
113
|
return typeof baseUrl === 'string' ? baseUrl : baseUrl?.url ?? '';
|