zeldwallet 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 +305 -0
- package/dist/index.d.ts +6 -0
- package/dist/src/ZeldWallet.d.ts +254 -0
- package/dist/src/ZeldWallet.d.ts.map +1 -0
- package/dist/src/component/ZeldWalletUI.d.ts +56 -0
- package/dist/src/component/ZeldWalletUI.d.ts.map +1 -0
- package/dist/src/component/balance.d.ts +41 -0
- package/dist/src/component/balance.d.ts.map +1 -0
- package/dist/src/component/bindings.d.ts +76 -0
- package/dist/src/component/bindings.d.ts.map +1 -0
- package/dist/src/component/constants.d.ts +15 -0
- package/dist/src/component/constants.d.ts.map +1 -0
- package/dist/src/component/controller.d.ts +224 -0
- package/dist/src/component/controller.d.ts.map +1 -0
- package/dist/src/component/errors.d.ts +5 -0
- package/dist/src/component/errors.d.ts.map +1 -0
- package/dist/src/component/i18n.d.ts +156 -0
- package/dist/src/component/i18n.d.ts.map +1 -0
- package/dist/src/component/messages/ar.d.ts +3 -0
- package/dist/src/component/messages/ar.d.ts.map +1 -0
- package/dist/src/component/messages/bn.d.ts +3 -0
- package/dist/src/component/messages/bn.d.ts.map +1 -0
- package/dist/src/component/messages/cs.d.ts +3 -0
- package/dist/src/component/messages/cs.d.ts.map +1 -0
- package/dist/src/component/messages/de.d.ts +3 -0
- package/dist/src/component/messages/de.d.ts.map +1 -0
- package/dist/src/component/messages/el.d.ts +3 -0
- package/dist/src/component/messages/el.d.ts.map +1 -0
- package/dist/src/component/messages/en.d.ts +3 -0
- package/dist/src/component/messages/en.d.ts.map +1 -0
- package/dist/src/component/messages/es.d.ts +3 -0
- package/dist/src/component/messages/es.d.ts.map +1 -0
- package/dist/src/component/messages/fa.d.ts +3 -0
- package/dist/src/component/messages/fa.d.ts.map +1 -0
- package/dist/src/component/messages/fr.d.ts +3 -0
- package/dist/src/component/messages/fr.d.ts.map +1 -0
- package/dist/src/component/messages/he.d.ts +3 -0
- package/dist/src/component/messages/he.d.ts.map +1 -0
- package/dist/src/component/messages/hi.d.ts +3 -0
- package/dist/src/component/messages/hi.d.ts.map +1 -0
- package/dist/src/component/messages/id.d.ts +3 -0
- package/dist/src/component/messages/id.d.ts.map +1 -0
- package/dist/src/component/messages/index.d.ts +31 -0
- package/dist/src/component/messages/index.d.ts.map +1 -0
- package/dist/src/component/messages/it.d.ts +3 -0
- package/dist/src/component/messages/it.d.ts.map +1 -0
- package/dist/src/component/messages/ja.d.ts +3 -0
- package/dist/src/component/messages/ja.d.ts.map +1 -0
- package/dist/src/component/messages/ko.d.ts +3 -0
- package/dist/src/component/messages/ko.d.ts.map +1 -0
- package/dist/src/component/messages/ms.d.ts +3 -0
- package/dist/src/component/messages/ms.d.ts.map +1 -0
- package/dist/src/component/messages/nl.d.ts +3 -0
- package/dist/src/component/messages/nl.d.ts.map +1 -0
- package/dist/src/component/messages/pl.d.ts +3 -0
- package/dist/src/component/messages/pl.d.ts.map +1 -0
- package/dist/src/component/messages/pt.d.ts +3 -0
- package/dist/src/component/messages/pt.d.ts.map +1 -0
- package/dist/src/component/messages/ro.d.ts +3 -0
- package/dist/src/component/messages/ro.d.ts.map +1 -0
- package/dist/src/component/messages/ru.d.ts +3 -0
- package/dist/src/component/messages/ru.d.ts.map +1 -0
- package/dist/src/component/messages/sw.d.ts +3 -0
- package/dist/src/component/messages/sw.d.ts.map +1 -0
- package/dist/src/component/messages/th.d.ts +3 -0
- package/dist/src/component/messages/th.d.ts.map +1 -0
- package/dist/src/component/messages/tl.d.ts +3 -0
- package/dist/src/component/messages/tl.d.ts.map +1 -0
- package/dist/src/component/messages/tr.d.ts +3 -0
- package/dist/src/component/messages/tr.d.ts.map +1 -0
- package/dist/src/component/messages/uk.d.ts +3 -0
- package/dist/src/component/messages/uk.d.ts.map +1 -0
- package/dist/src/component/messages/ur.d.ts +3 -0
- package/dist/src/component/messages/ur.d.ts.map +1 -0
- package/dist/src/component/messages/vi.d.ts +3 -0
- package/dist/src/component/messages/vi.d.ts.map +1 -0
- package/dist/src/component/messages/zh-CN.d.ts +3 -0
- package/dist/src/component/messages/zh-CN.d.ts.map +1 -0
- package/dist/src/component/messages/zh-TW.d.ts +3 -0
- package/dist/src/component/messages/zh-TW.d.ts.map +1 -0
- package/dist/src/component/miner.d.ts +108 -0
- package/dist/src/component/miner.d.ts.map +1 -0
- package/dist/src/component/render.d.ts +11 -0
- package/dist/src/component/render.d.ts.map +1 -0
- package/dist/src/component/state.d.ts +142 -0
- package/dist/src/component/state.d.ts.map +1 -0
- package/dist/src/component/styles.d.ts +2 -0
- package/dist/src/component/styles.d.ts.map +1 -0
- package/dist/src/component/viewModel.d.ts +281 -0
- package/dist/src/component/viewModel.d.ts.map +1 -0
- package/dist/src/component/wallets.d.ts +40 -0
- package/dist/src/component/wallets.d.ts.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/keys/KeyManager.d.ts +132 -0
- package/dist/src/keys/KeyManager.d.ts.map +1 -0
- package/dist/src/keys/derivation.d.ts +58 -0
- package/dist/src/keys/derivation.d.ts.map +1 -0
- package/dist/src/keys/signing.d.ts +44 -0
- package/dist/src/keys/signing.d.ts.map +1 -0
- package/dist/src/provider/WBIPProvider.d.ts +74 -0
- package/dist/src/provider/WBIPProvider.d.ts.map +1 -0
- package/dist/src/react/ZeldWalletCard.d.ts +29 -0
- package/dist/src/react/ZeldWalletCard.d.ts.map +1 -0
- package/dist/src/react/index.d.ts +3 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/useZeldWalletController.d.ts +28 -0
- package/dist/src/react/useZeldWalletController.d.ts.map +1 -0
- package/dist/src/storage/SecureStorage.d.ts +183 -0
- package/dist/src/storage/SecureStorage.d.ts.map +1 -0
- package/dist/src/storage/constants.d.ts +59 -0
- package/dist/src/storage/constants.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +245 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/ui/Modal.d.ts +19 -0
- package/dist/src/ui/Modal.d.ts.map +1 -0
- package/dist/src/unifiedWallet.d.ts +29 -0
- package/dist/src/unifiedWallet.d.ts.map +1 -0
- package/dist/src/utils/crypto.d.ts +36 -0
- package/dist/src/utils/crypto.d.ts.map +1 -0
- package/dist/src/utils/encoding.d.ts +46 -0
- package/dist/src/utils/encoding.d.ts.map +1 -0
- package/dist/src/utils/validation.d.ts +42 -0
- package/dist/src/utils/validation.d.ts.map +1 -0
- package/dist/wasm/package.json +31 -0
- package/dist/wasm/zeldhash_miner_wasm.d.ts +82 -0
- package/dist/wasm/zeldhash_miner_wasm.js +1404 -0
- package/dist/wasm/zeldhash_miner_wasm_bg.wasm +0 -0
- package/dist/wasm/zeldhash_miner_wasm_bg.wasm.d.ts +27 -0
- package/dist/worker.js +338 -0
- package/dist/zeldwallet.es.js +36558 -0
- package/dist/zeldwallet.es.js.map +1 -0
- package/package.json +99 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# ZeldWallet
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ouziel-slama/zeldwallet/actions/workflows/lint.yml)
|
|
4
|
+
[](https://github.com/ouziel-slama/zeldwallet/actions/workflows/test.yml)
|
|
5
|
+
[](https://codecov.io/gh/ouziel-slama/zeldwallet)
|
|
6
|
+
[](https://www.npmjs.com/package/zeldwallet)
|
|
7
|
+
|
|
8
|
+
Lightweight JavaScript library for creating a Bitcoin wallet directly in the browser.
|
|
9
|
+
|
|
10
|
+
ZeldWallet combines Bitcoin key generation, secure storage (IndexedDB + Web Crypto API), and WBIP004 standard compatibility to be detected by existing Bitcoin applications like sats-connect.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🔐 **Secure Storage**: AES-256-GCM encryption with PBKDF2 key derivation
|
|
15
|
+
- 🔑 **BIP Standards**: Full support for BIP32/39/44/49/84/86
|
|
16
|
+
- 🌐 **Browser Native**: No extensions needed, works directly in the browser
|
|
17
|
+
- 📱 **WBIP Compatible**: Works with sats-connect and other WBIP004-compatible apps
|
|
18
|
+
- ⚡ **Multiple Address Types**: Legacy, SegWit, Nested SegWit, and Taproot
|
|
19
|
+
- 🔓 **Flexible Security**: Start passwordless for quick onboarding, add password later
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install zeldwallet
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Create a New Wallet
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { ZeldWallet, ConfirmationModal } from 'zeldwallet';
|
|
33
|
+
|
|
34
|
+
const wallet = new ZeldWallet();
|
|
35
|
+
|
|
36
|
+
// Optional: use the built-in modal confirmation UI (auto-enabled in browsers)
|
|
37
|
+
wallet.useDefaultConfirmationModal();
|
|
38
|
+
|
|
39
|
+
// Quick creation WITHOUT password (simple onboarding)
|
|
40
|
+
const { mnemonic } = await wallet.create();
|
|
41
|
+
console.log('Backup:', mnemonic); // IMPORTANT: User must save this!
|
|
42
|
+
|
|
43
|
+
// OR with password (more secure)
|
|
44
|
+
const { mnemonic: securedMnemonic } = await wallet.create('my-secure-password');
|
|
45
|
+
|
|
46
|
+
// User can add a password later
|
|
47
|
+
await wallet.setPassword('my-secure-password');
|
|
48
|
+
|
|
49
|
+
// Make the wallet discoverable by sats-connect
|
|
50
|
+
wallet.registerProvider({
|
|
51
|
+
id: 'ZeldWallet',
|
|
52
|
+
name: 'Zeld Wallet',
|
|
53
|
+
icon: 'data:image/svg+xml;base64,...'
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Restore from Mnemonic
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const wallet = new ZeldWallet();
|
|
61
|
+
await wallet.restore('your twelve word mnemonic phrase goes here ...', 'optional-password');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Backup & Restore
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Export (requires wallet password – disable the button until hasPassword() is true)
|
|
68
|
+
if (!(await wallet.hasPassword())) {
|
|
69
|
+
await wallet.setPassword('my-secure-password');
|
|
70
|
+
}
|
|
71
|
+
const backupString = await wallet.exportBackup('backup-password');
|
|
72
|
+
|
|
73
|
+
// Import (walletPassword is required to hydrate storage)
|
|
74
|
+
await wallet.importBackup(backupString, 'backup-password', 'my-secure-password');
|
|
75
|
+
```
|
|
76
|
+
Gate the “Export backup” action behind a password prompt or disable it until `await wallet.hasPassword()` resolves to `true` to avoid confusing users.
|
|
77
|
+
|
|
78
|
+
### Get Addresses
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const addresses = wallet.getAddresses(['payment', 'ordinals']);
|
|
82
|
+
console.log(addresses);
|
|
83
|
+
// [
|
|
84
|
+
// { address: 'bc1q...', publicKey: '...', purpose: 'payment', addressType: 'p2wpkh', derivationPath: "m/84'/0'/0'/0/0" },
|
|
85
|
+
// { address: 'bc1p...', publicKey: '...', purpose: 'ordinals', addressType: 'p2tr', derivationPath: "m/86'/0'/0'/0/0" }
|
|
86
|
+
// ]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Sign a Message
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const signature = await wallet.signMessage('Hello Bitcoin!', 'bc1q...');
|
|
93
|
+
console.log(signature); // Base64 encoded signature
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Sign a PSBT
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const signedPsbt = await wallet.signPsbt(psbtBase64, [
|
|
100
|
+
{ index: 0, address: 'bc1q...' }
|
|
101
|
+
]);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### WBIP Provider Registration
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Register as a WBIP provider (makes wallet detectable by sats-connect)
|
|
108
|
+
wallet.registerProvider({
|
|
109
|
+
id: 'ZeldWallet',
|
|
110
|
+
name: 'Zeld Wallet',
|
|
111
|
+
icon: 'data:image/svg+xml;base64,...'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Now apps using sats-connect can discover and use ZeldWallet!
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Confirmation UI
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { ConfirmationModal } from 'zeldwallet';
|
|
121
|
+
|
|
122
|
+
const modal = new ConfirmationModal();
|
|
123
|
+
wallet.useConfirmationModal(modal); // or wallet.useDefaultConfirmationModal();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
ZeldWallet uses the provided confirmation handler for connect/sign flows. In browsers the built-in modal is enabled automatically; in SSR/native contexts plug in your own handler instead of relying on `window.confirm`.
|
|
127
|
+
|
|
128
|
+
### Web Component
|
|
129
|
+
|
|
130
|
+
`<zeld-wallet-ui>` is a native web component that silently creates/unlocks a wallet (passwordless by default), registers the WBIP provider, and renders payment + ordinals addresses. If the wallet is password-protected it switches to a locked state with a password form.
|
|
131
|
+
|
|
132
|
+
```html
|
|
133
|
+
<script type="module">
|
|
134
|
+
import { defineZeldWalletUI } from 'zeldwallet';
|
|
135
|
+
defineZeldWalletUI(); // no-op if already defined
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<zeld-wallet-ui lang="en" autoconnect="true"></zeld-wallet-ui>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Attributes / props:
|
|
142
|
+
- `lang`: i18n (`en` default, `fr` available, falls back `en`)
|
|
143
|
+
- `network`: `mainnet` or `testnet` (applied after unlock)
|
|
144
|
+
- `autoconnect`: defaults to `true`; set `autoconnect="false"` to require a manual `connect()`
|
|
145
|
+
|
|
146
|
+
CSS hooks (shadow DOM classes): `zeldwallet-card`, `zeldwallet-header`, `zeldwallet-title`, `zeldwallet-subtitle`, `zeldwallet-rows`, `zeldwallet-row`, `zeldwallet-label`, `zeldwallet-value`, `zeldwallet-copy`, `zeldwallet-status`, `zeldwallet-status--error`, `zeldwallet-status--loading`, `zeldwallet-password-form`, `zeldwallet-password-fields`, `zeldwallet-password-input`, `zeldwallet-password-button`, `zeldwallet-password-error`.
|
|
147
|
+
|
|
148
|
+
See `examples/web-component.html` for a complete demo with language toggle and style overrides.
|
|
149
|
+
|
|
150
|
+
### React Component
|
|
151
|
+
|
|
152
|
+
`ZeldWalletCard` is a thin React wrapper around the **same** `<zeld-wallet-ui>` custom element; there is no separate React UI to maintain. It autoconnects by default, registers the WBIP provider, and exposes a `connect(password?)` imperative handle via `ref`.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
import { ZeldWalletCard, type ZeldWalletCardRef } from 'zeldwallet';
|
|
156
|
+
import { useRef } from 'react';
|
|
157
|
+
|
|
158
|
+
const walletRef = useRef<ZeldWalletCardRef>(null);
|
|
159
|
+
|
|
160
|
+
<ZeldWalletCard ref={walletRef} lang="en" network="mainnet" variant="dark" autoconnect />;
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Props:
|
|
164
|
+
- `lang`: `en` or `fr` (defaults to `en`)
|
|
165
|
+
- `network`: `mainnet` | `testnet` (applied after unlock)
|
|
166
|
+
- `autoconnect`: defaults to `true`; set `false` to require manual `connect()`
|
|
167
|
+
- `variant`: `light` (default) or `dark` to mirror the web component classes
|
|
168
|
+
- `className`: optional custom wrapper class
|
|
169
|
+
|
|
170
|
+
See `examples/react` for a Vite demo with language toggle, dark mode, destroy/remount, and message signing.
|
|
171
|
+
|
|
172
|
+
## Examples
|
|
173
|
+
|
|
174
|
+
- Run `npm run build` once to refresh `dist/zeldwallet.es.js`, then `npm run dev`.
|
|
175
|
+
- Open http://localhost:5173/ (examples root) to pick the Web Component, sats-connect, or React demos.
|
|
176
|
+
|
|
177
|
+
## API Reference
|
|
178
|
+
|
|
179
|
+
### Lifecycle Methods
|
|
180
|
+
|
|
181
|
+
| Method | Description |
|
|
182
|
+
|--------|-------------|
|
|
183
|
+
| `create(password?)` | Create a new wallet, returns mnemonic |
|
|
184
|
+
| `restore(mnemonic, password?)` | Restore wallet from mnemonic |
|
|
185
|
+
| `unlock(password?)` | Unlock an existing wallet |
|
|
186
|
+
| `lock()` | Lock the wallet, clear sensitive data |
|
|
187
|
+
| `exists()` | Check if a wallet exists |
|
|
188
|
+
| `destroy()` | Permanently delete all wallet data |
|
|
189
|
+
|
|
190
|
+
### Password Management
|
|
191
|
+
|
|
192
|
+
| Method | Description |
|
|
193
|
+
|--------|-------------|
|
|
194
|
+
| `setPassword(password)` | Add password protection |
|
|
195
|
+
| `changePassword(old, new)` | Change the password |
|
|
196
|
+
| `removePassword(current)` | Remove password protection |
|
|
197
|
+
| `hasPassword()` | Check if password protected |
|
|
198
|
+
|
|
199
|
+
### Address & Signing
|
|
200
|
+
|
|
201
|
+
| Method | Description |
|
|
202
|
+
|--------|-------------|
|
|
203
|
+
| `getAddresses(purposes)` | Get addresses for purposes |
|
|
204
|
+
| `signMessage(message, address, protocol?)` | Sign a message |
|
|
205
|
+
| `signPsbt(psbt, inputsToSign)` | Sign a PSBT |
|
|
206
|
+
|
|
207
|
+
### Network & Backup
|
|
208
|
+
|
|
209
|
+
| Method | Description |
|
|
210
|
+
|--------|-------------|
|
|
211
|
+
| `getNetwork()` | Get current network |
|
|
212
|
+
| `setNetwork(network)` | Set network (mainnet/testnet) |
|
|
213
|
+
| `exportMnemonic()` | Export the mnemonic phrase |
|
|
214
|
+
| `exportBackup(password)` | Export encrypted backup |
|
|
215
|
+
| `importBackup(backup, backupPwd, walletPwd?)` | Import backup |
|
|
216
|
+
|
|
217
|
+
### Events
|
|
218
|
+
|
|
219
|
+
| Event | Description |
|
|
220
|
+
|-------|-------------|
|
|
221
|
+
| `lock` | Wallet was locked |
|
|
222
|
+
| `unlock` | Wallet was unlocked |
|
|
223
|
+
| `accountsChanged` | Addresses changed |
|
|
224
|
+
| `networkChanged` | Network changed |
|
|
225
|
+
|
|
226
|
+
## Security Considerations
|
|
227
|
+
|
|
228
|
+
| Mode | Protection Level | Best For |
|
|
229
|
+
|------|-----------------|----------|
|
|
230
|
+
| No password | AES key stored in IndexedDB | Quick onboarding, small amounts |
|
|
231
|
+
| With password | Key derived via PBKDF2 (600k iterations) | Medium amounts |
|
|
232
|
+
| Hardware wallet | (not supported yet) | Large amounts |
|
|
233
|
+
|
|
234
|
+
### ⚠️ Important Security Notes
|
|
235
|
+
|
|
236
|
+
- **Backup your mnemonic**: The 12/24 word phrase is the only way to recover your wallet
|
|
237
|
+
- **Designed for small amounts**: For large sums, use a hardware wallet
|
|
238
|
+
- **Browser storage**: Data persists in IndexedDB, vulnerable to XSS if site is compromised
|
|
239
|
+
- **Add a password**: Protects against casual physical access and some browser extensions
|
|
240
|
+
- **Passwordless mode is weaker**: When the browser cannot persist a non-extractable key (e.g., some Safari/Firefox versions), a raw key envelope is stored in IndexedDB. Malicious extensions could exfiltrate it—set a password to harden the wallet.
|
|
241
|
+
- **Lock when idle**: `wallet.lock()` wipes keys from memory and closes storage handles.
|
|
242
|
+
- **No key logging**: The library avoids logging secrets; keep your app logs clean too.
|
|
243
|
+
- **CSP**: Ship a strict Content-Security-Policy (no inline/eval) to reduce XSS risk around IndexedDB/crypto usage.
|
|
244
|
+
|
|
245
|
+
### Security posture comparison
|
|
246
|
+
|
|
247
|
+
| Aspect | ZeldWallet (no password, no backup) | ZeldWallet (password, no backup) | ZeldWallet (password + backup) | Extension wallet (e.g., Xverse) | Custodial wallet (e.g., Web3Auth) |
|
|
248
|
+
|---|---|---|---|---|---|
|
|
249
|
+
| Key custody | Fully self-custodial | Fully self-custodial | Fully self-custodial | Self-custodial | Custodial / shared custody |
|
|
250
|
+
| Secrets at rest | Raw AES key envelope in IndexedDB; weak against device malware/XSS | AES key derived via PBKDF2 (600k); stronger against casual access, still in IndexedDB | Encrypted at rest; off-device backup available with backup password | Stored in extension storage/background page; exposed to extension supply-chain risks | Keys or recovery shares held by service; relies on server/cloud security |
|
|
251
|
+
| Exposure surface | Browser tab + other extensions; XSS can read storage | Same surface, but password gates decryption | Same as passworded; backup allows cold copy off the device | Extension APIs and any installed extensions; phishing of extension permissions | Web/app auth; service infrastructure; phishing of login factors |
|
|
252
|
+
| Device loss | Funds lost (no recovery) | Funds lost (no recovery) | Recoverable via mnemonic or encrypted backup | Recoverable via seed; loss if no seed backup | Recoverable via account recovery / service-managed backup |
|
|
253
|
+
| Recommended use | Only for throwaway/test funds | Small/medium amounts; add backup ASAP | Primary mode for non-custodial users; safer against loss | Small/medium amounts; depends on extension supply chain | Convenience; mitigates device loss; trust placed in provider |
|
|
254
|
+
|
|
255
|
+
Using ZeldWallet inside a web page means the wallet shares the page’s security boundary: a compromised site, injected script (XSS), or malicious extension can try to read IndexedDB data or page memory. Browser extensions like Xverse run with background-page storage and stricter isolation, so they are less exposed to the host site—but they add their own supply-chain and permission phishing risks. Use a strong CSP, avoid untrusted extensions, and prefer password + backup for ZeldWallet.
|
|
256
|
+
|
|
257
|
+
### Integration checklist for developers
|
|
258
|
+
|
|
259
|
+
- Enforce CSP: start with `default-src 'self'; script-src 'self' 'nonce-{random}'; style-src 'self' 'nonce-{random}'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none';` and add only the `connect-src`, `img-src`, `font-src` you truly need. Avoid `'unsafe-inline'`/`'unsafe-eval'`; use nonces or hashes for any inline script/style you must keep.
|
|
260
|
+
- Avoid inline scripts/styles in your app and in any ZeldWallet integration code; keep everything external or nonce-based.
|
|
261
|
+
- Minimize third-party scripts/extensions on pages hosting ZeldWallet; treat every added script as part of your attack surface.
|
|
262
|
+
- Always enable wallet password and encourage users to export an encrypted backup; lock the wallet when idle.
|
|
263
|
+
- Do not log secrets; scrub request/response bodies and console logs around signing flows.
|
|
264
|
+
- If embedding ZeldWallet in an iframe, set `sandbox` appropriately and restrict `allow` attributes; prefer same-origin frames to reduce cross-context exposure.
|
|
265
|
+
|
|
266
|
+
## Development
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Install dependencies
|
|
270
|
+
npm install
|
|
271
|
+
|
|
272
|
+
# Development server
|
|
273
|
+
npm run dev
|
|
274
|
+
|
|
275
|
+
# Build for production
|
|
276
|
+
npm run build
|
|
277
|
+
|
|
278
|
+
# Run tests
|
|
279
|
+
npm test
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Build Outputs
|
|
283
|
+
|
|
284
|
+
`npm run build` emits to `dist/`:
|
|
285
|
+
- ES module: `zeldwallet.es.js` (used by `exports.import` and `main`)
|
|
286
|
+
- TypeScript declarations: `index.d.ts` and nested `.d.ts` files
|
|
287
|
+
|
|
288
|
+
## Standards
|
|
289
|
+
|
|
290
|
+
- [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) - HD Wallets
|
|
291
|
+
- [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) - Mnemonic code
|
|
292
|
+
- [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) - Multi-Account HD
|
|
293
|
+
- [BIP84](https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki) - Native SegWit
|
|
294
|
+
- [BIP86](https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki) - Taproot
|
|
295
|
+
- [WBIP004](https://wbips.netlify.app) - Browser Wallet Standard
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
This project is licensed under either of:
|
|
300
|
+
|
|
301
|
+
- [Apache License, Version 2.0](LICENSE-APACHE)
|
|
302
|
+
- [MIT License](LICENSE-MIT)
|
|
303
|
+
|
|
304
|
+
at your option.
|
|
305
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { ConfirmationHandler } from './provider/WBIPProvider';
|
|
2
|
+
import { ConfirmationModal } from './ui/Modal';
|
|
3
|
+
import { AddressPurpose, AddressInfo, NetworkType, WalletEvent, EventHandler, SignInputOptions, WBIPProviderOptions } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { SecureStorage } from './storage/SecureStorage';
|
|
6
|
+
export { KeyManager } from './keys/KeyManager';
|
|
7
|
+
export { ConfirmationModal } from './ui/Modal';
|
|
8
|
+
/**
|
|
9
|
+
* Main ZeldWallet class
|
|
10
|
+
*
|
|
11
|
+
* Provides a simple API for wallet creation, management, and signing.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ZeldWallet {
|
|
14
|
+
private static defaultInstance;
|
|
15
|
+
private storage;
|
|
16
|
+
private keyManager;
|
|
17
|
+
private provider;
|
|
18
|
+
private eventHandlers;
|
|
19
|
+
private unlocked;
|
|
20
|
+
private lastProviderId;
|
|
21
|
+
private config;
|
|
22
|
+
private defaultModal?;
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Create a new wallet
|
|
26
|
+
* @param password - Optional password for encryption. If not provided, uses browser-stored key.
|
|
27
|
+
* @returns The generated mnemonic phrase (MUST be backed up by user!)
|
|
28
|
+
*/
|
|
29
|
+
create(password?: string, mnemonicPassphrase?: string): Promise<{
|
|
30
|
+
mnemonic: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Restore a wallet from a mnemonic phrase
|
|
34
|
+
* @param mnemonic - The BIP39 mnemonic phrase
|
|
35
|
+
* @param password - Optional password for encryption
|
|
36
|
+
* @param mnemonicPassphrase - Optional BIP39 passphrase
|
|
37
|
+
* @param customPaths - Optional custom derivation paths for payment and ordinals addresses
|
|
38
|
+
*/
|
|
39
|
+
restore(mnemonic: string, password?: string, mnemonicPassphrase?: string, customPaths?: {
|
|
40
|
+
payment?: string;
|
|
41
|
+
ordinals?: string;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Unlock an existing wallet
|
|
45
|
+
* @param password - The password (if password-protected)
|
|
46
|
+
*/
|
|
47
|
+
unlock(password?: string, mnemonicPassphrase?: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Lock the wallet - clear sensitive data from memory
|
|
50
|
+
*/
|
|
51
|
+
lock(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a wallet exists in storage
|
|
54
|
+
*/
|
|
55
|
+
exists(): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Destroy the wallet - permanently delete all data
|
|
58
|
+
*/
|
|
59
|
+
destroy(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Add password protection to a passwordless wallet
|
|
62
|
+
*/
|
|
63
|
+
setPassword(password: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Change the wallet password
|
|
66
|
+
*/
|
|
67
|
+
changePassword(oldPassword: string, newPassword: string, options?: {
|
|
68
|
+
iterations?: number;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Remove password protection (revert to passwordless mode)
|
|
72
|
+
*/
|
|
73
|
+
removePassword(currentPassword: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Check if the wallet has password protection
|
|
76
|
+
*/
|
|
77
|
+
hasPassword(): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Check if the wallet has ever produced a backup
|
|
80
|
+
*/
|
|
81
|
+
hasBackup(): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Mark the wallet as backed up (e.g., when restoring from mnemonic)
|
|
84
|
+
*/
|
|
85
|
+
markBackupCompleted(timestamp?: number): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Get addresses for the specified purposes
|
|
88
|
+
*/
|
|
89
|
+
getAddresses(purposes: AddressPurpose[]): AddressInfo[];
|
|
90
|
+
/**
|
|
91
|
+
* Sign a message with the private key of the specified address
|
|
92
|
+
*/
|
|
93
|
+
signMessage(message: string, address: string, protocol?: 'ecdsa' | 'bip322-simple'): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Sign a PSBT (Partially Signed Bitcoin Transaction)
|
|
96
|
+
*/
|
|
97
|
+
signPsbt(psbtBase64: string, inputsToSign: SignInputOptions[]): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Configure address lookup windows used when resolving addresses to paths.
|
|
100
|
+
* Useful for wallets with large index gaps.
|
|
101
|
+
*/
|
|
102
|
+
setAddressLookupConfig(config: Partial<{
|
|
103
|
+
maxAccount: number;
|
|
104
|
+
receiveWindow: number;
|
|
105
|
+
changeWindow: number;
|
|
106
|
+
}>): void;
|
|
107
|
+
/**
|
|
108
|
+
* Get the current network
|
|
109
|
+
*/
|
|
110
|
+
getNetwork(): NetworkType;
|
|
111
|
+
/**
|
|
112
|
+
* Set the network (mainnet or testnet)
|
|
113
|
+
*/
|
|
114
|
+
setNetwork(network: NetworkType): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Export the mnemonic phrase
|
|
117
|
+
* WARNING: This exposes the seed - use with caution and always re-encrypt!
|
|
118
|
+
*/
|
|
119
|
+
exportMnemonic(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Export wallet backup as a portable string
|
|
122
|
+
*/
|
|
123
|
+
exportBackup(backupPassword: string): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Import wallet from backup string
|
|
126
|
+
*/
|
|
127
|
+
importBackup(backupString: string, backupPassword: string, walletPassword?: string, options?: {
|
|
128
|
+
overwrite?: boolean;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Subscribe to wallet events
|
|
132
|
+
*/
|
|
133
|
+
on<T = unknown>(event: WalletEvent, handler: EventHandler<T>): void;
|
|
134
|
+
/**
|
|
135
|
+
* Unsubscribe from wallet events
|
|
136
|
+
*/
|
|
137
|
+
off<T = unknown>(event: WalletEvent, handler: EventHandler<T>): void;
|
|
138
|
+
/**
|
|
139
|
+
* Emit an event
|
|
140
|
+
*/
|
|
141
|
+
private emit;
|
|
142
|
+
/**
|
|
143
|
+
* Emit the latest accounts snapshot to listeners (used after unlock/create).
|
|
144
|
+
*/
|
|
145
|
+
private emitAccountsSnapshot;
|
|
146
|
+
/**
|
|
147
|
+
* Parse a backup envelope or fall back to legacy format.
|
|
148
|
+
*/
|
|
149
|
+
private parseBackupEnvelope;
|
|
150
|
+
/**
|
|
151
|
+
* Lightweight structural validation of a backup envelope to catch tampering.
|
|
152
|
+
*/
|
|
153
|
+
private isValidBackupEnvelope;
|
|
154
|
+
/**
|
|
155
|
+
* Load persisted configuration (network, custom paths, etc.) from storage.
|
|
156
|
+
*/
|
|
157
|
+
private applyStoredConfig;
|
|
158
|
+
/**
|
|
159
|
+
* Persist current configuration to storage.
|
|
160
|
+
*/
|
|
161
|
+
private persistConfig;
|
|
162
|
+
/**
|
|
163
|
+
* Check if the wallet is currently unlocked
|
|
164
|
+
*/
|
|
165
|
+
isUnlocked(): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Ensure the wallet is unlocked before performing operations
|
|
168
|
+
*/
|
|
169
|
+
private ensureUnlocked;
|
|
170
|
+
/**
|
|
171
|
+
* Enforce basic password strength for new passwords/backups.
|
|
172
|
+
* Existing (possibly weak) passwords are still accepted for decryption flows.
|
|
173
|
+
* In test environments, allow shorter passwords to keep fixtures lightweight.
|
|
174
|
+
*/
|
|
175
|
+
private assertPasswordStrength;
|
|
176
|
+
private isTestEnvironment;
|
|
177
|
+
/**
|
|
178
|
+
* Get the shared singleton instance used by static helpers.
|
|
179
|
+
*/
|
|
180
|
+
private static getDefaultInstance;
|
|
181
|
+
static create(password?: string, mnemonicPassphrase?: string): Promise<{
|
|
182
|
+
mnemonic: string;
|
|
183
|
+
}>;
|
|
184
|
+
static restore(mnemonic: string, password?: string, mnemonicPassphrase?: string, customPaths?: {
|
|
185
|
+
payment?: string;
|
|
186
|
+
ordinals?: string;
|
|
187
|
+
}): Promise<void>;
|
|
188
|
+
static unlock(password?: string, mnemonicPassphrase?: string): Promise<void>;
|
|
189
|
+
static lock(): void;
|
|
190
|
+
static exists(): Promise<boolean>;
|
|
191
|
+
static destroy(): Promise<void>;
|
|
192
|
+
static registerProvider(options: WBIPProviderOptions): void;
|
|
193
|
+
static unregisterProvider(id?: string): void;
|
|
194
|
+
static setConfirmationHandler(handler?: ConfirmationHandler): void;
|
|
195
|
+
static useConfirmationModal(modal: ConfirmationModal): void;
|
|
196
|
+
static useDefaultConfirmationModal(): void;
|
|
197
|
+
static setPassword(password: string): Promise<void>;
|
|
198
|
+
static changePassword(oldPassword: string, newPassword: string, options?: {
|
|
199
|
+
iterations?: number;
|
|
200
|
+
}): Promise<void>;
|
|
201
|
+
static removePassword(currentPassword: string): Promise<void>;
|
|
202
|
+
static hasPassword(): Promise<boolean>;
|
|
203
|
+
static hasBackup(): Promise<boolean>;
|
|
204
|
+
static markBackupCompleted(timestamp?: number): Promise<void>;
|
|
205
|
+
static exportBackup(backupPassword: string): Promise<string>;
|
|
206
|
+
static importBackup(backup: string, backupPassword: string, walletPassword?: string, options?: {
|
|
207
|
+
overwrite?: boolean;
|
|
208
|
+
}): Promise<void>;
|
|
209
|
+
static getAddresses(purposes: AddressPurpose[]): AddressInfo[];
|
|
210
|
+
static signMessage(message: string, address: string, protocol?: 'ecdsa' | 'bip322-simple'): Promise<string>;
|
|
211
|
+
static signPsbt(psbt: string, options: SignInputOptions[]): Promise<string>;
|
|
212
|
+
static on(event: WalletEvent, handler: EventHandler): void;
|
|
213
|
+
static off(event: WalletEvent, handler: EventHandler): void;
|
|
214
|
+
static isUnlocked(): boolean;
|
|
215
|
+
static getNetwork(): NetworkType;
|
|
216
|
+
static setNetwork(network: NetworkType): Promise<void>;
|
|
217
|
+
static setAddressLookupConfig(config: Partial<{
|
|
218
|
+
maxAccount: number;
|
|
219
|
+
receiveWindow: number;
|
|
220
|
+
changeWindow: number;
|
|
221
|
+
}>): void;
|
|
222
|
+
/**
|
|
223
|
+
* Override the confirmation handler used by the WBIP provider.
|
|
224
|
+
* Useful to plug in custom modals or native prompts.
|
|
225
|
+
*/
|
|
226
|
+
setConfirmationHandler(handler?: ConfirmationHandler): void;
|
|
227
|
+
/**
|
|
228
|
+
* Use a provided ConfirmationModal instance for UX prompts.
|
|
229
|
+
*/
|
|
230
|
+
useConfirmationModal(modal: ConfirmationModal): void;
|
|
231
|
+
/**
|
|
232
|
+
* Use the built-in modal when running in a browser environment.
|
|
233
|
+
*/
|
|
234
|
+
useDefaultConfirmationModal(): void;
|
|
235
|
+
/**
|
|
236
|
+
* Register as a WBIP provider
|
|
237
|
+
* This makes the wallet discoverable by apps using sats-connect
|
|
238
|
+
*/
|
|
239
|
+
registerProvider(options: WBIPProviderOptions): void;
|
|
240
|
+
/**
|
|
241
|
+
* Unregister as a WBIP provider
|
|
242
|
+
*/
|
|
243
|
+
unregisterProvider(id?: string): void;
|
|
244
|
+
/**
|
|
245
|
+
* Reset provider access grants (used on lock/destroy).
|
|
246
|
+
*/
|
|
247
|
+
private resetProviderAccess;
|
|
248
|
+
/**
|
|
249
|
+
* Enable the default modal confirmation handler when the DOM is available.
|
|
250
|
+
*/
|
|
251
|
+
private tryEnableDefaultConfirmation;
|
|
252
|
+
}
|
|
253
|
+
export default ZeldWallet;
|
|
254
|
+
//# sourceMappingURL=ZeldWallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZeldWallet.d.ts","sourceRoot":"","sources":["../../src/ZeldWallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EAEX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,SAAS,CAAC;AAYjB,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,UAAU;IAErB,OAAO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AAM,CAAC;WAIL,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAI1D,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAI3D,MAAM,CAAC,UAAU,IAAI,OAAO;IAK5B,MAAM,CAAC,UAAU,IAAI,WAAW;WAInB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI;IAIzH;;;OAGG;IACH,sBAAsB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAI3D;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAKpD;;OAEG;IACH,2BAA2B,IAAI,IAAI;IAYnC;;;OAGG;IACH,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAOpD;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IASrC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,4BAA4B;CAMrC;AA2BD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NetworkType } from '../types';
|
|
2
|
+
import { BaseElement } from './constants';
|
|
3
|
+
export declare class ZeldWalletUI extends BaseElement {
|
|
4
|
+
private controller;
|
|
5
|
+
private snapshot;
|
|
6
|
+
private unsubscribe?;
|
|
7
|
+
private shadowRootRef?;
|
|
8
|
+
private initialVariant;
|
|
9
|
+
private variantApplied;
|
|
10
|
+
private boundActivityHandler?;
|
|
11
|
+
/**
|
|
12
|
+
* Activity events that reset the idle timer (for shadow DOM).
|
|
13
|
+
*/
|
|
14
|
+
private static readonly ACTIVITY_EVENTS;
|
|
15
|
+
private applyVariant;
|
|
16
|
+
constructor();
|
|
17
|
+
static get observedAttributes(): string[];
|
|
18
|
+
get lang(): string;
|
|
19
|
+
set lang(value: string);
|
|
20
|
+
get network(): NetworkType;
|
|
21
|
+
set network(value: NetworkType);
|
|
22
|
+
get variant(): 'light' | 'dark';
|
|
23
|
+
set variant(value: 'light' | 'dark');
|
|
24
|
+
get autoconnect(): boolean;
|
|
25
|
+
set autoconnect(value: boolean);
|
|
26
|
+
get electrsUrl(): string | null;
|
|
27
|
+
set electrsUrl(value: string | null);
|
|
28
|
+
get zeldhashApiUrl(): string | null;
|
|
29
|
+
set zeldhashApiUrl(value: string | null);
|
|
30
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
31
|
+
connectedCallback(): void;
|
|
32
|
+
disconnectedCallback(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Set up activity event listeners on the shadow DOM root.
|
|
35
|
+
* These events bubble up from the shadow DOM and notify the controller.
|
|
36
|
+
*/
|
|
37
|
+
private setupActivityListeners;
|
|
38
|
+
/**
|
|
39
|
+
* Remove activity event listeners from the shadow DOM root.
|
|
40
|
+
*/
|
|
41
|
+
private teardownActivityListeners;
|
|
42
|
+
/**
|
|
43
|
+
* Public API to set the locale programmatically.
|
|
44
|
+
*/
|
|
45
|
+
setLocale(lang?: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Public API to trigger (or retry) connection manually.
|
|
48
|
+
*/
|
|
49
|
+
connect(password?: string): Promise<void>;
|
|
50
|
+
private render;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Helper to define the custom element with an optional custom tag name.
|
|
54
|
+
*/
|
|
55
|
+
export declare function defineZeldWalletUI(tagName?: string): string;
|
|
56
|
+
//# sourceMappingURL=ZeldWalletUI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZeldWalletUI.d.ts","sourceRoot":"","sources":["../../../src/component/ZeldWalletUI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAY5C,OAAO,EAAE,WAAW,EAAoB,MAAM,aAAa,CAAC;AAK5D,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,aAAa,CAAC,CAAa;IACnC,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAa;IAE1C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAQ5B;IAEX,OAAO,CAAC,YAAY;;IAgCpB,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAMrB;IAED,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,WAAW,EAM7B;IAED,IAAI,OAAO,IAAI,OAAO,GAAG,MAAM,CAE9B;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAOlC;IAED,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,OAAO,EAG7B;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,IAAI,CAE9B;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAMlC;IAED,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAElC;IAED,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAMtC;IAED,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IA6B/F,iBAAiB,IAAI,IAAI;IAazB,oBAAoB,IAAI,IAAI;IAM5B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IASjC;;OAEG;IACH,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ9B;;OAEG;IACG,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,OAAO,CAAC,MAAM;CAuGf;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,MAAyB,GAAG,MAAM,CAQ7E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AddressInfo } from '../types';
|
|
2
|
+
export type UtxoResponse = {
|
|
3
|
+
txid: string;
|
|
4
|
+
vout: number;
|
|
5
|
+
value: number;
|
|
6
|
+
status: {
|
|
7
|
+
confirmed: boolean;
|
|
8
|
+
block_height?: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type ZeldBalanceResponse = {
|
|
12
|
+
txid: string;
|
|
13
|
+
vout: number;
|
|
14
|
+
balance: number;
|
|
15
|
+
};
|
|
16
|
+
export type BalanceResult = {
|
|
17
|
+
btcSats: number;
|
|
18
|
+
zeldBalance: number;
|
|
19
|
+
/** BTC balance in sats for payment address only (first address if multiple) */
|
|
20
|
+
btcPaymentSats?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Fetches combined balance for multiple addresses.
|
|
24
|
+
* Explicitly identifies the payment address by purpose to avoid ordering issues.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchBalances(addresses: AddressInfo[], electrsUrl?: string, zeldhashApiUrl?: string): Promise<BalanceResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Formats satoshis to BTC string with 8 decimal places.
|
|
29
|
+
* Uses locale-aware thousand separators when locale is provided.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatBtc(sats: number, locale?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Formats ZELD balance (stored in minimal units, 8 decimals).
|
|
34
|
+
* Uses locale-aware thousand separators when locale is provided.
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatZeld(balance: number, locale?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Truncates an address for display (first 6 + … + last 6 characters).
|
|
39
|
+
*/
|
|
40
|
+
export declare function truncateAddress(address: string, prefixLen?: number, suffixLen?: number): string;
|
|
41
|
+
//# sourceMappingURL=balance.d.ts.map
|