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.
- package/.parcel-cache/3e09f086f3c4d605-AssetGraph +0 -0
- package/.parcel-cache/5eac57ec674cdae8-AssetGraph +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/e43547b6c9167b58-RequestGraph +0 -0
- package/.parcel-cache/ecfe15d74834bbfd-BundleGraph +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/.parcel-cache/snapshot-e43547b6c9167b58.txt +2 -0
- package/README.md +445 -0
- package/dist/browser/index.js +2456 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/index.d.ts +918 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2915 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2456 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +90 -0
- package/spec.md +257 -0
- package/src/index.ts +93 -0
- package/src/models/rostrum.entities.ts +159 -0
- package/src/models/transaction.entities.ts +46 -0
- package/src/models/wallet.entities.ts +42 -0
- package/src/network/RostrumProvider.ts +137 -0
- package/src/types.ts +0 -0
- package/src/utils/CommonUtils.ts +123 -0
- package/src/utils/TXUtils.ts +445 -0
- package/src/utils/TokenUtils.ts +75 -0
- package/src/utils/ValidationUtils.ts +86 -0
- package/src/utils/WalletUtils.ts +522 -0
- package/src/utils/WatchOnlyTXUtils.ts +275 -0
- package/src/wallet/Wallet.ts +397 -0
- package/src/wallet/WatchOnlyWallet.ts +169 -0
- package/src/wallet/accounts/AccountStore.ts +173 -0
- package/src/wallet/accounts/interfaces/BaseAccountInterface.ts +56 -0
- package/src/wallet/accounts/models/DappAccount.ts +80 -0
- package/src/wallet/accounts/models/DefaultAccount.ts +96 -0
- package/src/wallet/accounts/models/VaultAccount.ts +81 -0
- package/src/wallet/transactions/WalletTransactionCreator.ts +145 -0
- package/src/wallet/transactions/WatchOnlyTransactionCreator.ts +189 -0
- package/src/wallet/transactions/interfaces/TransactionCreator.ts +438 -0
- package/tests/core/tx/transactioncreator.test.ts +455 -0
- package/tests/core/tx/wallettransactioncreator.test.ts +362 -0
- package/tests/core/tx/watchonlytransactioncreator.test.ts +258 -0
- package/tests/core/wallet/accountstore.test.ts +341 -0
- package/tests/core/wallet/wallet.test.ts +69 -0
- package/tests/core/watchonlywallet/watchonlywallet.test.ts +251 -0
- package/tests/index.test.ts +12 -0
- package/tsconfig.json +113 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2915 @@
|
|
|
1
|
+
var $l50U0$libnexats = require("libnexa-ts");
|
|
2
|
+
var $l50U0$bip39 = require("bip39");
|
|
3
|
+
var $l50U0$vgrunnerelectrumcash = require("@vgrunner/electrum-cash");
|
|
4
|
+
var $l50U0$jsbigdecimal = require("js-big-decimal");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var $parcel$global = globalThis;
|
|
12
|
+
|
|
13
|
+
function $parcel$defineInteropFlag(a) {
|
|
14
|
+
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function $parcel$interopDefault(a) {
|
|
18
|
+
return a && a.__esModule ? a.default : a;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var $parcel$modules = {};
|
|
22
|
+
var $parcel$inits = {};
|
|
23
|
+
|
|
24
|
+
var parcelRequire = $parcel$global["parcelRequire77ae"];
|
|
25
|
+
|
|
26
|
+
if (parcelRequire == null) {
|
|
27
|
+
parcelRequire = function(id) {
|
|
28
|
+
if (id in $parcel$modules) {
|
|
29
|
+
return $parcel$modules[id].exports;
|
|
30
|
+
}
|
|
31
|
+
if (id in $parcel$inits) {
|
|
32
|
+
var init = $parcel$inits[id];
|
|
33
|
+
delete $parcel$inits[id];
|
|
34
|
+
var module = {id: id, exports: {}};
|
|
35
|
+
$parcel$modules[id] = module;
|
|
36
|
+
init.call(module.exports, module, module.exports);
|
|
37
|
+
return module.exports;
|
|
38
|
+
}
|
|
39
|
+
var err = new Error("Cannot find module '" + id + "'");
|
|
40
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
41
|
+
throw err;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
parcelRequire.register = function register(id, init) {
|
|
45
|
+
$parcel$inits[id] = init;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
$parcel$global["parcelRequire77ae"] = parcelRequire;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var parcelRegister = parcelRequire.register;
|
|
52
|
+
parcelRegister("kNPhA", function(module, exports) {
|
|
53
|
+
|
|
54
|
+
$parcel$export(module.exports, "default", () => $f25029ea39a3086e$export$2e2bcd8739ae039);
|
|
55
|
+
|
|
56
|
+
var $cpiMl = parcelRequire("cpiMl");
|
|
57
|
+
|
|
58
|
+
var $j6iK9 = parcelRequire("j6iK9");
|
|
59
|
+
/** Detect free variable `exports`. */ var freeExports = exports && !exports.nodeType && exports;
|
|
60
|
+
/** Detect free variable `module`. */ var freeModule = freeExports && true && module && !module.nodeType && module;
|
|
61
|
+
/** Detect the popular CommonJS extension `module.exports`. */ var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
62
|
+
/** Built-in value references. */ var Buffer = moduleExports ? (0, $cpiMl.default).Buffer : undefined;
|
|
63
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */ var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if `value` is a buffer.
|
|
66
|
+
*
|
|
67
|
+
* @static
|
|
68
|
+
* @memberOf _
|
|
69
|
+
* @since 4.3.0
|
|
70
|
+
* @category Lang
|
|
71
|
+
* @param {*} value The value to check.
|
|
72
|
+
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|
73
|
+
* @example
|
|
74
|
+
*
|
|
75
|
+
* _.isBuffer(new Buffer(2));
|
|
76
|
+
* // => true
|
|
77
|
+
*
|
|
78
|
+
* _.isBuffer(new Uint8Array(2));
|
|
79
|
+
* // => false
|
|
80
|
+
*/ var isBuffer = nativeIsBuffer || (0, $j6iK9.default);
|
|
81
|
+
var $f25029ea39a3086e$export$2e2bcd8739ae039 = isBuffer;
|
|
82
|
+
|
|
83
|
+
});
|
|
84
|
+
parcelRegister("cpiMl", function(module, exports) {
|
|
85
|
+
|
|
86
|
+
$parcel$export(module.exports, "default", () => $908662eb8e7c9a57$export$2e2bcd8739ae039);
|
|
87
|
+
|
|
88
|
+
var $hYTRB = parcelRequire("hYTRB");
|
|
89
|
+
/** Detect free variable `self`. */ var $908662eb8e7c9a57$var$freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
90
|
+
/** Used as a reference to the global object. */ var $908662eb8e7c9a57$var$root = (0, $hYTRB.default) || $908662eb8e7c9a57$var$freeSelf || Function('return this')();
|
|
91
|
+
var $908662eb8e7c9a57$export$2e2bcd8739ae039 = $908662eb8e7c9a57$var$root;
|
|
92
|
+
|
|
93
|
+
});
|
|
94
|
+
parcelRegister("hYTRB", function(module, exports) {
|
|
95
|
+
|
|
96
|
+
$parcel$export(module.exports, "default", () => $d1735f9d9792bc22$export$2e2bcd8739ae039);
|
|
97
|
+
/** Detect free variable `global` from Node.js. */ var $d1735f9d9792bc22$var$freeGlobal = typeof $parcel$global == 'object' && $parcel$global && $parcel$global.Object === Object && $parcel$global;
|
|
98
|
+
var $d1735f9d9792bc22$export$2e2bcd8739ae039 = $d1735f9d9792bc22$var$freeGlobal;
|
|
99
|
+
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
parcelRegister("j6iK9", function(module, exports) {
|
|
104
|
+
|
|
105
|
+
$parcel$export(module.exports, "default", () => $de7d1de29f9a7741$export$2e2bcd8739ae039);
|
|
106
|
+
/**
|
|
107
|
+
* This method returns `false`.
|
|
108
|
+
*
|
|
109
|
+
* @static
|
|
110
|
+
* @memberOf _
|
|
111
|
+
* @since 4.13.0
|
|
112
|
+
* @category Util
|
|
113
|
+
* @returns {boolean} Returns `false`.
|
|
114
|
+
* @example
|
|
115
|
+
*
|
|
116
|
+
* _.times(2, _.stubFalse);
|
|
117
|
+
* // => [false, false]
|
|
118
|
+
*/ function $de7d1de29f9a7741$var$stubFalse() {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
var $de7d1de29f9a7741$export$2e2bcd8739ae039 = $de7d1de29f9a7741$var$stubFalse;
|
|
122
|
+
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
$parcel$defineInteropFlag(module.exports);
|
|
128
|
+
|
|
129
|
+
$parcel$export(module.exports, "default", () => $56b18ab116ff33bd$export$2e2bcd8739ae039);
|
|
130
|
+
$parcel$export(module.exports, "Wallet", () => $b76d3bd5024ccfc0$export$2e2bcd8739ae039);
|
|
131
|
+
$parcel$export(module.exports, "WatchOnlyWallet", () => $f4ad400261a08cba$export$2e2bcd8739ae039);
|
|
132
|
+
$parcel$export(module.exports, "AccountType", () => $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7);
|
|
133
|
+
$parcel$export(module.exports, "TxTokenType", () => $0d59d2bcffd646c5$export$dcc1fb6ad5308e56);
|
|
134
|
+
$parcel$export(module.exports, "BaseAccount", () => $f8a48da5c0b6346a$export$c54c8796e94a37a0);
|
|
135
|
+
$parcel$export(module.exports, "DefaultAccount", () => $1c49a4fffc97409b$export$2e2bcd8739ae039);
|
|
136
|
+
$parcel$export(module.exports, "DappAccount", () => $cf960f437fe63027$export$2e2bcd8739ae039);
|
|
137
|
+
$parcel$export(module.exports, "VaultAccount", () => $0b557605c0e99621$export$2e2bcd8739ae039);
|
|
138
|
+
$parcel$export(module.exports, "AccountStore", () => $7fcf3b163a95e69a$export$2e2bcd8739ae039);
|
|
139
|
+
$parcel$export(module.exports, "WalletTransactionCreator", () => $e1896e59040fa3c5$export$2e2bcd8739ae039);
|
|
140
|
+
$parcel$export(module.exports, "WatchOnlyTransactionCreator", () => $2ce5b75d10954bb1$export$2e2bcd8739ae039);
|
|
141
|
+
$parcel$export(module.exports, "rostrumProvider", () => $b5bfd17fdf06d231$export$eaa49f0478d81b9d);
|
|
142
|
+
// @ts-ignore
|
|
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\"}}");
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
const $95d1e8196bc3f78b$export$1f6f962b0b96558 = {
|
|
151
|
+
WS: 'ws',
|
|
152
|
+
WSS: 'wss'
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class $b5bfd17fdf06d231$export$ba81aefc89aef50c {
|
|
157
|
+
constructor(){}
|
|
158
|
+
async getVersion() {
|
|
159
|
+
return await this.execute('server.version');
|
|
160
|
+
}
|
|
161
|
+
async getBlockTip() {
|
|
162
|
+
return await this.execute('blockchain.headers.tip');
|
|
163
|
+
}
|
|
164
|
+
async getBalance(address) {
|
|
165
|
+
return await this.execute('blockchain.address.get_balance', address, 'exclude_tokens');
|
|
166
|
+
}
|
|
167
|
+
async getTransactionsHistory(address) {
|
|
168
|
+
return await this.execute('blockchain.address.get_history', address);
|
|
169
|
+
}
|
|
170
|
+
async getFirstUse(address) {
|
|
171
|
+
return await this.execute('blockchain.address.get_first_use', address);
|
|
172
|
+
}
|
|
173
|
+
async getTransaction(id, verbose = true) {
|
|
174
|
+
return await this.execute('blockchain.transaction.get', id, verbose);
|
|
175
|
+
}
|
|
176
|
+
async getUtxo(outpoint) {
|
|
177
|
+
return await this.execute('blockchain.utxo.get', outpoint);
|
|
178
|
+
}
|
|
179
|
+
async getNexaUtxos(address) {
|
|
180
|
+
return await this.execute('blockchain.address.listunspent', address, 'exclude_tokens');
|
|
181
|
+
}
|
|
182
|
+
async getTokenUtxos(address, token) {
|
|
183
|
+
let listunspent = await this.execute('token.address.listunspent', address, null, token);
|
|
184
|
+
return listunspent.unspent;
|
|
185
|
+
}
|
|
186
|
+
async getTokensBalance(address, token) {
|
|
187
|
+
if (token) return await this.execute('token.address.get_balance', address, null, token);
|
|
188
|
+
return await this.execute('token.address.get_balance', address);
|
|
189
|
+
}
|
|
190
|
+
async getTokenGenesis(token) {
|
|
191
|
+
return await this.execute('token.genesis.info', token);
|
|
192
|
+
}
|
|
193
|
+
async subscribeToAddresses(addresses, callback) {
|
|
194
|
+
for (const addr of addresses)await this.client?.subscribe(callback, 'blockchain.address.subscribe', addr);
|
|
195
|
+
}
|
|
196
|
+
async broadcast(txHex) {
|
|
197
|
+
return await this.execute('blockchain.transaction.broadcast', txHex);
|
|
198
|
+
}
|
|
199
|
+
async getLatency() {
|
|
200
|
+
try {
|
|
201
|
+
let start = Date.now();
|
|
202
|
+
let res = await this.getBlockTip();
|
|
203
|
+
if (res) return Date.now() - start;
|
|
204
|
+
return 0;
|
|
205
|
+
} catch {
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async connect(params) {
|
|
210
|
+
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);
|
|
217
|
+
await this.client.connect();
|
|
218
|
+
} catch (e) {
|
|
219
|
+
if (e instanceof Error) console.info(e.message);
|
|
220
|
+
else console.error(e);
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async disconnect(force) {
|
|
225
|
+
try {
|
|
226
|
+
return await this.client.disconnect(force);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
console.log(e);
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async execute(method, ...parameters) {
|
|
233
|
+
var res = await this.client.request(method, ...parameters);
|
|
234
|
+
if (res instanceof Error) throw res;
|
|
235
|
+
return res;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const $b5bfd17fdf06d231$export$eaa49f0478d81b9d = new $b5bfd17fdf06d231$export$ba81aefc89aef50c();
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Checks if `value` is `null` or `undefined`.
|
|
247
|
+
*
|
|
248
|
+
* @static
|
|
249
|
+
* @memberOf _
|
|
250
|
+
* @since 4.0.0
|
|
251
|
+
* @category Lang
|
|
252
|
+
* @param {*} value The value to check.
|
|
253
|
+
* @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
|
254
|
+
* @example
|
|
255
|
+
*
|
|
256
|
+
* _.isNil(null);
|
|
257
|
+
* // => true
|
|
258
|
+
*
|
|
259
|
+
* _.isNil(void 0);
|
|
260
|
+
* // => true
|
|
261
|
+
*
|
|
262
|
+
* _.isNil(NaN);
|
|
263
|
+
* // => false
|
|
264
|
+
*/ function $54dde1e65fb8e5b8$var$isNil(value) {
|
|
265
|
+
return value == null;
|
|
266
|
+
}
|
|
267
|
+
var $54dde1e65fb8e5b8$export$2e2bcd8739ae039 = $54dde1e65fb8e5b8$var$isNil;
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class $f8a48da5c0b6346a$export$c54c8796e94a37a0 {
|
|
271
|
+
get transactions() {
|
|
272
|
+
return this._transactions;
|
|
273
|
+
}
|
|
274
|
+
set transactions(value) {
|
|
275
|
+
this._transactions = value;
|
|
276
|
+
}
|
|
277
|
+
constructor(_bip44Account){
|
|
278
|
+
this._tokenBalances = {};
|
|
279
|
+
this._transactions = new Map();
|
|
280
|
+
this._bip44Account = _bip44Account;
|
|
281
|
+
this._balance = {
|
|
282
|
+
confirmed: 0,
|
|
283
|
+
unconfirmed: 0
|
|
284
|
+
};
|
|
285
|
+
this._tokenBalances = {};
|
|
286
|
+
}
|
|
287
|
+
get balance() {
|
|
288
|
+
return this._balance;
|
|
289
|
+
}
|
|
290
|
+
set balance(value) {
|
|
291
|
+
this._balance = value;
|
|
292
|
+
}
|
|
293
|
+
get tokenBalances() {
|
|
294
|
+
return this._tokenBalances;
|
|
295
|
+
}
|
|
296
|
+
set tokenBalances(value) {
|
|
297
|
+
this._tokenBalances = value;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class $cf960f437fe63027$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) {
|
|
304
|
+
constructor(bip44Account, accountIndex, addressKey){
|
|
305
|
+
super(bip44Account);
|
|
306
|
+
this._accountIndex = accountIndex;
|
|
307
|
+
this._accountKey = addressKey;
|
|
308
|
+
}
|
|
309
|
+
// this is used in AccountStore.ts to get the key to be used in the map for this account
|
|
310
|
+
getAccountStoreKey() {
|
|
311
|
+
return String(this._bip44Account + '.' + this._accountIndex);
|
|
312
|
+
}
|
|
313
|
+
getAccountType() {
|
|
314
|
+
return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT;
|
|
315
|
+
}
|
|
316
|
+
getNewAddress() {
|
|
317
|
+
return this._accountKey.address;
|
|
318
|
+
}
|
|
319
|
+
getNewChangeAddress() {
|
|
320
|
+
return this._accountKey.address;
|
|
321
|
+
}
|
|
322
|
+
get accountIndexes() {
|
|
323
|
+
return {
|
|
324
|
+
rIndex: this._accountIndex,
|
|
325
|
+
cIndex: 0
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
get accountKeys() {
|
|
329
|
+
return {
|
|
330
|
+
receiveKeys: [
|
|
331
|
+
this._accountKey
|
|
332
|
+
],
|
|
333
|
+
changeKeys: [
|
|
334
|
+
this._accountKey
|
|
335
|
+
]
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
async loadBalances() {
|
|
339
|
+
let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([
|
|
340
|
+
this._accountKey
|
|
341
|
+
]);
|
|
342
|
+
let tokenBalances = [
|
|
343
|
+
this._accountKey
|
|
344
|
+
].map((k)=>k.tokensBalance);
|
|
345
|
+
super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
|
|
346
|
+
super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
|
|
347
|
+
}
|
|
348
|
+
getKeyFromAddress(address) {
|
|
349
|
+
return this._accountKey;
|
|
350
|
+
}
|
|
351
|
+
async getTransactions(fromHeight, address) {
|
|
352
|
+
let txPromises = [];
|
|
353
|
+
const transactions = await (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)([
|
|
354
|
+
address ?? this._accountKey.address
|
|
355
|
+
], fromHeight ?? 0);
|
|
356
|
+
for (let tx of transactions.txs.values()){
|
|
357
|
+
let t = await (0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, [
|
|
358
|
+
address ?? this._accountKey.address
|
|
359
|
+
]);
|
|
360
|
+
txPromises.push(t);
|
|
361
|
+
}
|
|
362
|
+
await Promise.all(txPromises);
|
|
363
|
+
for (let txEntity of txPromises)this.transactions.set(txEntity.txId, txEntity);
|
|
364
|
+
return this.transactions;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class $1c49a4fffc97409b$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) {
|
|
372
|
+
constructor(bip44Account, accountIndexes, accountKeys){
|
|
373
|
+
super(bip44Account);
|
|
374
|
+
if (accountIndexes.rIndex < 0) throw new Error(`Can not create nexa account with an rindex of ${accountIndexes.rIndex}. must be >= 0.`);
|
|
375
|
+
if (accountIndexes.cIndex < 0) throw new Error(`Can not create nexa account with an cindex of ${accountIndexes.cIndex}. must be >= 0.`);
|
|
376
|
+
this._accountIndexes = accountIndexes;
|
|
377
|
+
this._accountKeys = accountKeys;
|
|
378
|
+
}
|
|
379
|
+
// this is used in AccountStore.ts to get the key to be used in the map for this account
|
|
380
|
+
getAccountStoreKey() {
|
|
381
|
+
return String(this._bip44Account);
|
|
382
|
+
}
|
|
383
|
+
getAccountType() {
|
|
384
|
+
return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).NEXA_ACCOUNT;
|
|
385
|
+
}
|
|
386
|
+
getNewAddress() {
|
|
387
|
+
return this._accountKeys.receiveKeys[this._accountKeys.receiveKeys.length - 1]?.address ?? '';
|
|
388
|
+
}
|
|
389
|
+
getNewChangeAddress() {
|
|
390
|
+
return this._accountKeys.changeKeys[this._accountKeys.changeKeys.length - 1]?.address ?? '';
|
|
391
|
+
}
|
|
392
|
+
get accountIndexes() {
|
|
393
|
+
return this._accountIndexes;
|
|
394
|
+
}
|
|
395
|
+
get accountKeys() {
|
|
396
|
+
return this._accountKeys;
|
|
397
|
+
}
|
|
398
|
+
async loadBalances() {
|
|
399
|
+
let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)(this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys));
|
|
400
|
+
let tokenBalances = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys).map((k)=>k.tokensBalance);
|
|
401
|
+
super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
|
|
402
|
+
super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
|
|
403
|
+
}
|
|
404
|
+
getKeyFromAddress(address) {
|
|
405
|
+
const allKeys = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys);
|
|
406
|
+
const keyFound = allKeys.find((key)=>key.address === address);
|
|
407
|
+
return keyFound;
|
|
408
|
+
}
|
|
409
|
+
async getTransactions(fromHeight, address) {
|
|
410
|
+
let receiveAddresses = this.accountKeys.receiveKeys.map((ak)=>ak.address);
|
|
411
|
+
let changeAddresses = this.accountKeys.changeKeys.map((ak)=>ak.address);
|
|
412
|
+
let allAddresses = receiveAddresses.concat(changeAddresses);
|
|
413
|
+
let rTxs = (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)(address != null ? [
|
|
414
|
+
address
|
|
415
|
+
] : receiveAddresses, fromHeight ?? 0);
|
|
416
|
+
let cTxs = (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)(address != null ? [
|
|
417
|
+
address
|
|
418
|
+
] : receiveAddresses, fromHeight ?? 0);
|
|
419
|
+
let [rData, cData] = await Promise.all([
|
|
420
|
+
rTxs,
|
|
421
|
+
cTxs
|
|
422
|
+
]);
|
|
423
|
+
let txHistory = rData.txs;
|
|
424
|
+
for (let tx of cData.txs.values())txHistory.set(tx.tx_hash, tx);
|
|
425
|
+
let txPromises = [];
|
|
426
|
+
for (let tx of txHistory.values()){
|
|
427
|
+
let t = await (0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, allAddresses);
|
|
428
|
+
txPromises.push(t);
|
|
429
|
+
}
|
|
430
|
+
await Promise.all(txPromises);
|
|
431
|
+
for (let txEntity of txPromises)this.transactions.set(txEntity.txId, txEntity);
|
|
432
|
+
return this.transactions;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class $0b557605c0e99621$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) {
|
|
440
|
+
constructor(bip44Account, accountIndex, addressKey){
|
|
441
|
+
super(bip44Account);
|
|
442
|
+
this._accountIndex = accountIndex;
|
|
443
|
+
this._accountKey = addressKey;
|
|
444
|
+
}
|
|
445
|
+
// this is used in AccountStore.ts to get the key to be used in the map for this account
|
|
446
|
+
getAccountStoreKey() {
|
|
447
|
+
return String(this._bip44Account + '.' + this._accountIndex);
|
|
448
|
+
}
|
|
449
|
+
getAccountType() {
|
|
450
|
+
return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).VAULT_ACCOUNT;
|
|
451
|
+
}
|
|
452
|
+
getNewAddress() {
|
|
453
|
+
return this._accountKey.address;
|
|
454
|
+
}
|
|
455
|
+
getNewChangeAddress() {
|
|
456
|
+
return this._accountKey.address;
|
|
457
|
+
}
|
|
458
|
+
get accountIndexes() {
|
|
459
|
+
return {
|
|
460
|
+
rIndex: this._accountIndex,
|
|
461
|
+
cIndex: 0
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
get accountKeys() {
|
|
465
|
+
return {
|
|
466
|
+
receiveKeys: [
|
|
467
|
+
this._accountKey
|
|
468
|
+
],
|
|
469
|
+
changeKeys: [
|
|
470
|
+
this._accountKey
|
|
471
|
+
]
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
async loadBalances() {
|
|
475
|
+
let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([
|
|
476
|
+
this._accountKey
|
|
477
|
+
]);
|
|
478
|
+
let tokenBalances = [
|
|
479
|
+
this._accountKey
|
|
480
|
+
].map((k)=>k.tokensBalance);
|
|
481
|
+
super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
|
|
482
|
+
super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
|
|
483
|
+
}
|
|
484
|
+
getKeyFromAddress(address) {
|
|
485
|
+
return this._accountKey;
|
|
486
|
+
}
|
|
487
|
+
async getTransactions(fromHeight, address) {
|
|
488
|
+
let txPromises = [];
|
|
489
|
+
const transactions = await (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)([
|
|
490
|
+
address ?? this._accountKey.address
|
|
491
|
+
], fromHeight ?? 0);
|
|
492
|
+
for (let tx of transactions.txs.values()){
|
|
493
|
+
let t = await (0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, [
|
|
494
|
+
address ?? this._accountKey.address
|
|
495
|
+
]);
|
|
496
|
+
txPromises.push(t);
|
|
497
|
+
}
|
|
498
|
+
await Promise.all(txPromises);
|
|
499
|
+
for (let txEntity of txPromises)this.transactions.set(txEntity.txId, txEntity);
|
|
500
|
+
return this.transactions;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
const $bc5ca2c06b1affa3$export$8ba128bc85947a2a = 9223372036854775807n;
|
|
508
|
+
function $bc5ca2c06b1affa3$export$78d0476e8d098ba7() {
|
|
509
|
+
return Math.floor(Date.now() / 1000);
|
|
510
|
+
}
|
|
511
|
+
function $bc5ca2c06b1affa3$export$c8733ae29fb53302(arg) {
|
|
512
|
+
return !arg || arg.length === 0;
|
|
513
|
+
}
|
|
514
|
+
function $bc5ca2c06b1affa3$export$78e516cc94be797b(amount, decimals) {
|
|
515
|
+
let val = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(amount).divide(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(Math.pow(10, decimals)), decimals).getPrettyValue();
|
|
516
|
+
if (val.match(/\./)) val = val.replace(/\.?0+$/, '');
|
|
517
|
+
return val;
|
|
518
|
+
}
|
|
519
|
+
function $bc5ca2c06b1affa3$export$9ad78026dec58d6(amount, decimals) {
|
|
520
|
+
return new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(amount).multiply(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(Math.pow(10, decimals))).getValue();
|
|
521
|
+
}
|
|
522
|
+
function $bc5ca2c06b1affa3$export$23010fd5dda8dec1(address) {
|
|
523
|
+
if ((0, $l50U0$libnexats.CommonUtils).isHexa(address)) return Buffer.from(address, 'hex');
|
|
524
|
+
return (0, $l50U0$libnexats.Address).fromString(address).data;
|
|
525
|
+
}
|
|
526
|
+
function $bc5ca2c06b1affa3$export$254a5c7330bbfd41(token) {
|
|
527
|
+
if ((0, $l50U0$libnexats.CommonUtils).isHexa(token)) return token;
|
|
528
|
+
return $bc5ca2c06b1affa3$export$23010fd5dda8dec1(token).toString('hex');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
var $0d59d2bcffd646c5$export$dcc1fb6ad5308e56 = /*#__PURE__*/ function(TxTokenType) {
|
|
533
|
+
TxTokenType[TxTokenType["NO_GROUP"] = 0] = "NO_GROUP";
|
|
534
|
+
TxTokenType[TxTokenType["CREATE"] = 1] = "CREATE";
|
|
535
|
+
TxTokenType[TxTokenType["MINT"] = 2] = "MINT";
|
|
536
|
+
TxTokenType[TxTokenType["MELT"] = 3] = "MELT";
|
|
537
|
+
TxTokenType[TxTokenType["RENEW"] = 4] = "RENEW";
|
|
538
|
+
TxTokenType[TxTokenType["TRANSFER"] = 5] = "TRANSFER";
|
|
539
|
+
return TxTokenType;
|
|
540
|
+
}({});
|
|
541
|
+
var $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7 = /*#__PURE__*/ function(AccountType) {
|
|
542
|
+
AccountType[AccountType["NEXA_ACCOUNT"] = 0] = "NEXA_ACCOUNT";
|
|
543
|
+
AccountType[AccountType["VAULT_ACCOUNT"] = 1] = "VAULT_ACCOUNT";
|
|
544
|
+
AccountType[AccountType["DAPP_ACCOUNT"] = 2] = "DAPP_ACCOUNT";
|
|
545
|
+
return AccountType;
|
|
546
|
+
}({});
|
|
547
|
+
function $0d59d2bcffd646c5$export$8d986bd2866fe6ab(address, network, type = (0, $l50U0$libnexats.AddressType).PayToScriptTemplate) {
|
|
548
|
+
return (0, $l50U0$libnexats.Address).isValid(address, network, type);
|
|
549
|
+
}
|
|
550
|
+
function $0d59d2bcffd646c5$export$11f4ae2b4ff9633d(mnemonic, passphrase) {
|
|
551
|
+
const seed = $l50U0$bip39.mnemonicToSeedSync(mnemonic, passphrase);
|
|
552
|
+
const masterKey = (0, $l50U0$libnexats.HDPrivateKey).fromSeed(seed);
|
|
553
|
+
return masterKey.deriveChild(44, true).deriveChild(29223, true);
|
|
554
|
+
}
|
|
555
|
+
function $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, account) {
|
|
556
|
+
return masterKey.deriveChild(account, true);
|
|
557
|
+
}
|
|
558
|
+
function $0d59d2bcffd646c5$export$d6e8eb22902c6b88(accountKey, fromRIndex, rIndex, fromCIndex, cIndex) {
|
|
559
|
+
if (fromRIndex < 0) throw new Error(`Can not generate keys with fromRIndex ${fromRIndex}. must be >= 0.`);
|
|
560
|
+
if (fromCIndex < 0) throw new Error(`Can not generate keys with fromCIndex ${fromCIndex}. must be >= 0.`);
|
|
561
|
+
let receive = accountKey.deriveChild(0, false);
|
|
562
|
+
let change = accountKey.deriveChild(1, false);
|
|
563
|
+
let rKeys = [], cKeys = [];
|
|
564
|
+
for(let index = fromRIndex; index < rIndex; index++){
|
|
565
|
+
let k = receive.deriveChild(index, false);
|
|
566
|
+
let addr = k.privateKey.toAddress().toString();
|
|
567
|
+
rKeys.push({
|
|
568
|
+
key: k,
|
|
569
|
+
address: addr,
|
|
570
|
+
balance: "0",
|
|
571
|
+
tokensBalance: {}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
for(let index = fromCIndex; index < cIndex; index++){
|
|
575
|
+
let k = change.deriveChild(index, false);
|
|
576
|
+
let addr = k.privateKey.toAddress().toString();
|
|
577
|
+
cKeys.push({
|
|
578
|
+
key: k,
|
|
579
|
+
address: addr,
|
|
580
|
+
balance: "0",
|
|
581
|
+
tokensBalance: {}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
receiveKeys: rKeys,
|
|
586
|
+
changeKeys: cKeys
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(accountKey, rIndex) {
|
|
590
|
+
let receive = accountKey.deriveChild(0, false);
|
|
591
|
+
let k = receive.deriveChild(rIndex, false);
|
|
592
|
+
let addr = k.privateKey.toAddress().toString();
|
|
593
|
+
return {
|
|
594
|
+
key: k,
|
|
595
|
+
address: addr,
|
|
596
|
+
balance: "0",
|
|
597
|
+
tokensBalance: {}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
async function $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(deriveKey) {
|
|
601
|
+
let lastUsed = -1, index = 0, toScan = 20;
|
|
602
|
+
while(toScan > 0){
|
|
603
|
+
toScan--;
|
|
604
|
+
let rAddr = deriveKey.deriveChild(index, false).privateKey.toAddress().toString();
|
|
605
|
+
let isUsed = await $0d59d2bcffd646c5$var$isAddressUsed(rAddr);
|
|
606
|
+
if (isUsed) {
|
|
607
|
+
lastUsed = index;
|
|
608
|
+
toScan = 20;
|
|
609
|
+
}
|
|
610
|
+
index++;
|
|
611
|
+
}
|
|
612
|
+
// return the last used index, returns -1 if no indexes are used
|
|
613
|
+
return lastUsed;
|
|
614
|
+
}
|
|
615
|
+
async function $0d59d2bcffd646c5$export$4aeb2c92e53ab137(accountKey) {
|
|
616
|
+
let receiveKey = accountKey.deriveChild(0, false);
|
|
617
|
+
let changeKey = accountKey.deriveChild(1, false);
|
|
618
|
+
let rIndexPromise = $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(receiveKey);
|
|
619
|
+
let cIndexPromise = $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(changeKey);
|
|
620
|
+
let [rIndex, cIndex] = await Promise.all([
|
|
621
|
+
rIndexPromise,
|
|
622
|
+
cIndexPromise
|
|
623
|
+
]);
|
|
624
|
+
// get the index that is the last used nexa addr
|
|
625
|
+
let indexes = {
|
|
626
|
+
rIndex: rIndex,
|
|
627
|
+
cIndex: cIndex
|
|
628
|
+
};
|
|
629
|
+
return indexes;
|
|
630
|
+
}
|
|
631
|
+
async function $0d59d2bcffd646c5$export$f421913908d4303e(masterKey) {
|
|
632
|
+
let accounts = [];
|
|
633
|
+
let index = 0;
|
|
634
|
+
while(true){
|
|
635
|
+
const nexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, index);
|
|
636
|
+
const indexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(nexaAccountKey);
|
|
637
|
+
if (indexes.rIndex < 0 && indexes.cIndex < 0) break;
|
|
638
|
+
if (indexes.rIndex < 0) indexes.rIndex = 0;
|
|
639
|
+
if (indexes.cIndex < 0) indexes.cIndex = 0;
|
|
640
|
+
// make account after break check, otherwise we might push an empty account
|
|
641
|
+
const nexaAccount = new (0, $1c49a4fffc97409b$export$2e2bcd8739ae039)(index, indexes, $0d59d2bcffd646c5$export$d6e8eb22902c6b88(nexaAccountKey, indexes.rIndex + 1, indexes.rIndex + 20, indexes.cIndex + 1, indexes.cIndex + 20));
|
|
642
|
+
await nexaAccount.loadBalances();
|
|
643
|
+
accounts.push(nexaAccount);
|
|
644
|
+
if (index == 0) index = 100;
|
|
645
|
+
else index++;
|
|
646
|
+
}
|
|
647
|
+
if (accounts.length == 0) {
|
|
648
|
+
// default account was unused but we need to populate at least one account,
|
|
649
|
+
// make the default account here
|
|
650
|
+
let defaultNexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 0);
|
|
651
|
+
// get the last used indexes, -1 means unused
|
|
652
|
+
let defaultIndexes = {
|
|
653
|
+
rIndex: 0,
|
|
654
|
+
cIndex: 0
|
|
655
|
+
};
|
|
656
|
+
const defaultAccount = new (0, $1c49a4fffc97409b$export$2e2bcd8739ae039)(0, defaultIndexes, $0d59d2bcffd646c5$export$d6e8eb22902c6b88(defaultNexaAccountKey, defaultIndexes.rIndex, defaultIndexes.rIndex + 20, defaultIndexes.cIndex, defaultIndexes.cIndex + 20));
|
|
657
|
+
await defaultAccount.loadBalances();
|
|
658
|
+
accounts.push(defaultAccount);
|
|
659
|
+
}
|
|
660
|
+
return accounts;
|
|
661
|
+
}
|
|
662
|
+
async function $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey) {
|
|
663
|
+
// all vaults are in bip44 account 1
|
|
664
|
+
let vaultAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 1);
|
|
665
|
+
// all vaults are in the external chain
|
|
666
|
+
let vaultChain = vaultAccountKey.deriveChild(0, false);
|
|
667
|
+
// get the index that is the last used vault
|
|
668
|
+
return await $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(vaultChain);
|
|
669
|
+
}
|
|
670
|
+
async function $0d59d2bcffd646c5$export$eb24265dd203eccb(masterKey) {
|
|
671
|
+
let accounts = [];
|
|
672
|
+
// all vaults are in bip44 account 1
|
|
673
|
+
let vaultAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 1);
|
|
674
|
+
// find the next unused vault
|
|
675
|
+
let lastUsedVaultIndex = await $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey);
|
|
676
|
+
// if all vaults unused, generate at least the first vault account
|
|
677
|
+
if (lastUsedVaultIndex < 0) lastUsedVaultIndex = 0;
|
|
678
|
+
// for each vault found, make the DefaultAccount for that vault
|
|
679
|
+
for(let index = 0; index <= lastUsedVaultIndex; index++){
|
|
680
|
+
const vaultAccount = new (0, $0b557605c0e99621$export$2e2bcd8739ae039)(1, index, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(vaultAccountKey, index));
|
|
681
|
+
await vaultAccount.loadBalances();
|
|
682
|
+
accounts.push(vaultAccount);
|
|
683
|
+
}
|
|
684
|
+
return accounts;
|
|
685
|
+
}
|
|
686
|
+
async function $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey) {
|
|
687
|
+
// all dApp accounts are in bip44 account 2
|
|
688
|
+
let dappAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 2);
|
|
689
|
+
// all dApp accounts use the external chain
|
|
690
|
+
let dappChain = dappAccountKey.deriveChild(0, false);
|
|
691
|
+
// get the index that is the next unused dApp account
|
|
692
|
+
return await $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(dappChain);
|
|
693
|
+
}
|
|
694
|
+
async function $0d59d2bcffd646c5$export$e3d879d0e09f52c3(masterKey) {
|
|
695
|
+
let accounts = [];
|
|
696
|
+
// all dApp accounts are in bip44 account 2
|
|
697
|
+
let dappAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 2);
|
|
698
|
+
// find the next unused dapp account
|
|
699
|
+
let lastUsedDappIndex = await $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey);
|
|
700
|
+
// if all dapp accounts unused, generate at least the first dapp account
|
|
701
|
+
if (lastUsedDappIndex < 0) lastUsedDappIndex = 0;
|
|
702
|
+
// for each dApp account found, make the DefaultAccount for that dApp account
|
|
703
|
+
// for each vault found, make the DefaultAccount for that vault
|
|
704
|
+
for(let index = 0; index <= lastUsedDappIndex; index++){
|
|
705
|
+
const dappAccount = new (0, $cf960f437fe63027$export$2e2bcd8739ae039)(2, index, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(dappAccountKey, index));
|
|
706
|
+
await dappAccount.loadBalances();
|
|
707
|
+
accounts.push(dappAccount);
|
|
708
|
+
}
|
|
709
|
+
return accounts;
|
|
710
|
+
}
|
|
711
|
+
async function $0d59d2bcffd646c5$export$4e4f91181d6bd31c(masterKey) {
|
|
712
|
+
let accounts = [];
|
|
713
|
+
// accounts 0, 100+
|
|
714
|
+
const nexaAccounts = await $0d59d2bcffd646c5$export$f421913908d4303e(masterKey);
|
|
715
|
+
// vaults in bip44 account 1
|
|
716
|
+
const vaultAccounts = await $0d59d2bcffd646c5$export$eb24265dd203eccb(masterKey);
|
|
717
|
+
// dApp accounts in bip44 account 2
|
|
718
|
+
const dappAccounts = await $0d59d2bcffd646c5$export$e3d879d0e09f52c3(masterKey);
|
|
719
|
+
// 3 - 99 are reserved and will go here when added
|
|
720
|
+
accounts = accounts.concat(nexaAccounts);
|
|
721
|
+
accounts = accounts.concat(vaultAccounts);
|
|
722
|
+
accounts = accounts.concat(dappAccounts);
|
|
723
|
+
return accounts;
|
|
724
|
+
}
|
|
725
|
+
async function $0d59d2bcffd646c5$var$isAddressUsed(address) {
|
|
726
|
+
try {
|
|
727
|
+
let firstUse = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getFirstUse(address);
|
|
728
|
+
return firstUse.tx_hash && firstUse.tx_hash !== "";
|
|
729
|
+
} catch (e) {
|
|
730
|
+
if (e instanceof Error && e.message.includes("not found")) return false;
|
|
731
|
+
throw e;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async function $0d59d2bcffd646c5$var$getKeyTokenBalance(key) {
|
|
735
|
+
let tokensBalance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokensBalance(key.address);
|
|
736
|
+
let balance = {};
|
|
737
|
+
for(const cToken in tokensBalance.confirmed)if (tokensBalance.confirmed[cToken] != 0) balance[cToken] = {
|
|
738
|
+
confirmed: BigInt(tokensBalance.confirmed[cToken]).toString(),
|
|
739
|
+
unconfirmed: "0"
|
|
740
|
+
};
|
|
741
|
+
for(const uToken in tokensBalance.unconfirmed)if (tokensBalance.unconfirmed[uToken] != 0) {
|
|
742
|
+
if (balance[uToken]) balance[uToken].unconfirmed = BigInt(tokensBalance.unconfirmed[uToken]).toString();
|
|
743
|
+
else balance[uToken] = {
|
|
744
|
+
confirmed: "0",
|
|
745
|
+
unconfirmed: BigInt(tokensBalance.unconfirmed[uToken]).toString()
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
return balance;
|
|
749
|
+
}
|
|
750
|
+
async function $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key) {
|
|
751
|
+
let balance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getBalance(key.address);
|
|
752
|
+
key.balance = (BigInt(balance.confirmed) + BigInt(balance.unconfirmed)).toString();
|
|
753
|
+
key.tokensBalance = await $0d59d2bcffd646c5$var$getKeyTokenBalance(key);
|
|
754
|
+
return balance;
|
|
755
|
+
}
|
|
756
|
+
async function $0d59d2bcffd646c5$export$9e38d26dbd7c33f4(keys) {
|
|
757
|
+
let promises = [];
|
|
758
|
+
keys.forEach((key)=>{
|
|
759
|
+
let b = $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key);
|
|
760
|
+
promises.push(b);
|
|
761
|
+
});
|
|
762
|
+
return await Promise.all(promises);
|
|
763
|
+
}
|
|
764
|
+
function $0d59d2bcffd646c5$export$a26005fb5b8d1e4a(balances) {
|
|
765
|
+
let confirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0), unconfirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
766
|
+
balances.forEach((b)=>{
|
|
767
|
+
confirmed = confirmed.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(b.confirmed));
|
|
768
|
+
unconfirmed = unconfirmed.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(b.unconfirmed));
|
|
769
|
+
});
|
|
770
|
+
return {
|
|
771
|
+
confirmed: confirmed.getValue(),
|
|
772
|
+
unconfirmed: unconfirmed.getValue()
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
function $0d59d2bcffd646c5$export$dec515296f176dbe(balances) {
|
|
776
|
+
let tokensBalance = {};
|
|
777
|
+
balances.forEach((b)=>{
|
|
778
|
+
for(const key in b)if (tokensBalance[key]) {
|
|
779
|
+
tokensBalance[key].confirmed = (BigInt(tokensBalance[key].confirmed) + BigInt(b[key].confirmed)).toString();
|
|
780
|
+
tokensBalance[key].unconfirmed = (BigInt(tokensBalance[key].unconfirmed) + BigInt(b[key].unconfirmed)).toString();
|
|
781
|
+
} else tokensBalance[key] = {
|
|
782
|
+
confirmed: b[key].confirmed,
|
|
783
|
+
unconfirmed: b[key].unconfirmed
|
|
784
|
+
};
|
|
785
|
+
});
|
|
786
|
+
return tokensBalance;
|
|
787
|
+
}
|
|
788
|
+
async function $0d59d2bcffd646c5$export$a2ed4b531376a5a4(addresses, fromHeight) {
|
|
789
|
+
let index = 0, i = 0, data = new Map(), maxHeight = fromHeight;
|
|
790
|
+
for (let address of addresses){
|
|
791
|
+
i++;
|
|
792
|
+
let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionsHistory(address);
|
|
793
|
+
if (txHistory && txHistory.length > 0) {
|
|
794
|
+
index = i;
|
|
795
|
+
for (let tx of txHistory)if (tx.height === 0 || tx.height > fromHeight) {
|
|
796
|
+
maxHeight = Math.max(maxHeight, tx.height);
|
|
797
|
+
data.set(tx.tx_hash, tx);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
index: index,
|
|
803
|
+
txs: data,
|
|
804
|
+
lastHeight: maxHeight
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
async function $0d59d2bcffd646c5$var$rescanAddressesHistory(addresses) {
|
|
808
|
+
let index = 0, i = 0, minHeight = Number.MAX_SAFE_INTEGER;
|
|
809
|
+
for (let address of addresses){
|
|
810
|
+
i++;
|
|
811
|
+
let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionsHistory(address);
|
|
812
|
+
if (!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(txHistory)) {
|
|
813
|
+
index = i;
|
|
814
|
+
let heights = txHistory.filter((tx)=>tx.height > 0).map((h)=>h.height);
|
|
815
|
+
if (!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(heights)) minHeight = Math.min(minHeight, ...heights);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return {
|
|
819
|
+
index: index > 0 ? index + 1 : 0,
|
|
820
|
+
height: minHeight == Number.MAX_SAFE_INTEGER ? 0 : minHeight
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
async function $0d59d2bcffd646c5$export$ef13479e8d3251d7(accountType, masterKey) {
|
|
824
|
+
if (accountType == 0) {
|
|
825
|
+
let defaultNexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 0);
|
|
826
|
+
const defaultIndexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(defaultNexaAccountKey);
|
|
827
|
+
if (defaultIndexes.rIndex < 0 && defaultIndexes.cIndex < 0) return 0;
|
|
828
|
+
else // account 0 was not empty
|
|
829
|
+
for(let index = 100;; index++){
|
|
830
|
+
const nexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, index);
|
|
831
|
+
const indexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(nexaAccountKey);
|
|
832
|
+
if (indexes.rIndex < 0 && indexes.cIndex < 0) return index;
|
|
833
|
+
}
|
|
834
|
+
} else if (accountType == 1) {
|
|
835
|
+
// find the next unused vault
|
|
836
|
+
const lastUsedVault = await $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey);
|
|
837
|
+
return lastUsedVault + 1;
|
|
838
|
+
} else if (accountType == 2) {
|
|
839
|
+
// find the next unused dapp account
|
|
840
|
+
const lastUsedDappAccount = await $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey);
|
|
841
|
+
return lastUsedDappAccount + 1;
|
|
842
|
+
} else throw new Error("Can not get next account index. Invalid accountType.");
|
|
843
|
+
}
|
|
844
|
+
async function $0d59d2bcffd646c5$export$9c6f4f51acbc89b9(txHistory, myAddresses) {
|
|
845
|
+
let t = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransaction(txHistory.tx_hash);
|
|
846
|
+
let outputs = t.vout.filter((utxo)=>!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(utxo.scriptPubKey.addresses));
|
|
847
|
+
let isOutgoing = t.vin.length > 0 && myAddresses.includes(t.vin[0].addresses[0]);
|
|
848
|
+
let isIncoming = !isOutgoing || outputs.every((utxo)=>myAddresses.includes(utxo.scriptPubKey.addresses[0]));
|
|
849
|
+
let isConfirmed = t.height > 0;
|
|
850
|
+
let txEntry = {};
|
|
851
|
+
txEntry.txId = t.txid;
|
|
852
|
+
txEntry.txIdem = t.txidem;
|
|
853
|
+
txEntry.height = isConfirmed ? t.height : 0;
|
|
854
|
+
txEntry.time = isConfirmed ? t.time : (0, $bc5ca2c06b1affa3$export$78d0476e8d098ba7)();
|
|
855
|
+
txEntry.fee = t.fee_satoshi;
|
|
856
|
+
if (isOutgoing && isIncoming) {
|
|
857
|
+
txEntry.state = 'both';
|
|
858
|
+
txEntry.value = "0";
|
|
859
|
+
txEntry.payTo = "Payment to yourself";
|
|
860
|
+
} else if (isIncoming) {
|
|
861
|
+
txEntry.state = 'incoming';
|
|
862
|
+
let utxos = outputs.filter((utxo)=>myAddresses.includes(utxo.scriptPubKey.addresses[0]));
|
|
863
|
+
let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
864
|
+
utxos.forEach((utxo)=>{
|
|
865
|
+
amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.value_satoshi));
|
|
866
|
+
});
|
|
867
|
+
txEntry.value = amount.getValue();
|
|
868
|
+
txEntry.payTo = utxos[0].scriptPubKey.addresses[0];
|
|
869
|
+
} else if (isOutgoing) {
|
|
870
|
+
txEntry.state = 'outgoing';
|
|
871
|
+
let utxos = outputs.filter((utxo)=>!myAddresses.includes(utxo.scriptPubKey.addresses[0]));
|
|
872
|
+
let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
873
|
+
utxos.forEach((utxo)=>{
|
|
874
|
+
amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.value_satoshi));
|
|
875
|
+
});
|
|
876
|
+
txEntry.value = amount.getValue();
|
|
877
|
+
txEntry.payTo = utxos[0].scriptPubKey.addresses[0];
|
|
878
|
+
}
|
|
879
|
+
let [txType, txGroup, tokenAmount, extraGroup] = $0d59d2bcffd646c5$var$classifyTokenTransaction(t.vin, outputs, txEntry.state, myAddresses);
|
|
880
|
+
txEntry.txGroupType = txType;
|
|
881
|
+
txEntry.token = txGroup;
|
|
882
|
+
txEntry.tokenAmount = tokenAmount;
|
|
883
|
+
txEntry.extraGroup = extraGroup;
|
|
884
|
+
return txEntry;
|
|
885
|
+
}
|
|
886
|
+
function $0d59d2bcffd646c5$var$classifyTokenTransaction(vin, vout, txState, myAddresses) {
|
|
887
|
+
let groupInputs = vin.filter((input)=>!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(input.group));
|
|
888
|
+
let groupOutputs = vout.filter((output)=>!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(output.scriptPubKey.group));
|
|
889
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupOutputs)) return [
|
|
890
|
+
0,
|
|
891
|
+
"none",
|
|
892
|
+
"0",
|
|
893
|
+
"none"
|
|
894
|
+
];
|
|
895
|
+
let myGroupInputs = groupInputs.filter((input)=>myAddresses.includes(input.addresses[0]));
|
|
896
|
+
let myGroupOutputs = groupOutputs.filter((output)=>myAddresses.includes(output.scriptPubKey.addresses[0]));
|
|
897
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(myGroupInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(myGroupOutputs)) return [
|
|
898
|
+
0,
|
|
899
|
+
"none",
|
|
900
|
+
"0",
|
|
901
|
+
"none"
|
|
902
|
+
];
|
|
903
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupInputs)) {
|
|
904
|
+
let group = myGroupOutputs.find((output)=>BigInt(output.scriptPubKey.groupQuantity) < 0n)?.scriptPubKey.group ?? "none";
|
|
905
|
+
return [
|
|
906
|
+
1,
|
|
907
|
+
group,
|
|
908
|
+
"0",
|
|
909
|
+
"none"
|
|
910
|
+
];
|
|
911
|
+
}
|
|
912
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupOutputs)) {
|
|
913
|
+
if (txState === 'incoming') return [
|
|
914
|
+
0,
|
|
915
|
+
"none",
|
|
916
|
+
"0",
|
|
917
|
+
"none"
|
|
918
|
+
];
|
|
919
|
+
let inputs = myGroupInputs.filter((input)=>BigInt(input.groupQuantity) > 0n);
|
|
920
|
+
if (!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(inputs)) {
|
|
921
|
+
let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
922
|
+
inputs.forEach((utxo)=>{
|
|
923
|
+
amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.groupQuantity));
|
|
924
|
+
});
|
|
925
|
+
let group = inputs[0].group;
|
|
926
|
+
let extraGroup = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && inputs[0].group != input.group)?.group ?? "none";
|
|
927
|
+
return [
|
|
928
|
+
3,
|
|
929
|
+
group,
|
|
930
|
+
amount.getValue(),
|
|
931
|
+
extraGroup
|
|
932
|
+
];
|
|
933
|
+
}
|
|
934
|
+
let group = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n)?.group ?? "none";
|
|
935
|
+
let extraGroup = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none";
|
|
936
|
+
return [
|
|
937
|
+
3,
|
|
938
|
+
group,
|
|
939
|
+
"0",
|
|
940
|
+
extraGroup
|
|
941
|
+
];
|
|
942
|
+
}
|
|
943
|
+
let tokenInputs = groupInputs.filter((input)=>BigInt(input.groupQuantity) > 0n);
|
|
944
|
+
let tokenOutputs = groupOutputs.filter((output)=>BigInt(output.scriptPubKey.groupQuantity) > 0n);
|
|
945
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenOutputs)) {
|
|
946
|
+
let group = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n)?.group ?? "none";
|
|
947
|
+
let extraGroup = groupOutputs.find((output)=>BigInt(output.scriptPubKey.groupQuantity) < 0n && group != output.scriptPubKey.group)?.scriptPubKey.group ?? "none";
|
|
948
|
+
return [
|
|
949
|
+
4,
|
|
950
|
+
extraGroup !== 'none' ? extraGroup : group,
|
|
951
|
+
"0",
|
|
952
|
+
extraGroup !== 'none' ? group : extraGroup
|
|
953
|
+
];
|
|
954
|
+
}
|
|
955
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenInputs)) {
|
|
956
|
+
let group = tokenOutputs[0].scriptPubKey.group;
|
|
957
|
+
let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
958
|
+
tokenOutputs.forEach((utxo)=>{
|
|
959
|
+
amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.scriptPubKey.groupQuantity));
|
|
960
|
+
});
|
|
961
|
+
let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none";
|
|
962
|
+
return [
|
|
963
|
+
2,
|
|
964
|
+
group,
|
|
965
|
+
amount.getValue(),
|
|
966
|
+
extraGroup
|
|
967
|
+
];
|
|
968
|
+
}
|
|
969
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenOutputs)) {
|
|
970
|
+
let group = tokenInputs[0].group;
|
|
971
|
+
let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
|
|
972
|
+
tokenInputs.forEach((utxo)=>{
|
|
973
|
+
amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.groupQuantity));
|
|
974
|
+
});
|
|
975
|
+
let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none";
|
|
976
|
+
return [
|
|
977
|
+
3,
|
|
978
|
+
group,
|
|
979
|
+
amount.getValue(),
|
|
980
|
+
extraGroup
|
|
981
|
+
];
|
|
982
|
+
}
|
|
983
|
+
let outQuantitySum = tokenOutputs.map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n);
|
|
984
|
+
let inQuantitySum = tokenInputs.map((input)=>BigInt(input.groupQuantity)).reduce((a, b)=>a + b, 0n);
|
|
985
|
+
if (outQuantitySum > inQuantitySum) {
|
|
986
|
+
let group = tokenOutputs[0].scriptPubKey.group;
|
|
987
|
+
let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none";
|
|
988
|
+
return [
|
|
989
|
+
2,
|
|
990
|
+
group,
|
|
991
|
+
(outQuantitySum - inQuantitySum).toString(),
|
|
992
|
+
extraGroup
|
|
993
|
+
];
|
|
994
|
+
}
|
|
995
|
+
if (inQuantitySum > outQuantitySum) {
|
|
996
|
+
let group = tokenInputs[0].group;
|
|
997
|
+
let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none";
|
|
998
|
+
return [
|
|
999
|
+
3,
|
|
1000
|
+
group,
|
|
1001
|
+
(inQuantitySum - outQuantitySum).toString(),
|
|
1002
|
+
extraGroup
|
|
1003
|
+
];
|
|
1004
|
+
}
|
|
1005
|
+
let group = tokenOutputs[0].scriptPubKey.group;
|
|
1006
|
+
let amount = "";
|
|
1007
|
+
if (txState === 'incoming') amount = tokenOutputs.filter((output)=>myAddresses.includes(output.scriptPubKey.addresses[0])).map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n).toString();
|
|
1008
|
+
else if (txState === 'outgoing') amount = tokenOutputs.filter((output)=>!myAddresses.includes(output.scriptPubKey.addresses[0])).map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n).toString();
|
|
1009
|
+
else amount = "0";
|
|
1010
|
+
return [
|
|
1011
|
+
5,
|
|
1012
|
+
group,
|
|
1013
|
+
amount,
|
|
1014
|
+
"none"
|
|
1015
|
+
];
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
var $kNPhA = parcelRequire("kNPhA");
|
|
1021
|
+
var $cpiMl = parcelRequire("cpiMl");
|
|
1022
|
+
/** Built-in value references. */ var $ff9e97e034030f4b$var$Symbol = (0, $cpiMl.default).Symbol;
|
|
1023
|
+
var $ff9e97e034030f4b$export$2e2bcd8739ae039 = $ff9e97e034030f4b$var$Symbol;
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
/** Used for built-in method references. */ var $5821915922f18ec9$var$objectProto = Object.prototype;
|
|
1028
|
+
/** Used to check objects for own properties. */ var $5821915922f18ec9$var$hasOwnProperty = $5821915922f18ec9$var$objectProto.hasOwnProperty;
|
|
1029
|
+
/**
|
|
1030
|
+
* Used to resolve the
|
|
1031
|
+
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
1032
|
+
* of values.
|
|
1033
|
+
*/ var $5821915922f18ec9$var$nativeObjectToString = $5821915922f18ec9$var$objectProto.toString;
|
|
1034
|
+
/** Built-in value references. */ var $5821915922f18ec9$var$symToStringTag = (0, $ff9e97e034030f4b$export$2e2bcd8739ae039) ? (0, $ff9e97e034030f4b$export$2e2bcd8739ae039).toStringTag : undefined;
|
|
1035
|
+
/**
|
|
1036
|
+
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
|
1037
|
+
*
|
|
1038
|
+
* @private
|
|
1039
|
+
* @param {*} value The value to query.
|
|
1040
|
+
* @returns {string} Returns the raw `toStringTag`.
|
|
1041
|
+
*/ function $5821915922f18ec9$var$getRawTag(value) {
|
|
1042
|
+
var isOwn = $5821915922f18ec9$var$hasOwnProperty.call(value, $5821915922f18ec9$var$symToStringTag), tag = value[$5821915922f18ec9$var$symToStringTag];
|
|
1043
|
+
try {
|
|
1044
|
+
value[$5821915922f18ec9$var$symToStringTag] = undefined;
|
|
1045
|
+
var unmasked = true;
|
|
1046
|
+
} catch (e) {}
|
|
1047
|
+
var result = $5821915922f18ec9$var$nativeObjectToString.call(value);
|
|
1048
|
+
if (unmasked) {
|
|
1049
|
+
if (isOwn) value[$5821915922f18ec9$var$symToStringTag] = tag;
|
|
1050
|
+
else delete value[$5821915922f18ec9$var$symToStringTag];
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1053
|
+
}
|
|
1054
|
+
var $5821915922f18ec9$export$2e2bcd8739ae039 = $5821915922f18ec9$var$getRawTag;
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
/** Used for built-in method references. */ var $8b46445dc5373cfc$var$objectProto = Object.prototype;
|
|
1058
|
+
/**
|
|
1059
|
+
* Used to resolve the
|
|
1060
|
+
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
1061
|
+
* of values.
|
|
1062
|
+
*/ var $8b46445dc5373cfc$var$nativeObjectToString = $8b46445dc5373cfc$var$objectProto.toString;
|
|
1063
|
+
/**
|
|
1064
|
+
* Converts `value` to a string using `Object.prototype.toString`.
|
|
1065
|
+
*
|
|
1066
|
+
* @private
|
|
1067
|
+
* @param {*} value The value to convert.
|
|
1068
|
+
* @returns {string} Returns the converted string.
|
|
1069
|
+
*/ function $8b46445dc5373cfc$var$objectToString(value) {
|
|
1070
|
+
return $8b46445dc5373cfc$var$nativeObjectToString.call(value);
|
|
1071
|
+
}
|
|
1072
|
+
var $8b46445dc5373cfc$export$2e2bcd8739ae039 = $8b46445dc5373cfc$var$objectToString;
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
/** `Object#toString` result references. */ var $6911cdf7f985d482$var$nullTag = '[object Null]', $6911cdf7f985d482$var$undefinedTag = '[object Undefined]';
|
|
1076
|
+
/** Built-in value references. */ var $6911cdf7f985d482$var$symToStringTag = (0, $ff9e97e034030f4b$export$2e2bcd8739ae039) ? (0, $ff9e97e034030f4b$export$2e2bcd8739ae039).toStringTag : undefined;
|
|
1077
|
+
/**
|
|
1078
|
+
* The base implementation of `getTag` without fallbacks for buggy environments.
|
|
1079
|
+
*
|
|
1080
|
+
* @private
|
|
1081
|
+
* @param {*} value The value to query.
|
|
1082
|
+
* @returns {string} Returns the `toStringTag`.
|
|
1083
|
+
*/ function $6911cdf7f985d482$var$baseGetTag(value) {
|
|
1084
|
+
if (value == null) return value === undefined ? $6911cdf7f985d482$var$undefinedTag : $6911cdf7f985d482$var$nullTag;
|
|
1085
|
+
return $6911cdf7f985d482$var$symToStringTag && $6911cdf7f985d482$var$symToStringTag in Object(value) ? (0, $5821915922f18ec9$export$2e2bcd8739ae039)(value) : (0, $8b46445dc5373cfc$export$2e2bcd8739ae039)(value);
|
|
1086
|
+
}
|
|
1087
|
+
var $6911cdf7f985d482$export$2e2bcd8739ae039 = $6911cdf7f985d482$var$baseGetTag;
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Checks if `value` is classified as an `Array` object.
|
|
1092
|
+
*
|
|
1093
|
+
* @static
|
|
1094
|
+
* @memberOf _
|
|
1095
|
+
* @since 0.1.0
|
|
1096
|
+
* @category Lang
|
|
1097
|
+
* @param {*} value The value to check.
|
|
1098
|
+
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1099
|
+
* @example
|
|
1100
|
+
*
|
|
1101
|
+
* _.isArray([1, 2, 3]);
|
|
1102
|
+
* // => true
|
|
1103
|
+
*
|
|
1104
|
+
* _.isArray(document.body.children);
|
|
1105
|
+
* // => false
|
|
1106
|
+
*
|
|
1107
|
+
* _.isArray('abc');
|
|
1108
|
+
* // => false
|
|
1109
|
+
*
|
|
1110
|
+
* _.isArray(_.noop);
|
|
1111
|
+
* // => false
|
|
1112
|
+
*/ var $36cc8c1055cfbf3b$var$isArray = Array.isArray;
|
|
1113
|
+
var $36cc8c1055cfbf3b$export$2e2bcd8739ae039 = $36cc8c1055cfbf3b$var$isArray;
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
1118
|
+
* and has a `typeof` result of "object".
|
|
1119
|
+
*
|
|
1120
|
+
* @static
|
|
1121
|
+
* @memberOf _
|
|
1122
|
+
* @since 4.0.0
|
|
1123
|
+
* @category Lang
|
|
1124
|
+
* @param {*} value The value to check.
|
|
1125
|
+
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
1126
|
+
* @example
|
|
1127
|
+
*
|
|
1128
|
+
* _.isObjectLike({});
|
|
1129
|
+
* // => true
|
|
1130
|
+
*
|
|
1131
|
+
* _.isObjectLike([1, 2, 3]);
|
|
1132
|
+
* // => true
|
|
1133
|
+
*
|
|
1134
|
+
* _.isObjectLike(_.noop);
|
|
1135
|
+
* // => false
|
|
1136
|
+
*
|
|
1137
|
+
* _.isObjectLike(null);
|
|
1138
|
+
* // => false
|
|
1139
|
+
*/ function $2dbf41b550c5f478$var$isObjectLike(value) {
|
|
1140
|
+
return value != null && typeof value == 'object';
|
|
1141
|
+
}
|
|
1142
|
+
var $2dbf41b550c5f478$export$2e2bcd8739ae039 = $2dbf41b550c5f478$var$isObjectLike;
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
/** `Object#toString` result references. */ var $90290c84737dbb50$var$stringTag = '[object String]';
|
|
1146
|
+
/**
|
|
1147
|
+
* Checks if `value` is classified as a `String` primitive or object.
|
|
1148
|
+
*
|
|
1149
|
+
* @static
|
|
1150
|
+
* @since 0.1.0
|
|
1151
|
+
* @memberOf _
|
|
1152
|
+
* @category Lang
|
|
1153
|
+
* @param {*} value The value to check.
|
|
1154
|
+
* @returns {boolean} Returns `true` if `value` is a string, else `false`.
|
|
1155
|
+
* @example
|
|
1156
|
+
*
|
|
1157
|
+
* _.isString('abc');
|
|
1158
|
+
* // => true
|
|
1159
|
+
*
|
|
1160
|
+
* _.isString(1);
|
|
1161
|
+
* // => false
|
|
1162
|
+
*/ function $90290c84737dbb50$var$isString(value) {
|
|
1163
|
+
return typeof value == 'string' || !(0, $36cc8c1055cfbf3b$export$2e2bcd8739ae039)(value) && (0, $2dbf41b550c5f478$export$2e2bcd8739ae039)(value) && (0, $6911cdf7f985d482$export$2e2bcd8739ae039)(value) == $90290c84737dbb50$var$stringTag;
|
|
1164
|
+
}
|
|
1165
|
+
var $90290c84737dbb50$export$2e2bcd8739ae039 = $90290c84737dbb50$var$isString;
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
function $22e282633cad8f97$export$7f7cffd29bf2d96d(authFlags, permission) {
|
|
1175
|
+
if (authFlags > 0) return false;
|
|
1176
|
+
let flags = BigInt.asUintN(64, BigInt(authFlags));
|
|
1177
|
+
switch(permission){
|
|
1178
|
+
case 'authorise':
|
|
1179
|
+
return (0, $l50U0$libnexats.GroupToken).allowsRenew(flags);
|
|
1180
|
+
case 'mint':
|
|
1181
|
+
return (0, $l50U0$libnexats.GroupToken).allowsMint(flags);
|
|
1182
|
+
case 'melt':
|
|
1183
|
+
return (0, $l50U0$libnexats.GroupToken).allowsMelt(flags);
|
|
1184
|
+
case 'rescript':
|
|
1185
|
+
return (0, $l50U0$libnexats.GroupToken).allowsRescript(flags);
|
|
1186
|
+
case 'subgroup':
|
|
1187
|
+
return (0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags);
|
|
1188
|
+
default:
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
function $22e282633cad8f97$export$636fb0b03b94ac81(authFlags, withSubgroup = true) {
|
|
1193
|
+
if (authFlags > 0) return 0n;
|
|
1194
|
+
let flags = BigInt.asUintN(64, BigInt(authFlags));
|
|
1195
|
+
let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
|
|
1196
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsRenew(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
|
|
1197
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsMint(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
|
|
1198
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsMelt(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
|
|
1199
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsRescript(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
|
|
1200
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags) && withSubgroup) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
|
|
1201
|
+
return newFlags;
|
|
1202
|
+
}
|
|
1203
|
+
function $22e282633cad8f97$export$e240c810a53c3a0c(perms) {
|
|
1204
|
+
let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
|
|
1205
|
+
for (let perm of perms)switch(perm){
|
|
1206
|
+
case 'authorise':
|
|
1207
|
+
newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
|
|
1208
|
+
break;
|
|
1209
|
+
case 'mint':
|
|
1210
|
+
newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
|
|
1211
|
+
break;
|
|
1212
|
+
case 'melt':
|
|
1213
|
+
newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
|
|
1214
|
+
break;
|
|
1215
|
+
case 'rescript':
|
|
1216
|
+
newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
|
|
1217
|
+
break;
|
|
1218
|
+
case 'subgroup':
|
|
1219
|
+
newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
return newFlags;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
/** Maximum number of inputs/outputs allowed in a single transaction */ const $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS = 250;
|
|
1227
|
+
async function $b4a043612f1c4089$export$afd979971a55acfc(txBuilder, keys, totalTxValue, options) {
|
|
1228
|
+
let rKeys = keys.receiveKeys.filter((k)=>BigInt(k.balance) > 0n);
|
|
1229
|
+
let cKeys = keys.changeKeys.filter((k)=>BigInt(k.balance) > 0n);
|
|
1230
|
+
let allKeys = rKeys.concat(cKeys);
|
|
1231
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(allKeys)) throw new Error("Not enough Nexa balance.");
|
|
1232
|
+
let usedKeys = new Map();
|
|
1233
|
+
let origAmount = options.isConsolidate ? 0 : Number(totalTxValue);
|
|
1234
|
+
for (let key of allKeys){
|
|
1235
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(key.address);
|
|
1236
|
+
for (let utxo of utxos){
|
|
1237
|
+
let input = {
|
|
1238
|
+
outpoint: utxo.outpoint_hash,
|
|
1239
|
+
address: key.address,
|
|
1240
|
+
satoshis: utxo.value,
|
|
1241
|
+
templateData: options.templateData
|
|
1242
|
+
};
|
|
1243
|
+
txBuilder.from(input);
|
|
1244
|
+
if (!usedKeys.has(key.address)) usedKeys.set(key.address, key.key.privateKey);
|
|
1245
|
+
if (options.isConsolidate) {
|
|
1246
|
+
txBuilder.change(options.toChange ?? keys.receiveKeys[keys.receiveKeys.length - 1].address);
|
|
1247
|
+
if (txBuilder.transaction.inputs.length > $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS) return Array.from(usedKeys.values());
|
|
1248
|
+
} else {
|
|
1249
|
+
let tx = txBuilder.transaction;
|
|
1250
|
+
if (tx.inputs.length > $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS) throw new Error("Too many inputs. Consider consolidate transactions or reduce the send amount.");
|
|
1251
|
+
let unspent = tx.getUnspentValue();
|
|
1252
|
+
if (unspent < 0n) continue;
|
|
1253
|
+
if (unspent == 0n && options.feeFromAmount) {
|
|
1254
|
+
let txFee = tx.estimateRequiredFee();
|
|
1255
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
1256
|
+
return Array.from(usedKeys.values());
|
|
1257
|
+
}
|
|
1258
|
+
txBuilder.change(options.toChange ?? keys.changeKeys[keys.changeKeys.length - 1].address);
|
|
1259
|
+
if (options.feeFromAmount) {
|
|
1260
|
+
let hasChange = tx.getChangeOutput();
|
|
1261
|
+
let txFee = tx.estimateRequiredFee();
|
|
1262
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
1263
|
+
// edge case where change added after update
|
|
1264
|
+
if (!hasChange && tx.getChangeOutput()) {
|
|
1265
|
+
txFee = tx.estimateRequiredFee();
|
|
1266
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
// check again after change output manipulation
|
|
1270
|
+
if (tx.getUnspentValue() < tx.estimateRequiredFee()) continue;
|
|
1271
|
+
return Array.from(usedKeys.values());
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
if (options.isConsolidate) {
|
|
1276
|
+
if (usedKeys.size > 0) return Array.from(usedKeys.values());
|
|
1277
|
+
throw new Error("Not enough Nexa balance.");
|
|
1278
|
+
}
|
|
1279
|
+
let err = {
|
|
1280
|
+
errorMsg: "Not enough Nexa balance.",
|
|
1281
|
+
amount: (0, $l50U0$libnexats.UnitUtils).formatNEXA(txBuilder.transaction.outputs[0].value),
|
|
1282
|
+
fee: (0, $l50U0$libnexats.UnitUtils).formatNEXA(txBuilder.transaction.estimateRequiredFee())
|
|
1283
|
+
};
|
|
1284
|
+
throw new Error(JSON.stringify(err));
|
|
1285
|
+
}
|
|
1286
|
+
async function $b4a043612f1c4089$export$931e37acdaa22dcf(txBuilder, keys, token, outTokenAmount) {
|
|
1287
|
+
let tokenHex = (0, $bc5ca2c06b1affa3$export$254a5c7330bbfd41)(token);
|
|
1288
|
+
let rKeys = keys.receiveKeys.filter((k)=>Object.keys(k.tokensBalance).includes(tokenHex));
|
|
1289
|
+
let cKeys = keys.changeKeys.filter((k)=>Object.keys(k.tokensBalance).includes(tokenHex));
|
|
1290
|
+
let allKeys = rKeys.concat(cKeys);
|
|
1291
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(allKeys)) throw new Error("Not enough token balance.");
|
|
1292
|
+
let usedKeys = new Map();
|
|
1293
|
+
let inTokenAmount = 0n;
|
|
1294
|
+
for (let key of allKeys){
|
|
1295
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
|
|
1296
|
+
for (let utxo of utxos){
|
|
1297
|
+
if (utxo.token_amount < 0) continue;
|
|
1298
|
+
txBuilder.from({
|
|
1299
|
+
outpoint: utxo.outpoint_hash,
|
|
1300
|
+
address: key.address,
|
|
1301
|
+
satoshis: utxo.value,
|
|
1302
|
+
groupId: utxo.group,
|
|
1303
|
+
groupAmount: BigInt(utxo.token_amount)
|
|
1304
|
+
});
|
|
1305
|
+
inTokenAmount = inTokenAmount + BigInt(utxo.token_amount);
|
|
1306
|
+
if (!usedKeys.has(key.address)) usedKeys.set(key.address, key.key.privateKey);
|
|
1307
|
+
if (inTokenAmount > (0, $bc5ca2c06b1affa3$export$8ba128bc85947a2a)) throw new Error("Token inputs exceeded max amount. Consider sending in small chunks");
|
|
1308
|
+
if (txBuilder.transaction.inputs.length > $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS) throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
|
|
1309
|
+
if (inTokenAmount == outTokenAmount) return Array.from(usedKeys.values());
|
|
1310
|
+
if (inTokenAmount > outTokenAmount) {
|
|
1311
|
+
// change
|
|
1312
|
+
txBuilder.to(keys.changeKeys[keys.changeKeys.length - 1].address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, inTokenAmount - outTokenAmount);
|
|
1313
|
+
return Array.from(usedKeys.values());
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
throw new Error("Not enough token balance");
|
|
1318
|
+
}
|
|
1319
|
+
async function $b4a043612f1c4089$export$d7f2b844e1d59768(txBuilder, keys, opReturnData, network) {
|
|
1320
|
+
// TODO validate opreturn data
|
|
1321
|
+
const allKeys = keys.receiveKeys.concat(keys.changeKeys);
|
|
1322
|
+
let outpoint = '';
|
|
1323
|
+
let usedKeys = [];
|
|
1324
|
+
let signKey = undefined;
|
|
1325
|
+
for (let key of allKeys){
|
|
1326
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(key.address);
|
|
1327
|
+
for (let utxo of utxos){
|
|
1328
|
+
txBuilder.from({
|
|
1329
|
+
outpoint: utxo.outpoint_hash,
|
|
1330
|
+
address: key.address,
|
|
1331
|
+
satoshis: utxo.value
|
|
1332
|
+
});
|
|
1333
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(outpoint)) {
|
|
1334
|
+
outpoint = utxo.outpoint_hash;
|
|
1335
|
+
let id = (0, $l50U0$libnexats.GroupToken).findGroupId(Buffer.from(outpoint, 'hex'), Buffer.from(opReturnData, 'hex'), (0, $l50U0$libnexats.GroupToken).authFlags.ACTIVE_FLAG_BITS);
|
|
1336
|
+
const groupId = new (0, $l50U0$libnexats.Address)(id.hashBuffer, network, (0, $l50U0$libnexats.AddressType).GroupIdAddress).toString();
|
|
1337
|
+
txBuilder.to(keys.receiveKeys.at(-1).address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, groupId, (0, $l50U0$libnexats.GroupToken).authFlags.ACTIVE_FLAG_BITS | id.nonce);
|
|
1338
|
+
signKey = key.key.privateKey;
|
|
1339
|
+
usedKeys.push(signKey);
|
|
1340
|
+
return usedKeys;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
throw new Error("Not enough Nexa balance.");
|
|
1345
|
+
}
|
|
1346
|
+
async function $b4a043612f1c4089$export$48a48877d6df17e9(txBuilder, keys, outpoint) {
|
|
1347
|
+
let utxo = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getUtxo(outpoint);
|
|
1348
|
+
let address = utxo.addresses[0];
|
|
1349
|
+
txBuilder.from({
|
|
1350
|
+
outpoint: outpoint,
|
|
1351
|
+
address: address,
|
|
1352
|
+
satoshis: utxo.amount
|
|
1353
|
+
});
|
|
1354
|
+
let allKeys = keys.receiveKeys.concat(keys.changeKeys);
|
|
1355
|
+
let addrKey = allKeys.find((k)=>k.address === address);
|
|
1356
|
+
if (!addrKey) throw new Error('UTXO associated key not found in the wallet');
|
|
1357
|
+
return [
|
|
1358
|
+
addrKey.key.privateKey
|
|
1359
|
+
];
|
|
1360
|
+
}
|
|
1361
|
+
async function $b4a043612f1c4089$export$1dfa5d829fc95097(txBuilder, keys, token, perm, subgroup = '', subgroupAddr = '') {
|
|
1362
|
+
let allKeys = keys.receiveKeys.concat(keys.changeKeys);
|
|
1363
|
+
for (let key of allKeys){
|
|
1364
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
|
|
1365
|
+
for (let utxo of utxos){
|
|
1366
|
+
if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) continue;
|
|
1367
|
+
txBuilder.from({
|
|
1368
|
+
outpoint: utxo.outpoint_hash,
|
|
1369
|
+
address: key.address,
|
|
1370
|
+
satoshis: utxo.value
|
|
1371
|
+
});
|
|
1372
|
+
if (perm === 'subgroup') txBuilder.to(subgroupAddr, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, subgroup, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount, false));
|
|
1373
|
+
// if renew flag included, we don't want to burn it
|
|
1374
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) txBuilder.to(keys.receiveKeys.at(-1).address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
|
|
1375
|
+
return [
|
|
1376
|
+
key.key.privateKey
|
|
1377
|
+
];
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
throw new Error("The requested authority not found");
|
|
1381
|
+
}
|
|
1382
|
+
async function $b4a043612f1c4089$export$28a843ca046a6b3f(txBuilder, keys, token, perms, toAddr) {
|
|
1383
|
+
let allKeys = keys.receiveKeys.concat(keys.changeKeys);
|
|
1384
|
+
let usedKeys = [];
|
|
1385
|
+
let reqiredPerms = new Set(perms);
|
|
1386
|
+
reqiredPerms.add('authorise');
|
|
1387
|
+
for (let key of allKeys){
|
|
1388
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
|
|
1389
|
+
for (let utxo of utxos){
|
|
1390
|
+
if (utxo.token_amount > 0) continue;
|
|
1391
|
+
let found = false;
|
|
1392
|
+
for (let perm of reqiredPerms)if ((0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) {
|
|
1393
|
+
reqiredPerms.delete(perm);
|
|
1394
|
+
found = true;
|
|
1395
|
+
}
|
|
1396
|
+
if (!found) continue;
|
|
1397
|
+
txBuilder.from({
|
|
1398
|
+
outpoint: utxo.outpoint_hash,
|
|
1399
|
+
address: key.address,
|
|
1400
|
+
satoshis: utxo.value
|
|
1401
|
+
});
|
|
1402
|
+
usedKeys.push(key.key.privateKey);
|
|
1403
|
+
// duplicate
|
|
1404
|
+
txBuilder.to(toAddr != null ? toAddr : keys.receiveKeys.at(-1).address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
|
|
1405
|
+
if (reqiredPerms.size === 0) return usedKeys;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
throw new Error("The required authorities not found");
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
var $cpiMl = parcelRequire("cpiMl");
|
|
1416
|
+
|
|
1417
|
+
/**
|
|
1418
|
+
* A specialized version of `_.map` for arrays without support for iteratee
|
|
1419
|
+
* shorthands.
|
|
1420
|
+
*
|
|
1421
|
+
* @private
|
|
1422
|
+
* @param {Array} [array] The array to iterate over.
|
|
1423
|
+
* @param {Function} iteratee The function invoked per iteration.
|
|
1424
|
+
* @returns {Array} Returns the new mapped array.
|
|
1425
|
+
*/ function $a73a31c10d15d7eb$var$arrayMap(array, iteratee) {
|
|
1426
|
+
var index = -1, length = array == null ? 0 : array.length, result = Array(length);
|
|
1427
|
+
while(++index < length)result[index] = iteratee(array[index], index, array);
|
|
1428
|
+
return result;
|
|
1429
|
+
}
|
|
1430
|
+
var $a73a31c10d15d7eb$export$2e2bcd8739ae039 = $a73a31c10d15d7eb$var$arrayMap;
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
/** `Object#toString` result references. */ var $9f098434abbe9d75$var$symbolTag = '[object Symbol]';
|
|
1437
|
+
/**
|
|
1438
|
+
* Checks if `value` is classified as a `Symbol` primitive or object.
|
|
1439
|
+
*
|
|
1440
|
+
* @static
|
|
1441
|
+
* @memberOf _
|
|
1442
|
+
* @since 4.0.0
|
|
1443
|
+
* @category Lang
|
|
1444
|
+
* @param {*} value The value to check.
|
|
1445
|
+
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
|
1446
|
+
* @example
|
|
1447
|
+
*
|
|
1448
|
+
* _.isSymbol(Symbol.iterator);
|
|
1449
|
+
* // => true
|
|
1450
|
+
*
|
|
1451
|
+
* _.isSymbol('abc');
|
|
1452
|
+
* // => false
|
|
1453
|
+
*/ function $9f098434abbe9d75$var$isSymbol(value) {
|
|
1454
|
+
return typeof value == 'symbol' || (0, $2dbf41b550c5f478$export$2e2bcd8739ae039)(value) && (0, $6911cdf7f985d482$export$2e2bcd8739ae039)(value) == $9f098434abbe9d75$var$symbolTag;
|
|
1455
|
+
}
|
|
1456
|
+
var $9f098434abbe9d75$export$2e2bcd8739ae039 = $9f098434abbe9d75$var$isSymbol;
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
/** Used as references for various `Number` constants. */ var $d3d5261e2cef37e4$var$INFINITY = 1 / 0;
|
|
1460
|
+
/** Used to convert symbols to primitives and strings. */ var $d3d5261e2cef37e4$var$symbolProto = (0, $ff9e97e034030f4b$export$2e2bcd8739ae039) ? (0, $ff9e97e034030f4b$export$2e2bcd8739ae039).prototype : undefined, $d3d5261e2cef37e4$var$symbolToString = $d3d5261e2cef37e4$var$symbolProto ? $d3d5261e2cef37e4$var$symbolProto.toString : undefined;
|
|
1461
|
+
/**
|
|
1462
|
+
* The base implementation of `_.toString` which doesn't convert nullish
|
|
1463
|
+
* values to empty strings.
|
|
1464
|
+
*
|
|
1465
|
+
* @private
|
|
1466
|
+
* @param {*} value The value to process.
|
|
1467
|
+
* @returns {string} Returns the string.
|
|
1468
|
+
*/ function $d3d5261e2cef37e4$var$baseToString(value) {
|
|
1469
|
+
// Exit early for strings to avoid a performance hit in some environments.
|
|
1470
|
+
if (typeof value == 'string') return value;
|
|
1471
|
+
if ((0, $36cc8c1055cfbf3b$export$2e2bcd8739ae039)(value)) // Recursively convert values (susceptible to call stack limits).
|
|
1472
|
+
return (0, $a73a31c10d15d7eb$export$2e2bcd8739ae039)(value, $d3d5261e2cef37e4$var$baseToString) + '';
|
|
1473
|
+
if ((0, $9f098434abbe9d75$export$2e2bcd8739ae039)(value)) return $d3d5261e2cef37e4$var$symbolToString ? $d3d5261e2cef37e4$var$symbolToString.call(value) : '';
|
|
1474
|
+
var result = value + '';
|
|
1475
|
+
return result == '0' && 1 / value == -$d3d5261e2cef37e4$var$INFINITY ? '-0' : result;
|
|
1476
|
+
}
|
|
1477
|
+
var $d3d5261e2cef37e4$export$2e2bcd8739ae039 = $d3d5261e2cef37e4$var$baseToString;
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* Converts `value` to a string. An empty string is returned for `null`
|
|
1482
|
+
* and `undefined` values. The sign of `-0` is preserved.
|
|
1483
|
+
*
|
|
1484
|
+
* @static
|
|
1485
|
+
* @memberOf _
|
|
1486
|
+
* @since 4.0.0
|
|
1487
|
+
* @category Lang
|
|
1488
|
+
* @param {*} value The value to convert.
|
|
1489
|
+
* @returns {string} Returns the converted string.
|
|
1490
|
+
* @example
|
|
1491
|
+
*
|
|
1492
|
+
* _.toString(null);
|
|
1493
|
+
* // => ''
|
|
1494
|
+
*
|
|
1495
|
+
* _.toString(-0);
|
|
1496
|
+
* // => '-0'
|
|
1497
|
+
*
|
|
1498
|
+
* _.toString([1, 2, 3]);
|
|
1499
|
+
* // => '1,2,3'
|
|
1500
|
+
*/ function $2b7b63cdaf61fcff$var$toString(value) {
|
|
1501
|
+
return value == null ? '' : (0, $d3d5261e2cef37e4$export$2e2bcd8739ae039)(value);
|
|
1502
|
+
}
|
|
1503
|
+
var $2b7b63cdaf61fcff$export$2e2bcd8739ae039 = $2b7b63cdaf61fcff$var$toString;
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
/** Used to match leading whitespace. */ var $ed110f8656071ee4$var$reTrimStart = /^\s+/;
|
|
1507
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */ var $ed110f8656071ee4$var$nativeParseInt = (0, $cpiMl.default).parseInt;
|
|
1508
|
+
/**
|
|
1509
|
+
* Converts `string` to an integer of the specified radix. If `radix` is
|
|
1510
|
+
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a
|
|
1511
|
+
* hexadecimal, in which case a `radix` of `16` is used.
|
|
1512
|
+
*
|
|
1513
|
+
* **Note:** This method aligns with the
|
|
1514
|
+
* [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
|
|
1515
|
+
*
|
|
1516
|
+
* @static
|
|
1517
|
+
* @memberOf _
|
|
1518
|
+
* @since 1.1.0
|
|
1519
|
+
* @category String
|
|
1520
|
+
* @param {string} string The string to convert.
|
|
1521
|
+
* @param {number} [radix=10] The radix to interpret `value` by.
|
|
1522
|
+
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|
1523
|
+
* @returns {number} Returns the converted integer.
|
|
1524
|
+
* @example
|
|
1525
|
+
*
|
|
1526
|
+
* _.parseInt('08');
|
|
1527
|
+
* // => 8
|
|
1528
|
+
*
|
|
1529
|
+
* _.map(['6', '08', '10'], _.parseInt);
|
|
1530
|
+
* // => [6, 8, 10]
|
|
1531
|
+
*/ function $ed110f8656071ee4$var$parseInt(string, radix, guard) {
|
|
1532
|
+
if (guard || radix == null) radix = 0;
|
|
1533
|
+
else if (radix) radix = +radix;
|
|
1534
|
+
return $ed110f8656071ee4$var$nativeParseInt((0, $2b7b63cdaf61fcff$export$2e2bcd8739ae039)(string).replace($ed110f8656071ee4$var$reTrimStart, ''), radix || 0);
|
|
1535
|
+
}
|
|
1536
|
+
var $ed110f8656071ee4$export$2e2bcd8739ae039 = $ed110f8656071ee4$var$parseInt;
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
class $57b0117fe8233fef$export$bba690fb5c12ba04 {
|
|
1541
|
+
/**
|
|
1542
|
+
* Creates a new TransactionCreator instance
|
|
1543
|
+
* @param tx Optional existing TransactionBuilder, hex string, or buffer
|
|
1544
|
+
*/ constructor(tx){
|
|
1545
|
+
/** Array of async functions to execute when building the transaction */ this._builder = [];
|
|
1546
|
+
/** Total value of NEXA being sent in this transaction */ this._totalValue = BigInt(0);
|
|
1547
|
+
/** Network this transaction will be broadcast on */ this._network = (0, $l50U0$libnexats.Networks).mainnet;
|
|
1548
|
+
/** Transaction options for customizing behavior */ this._txOptions = {};
|
|
1549
|
+
if (tx instanceof (0, $l50U0$libnexats.TransactionBuilder)) this.transactionBuilder = tx;
|
|
1550
|
+
this.tokens = new Set();
|
|
1551
|
+
this.transactionBuilder = new (0, $l50U0$libnexats.TransactionBuilder)();
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Sets the network for this transaction
|
|
1555
|
+
* @param network Network name or Networkish object
|
|
1556
|
+
* @returns This instance for chaining
|
|
1557
|
+
*/ onNetwork(network) {
|
|
1558
|
+
this.network = (0, $l50U0$libnexats.Networks).get(network);
|
|
1559
|
+
return this;
|
|
1560
|
+
}
|
|
1561
|
+
/** Gets transaction options */ get txOptions() {
|
|
1562
|
+
return this._txOptions;
|
|
1563
|
+
}
|
|
1564
|
+
/** Sets transaction options */ set txOptions(value) {
|
|
1565
|
+
this._txOptions = value;
|
|
1566
|
+
}
|
|
1567
|
+
/** Gets the network for this transaction */ get network() {
|
|
1568
|
+
return this._network;
|
|
1569
|
+
}
|
|
1570
|
+
/** Sets the network for this transaction */ set network(value) {
|
|
1571
|
+
this._network = value;
|
|
1572
|
+
}
|
|
1573
|
+
/** Gets the builder function array */ get builder() {
|
|
1574
|
+
return this._builder;
|
|
1575
|
+
}
|
|
1576
|
+
/** Sets the builder function array */ set builder(value) {
|
|
1577
|
+
this._builder = value;
|
|
1578
|
+
}
|
|
1579
|
+
/** Gets the underlying transaction builder */ get transactionBuilder() {
|
|
1580
|
+
return this._transactionBuilder;
|
|
1581
|
+
}
|
|
1582
|
+
/** Sets the underlying transaction builder */ set transactionBuilder(value) {
|
|
1583
|
+
this._transactionBuilder = value;
|
|
1584
|
+
}
|
|
1585
|
+
/** Gets the set of token actions */ get tokens() {
|
|
1586
|
+
return this._tokens;
|
|
1587
|
+
}
|
|
1588
|
+
/** Sets the set of token actions */ set tokens(value) {
|
|
1589
|
+
this._tokens = value;
|
|
1590
|
+
}
|
|
1591
|
+
/** Gets the total NEXA value being sent */ get totalValue() {
|
|
1592
|
+
return this._totalValue;
|
|
1593
|
+
}
|
|
1594
|
+
/** Sets the total NEXA value being sent */ set totalValue(value) {
|
|
1595
|
+
this._totalValue = value;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Validates and creates a token action
|
|
1599
|
+
* @param toAddr Destination address
|
|
1600
|
+
* @param amount Amount to send
|
|
1601
|
+
* @param token Token ID
|
|
1602
|
+
* @param action Action type (mint, melt, send, etc.)
|
|
1603
|
+
* @throws Error if validation fails
|
|
1604
|
+
*/ tokenAction(toAddr, amount, token, action) {
|
|
1605
|
+
// Validate destination address
|
|
1606
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
1607
|
+
// Validate amount ranges
|
|
1608
|
+
if (token && BigInt(amount) < 1n || !token && (0, $ed110f8656071ee4$export$2e2bcd8739ae039)(amount) < (0, $l50U0$libnexats.Transaction).DUST_AMOUNT) throw new Error("The amount is too low.");
|
|
1609
|
+
if (token && BigInt(amount) > (0, $bc5ca2c06b1affa3$export$8ba128bc85947a2a) || !token && (0, $ed110f8656071ee4$export$2e2bcd8739ae039)(amount) > (0, $l50U0$libnexats.Transaction).MAX_MONEY) throw new Error("The amount is too high.");
|
|
1610
|
+
// Validate token ID
|
|
1611
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(token, this.network, (0, $l50U0$libnexats.AddressType).GroupIdAddress)) throw new Error('Invalid Token ID');
|
|
1612
|
+
// Ensure tokens are sent to script template addresses
|
|
1613
|
+
if ((0, $l50U0$libnexats.Address).getOutputType(toAddr) === 0) throw new Error('Token must be sent to script template address');
|
|
1614
|
+
// Add output to transaction
|
|
1615
|
+
this.transactionBuilder.to(toAddr, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, BigInt(amount));
|
|
1616
|
+
// Record the token action
|
|
1617
|
+
this.tokens.add({
|
|
1618
|
+
token: token,
|
|
1619
|
+
amount: BigInt(amount),
|
|
1620
|
+
action: action
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Configures transaction to consolidate UTXOs to a single address
|
|
1625
|
+
* @param toAddr Address to consolidate funds to
|
|
1626
|
+
* @returns This instance for chaining
|
|
1627
|
+
*/ consolidate(toAddr) {
|
|
1628
|
+
this.builder.push(async ()=>{
|
|
1629
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
1630
|
+
this._txOptions.isConsolidate = true;
|
|
1631
|
+
this._txOptions.toChange = toAddr;
|
|
1632
|
+
});
|
|
1633
|
+
return this;
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Configures transaction to deduct fee from the send amount
|
|
1637
|
+
* @returns This instance for chaining
|
|
1638
|
+
*/ feeFromAmount() {
|
|
1639
|
+
this.builder.push(async ()=>{
|
|
1640
|
+
this._txOptions.feeFromAmount = true;
|
|
1641
|
+
});
|
|
1642
|
+
return this;
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Adds a token send operation to the transaction
|
|
1646
|
+
* @param toAddr Destination address
|
|
1647
|
+
* @param amount Amount of tokens to send
|
|
1648
|
+
* @param token Token ID
|
|
1649
|
+
* @returns This instance for chaining
|
|
1650
|
+
*/ sendToToken(toAddr, amount, token) {
|
|
1651
|
+
this.builder.push(async ()=>{
|
|
1652
|
+
this.tokenAction(toAddr, amount, token, 'send');
|
|
1653
|
+
});
|
|
1654
|
+
return this;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Adds a NEXA send operation to the transaction
|
|
1658
|
+
* @param toAddr Destination address
|
|
1659
|
+
* @param amount Amount of NEXA to send
|
|
1660
|
+
* @returns This instance for chaining
|
|
1661
|
+
*/ sendTo(toAddr, amount) {
|
|
1662
|
+
this.builder.push(async ()=>{
|
|
1663
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
1664
|
+
this.transactionBuilder.to(toAddr, amount);
|
|
1665
|
+
this.totalValue = BigInt(this.totalValue + amount);
|
|
1666
|
+
});
|
|
1667
|
+
return this;
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Adds a token authority renewal operation
|
|
1671
|
+
* @param token Token ID to renew authority for
|
|
1672
|
+
* @param perms Permissions to renew
|
|
1673
|
+
* @param toAddr
|
|
1674
|
+
* @returns This instance for chaining
|
|
1675
|
+
*/ renewAuthority(token, perms, toAddr) {
|
|
1676
|
+
this.builder.push(async ()=>{
|
|
1677
|
+
if (toAddr != null) {
|
|
1678
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
1679
|
+
}
|
|
1680
|
+
this.tokens.add({
|
|
1681
|
+
token: token,
|
|
1682
|
+
action: 'renew',
|
|
1683
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1684
|
+
parentToken: undefined,
|
|
1685
|
+
extraData: {
|
|
1686
|
+
perms: perms,
|
|
1687
|
+
address: toAddr
|
|
1688
|
+
}
|
|
1689
|
+
});
|
|
1690
|
+
});
|
|
1691
|
+
return this;
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Adds a token authority deletion operation
|
|
1695
|
+
* @param token Token ID to delete authority for
|
|
1696
|
+
* @param outpoint Outpoint of the authority to delete
|
|
1697
|
+
* @returns This instance for chaining
|
|
1698
|
+
*/ deleteAuthority(token, outpoint) {
|
|
1699
|
+
this.builder.push(async ()=>{
|
|
1700
|
+
this.tokens.add({
|
|
1701
|
+
token: token,
|
|
1702
|
+
action: 'delete',
|
|
1703
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1704
|
+
parentToken: undefined,
|
|
1705
|
+
extraData: {
|
|
1706
|
+
outpoint: outpoint
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
return this;
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Creates a legacy token (not implemented)
|
|
1714
|
+
* @returns This instance for chaining
|
|
1715
|
+
*/ legacyToken(name, ticker, decimals, docUrl, docHash) {
|
|
1716
|
+
this.builder.push(async ()=>{
|
|
1717
|
+
const opReturn = (0, $l50U0$libnexats.ScriptFactory).buildTokenDescriptionLegacy(ticker, name, docUrl, docHash, decimals);
|
|
1718
|
+
this.transactionBuilder.addData(opReturn, true);
|
|
1719
|
+
this.tokens.add({
|
|
1720
|
+
action: 'group',
|
|
1721
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1722
|
+
extraData: {
|
|
1723
|
+
opReturnData: opReturn.toHex()
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
});
|
|
1727
|
+
return this;
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Creates a legacy group (not implemented)
|
|
1731
|
+
* @returns This instance for chaining
|
|
1732
|
+
*/ legacyGroup(name, ticker, docUrl, docHash) {
|
|
1733
|
+
this.builder.push(async ()=>{
|
|
1734
|
+
const opReturn = (0, $l50U0$libnexats.ScriptFactory).buildTokenDescriptionLegacy(ticker, name, docUrl, docHash);
|
|
1735
|
+
this.transactionBuilder.addData(opReturn, true);
|
|
1736
|
+
this.tokens.add({
|
|
1737
|
+
action: 'group',
|
|
1738
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1739
|
+
extraData: {
|
|
1740
|
+
opReturnData: opReturn.toHex()
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
});
|
|
1744
|
+
return this;
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Creates a token with metadata
|
|
1748
|
+
* @param name Token name
|
|
1749
|
+
* @param ticker Token ticker symbol
|
|
1750
|
+
* @param decimals Number of decimal places
|
|
1751
|
+
* @param docUrl URL to token documentation
|
|
1752
|
+
* @param docHash Hash of token documentation
|
|
1753
|
+
* @returns This instance for chaining
|
|
1754
|
+
*/ token(name, ticker, decimals, docUrl, docHash) {
|
|
1755
|
+
this.builder.push(async ()=>{
|
|
1756
|
+
const opReturn = (0, $l50U0$libnexats.ScriptFactory).buildTokenDescription(ticker, name, docUrl, docHash, decimals);
|
|
1757
|
+
this.transactionBuilder.addData(opReturn, true);
|
|
1758
|
+
this.tokens.add({
|
|
1759
|
+
action: 'group',
|
|
1760
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1761
|
+
extraData: {
|
|
1762
|
+
opReturnData: opReturn.toHex()
|
|
1763
|
+
}
|
|
1764
|
+
});
|
|
1765
|
+
});
|
|
1766
|
+
return this;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Creates an NFT collection with metadata
|
|
1770
|
+
* @param name Collection name
|
|
1771
|
+
* @param ticker Collection ticker symbol
|
|
1772
|
+
* @param docUrl URL to collection documentation
|
|
1773
|
+
* @param docHash Hash of collection documentation
|
|
1774
|
+
* @returns This instance for chaining
|
|
1775
|
+
*/ collection(name, ticker, docUrl, docHash) {
|
|
1776
|
+
this.builder.push(async ()=>{
|
|
1777
|
+
const opReturn = (0, $l50U0$libnexats.ScriptFactory).buildNFTCollectionDescription(ticker, name, docUrl, docHash);
|
|
1778
|
+
this.transactionBuilder.addData(opReturn, true);
|
|
1779
|
+
this.tokens.add({
|
|
1780
|
+
action: 'group',
|
|
1781
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1782
|
+
extraData: {
|
|
1783
|
+
opReturnData: opReturn.toHex()
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
});
|
|
1787
|
+
return this;
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Creates an NFT within a collection
|
|
1791
|
+
* @param parent Parent collection token ID
|
|
1792
|
+
* @param zipUrl URL to NFT content ZIP file
|
|
1793
|
+
* @param zipHash Hash of NFT content ZIP file
|
|
1794
|
+
* @returns This instance for chaining
|
|
1795
|
+
*/ nft(parent, zipUrl, zipHash) {
|
|
1796
|
+
this.builder.push(async ()=>{
|
|
1797
|
+
// add op_return for the nft
|
|
1798
|
+
let opReturn = (0, $l50U0$libnexats.ScriptFactory).buildNFTDescription(zipUrl, zipHash);
|
|
1799
|
+
this.transactionBuilder.addData(opReturn, true);
|
|
1800
|
+
// generate subgroup ID
|
|
1801
|
+
const subGroup = (0, $l50U0$libnexats.GroupToken).generateSubgroupId(parent, opReturn.toBuffer()).toString('hex');
|
|
1802
|
+
this.tokens.add({
|
|
1803
|
+
token: subGroup,
|
|
1804
|
+
parentToken: parent,
|
|
1805
|
+
amount: BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT),
|
|
1806
|
+
action: 'subgroup'
|
|
1807
|
+
});
|
|
1808
|
+
});
|
|
1809
|
+
return this;
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Adds an OP_RETURN output to the transaction
|
|
1813
|
+
* @param data Data to include in the OP_RETURN
|
|
1814
|
+
* @param isFullScript Whether the data is already a complete script
|
|
1815
|
+
* @returns This instance for chaining
|
|
1816
|
+
*/ addOpReturn(data, isFullScript = false) {
|
|
1817
|
+
this.builder.push(async ()=>{
|
|
1818
|
+
let script = isFullScript ? new (0, $l50U0$libnexats.Script)(data) : (0, $l50U0$libnexats.ScriptFactory).buildDataOut(data);
|
|
1819
|
+
let output = new (0, $l50U0$libnexats.Output)(0, script);
|
|
1820
|
+
this.transactionBuilder.transaction.addOutput(output);
|
|
1821
|
+
});
|
|
1822
|
+
return this;
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Builds the transaction by executing all queued operations
|
|
1826
|
+
* @returns Promise resolving to the serialized transaction hex
|
|
1827
|
+
*/ async build() {
|
|
1828
|
+
for (const task of this.builder)await task();
|
|
1829
|
+
return this.transactionBuilder.transaction.serialize({
|
|
1830
|
+
disableAll: true
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
|
|
1836
|
+
class $e1896e59040fa3c5$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$export$bba690fb5c12ba04) {
|
|
1837
|
+
constructor(fromAccount, tx){
|
|
1838
|
+
super(tx), this._keysToSign = [];
|
|
1839
|
+
this._account = fromAccount;
|
|
1840
|
+
this.validateAccount();
|
|
1841
|
+
}
|
|
1842
|
+
fromAccount(fromAccount) {
|
|
1843
|
+
this._account = fromAccount;
|
|
1844
|
+
return this;
|
|
1845
|
+
}
|
|
1846
|
+
parseTxHex(tx) {
|
|
1847
|
+
this.builder.push(async ()=>{
|
|
1848
|
+
const txBuilder = new (0, $l50U0$libnexats.TransactionBuilder)(tx);
|
|
1849
|
+
const newTxBuilder = new (0, $l50U0$libnexats.TransactionBuilder)();
|
|
1850
|
+
const oldInputs = txBuilder.transaction.inputs;
|
|
1851
|
+
for (const input of oldInputs){
|
|
1852
|
+
const utxo = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getUtxo(input.outpoint.toString('hex'));
|
|
1853
|
+
newTxBuilder.from({
|
|
1854
|
+
outpoint: utxo.tx_hash,
|
|
1855
|
+
amount: utxo.amount,
|
|
1856
|
+
scriptPubKey: utxo.scriptpubkey
|
|
1857
|
+
});
|
|
1858
|
+
const foundKey = this.findPrivateKeyFromAddress(utxo.addresses[0]);
|
|
1859
|
+
if (foundKey) this._keysToSign.push(foundKey.key.privateKey);
|
|
1860
|
+
}
|
|
1861
|
+
newTxBuilder.transaction.outputs = txBuilder.transaction.outputs;
|
|
1862
|
+
});
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
parseTxBuffer(tx) {
|
|
1866
|
+
this.builder.push(async ()=>{
|
|
1867
|
+
this.transactionBuilder = new (0, $l50U0$libnexats.TransactionBuilder)(tx);
|
|
1868
|
+
});
|
|
1869
|
+
return this;
|
|
1870
|
+
}
|
|
1871
|
+
mint(token, amount) {
|
|
1872
|
+
this.builder.push(async ()=>{
|
|
1873
|
+
let toAddr = this._account.accountKeys.receiveKeys.at(-1).address;
|
|
1874
|
+
this.tokenAction(toAddr, amount, token, 'mint');
|
|
1875
|
+
});
|
|
1876
|
+
return this;
|
|
1877
|
+
}
|
|
1878
|
+
melt(token, amount) {
|
|
1879
|
+
this.builder.push(async ()=>{
|
|
1880
|
+
let toAddr = this._account.accountKeys.receiveKeys.at(-1).address;
|
|
1881
|
+
this.tokenAction(toAddr, amount, token, 'melt');
|
|
1882
|
+
});
|
|
1883
|
+
return this;
|
|
1884
|
+
}
|
|
1885
|
+
populate() {
|
|
1886
|
+
this.validateAccount();
|
|
1887
|
+
this.builder.push(async ()=>{
|
|
1888
|
+
let tK = [];
|
|
1889
|
+
let nK = [];
|
|
1890
|
+
if (this.tokens.size > 0) for (const tokenAction of this.tokens){
|
|
1891
|
+
if (tokenAction.action == 'mint' || tokenAction.action == 'melt') tK = tK.concat(await (0, $b4a043612f1c4089$export$1dfa5d829fc95097)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.action));
|
|
1892
|
+
else if (tokenAction.action == 'group') tK = tK.concat(await (0, $b4a043612f1c4089$export$d7f2b844e1d59768)(this.transactionBuilder, this._account.accountKeys, tokenAction.extraData?.opReturnData, this.network));
|
|
1893
|
+
else if (tokenAction.action == 'subgroup') tK = tK.concat(await (0, $b4a043612f1c4089$export$1dfa5d829fc95097)(this.transactionBuilder, this._account.accountKeys, tokenAction.parentToken, 'subgroup', tokenAction.token, this._account.accountKeys.receiveKeys.at(-1).address));
|
|
1894
|
+
else if (tokenAction.action == 'renew') tK = tK.concat(await (0, $b4a043612f1c4089$export$28a843ca046a6b3f)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.extraData.perms, tokenAction.extraData.address));
|
|
1895
|
+
else if (tokenAction.action == 'delete') tK = tK.concat(await (0, $b4a043612f1c4089$export$48a48877d6df17e9)(this.transactionBuilder, this._account.accountKeys, tokenAction.extraData.outpoint));
|
|
1896
|
+
else tK = tK.concat(await (0, $b4a043612f1c4089$export$931e37acdaa22dcf)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.amount));
|
|
1897
|
+
this._keysToSign.concat(tK);
|
|
1898
|
+
}
|
|
1899
|
+
nK = nK.concat(await (0, $b4a043612f1c4089$export$afd979971a55acfc)(this.transactionBuilder, this._account.accountKeys, this.totalValue, this.txOptions));
|
|
1900
|
+
this._keysToSign = tK.concat(nK);
|
|
1901
|
+
});
|
|
1902
|
+
return this;
|
|
1903
|
+
}
|
|
1904
|
+
sign() {
|
|
1905
|
+
this.builder.push(async ()=>{
|
|
1906
|
+
const blockHeight = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getBlockTip();
|
|
1907
|
+
this.transactionBuilder.lockUntilBlockHeight(blockHeight.height).sign(this._keysToSign);
|
|
1908
|
+
});
|
|
1909
|
+
return this;
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Validates that the account has the necessary keys before performing operations
|
|
1913
|
+
* @throws Error if account or keys are not properly initialized
|
|
1914
|
+
*/ validateAccount() {
|
|
1915
|
+
if (!this._account) throw new Error('Account must be set before performing transactions');
|
|
1916
|
+
if (!this._account.accountKeys) throw new Error('Account keys are not initialized');
|
|
1917
|
+
if (!this._account.accountKeys.receiveKeys || this._account.accountKeys.receiveKeys.length === 0) throw new Error('No receive keys available in account');
|
|
1918
|
+
}
|
|
1919
|
+
findPrivateKeyFromAddress(addr) {
|
|
1920
|
+
const keys = this._account.accountKeys.receiveKeys.concat(this._account.accountKeys.changeKeys);
|
|
1921
|
+
return keys.find((key)=>key.address === addr);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
class $7fcf3b163a95e69a$export$2e2bcd8739ae039 {
|
|
1931
|
+
/**
|
|
1932
|
+
* Creates a new AccountStore instance
|
|
1933
|
+
* Initializes an empty map to store accounts
|
|
1934
|
+
*/ constructor(){
|
|
1935
|
+
this._accounts = new Map();
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Generates a unique store key for an account based on its type and index
|
|
1939
|
+
* @param accountType The type of account (DAPP, VAULT, or DEFAULT)
|
|
1940
|
+
* @param index The account index
|
|
1941
|
+
* @returns Unique string key for storing the account
|
|
1942
|
+
*/ getAccountStoreKey(accountType, index) {
|
|
1943
|
+
switch(accountType){
|
|
1944
|
+
case (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT:
|
|
1945
|
+
// DApp accounts use format: "2.index"
|
|
1946
|
+
return String(accountType + '.' + index);
|
|
1947
|
+
case (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).VAULT_ACCOUNT:
|
|
1948
|
+
// Vault accounts use format: "1.index"
|
|
1949
|
+
return String(accountType + '.' + index);
|
|
1950
|
+
default:
|
|
1951
|
+
// Default accounts use just the index
|
|
1952
|
+
return String(index);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Creates a new account of the specified type
|
|
1957
|
+
* @param accountType Type of account to create (DAPP, VAULT, or DEFAULT)
|
|
1958
|
+
* @param masterKey Master HD private key for deriving account keys
|
|
1959
|
+
* @returns Promise resolving to the created account
|
|
1960
|
+
*/ async createAccount(accountType, masterKey) {
|
|
1961
|
+
// Get the next available index for this account type
|
|
1962
|
+
const nextIndex = await (0, $0d59d2bcffd646c5$export$ef13479e8d3251d7)(accountType, masterKey);
|
|
1963
|
+
const accountStoreKey = this.getAccountStoreKey(accountType, nextIndex);
|
|
1964
|
+
// Check if account already exists
|
|
1965
|
+
const indexExists = this._accounts.get(String(accountStoreKey));
|
|
1966
|
+
if (indexExists) return indexExists;
|
|
1967
|
+
switch(accountType){
|
|
1968
|
+
case (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT:
|
|
1969
|
+
// Create DApp account (purpose 2)
|
|
1970
|
+
let dappAccountKey = (0, $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9)(masterKey, 2);
|
|
1971
|
+
const dAppAccount = new (0, $cf960f437fe63027$export$2e2bcd8739ae039)(2, nextIndex, (0, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9)(dappAccountKey, nextIndex));
|
|
1972
|
+
await dAppAccount.loadBalances();
|
|
1973
|
+
this._accounts.set(dAppAccount.getAccountStoreKey(), dAppAccount);
|
|
1974
|
+
return dAppAccount;
|
|
1975
|
+
case (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).VAULT_ACCOUNT:
|
|
1976
|
+
// Create Vault account (purpose 1)
|
|
1977
|
+
let vaultAccountKey = (0, $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9)(masterKey, 1);
|
|
1978
|
+
const vaultAccount = new (0, $0b557605c0e99621$export$2e2bcd8739ae039)(1, nextIndex, (0, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9)(vaultAccountKey, nextIndex));
|
|
1979
|
+
await vaultAccount.loadBalances();
|
|
1980
|
+
this._accounts.set(vaultAccount.getAccountStoreKey(), vaultAccount);
|
|
1981
|
+
return vaultAccount;
|
|
1982
|
+
default:
|
|
1983
|
+
// Create default NEXA account with receive and change addresses
|
|
1984
|
+
let nexaAccountKey = (0, $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9)(masterKey, nextIndex);
|
|
1985
|
+
const nexaAccountIndexes = {
|
|
1986
|
+
rIndex: 0,
|
|
1987
|
+
cIndex: 0
|
|
1988
|
+
};
|
|
1989
|
+
const nexaAccount = new (0, $1c49a4fffc97409b$export$2e2bcd8739ae039)(nextIndex, nexaAccountIndexes, (0, $0d59d2bcffd646c5$export$d6e8eb22902c6b88)(nexaAccountKey, nexaAccountIndexes.rIndex + 1, nexaAccountIndexes.rIndex + 20, nexaAccountIndexes.cIndex + 1, nexaAccountIndexes.cIndex + 20));
|
|
1990
|
+
await nexaAccount.loadBalances();
|
|
1991
|
+
this._accounts.set(nexaAccount.getAccountStoreKey(), nexaAccount);
|
|
1992
|
+
return nexaAccount;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Finds the private key associated with a given address across all accounts
|
|
1997
|
+
* @param address The address to search for
|
|
1998
|
+
* @returns The AddressKey containing the private key, or null if not found
|
|
1999
|
+
*/ findKeyForAddress(address) {
|
|
2000
|
+
// Search through all accounts
|
|
2001
|
+
for (const [_, account] of this._accounts.entries()){
|
|
2002
|
+
// Combine receive and change keys for this account
|
|
2003
|
+
const allKeys = account.accountKeys.receiveKeys.concat(account.accountKeys.changeKeys);
|
|
2004
|
+
// Check each key for a matching address
|
|
2005
|
+
for (const key of allKeys){
|
|
2006
|
+
if (key.address == address) return key;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return null;
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* Imports an existing account into the store
|
|
2013
|
+
* @param accountData The account data to import
|
|
2014
|
+
* @throws Error if an account with the same key already exists
|
|
2015
|
+
*/ importAccount(accountData) {
|
|
2016
|
+
let index = accountData.getAccountStoreKey();
|
|
2017
|
+
if (this._accounts.get(index)) throw Error('Account already exists!');
|
|
2018
|
+
this._accounts.set(String(index), accountData);
|
|
2019
|
+
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Exports account data by index
|
|
2022
|
+
* @param accountIndex The account index to export
|
|
2023
|
+
* @returns The account data
|
|
2024
|
+
* @throws Error if the account doesn't exist
|
|
2025
|
+
*/ exportAccount(accountIndex) {
|
|
2026
|
+
if (!this._accounts.get(accountIndex)) throw Error('Cannot find account!');
|
|
2027
|
+
return this._accounts.get(accountIndex);
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* Removes an account from the store
|
|
2031
|
+
* @param accountIndex The account index to remove
|
|
2032
|
+
* @throws Error if the account doesn't exist
|
|
2033
|
+
*/ removeAccount(accountIndex) {
|
|
2034
|
+
if (!this._accounts.get(accountIndex)) throw Error('Cannot find account!');
|
|
2035
|
+
this._accounts.delete(accountIndex);
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* Returns all accounts in the store
|
|
2039
|
+
* @returns Map of account store keys to BaseAccount objects
|
|
2040
|
+
*/ listAccounts() {
|
|
2041
|
+
return this._accounts;
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Retrieves a specific account by its index
|
|
2045
|
+
* @param index The account index to retrieve
|
|
2046
|
+
* @returns The account if found, undefined otherwise
|
|
2047
|
+
*/ getAccount(index) {
|
|
2048
|
+
return this._accounts.get(index);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
class $a635077caedb9044$export$2e2bcd8739ae039 {
|
|
2055
|
+
/**
|
|
2056
|
+
* Validate that a state condition is true
|
|
2057
|
+
*
|
|
2058
|
+
* @param condition - The condition to validate
|
|
2059
|
+
* @param message - Error message to throw if condition is false
|
|
2060
|
+
* @throws {Error} If condition is false
|
|
2061
|
+
*
|
|
2062
|
+
* @example
|
|
2063
|
+
* ```typescript
|
|
2064
|
+
* ValidationUtils.validateState(wallet.isInitialized, 'Wallet must be initialized');
|
|
2065
|
+
* ```
|
|
2066
|
+
*/ static validateState(condition, message) {
|
|
2067
|
+
if (!condition) throw new Error(`Invalid State: ${message}`);
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* Validate that an argument condition is true
|
|
2071
|
+
*
|
|
2072
|
+
* @param condition - The condition to validate
|
|
2073
|
+
* @param argumentName - Name of the argument being validated
|
|
2074
|
+
* @param message - Optional additional error message
|
|
2075
|
+
* @throws {Error} If condition is false
|
|
2076
|
+
*
|
|
2077
|
+
* @example
|
|
2078
|
+
* ```typescript
|
|
2079
|
+
* ValidationUtils.validateArgument(
|
|
2080
|
+
* typeof amount === 'number',
|
|
2081
|
+
* 'amount',
|
|
2082
|
+
* 'must be a number'
|
|
2083
|
+
* );
|
|
2084
|
+
* ```
|
|
2085
|
+
*/ static validateArgument(condition, argumentName, message = "") {
|
|
2086
|
+
if (!condition) throw new Error(`Invalid Argument: ${argumentName}. ${message}`);
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Validate that an argument is of the expected type
|
|
2090
|
+
*
|
|
2091
|
+
* @param argument - The argument to validate
|
|
2092
|
+
* @param type - Expected type (string name or constructor function)
|
|
2093
|
+
* @param argumentName - Name of the argument being validated
|
|
2094
|
+
* @throws {TypeError} If argument is not of expected type
|
|
2095
|
+
*
|
|
2096
|
+
* @example
|
|
2097
|
+
* ```typescript
|
|
2098
|
+
* ValidationUtils.validateArgumentType(buffer, 'Buffer', 'data');
|
|
2099
|
+
* ValidationUtils.validateArgumentType(wallet, Wallet, 'wallet');
|
|
2100
|
+
* ValidationUtils.validateArgumentType(amount, 'number', 'amount');
|
|
2101
|
+
* ```
|
|
2102
|
+
*/ static validateArgumentType(argument, type, argumentName) {
|
|
2103
|
+
argumentName = argumentName || '(unknown name)';
|
|
2104
|
+
if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(type)) {
|
|
2105
|
+
if (type === 'Buffer') {
|
|
2106
|
+
if (!Buffer.isBuffer(argument)) throw new TypeError(`Invalid Argument for ${argumentName}, expected ${type} but got ${typeof argument}`);
|
|
2107
|
+
} else if (typeof argument !== type) throw new TypeError(`Invalid Argument for ${argumentName}, expected ${type} but got ${typeof argument}`);
|
|
2108
|
+
} else {
|
|
2109
|
+
if (!(argument instanceof type)) throw new TypeError(`Invalid Argument for ${argumentName}, expected ${type} but got ${typeof argument}`);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
class $b76d3bd5024ccfc0$export$2e2bcd8739ae039 {
|
|
2116
|
+
/**
|
|
2117
|
+
* Creates a new Wallet instance
|
|
2118
|
+
*
|
|
2119
|
+
* @param data - Optional wallet data:
|
|
2120
|
+
* - undefined: Generate new random seed phrase
|
|
2121
|
+
* - string: Use as BIP39 seed phrase
|
|
2122
|
+
* - HDPrivateKey: Use as master key directly
|
|
2123
|
+
* @param network - Network name ('mainnet', 'testnet', 'regtest'). Defaults to 'mainnet'
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* ```typescript
|
|
2127
|
+
* // Create new wallet with random seed
|
|
2128
|
+
* const wallet = new Wallet();
|
|
2129
|
+
*
|
|
2130
|
+
* // Create from seed phrase
|
|
2131
|
+
* const wallet = new Wallet('abandon abandon abandon...');
|
|
2132
|
+
*
|
|
2133
|
+
* // Create from master key
|
|
2134
|
+
* const masterKey = HDPrivateKey.fromString('xprv...');
|
|
2135
|
+
* const wallet = new Wallet(masterKey);
|
|
2136
|
+
*
|
|
2137
|
+
* // Create on testnet
|
|
2138
|
+
* const wallet = new Wallet(undefined, 'testnet');
|
|
2139
|
+
* ```
|
|
2140
|
+
*/ constructor(data, network){
|
|
2141
|
+
this._network = (0, $l50U0$libnexats.Networks).get(network) ?? (0, $l50U0$libnexats.Networks).mainnet;
|
|
2142
|
+
this._accountStore = new (0, $7fcf3b163a95e69a$export$2e2bcd8739ae039)();
|
|
2143
|
+
if ((0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(data)) {
|
|
2144
|
+
this.phrase = $l50U0$bip39.generateMnemonic(128, undefined, $l50U0$bip39.wordlists.english);
|
|
2145
|
+
const seed = $l50U0$bip39.mnemonicToSeedSync(this.phrase, '');
|
|
2146
|
+
const masterKey = (0, $l50U0$libnexats.HDPrivateKey).fromSeed(seed, this._network ?? (0, $l50U0$libnexats.Networks).mainnet);
|
|
2147
|
+
this.masterKey = masterKey.deriveChild(44, true).deriveChild(29223, true);
|
|
2148
|
+
} else if (data instanceof (0, $l50U0$libnexats.HDPrivateKey)) this.masterKey = data;
|
|
2149
|
+
else if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(data)) {
|
|
2150
|
+
this.phrase = data;
|
|
2151
|
+
const seed = $l50U0$bip39.mnemonicToSeedSync(this.phrase, '');
|
|
2152
|
+
const masterKey = (0, $l50U0$libnexats.HDPrivateKey).fromSeed(seed, this._network ?? (0, $l50U0$libnexats.Networks).mainnet);
|
|
2153
|
+
this.masterKey = masterKey.deriveChild(44, true).deriveChild(29223, true);
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
/**
|
|
2157
|
+
* Create a new wallet with a randomly generated seed phrase
|
|
2158
|
+
*
|
|
2159
|
+
* This is the recommended way to create a new wallet for first-time users.
|
|
2160
|
+
* The generated seed phrase should be securely stored by the user.
|
|
2161
|
+
*
|
|
2162
|
+
* @returns A new Wallet instance with a random 12-word seed phrase
|
|
2163
|
+
*
|
|
2164
|
+
* @example
|
|
2165
|
+
* ```typescript
|
|
2166
|
+
* const wallet = Wallet.create();
|
|
2167
|
+
* console.log(wallet.export().phrase); // Store this securely!
|
|
2168
|
+
* ```
|
|
2169
|
+
*/ static create() {
|
|
2170
|
+
return new $b76d3bd5024ccfc0$export$2e2bcd8739ae039();
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Create a wallet from an existing BIP39 seed phrase
|
|
2174
|
+
*
|
|
2175
|
+
* Use this method to restore a wallet from a previously generated seed phrase.
|
|
2176
|
+
* The seed phrase should be a valid BIP39 mnemonic.
|
|
2177
|
+
*
|
|
2178
|
+
* @param phrase - The BIP39 seed phrase (12 or 24 words)
|
|
2179
|
+
* @param network - Optional network name ('mainnet', 'testnet', 'regtest')
|
|
2180
|
+
* @returns A new Wallet instance restored from the seed phrase
|
|
2181
|
+
* @throws {Error} If the seed phrase is invalid or not provided
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```typescript
|
|
2185
|
+
* const wallet = Wallet.fromSeedPhrase(
|
|
2186
|
+
* 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
2187
|
+
* 'testnet'
|
|
2188
|
+
* );
|
|
2189
|
+
* ```
|
|
2190
|
+
*/ static fromSeedPhrase(phrase, network) {
|
|
2191
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $90290c84737dbb50$export$2e2bcd8739ae039)(phrase), 'seedphrase must be provided');
|
|
2192
|
+
return new $b76d3bd5024ccfc0$export$2e2bcd8739ae039(phrase, network);
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Create a wallet from an extended private key (xpriv)
|
|
2196
|
+
*
|
|
2197
|
+
* Use this method to create a wallet from a master private key in extended format.
|
|
2198
|
+
* This is useful for advanced users who want to use a specific key derivation.
|
|
2199
|
+
*
|
|
2200
|
+
* @param xpriv - The extended private key string (starts with 'xprv')
|
|
2201
|
+
* @param network - Optional network name ('mainnet', 'testnet', 'regtest')
|
|
2202
|
+
* @returns A new Wallet instance using the provided master key
|
|
2203
|
+
* @throws {Error} If the private key is invalid or not provided
|
|
2204
|
+
*
|
|
2205
|
+
* @example
|
|
2206
|
+
* ```typescript
|
|
2207
|
+
* const wallet = Wallet.fromXpriv(
|
|
2208
|
+
* 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
|
2209
|
+
* );
|
|
2210
|
+
* ```
|
|
2211
|
+
*/ static fromXpriv(xpriv, network) {
|
|
2212
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $90290c84737dbb50$export$2e2bcd8739ae039)(xpriv), 'private key must be provided');
|
|
2213
|
+
const masterKey = (0, $l50U0$libnexats.HDPrivateKey).fromString(xpriv);
|
|
2214
|
+
return new $b76d3bd5024ccfc0$export$2e2bcd8739ae039(masterKey, network);
|
|
2215
|
+
}
|
|
2216
|
+
/**
|
|
2217
|
+
* Initialize the wallet by discovering accounts and loading balances
|
|
2218
|
+
*
|
|
2219
|
+
* This method performs account discovery using the BIP44 derivation path
|
|
2220
|
+
* and scans for existing accounts with transaction history or balances.
|
|
2221
|
+
* Must be called before using the wallet's accounts.
|
|
2222
|
+
*
|
|
2223
|
+
* @returns Promise that resolves when initialization is complete
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
2226
|
+
* ```typescript
|
|
2227
|
+
* const wallet = Wallet.fromSeedPhrase('your seed phrase');
|
|
2228
|
+
* await wallet.initialize();
|
|
2229
|
+
*
|
|
2230
|
+
* // Now you can access discovered accounts
|
|
2231
|
+
* const accounts = wallet.accountStore.listAccounts();
|
|
2232
|
+
* ```
|
|
2233
|
+
*/ async initialize() {
|
|
2234
|
+
const walletAccounts = await (0, $0d59d2bcffd646c5$export$4e4f91181d6bd31c)(this.masterKey);
|
|
2235
|
+
for (const account of walletAccounts)this._accountStore.importAccount(account);
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Create a new transaction builder for this wallet
|
|
2239
|
+
*
|
|
2240
|
+
* @param fromAccount - The account to send the transaction from
|
|
2241
|
+
* @param x - Optional existing transaction data:
|
|
2242
|
+
* - TransactionBuilder: Use existing transaction builder
|
|
2243
|
+
* - string: Parse from hex string
|
|
2244
|
+
* - Buffer: Parse from binary buffer
|
|
2245
|
+
* - undefined: Create new empty transaction
|
|
2246
|
+
* @returns A new WalletTransactionCreator instance
|
|
2247
|
+
*
|
|
2248
|
+
* @example
|
|
2249
|
+
* ```typescript
|
|
2250
|
+
* const account = wallet.accountStore.getAccount(0);
|
|
2251
|
+
* const tx = wallet.newTransaction(account)
|
|
2252
|
+
* .to('nexa:address', 1000000) // 1 NEXA
|
|
2253
|
+
* .sign();
|
|
2254
|
+
*
|
|
2255
|
+
* // Or from existing transaction hex
|
|
2256
|
+
* const tx = wallet.newTransaction(account, 'raw_tx_hex')
|
|
2257
|
+
* .sign();
|
|
2258
|
+
* ```
|
|
2259
|
+
*/ newTransaction(fromAccount, x) {
|
|
2260
|
+
let tx;
|
|
2261
|
+
if (x instanceof (0, $l50U0$libnexats.TransactionBuilder)) tx = new (0, $e1896e59040fa3c5$export$2e2bcd8739ae039)(fromAccount, x);
|
|
2262
|
+
else if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(x)) tx = new (0, $e1896e59040fa3c5$export$2e2bcd8739ae039)(fromAccount).parseTxHex(x);
|
|
2263
|
+
else if ((0, $kNPhA.default)(x) && !(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(x)) tx = new (0, $e1896e59040fa3c5$export$2e2bcd8739ae039)(fromAccount).parseTxBuffer(x);
|
|
2264
|
+
else tx = new (0, $e1896e59040fa3c5$export$2e2bcd8739ae039)(fromAccount);
|
|
2265
|
+
return tx.onNetwork(this._network);
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Create a new account for this wallet
|
|
2269
|
+
*
|
|
2270
|
+
* @param accountType - The type of account to create:
|
|
2271
|
+
* - 'DefaultAccount': Standard account for general use
|
|
2272
|
+
* - 'VaultAccount': Secured account with additional protection
|
|
2273
|
+
* - 'DappAccount': Account optimized for dApp interactions
|
|
2274
|
+
* @returns Promise that resolves to the newly created account
|
|
2275
|
+
*
|
|
2276
|
+
* @example
|
|
2277
|
+
* ```typescript
|
|
2278
|
+
* const defaultAccount = await wallet.newAccount('DefaultAccount');
|
|
2279
|
+
* const vaultAccount = await wallet.newAccount('VaultAccount');
|
|
2280
|
+
* const dappAccount = await wallet.newAccount('DappAccount');
|
|
2281
|
+
* ```
|
|
2282
|
+
*/ async newAccount(accountType) {
|
|
2283
|
+
return await this.accountStore.createAccount(accountType, this.masterKey);
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Broadcast a signed transaction to the Nexa network
|
|
2287
|
+
*
|
|
2288
|
+
* @param transaction - The signed transaction in hex format
|
|
2289
|
+
* @returns Promise that resolves to the transaction ID (txid)
|
|
2290
|
+
* @throws {Error} If the transaction is invalid or broadcast fails
|
|
2291
|
+
*
|
|
2292
|
+
* @example
|
|
2293
|
+
* ```typescript
|
|
2294
|
+
* const tx = wallet.newTransaction(account)
|
|
2295
|
+
* .to('nexa:address', 1000000)
|
|
2296
|
+
* .sign();
|
|
2297
|
+
*
|
|
2298
|
+
* const txId = await wallet.sendTransaction(tx.toHex());
|
|
2299
|
+
* console.log('Transaction sent:', txId);
|
|
2300
|
+
* ```
|
|
2301
|
+
*/ async sendTransaction(transaction) {
|
|
2302
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $90290c84737dbb50$export$2e2bcd8739ae039)(transaction), 'transaction must be present and valid');
|
|
2303
|
+
return (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).broadcast(transaction);
|
|
2304
|
+
}
|
|
2305
|
+
/**
|
|
2306
|
+
* Sign a message using a specific address from this wallet
|
|
2307
|
+
*
|
|
2308
|
+
* The message is signed using the private key associated with the given address.
|
|
2309
|
+
* This can be used for authentication or to prove ownership of an address.
|
|
2310
|
+
*
|
|
2311
|
+
* @param message - The message to sign
|
|
2312
|
+
* @param addressToUse - The address whose private key should sign the message
|
|
2313
|
+
* @returns The signature as a base64-encoded string
|
|
2314
|
+
* @throws {Error} If the address is not owned by this wallet
|
|
2315
|
+
*
|
|
2316
|
+
* @example
|
|
2317
|
+
* ```typescript
|
|
2318
|
+
* const account = wallet.accountStore.getAccount(0);
|
|
2319
|
+
* const address = account.getReceiveAddress();
|
|
2320
|
+
* const signature = wallet.signMessage('Hello World', address);
|
|
2321
|
+
* ```
|
|
2322
|
+
*/ signMessage(message, addressToUse) {
|
|
2323
|
+
let msg = new (0, $l50U0$libnexats.Message)(message);
|
|
2324
|
+
const addressKey = this.accountStore.findKeyForAddress(addressToUse);
|
|
2325
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(addressKey), "You dont own this private key");
|
|
2326
|
+
return msg.sign(addressKey?.key.privateKey);
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Verify a message signature against an address
|
|
2330
|
+
*
|
|
2331
|
+
* This method can verify signatures created by any address, not just addresses
|
|
2332
|
+
* owned by this wallet. It's useful for verifying messages from other parties.
|
|
2333
|
+
*
|
|
2334
|
+
* @param message - The original message that was signed
|
|
2335
|
+
* @param signature - The signature to verify (base64-encoded)
|
|
2336
|
+
* @param address - The address that supposedly signed the message
|
|
2337
|
+
* @returns true if the signature is valid, false otherwise
|
|
2338
|
+
* @throws {Error} If any parameters are missing or invalid
|
|
2339
|
+
*
|
|
2340
|
+
* @example
|
|
2341
|
+
* ```typescript
|
|
2342
|
+
* const isValid = wallet.verifyMessage(
|
|
2343
|
+
* 'Hello World',
|
|
2344
|
+
* 'signature_string',
|
|
2345
|
+
* 'nexa:address'
|
|
2346
|
+
* );
|
|
2347
|
+
* console.log('Signature valid:', isValid);
|
|
2348
|
+
* ```
|
|
2349
|
+
*/ verifyMessage(message, signature, address) {
|
|
2350
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(message), 'message is required');
|
|
2351
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(signature), 'signature is required');
|
|
2352
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument(!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(address), 'address is required ');
|
|
2353
|
+
let msg = new (0, $l50U0$libnexats.Message)(message);
|
|
2354
|
+
const addressKey = this.accountStore.findKeyForAddress(address);
|
|
2355
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(addressKey), "You dont own this private key");
|
|
2356
|
+
return msg.verify(address, signature);
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Export the wallet data for backup or storage
|
|
2360
|
+
*
|
|
2361
|
+
* Returns an object containing the wallet's seed phrase, master key, and accounts.
|
|
2362
|
+
* This data can be used to restore the wallet later. The seed phrase should be
|
|
2363
|
+
* stored securely as it provides full access to the wallet.
|
|
2364
|
+
*
|
|
2365
|
+
* @returns Object containing wallet data
|
|
2366
|
+
* @property {string} phrase - The BIP39 seed phrase (if available)
|
|
2367
|
+
* @property {HDPrivateKey} masterKey - The master private key
|
|
2368
|
+
* @property {BaseAccount[]} accounts - Array of discovered accounts
|
|
2369
|
+
*
|
|
2370
|
+
* @example
|
|
2371
|
+
* ```typescript
|
|
2372
|
+
* const walletData = wallet.export();
|
|
2373
|
+
*
|
|
2374
|
+
* // Store the seed phrase securely
|
|
2375
|
+
* const seedPhrase = walletData.phrase;
|
|
2376
|
+
*
|
|
2377
|
+
* // Later, restore the wallet
|
|
2378
|
+
* const restoredWallet = Wallet.fromSeedPhrase(seedPhrase);
|
|
2379
|
+
* ```
|
|
2380
|
+
*/ export() {
|
|
2381
|
+
return {
|
|
2382
|
+
phrase: this.phrase,
|
|
2383
|
+
masterKey: this.masterKey,
|
|
2384
|
+
accounts: this._accountStore.listAccounts(),
|
|
2385
|
+
accountIndexes: this.accountStore.listAccounts().keys()
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
/**
|
|
2389
|
+
* Get the account store for managing wallet accounts
|
|
2390
|
+
*
|
|
2391
|
+
* The account store provides methods to create, import, and manage accounts
|
|
2392
|
+
* within this wallet. Each account has its own set of addresses and keys.
|
|
2393
|
+
*
|
|
2394
|
+
* @returns The wallet's account store
|
|
2395
|
+
*
|
|
2396
|
+
* @example
|
|
2397
|
+
* ```typescript
|
|
2398
|
+
* const accountStore = wallet.accountStore;
|
|
2399
|
+
* const accounts = accountStore.listAccounts();
|
|
2400
|
+
* const firstAccount = accountStore.getAccount(0);
|
|
2401
|
+
* ```
|
|
2402
|
+
*/ get accountStore() {
|
|
2403
|
+
return this._accountStore;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Get the network this wallet is operating on
|
|
2407
|
+
*
|
|
2408
|
+
* @returns The network object (mainnet, testnet, or regtest)
|
|
2409
|
+
*
|
|
2410
|
+
* @example
|
|
2411
|
+
* ```typescript
|
|
2412
|
+
* const network = wallet.network;
|
|
2413
|
+
* console.log('Network:', network.name);
|
|
2414
|
+
* ```
|
|
2415
|
+
*/ get network() {
|
|
2416
|
+
return this._network;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
const $52632971edbdb934$var$MAX_INPUTS_OUTPUTS = 250;
|
|
2429
|
+
async function $52632971edbdb934$export$20e004915450ed44(txBuilder, addresses, totalTxValue, options) {
|
|
2430
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(addresses)) throw new Error("Not enough Nexa balance.");
|
|
2431
|
+
let usedAddresses = new Set();
|
|
2432
|
+
let origAmount = options.isConsolidate ? 0 : Number(totalTxValue);
|
|
2433
|
+
for (let item of addresses){
|
|
2434
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(item.address);
|
|
2435
|
+
for (let utxo of utxos){
|
|
2436
|
+
let input = {
|
|
2437
|
+
outpoint: utxo.outpoint_hash,
|
|
2438
|
+
address: item.address,
|
|
2439
|
+
satoshis: utxo.value,
|
|
2440
|
+
templateData: options.templateData
|
|
2441
|
+
};
|
|
2442
|
+
txBuilder.from(input);
|
|
2443
|
+
if (!usedAddresses.has(item.address)) usedAddresses.add(item.address);
|
|
2444
|
+
if (options.isConsolidate) {
|
|
2445
|
+
// need to handle change
|
|
2446
|
+
txBuilder.change(options.toChange ?? item.address);
|
|
2447
|
+
if (txBuilder.transaction.inputs.length > $52632971edbdb934$var$MAX_INPUTS_OUTPUTS) return Array.from(usedAddresses.values());
|
|
2448
|
+
} else {
|
|
2449
|
+
let tx = txBuilder.transaction;
|
|
2450
|
+
if (tx.inputs.length > $52632971edbdb934$var$MAX_INPUTS_OUTPUTS) throw new Error("Too many inputs. Consider consolidate transactions or reduce the send amount.");
|
|
2451
|
+
let unspent = tx.getUnspentValue();
|
|
2452
|
+
if (unspent < 0n) continue;
|
|
2453
|
+
if (unspent == 0n && options.feeFromAmount) {
|
|
2454
|
+
let txFee = tx.estimateRequiredFee();
|
|
2455
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
2456
|
+
return Array.from(usedAddresses.values());
|
|
2457
|
+
}
|
|
2458
|
+
txBuilder.change(options.toChange ?? item.address);
|
|
2459
|
+
if (options.feeFromAmount) {
|
|
2460
|
+
let hasChange = tx.getChangeOutput();
|
|
2461
|
+
let txFee = tx.estimateRequiredFee();
|
|
2462
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
2463
|
+
// edge case where change added after update
|
|
2464
|
+
if (!hasChange && tx.getChangeOutput()) {
|
|
2465
|
+
txFee = tx.estimateRequiredFee();
|
|
2466
|
+
tx.updateOutputAmount(0, origAmount - txFee);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
// check again after change output manipulation
|
|
2470
|
+
if (tx.getUnspentValue() < tx.estimateRequiredFee()) continue;
|
|
2471
|
+
return Array.from(usedAddresses.values());
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
if (options.isConsolidate) {
|
|
2476
|
+
if (usedAddresses.size > 0) return Array.from(usedAddresses.values());
|
|
2477
|
+
throw new Error("Not enough Nexa balance.");
|
|
2478
|
+
}
|
|
2479
|
+
let err = {
|
|
2480
|
+
errorMsg: "Not enough Nexa balance.",
|
|
2481
|
+
amount: (0, $l50U0$libnexats.UnitUtils).formatNEXA(Number(totalTxValue)),
|
|
2482
|
+
fee: (0, $l50U0$libnexats.UnitUtils).formatNEXA(txBuilder.transaction.estimateRequiredFee())
|
|
2483
|
+
};
|
|
2484
|
+
throw new Error(JSON.stringify(err));
|
|
2485
|
+
}
|
|
2486
|
+
async function $52632971edbdb934$export$49bc96b87058cba4(txBuilder, addresses, token, outTokenAmount) {
|
|
2487
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(addresses)) throw new Error("Not enough token balance.");
|
|
2488
|
+
let usedKeys = new Set();
|
|
2489
|
+
let inTokenAmount = 0n;
|
|
2490
|
+
for (let item of addresses){
|
|
2491
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, token);
|
|
2492
|
+
for (let utxo of utxos){
|
|
2493
|
+
if (utxo.token_amount < 0) continue;
|
|
2494
|
+
txBuilder.from({
|
|
2495
|
+
outpoint: utxo.outpoint_hash,
|
|
2496
|
+
address: item.address,
|
|
2497
|
+
satoshis: utxo.value,
|
|
2498
|
+
groupId: utxo.group,
|
|
2499
|
+
groupAmount: BigInt(utxo.token_amount)
|
|
2500
|
+
});
|
|
2501
|
+
inTokenAmount = inTokenAmount + BigInt(utxo.token_amount);
|
|
2502
|
+
if (!usedKeys.has(item.address)) usedKeys.add(item.address);
|
|
2503
|
+
if (inTokenAmount > (0, $bc5ca2c06b1affa3$export$8ba128bc85947a2a)) throw new Error("Token inputs exceeded max amount. Consider sending in small chunks");
|
|
2504
|
+
if (txBuilder.transaction.inputs.length > $52632971edbdb934$var$MAX_INPUTS_OUTPUTS) throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
|
|
2505
|
+
if (inTokenAmount == outTokenAmount) return Array.from(usedKeys.values());
|
|
2506
|
+
if (inTokenAmount > outTokenAmount) {
|
|
2507
|
+
// change
|
|
2508
|
+
txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, inTokenAmount - outTokenAmount);
|
|
2509
|
+
return Array.from(usedKeys.values());
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
throw new Error("Not enough token balance");
|
|
2514
|
+
}
|
|
2515
|
+
async function $52632971edbdb934$export$74e83de914f372c5(txBuilder, addresses, opReturnData, network) {
|
|
2516
|
+
let outpoint = '', idHex = '';
|
|
2517
|
+
let usedKeys = [];
|
|
2518
|
+
for (let item of addresses){
|
|
2519
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(item.address);
|
|
2520
|
+
for (let utxo of utxos){
|
|
2521
|
+
txBuilder.from({
|
|
2522
|
+
outpoint: utxo.outpoint_hash,
|
|
2523
|
+
address: item.address,
|
|
2524
|
+
satoshis: utxo.value
|
|
2525
|
+
});
|
|
2526
|
+
if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(outpoint)) {
|
|
2527
|
+
outpoint = utxo.outpoint_hash;
|
|
2528
|
+
let id = (0, $l50U0$libnexats.GroupToken).findGroupId(Buffer.from(outpoint, 'hex'), Buffer.from(opReturnData, 'hex'), (0, $l50U0$libnexats.GroupToken).authFlags.ACTIVE_FLAG_BITS);
|
|
2529
|
+
const groupId = new (0, $l50U0$libnexats.Address)(id.hashBuffer, network, (0, $l50U0$libnexats.AddressType).GroupIdAddress).toString();
|
|
2530
|
+
txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, groupId, (0, $l50U0$libnexats.GroupToken).authFlags.ACTIVE_FLAG_BITS | id.nonce);
|
|
2531
|
+
idHex = id.hashBuffer.toString('hex');
|
|
2532
|
+
usedKeys.push(item.address);
|
|
2533
|
+
return usedKeys;
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
throw new Error("Not enough Nexa balance.");
|
|
2538
|
+
}
|
|
2539
|
+
async function $52632971edbdb934$export$1eb54f2f084fd3c6(txBuilder, addresses, outpoint) {
|
|
2540
|
+
let utxo = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getUtxo(outpoint);
|
|
2541
|
+
let address = utxo.addresses[0];
|
|
2542
|
+
txBuilder.from({
|
|
2543
|
+
outpoint: outpoint,
|
|
2544
|
+
address: address,
|
|
2545
|
+
satoshis: utxo.amount
|
|
2546
|
+
});
|
|
2547
|
+
let addrKey = addresses.find((k)=>k.address === address);
|
|
2548
|
+
if (!addrKey) throw new Error('UTXO associated key not found in the wallet');
|
|
2549
|
+
return [
|
|
2550
|
+
addrKey.address
|
|
2551
|
+
];
|
|
2552
|
+
}
|
|
2553
|
+
async function $52632971edbdb934$export$d7c9c386067a6463(txBuilder, addresses, token, perm, subgroup = '') {
|
|
2554
|
+
for (let item of addresses){
|
|
2555
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, token);
|
|
2556
|
+
for (let utxo of utxos){
|
|
2557
|
+
if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) continue;
|
|
2558
|
+
txBuilder.from({
|
|
2559
|
+
outpoint: utxo.outpoint_hash,
|
|
2560
|
+
address: item.address,
|
|
2561
|
+
satoshis: utxo.value
|
|
2562
|
+
});
|
|
2563
|
+
if (perm === 'subgroup') txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, subgroup, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount, false));
|
|
2564
|
+
// if renew flag included, we don't want to burn it
|
|
2565
|
+
if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
|
|
2566
|
+
return [
|
|
2567
|
+
item.address
|
|
2568
|
+
];
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
throw new Error("The requested authority not found");
|
|
2572
|
+
}
|
|
2573
|
+
async function $52632971edbdb934$export$5c44e04d8c04c292(txBuilder, addresses, token, perms, toAddr) {
|
|
2574
|
+
let usedAddresses = [];
|
|
2575
|
+
let reqiredPerms = new Set(perms);
|
|
2576
|
+
reqiredPerms.add('authorise');
|
|
2577
|
+
for (let item of addresses){
|
|
2578
|
+
let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, token);
|
|
2579
|
+
for (let utxo of utxos){
|
|
2580
|
+
if (utxo.token_amount > 0) continue;
|
|
2581
|
+
let found = false;
|
|
2582
|
+
for (let perm of reqiredPerms)if ((0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) {
|
|
2583
|
+
reqiredPerms.delete(perm);
|
|
2584
|
+
found = true;
|
|
2585
|
+
}
|
|
2586
|
+
if (!found) continue;
|
|
2587
|
+
txBuilder.from({
|
|
2588
|
+
outpoint: utxo.outpoint_hash,
|
|
2589
|
+
address: item.address,
|
|
2590
|
+
satoshis: utxo.value
|
|
2591
|
+
});
|
|
2592
|
+
usedAddresses.push(item.address);
|
|
2593
|
+
// duplicate
|
|
2594
|
+
txBuilder.to(toAddr != null ? toAddr : item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
|
|
2595
|
+
if (reqiredPerms.size === 0) return usedAddresses;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
throw new Error("The required authorities not found");
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
|
|
2603
|
+
|
|
2604
|
+
|
|
2605
|
+
class $2ce5b75d10954bb1$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$export$bba690fb5c12ba04) {
|
|
2606
|
+
/**
|
|
2607
|
+
* Creates a new WatchOnlyTransactionCreator
|
|
2608
|
+
* @param tx Optional existing transaction builder or transaction data
|
|
2609
|
+
*/ constructor(tx){
|
|
2610
|
+
super(tx), /** Addresses that need to be signed with (populated during transaction building) */ this._addressesToSignWith = [], /** Available addresses for input selection and change */ this._availableAddresses = [];
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* Sets the source addresses for transaction inputs
|
|
2614
|
+
* @param address Single address string, array of addresses, or WatchOnlyAddress objects
|
|
2615
|
+
* @returns This instance for chaining
|
|
2616
|
+
*/ from(address) {
|
|
2617
|
+
if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(address)) {
|
|
2618
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(address, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(address, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
2619
|
+
// Single address string
|
|
2620
|
+
this._availableAddresses.push({
|
|
2621
|
+
address: address
|
|
2622
|
+
});
|
|
2623
|
+
} else if (Array.isArray(address)) // Array of addresses or WatchOnlyAddress objects
|
|
2624
|
+
address.forEach((addr)=>{
|
|
2625
|
+
if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(addr)) {
|
|
2626
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(addr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(addr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
|
|
2627
|
+
// String address
|
|
2628
|
+
this._availableAddresses.push({
|
|
2629
|
+
address: addr
|
|
2630
|
+
});
|
|
2631
|
+
} else if (addr && typeof addr === 'object' && 'address' in addr) // WatchOnlyAddress object
|
|
2632
|
+
this._availableAddresses.push(addr);
|
|
2633
|
+
});
|
|
2634
|
+
else if (address.address != null) // Single WatchOnlyAddress object
|
|
2635
|
+
this._availableAddresses.push(address);
|
|
2636
|
+
return this;
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* Adds a token minting operation to the transaction
|
|
2640
|
+
* @param token Token ID to mint
|
|
2641
|
+
* @param amount Amount to mint
|
|
2642
|
+
* @param toAddr Destination address for minted tokens
|
|
2643
|
+
* @returns This instance for chaining
|
|
2644
|
+
*/ mint(token, amount, toAddr) {
|
|
2645
|
+
this.builder.push(async ()=>{
|
|
2646
|
+
this.tokenAction(toAddr, amount, token, 'mint');
|
|
2647
|
+
});
|
|
2648
|
+
return this;
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Adds a token melting operation to the transaction
|
|
2652
|
+
* @param token Token ID to melt
|
|
2653
|
+
* @param amount Amount to melt
|
|
2654
|
+
* @param toAddr Destination address for melted tokens
|
|
2655
|
+
* @returns This instance for chaining
|
|
2656
|
+
*/ melt(token, amount, toAddr) {
|
|
2657
|
+
this.builder.push(async ()=>{
|
|
2658
|
+
this.tokenAction(toAddr, amount, token, 'melt');
|
|
2659
|
+
});
|
|
2660
|
+
return this;
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Populates the transaction with inputs and outputs based on the configured actions.
|
|
2664
|
+
* Handles different token operations (mint, melt, group creation, etc.) and
|
|
2665
|
+
* populates NEXA inputs for transaction fees.
|
|
2666
|
+
* @returns This instance for chaining
|
|
2667
|
+
*/ populate() {
|
|
2668
|
+
this.builder.push(async ()=>{
|
|
2669
|
+
let tokenAddresses = [];
|
|
2670
|
+
let nexaAddresses = [];
|
|
2671
|
+
// Process token operations if any are configured
|
|
2672
|
+
if (this.tokens.size > 0) for (const tokenAction of this.tokens){
|
|
2673
|
+
if (tokenAction.action == 'mint' || tokenAction.action == 'melt') // Handle token minting/melting - requires authority
|
|
2674
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$d7c9c386067a6463)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.action));
|
|
2675
|
+
else if (tokenAction.action == 'group') // Handle group token creation
|
|
2676
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$74e83de914f372c5)(this.transactionBuilder, this._availableAddresses, tokenAction.token, this.network));
|
|
2677
|
+
else if (tokenAction.action == 'subgroup') // Handle subgroup token creation
|
|
2678
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$d7c9c386067a6463)(this.transactionBuilder, this._availableAddresses, tokenAction.parentToken, tokenAction.action, tokenAction.token));
|
|
2679
|
+
else if (tokenAction.action == 'renew') // Handle authority renewal
|
|
2680
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$5c44e04d8c04c292)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.extraData.perms, tokenAction.extraData?.address));
|
|
2681
|
+
else if (tokenAction.action == 'delete') // Handle authority deletion
|
|
2682
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$1eb54f2f084fd3c6)(this.transactionBuilder, this._availableAddresses, tokenAction.extraData.outpoint));
|
|
2683
|
+
else // Handle regular token transfers
|
|
2684
|
+
tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$49bc96b87058cba4)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.amount));
|
|
2685
|
+
// Accumulate addresses that need signing
|
|
2686
|
+
this._addressesToSignWith.concat(tokenAddresses);
|
|
2687
|
+
}
|
|
2688
|
+
// Populate NEXA inputs for transaction fees and change
|
|
2689
|
+
nexaAddresses = nexaAddresses.concat(await (0, $52632971edbdb934$export$20e004915450ed44)(this.transactionBuilder, this._availableAddresses, this.totalValue, this.txOptions));
|
|
2690
|
+
// Combine all addresses that need signing
|
|
2691
|
+
this._addressesToSignWith = tokenAddresses.concat(nexaAddresses);
|
|
2692
|
+
});
|
|
2693
|
+
return this;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Parse transaction from buffer (not implemented for watch-only)
|
|
2697
|
+
* @param tx Transaction buffer
|
|
2698
|
+
* @returns This instance for chaining
|
|
2699
|
+
* @throws Error indicating method not implemented
|
|
2700
|
+
*/ parseTxBuffer(tx) {
|
|
2701
|
+
this.builder.push(async ()=>{
|
|
2702
|
+
this.transactionBuilder = new (0, $l50U0$libnexats.TransactionBuilder)(tx);
|
|
2703
|
+
});
|
|
2704
|
+
return this;
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* Parse transaction from hex string (not implemented for watch-only)
|
|
2708
|
+
* @param tx Transaction hex string
|
|
2709
|
+
* @returns This instance for chaining
|
|
2710
|
+
* @throws Error indicating method not implemented
|
|
2711
|
+
*/ parseTxHex(tx) {
|
|
2712
|
+
this.builder.push(async ()=>{
|
|
2713
|
+
const txBuilder = new (0, $l50U0$libnexats.TransactionBuilder)(tx);
|
|
2714
|
+
const newTxBuilder = new (0, $l50U0$libnexats.TransactionBuilder)();
|
|
2715
|
+
const oldInputs = txBuilder.transaction.inputs;
|
|
2716
|
+
for (const input of oldInputs){
|
|
2717
|
+
const utxo = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getUtxo(input.outpoint.toString('hex'));
|
|
2718
|
+
newTxBuilder.from({
|
|
2719
|
+
outpoint: utxo.tx_hash,
|
|
2720
|
+
amount: utxo.amount,
|
|
2721
|
+
scriptPubKey: utxo.scriptpubkey
|
|
2722
|
+
});
|
|
2723
|
+
}
|
|
2724
|
+
newTxBuilder.transaction.outputs = txBuilder.transaction.outputs;
|
|
2725
|
+
this.transactionBuilder = newTxBuilder;
|
|
2726
|
+
});
|
|
2727
|
+
return this;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
|
|
2732
|
+
|
|
2733
|
+
|
|
2734
|
+
var $kNPhA = parcelRequire("kNPhA");/**
|
|
2735
|
+
* Checks if `value` is the
|
|
2736
|
+
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
2737
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
2738
|
+
*
|
|
2739
|
+
* @static
|
|
2740
|
+
* @memberOf _
|
|
2741
|
+
* @since 0.1.0
|
|
2742
|
+
* @category Lang
|
|
2743
|
+
* @param {*} value The value to check.
|
|
2744
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
2745
|
+
* @example
|
|
2746
|
+
*
|
|
2747
|
+
* _.isObject({});
|
|
2748
|
+
* // => true
|
|
2749
|
+
*
|
|
2750
|
+
* _.isObject([1, 2, 3]);
|
|
2751
|
+
* // => true
|
|
2752
|
+
*
|
|
2753
|
+
* _.isObject(_.noop);
|
|
2754
|
+
* // => true
|
|
2755
|
+
*
|
|
2756
|
+
* _.isObject(null);
|
|
2757
|
+
* // => false
|
|
2758
|
+
*/ function $fb85a1f0e1002a93$var$isObject(value) {
|
|
2759
|
+
var type = typeof value;
|
|
2760
|
+
return value != null && (type == 'object' || type == 'function');
|
|
2761
|
+
}
|
|
2762
|
+
var $fb85a1f0e1002a93$export$2e2bcd8739ae039 = $fb85a1f0e1002a93$var$isObject;
|
|
2763
|
+
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
|
|
2767
|
+
class $f4ad400261a08cba$export$2e2bcd8739ae039 {
|
|
2768
|
+
/**
|
|
2769
|
+
* Creates a new WatchOnlyWallet instance
|
|
2770
|
+
* @param addressesToWatch Array of addresses to monitor
|
|
2771
|
+
* @param network Optional network name (defaults to mainnet)
|
|
2772
|
+
* @throws Error if validation fails
|
|
2773
|
+
*/ constructor(addressesToWatch, network){
|
|
2774
|
+
// Validate network parameter
|
|
2775
|
+
if (network !== undefined && !(0, $90290c84737dbb50$export$2e2bcd8739ae039)(network)) throw new Error('Network must be a string');
|
|
2776
|
+
if (network !== undefined && (0, $90290c84737dbb50$export$2e2bcd8739ae039)(network)) {
|
|
2777
|
+
const n = (0, $l50U0$libnexats.Networks).get(network);
|
|
2778
|
+
if (n === undefined) throw new Error(`Invalid network: ${network}`);
|
|
2779
|
+
}
|
|
2780
|
+
this._network = (0, $l50U0$libnexats.Networks).get(network) ?? (0, $l50U0$libnexats.Networks).mainnet;
|
|
2781
|
+
// Validate addressesToWatch parameter
|
|
2782
|
+
this._addressesToWatch = this.validateAddressesToWatch(addressesToWatch);
|
|
2783
|
+
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Validates the addresses to watch array
|
|
2786
|
+
* @param addressesToWatch Array of addresses to validate
|
|
2787
|
+
* @returns Validated array of WatchOnlyAddress objects
|
|
2788
|
+
* @throws Error if validation fails
|
|
2789
|
+
*/ validateAddressesToWatch(addressesToWatch) {
|
|
2790
|
+
if (addressesToWatch === null || addressesToWatch === undefined) throw new Error('addresesToWatch is required');
|
|
2791
|
+
if (!(0, $36cc8c1055cfbf3b$export$2e2bcd8739ae039)(addressesToWatch)) throw new Error('addressesToWatch must be an array');
|
|
2792
|
+
// Check if array is not empty
|
|
2793
|
+
if (addressesToWatch.length === 0) throw new Error('addressesToWatch cannot be empty');
|
|
2794
|
+
// Validate each address object
|
|
2795
|
+
const validatedAddresses = [];
|
|
2796
|
+
for(let i = 0; i < addressesToWatch.length; i++){
|
|
2797
|
+
const addr = addressesToWatch[i];
|
|
2798
|
+
// Check if address is an object
|
|
2799
|
+
if (!(0, $fb85a1f0e1002a93$export$2e2bcd8739ae039)(addr) || (0, $36cc8c1055cfbf3b$export$2e2bcd8739ae039)(addr)) throw new Error(`addressesToWatch[${i}] must be an object`);
|
|
2800
|
+
// Check if address property exists and is a string
|
|
2801
|
+
if (!addr.hasOwnProperty('address') || !(0, $90290c84737dbb50$export$2e2bcd8739ae039)(addr.address)) throw new Error(`addressesToWatch[${i}].address must be a string`);
|
|
2802
|
+
// Check if address is not empty
|
|
2803
|
+
if (addr.address.trim() === '') throw new Error(`addressesToWatch[${i}].address cannot be empty`);
|
|
2804
|
+
// Validate address format
|
|
2805
|
+
if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(addr.address, this._network)) throw new Error(`addressesToWatch[${i}].address is not a valid NEXA address: ${addr.address}`);
|
|
2806
|
+
// Validate optional xPub property
|
|
2807
|
+
if (addr.xPub !== undefined && !(0, $fb85a1f0e1002a93$export$2e2bcd8739ae039)(addr.xPub)) throw new Error(`addressesToWatch[${i}].xPub must be a PublicKey object`);
|
|
2808
|
+
// Validate optional derivationPath property
|
|
2809
|
+
if (addr.derivationPath !== undefined && !(0, $90290c84737dbb50$export$2e2bcd8739ae039)(addr.derivationPath)) throw new Error(`addressesToWatch[${i}].derivationPath must be a string`);
|
|
2810
|
+
// Check for duplicate addresses
|
|
2811
|
+
const isDuplicate = validatedAddresses.some((existingAddr)=>existingAddr.address === addr.address);
|
|
2812
|
+
if (isDuplicate) throw new Error(`Duplicate address found: ${addr.address}`);
|
|
2813
|
+
validatedAddresses.push({
|
|
2814
|
+
address: addr.address.trim(),
|
|
2815
|
+
xPub: addr.xPub,
|
|
2816
|
+
derivationPath: addr.derivationPath
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
return validatedAddresses;
|
|
2820
|
+
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Creates a new transaction creator for this watch-only wallet
|
|
2823
|
+
* @param x Optional transaction data - can be a TransactionBuilder, hex string, or Buffer
|
|
2824
|
+
* @returns WatchOnlyTransactionCreator configured with wallet's addresses and network
|
|
2825
|
+
*/ newTransaction(x) {
|
|
2826
|
+
let tx;
|
|
2827
|
+
// Handle different input types for creating transactions
|
|
2828
|
+
if (x instanceof (0, $l50U0$libnexats.TransactionBuilder)) // Use existing TransactionBuilder instance
|
|
2829
|
+
tx = new (0, $2ce5b75d10954bb1$export$2e2bcd8739ae039)(x);
|
|
2830
|
+
else if ((0, $90290c84737dbb50$export$2e2bcd8739ae039)(x)) // Parse transaction from hex string
|
|
2831
|
+
tx = new (0, $2ce5b75d10954bb1$export$2e2bcd8739ae039)().parseTxHex(x);
|
|
2832
|
+
else if ((0, $kNPhA.default)(x) && !(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(x)) // Parse transaction from buffer
|
|
2833
|
+
tx = new (0, $2ce5b75d10954bb1$export$2e2bcd8739ae039)().parseTxBuffer(x);
|
|
2834
|
+
else // Create new empty transaction
|
|
2835
|
+
tx = new (0, $2ce5b75d10954bb1$export$2e2bcd8739ae039)();
|
|
2836
|
+
// Configure transaction with wallet's addresses and network
|
|
2837
|
+
return tx.from(this._addressesToWatch).onNetwork(this._network);
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Broadcasts a signed transaction to the network
|
|
2841
|
+
* @param transaction Hex-encoded signed transaction
|
|
2842
|
+
* @returns Promise resolving to transaction ID
|
|
2843
|
+
* @throws Error if transaction is invalid or broadcast fails
|
|
2844
|
+
*/ async sendTransaction(transaction) {
|
|
2845
|
+
(0, $a635077caedb9044$export$2e2bcd8739ae039).validateArgument((0, $90290c84737dbb50$export$2e2bcd8739ae039)(transaction), 'transaction must be present and valid');
|
|
2846
|
+
return (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).broadcast(transaction);
|
|
2847
|
+
}
|
|
2848
|
+
async subscribeToAddressNotifications(callback) {
|
|
2849
|
+
await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).subscribeToAddresses(this._addressesToWatch.map((addr)=>addr.address), callback);
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Gets the list of addresses being watched
|
|
2853
|
+
* @returns Array of watched addresses (copy to prevent mutation)
|
|
2854
|
+
*/ getWatchedAddresses() {
|
|
2855
|
+
return [
|
|
2856
|
+
...this._addressesToWatch
|
|
2857
|
+
];
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
|
|
2862
|
+
|
|
2863
|
+
|
|
2864
|
+
|
|
2865
|
+
|
|
2866
|
+
|
|
2867
|
+
|
|
2868
|
+
|
|
2869
|
+
|
|
2870
|
+
|
|
2871
|
+
/**
|
|
2872
|
+
* Guards against multiple instances of the wallet SDK being loaded.
|
|
2873
|
+
* This prevents conflicts and ensures only one version is active at a time.
|
|
2874
|
+
* @param version - The version string to check
|
|
2875
|
+
* @throws {Error} When multiple instances are detected
|
|
2876
|
+
*/ function $56b18ab116ff33bd$var$versionGuard(version) {
|
|
2877
|
+
if (version !== undefined) {
|
|
2878
|
+
let message = "More than one instance of Wallet SDKPlease make sure to require Wallet SDK and check that submodules do not also include their own Wallet SDK dependency.";
|
|
2879
|
+
throw new Error(message);
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
$56b18ab116ff33bd$var$versionGuard($parcel$global._walletSdk_ver);
|
|
2883
|
+
$parcel$global._walletSdk_ver = `v${0, $2dd241e44b9dc3c2$exports.version}`;
|
|
2884
|
+
/**
|
|
2885
|
+
* Wallet SDK - A TypeScript SDK for the Nexa blockchain
|
|
2886
|
+
*
|
|
2887
|
+
* This SDK provides comprehensive wallet functionality including:
|
|
2888
|
+
* - Creating and managing wallets from seed phrases or private keys
|
|
2889
|
+
* - Account management with different account types
|
|
2890
|
+
* - Transaction building and signing
|
|
2891
|
+
* - Token operations and management
|
|
2892
|
+
* - Message signing and verification
|
|
2893
|
+
*
|
|
2894
|
+
* @example
|
|
2895
|
+
* ```typescript
|
|
2896
|
+
* import { Wallet } from 'wallet-sdk-ts';
|
|
2897
|
+
*
|
|
2898
|
+
* // Create a new wallet
|
|
2899
|
+
* const wallet = Wallet.create();
|
|
2900
|
+
*
|
|
2901
|
+
* // Or restore from seed phrase
|
|
2902
|
+
* const wallet = Wallet.fromSeedPhrase('your seed phrase here');
|
|
2903
|
+
*
|
|
2904
|
+
* // Initialize and discover accounts
|
|
2905
|
+
* await wallet.initialize();
|
|
2906
|
+
* ```
|
|
2907
|
+
*/ const $56b18ab116ff33bd$var$walletSdk = {
|
|
2908
|
+
versionGuard: $56b18ab116ff33bd$var$versionGuard,
|
|
2909
|
+
version: `v${(0, $2dd241e44b9dc3c2$exports.version)}`,
|
|
2910
|
+
Wallet: $b76d3bd5024ccfc0$export$2e2bcd8739ae039
|
|
2911
|
+
};
|
|
2912
|
+
var $56b18ab116ff33bd$export$2e2bcd8739ae039 = $56b18ab116ff33bd$var$walletSdk;
|
|
2913
|
+
|
|
2914
|
+
|
|
2915
|
+
//# sourceMappingURL=index.js.map
|