nexa-wallet-sdk 0.1.4 → 0.2.1
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 +30 -0
- package/dist/index.cjs +105 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +54 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +82 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.web.mjs +82 -8
- package/dist/index.web.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -313,6 +313,36 @@ await watchOnlyWallet.subscribeToAddressNotifications((notification) => {
|
|
|
313
313
|
|
|
314
314
|
## Advanced Features
|
|
315
315
|
|
|
316
|
+
### Address Notifications
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
// Subscribe to a single address
|
|
320
|
+
await wallet.subscribeToAddressNotifications(
|
|
321
|
+
'nexa:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc',
|
|
322
|
+
(notification) => {
|
|
323
|
+
console.log('Address notification:', notification)
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
// Subscribe to addresses as an array
|
|
328
|
+
const addresses = [
|
|
329
|
+
'nexa:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc'
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
await wallet.subscribeToAddressNotifications(addresses, (notification) => {
|
|
333
|
+
console.log('Array Address notification:', notification)
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
// Subscribe to all wallet addresses
|
|
337
|
+
const accounts = wallet.accountStore.listAccounts()
|
|
338
|
+
const allAddresses = accounts.flatMap(account =>
|
|
339
|
+
account.getAddresses().map(addr => addr.address)
|
|
340
|
+
)
|
|
341
|
+
await wallet.subscribeToAddressNotifications(allAddresses, (notification) => {
|
|
342
|
+
console.log('Wallet notification:', notification)
|
|
343
|
+
})
|
|
344
|
+
```
|
|
345
|
+
|
|
316
346
|
### Parse Existing Transactions
|
|
317
347
|
|
|
318
348
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -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\",\"version\":\"0.1
|
|
144
|
+
$2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.2.1\",\"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
|
|
|
@@ -253,9 +253,10 @@ class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
|
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
255
|
* Create initial connection with the rostrum server
|
|
256
|
-
* @param netOrParams
|
|
257
|
-
* @param params
|
|
258
|
-
|
|
256
|
+
* @param netOrParams - Network identifier or RostrumParams object
|
|
257
|
+
* @param params - RostrumParams object (for backward compatibility)
|
|
258
|
+
* @param electrumClient - Optional pre-configured ElectrumClient instance
|
|
259
|
+
*/ async connect(netOrParams, params, electrumClient) {
|
|
259
260
|
try {
|
|
260
261
|
let connectionParams;
|
|
261
262
|
// Handle backward compatibility: connect(params) or connect(network, params)
|
|
@@ -283,8 +284,13 @@ class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
|
|
|
283
284
|
scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WS
|
|
284
285
|
};
|
|
285
286
|
}
|
|
286
|
-
|
|
287
|
-
|
|
287
|
+
if (electrumClient) {
|
|
288
|
+
this.client = electrumClient;
|
|
289
|
+
if (this.client.connection.status == (0, $l50U0$vgrunnerelectrumcash.ConnectionStatus).DISCONNECTED) await this.client.connect();
|
|
290
|
+
} else {
|
|
291
|
+
this.client = new (0, $l50U0$vgrunnerelectrumcash.ElectrumClient)("com.nexa.wallet-sdk", "1.4.3", connectionParams.host, connectionParams.port, connectionParams.scheme, 30000, 10000, true);
|
|
292
|
+
await this.client.connect();
|
|
293
|
+
}
|
|
288
294
|
} catch (e) {
|
|
289
295
|
if (e instanceof Error) console.info(e.message);
|
|
290
296
|
else console.error(e);
|
|
@@ -1094,6 +1100,31 @@ function $0d59d2bcffd646c5$var$classifyTokenTransaction(vin, vout, txState, myAd
|
|
|
1094
1100
|
}
|
|
1095
1101
|
|
|
1096
1102
|
|
|
1103
|
+
/**
|
|
1104
|
+
* Checks if `value` is classified as an `Array` object.
|
|
1105
|
+
*
|
|
1106
|
+
* @static
|
|
1107
|
+
* @memberOf _
|
|
1108
|
+
* @since 0.1.0
|
|
1109
|
+
* @category Lang
|
|
1110
|
+
* @param {*} value The value to check.
|
|
1111
|
+
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1112
|
+
* @example
|
|
1113
|
+
*
|
|
1114
|
+
* _.isArray([1, 2, 3]);
|
|
1115
|
+
* // => true
|
|
1116
|
+
*
|
|
1117
|
+
* _.isArray(document.body.children);
|
|
1118
|
+
* // => false
|
|
1119
|
+
*
|
|
1120
|
+
* _.isArray('abc');
|
|
1121
|
+
* // => false
|
|
1122
|
+
*
|
|
1123
|
+
* _.isArray(_.noop);
|
|
1124
|
+
* // => false
|
|
1125
|
+
*/ var $36cc8c1055cfbf3b$var$isArray = Array.isArray;
|
|
1126
|
+
var $36cc8c1055cfbf3b$export$2e2bcd8739ae039 = $36cc8c1055cfbf3b$var$isArray;
|
|
1127
|
+
|
|
1097
1128
|
|
|
1098
1129
|
var $kNPhA = parcelRequire("kNPhA");
|
|
1099
1130
|
var $cpiMl = parcelRequire("cpiMl");
|
|
@@ -1165,31 +1196,6 @@ var $8b46445dc5373cfc$export$2e2bcd8739ae039 = $8b46445dc5373cfc$var$objectToStr
|
|
|
1165
1196
|
var $6911cdf7f985d482$export$2e2bcd8739ae039 = $6911cdf7f985d482$var$baseGetTag;
|
|
1166
1197
|
|
|
1167
1198
|
|
|
1168
|
-
/**
|
|
1169
|
-
* Checks if `value` is classified as an `Array` object.
|
|
1170
|
-
*
|
|
1171
|
-
* @static
|
|
1172
|
-
* @memberOf _
|
|
1173
|
-
* @since 0.1.0
|
|
1174
|
-
* @category Lang
|
|
1175
|
-
* @param {*} value The value to check.
|
|
1176
|
-
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1177
|
-
* @example
|
|
1178
|
-
*
|
|
1179
|
-
* _.isArray([1, 2, 3]);
|
|
1180
|
-
* // => true
|
|
1181
|
-
*
|
|
1182
|
-
* _.isArray(document.body.children);
|
|
1183
|
-
* // => false
|
|
1184
|
-
*
|
|
1185
|
-
* _.isArray('abc');
|
|
1186
|
-
* // => false
|
|
1187
|
-
*
|
|
1188
|
-
* _.isArray(_.noop);
|
|
1189
|
-
* // => false
|
|
1190
|
-
*/ var $36cc8c1055cfbf3b$var$isArray = Array.isArray;
|
|
1191
|
-
var $36cc8c1055cfbf3b$export$2e2bcd8739ae039 = $36cc8c1055cfbf3b$var$isArray;
|
|
1192
|
-
|
|
1193
1199
|
|
|
1194
1200
|
/**
|
|
1195
1201
|
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
@@ -1899,6 +1905,24 @@ class $57b0117fe8233fef$export$bba690fb5c12ba04 {
|
|
|
1899
1905
|
});
|
|
1900
1906
|
return this;
|
|
1901
1907
|
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Adds nexa contract constraint to spending inputs
|
|
1910
|
+
* @param templateScript
|
|
1911
|
+
* @param constraintScript
|
|
1912
|
+
* @param visibleArgs
|
|
1913
|
+
* @param pubKey
|
|
1914
|
+
* @returns This instance for chaining
|
|
1915
|
+
*/ addContract(templateScript, constraintScript, visibleArgs, pubKey) {
|
|
1916
|
+
this.builder.push(async ()=>{
|
|
1917
|
+
this.txOptions.templateData = {
|
|
1918
|
+
publicKey: pubKey,
|
|
1919
|
+
templateScript: templateScript,
|
|
1920
|
+
constraintScript: constraintScript,
|
|
1921
|
+
visibleArgs: visibleArgs
|
|
1922
|
+
};
|
|
1923
|
+
});
|
|
1924
|
+
return this;
|
|
1925
|
+
}
|
|
1902
1926
|
/**
|
|
1903
1927
|
* Builds the transaction by executing all queued operations
|
|
1904
1928
|
* @returns Promise resolving to the serialized transaction hex
|
|
@@ -2380,6 +2404,56 @@ class $b76d3bd5024ccfc0$export$2e2bcd8739ae039 {
|
|
|
2380
2404
|
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $90290c84737dbb50$export$2e2bcd8739ae039)(transaction), 'transaction must be present and valid');
|
|
2381
2405
|
return (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).broadcast(transaction);
|
|
2382
2406
|
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Subscribe to address notifications for transaction updates
|
|
2409
|
+
*
|
|
2410
|
+
* This method allows you to monitor one or more addresses for incoming and outgoing transactions.
|
|
2411
|
+
* You can provide either a single address string or an array of addresses. The callback will be
|
|
2412
|
+
* invoked whenever there are updates to any of the monitored addresses.
|
|
2413
|
+
*
|
|
2414
|
+
* @param addresses - A single address string or array of addresses to monitor
|
|
2415
|
+
* @param callback - Function to call when address notifications are received
|
|
2416
|
+
* @returns Promise that resolves when subscription is established
|
|
2417
|
+
* @throws {Error} If addresses parameter is invalid or empty
|
|
2418
|
+
*
|
|
2419
|
+
* @example
|
|
2420
|
+
* ```typescript
|
|
2421
|
+
* // Subscribe to a single address
|
|
2422
|
+
* await wallet.subscribeToAddressNotifications(
|
|
2423
|
+
* 'nexa:address123',
|
|
2424
|
+
* (notification) => {
|
|
2425
|
+
* console.log('Address notification:', notification);
|
|
2426
|
+
* }
|
|
2427
|
+
* );
|
|
2428
|
+
*
|
|
2429
|
+
* // Subscribe to multiple addresses
|
|
2430
|
+
* await wallet.subscribeToAddressNotifications(
|
|
2431
|
+
* ['nexa:address1', 'nexa:address2', 'nexa:address3'],
|
|
2432
|
+
* (notification) => {
|
|
2433
|
+
* console.log('Address notification:', notification);
|
|
2434
|
+
* }
|
|
2435
|
+
* );
|
|
2436
|
+
*
|
|
2437
|
+
* // Subscribe to all wallet addresses
|
|
2438
|
+
* const accounts = wallet.accountStore.listAccounts();
|
|
2439
|
+
* const addresses = accounts.flatMap(account =>
|
|
2440
|
+
* account.getAddresses().map(addr => addr.address)
|
|
2441
|
+
* );
|
|
2442
|
+
* await wallet.subscribeToAddressNotifications(addresses, callback);
|
|
2443
|
+
* ```
|
|
2444
|
+
*/ async subscribeToAddressNotifications(addresses, callback) {
|
|
2445
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(addresses), 'addresses parameter is required');
|
|
2446
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(callback), 'callback function is required');
|
|
2447
|
+
let addressArray;
|
|
2448
|
+
if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(addresses)) addressArray = [
|
|
2449
|
+
addresses
|
|
2450
|
+
];
|
|
2451
|
+
else if ((0, $36cc8c1055cfbf3b$export$2e2bcd8739ae039)(addresses)) {
|
|
2452
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(addresses.length > 0, 'addresses array cannot be empty');
|
|
2453
|
+
addressArray = addresses;
|
|
2454
|
+
} else throw new Error('addresses must be a string or array of strings');
|
|
2455
|
+
return (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).subscribeToAddresses(addressArray, callback);
|
|
2456
|
+
}
|
|
2383
2457
|
/**
|
|
2384
2458
|
* Sign a message using a specific address from this wallet
|
|
2385
2459
|
*
|