@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/README.md +197 -0
- package/dist/f4jumble.d.ts +2 -0
- package/dist/f4jumble.js +82 -0
- package/dist/index.d.mts +239 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.global.js +108 -0
- package/dist/index.js +132 -0
- package/dist/index.mjs +727 -0
- package/dist/qrcode.d.ts +18 -0
- package/dist/qrcode.js +72 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.js +2 -0
- package/dist/unified_address.d.ts +11 -0
- package/dist/unified_address.js +154 -0
- package/dist/unified_address.test.d.ts +1 -0
- package/dist/unified_address.test.js +45 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +58 -0
- package/dist/zip321.d.ts +46 -0
- package/dist/zip321.js +354 -0
- package/dist/zip321.test.d.ts +1 -0
- package/dist/zip321.test.js +109 -0
- package/dist/zip321_orchard.test.d.ts +1 -0
- package/dist/zip321_orchard.test.js +34 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Zucchini SDK
|
|
2
|
+
|
|
3
|
+
The Zucchini SDK provides a simple way for DApps to interact with the Zucchini Wallet extension.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @zucchinifi/dapp-sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @zucchinifi/dapp-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
First, check if the Zucchini wallet is installed and connect to it.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { zucchini } from '@zucchinifi/dapp-sdk';
|
|
19
|
+
|
|
20
|
+
// Check if installed
|
|
21
|
+
if (zucchini.isInstalled) {
|
|
22
|
+
// Connect and request permissions
|
|
23
|
+
// Available permissions: 'view_balance', 'send_transaction', 'view_addresses', 'view_keys'
|
|
24
|
+
const response = await zucchini.connect(['view_balance', 'send_transaction']);
|
|
25
|
+
console.log('Connected:', response);
|
|
26
|
+
} else {
|
|
27
|
+
console.log('Zucchini Wallet is not installed');
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Core Features
|
|
32
|
+
|
|
33
|
+
### Get Balance
|
|
34
|
+
Requires `view_balance` permission.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const balance = await zucchini.getBalance();
|
|
38
|
+
console.log('Total:', balance.total);
|
|
39
|
+
console.log('Sapling:', balance.sapling);
|
|
40
|
+
console.log('Orchard:', balance.orchard);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Get Addresses
|
|
44
|
+
Requires `view_addresses` permission.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const addresses = await zucchini.getAddresses();
|
|
48
|
+
console.log('Unified:', addresses.unified);
|
|
49
|
+
console.log('Sapling:', addresses.sapling);
|
|
50
|
+
console.log('Transparent:', addresses.transparent);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Send Transaction
|
|
54
|
+
Requires `send_transaction` permission.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
const txid = await zucchini.sendTransaction({
|
|
58
|
+
to: 'u1...', // Recipient address
|
|
59
|
+
amount: '0.001', // Amount in ZEC
|
|
60
|
+
memo: 'Hello Zcash!' // Optional memo
|
|
61
|
+
});
|
|
62
|
+
console.log('Transaction sent:', txid);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Network & Status
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// Get current network ('main' or 'test')
|
|
69
|
+
const network = await zucchini.getNetwork();
|
|
70
|
+
|
|
71
|
+
// Check wallet status
|
|
72
|
+
const status = await zucchini.getWalletStatus();
|
|
73
|
+
console.log('Is Locked:', status.isLocked);
|
|
74
|
+
console.log('Has Wallet:', status.hasWallet);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Viewing Keys
|
|
78
|
+
Requires `view_keys` permission.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Get Universal Viewing Key (UVK)
|
|
82
|
+
const uvk = await zucchini.getUniversalViewingKey();
|
|
83
|
+
|
|
84
|
+
// Get all viewing keys
|
|
85
|
+
const keys = await zucchini.getAllViewingKeys();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## ZIP 321 Payment Requests
|
|
89
|
+
|
|
90
|
+
The SDK provides utilities for creating and parsing [ZIP 321](https://zips.z.cash/zip-0321) payment URIs (`zcash:`).
|
|
91
|
+
|
|
92
|
+
### Create Payment URI
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { createPaymentUri } from '@zucchinifi/dapp-sdk';
|
|
96
|
+
|
|
97
|
+
const payments = [{
|
|
98
|
+
address: 'u1...',
|
|
99
|
+
amount: 100000n, // Amount in zatoshis (BigInt)
|
|
100
|
+
memo: 'Thanks!', // Base64URL encoded memo
|
|
101
|
+
label: 'Coffee'
|
|
102
|
+
}];
|
|
103
|
+
|
|
104
|
+
// Create URI
|
|
105
|
+
const uri = createPaymentUri(payments);
|
|
106
|
+
|
|
107
|
+
// Create URI with auto-conversion of Unified Addresses to Orchard receivers
|
|
108
|
+
// This is useful for compatibility with wallets that prefer Orchard-only addresses
|
|
109
|
+
const orchardUri = createPaymentUri(payments, { useOrchard: true });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Parse Payment URI
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { parsePaymentUri } from '@zucchinifi/dapp-sdk';
|
|
116
|
+
|
|
117
|
+
const uri = 'zcash:u1...?amount=0.001';
|
|
118
|
+
|
|
119
|
+
const requests = parsePaymentUri(uri);
|
|
120
|
+
|
|
121
|
+
// Parse and automatically extract Orchard receivers from Unified Addresses
|
|
122
|
+
const orchardRequests = parsePaymentUri(uri, { useOrchard: true });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Generate QR Code
|
|
126
|
+
|
|
127
|
+
Generate a QR code for a payment URI. The Zucchini logo is embedded by default.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { generateQRCode } from '@zucchinifi/dapp-sdk';
|
|
131
|
+
|
|
132
|
+
const dataUrl = await generateQRCode(uri);
|
|
133
|
+
|
|
134
|
+
// Display in an image tag
|
|
135
|
+
document.getElementById('qr-code').src = dataUrl;
|
|
136
|
+
|
|
137
|
+
// Custom options
|
|
138
|
+
const customQr = await generateQRCode(uri, {
|
|
139
|
+
logoUrl: 'https://example.com/logo.png', // Custom logo
|
|
140
|
+
width: 256,
|
|
141
|
+
logoWidth: 60,
|
|
142
|
+
logoHeight: 60
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Swap
|
|
147
|
+
|
|
148
|
+
Fetch supported tokens and get swap quotes.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Get supported tokens
|
|
152
|
+
const tokens = await zucchini.getTokens();
|
|
153
|
+
|
|
154
|
+
// Get a swap quote
|
|
155
|
+
const quote = await zucchini.getSwapQuote({
|
|
156
|
+
from: 'ZEC',
|
|
157
|
+
to: 'USDC',
|
|
158
|
+
amount: '100000000', // Amount in base units
|
|
159
|
+
recipient: '0x...', // Destination address
|
|
160
|
+
refundAddress: '0x...' // Refund address (if needed)
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Events
|
|
165
|
+
|
|
166
|
+
Listen for account and chain changes.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
zucchini.on('accountsChanged', (accounts) => {
|
|
170
|
+
console.log('Accounts changed:', accounts);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
zucchini.on('chainChanged', (chain) => {
|
|
174
|
+
console.log('Chain changed:', chain);
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Running the Example
|
|
179
|
+
|
|
180
|
+
An example project is included in the `example` directory. To run it:
|
|
181
|
+
|
|
182
|
+
1. Navigate to the example directory:
|
|
183
|
+
```bash
|
|
184
|
+
cd example
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
2. Install dependencies:
|
|
188
|
+
```bash
|
|
189
|
+
pnpm install
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
3. Start the development server:
|
|
193
|
+
```bash
|
|
194
|
+
pnpm dev
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
4. Open `http://localhost:3000` in your browser.
|
package/dist/f4jumble.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.f4jumble = f4jumble;
|
|
4
|
+
exports.f4jumble_inv = f4jumble_inv;
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const blakejs_1 = require("blakejs");
|
|
7
|
+
// ZIP 316: F4Jumble
|
|
8
|
+
// Based on librustzcash implementation
|
|
9
|
+
function get_h_pers(i) {
|
|
10
|
+
// "UA_F4Jumble_H" || i || 0 || 0
|
|
11
|
+
const p = new Uint8Array(16);
|
|
12
|
+
p.set([85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 72, i, 0, 0]);
|
|
13
|
+
return p;
|
|
14
|
+
}
|
|
15
|
+
function get_g_pers(i, j) {
|
|
16
|
+
// "UA_F4Jumble_G" || i || j_low || j_high
|
|
17
|
+
const p = new Uint8Array(16);
|
|
18
|
+
p.set([85, 65, 95, 70, 52, 74, 117, 109, 98, 108, 101, 95, 71, i, j & 0xFF, (j >> 8) & 0xFF]);
|
|
19
|
+
return p;
|
|
20
|
+
}
|
|
21
|
+
function xor(target, source) {
|
|
22
|
+
const len = Math.min(target.length, source.length);
|
|
23
|
+
for (let i = 0; i < len; i++) {
|
|
24
|
+
target[i] ^= source[i];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class State {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
const leftLen = Math.min(64, Math.floor(message.length / 2));
|
|
30
|
+
this.left = message.subarray(0, leftLen);
|
|
31
|
+
this.right = message.subarray(leftLen);
|
|
32
|
+
}
|
|
33
|
+
h_round(i) {
|
|
34
|
+
// Hash right, xor into left
|
|
35
|
+
// hash_length = left.len() (max 64)
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const ctx = (0, blakejs_1.blake2bInit)(this.left.length, null, null, get_h_pers(i));
|
|
38
|
+
(0, blakejs_1.blake2bUpdate)(ctx, this.right);
|
|
39
|
+
const hash = (0, blakejs_1.blake2bFinal)(ctx);
|
|
40
|
+
xor(this.left, hash);
|
|
41
|
+
}
|
|
42
|
+
g_round(i) {
|
|
43
|
+
// Hash left, xor into right
|
|
44
|
+
// Iterate j
|
|
45
|
+
const outBytes = 64;
|
|
46
|
+
const numChunks = Math.ceil(this.right.length / outBytes);
|
|
47
|
+
for (let j = 0; j < numChunks; j++) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const ctx = (0, blakejs_1.blake2bInit)(outBytes, null, null, get_g_pers(i, j));
|
|
50
|
+
(0, blakejs_1.blake2bUpdate)(ctx, this.left);
|
|
51
|
+
const hash = (0, blakejs_1.blake2bFinal)(ctx);
|
|
52
|
+
const offset = j * outBytes;
|
|
53
|
+
const targetChunk = this.right.subarray(offset, offset + outBytes);
|
|
54
|
+
xor(targetChunk, hash);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
apply_f4jumble() {
|
|
58
|
+
this.g_round(0);
|
|
59
|
+
this.h_round(0);
|
|
60
|
+
this.g_round(1);
|
|
61
|
+
this.h_round(1);
|
|
62
|
+
}
|
|
63
|
+
apply_f4jumble_inv() {
|
|
64
|
+
this.h_round(1);
|
|
65
|
+
this.g_round(1);
|
|
66
|
+
this.h_round(0);
|
|
67
|
+
this.g_round(0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function f4jumble(message) {
|
|
71
|
+
// We need to copy message because State modifies it in place
|
|
72
|
+
const msgCopy = new Uint8Array(message);
|
|
73
|
+
const state = new State(msgCopy);
|
|
74
|
+
state.apply_f4jumble();
|
|
75
|
+
return msgCopy;
|
|
76
|
+
}
|
|
77
|
+
function f4jumble_inv(message) {
|
|
78
|
+
const msgCopy = new Uint8Array(message);
|
|
79
|
+
const state = new State(msgCopy);
|
|
80
|
+
state.apply_f4jumble_inv();
|
|
81
|
+
return msgCopy;
|
|
82
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
type Permission = 'view_balance' | 'view_addresses' | 'send_transaction' | 'view_keys';
|
|
2
|
+
interface RequestArguments {
|
|
3
|
+
method: string;
|
|
4
|
+
params?: any;
|
|
5
|
+
}
|
|
6
|
+
interface SendTransactionArgs {
|
|
7
|
+
to: string;
|
|
8
|
+
amount: string;
|
|
9
|
+
memo?: string;
|
|
10
|
+
}
|
|
11
|
+
interface ConnectRequest {
|
|
12
|
+
permissions?: Permission[];
|
|
13
|
+
}
|
|
14
|
+
interface ConnectResponse {
|
|
15
|
+
connected: boolean;
|
|
16
|
+
accounts: Account[];
|
|
17
|
+
approvedPermissions: Permission[];
|
|
18
|
+
}
|
|
19
|
+
interface Account {
|
|
20
|
+
name: string;
|
|
21
|
+
address: string;
|
|
22
|
+
}
|
|
23
|
+
interface ZucchiniProvider {
|
|
24
|
+
request(args: RequestArguments): Promise<any>;
|
|
25
|
+
getBalance(): Promise<{
|
|
26
|
+
total: string;
|
|
27
|
+
sapling: string;
|
|
28
|
+
orchard: string;
|
|
29
|
+
}>;
|
|
30
|
+
getAddresses(): Promise<{
|
|
31
|
+
transparent: string;
|
|
32
|
+
unified: string;
|
|
33
|
+
}>;
|
|
34
|
+
getNetwork(): Promise<{
|
|
35
|
+
network: 'main' | 'test';
|
|
36
|
+
}>;
|
|
37
|
+
getUniversalViewingKey(): Promise<string>;
|
|
38
|
+
getAllViewingKeys(): Promise<Record<string, DetailedKey>>;
|
|
39
|
+
getWalletStatus(): Promise<{
|
|
40
|
+
isLocked: boolean;
|
|
41
|
+
hasWallet: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
on(event: string, callback: (data: any) => void): void;
|
|
44
|
+
off(event: string, callback: (data: any) => void): void;
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
isConnected(): Promise<boolean>;
|
|
47
|
+
}
|
|
48
|
+
interface DetailedKey {
|
|
49
|
+
unified: string;
|
|
50
|
+
unified_full: string;
|
|
51
|
+
unified_incoming: string;
|
|
52
|
+
unified_outgoing?: string;
|
|
53
|
+
transparent?: string;
|
|
54
|
+
sapling?: string;
|
|
55
|
+
orchard?: string;
|
|
56
|
+
}
|
|
57
|
+
interface Token {
|
|
58
|
+
symbol: string;
|
|
59
|
+
name: string;
|
|
60
|
+
icon: string;
|
|
61
|
+
decimals: number;
|
|
62
|
+
assetId?: string;
|
|
63
|
+
}
|
|
64
|
+
interface SwapQuote {
|
|
65
|
+
quote: {
|
|
66
|
+
amountOutFormatted: string;
|
|
67
|
+
amountIn: string;
|
|
68
|
+
amountOut: string;
|
|
69
|
+
depositAddress?: string;
|
|
70
|
+
depositMemo?: string;
|
|
71
|
+
timeEstimate: number;
|
|
72
|
+
};
|
|
73
|
+
quoteRequest: {
|
|
74
|
+
deadline: string;
|
|
75
|
+
};
|
|
76
|
+
depositAddress?: string;
|
|
77
|
+
}
|
|
78
|
+
interface QuoteRequestArgs {
|
|
79
|
+
from: string;
|
|
80
|
+
to: string;
|
|
81
|
+
amount: string;
|
|
82
|
+
recipient?: string;
|
|
83
|
+
refundAddress?: string;
|
|
84
|
+
}
|
|
85
|
+
declare global {
|
|
86
|
+
interface Window {
|
|
87
|
+
zucchini?: ZucchiniProvider;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Convert ZEC (decimal string or number) to Zatoshis (bigint).
|
|
93
|
+
* 1 ZEC = 100,000,000 Zatoshis.
|
|
94
|
+
* Handles up to 8 decimal places.
|
|
95
|
+
*/
|
|
96
|
+
declare function toZats(amount: string | number): bigint;
|
|
97
|
+
/**
|
|
98
|
+
* Convert Zatoshis (bigint or string) to ZEC (decimal string).
|
|
99
|
+
* 1 ZEC = 100,000,000 Zatoshis.
|
|
100
|
+
*/
|
|
101
|
+
declare function fromZats(amount: bigint | string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Shorten an address for display.
|
|
104
|
+
* Example: zs1...abcd
|
|
105
|
+
*/
|
|
106
|
+
declare function shortenAddress(address: string, chars?: number): string;
|
|
107
|
+
|
|
108
|
+
interface Payment {
|
|
109
|
+
address: string;
|
|
110
|
+
amount?: bigint;
|
|
111
|
+
assetId?: string;
|
|
112
|
+
memo?: string;
|
|
113
|
+
label?: string;
|
|
114
|
+
message?: string;
|
|
115
|
+
otherParams?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
interface Zip321Options {
|
|
118
|
+
useOrchard?: boolean;
|
|
119
|
+
}
|
|
120
|
+
declare class Zip321ParsingError extends Error {
|
|
121
|
+
constructor(message: string);
|
|
122
|
+
}
|
|
123
|
+
declare class Zip321Parser {
|
|
124
|
+
/**
|
|
125
|
+
* Parses a zcash: URI into a list of Payment objects.
|
|
126
|
+
* @param uri The zcash URI string.
|
|
127
|
+
* @param options Parsing options.
|
|
128
|
+
* @returns An array of Payment objects.
|
|
129
|
+
* @throws Zip321ParsingError if the URI is invalid.
|
|
130
|
+
*/
|
|
131
|
+
static parse(uri: string, options?: Zip321Options): Payment[];
|
|
132
|
+
private static isValidAddress;
|
|
133
|
+
private static isTransparent;
|
|
134
|
+
private static isSapling;
|
|
135
|
+
private static isUnified;
|
|
136
|
+
private static parseAmount;
|
|
137
|
+
private static parseAsset;
|
|
138
|
+
private static isValidBase64Url;
|
|
139
|
+
}
|
|
140
|
+
declare class Zip321Generator {
|
|
141
|
+
/**
|
|
142
|
+
* Creates a ZIP 321 compliant URI from a list of payments.
|
|
143
|
+
* @param payments List of Payment objects.
|
|
144
|
+
* @param options Generation options.
|
|
145
|
+
* @returns The formatted zcash: URI.
|
|
146
|
+
* @throws Error if payments list is empty or invalid.
|
|
147
|
+
*/
|
|
148
|
+
static create(payments: Payment[], options?: Zip321Options): string;
|
|
149
|
+
private static formatAmount;
|
|
150
|
+
private static formatAsset;
|
|
151
|
+
}
|
|
152
|
+
declare function parsePaymentUri(uri: string, options?: Zip321Options): Payment[];
|
|
153
|
+
declare function createPaymentUri(payments: Payment[], options?: Zip321Options): string;
|
|
154
|
+
|
|
155
|
+
interface QRCodeOptions {
|
|
156
|
+
width?: number;
|
|
157
|
+
margin?: number;
|
|
158
|
+
color?: {
|
|
159
|
+
dark?: string;
|
|
160
|
+
light?: string;
|
|
161
|
+
};
|
|
162
|
+
logoUrl?: string;
|
|
163
|
+
logoWidth?: number;
|
|
164
|
+
logoHeight?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Generates a QR code Data URL from a string (e.g., a ZIP 321 URI).
|
|
168
|
+
* @param text The text to encode.
|
|
169
|
+
* @param options QR code options.
|
|
170
|
+
* @returns A Promise resolving to a Data URL string (image/png).
|
|
171
|
+
*/
|
|
172
|
+
declare function generateQRCode(text: string, options?: QRCodeOptions): Promise<string>;
|
|
173
|
+
|
|
174
|
+
interface UnifiedAddressResult {
|
|
175
|
+
orchard?: string;
|
|
176
|
+
sapling?: string;
|
|
177
|
+
transparent?: string;
|
|
178
|
+
unknown?: Receiver[];
|
|
179
|
+
}
|
|
180
|
+
interface Receiver {
|
|
181
|
+
typeCode: number;
|
|
182
|
+
data: Uint8Array;
|
|
183
|
+
}
|
|
184
|
+
declare function parseUnifiedAddress(unifiedAddress: string): UnifiedAddressResult;
|
|
185
|
+
|
|
186
|
+
declare class ZucchiniSDK {
|
|
187
|
+
/**
|
|
188
|
+
* Check if the Zucchini extension is installed and the provider is injected.
|
|
189
|
+
*/
|
|
190
|
+
get isInstalled(): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Get the provider instance.
|
|
193
|
+
* @throws Error if Zucchini is not installed.
|
|
194
|
+
*/
|
|
195
|
+
get provider(): ZucchiniProvider;
|
|
196
|
+
/**
|
|
197
|
+
* Connect to the wallet.
|
|
198
|
+
* Requests permission from the user to access their accounts.
|
|
199
|
+
* @param permissions List of permissions to request.
|
|
200
|
+
*/
|
|
201
|
+
connect(permissions?: Permission[]): Promise<ConnectResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Send a transaction.
|
|
204
|
+
* Requires 'send_transaction' permission.
|
|
205
|
+
*/
|
|
206
|
+
sendTransaction(args: SendTransactionArgs): Promise<string>;
|
|
207
|
+
getBalance(): Promise<{
|
|
208
|
+
total: string;
|
|
209
|
+
sapling: string;
|
|
210
|
+
orchard: string;
|
|
211
|
+
}>;
|
|
212
|
+
getAddresses(): Promise<{
|
|
213
|
+
sapling: string;
|
|
214
|
+
transparent: string;
|
|
215
|
+
unified: string;
|
|
216
|
+
}>;
|
|
217
|
+
getNetwork(): Promise<{
|
|
218
|
+
network: 'main' | 'test';
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* Send a generic request to the wallet.
|
|
222
|
+
*/
|
|
223
|
+
request(args: RequestArguments): Promise<any>;
|
|
224
|
+
on(event: string, handler: (data: any) => void): void;
|
|
225
|
+
off(event: string, handler: (data: any) => void): void;
|
|
226
|
+
disconnect(): Promise<void>;
|
|
227
|
+
isConnected(): Promise<boolean>;
|
|
228
|
+
getUniversalViewingKey(): Promise<string>;
|
|
229
|
+
getAllViewingKeys(): Promise<Record<string, string>>;
|
|
230
|
+
getWalletStatus(): Promise<{
|
|
231
|
+
isLocked: boolean;
|
|
232
|
+
hasWallet: boolean;
|
|
233
|
+
}>;
|
|
234
|
+
getTokens(): Promise<Token[]>;
|
|
235
|
+
getSwapQuote(args: QuoteRequestArgs): Promise<SwapQuote>;
|
|
236
|
+
}
|
|
237
|
+
declare const zucchini: ZucchiniSDK;
|
|
238
|
+
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ZucchiniProvider, ConnectResponse, RequestArguments, Permission, SendTransactionArgs, Token, SwapQuote, QuoteRequestArgs } from './types';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './utils';
|
|
4
|
+
export * from './zip321';
|
|
5
|
+
export * from './qrcode';
|
|
6
|
+
export * from './unified_address';
|
|
7
|
+
export declare class ZucchiniSDK {
|
|
8
|
+
/**
|
|
9
|
+
* Check if the Zucchini extension is installed and the provider is injected.
|
|
10
|
+
*/
|
|
11
|
+
get isInstalled(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get the provider instance.
|
|
14
|
+
* @throws Error if Zucchini is not installed.
|
|
15
|
+
*/
|
|
16
|
+
get provider(): ZucchiniProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Connect to the wallet.
|
|
19
|
+
* Requests permission from the user to access their accounts.
|
|
20
|
+
* @param permissions List of permissions to request.
|
|
21
|
+
*/
|
|
22
|
+
connect(permissions?: Permission[]): Promise<ConnectResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Send a transaction.
|
|
25
|
+
* Requires 'send_transaction' permission.
|
|
26
|
+
*/
|
|
27
|
+
sendTransaction(args: SendTransactionArgs): Promise<string>;
|
|
28
|
+
getBalance(): Promise<{
|
|
29
|
+
total: string;
|
|
30
|
+
sapling: string;
|
|
31
|
+
orchard: string;
|
|
32
|
+
}>;
|
|
33
|
+
getAddresses(): Promise<{
|
|
34
|
+
sapling: string;
|
|
35
|
+
transparent: string;
|
|
36
|
+
unified: string;
|
|
37
|
+
}>;
|
|
38
|
+
getNetwork(): Promise<{
|
|
39
|
+
network: 'main' | 'test';
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Send a generic request to the wallet.
|
|
43
|
+
*/
|
|
44
|
+
request(args: RequestArguments): Promise<any>;
|
|
45
|
+
on(event: string, handler: (data: any) => void): void;
|
|
46
|
+
off(event: string, handler: (data: any) => void): void;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
48
|
+
isConnected(): Promise<boolean>;
|
|
49
|
+
getUniversalViewingKey(): Promise<string>;
|
|
50
|
+
getAllViewingKeys(): Promise<Record<string, string>>;
|
|
51
|
+
getWalletStatus(): Promise<{
|
|
52
|
+
isLocked: boolean;
|
|
53
|
+
hasWallet: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
getTokens(): Promise<Token[]>;
|
|
56
|
+
getSwapQuote(args: QuoteRequestArgs): Promise<SwapQuote>;
|
|
57
|
+
}
|
|
58
|
+
export declare const zucchini: ZucchiniSDK;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ZucchiniSDK = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
ZucchiniSDK: () => ZucchiniSDK,
|
|
25
|
+
zucchini: () => zucchini
|
|
26
|
+
});
|
|
27
|
+
var ZucchiniSDK = class {
|
|
28
|
+
/**
|
|
29
|
+
* Check if the Zucchini extension is installed and the provider is injected.
|
|
30
|
+
*/
|
|
31
|
+
get isInstalled() {
|
|
32
|
+
return typeof window !== "undefined" && !!window.zucchini;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the provider instance.
|
|
36
|
+
* @throws Error if Zucchini is not installed.
|
|
37
|
+
*/
|
|
38
|
+
get provider() {
|
|
39
|
+
if (!this.isInstalled) {
|
|
40
|
+
throw new Error("Zucchini Wallet is not installed");
|
|
41
|
+
}
|
|
42
|
+
return window.zucchini;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Connect to the wallet.
|
|
46
|
+
* Requests permission from the user to access their accounts.
|
|
47
|
+
* @param permissions List of permissions to request.
|
|
48
|
+
*/
|
|
49
|
+
async connect(permissions = []) {
|
|
50
|
+
return this.request({ method: "connect", params: { permissions } });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Send a transaction.
|
|
54
|
+
* Requires 'send_transaction' permission.
|
|
55
|
+
*/
|
|
56
|
+
async sendTransaction(args) {
|
|
57
|
+
return this.request({
|
|
58
|
+
method: "sendTransaction",
|
|
59
|
+
params: args
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async getBalance() {
|
|
63
|
+
return this.request({
|
|
64
|
+
method: "getBalance"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async getAddresses() {
|
|
68
|
+
return this.request({
|
|
69
|
+
method: "getAddresses"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async getNetwork() {
|
|
73
|
+
return this.request({
|
|
74
|
+
method: "getNetwork"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Send a generic request to the wallet.
|
|
79
|
+
*/
|
|
80
|
+
async request(args) {
|
|
81
|
+
return this.provider.request(args);
|
|
82
|
+
}
|
|
83
|
+
on(event, handler) {
|
|
84
|
+
this.provider.on(event, handler);
|
|
85
|
+
}
|
|
86
|
+
off(event, handler) {
|
|
87
|
+
this.provider.off(event, handler);
|
|
88
|
+
}
|
|
89
|
+
async disconnect() {
|
|
90
|
+
return this.request({ method: "disconnect" });
|
|
91
|
+
}
|
|
92
|
+
async isConnected() {
|
|
93
|
+
try {
|
|
94
|
+
return await this.request({ method: "isConnected" });
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async getUniversalViewingKey() {
|
|
100
|
+
return this.request({ method: "getUniversalViewingKey" });
|
|
101
|
+
}
|
|
102
|
+
async getAllViewingKeys() {
|
|
103
|
+
return this.request({ method: "getAllViewingKeys" });
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var zucchini = new ZucchiniSDK();
|
|
107
|
+
return __toCommonJS(index_exports);
|
|
108
|
+
})();
|