nexa-wallet-sdk 0.1.2 → 0.1.4

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 (50) hide show
  1. package/README.md +17 -7
  2. package/dist/{index.js → index.cjs} +108 -30
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +70 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.mjs +105 -27
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/{browser/index.js → index.web.mjs} +246 -168
  9. package/dist/index.web.mjs.map +1 -0
  10. package/package.json +30 -5
  11. package/.parcel-cache/3e09f086f3c4d605-AssetGraph +0 -0
  12. package/.parcel-cache/5eac57ec674cdae8-AssetGraph +0 -0
  13. package/.parcel-cache/data.mdb +0 -0
  14. package/.parcel-cache/e43547b6c9167b58-RequestGraph +0 -0
  15. package/.parcel-cache/ecfe15d74834bbfd-BundleGraph +0 -0
  16. package/.parcel-cache/lock.mdb +0 -0
  17. package/.parcel-cache/snapshot-e43547b6c9167b58.txt +0 -2
  18. package/dist/browser/index.js.map +0 -1
  19. package/dist/index.js.map +0 -1
  20. package/spec.md +0 -257
  21. package/src/index.ts +0 -93
  22. package/src/models/rostrum.entities.ts +0 -159
  23. package/src/models/transaction.entities.ts +0 -46
  24. package/src/models/wallet.entities.ts +0 -42
  25. package/src/network/RostrumProvider.ts +0 -137
  26. package/src/types.ts +0 -0
  27. package/src/utils/CommonUtils.ts +0 -123
  28. package/src/utils/TXUtils.ts +0 -445
  29. package/src/utils/TokenUtils.ts +0 -75
  30. package/src/utils/ValidationUtils.ts +0 -86
  31. package/src/utils/WalletUtils.ts +0 -522
  32. package/src/utils/WatchOnlyTXUtils.ts +0 -275
  33. package/src/wallet/Wallet.ts +0 -397
  34. package/src/wallet/WatchOnlyWallet.ts +0 -169
  35. package/src/wallet/accounts/AccountStore.ts +0 -173
  36. package/src/wallet/accounts/interfaces/BaseAccountInterface.ts +0 -56
  37. package/src/wallet/accounts/models/DappAccount.ts +0 -80
  38. package/src/wallet/accounts/models/DefaultAccount.ts +0 -96
  39. package/src/wallet/accounts/models/VaultAccount.ts +0 -81
  40. package/src/wallet/transactions/WalletTransactionCreator.ts +0 -145
  41. package/src/wallet/transactions/WatchOnlyTransactionCreator.ts +0 -189
  42. package/src/wallet/transactions/interfaces/TransactionCreator.ts +0 -438
  43. package/tests/core/tx/transactioncreator.test.ts +0 -455
  44. package/tests/core/tx/wallettransactioncreator.test.ts +0 -362
  45. package/tests/core/tx/watchonlytransactioncreator.test.ts +0 -258
  46. package/tests/core/wallet/accountstore.test.ts +0 -341
  47. package/tests/core/wallet/wallet.test.ts +0 -69
  48. package/tests/core/watchonlywallet/watchonlywallet.test.ts +0 -251
  49. package/tests/index.test.ts +0 -12
  50. package/tsconfig.json +0 -113
package/README.md CHANGED
@@ -15,7 +15,7 @@ A comprehensive TypeScript SDK for building applications on the Nexa blockchain.
15
15
  ## Installation
16
16
 
17
17
  ```bash
18
- npm install @dolaned/wallet-sdk-ts
18
+ npm install nexa-wallet-sdk
19
19
  ```
20
20
 
21
21
  ## Quick Start
@@ -23,11 +23,22 @@ npm install @dolaned/wallet-sdk-ts
23
23
  ### Basic Wallet Setup
24
24
 
