@zucchinifi/dapp-sdk 0.1.0 → 0.1.2
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/README.md +21 -3
- package/dist/index.d.mts +67 -16
- package/dist/index.d.ts +241 -9
- package/dist/index.js +828 -108
- package/dist/index.mjs +105 -28
- package/dist/types.d.ts +40 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Zucchini SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@zucchinifi/dapp-sdk)
|
|
4
|
+
|
|
5
|
+
The Zucchini SDK provides a simple way for DApps to interact with the Zucchini Wallet extension and Mini-App.
|
|
6
|
+
|
|
7
|
+
**Zucchini Wallet is now live!**
|
|
8
|
+
- Desktop: [Chrome Web Store](https://chromewebstore.google.com/detail/zucchini/khaifnjdhfaadfhgbilokobnaalmimad)
|
|
9
|
+
- Mobile: Coming soon to the **Base App** as a Farcaster Mini-App.
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
@@ -152,15 +158,27 @@ Fetch supported tokens and get swap quotes.
|
|
|
152
158
|
const tokens = await zucchini.getTokens();
|
|
153
159
|
|
|
154
160
|
// Get a swap quote
|
|
155
|
-
const quote = await zucchini.
|
|
161
|
+
const quote = await zucchini.swap.getQuote({
|
|
156
162
|
from: 'ZEC',
|
|
157
|
-
to: '
|
|
163
|
+
to: 'nep141:usd-coin.omft.near', // Using asset ID or symbol
|
|
158
164
|
amount: '100000000', // Amount in base units
|
|
159
165
|
recipient: '0x...', // Destination address
|
|
160
166
|
refundAddress: '0x...' // Refund address (if needed)
|
|
161
167
|
});
|
|
162
168
|
```
|
|
163
169
|
|
|
170
|
+
## Explorer
|
|
171
|
+
|
|
172
|
+
Query transaction history from the Zucchini Explorer.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// Get transactions
|
|
176
|
+
const transactions = await zucchini.explorer.getTransactions({
|
|
177
|
+
limit: 10,
|
|
178
|
+
offset: 0
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
164
182
|
## Events
|
|
165
183
|
|
|
166
184
|
Listen for account and chain changes.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
type Permission = 'view_balance' | 'view_addresses' | 'send_transaction' | 'view_keys';
|
|
2
|
+
interface ZucchiniConfig {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
dev?: boolean;
|
|
5
|
+
}
|
|
2
6
|
interface RequestArguments {
|
|
3
7
|
method: string;
|
|
4
8
|
params?: any;
|
|
@@ -56,24 +60,21 @@ interface DetailedKey {
|
|
|
56
60
|
}
|
|
57
61
|
interface Token {
|
|
58
62
|
symbol: string;
|
|
59
|
-
|
|
60
|
-
icon: string;
|
|
63
|
+
assetId: string;
|
|
61
64
|
decimals: number;
|
|
62
|
-
|
|
65
|
+
blockchain: string;
|
|
66
|
+
price?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
icon?: string;
|
|
63
69
|
}
|
|
64
70
|
interface SwapQuote {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
amountOut: string;
|
|
69
|
-
depositAddress?: string;
|
|
70
|
-
depositMemo?: string;
|
|
71
|
-
timeEstimate: number;
|
|
72
|
-
};
|
|
73
|
-
quoteRequest: {
|
|
74
|
-
deadline: string;
|
|
75
|
-
};
|
|
71
|
+
amountOutFormatted: string;
|
|
72
|
+
amountIn: string;
|
|
73
|
+
amountOut: string;
|
|
76
74
|
depositAddress?: string;
|
|
75
|
+
depositMemo?: string;
|
|
76
|
+
timeEstimate: number;
|
|
77
|
+
deadline?: string;
|
|
77
78
|
}
|
|
78
79
|
interface QuoteRequestArgs {
|
|
79
80
|
from: string;
|
|
@@ -81,6 +82,35 @@ interface QuoteRequestArgs {
|
|
|
81
82
|
amount: string;
|
|
82
83
|
recipient?: string;
|
|
83
84
|
refundAddress?: string;
|
|
85
|
+
dry?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface DepositSubmitArgs {
|
|
88
|
+
transactionHash: string;
|
|
89
|
+
depositAddress: string;
|
|
90
|
+
memo?: string;
|
|
91
|
+
userAccount?: string;
|
|
92
|
+
}
|
|
93
|
+
interface SwapStatus {
|
|
94
|
+
status: 'KNOWN_DEPOSIT_TX' | 'PENDING_DEPOSIT' | 'INCOMPLETE_DEPOSIT' | 'PROCESSING' | 'SUCCESS' | 'REFUNDED' | 'FAILED';
|
|
95
|
+
depositAddress: string;
|
|
96
|
+
depositMemo?: string;
|
|
97
|
+
swaps?: any[];
|
|
98
|
+
}
|
|
99
|
+
interface Withdrawal {
|
|
100
|
+
id: string;
|
|
101
|
+
status: string;
|
|
102
|
+
amount: string;
|
|
103
|
+
assetId: string;
|
|
104
|
+
timestamp: string;
|
|
105
|
+
}
|
|
106
|
+
interface ExplorerTransaction {
|
|
107
|
+
depositAddressAndMemo: string;
|
|
108
|
+
status: string;
|
|
109
|
+
originAsset: string;
|
|
110
|
+
destinationAsset: string;
|
|
111
|
+
amountIn: string;
|
|
112
|
+
amountOut: string;
|
|
113
|
+
timestamp: string;
|
|
84
114
|
}
|
|
85
115
|
declare global {
|
|
86
116
|
interface Window {
|
|
@@ -184,6 +214,13 @@ interface Receiver {
|
|
|
184
214
|
declare function parseUnifiedAddress(unifiedAddress: string): UnifiedAddressResult;
|
|
185
215
|
|
|
186
216
|
declare class ZucchiniSDK {
|
|
217
|
+
private _apiUrl;
|
|
218
|
+
constructor(config?: ZucchiniConfig);
|
|
219
|
+
/**
|
|
220
|
+
* Configure the SDK at runtime.
|
|
221
|
+
*/
|
|
222
|
+
configure(config: ZucchiniConfig): void;
|
|
223
|
+
get apiUrl(): string;
|
|
187
224
|
/**
|
|
188
225
|
* Check if the Zucchini extension is installed and the provider is injected.
|
|
189
226
|
*/
|
|
@@ -232,8 +269,22 @@ declare class ZucchiniSDK {
|
|
|
232
269
|
hasWallet: boolean;
|
|
233
270
|
}>;
|
|
234
271
|
getTokens(): Promise<Token[]>;
|
|
235
|
-
|
|
272
|
+
swap: {
|
|
273
|
+
getQuote: (args: QuoteRequestArgs) => Promise<SwapQuote>;
|
|
274
|
+
submitDepositHash: (args: DepositSubmitArgs) => Promise<any>;
|
|
275
|
+
getStatus: (depositAddress: string, memo?: string) => Promise<SwapStatus>;
|
|
276
|
+
getWithdrawals: (depositAddress: string, options?: {
|
|
277
|
+
memo?: string;
|
|
278
|
+
timestampFrom?: string;
|
|
279
|
+
page?: number;
|
|
280
|
+
limit?: number;
|
|
281
|
+
sortOrder?: "asc" | "desc";
|
|
282
|
+
}) => Promise<Withdrawal[]>;
|
|
283
|
+
};
|
|
284
|
+
explorer: {
|
|
285
|
+
getTransactions: (params?: Record<string, string | number | boolean | undefined | null>) => Promise<ExplorerTransaction[]>;
|
|
286
|
+
};
|
|
236
287
|
}
|
|
237
288
|
declare const zucchini: ZucchiniSDK;
|
|
238
289
|
|
|
239
|
-
export { type Account, type ConnectRequest, type ConnectResponse, type DetailedKey, type Payment, type Permission, type QRCodeOptions, type QuoteRequestArgs, type Receiver, type RequestArguments, type SendTransactionArgs, type SwapQuote, type Token, type UnifiedAddressResult, Zip321Generator, type Zip321Options, Zip321Parser, Zip321ParsingError, type ZucchiniProvider, ZucchiniSDK, createPaymentUri, fromZats, generateQRCode, parsePaymentUri, parseUnifiedAddress, shortenAddress, toZats, zucchini };
|
|
290
|
+
export { type Account, type ConnectRequest, type ConnectResponse, type DepositSubmitArgs, type DetailedKey, type ExplorerTransaction, type Payment, type Permission, type QRCodeOptions, type QuoteRequestArgs, type Receiver, type RequestArguments, type SendTransactionArgs, type SwapQuote, type SwapStatus, type Token, type UnifiedAddressResult, type Withdrawal, Zip321Generator, type Zip321Options, Zip321Parser, Zip321ParsingError, type ZucchiniConfig, type ZucchiniProvider, ZucchiniSDK, createPaymentUri, fromZats, generateQRCode, parsePaymentUri, parseUnifiedAddress, shortenAddress, toZats, zucchini };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
type Permission = 'view_balance' | 'view_addresses' | 'send_transaction' | 'view_keys';
|
|
2
|
+
interface ZucchiniConfig {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
dev?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface RequestArguments {
|
|
7
|
+
method: string;
|
|
8
|
+
params?: any;
|
|
9
|
+
}
|
|
10
|
+
interface SendTransactionArgs {
|
|
11
|
+
to: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
memo?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ConnectRequest {
|
|
16
|
+
permissions?: Permission[];
|
|
17
|
+
}
|
|
18
|
+
interface ConnectResponse {
|
|
19
|
+
connected: boolean;
|
|
20
|
+
accounts: Account[];
|
|
21
|
+
approvedPermissions: Permission[];
|
|
22
|
+
}
|
|
23
|
+
interface Account {
|
|
24
|
+
name: string;
|
|
25
|
+
address: string;
|
|
26
|
+
}
|
|
27
|
+
interface ZucchiniProvider {
|
|
28
|
+
request(args: RequestArguments): Promise<any>;
|
|
29
|
+
getBalance(): Promise<{
|
|
30
|
+
total: string;
|
|
31
|
+
sapling: string;
|
|
32
|
+
orchard: string;
|
|
33
|
+
}>;
|
|
34
|
+
getAddresses(): Promise<{
|
|
35
|
+
transparent: string;
|
|
36
|
+
unified: string;
|
|
37
|
+
}>;
|
|
38
|
+
getNetwork(): Promise<{
|
|
39
|
+
network: 'main' | 'test';
|
|
40
|
+
}>;
|
|
41
|
+
getUniversalViewingKey(): Promise<string>;
|
|
42
|
+
getAllViewingKeys(): Promise<Record<string, DetailedKey>>;
|
|
43
|
+
getWalletStatus(): Promise<{
|
|
44
|
+
isLocked: boolean;
|
|
45
|
+
hasWallet: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
on(event: string, callback: (data: any) => void): void;
|
|
48
|
+
off(event: string, callback: (data: any) => void): void;
|
|
49
|
+
disconnect(): Promise<void>;
|
|
50
|
+
isConnected(): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
interface DetailedKey {
|
|
53
|
+
unified: string;
|
|
54
|
+
unified_full: string;
|
|
55
|
+
unified_incoming: string;
|
|
56
|
+
unified_outgoing?: string;
|
|
57
|
+
transparent?: string;
|
|
58
|
+
sapling?: string;
|
|
59
|
+
orchard?: string;
|
|
60
|
+
}
|
|
61
|
+
interface Token {
|
|
62
|
+
symbol: string;
|
|
63
|
+
assetId: string;
|
|
64
|
+
decimals: number;
|
|
65
|
+
blockchain: string;
|
|
66
|
+
price?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
icon?: string;
|
|
69
|
+
}
|
|
70
|
+
interface SwapQuote {
|
|
71
|
+
amountOutFormatted: string;
|
|
72
|
+
amountIn: string;
|
|
73
|
+
amountOut: string;
|
|
74
|
+
depositAddress?: string;
|
|
75
|
+
depositMemo?: string;
|
|
76
|
+
timeEstimate: number;
|
|
77
|
+
deadline?: string;
|
|
78
|
+
}
|
|
79
|
+
interface QuoteRequestArgs {
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
amount: string;
|
|
83
|
+
recipient?: string;
|
|
84
|
+
refundAddress?: string;
|
|
85
|
+
dry?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface DepositSubmitArgs {
|
|
88
|
+
transactionHash: string;
|
|
89
|
+
depositAddress: string;
|
|
90
|
+
memo?: string;
|
|
91
|
+
userAccount?: string;
|
|
92
|
+
}
|
|
93
|
+
interface SwapStatus {
|
|
94
|
+
status: 'KNOWN_DEPOSIT_TX' | 'PENDING_DEPOSIT' | 'INCOMPLETE_DEPOSIT' | 'PROCESSING' | 'SUCCESS' | 'REFUNDED' | 'FAILED';
|
|
95
|
+
depositAddress: string;
|
|
96
|
+
depositMemo?: string;
|
|
97
|
+
swaps?: any[];
|
|
98
|
+
}
|
|
99
|
+
interface Withdrawal {
|
|
100
|
+
id: string;
|
|
101
|
+
status: string;
|
|
102
|
+
amount: string;
|
|
103
|
+
assetId: string;
|
|
104
|
+
timestamp: string;
|
|
105
|
+
}
|
|
106
|
+
interface ExplorerTransaction {
|
|
107
|
+
depositAddressAndMemo: string;
|
|
108
|
+
status: string;
|
|
109
|
+
originAsset: string;
|
|
110
|
+
destinationAsset: string;
|
|
111
|
+
amountIn: string;
|
|
112
|
+
amountOut: string;
|
|
113
|
+
timestamp: string;
|
|
114
|
+
}
|
|
115
|
+
declare global {
|
|
116
|
+
interface Window {
|
|
117
|
+
zucchini?: ZucchiniProvider;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Convert ZEC (decimal string or number) to Zatoshis (bigint).
|
|
123
|
+
* 1 ZEC = 100,000,000 Zatoshis.
|
|
124
|
+
* Handles up to 8 decimal places.
|
|
125
|
+
*/
|
|
126
|
+
declare function toZats(amount: string | number): bigint;
|
|
127
|
+
/**
|
|
128
|
+
* Convert Zatoshis (bigint or string) to ZEC (decimal string).
|
|
129
|
+
* 1 ZEC = 100,000,000 Zatoshis.
|
|
130
|
+
*/
|
|
131
|
+
declare function fromZats(amount: bigint | string): string;
|
|
132
|
+
/**
|
|
133
|
+
* Shorten an address for display.
|
|
134
|
+
* Example: zs1...abcd
|
|
135
|
+
*/
|
|
136
|
+
declare function shortenAddress(address: string, chars?: number): string;
|
|
137
|
+
|
|
138
|
+
interface Payment {
|
|
139
|
+
address: string;
|
|
140
|
+
amount?: bigint;
|
|
141
|
+
assetId?: string;
|
|
142
|
+
memo?: string;
|
|
143
|
+
label?: string;
|
|
144
|
+
message?: string;
|
|
145
|
+
otherParams?: Record<string, string>;
|
|
146
|
+
}
|
|
147
|
+
interface Zip321Options {
|
|
148
|
+
useOrchard?: boolean;
|
|
149
|
+
}
|
|
150
|
+
declare class Zip321ParsingError extends Error {
|
|
151
|
+
constructor(message: string);
|
|
152
|
+
}
|
|
153
|
+
declare class Zip321Parser {
|
|
154
|
+
/**
|
|
155
|
+
* Parses a zcash: URI into a list of Payment objects.
|
|
156
|
+
* @param uri The zcash URI string.
|
|
157
|
+
* @param options Parsing options.
|
|
158
|
+
* @returns An array of Payment objects.
|
|
159
|
+
* @throws Zip321ParsingError if the URI is invalid.
|
|
160
|
+
*/
|
|
161
|
+
static parse(uri: string, options?: Zip321Options): Payment[];
|
|
162
|
+
private static isValidAddress;
|
|
163
|
+
private static isTransparent;
|
|
164
|
+
private static isSapling;
|
|
165
|
+
private static isUnified;
|
|
166
|
+
private static parseAmount;
|
|
167
|
+
private static parseAsset;
|
|
168
|
+
private static isValidBase64Url;
|
|
169
|
+
}
|
|
170
|
+
declare class Zip321Generator {
|
|
171
|
+
/**
|
|
172
|
+
* Creates a ZIP 321 compliant URI from a list of payments.
|
|
173
|
+
* @param payments List of Payment objects.
|
|
174
|
+
* @param options Generation options.
|
|
175
|
+
* @returns The formatted zcash: URI.
|
|
176
|
+
* @throws Error if payments list is empty or invalid.
|
|
177
|
+
*/
|
|
178
|
+
static create(payments: Payment[], options?: Zip321Options): string;
|
|
179
|
+
private static formatAmount;
|
|
180
|
+
private static formatAsset;
|
|
181
|
+
}
|
|
182
|
+
declare function parsePaymentUri(uri: string, options?: Zip321Options): Payment[];
|
|
183
|
+
declare function createPaymentUri(payments: Payment[], options?: Zip321Options): string;
|
|
184
|
+
|
|
185
|
+
interface QRCodeOptions {
|
|
186
|
+
width?: number;
|
|
187
|
+
margin?: number;
|
|
188
|
+
color?: {
|
|
189
|
+
dark?: string;
|
|
190
|
+
light?: string;
|
|
191
|
+
};
|
|
192
|
+
logoUrl?: string;
|
|
193
|
+
logoWidth?: number;
|
|
194
|
+
logoHeight?: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generates a QR code Data URL from a string (e.g., a ZIP 321 URI).
|
|
198
|
+
* @param text The text to encode.
|
|
199
|
+
* @param options QR code options.
|
|
200
|
+
* @returns A Promise resolving to a Data URL string (image/png).
|
|
201
|
+
*/
|
|
202
|
+
declare function generateQRCode(text: string, options?: QRCodeOptions): Promise<string>;
|
|
203
|
+
|
|
204
|
+
interface UnifiedAddressResult {
|
|
205
|
+
orchard?: string;
|
|
206
|
+
sapling?: string;
|
|
207
|
+
transparent?: string;
|
|
208
|
+
unknown?: Receiver[];
|
|
209
|
+
}
|
|
210
|
+
interface Receiver {
|
|
211
|
+
typeCode: number;
|
|
212
|
+
data: Uint8Array;
|
|
213
|
+
}
|
|
214
|
+
declare function parseUnifiedAddress(unifiedAddress: string): UnifiedAddressResult;
|
|
215
|
+
|
|
216
|
+
declare class ZucchiniSDK {
|
|
217
|
+
private _apiUrl;
|
|
218
|
+
constructor(config?: ZucchiniConfig);
|
|
219
|
+
/**
|
|
220
|
+
* Configure the SDK at runtime.
|
|
221
|
+
*/
|
|
222
|
+
configure(config: ZucchiniConfig): void;
|
|
223
|
+
get apiUrl(): string;
|
|
8
224
|
/**
|
|
9
225
|
* Check if the Zucchini extension is installed and the provider is injected.
|
|
10
226
|
*/
|
|
@@ -53,6 +269,22 @@ export declare class ZucchiniSDK {
|
|
|
53
269
|
hasWallet: boolean;
|
|
54
270
|
}>;
|
|
55
271
|
getTokens(): Promise<Token[]>;
|
|
56
|
-
|
|
272
|
+
swap: {
|
|
273
|
+
getQuote: (args: QuoteRequestArgs) => Promise<SwapQuote>;
|
|
274
|
+
submitDepositHash: (args: DepositSubmitArgs) => Promise<any>;
|
|
275
|
+
getStatus: (depositAddress: string, memo?: string) => Promise<SwapStatus>;
|
|
276
|
+
getWithdrawals: (depositAddress: string, options?: {
|
|
277
|
+
memo?: string;
|
|
278
|
+
timestampFrom?: string;
|
|
279
|
+
page?: number;
|
|
280
|
+
limit?: number;
|
|
281
|
+
sortOrder?: "asc" | "desc";
|
|
282
|
+
}) => Promise<Withdrawal[]>;
|
|
283
|
+
};
|
|
284
|
+
explorer: {
|
|
285
|
+
getTransactions: (params?: Record<string, string | number | boolean | undefined | null>) => Promise<ExplorerTransaction[]>;
|
|
286
|
+
};
|
|
57
287
|
}
|
|
58
|
-
|
|
288
|
+
declare const zucchini: ZucchiniSDK;
|
|
289
|
+
|
|
290
|
+
export { type Account, type ConnectRequest, type ConnectResponse, type DepositSubmitArgs, type DetailedKey, type ExplorerTransaction, type Payment, type Permission, type QRCodeOptions, type QuoteRequestArgs, type Receiver, type RequestArguments, type SendTransactionArgs, type SwapQuote, type SwapStatus, type Token, type UnifiedAddressResult, type Withdrawal, Zip321Generator, type Zip321Options, Zip321Parser, Zip321ParsingError, type ZucchiniConfig, type ZucchiniProvider, ZucchiniSDK, createPaymentUri, fromZats, generateQRCode, parsePaymentUri, parseUnifiedAddress, shortenAddress, toZats, zucchini };
|