nexa-wallet-sdk 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.
Files changed (48) hide show
  1. package/.parcel-cache/3e09f086f3c4d605-AssetGraph +0 -0
  2. package/.parcel-cache/5eac57ec674cdae8-AssetGraph +0 -0
  3. package/.parcel-cache/data.mdb +0 -0
  4. package/.parcel-cache/e43547b6c9167b58-RequestGraph +0 -0
  5. package/.parcel-cache/ecfe15d74834bbfd-BundleGraph +0 -0
  6. package/.parcel-cache/lock.mdb +0 -0
  7. package/.parcel-cache/snapshot-e43547b6c9167b58.txt +2 -0
  8. package/README.md +445 -0
  9. package/dist/browser/index.js +2456 -0
  10. package/dist/browser/index.js.map +1 -0
  11. package/dist/index.d.ts +918 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +2915 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/index.mjs +2456 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/package.json +90 -0
  18. package/spec.md +257 -0
  19. package/src/index.ts +93 -0
  20. package/src/models/rostrum.entities.ts +159 -0
  21. package/src/models/transaction.entities.ts +46 -0
  22. package/src/models/wallet.entities.ts +42 -0
  23. package/src/network/RostrumProvider.ts +137 -0
  24. package/src/types.ts +0 -0
  25. package/src/utils/CommonUtils.ts +123 -0
  26. package/src/utils/TXUtils.ts +445 -0
  27. package/src/utils/TokenUtils.ts +75 -0
  28. package/src/utils/ValidationUtils.ts +86 -0
  29. package/src/utils/WalletUtils.ts +522 -0
  30. package/src/utils/WatchOnlyTXUtils.ts +275 -0
  31. package/src/wallet/Wallet.ts +397 -0
  32. package/src/wallet/WatchOnlyWallet.ts +169 -0
  33. package/src/wallet/accounts/AccountStore.ts +173 -0
  34. package/src/wallet/accounts/interfaces/BaseAccountInterface.ts +56 -0
  35. package/src/wallet/accounts/models/DappAccount.ts +80 -0
  36. package/src/wallet/accounts/models/DefaultAccount.ts +96 -0
  37. package/src/wallet/accounts/models/VaultAccount.ts +81 -0
  38. package/src/wallet/transactions/WalletTransactionCreator.ts +145 -0
  39. package/src/wallet/transactions/WatchOnlyTransactionCreator.ts +189 -0
  40. package/src/wallet/transactions/interfaces/TransactionCreator.ts +438 -0
  41. package/tests/core/tx/transactioncreator.test.ts +455 -0
  42. package/tests/core/tx/wallettransactioncreator.test.ts +362 -0
  43. package/tests/core/tx/watchonlytransactioncreator.test.ts +258 -0
  44. package/tests/core/wallet/accountstore.test.ts +341 -0
  45. package/tests/core/wallet/wallet.test.ts +69 -0
  46. package/tests/core/watchonlywallet/watchonlywallet.test.ts +251 -0
  47. package/tests/index.test.ts +12 -0
  48. package/tsconfig.json +113 -0