25
25
  ```typescript
26
- import { Wallet, rostrumProvider } from '@dolaned/wallet-sdk-ts'
26
+ import { Wallet, rostrumProvider } from 'nexa-wallet-sdk'
27
27
 
28
- // Connect to the network
28
+ // Connect to the default mainnet node
29
29
  await rostrumProvider.connect()
30
30
 
31
+ // Connect to a specific network (mainnet or testnet)
32
+ await rostrumProvider.connect('testnet') // Uses predefined testnet node
33
+ await rostrumProvider.connect('mainnet') // Uses predefined mainnet node
34
+
35
+ // Connect to a custom node (ignores network parameter)
36
+ await rostrumProvider.connect({
37
+ host: 'your-custom-node.example.com',
38
+ port: 30004,
39
+ scheme: 'wss' // or 'ws' for unencrypted connection
40
+ })
41
+
31
42
  // Create wallet from seed phrase
32
43
  const wallet = new Wallet(
33
44
  'your twelve word seed phrase goes here for wallet creation',
@@ -266,11 +277,10 @@ Watch-only wallets allow you to monitor addresses and create unsigned transactio
266
277
  ### Create Watch-Only Wallet
267
278
 
268
279
  ```typescript
269
- import { WatchOnlyWallet } from '@dolaned/wallet-sdk-ts'
280
+ import { WatchOnlyWallet } from 'nexa-wallet-sdk'
270
281
 
271
282
  const watchOnlyWallet = new WatchOnlyWallet([
272
- { address: 'nexatest:nqtsq5g5dsgh6mwjchqypn8hvdrjue0xpmz293fl7rm926xv' },
273
- { address: 'nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc' }
283
+ { address: 'nexatest:nqtsq5g5dsgh6mwjchqypn8hvdrjue0xpmz293fl7rm926xv' }
274
284
  ], 'testnet')
275
285
  ```
276
286
 
@@ -375,7 +385,7 @@ import {
375
385
  Balance,
376
386
  TransactionEntity,
377
387
  TokenAction
378
- } from '@dolaned/wallet-sdk-ts'
388
+ } from 'nexa-wallet-sdk'
379
389
  ```
380
390
 
381
391
  ## Error Handling
