@zucchinifi/dapp-sdk 0.1.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.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.zucchini = exports.ZucchiniSDK = void 0;
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./zip321"), exports);
21
+ __exportStar(require("./qrcode"), exports);
22
+ __exportStar(require("./unified_address"), exports);
23
+ class ZucchiniSDK {
24
+ /**
25
+ * Check if the Zucchini extension is installed and the provider is injected.
26
+ */
27
+ get isInstalled() {
28
+ return typeof window !== 'undefined' && !!window.zucchini;
29
+ }
30
+ /**
31
+ * Get the provider instance.
32
+ * @throws Error if Zucchini is not installed.
33
+ */
34
+ get provider() {
35
+ if (!this.isInstalled) {
36
+ throw new Error("Zucchini Wallet is not installed");
37
+ }
38
+ return window.zucchini;
39
+ }
40
+ /**
41
+ * Connect to the wallet.
42
+ * Requests permission from the user to access their accounts.
43
+ * @param permissions List of permissions to request.
44
+ */
45
+ async connect(permissions = []) {
46
+ return this.request({ method: 'connect', params: { permissions } });
47
+ }
48
+ /**
49
+ * Send a transaction.
50
+ * Requires 'send_transaction' permission.
51
+ */
52
+ async sendTransaction(args) {
53
+ return this.request({
54
+ method: 'sendTransaction',
55
+ params: args
56
+ });
57
+ }
58
+ async getBalance() {
59
+ return this.request({
60
+ method: 'getBalance'
61
+ });
62
+ }
63
+ async getAddresses() {
64
+ return this.request({
65
+ method: 'getAddresses'
66
+ });
67
+ }
68
+ async getNetwork() {
69
+ return this.request({
70
+ method: 'getNetwork'
71
+ });
72
+ }
73
+ /**
74
+ * Send a generic request to the wallet.
75
+ */
76
+ async request(args) {
77
+ return this.provider.request(args);
78
+ }
79
+ on(event, handler) {
80
+ this.provider.on(event, handler);
81
+ }
82
+ off(event, handler) {
83
+ this.provider.off(event, handler);
84
+ }
85
+ async disconnect() {
86
+ return this.request({ method: 'disconnect' });
87
+ }
88
+ async isConnected() {
89
+ try {
90
+ return await this.request({ method: 'isConnected' });
91
+ }
92
+ catch (e) {
93
+ return false;
94
+ }
95
+ }
96
+ async getUniversalViewingKey() {
97
+ return this.request({ method: 'getUniversalViewingKey' });
98
+ }
99
+ async getAllViewingKeys() {
100
+ return this.request({ method: 'getAllViewingKeys' });
101
+ }
102
+ async getWalletStatus() {
103
+ return this.request({ method: 'getWalletStatus' });
104
+ }
105
+ async getTokens() {
106
+ const API_BASE_URL = 'https://api.zucchinifi.xyz';
107
+ const res = await fetch(`${API_BASE_URL}/tokens`);
108
+ if (!res.ok)
109
+ throw new Error("Failed to fetch tokens");
110
+ return res.json();
111
+ }
112
+ async getSwapQuote(args) {
113
+ const API_BASE_URL = 'https://api.zucchinifi.xyz';
114
+ const { from, to, amount, recipient, refundAddress } = args;
115
+ const params = new URLSearchParams({
116
+ from,
117
+ to,
118
+ amount,
119
+ recipient: recipient || '0x0000000000000000000000000000000000000000',
120
+ refundAddress: refundAddress || '0x0000000000000000000000000000000000000000',
121
+ dry: 'true'
122
+ });
123
+ const res = await fetch(`${API_BASE_URL}/swap/quote?${params.toString()}`);
124
+ const data = await res.json();
125
+ if (data.error) {
126
+ throw new Error(data.error);
127
+ }
128
+ return data.quote;
129
+ }
130
+ }
131
+ exports.ZucchiniSDK = ZucchiniSDK;
132
+ exports.zucchini = new ZucchiniSDK();