Binary file
Binary file
@@ -0,0 +1,2 @@
1
+ 874635454
2
+ 1752722741737175000
package/README.md ADDED
@@ -0,0 +1,445 @@
1
+ # Nexa Wallet SDK for TypeScript
2
+
3
+ A comprehensive TypeScript SDK for building applications on the Nexa blockchain. This SDK provides wallet functionality, transaction building, token operations, and more.
4
+
5
+ ## Features
6
+
7
+ - **Wallet Management**: Create wallets from seed phrases or private keys
8
+ - **Account Types**: Support for multiple account types (NEXA, Vault, DApp)
9
+ - **Transaction Building**: Fluent API for building and signing transactions
10
+ - **Token Operations**: Create, mint, melt, and transfer tokens and NFTs
11
+ - **Watch-Only Wallets**: Monitor addresses without storing private keys
12
+ - **Network Support**: Mainnet and testnet compatibility
13
+ - **Multiple Formats**: CommonJS, ES modules, and browser bundles
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @dolaned/wallet-sdk-ts
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Basic Wallet Setup
24
+
25
+ ```typescript
26
+ import { Wallet, rostrumProvider } from '@dolaned/wallet-sdk-ts'
27
+
28
+ // Connect to the network
29
+ await rostrumProvider.connect()
30
+
31
+ // Create wallet from seed phrase
32
+ const wallet = new Wallet(
33
+ 'your twelve word seed phrase goes here for wallet creation',
34
+ 'testnet' // or 'mainnet'
35
+ )
36
+
37
+ // Initialize wallet to discover accounts
38
+ await wallet.initialize()
39
+
40
+ // Get the default account
41
+ const account = wallet.accountStore.getAccount('1.0')
42
+ ```
43
+
44
+ ### Simple Transaction
45
+
46
+ ```typescript
47
+ // Send 100 NEXA
48
+ const tx = await wallet.newTransaction(account)
49
+ .onNetwork('testnet')
50
+ .sendTo('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc', '10000')
51
+ .populate()
52
+ .sign()
53
+ .build()
54
+
55
+ console.log('Transaction:', tx)
56
+ ```
57
+
58
+ ## Core Concepts
59
+
60
+ ### Accounts
61
+
62
+ The SDK supports different account types:
63
+
64
+ - **NEXA Account**: Standard accounts for regular transactions
65
+ - **Vault Account**: Secure storage accounts
66
+ - **DApp Account**: Application-specific accounts
67
+
68
+ ```typescript
69
+ // Get a new receiving address (This only returns a different address for default accounts)
70
+ const address = account.getNewAddress()
71
+
72
+ // Check account balance
73
+ const balance = account.balance
74
+ console.log('Confirmed:', balance.confirmed)
75
+ console.log('Unconfirmed:', balance.unconfirmed)
76
+
77
+ // Get transaction history
78
+ const transactions = await account.getTransactions()
79
+ ```
80
+
81
+ ### Transaction Building
82
+
83
+ All transactions follow the same pattern: **create → configure → populate → sign → build**
84
+
85
+ ```typescript
86
+ const tx = await wallet.newTransaction(account)
87
+ .onNetwork('testnet') // 1. Set network
88
+ .sendTo(address, amount) // 2. Configure outputs
89
+ .addOpReturn(data) // 3. Add optional data
90
+ .populate() // 4. Find inputs and calculate fees
91
+ .sign() // 5. Sign the transaction
92
+ .build() // 6. Get final transaction hex
93
+ ```
94
+
95
+ ## Transaction Examples
96
+
97
+ ### Basic Send Transaction
98
+
99
+ ```typescript
100
+ // Send 500 Nexa
101
+ const tx = await wallet.newTransaction(account)
102
+ .onNetwork('testnet')
103
+ .sendTo('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc', '50000')
104
+ .populate()
105
+ .sign()
106
+ .build()
107
+ ```
108
+
109
+ ### Multiple Outputs
110
+
111
+ ```typescript
112
+ const tx = await wallet.newTransaction(account)
113
+ .onNetwork('testnet')
114
+ .sendTo('nexatest:address1', '10000')
115
+ .sendTo('nexatest:address2', '20000')
116
+ .sendTo('nexatest:address3', '30000')
117
+ .addOpReturn('Multi-output transaction')
118
+ .populate()
119
+ .sign()
120
+ .build()
121
+ ```
122
+
123
+ ### Fee From Amount
124
+
125
+ ```typescript
126
+ // Deduct transaction fee from the send amount
127
+ const tx = await wallet.newTransaction(account)
128
+ .sendTo(recipient, '50000')
129
+ .feeFromAmount() // Fee will be subtracted from the 50000
130
+ .populate()
131
+ .sign()
132
+ .build()
133
+ ```
134
+
135
+ ### Consolidate UTXOs
136
+
137
+ ```typescript
138
+ // Consolidate all UTXOs to a single address
139
+ const tx = await wallet.newTransaction(account)
140
+ .consolidate('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc')
141
+ .populate()
142
+ .sign()
143
+ .build()
144
+ ```
145
+
146
+ ## Token Operations
147
+
148
+ ### Create a Fungible Token
149
+
150
+ ```typescript
151
+ const tx = await wallet.newTransaction(account)
152
+ .onNetwork('testnet')
153
+ .token(
154
+ 'MyToken', // Token name
155
+ 'MTK', // Ticker symbol
156
+ 8, // Decimal places
157
+ 'https://mytoken.com/info', // Documentation URL
158
+ 'sha256hash' // Documentation hash
159
+ )
160
+ .populate()
161
+ .sign()
162
+ .build()
163
+ ```
164
+
165
+ ### Create an NFT Collection
166
+
167
+ ```typescript
168
+ const tx = await wallet.newTransaction(account)
169
+ .onNetwork('testnet')
170
+ .collection(
171
+ 'My NFT Collection',
172
+ 'MNC',
173
+ 'https://mycollection.com/metadata',
174
+ 'collectionhash'
175
+ )
176
+ .populate()
177
+ .sign()
178
+ .build()
179
+ ```
180
+
181
+ ### Mint an NFT
182
+
183
+ ```typescript
184
+ const parentCollectionId = 'nexatest:tq8r37lcjlqazz7vuvug84q2ev50573hesrnxkv9y6hvhhl5k5qqqnmyf79mx'
185
+
186
+ const tx = await wallet.newTransaction(account)
187
+ .onNetwork('testnet')
188
+ .nft(
189
+ parentCollectionId,
190
+ 'https://mynft.com/content.zip',
191
+ 'contenthash123'
192
+ )
193
+ .populate()
194
+ .sign()
195
+ .build()
196
+ ```
197
+
198
+ ### Token Transfers
199
+
200
+ ```typescript
201
+ const tokenId = 'nexatest:tqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc'
202
+
203
+ const tx = await wallet.newTransaction(account)
204
+ .onNetwork('testnet')
205
+ .sendTo('nexatest:recipient', '1000') // Send NEXA
206
+ .sendToToken('nexatest:recipient', '500', tokenId) // Send tokens
207
+ .populate()
208
+ .sign()
209
+ .build()
210
+ ```
211
+
212
+ ### Mint Additional Tokens
213
+
214
+ ```typescript
215
+ const tx = await wallet.newTransaction(account)
216
+ .onNetwork('testnet')
217
+ .mint(tokenId, '1000000') // Mint 1,000,000 token units
218
+ .populate()
219
+ .sign()
220
+ .build()
221
+ ```
222
+
223
+ ### Burn (Melt) Tokens
224
+
225
+ ```typescript
226
+ const tx = await wallet.newTransaction(account)
227
+ .onNetwork('testnet')
228
+ .melt(tokenId, '500000') // Burn 500,000 token units
229
+ .populate()
230
+ .sign()
231
+ .build()
232
+ ```
233
+
234
+ ## Authority Management
235
+
236
+ ### Renew Token Authorities
237
+
238
+ ```typescript
239
+ const tx = await wallet.newTransaction(account)
240
+ .onNetwork('testnet')
241
+ .renewAuthority(
242
+ tokenId,
243
+ ['mint', 'melt'], // Permissions to renew
244
+ 'nexatest:nqtsq5g5...' // Optional: new authority address
245
+ )
246
+ .populate()
247
+ .sign()
248
+ .build()
249
+ ```
250
+
251
+ ### Delete Token Authority
252
+
253
+ ```typescript
254
+ const tx = await wallet.newTransaction(account)
255
+ .onNetwork('testnet')
256
+ .deleteAuthority(tokenId, 'abc123:0') // outpoint of authority to delete
257
+ .populate()
258
+ .sign()
259
+ .build()
260
+ ```
261
+
262
+ ## Watch-Only Wallets
263
+
264
+ Watch-only wallets allow you to monitor addresses and create unsigned transactions without storing private keys.
265
+
266
+ ### Create Watch-Only Wallet
267
+
268
+ ```typescript
269
+ import { WatchOnlyWallet } from '@dolaned/wallet-sdk-ts'
270
+
271
+ const watchOnlyWallet = new WatchOnlyWallet([
272
+ { address: 'nexatest:nqtsq5g5dsgh6mwjchqypn8hvdrjue0xpmz293fl7rm926xv' },
273
+ { address: 'nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc' }
274
+ ], 'testnet')
275
+ ```
276
+
277
+ ### Create Unsigned Transaction
278
+
279
+ ```typescript
280
+ const unsignedTx = await watchOnlyWallet.newTransaction()
281
+ .sendTo('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc', '100000')
282
+ .addOpReturn("Watch-only transaction")
283
+ .populate()
284
+ .build()
285
+ ```
286
+
287
+ ### Sign Watch-Only Transaction
288
+
289
+ ```typescript
290
+ // Pass the unsigned transaction to a wallet with private keys
291
+ const signedTx = await wallet.newTransaction(account, unsignedTx)
292
+ .sign()
293
+ .build()
294
+ ```
295
+
296
+ ### Subscribe to Address Updates
297
+
298
+ ```typescript
299
+ await watchOnlyWallet.subscribeToAddressNotifications((notification) => {
300
+ console.log('Address activity:', notification)
301
+ })
302
+ ```
303
+
304
+ ## Advanced Features
305
+
306
+ ### Parse Existing Transactions
307
+
308
+ ```typescript
309
+ // From hex string
310
+ const tx = await wallet.newTransaction(account)
311
+ .parseTxHex('0100000001...')
312
+ .sign()
313
+ .build()
314
+
315
+ // From buffer
316
+ const txBuffer = Buffer.from('0100000001...', 'hex')
317
+ const tx = await wallet.newTransaction(account)
318
+ .parseTxBuffer(txBuffer)
319
+ .sign()
320
+ .build()
321
+ ```
322
+
323
+ ### Export Wallet Data
324
+
325
+ ```typescript
326
+ const walletData = wallet.export()
327
+ // Contains encrypted seed and account information for backup
328
+ ```
329
+
330
+ ### Broadcasting Transactions
331
+
332
+ ```typescript
333
+ // Broadcast a signed transaction
334
+ const txId = await wallet.sendTransaction(signedTxHex)
335
+ console.log('Transaction ID:', txId)
336
+
337
+ // Or use watch-only wallet
338
+ const txId = await watchOnlyWallet.sendTransaction(signedTxHex)
339
+ ```
340
+
341
+ ## Available Exports
342
+
343
+ The SDK exports the following components:
344
+
345
+ ```typescript
346
+ import {
347
+ // Core classes
348
+ Wallet,
349
+ WatchOnlyWallet,
350
+
351
+ // Account types
352
+ BaseAccount,
353
+ DefaultAccount,
354
+ DappAccount,
355
+ VaultAccount,
356
+ AccountStore,
357
+
358
+ // Transaction creators
359
+ WalletTransactionCreator,
360
+ WatchOnlyTransactionCreator,
361
+
362
+ // Network provider
363
+ rostrumProvider,
364
+
365
+ // Utility functions
366
+ ValidationUtils,
367
+ isValidNexaAddress,
368
+
369
+ // Enums
370
+ AccountType,
371
+ TxTokenType,
372
+
373
+ // Types
374
+ AccountKeys,
375
+ Balance,
376
+ TransactionEntity,
377
+ TokenAction
378
+ } from '@dolaned/wallet-sdk-ts'
379
+ ```
380
+
381
+ ## Error Handling
382
+
383
+ ```typescript
384
+ try {
385
+ const tx = await wallet.newTransaction(account)
386
+ .sendTo('invalid-address', '1000')
387
+ .populate()
388
+ .sign()
389
+ .build()
390
+ } catch (error) {
391
+ if (error.message.includes('Invalid address')) {
392
+ console.error('Invalid Nexa address provided')
393
+ } else if (error.message.includes('Insufficient funds')) {
394
+ console.error('Not enough balance for transaction')
395
+ } else {
396
+ console.error('Transaction failed:', error.message)
397
+ }
398
+ }
399
+ ```
400
+
401
+ ## Network Configuration
402
+
403
+ ```typescript
404
+ // Testnet (for development)
405
+ const wallet = new Wallet(seedPhrase, 'testnet')
406
+
407
+ // Mainnet (for production)
408
+ const wallet = new Wallet(seedPhrase, 'mainnet')
409
+
410
+ // Always specify network in transactions
411
+ const tx = await wallet.newTransaction(account)
412
+ .onNetwork('testnet') // Must match wallet network
413
+ .sendTo(address, amount)
414
+ .populate()
415
+ .sign()
416
+ .build()
417
+ ```
418
+
419
+ ## Best Practices
420
+
421
+ 1. **Always Connect First**: Call `await rostrumProvider.connect()` before wallet operations
422
+ 2. **Network Consistency**: Ensure wallet and transaction networks match
423
+ 3. **Amount Precision**: Use strings for amounts to avoid floating-point precision issues
424
+ 4. **Error Handling**: Wrap wallet operations in try-catch blocks
425
+ 5. **Private Key Security**: Never log or expose private keys or seed phrases
426
+ 6. **Address Validation**: Validate addresses before sending transactions
427
+ 7. **Fee Estimation**: Use `populate()` to estimate fees before signing
428
+
429
+ ## Contributing
430
+
431
+ Contributions are welcome! Please feel free to submit a Pull Request.
432
+
433
+ ## License
434
+
435
+ This project is licensed under the MIT License - see the LICENSE file for details.
436
+
437
+ ## Support
438
+
439
+ For issues and questions:
440
+ - GitHub Issues: [wallet-sdk-ts issues](https://gitlab.com/nexa/wallet-sdk-ts/issues)
441
+ - Documentation: [Nexa Documentation](https://docs.nexa.org)
442
+
443
+ ---
444
+
445
+ **⚠️ Security Notice**: Never share your seed phrases or private keys. Always verify addresses before sending transactions. This SDK is for development purposes - use appropriate security measures in production applications.