@@ -21,7 +21,7 @@ function $parcel$interopDefault(a) {
21
21
  var $parcel$modules = {};
22
22
  var $parcel$inits = {};
23
23
 
24
- var parcelRequire = $parcel$global["parcelRequire77ae"];
24
+ var parcelRequire = $parcel$global["parcelRequire3d58"];
25
25
 
26
26
  if (parcelRequire == null) {
27
27
  parcelRequire = function(id) {
@@ -45,7 +45,7 @@ if (parcelRequire == null) {
45
45
  $parcel$inits[id] = init;
46
46
  };
47
47
 
48
- $parcel$global["parcelRequire77ae"] = parcelRequire;
48
+ $parcel$global["parcelRequire3d58"] = parcelRequire;
49
49
  }
50
50
 
51
51
  var parcelRegister = parcelRequire.register;
@@ -141,7 +141,7 @@ $parcel$export(module.exports, "WatchOnlyTransactionCreator", () => $2ce5b75d109
141
141
  $parcel$export(module.exports, "rostrumProvider", () => $b5bfd17fdf06d231$export$eaa49f0478d81b9d);
142
142
  // @ts-ignore
143
143
  var $2dd241e44b9dc3c2$exports = {};
144
- $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"@nexa/wallet-sdk-ts\",\"version\":\"0.1.0\",\"main\":\"dist/index.js\",\"module\":\"dist/index.mjs\",\"types\":\"dist/index.d.ts\",\"source\":\"src/index.ts\",\"scripts\":{\"build\":\"parcel build\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"parcel\":\"^2.15.4\",\"typescript\":\"^5.8.3\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^1.0.5\",\"lodash-es\":\"^4.17.21\"},\"directories\":{\"test\":\"tests\"}}");
144
+ $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.1.4\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^1.0.5\",\"lodash-es\":\"^4.17.21\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
145
145
 
146
146
 
147
147
 
@@ -153,50 +153,95 @@ const $95d1e8196bc3f78b$export$1f6f962b0b96558 = {
153
153
  };
154
154
 
155
155
 
156
+
156
157
  class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
157
158
  constructor(){}
158
- async getVersion() {
159
+ /**
160
+ * Get Rostum Server Version
161
+ */ async getVersion() {
159
162
  return await this.execute('server.version');
160
163
  }
161
- async getBlockTip() {
164
+ /**
165
+ * Get the block tip of the network / chain we are currently connected to
166
+ */ async getBlockTip() {
162
167
  return await this.execute('blockchain.headers.tip');
163
168
  }
164
- async getBalance(address) {
169
+ /**
170
+ * Get the nexa balance of an address without the token balances
171
+ * @param address
172
+ */ async getBalance(address) {
165
173
  return await this.execute('blockchain.address.get_balance', address, 'exclude_tokens');
166
174
  }
167
- async getTransactionsHistory(address) {
175
+ /**
176
+ * Get The transaction history for an address
177
+ * @param address
178
+ */ async getTransactionHistory(address) {
168
179
  return await this.execute('blockchain.address.get_history', address);
169
180
  }
170
- async getFirstUse(address) {
181
+ /**
182
+ * Get the block height or block has of when the address was first used
183
+ * @param address
184
+ */ async getFirstUse(address) {
171
185
  return await this.execute('blockchain.address.get_first_use', address);
172
186
  }
173
- async getTransaction(id, verbose = true) {
187
+ /**
188
+ * Get a single transaction object
189
+ * @param id
190
+ * @param verbose
191
+ */ async getTransaction(id, verbose = true) {
174
192
  return await this.execute('blockchain.transaction.get', id, verbose);
175
193
  }
176
- async getUtxo(outpoint) {
194
+ /**
195
+ * Get a single unspent output including group data
196
+ * @param outpoint
197
+ */ async getUtxo(outpoint) {
177
198
  return await this.execute('blockchain.utxo.get', outpoint);
178
199
  }
179
- async getNexaUtxos(address) {
200
+ /**
201
+ * Get Utxos only containing nexa information
202
+ * @param address
203
+ */ async getNexaUtxos(address) {
180
204
  return await this.execute('blockchain.address.listunspent', address, 'exclude_tokens');
181
205
  }
182
- async getTokenUtxos(address, token) {
206
+ /**
207
+ * Get all the utxo's for a token at an address
208
+ * @param address
209
+ * @param token
210
+ */ async getTokenUtxos(address, token) {
183
211
  let listunspent = await this.execute('token.address.listunspent', address, null, token);
184
212
  return listunspent.unspent;
185
213
  }
186
- async getTokensBalance(address, token) {
214
+ /**
215
+ * Get the token balances for an address
216
+ * @param address
217
+ * @param token
218
+ */ async getTokensBalance(address, token) {
187
219
  if (token) return await this.execute('token.address.get_balance', address, null, token);
188
220
  return await this.execute('token.address.get_balance', address);
189
221
  }
190
- async getTokenGenesis(token) {
222
+ /**
223
+ * Get the token genesis for a token
224
+ * @param token
225
+ */ async getTokenGenesis(token) {
191
226
  return await this.execute('token.genesis.info', token);
192
227
  }
193
- async subscribeToAddresses(addresses, callback) {
228
+ /**
229
+ * Subscribe to address call back notifications, handy for updating the user when they receive nexa or tokens in
230
+ * their wallet
231
+ * @param addresses
232
+ * @param callback
233
+ */ async subscribeToAddresses(addresses, callback) {
194
234
  for (const addr of addresses)await this.client?.subscribe(callback, 'blockchain.address.subscribe', addr);
195
235
  }
196
- async broadcast(txHex) {
236
+ /**
237
+ * Broadcast a presigned transaction hash
238
+ * @param txHex
239
+ */ async broadcast(txHex) {
197
240
  return await this.execute('blockchain.transaction.broadcast', txHex);
198
241
  }
199
- async getLatency() {
242
+ /**
243
+ * Get the latency of the server connection
244
+ */ async getLatency() {
200
245
  try {
201
246
  let start = Date.now();
202
247
  let res = await this.getBlockTip();
@@ -206,14 +251,39 @@ class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
206
251
  return 0;
207
252
  }
208
253
  }
209
- async connect(params) {
254
+ /**
255
+ * Create initial connection with the rostrum server
256
+ * @param netOrParams
257
+ * @param params
258
+ */ async connect(netOrParams, params) {
210
259
  try {
211
- if (!params) params = {
212
- host: 'aus.electrum.nexa.onethirtyseven.dev',
213
- port: 30004,
214
- scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WSS
215
- };
216
- this.client = new (0, $l50U0$vgrunnerelectrumcash.ElectrumClient)("com.otoplo.wallet", "1.4.3", params.host, params.port, params.scheme, 30000, 10000, true);
260
+ let connectionParams;
261
+ // Handle backward compatibility: connect(params) or connect(network, params)
262
+ if (netOrParams && typeof netOrParams === 'object' && 'host' in netOrParams && 'port' in netOrParams && 'scheme' in netOrParams) // First parameter is RostrumParams
263
+ connectionParams = netOrParams;
264
+ else if (params) // Second parameter contains RostrumParams, ignore network
265
+ connectionParams = params;
266
+ else {
267
+ // Use network to determine default params
268
+ const network = netOrParams ? (0, $l50U0$libnexats.Networks).get(netOrParams) : (0, $l50U0$libnexats.Networks).mainnet;
269
+ if (network === (0, $l50U0$libnexats.Networks).mainnet) connectionParams = {
270
+ host: 'electrum.nexa.org',
271
+ port: 20004,
272
+ scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WSS
273
+ };
274
+ else if (network === (0, $l50U0$libnexats.Networks).testnet) connectionParams = {
275
+ host: 'testnet-electrum.nexa.org',
276
+ port: 30004,
277
+ scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WSS
278
+ };
279
+ else // Default fallback for other networks (like regtest)
280
+ connectionParams = {
281
+ host: 'localhost',
282
+ port: 30004,
283
+ scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WS
284
+ };
285
+ }
286
+ this.client = new (0, $l50U0$vgrunnerelectrumcash.ElectrumClient)("com.nexa.wallet-sdk", "0.1.4", connectionParams.host, connectionParams.port, connectionParams.scheme, 30000, 10000, true);
217
287
  await this.client.connect();
218
288
  } catch (e) {
219
289
  if (e instanceof Error) console.info(e.message);
@@ -221,7 +291,10 @@ class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
221
291
  throw e;
222
292
  }
223
293
  }
224
- async disconnect(force) {
294
+ /**
295
+ * Disconnect from the rostrum server
296
+ * @param force
297
+ */ async disconnect(force) {
225
298
  try {
226
299
  return await this.client.disconnect(force);
227
300
  } catch (e) {
@@ -229,8 +302,13 @@ class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
229
302
  return false;
230
303
  }
231
304
  }
232
- async execute(method, ...parameters) {
233
- var res = await this.client.request(method, ...parameters);
305
+ /**
306
+ * internal function to call commands against the rostrum API
307
+ * @param method
308
+ * @param parameters
309
+ * @private
310
+ */ async execute(method, ...parameters) {
311
+ let res = await this.client.request(method, ...parameters);
234
312
  if (res instanceof Error) throw res;
235
313
  return res;
236
314
  }
@@ -789,7 +867,7 @@ async function $0d59d2bcffd646c5$export$a2ed4b531376a5a4(addresses, fromHeight)
789
867
  let index = 0, i = 0, data = new Map(), maxHeight = fromHeight;
790
868
  for (let address of addresses){
791
869
  i++;
792
- let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionsHistory(address);
870
+ let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionHistory(address);
793
871
  if (txHistory && txHistory.length > 0) {
794
872
  index = i;
795
873
  for (let tx of txHistory)if (tx.height === 0 || tx.height > fromHeight) {
@@ -808,7 +886,7 @@ async function $0d59d2bcffd646c5$var$rescanAddressesHistory(addresses) {
808
886
  let index = 0, i = 0, minHeight = Number.MAX_SAFE_INTEGER;
809
887
  for (let address of addresses){
810
888
  i++;
811
- let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionsHistory(address);
889
+ let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionHistory(address);
812
890
  if (!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(txHistory)) {
813
891
  index = i;
814
892
  let heights = txHistory.filter((tx)=>tx.height > 0).map((h)=>h.height);
@@ -2912,4 +2990,4 @@ $parcel$global._walletSdk_ver = `v${0, $2dd241e44b9dc3c2$exports.version}`;
2912
2990
  var $56b18ab116ff33bd$export$2e2bcd8739ae039 = $56b18ab116ff33bd$var$walletSdk;
2913
2991
 
2914
2992
 
2915
- //# sourceMappingURL=index.js.map
2993
+ //# sourceMappingURL=index.cjs.map