@zucchinifi/dapp-sdk 0.1.5 → 0.1.7
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.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -5
- package/dist/index.mjs +25 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,7 @@ interface ZucchiniProvider {
|
|
|
33
33
|
spendable: string;
|
|
34
34
|
sapling: string;
|
|
35
35
|
orchard: string;
|
|
36
|
+
transparent: string;
|
|
36
37
|
}>;
|
|
37
38
|
getAddresses(): Promise<{
|
|
38
39
|
transparent: string;
|
|
@@ -49,6 +50,7 @@ interface ZucchiniProvider {
|
|
|
49
50
|
isLocked: boolean;
|
|
50
51
|
hasWallet: boolean;
|
|
51
52
|
}>;
|
|
53
|
+
shieldFunds(): Promise<string[]>;
|
|
52
54
|
on(event: string, callback: (data: any) => void): void;
|
|
53
55
|
off(event: string, callback: (data: any) => void): void;
|
|
54
56
|
disconnect(): Promise<void>;
|
|
@@ -101,6 +103,7 @@ interface SwapStatus {
|
|
|
101
103
|
depositAddress: string;
|
|
102
104
|
depositMemo?: string;
|
|
103
105
|
swaps?: any[];
|
|
106
|
+
deadline?: string;
|
|
104
107
|
}
|
|
105
108
|
interface Withdrawal {
|
|
106
109
|
id: string;
|
|
@@ -254,6 +257,7 @@ declare class ZucchiniSDK {
|
|
|
254
257
|
spendable: string;
|
|
255
258
|
sapling: string;
|
|
256
259
|
orchard: string;
|
|
260
|
+
transparent: string;
|
|
257
261
|
}>;
|
|
258
262
|
getAddresses(): Promise<{
|
|
259
263
|
sapling: string;
|
|
@@ -264,6 +268,10 @@ declare class ZucchiniSDK {
|
|
|
264
268
|
getNetwork(): Promise<{
|
|
265
269
|
network: 'main' | 'test';
|
|
266
270
|
}>;
|
|
271
|
+
/**
|
|
272
|
+
* Shield transparent funds.
|
|
273
|
+
*/
|
|
274
|
+
shieldFunds(): Promise<string[]>;
|
|
267
275
|
/**
|
|
268
276
|
* Send a generic request to the wallet.
|
|
269
277
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ interface ZucchiniProvider {
|
|
|
33
33
|
spendable: string;
|
|
34
34
|
sapling: string;
|
|
35
35
|
orchard: string;
|
|
36
|
+
transparent: string;
|
|
36
37
|
}>;
|
|
37
38
|
getAddresses(): Promise<{
|
|
38
39
|
transparent: string;
|
|
@@ -49,6 +50,7 @@ interface ZucchiniProvider {
|
|
|
49
50
|
isLocked: boolean;
|
|
50
51
|
hasWallet: boolean;
|
|
51
52
|
}>;
|
|
53
|
+
shieldFunds(): Promise<string[]>;
|
|
52
54
|
on(event: string, callback: (data: any) => void): void;
|
|
53
55
|
off(event: string, callback: (data: any) => void): void;
|
|
54
56
|
disconnect(): Promise<void>;
|
|
@@ -101,6 +103,7 @@ interface SwapStatus {
|
|
|
101
103
|
depositAddress: string;
|
|
102
104
|
depositMemo?: string;
|
|
103
105
|
swaps?: any[];
|
|
106
|
+
deadline?: string;
|
|
104
107
|
}
|
|
105
108
|
interface Withdrawal {
|
|
106
109
|
id: string;
|
|
@@ -254,6 +257,7 @@ declare class ZucchiniSDK {
|
|
|
254
257
|
spendable: string;
|
|
255
258
|
sapling: string;
|
|
256
259
|
orchard: string;
|
|
260
|
+
transparent: string;
|
|
257
261
|
}>;
|
|
258
262
|
getAddresses(): Promise<{
|
|
259
263
|
sapling: string;
|
|
@@ -264,6 +268,10 @@ declare class ZucchiniSDK {
|
|
|
264
268
|
getNetwork(): Promise<{
|
|
265
269
|
network: 'main' | 'test';
|
|
266
270
|
}>;
|
|
271
|
+
/**
|
|
272
|
+
* Shield transparent funds.
|
|
273
|
+
*/
|
|
274
|
+
shieldFunds(): Promise<string[]>;
|
|
267
275
|
/**
|
|
268
276
|
* Send a generic request to the wallet.
|
|
269
277
|
*/
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,9 @@ function toZats(amount) {
|
|
|
66
66
|
return BigInt(total);
|
|
67
67
|
}
|
|
68
68
|
function fromZats(amount) {
|
|
69
|
+
if (typeof amount === "string" && amount.includes(".")) {
|
|
70
|
+
return amount;
|
|
71
|
+
}
|
|
69
72
|
const zats = BigInt(amount).toString();
|
|
70
73
|
const padded = zats.padStart(9, "0");
|
|
71
74
|
const whole = padded.slice(0, -8);
|
|
@@ -208,13 +211,19 @@ function parseUnifiedAddress(unifiedAddress) {
|
|
|
208
211
|
switch (typeCode) {
|
|
209
212
|
case TYPE_P2PKH:
|
|
210
213
|
if (length !== 20) throw new Error("Invalid P2PKH length");
|
|
211
|
-
const p2pkhPrefix = hrp === "u" ? [28, 184] : [29, 37];
|
|
212
|
-
|
|
214
|
+
const p2pkhPrefix = new Uint8Array(hrp === "u" ? [28, 184] : [29, 37]);
|
|
215
|
+
const p2pkhCombined = new Uint8Array(p2pkhPrefix.length + receiverData.length);
|
|
216
|
+
p2pkhCombined.set(p2pkhPrefix);
|
|
217
|
+
p2pkhCombined.set(receiverData, p2pkhPrefix.length);
|
|
218
|
+
receivers.push({ type: "p2pkh", typeCode, data: receiverData, address: import_bs58check.default.encode(p2pkhCombined) });
|
|
213
219
|
break;
|
|
214
220
|
case TYPE_P2SH:
|
|
215
221
|
if (length !== 20) throw new Error("Invalid P2SH length");
|
|
216
|
-
const p2shPrefix = hrp === "u" ? [28, 189] : [28, 186];
|
|
217
|
-
|
|
222
|
+
const p2shPrefix = new Uint8Array(hrp === "u" ? [28, 189] : [28, 186]);
|
|
223
|
+
const p2shCombined = new Uint8Array(p2shPrefix.length + receiverData.length);
|
|
224
|
+
p2shCombined.set(p2shPrefix);
|
|
225
|
+
p2shCombined.set(receiverData, p2shPrefix.length);
|
|
226
|
+
receivers.push({ type: "p2sh", typeCode, data: receiverData, address: import_bs58check.default.encode(p2shCombined) });
|
|
218
227
|
break;
|
|
219
228
|
case TYPE_SAPLING:
|
|
220
229
|
if (length !== 43) throw new Error("Invalid Sapling length");
|
|
@@ -740,7 +749,10 @@ var ZucchiniSDK = class {
|
|
|
740
749
|
const res = await fetch(`${this.apiUrl}/swap/status?${params.toString()}`);
|
|
741
750
|
const data = await res.json();
|
|
742
751
|
if (data.error) throw new Error(data.error);
|
|
743
|
-
return
|
|
752
|
+
return {
|
|
753
|
+
...data,
|
|
754
|
+
deadline: data.deadline || data.quoteResponse?.quote?.deadline
|
|
755
|
+
};
|
|
744
756
|
},
|
|
745
757
|
getWithdrawals: async (depositAddress, options = {}) => {
|
|
746
758
|
const params = new URLSearchParams({ depositAddress });
|
|
@@ -833,6 +845,14 @@ var ZucchiniSDK = class {
|
|
|
833
845
|
method: "getNetwork"
|
|
834
846
|
});
|
|
835
847
|
}
|
|
848
|
+
/**
|
|
849
|
+
* Shield transparent funds.
|
|
850
|
+
*/
|
|
851
|
+
async shieldFunds() {
|
|
852
|
+
return this.request({
|
|
853
|
+
method: "shieldFunds"
|
|
854
|
+
});
|
|
855
|
+
}
|
|
836
856
|
/**
|
|
837
857
|
* Send a generic request to the wallet.
|
|
838
858
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,9 @@ function toZats(amount) {
|
|
|
17
17
|
return BigInt(total);
|
|
18
18
|
}
|
|
19
19
|
function fromZats(amount) {
|
|
20
|
+
if (typeof amount === "string" && amount.includes(".")) {
|
|
21
|
+
return amount;
|
|
22
|
+
}
|
|
20
23
|
const zats = BigInt(amount).toString();
|
|
21
24
|
const padded = zats.padStart(9, "0");
|
|
22
25
|
const whole = padded.slice(0, -8);
|
|
@@ -159,13 +162,19 @@ function parseUnifiedAddress(unifiedAddress) {
|
|
|
159
162
|
switch (typeCode) {
|
|
160
163
|
case TYPE_P2PKH:
|
|
161
164
|
if (length !== 20) throw new Error("Invalid P2PKH length");
|
|
162
|
-
const p2pkhPrefix = hrp === "u" ? [28, 184] : [29, 37];
|
|
163
|
-
|
|
165
|
+
const p2pkhPrefix = new Uint8Array(hrp === "u" ? [28, 184] : [29, 37]);
|
|
166
|
+
const p2pkhCombined = new Uint8Array(p2pkhPrefix.length + receiverData.length);
|
|
167
|
+
p2pkhCombined.set(p2pkhPrefix);
|
|
168
|
+
p2pkhCombined.set(receiverData, p2pkhPrefix.length);
|
|
169
|
+
receivers.push({ type: "p2pkh", typeCode, data: receiverData, address: bs58check.encode(p2pkhCombined) });
|
|
164
170
|
break;
|
|
165
171
|
case TYPE_P2SH:
|
|
166
172
|
if (length !== 20) throw new Error("Invalid P2SH length");
|
|
167
|
-
const p2shPrefix = hrp === "u" ? [28, 189] : [28, 186];
|
|
168
|
-
|
|
173
|
+
const p2shPrefix = new Uint8Array(hrp === "u" ? [28, 189] : [28, 186]);
|
|
174
|
+
const p2shCombined = new Uint8Array(p2shPrefix.length + receiverData.length);
|
|
175
|
+
p2shCombined.set(p2shPrefix);
|
|
176
|
+
p2shCombined.set(receiverData, p2shPrefix.length);
|
|
177
|
+
receivers.push({ type: "p2sh", typeCode, data: receiverData, address: bs58check.encode(p2shCombined) });
|
|
169
178
|
break;
|
|
170
179
|
case TYPE_SAPLING:
|
|
171
180
|
if (length !== 43) throw new Error("Invalid Sapling length");
|
|
@@ -691,7 +700,10 @@ var ZucchiniSDK = class {
|
|
|
691
700
|
const res = await fetch(`${this.apiUrl}/swap/status?${params.toString()}`);
|
|
692
701
|
const data = await res.json();
|
|
693
702
|
if (data.error) throw new Error(data.error);
|
|
694
|
-
return
|
|
703
|
+
return {
|
|
704
|
+
...data,
|
|
705
|
+
deadline: data.deadline || data.quoteResponse?.quote?.deadline
|
|
706
|
+
};
|
|
695
707
|
},
|
|
696
708
|
getWithdrawals: async (depositAddress, options = {}) => {
|
|
697
709
|
const params = new URLSearchParams({ depositAddress });
|
|
@@ -784,6 +796,14 @@ var ZucchiniSDK = class {
|
|
|
784
796
|
method: "getNetwork"
|
|
785
797
|
});
|
|
786
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Shield transparent funds.
|
|
801
|
+
*/
|
|
802
|
+
async shieldFunds() {
|
|
803
|
+
return this.request({
|
|
804
|
+
method: "shieldFunds"
|
|
805
|
+
});
|
|
806
|
+
}
|
|
787
807
|
/**
|
|
788
808
|
* Send a generic request to the wallet.
|
|
789
809
|
*/
|