@branta-ops/branta 0.0.4 → 0.0.6

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.
@@ -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) {
@@ -62,6 +72,9 @@ export class V2BrantaClient {
62
72
  if (brantaId && brantaSecret) {
63
73
  return this.getZKPayment(brantaId, brantaSecret, options);
64
74
  }
75
+ if (url.protocol === 'bitcoin:') {
76
+ return this.getPayments(this._normalizeAddress(url.pathname), options);
77
+ }
65
78
  if (url.protocol === 'http:' || url.protocol === 'https:') {
66
79
  const baseUrl = this._resolveBaseUrl(options);
67
80
  if (baseUrl && new URL(baseUrl).origin === url.origin) {
@@ -91,6 +104,13 @@ export class V2BrantaClient {
91
104
  const response = await httpClient.get("/v2/api-keys/health-check");
92
105
  return response.ok;
93
106
  }
107
+ _buildVerifyUrl(baseUrl, address, secret) {
108
+ const encoded = encodeURIComponent(address);
109
+ if (secret) {
110
+ return `${baseUrl}/v2/zk-verify/${encoded}#secret=${secret}`;
111
+ }
112
+ return `${baseUrl}/v2/verify/${encoded}`;
113
+ }
94
114
  _resolveBaseUrl(options) {
95
115
  const baseUrl = options?.baseUrl ?? this._defaultOptions?.baseUrl;
96
116
  return typeof baseUrl === 'string' ? baseUrl : baseUrl?.url ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@branta-ops/branta",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A JavaScript SDK for the Branta API",
5
5
  "homepage": "https://github.com/BrantaOps/branta-js#readme",
6
6
  "bugs": {