ychapi 0.903.0 → 0.917.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt ADDED
@@ -0,0 +1,33 @@
1
+ ychapi:
2
+ Copyright Lynxline LLC, yshurik, 2019-2025,
3
+ Common Clause license https://commonsclause.com/
4
+
5
+ coinbin:
6
+ The MIT License (MIT)
7
+
8
+ Crypto-JS v2.5.4:
9
+ http://code.google.com/p/crypto-js/
10
+ (c) 2009-2012 by Jeff Mott. All rights reserved.
11
+ http://code.google.com/p/crypto-js/wiki/License
12
+
13
+ Basic Javascript Elliptic Curve implementation
14
+ Ported loosely from BouncyCastle's Java EC code
15
+ Only Fp curves implemented for now
16
+ Copyright Tom Wu, bitaddress.org BSD License.
17
+ http://www-cs-students.stanford.edu/~tjw/jsbn/LICENSE
18
+
19
+ jsbn.js:
20
+ Copyright (c) 2005 Tom Wu
21
+ All Rights Reserved.
22
+ See "LICENSE" for details.
23
+ Basic JavaScript BN library - subset useful for RSA encryption.
24
+
25
+ CryptoJS v3.1.2
26
+ code.google.com/p/crypto-js
27
+ (c) 2009-2013 by Jeff Mott. All rights reserved.
28
+ code.google.com/p/crypto-js/wiki/License
29
+ (c) 2012 by Cédric Mesnil. All rights reserved.
30
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
31
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
32
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
33
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # ychapi
package/dist/api.js ADDED
@@ -0,0 +1,823 @@
1
+
2
+ /*!
3
+ * Walrus-compatible exchange API js layer
4
+ *
5
+ * Copyright Lynxline LLC, yshurik, 2019-2025,
6
+ * Common Clause license https://commonsclause.com/
7
+ */
8
+
9
+ /*!
10
+ * STARTUP API
11
+ */
12
+
13
+ /*!
14
+ * Start the system.
15
+ * Initialize the data and start the sync.
16
+ * If there is valid non-expired jwt token in cookies,
17
+ * then user data is loaded from the server and login is not required
18
+ * (still login key is not initialized and user needs to be asked for the password on first api call)
19
+ *
20
+ * @param {object} callbacks
21
+ * @param {function} callbacks.on_sync_connecting() - show "syncing...", hide all visible data
22
+ * @param {function} callbacks.on_sync_connection_lost() - to indicate error from sync connection lost
23
+ * @param {function} callbacks.on_sync_connection_error(err) - report error from call_init() data initialization
24
+ * @param {function} callbacks.on_sync_data_init - data init is complete, can now fill gui with datas (get calls)
25
+ * @param {function} callbacks.on_sync_ready - data init and sync connection established - switch to "ready" state
26
+ * @param {function} callbacks.on_sync_message - handle sync messages
27
+ * @param {function} callbacks.on_sync_data_update - notify about data updates
28
+ * available data:
29
+ * - login()
30
+ * - logout()
31
+ * - market(market)
32
+ * - coininfo(coininfo)
33
+ * - buys(market_name, coina, coinb, buys), buys - see details in get_buys()
34
+ * - sells(market_name, coina, coinb, sells), sells - see details in get_sells()
35
+ * - trades(market_name, coina, coinb, trades), trades - see details in get_trades()
36
+ * - balance(coin, balance)
37
+ * - txouts(coin, txouts)
38
+ * - user_buys(market_name, coina, coinb, buys), buys - see details in get_buys()
39
+ * - user_sells(market_name, coina, coinb, sells), sells - see details in get_sells()
40
+ * - user_trades(market_name, coina, coinb, trades), trades - see details in get_trades()
41
+ * @returns null
42
+ */
43
+ ychapi.start = function(base_uri, callbacks) {
44
+ return ychapi._start(base_uri, callbacks);
45
+ };
46
+
47
+ /*!
48
+ * Request the server for initial data.
49
+ * It is called automatically on start().
50
+ * Use only for cases like logout or force data reload.
51
+ * @returns {Promise}
52
+ * - resolved (no data)
53
+ * - rejected with the error from the server
54
+ */
55
+ ychapi.call_init = async function() {
56
+ return ychapi._call_init();
57
+ };
58
+
59
+ /*!
60
+ * Process the login and initialize data same as start()/call_init().
61
+ * @param {string} login
62
+ * @param {string} pass
63
+ * @param {string} otp_code (2FA)
64
+ * @returns {Promise}
65
+ * - resolved (no data)
66
+ * - rejected with the error from the server
67
+ * @security
68
+ * - pass is not sent to the server
69
+ * - login/pass converted to uprvk/upubk and kept in memory (login key)
70
+ */
71
+ ychapi.call_login = async function(login, pass, otp_code) {
72
+ return ychapi._call_login(login, pass, otp_code);
73
+ };
74
+
75
+ /*!
76
+ * Logout: clear the user data and remove jwt from cookies.
77
+ * @returns null
78
+ */
79
+ ychapi.call_logout = async function() {
80
+ return ychapi._call_logout();
81
+ };
82
+
83
+ /*!
84
+ * GET DATA API
85
+ */
86
+
87
+ /*!
88
+ * Get the server-sorted-ordered list of coin names
89
+ * @returns {string[]}
90
+ */
91
+ ychapi.get_coin_names = function() {
92
+ return ychapi._get_coin_names();
93
+ };
94
+
95
+ /*!
96
+ * Get the coininfo by coin name
97
+ * @param {string} coin
98
+ * @returns {object}
99
+ */
100
+ ychapi.get_coin_info = function(coin) {
101
+ return ychapi._get_coin_info(coin);
102
+ };
103
+
104
+ /*!
105
+ * Get the server-sorted-ordered list of market groups names
106
+ * @returns {string[]}
107
+ */
108
+ ychapi.get_markets_groups_names = function() {
109
+ return ychapi._get_markets_groups_names();
110
+ };
111
+
112
+ /*!
113
+ * Get the market group by group name
114
+ * @param {string} group_name
115
+ * @returns {object}
116
+ */
117
+ ychapi.get_market_group = function(group_name) {
118
+ return ychapi._get_market_group(group_name);
119
+ };
120
+
121
+ /*!
122
+ * Get the market group by coinb (grouped by coinb)
123
+ * @param {string} coinb
124
+ * @returns {object}
125
+ */
126
+ ychapi.get_market_group_by_coinb = function(coinb) {
127
+ return ychapi._get_market_group_by_coinb(coinb);
128
+ };
129
+
130
+ /*!
131
+ * Get the list of markets names in a group
132
+ * @param {string} group_name
133
+ * @returns {string[]}
134
+ */
135
+ ychapi.get_markets_names_in_group = function(group_name) {
136
+ return ychapi._get_markets_names_in_group(group_name);
137
+ };
138
+
139
+ /*!
140
+ * Get the server-sorted-ordered list of markets names
141
+ * @returns {string[]}
142
+ */
143
+ ychapi.get_markets_names = function() {
144
+ return ychapi._get_markets_names();
145
+ };
146
+
147
+ /*!
148
+ * Get the market info by market name
149
+ * @param {string} market_name
150
+ * @returns {object}
151
+ */
152
+ ychapi.get_market_info = function(market_name) {
153
+ return ychapi._get_market_info(market_name);
154
+ };
155
+
156
+ /*!
157
+ * Get the coin balance by coin name
158
+ * @param {string} coin
159
+ * @returns {Balance object}
160
+ * {
161
+ * coin: {string} - coin name
162
+ * sum: {BigInt} - total amount
163
+ * free: {BigInt} - available amount for operations
164
+ * debit: {BigInt} - debit (others owe to the user)
165
+ * credit: {BigInt} - credit (the user owes to others)
166
+ * txouts: {BigInt} - txouts sum
167
+ * offtrade: {BigInt} - allocated txouts, (can not trade)
168
+ * orders: {BigInt} - orders sum
169
+ * ordersindebit: {BigInt} - orders in debit sum
170
+ * ordersintxouts: {BigInt} - orders in txouts sum
171
+ * deposits: {BigInt} - deposits in processing sum
172
+ * withdraws: {BigInt} - withdrawals in processing sum
173
+ * clearance: {BigInt} - processing now sum (a change on the blockchain)
174
+ * cycle: {number} - cycle number for peg-based coins (peg_t1)
175
+ * }
176
+ */
177
+ ychapi.get_coin_balance = function(coin) {
178
+ return ychapi._get_coin_balance(coin);
179
+ };
180
+
181
+ /*!
182
+ * Get the coin usd rate by coin name
183
+ * @param {string} coin
184
+ * @returns {number} one coin value estimate in usd
185
+ */
186
+ ychapi.get_coin_usd_rate = function(coin) {
187
+ return ychapi._get_coin_usd_rate(coin);
188
+ };
189
+
190
+ /*!
191
+ * Get deposits by coin name
192
+ * @param {string} coin
193
+ * @returns {object[]}
194
+ */
195
+ ychapi.get_coin_deposits = function(coin) {
196
+ return ychapi._get_coin_deposits(coin);
197
+ };
198
+
199
+ /*!
200
+ * Get withdrawals by coin name
201
+ * @param {string} coin
202
+ * @returns {object[]}
203
+ */
204
+ ychapi.get_coin_withdrawals = function(coin) {
205
+ return ychapi._get_coin_withdrawals(coin);
206
+ };
207
+
208
+ /*!
209
+ * Get txouts by coin name
210
+ * @param {string} coin
211
+ * @returns {object[]}
212
+ */
213
+ ychapi.get_coin_txouts = function(coin) {
214
+ return ychapi._get_coin_txouts(coin);
215
+ };
216
+
217
+ /*!
218
+ * REGISTRATION API
219
+ */
220
+
221
+ /*!
222
+ * Register a new user
223
+ * @param {string} login - the login
224
+ * @param {string} pass - the password
225
+ * @param {string} invitation_code - the invitation code
226
+ * @returns {Promise}
227
+ * - resolved (no data)
228
+ * - rejected with the error from the server
229
+ * @security
230
+ * - pass is not sent to the server
231
+ * - login/pass are not kept in memory
232
+ */
233
+ ychapi.call_register = async function(login, pass, invitation_code) {
234
+ return ychapi._call_register(login, pass, invitation_code);
235
+ };
236
+
237
+ /*!
238
+ * Get the email from the redeem code
239
+ * @param {string} redeem_code - the redeem code
240
+ * @returns {Promise}
241
+ * - resolved with the email {string} from the server,
242
+ * - rejected with the error from the server
243
+ */
244
+ ychapi.call_get_email_from_redeem = async function(redeem_code) {
245
+ return ychapi._call_get_email_from_redeem(redeem_code);
246
+ };
247
+
248
+ /*!
249
+ * Get the login from the registration code
250
+ * @param {string} code - the confirmation code from email
251
+ * @returns {Promise}
252
+ * - resolved with the login {string} from the server,
253
+ * - rejected with the error from the server
254
+ */
255
+ ychapi.call_get_registration_login = async function(code) {
256
+ return ychapi._call_get_registration_login(code);
257
+ };
258
+
259
+ /*!
260
+ * Confirm the registration login and get the 2FA setup data
261
+ * @param {string} login - the login
262
+ * @param {string} pass - the password
263
+ * @param {string} email_code - the confirmation code from email
264
+ * @returns {Promise}
265
+ * - resolved with the data {qr, url, mob} from the server,
266
+ * - rejected with the error from the server
267
+ * @security
268
+ * - pass is not sent to the server
269
+ * - login/pass are not kept in memory
270
+ */
271
+ ychapi.call_confirm_registration_login = async function(login, pass, email_code) {
272
+ return ychapi._call_confirm_registration_login(login, pass, email_code);
273
+ };
274
+
275
+ /*!
276
+ * Confirm the registration 2FA
277
+ * @param {string} login - the login
278
+ * @param {string} pass - the password
279
+ * @param {string} email_code - the confirmation code from email
280
+ * @param {string} otp_code - the OTP code
281
+ * @returns {Promise}
282
+ * - resolved (no data)
283
+ * - rejected with the error from the server
284
+ * @security
285
+ * - pass is not sent to the server
286
+ * - login/pass are not kept in memory
287
+ */
288
+ ychapi.call_confirm_registration_2fa = async function(login, pass, email_code, otp_code) {
289
+ return ychapi._call_confirm_registration_2fa(login, pass, email_code, otp_code);
290
+ };
291
+
292
+ /*!
293
+ * KEYS API
294
+ */
295
+
296
+ /*!
297
+ * Get the keys from the user login/password
298
+ * @param {string} login
299
+ * @param {string} password
300
+ * @returns [uprvk, upubk]
301
+ */
302
+ ychapi.get_user_login_keys_v1 = function(login, password) {
303
+ return ychapi._get_user_login_keys_v1(login, password);
304
+ };
305
+
306
+ /*!
307
+ * Get the user login public key
308
+ * @returns {string}
309
+ */
310
+ ychapi.get_user_login_pubk = function() {
311
+ return ychapi._get_user_login_pubk();
312
+ };
313
+
314
+ /*!
315
+ * Check if the user login private key is set
316
+ * @returns {boolean}
317
+ */
318
+ ychapi.has_user_login_prvk = function() {
319
+ return ychapi._has_user_login_prvk();
320
+ };
321
+
322
+ /*!
323
+ * Get the user signing public key
324
+ * @returns {string}
325
+ */
326
+ ychapi.get_user_signing_pubk = function() {
327
+ return ychapi._get_user_signing_pubk();
328
+ };
329
+
330
+ /*!
331
+ * Check if the user signing private key is set
332
+ * @returns {boolean}
333
+ */
334
+ ychapi.has_user_signing_prvk = function() {
335
+ return ychapi._has_user_signing_prvk();
336
+ };
337
+
338
+ /*!
339
+ * Set the user login keys
340
+ * @param {string} pubk
341
+ * @param {string} prvk
342
+ */
343
+ ychapi.set_user_login_keys = function(pubk, prvk) {
344
+ return ychapi._set_user_login_keys(pubk, prvk);
345
+ };
346
+
347
+ /*!
348
+ * DEPOSITS API
349
+ */
350
+
351
+ /*!
352
+ * Check if the user has a holding address for a coin
353
+ * @param {string} coin
354
+ * @returns {boolean}
355
+ */
356
+ ychapi.has_coin_holding_address = function(coin) {
357
+ return ychapi._has_coin_holding_address(coin);
358
+ };
359
+
360
+ /*!
361
+ * Get the holding address for a coin
362
+ * @param {string} coin
363
+ * @returns {string}
364
+ */
365
+ ychapi.get_coin_holding_address = function(coin) {
366
+ return ychapi._get_coin_holding_address(coin);
367
+ };
368
+
369
+ /*!
370
+ * Get the user current locktime for a coin
371
+ * @param {string} coin
372
+ * @returns {number} time_t
373
+ */
374
+ ychapi.get_coin_user_locktime = function(coin) {
375
+ return ychapi._get_coin_user_locktime(coin);
376
+ };
377
+
378
+ /*!
379
+ * Get the server current locktime for a coin
380
+ * @param {string} coin
381
+ * @returns {number} time_t
382
+ */
383
+ ychapi.get_coin_server_locktime = function(coin) {
384
+ return ychapi._get_coin_server_locktime(coin);
385
+ };
386
+
387
+ /*!
388
+ * TODO: may obsolete
389
+ *
390
+ * @deprecated
391
+ * ALERT: API below is expected to be obsolete and planned to be removed in next versions
392
+ *
393
+ */
394
+ ychapi.get_coin_allowed_deposit_senders = function(coin) {
395
+ return ychapi._get_coin_allowed_deposit_senders(coin);
396
+ };
397
+
398
+ /*!
399
+ * Register the deposit evm address
400
+ * @param {string} coin
401
+ * @param {string} address
402
+ * @returns {Promise}
403
+ * - resolved (no data),
404
+ * - rejected with the error from the server
405
+ *
406
+ * @deprecated
407
+ * ALERT: API below is expected to be obsolete and planned to be removed in next versions
408
+ *
409
+ */
410
+ ychapi.call_register_deposit_evm_address = function(coin, address) {
411
+ return ychapi._call_register_deposit_evm_address(coin, address);
412
+ };
413
+
414
+ /*!
415
+ * Unregister the deposit evm address
416
+ * @param {string} coin
417
+ * @param {string} address
418
+ * @returns {Promise}
419
+ * - resolved (no data),
420
+ * - rejected with the error from the server
421
+ *
422
+ * @deprecated
423
+ * ALERT: API below is expected to be obsolete and planned to be removed in next versions
424
+ *
425
+ */
426
+ ychapi.call_unregister_deposit_evm_address = function(coin, address) {
427
+ return ychapi._call_unregister_deposit_evm_address(coin, address);
428
+ };
429
+
430
+ /*!
431
+ * TRADING API
432
+ */
433
+
434
+ /*!
435
+ * Get the user trading discount
436
+ * @returns {number}
437
+ */
438
+ ychapi.get_user_trading_discount = function() {
439
+ return ychapi._get_user_trading_discount();
440
+ };
441
+
442
+ /*!
443
+ * Get the buy fee with respect to the market and user discount
444
+ * @param {string} market_name - the market name
445
+ * @param {string} coina - the coin to buy
446
+ * @param {string} coinb - the coin to spend (base)
447
+ * @returns {BigInt}
448
+ */
449
+ ychapi.get_buy_fee = function(market_name, coina, coinb) {
450
+ return ychapi._get_buy_fee(market_name, coina, coinb);
451
+ };
452
+
453
+ /*!
454
+ * Get the sell fee with respect to the market and user discount
455
+ * @param {string} market_name - the market name
456
+ * @param {string} coina - the coin to sell
457
+ * @param {string} coinb - the coin to acquire (base)
458
+ * @returns {BigInt}
459
+ */
460
+ ychapi.get_sell_fee = function(market_name, coina, coinb) {
461
+ return ychapi._get_sell_fee(market_name, coina, coinb);
462
+ };
463
+
464
+ /*!
465
+ * Get the user buys
466
+ * @param {string} market_name - the market name
467
+ * @returns {object[]}
468
+ */
469
+ ychapi.get_user_buys = function(market_name) {
470
+ return ychapi._get_user_buys(market_name);
471
+ };
472
+
473
+ /*!
474
+ * Get the user sells
475
+ * @param {string} market_name - the market name
476
+ * @returns {object[]}
477
+ */
478
+ ychapi.get_user_sells = function(market_name) {
479
+ return ychapi._get_user_sells(market_name);
480
+ };
481
+
482
+ /*!
483
+ * Get the user trades
484
+ * @param {string} market_name - the market name
485
+ * @returns {object[]}
486
+ */
487
+ ychapi.get_user_trades = function(market_name) {
488
+ return ychapi._get_user_trades(market_name);
489
+ };
490
+
491
+ /*!
492
+ * Get the market buys
493
+ * @param {string} market_name - the market name
494
+ * @returns {object[]}
495
+ */
496
+ ychapi.get_market_buys = function(market_name) {
497
+ return ychapi._get_market_buys(market_name);
498
+ };
499
+
500
+ /*!
501
+ * Get the market sells
502
+ * @param {string} market_name - the market name
503
+ * @returns {object[]}
504
+ */
505
+ ychapi.get_market_sells = function(market_name) {
506
+ return ychapi._get_market_sells(market_name);
507
+ };
508
+
509
+ /*!
510
+ * Get the market trades
511
+ * @param {string} market_name - the market name
512
+ * @returns {object[]}
513
+ */
514
+ ychapi.get_market_trades = function(market_name) {
515
+ return ychapi._get_market_trades(market_name);
516
+ };
517
+
518
+ /*!
519
+ * Buy a coin
520
+ * @param {string} market_name - the market name
521
+ * @param {string} coina - the coin to buy
522
+ * @param {string} coinb - the coin to spend (base)
523
+ * @param {string} price - the price of the coin
524
+ * @param {BigInt} amounta - the amount of the coin to buy
525
+ * @param {BigInt} amountb - the amount of the coin to spend
526
+ * @param {BigInt} feeb - the fee (coinb) to buy
527
+ * @returns {Promise}
528
+ * - resolved (no data),
529
+ * - rejected with the error from the preparing/server
530
+ */
531
+ ychapi.call_buy = async function(market_name, coina, coinb, price, amounta, amountb, feeb) {
532
+ return ychapi._call_buy(market_name, coina, coinb, price, amounta, amountb, feeb);
533
+ };
534
+
535
+ /*!
536
+ * Sell a coin
537
+ * @param {string} market_name - the market name
538
+ * @param {string} coina - the coin to sell
539
+ * @param {string} coinb - the coin to acquire (base)
540
+ * @param {string} price - the price of the coin
541
+ * @param {BigInt} amounta - the amount of the coin to sell
542
+ * @param {BigInt} amountb - the amount of the coin to acquire
543
+ * @param {BigInt} feea - the fee (coina) to sell
544
+ * @returns {Promise}
545
+ * - resolved (no data),
546
+ * - rejected with the error from the preparing/server
547
+ */
548
+ ychapi.call_sell = async function(market_name, coina, coinb, price, amounta, amountb, feea) {
549
+ return ychapi._call_sell(market_name, coina, coinb, price, amounta, amountb, feea);
550
+ };
551
+
552
+ /*!
553
+ * Cancel a buy order
554
+ * @param {string} coina - the coin to buy
555
+ * @param {string} coinb - the coin to spend (base)
556
+ * @param {int} index - the index of the order
557
+ * @returns {Promise}
558
+ * - resolved (no data),
559
+ * - rejected with the error from the server
560
+ */
561
+ ychapi.call_buy_order_cancel = function(coina, coinb, index) {
562
+ return ychapi._call_buy_order_cancel(coina, coinb, index);
563
+ };
564
+
565
+ /*!
566
+ * Cancel a sell order
567
+ * @param {string} coina - the coin to sell
568
+ * @param {string} coinb - the coin to acquire (base)
569
+ * @param {int} index - the index of the order
570
+ * @returns {Promise}
571
+ * - resolved (no data),
572
+ * - rejected with the error from the server
573
+ */
574
+ ychapi.call_sell_order_cancel = function(coina, coinb, index) {
575
+ return ychapi._call_sell_order_cancel(coina, coinb, index);
576
+ };
577
+
578
+ /*!
579
+ * Get the chart data
580
+ * @param {string} market_name
581
+ * @param {string} period (60, 300, 900, 3600, 21600, 86400)
582
+ * @returns {Promise}
583
+ * - resolved with the chart data,
584
+ * - rejected with the error from the server
585
+ */
586
+ ychapi.call_get_chart_data = function(market_name, period) {
587
+ return ychapi._call_get_chart_data(market_name, period);
588
+ };
589
+
590
+ /*!
591
+ * WITHDRAW/TRANSFER API
592
+ */
593
+
594
+ /*!
595
+ * Validate an address
596
+ * @param {string} coin
597
+ * @param {string} address
598
+ * @returns error string or null if address is valid
599
+ */
600
+ ychapi.validate_address = function(coin, address) {
601
+ return ychapi._validate_address(coin, address);
602
+ };
603
+
604
+ /*!
605
+ * Get the withdraw rawtx
606
+ * @param {object} withdraw_plan
607
+ * @returns {string}
608
+ */
609
+ ychapi.get_withdraw_rawtx = function(withdraw_plan) {
610
+ return ychapi._get_withdraw_rawtx(withdraw_plan);
611
+ };
612
+
613
+ /*!
614
+ * Send an amount of a coin to a receiver - another user (internal transfer)
615
+ * @param {string} coin - the coin to send
616
+ * @param {string} receiver_login - the login of the receiver
617
+ * @param {string} amount - the amount to send
618
+ * @param {string} fee - the fee to send
619
+ * @returns {Promise}
620
+ * - resolved (no data),
621
+ * - rejected with the error from the preparing/server
622
+ */
623
+ ychapi.call_send = async function(coin, receiver_login, amount, fee) {
624
+ return ychapi._call_send(coin, receiver_login, amount, fee);
625
+ };
626
+
627
+ /*!
628
+ * Create the withdraw plan
629
+ * @param {string} coin
630
+ * @param {string} scope ("available", "allocated")
631
+ */
632
+ ychapi.create_withdraw = function(coin, scope) {
633
+ return ychapi._create_withdraw(coin, scope);
634
+ };
635
+
636
+ /*!
637
+ * Update the withdraw plan for inputs or fees change
638
+ * @param {object} withdraw_plan
639
+ */
640
+ ychapi.update_withdraw = function(withdraw_plan) {
641
+ return ychapi._update_withdraw(withdraw_plan);
642
+ };
643
+
644
+ /*!
645
+ * Set the withdraw amount
646
+ * @param {object} withdraw_plan
647
+ * @param {BigInt} amount_bn
648
+ * @param {string} mode ("manual", "reduce")
649
+ */
650
+ ychapi.set_withdraw_amount = function(withdraw_plan, amount_bn, mode) {
651
+ return ychapi._set_withdraw_amount(withdraw_plan, amount_bn, mode);
652
+ };
653
+
654
+ /*!
655
+ * Check if the withdraw has an inputs stage
656
+ * @param {object} withdraw_task
657
+ * @returns {boolean}
658
+ */
659
+ ychapi.has_withdraw_inputs_stage = function(withdraw_plan) {
660
+ return ychapi._has_withdraw_inputs_stage(withdraw_plan);
661
+ };
662
+
663
+ /*!
664
+ * Prepare the withdraw for the inputs to finalize the transaction to sign.
665
+ * Coin types: txout_t1
666
+ * @param {object} withdraw_plan
667
+ * @returns {Promise}
668
+ * - resolved with the txouts,
669
+ * - rejected with the error from the server
670
+ */
671
+ ychapi.call_withdraw_inputs_stage = function(withdraw_plan) {
672
+ return ychapi._call_withdraw_inputs_stage(withdraw_plan);
673
+ };
674
+
675
+ /*!
676
+ * Set the withdraw inputs for the debit
677
+ * @param {object} withdraw_plan
678
+ * @param {object[]} txouts
679
+ * @returns {Promise}
680
+ * - resolved (no data),
681
+ * - rejected with the error from the server
682
+ */
683
+ ychapi.set_withdraw_inputs_for_debit = function(withdraw_plan, txouts) {
684
+ return ychapi._set_withdraw_inputs_for_debit(withdraw_plan, txouts);
685
+ };
686
+
687
+ /*!
688
+ * Make the withdraw
689
+ * @param {string} coin
690
+ * @param {string} addr_send
691
+ * @param {string} sendfee
692
+ * @param {object} op1
693
+ * @param {object} op2
694
+ * @returns {Promise}
695
+ * - resolved (no data),
696
+ * - rejected with the error from the server
697
+ */
698
+ ychapi.call_withdraw = function(coin, addr_send, sendfee, op1, op2) {
699
+ return ychapi._call_withdraw(coin, addr_send, sendfee, op1, op2);
700
+ };
701
+
702
+ /*!
703
+ * Report the txid of the withdraw (erc20_t1, evm_t1) after the withdraw is broadcasted via web3 api
704
+ * @param {string} coin
705
+ * @param {string} gidx
706
+ * @param {string} txid
707
+ * @returns {Promise}
708
+ * - resolved (no data),
709
+ * - rejected with the error from the server
710
+ */
711
+ ychapi.call_withdraw_report_txid = function(coin, gidx, txid) {
712
+ return ychapi._call_withdraw_report_txid(coin, gidx, txid);
713
+ };
714
+
715
+ /*!
716
+ * Cancel the withdraw (erc20_t1, evm_t1)
717
+ * @param {string} coin
718
+ * @param {string} gidx
719
+ * @returns {Promise}
720
+ * - resolved (no data),
721
+ * - rejected with the error from the server
722
+ */
723
+ ychapi.call_withdraw_cancel = function(coin, gidx) {
724
+ return ychapi._call_withdraw_cancel(coin, gidx);
725
+ };
726
+
727
+ /*!
728
+ * UTILS API
729
+ */
730
+
731
+ /*!
732
+ * Get the page size
733
+ * @returns {number}
734
+ */
735
+ ychapi.get_page_size = function() {
736
+ return ychapi._get_page_size();
737
+ };
738
+
739
+ /*!
740
+ * Get the evm vault7u abi
741
+ * @returns {string}
742
+ */
743
+ ychapi.get_evm_vault7u_abi = function() {
744
+ return ychapi._get_evm_vault7u_abi();
745
+ };
746
+
747
+ /*!
748
+ * Sign the evm vault7u user1
749
+ * @param {string} user
750
+ * @param {string} statehex
751
+ * @param {string} amount
752
+ * @param {string} addr
753
+ * @param {string} tw
754
+ * @returns {string}
755
+ */
756
+ ychapi.sign_evm_vault7u_user1 = function(user, statehex, amount, addr, tw) {
757
+ return ychapi._sign_evm_vault7u_user1(user, statehex, amount, addr, tw);
758
+ };
759
+
760
+ /*!
761
+ * Get the user account id
762
+ * @returns {string}
763
+ */
764
+ ychapi.get_user_account_id = function() {
765
+ return ychapi._get_user_account_id();
766
+ };
767
+
768
+ /*!
769
+ * Get the user account login
770
+ * @returns {string}
771
+ */
772
+ ychapi.get_user_account_login = function() {
773
+ return ychapi._get_user_account_login();
774
+ };
775
+
776
+ /*!
777
+ * Get the user account twofa enabled
778
+ * @returns {boolean}
779
+ */
780
+ ychapi.get_user_account_twofa = function() {
781
+ return ychapi._get_user_account_twofa();
782
+ };
783
+
784
+ /*!
785
+ * Get the user rewards
786
+ * @param {string} coin
787
+ * @returns {BigInt}
788
+ */
789
+ ychapi.get_user_rewards = function(coin) {
790
+ return ychapi._get_user_rewards(coin);
791
+ };
792
+
793
+ /*!
794
+ * Get the user referral invitation code
795
+ * @returns {string}
796
+ */
797
+ ychapi.get_user_referral_invitation_code = function() {
798
+ return ychapi._get_user_referral_invitation_code();
799
+ };
800
+
801
+ /*!
802
+ * Get the user referral invitation title
803
+ * @returns {string}
804
+ */
805
+ ychapi.get_user_referral_invitation_title = function() {
806
+ return ychapi._get_user_referral_invitation_title();
807
+ };
808
+
809
+ /*!
810
+ * Check if the user is logged in
811
+ * @returns {boolean}
812
+ */
813
+ ychapi.is_logged_in = function() {
814
+ return ychapi._is_logged_in();
815
+ };
816
+
817
+ /*!
818
+ * Check if the user has a profile
819
+ * @returns {boolean}
820
+ */
821
+ ychapi.has_profile = function() {
822
+ return ychapi._has_profile();
823
+ };
@@ -0,0 +1 @@
1
+ var coinjs=window.coinjs=function(){};coinjs.bech32={charset:"qpzry9x8gf2tvdw0s3jn54khce6mua7l",version:0,hrp:"bc"},coinjs.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},coinjs.hash256=function(t){return Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})},coinjs.arrayEquals=function(t,e){return Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every(((t,n)=>t===e[n]))},coinjs.bech32_polymod=function(t){let e=1;const n=[996825010,642813549,513874426,1027748829,705979059];for(let i=0;i<t.length;++i){let r=e>>25;e=(33554431&e)<<5^t[i];for(let t=0;t<5;++t)r>>t&1&&(e^=n[t])}return e},coinjs.bech32_hrpExpand=function(t){var e,n=[];for(e=0;e<t.length;++e)n.push(t.charCodeAt(e)>>5);for(n.push(0),e=0;e<t.length;++e)n.push(31&t.charCodeAt(e));return n},coinjs.bech32_verifyChecksum=function(t,e){return 1===coinjs.bech32_polymod(coinjs.bech32_hrpExpand(t).concat(e))},coinjs.bech32_decode=function(t){var e,n=!1,i=!1;for(e=0;e<t.length;++e){if(t.charCodeAt(e)<33||t.charCodeAt(e)>126)return null;t.charCodeAt(e)>=97&&t.charCodeAt(e)<=122&&(n=!0),t.charCodeAt(e)>=65&&t.charCodeAt(e)<=90&&(i=!0)}if(n&&i)return null;var r=(t=t.toLowerCase()).lastIndexOf("1");if(r<1||r+7>t.length||t.length>90)return null;var o=t.substring(0,r),s=[];for(e=r+1;e<t.length;++e){var a=coinjs.bech32.charset.indexOf(t.charAt(e));if(-1===a)return null;s.push(a)}return coinjs.bech32_verifyChecksum(o,s)?{hrp:o,data:s.slice(0,s.length-6)}:null},coinjs.bech32_convert=function(t,e,n,i){for(var r=0,o=0,s=(1<<n)-1,a=[],c=0;c<t.length;++c)for(r=r<<e|t[c],o+=e;o>=n;)o-=n,a.push(r>>o&s);if(i)o>0&&a.push(r<<n-o&s);else{if(o>=e)throw new Error("Excess padding");if(r<<n-o&s)throw new Error("Non-zero padding")}return a},coinjs.bech32redeemscript=function(t){var e=coinjs.bech32_decode(t);return!!e&&(e.data.shift(),Crypto.util.bytesToHex(coinjs.bech32_convert(e.data,5,8,!1)))};var dbits,CHARSET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",CHARSET_INVERSE_INDEX={q:0,p:1,z:2,r:3,y:4,9:5,x:6,8:7,g:8,f:9,2:10,t:11,v:12,d:13,w:14,0:15,s:16,3:17,j:18,n:19,5:20,4:21,k:22,h:23,c:24,e:25,6:26,m:27,u:28,a:29,7:30,l:31},convertBits=function(t,e,n){let i=Math.ceil(t.length*e/n),r=(1<<n)-1,o=[];for(let t=0;t<i;++t)o.push(0);let s=0,a=0,c=0;for(let i=0;i<t.length;++i){for(a=a<<e|t[i],c+=e;c>=n;)c-=n,o[s]=a>>c&r,++s}return c>0&&(o[s]=a<<n-c&r,++s),o},base32polymod=function(t){let e=[0x98f2bc8e61n,0x79b76d99e2n,0xf33e5fb3c4n,0xae2eabe2a8n,0x1e4f43e470n],n=1n;for(let i=0;i<t.length;++i){let r=t[i],o=n>>35n;n=(0x07ffffffffn&n)<<5n^BigInt(r);for(let t=0;t<e.length;++t)1n==(o>>BigInt(t)&1n)&&(n^=BigInt(e[t]))}return 1n^n},decodeBase32AsBytes=function(t){let e=[];for(let n=0;n<t.length;++n){let i=t[n];e.push(CHARSET_INVERSE_INDEX[i])}e=e.slice(0,e.length-8);let n=convertBits(e,5,8);return n=n.slice(0,n.length-1),encodeBytesToBase32(n)==t&&n},encodeBytesToBase32=function(t){let e=convertBits(t,8,5),n=function(t){let e=[];for(let n=0;n<t.length;++n)e.push(31&t[n].charCodeAt(0));return e}(coinjs.base32pref);n.push(0),n.push(...e),n.push(0,0,0,0,0,0,0,0);e.push(...function(t){let e=[0,0,0,0,0,0,0,0];for(let n=0;n<8;++n)e[7-n]=Number(31n&t),t>>=5n;return e}(base32polymod(n)));let i="";for(let t=0;t<e.length;++t){let n=e[t];i+=CHARSET[n]}return i};coinjs.signHash=function(t,e){const n=EllipticCurve.getSECCurveByName("secp256k1"),i=coinjs.wif2privkey(t),r=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(i.privkey)),o=n.getN(),s=BigInteger.fromByteArrayUnsigned(e);let a=0,c=null,u=null;do{const i=coinjs.deterministicK(t,e,a);u=n.getG().multiply(i).getX().toBigInteger().mod(o),c=i.modInverse(o).multiply(s.add(r.multiply(u))).mod(o),a++}while(u.compareTo(BigInteger.ZERO)<=0||c.compareTo(BigInteger.ZERO)<=0);const l=o.shiftRight(1);c.compareTo(l)>0&&(c=o.subtract(c));let p=function serializeSig(t,e){const n=t.toByteArraySigned(),i=e.toByteArraySigned();let r=[];return r.push(2),r.push(n.length),r=r.concat(n),r.push(2),r.push(i.length),r=r.concat(i),r.unshift(r.length),r.unshift(48),r}(u,c);return p.push(parseInt(1,10)),Crypto.util.bytesToHex(p)},coinjs.script=function(t){var e={};return t?"string"==typeof t?e.buffer=Crypto.util.hexToBytes(t):coinjs.isArray(t)?e.buffer=t:t instanceof coinjs.script?e.buffer=t.buffer:e.buffer=t:e.buffer=[],e.parse=function(){var t=this;e.chunks=[];var n=0;function readChunk(e){t.chunks.push(t.buffer.slice(n,n+e)),n+=e}for(;n<this.buffer.length;){var i=this.buffer[n++];if(i>=240&&(i=i<<8|this.buffer[n++]),i>0&&i<76?readChunk(i):76==i?readChunk(this.buffer[n++]):77==i?readChunk(this.buffer[n++]<<8|this.buffer[n++]):78==i?readChunk(this.buffer[n++]<<24|this.buffer[n++]<<16|this.buffer[n++]<<8|this.buffer[n++]):this.chunks.push(i),n<0)break}return!0},e.spendToScript=function(t){var e=coinjs.addressDecode(t),n=coinjs.script();return"bech32"==e.type?(n.writeOp(0),n.writeBytes(Crypto.util.hexToBytes(e.redeemscript))):coinjs.arrayEquals(e.version,coinjs.multisig)||"multisig"==e.type?(n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(135)):(n.writeOp(118),n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(136),n.writeOp(172)),n},e.pubkeyHash=function(t){var e=coinjs.addressDecode(t),n=coinjs.script();return n.writeOp(118),n.writeOp(169),n.writeBytes(e.bytes),n.writeOp(136),n.writeOp(172),n},e.writeOp=function(t){return this.buffer.push(t),this.chunks.push(t),!0},e.writeBytes=function(t){return t.length<76?this.buffer.push(t.length):t.length<=255?(this.buffer.push(76),this.buffer.push(t.length)):t.length<=65535?(this.buffer.push(77),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255)):(this.buffer.push(78),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255),this.buffer.push(t.length>>>16&255),this.buffer.push(t.length>>>24&255)),this.buffer=this.buffer.concat(t),this.chunks.push(t),!0},e.parse(),e},coinjs.transaction=function(){var t={};return t.version=coinjs.txversion,t.lock_time=0,t.ins=[],t.outs=[],t.witness=[],t.timestamp=null,t.block=null,t.nTime=0,t.addinput=function(e,n,i,r,o){var s={};return s.outpoint={hash:e,index:n},s.script=coinjs.script(i||[]),s.sequence=r||(0==t.lock_time?4294967295:0),s.value="bigint"==typeof o?new BigInteger(o.toString()):o?new BigInteger(""+Math.round(1*o*1e8),10):null,this.ins.push(s)},t.addoutput=function(t,e){var n={};n.value="bigint"==typeof e?new BigInteger(e.toString()):new BigInteger(""+Math.round(1*e*1e8),10);var i=coinjs.script();return n.script=i.spendToScript(t),this.outs.push(n)},t.adddata=function(t,e){if(t.match(/^[a-f0-9]+$/gi)&&t.length<160&&t.length%2==0){var n=coinjs.script();return n.writeOp(106),n.writeBytes(Crypto.util.hexToBytes(t)),o={},o.value=e,o.script=n,this.outs.push(o)}return!1},t.transactionHash=function(t,e){var n=coinjs.clone(this),i=e||1;64==coinjs.shf&&(i|=64);for(var r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].script=coinjs.script());var o=this.extractScriptKey(t);if(n.ins[t].script=coinjs.script(o.script),n.ins&&n.ins[t]){var s=224&i,a=31&i;if(1==a);else if(2==a){n.outs=[];for(r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].sequence=0)}else if(3==a){n.outs.length=t+1;for(r=0;r<t;r++)n.outs[r].value=-1,n.outs[r].script.buffer=[];for(r=0;r<n.ins.length;r++)t!=r&&(n.ins[r].sequence=0)}var c,u=n.ins[t];if(128&s&&(n.ins=[n.ins[t]]),64&s){let e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];c=(c=[]).concat(coinjs.numToBytes(parseInt(n.version),4)),c=128&s?c.concat(e):c.concat(coinjs.hash256(n.getPrevouts())),c=(c=(c=(c=(c=(c=(c=128&s||3==a||2==a?c.concat(e):c.concat(coinjs.hash256(n.getSequences()))).concat(Crypto.util.hexToBytes(u.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(u.outpoint.index),4))).concat(coinjs.numToVarInt(u.script.buffer.length))).concat(u.script.buffer)).concat(coinjs.numToBytes(u.value,8))).concat(coinjs.numToBytes(parseInt(u.sequence),4)),c=(c=(c=3!=a&&2!=a?c.concat(coinjs.hash256(n.getOutputs())):3==a?c.concat(coinjs.hash256(n.getOutput(t))):c.concat(e)).concat(coinjs.numToBytes(parseInt(this.lock_time),4))).concat(coinjs.numToBytes(parseInt(i),4))}else c=(c=Crypto.util.hexToBytes(n.serialize())).concat(coinjs.numToBytes(parseInt(i),4));var l=Crypto.SHA256(c,{asBytes:!0});return Crypto.util.bytesToHex(Crypto.SHA256(l,{asBytes:!0}))}return!1},t.transactionHashSegWitV0=function(t,e,n,i){var r=[],o=coinjs.script(Crypto.util.hexToBytes(e));r=(r=r.concat(coinjs.numToVarInt(o.buffer.length))).concat(o.buffer);var s=coinjs.numToBytes(i,8),a=coinjs.numToBytes(0,32),c=coinjs.numToBytes(parseInt(this.version),4),u=[];if(!(n>=80))for(var l=0;l<this.ins.length;l++)u=(u=u.concat(Crypto.util.hexToBytes(this.ins[l].outpoint.hash).reverse())).concat(coinjs.numToBytes(this.ins[l].outpoint.index,4));var p=u.length>=1?Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}):a;u=[];if(!(n>=80)&&2!=n&&3!=n)for(l=0;l<this.ins.length;l++)u=u.concat(coinjs.numToBytes(this.ins[l].sequence,4));var h=u.length>=1?Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}):a,f=Crypto.util.hexToBytes(this.ins[t].outpoint.hash).reverse();f=f.concat(coinjs.numToBytes(this.ins[t].outpoint.index,4));var d=coinjs.numToBytes(this.ins[t].sequence,4),y=a;u=[];if(2!=n&&3!=n){for(l=0;l<this.outs.length;l++)u=(u=(u=u.concat(coinjs.numToBytes(this.outs[l].value,8))).concat(coinjs.numToVarInt(this.outs[l].script.buffer.length))).concat(this.outs[l].script.buffer);y=Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0})}else 2==n&&t<this.outs.length&&(u=(u=(u=u.concat(coinjs.numToBytes(this.outs[t].value,8))).concat(coinjs.numToVarInt(this.outs[l].script.buffer.length))).concat(this.outs[t].script.buffer),y=Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}));var _=coinjs.numToBytes(this.lock_time,4),g=coinjs.numToBytes(n,4),m=[];m=(m=(m=(m=(m=(m=(m=(m=(m=(m=m.concat(c)).concat(p)).concat(h)).concat(f)).concat(r)).concat(s)).concat(d)).concat(y)).concat(_)).concat(g);var b=Crypto.SHA256(m,{asBytes:!0});return{result:1,hash:Crypto.util.bytesToHex(Crypto.SHA256(b,{asBytes:!0})),response:"hash generated"}},t.getPrevouts=function(){for(var t=[],e=0;e<this.ins.length;e++){var n=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(n.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(n.outpoint.index),4))}return t},t.getSequences=function(){for(var t=[],e=0;e<this.ins.length;e++){var n=this.ins[e];t=t.concat(coinjs.numToBytes(parseInt(n.sequence),4))}return t},t.getOutputs=function(){for(var t=[],e=0;e<this.outs.length;e++){var n=this.outs[e];t=t.concat(coinjs.numToBytes(n.value,8));var i=n.script.buffer;t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)}return t},t.getOutput=function(t){for(var e=[],n=0;n<this.outs.length;n++)if(n==t){var i=this.outs[n];e=e.concat(coinjs.numToBytes(i.value,8));var r=i.script.buffer;e=(e=e.concat(coinjs.numToVarInt(r.length))).concat(r)}return e},t.extractScriptKey=function(t){if(this.ins[t]){if(5==this.ins[t].script.chunks.length&&172==this.ins[t].script.chunks[4]&&coinjs.isArray(this.ins[t].script.chunks[2]))return{type:"scriptpubkey",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0]&&5==this.ins[t].script.chunks[1].length&&177==this.ins[t].script.chunks[1][1])return{type:"hodl",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0])return{type:"scriptpubkey",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(5==this.ins[t].script.chunks.length&&177==this.ins[t].script.chunks[1])return{type:"hodl",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(this.ins[t].script.chunks.length<=3&&this.ins[t].script.chunks.length>0&&22==this.ins[t].script.chunks[0].length&&0==this.ins[t].script.chunks[0][0]){var e=this.witness[t]&&2==this.witness[t].length?"true":"false";return{type:"segwit",signed:e,signatures:"true"==e?1:0,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[0])}}return 0==this.ins[t].script.chunks[0]&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1][this.ins[t].script.chunks[this.ins[t].script.chunks.length-1].length-1]?{type:"multisig",signed:"true",signatures:this.ins[t].script.chunks.length-2,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[this.ins[t].script.chunks.length-1])}:this.ins[t].script.chunks[0]>=80&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1]?{type:"multisig",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}:0==this.ins[t].script.chunks.length?{type:"empty",signed:"false",signatures:0,script:""}:{type:"unknown",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}}return!1},t.transactionSig=function(t,e,n,i){var r=n||1;64==coinjs.shf&&(r|=64);var o=i||Crypto.util.hexToBytes(this.transactionHash(t,r));if(o){var s=EllipticCurve.getSECCurveByName("secp256k1"),a=coinjs.wif2privkey(e),c=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(a.privkey)),u=s.getN(),l=BigInteger.fromByteArrayUnsigned(o),p=0;do{var h=coinjs.deterministicK(e,o,p),f=s.getG().multiply(h).getX().toBigInteger().mod(u),d=h.modInverse(u).multiply(l.add(c.multiply(f))).mod(u);p++}while(f.compareTo(BigInteger.ZERO)<=0||d.compareTo(BigInteger.ZERO)<=0);var y=u.shiftRight(1);d.compareTo(y)>0&&(d=u.subtract(d));var _=function serializeSig(t,e){var n=t.toByteArraySigned(),i=e.toByteArraySigned(),r=[];return r.push(2),r.push(n.length),(r=r.concat(n)).push(2),r.push(i.length),(r=r.concat(i)).unshift(r.length),r.unshift(48),r}(f,d);return _.push(parseInt(r,10)),Crypto.util.bytesToHex(_)}return!1},t.serialize=function(){var t=[];t=t.concat(coinjs.numToBytes(parseInt(this.version),4)),this.witness.length>=1&&(t=t.concat([0,1])),coinjs.txExtraTimeField&&(t=t.concat(coinjs.numToBytes(parseInt(this.nTime),4))),t=t.concat(coinjs.numToVarInt(this.ins.length));for(var e=0;e<this.ins.length;e++){var n=this.ins[e];t=(t=t.concat(Crypto.util.hexToBytes(n.outpoint.hash).reverse())).concat(coinjs.numToBytes(parseInt(n.outpoint.index),4));var i=n.script.buffer;t=(t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)).concat(coinjs.numToBytes(parseInt(n.sequence),4))}t=t.concat(coinjs.numToVarInt(this.outs.length));for(e=0;e<this.outs.length;e++){var r=this.outs[e];t=t.concat(coinjs.numToBytes(r.value,8));i=r.script.buffer;t=(t=t.concat(coinjs.numToVarInt(i.length))).concat(i)}if(this.witness.length>=1)for(e=0;e<this.witness.length;e++){t=t.concat(coinjs.numToVarInt(this.witness[e].length));for(var o=0;o<this.witness[e].length;o++)t=(t=t.concat(coinjs.numToVarInt(Crypto.util.hexToBytes(this.witness[e][o]).length))).concat(Crypto.util.hexToBytes(this.witness[e][o]))}return t=t.concat(coinjs.numToBytes(parseInt(this.lock_time),4)),Crypto.util.bytesToHex(t)},t.deserialize=function(t){"string"==typeof t&&(t=Crypto.util.hexToBytes(t));var e=0,n=!1,readAsInt=function(n){return 0==n?0:(e++,t[e-1]+256*readAsInt(n-1))},readVarInt=function(){return e++,t[e-1]<253?t[e-1]:readAsInt(t[e-1]-251)},readBytes=function(n){return e+=n,t.slice(e-n,e)},readVarString=function(){var t=readVarInt();return readBytes(t)},i=new coinjs.transaction;i.version=readAsInt(4),coinjs.txExtraTimeField&&(i.nTime=readAsInt(4)),0==t[e]&&1==t[e+1]&&(n=!0,i.witness=[],e+=2);for(var r=readVarInt(),o=0;o<r;o++)i.ins.push({outpoint:{hash:Crypto.util.bytesToHex(readBytes(32).reverse()),index:readAsInt(4)},script:coinjs.script(readVarString()),sequence:readAsInt(4)});var s=readVarInt();for(o=0;o<s;o++)i.outs.push({value:coinjs.bytesToNum(readBytes(8)),script:coinjs.script(readVarString())});if(1==n)for(o=0;o<r;++o)for(var a=readVarInt(),c=0;c<a;c++){var u=readVarInt();e+=u,coinjs.isArray(i.witness[o])||(i.witness[o]=[]),i.witness[o].push(Crypto.util.bytesToHex(t.slice(e-u,e)))}return i.lock_time=readAsInt(4),i},t.size=function(){return(this.serialize().length/2).toFixed(0)},t},coinjs.deterministicK=function(t,e,n){n=n||0;var i=coinjs.wif2privkey(t),r=Crypto.util.hexToBytes(i.privkey),o=EllipticCurve.getSECCurveByName("secp256k1").getN(),s=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];a=Crypto.HMAC(Crypto.SHA256,s.concat([0]).concat(r).concat(e),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),a=Crypto.HMAC(Crypto.SHA256,s.concat([1]).concat(r).concat(e),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0});var c=[];c=s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0});for(var u=BigInteger.fromByteArrayUnsigned(c),l=0;u.compareTo(o)>=0||u.compareTo(BigInteger.ZERO)<=0||l<n;)a=Crypto.HMAC(Crypto.SHA256,s.concat([0]),a,{asBytes:!0}),s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),c=s=Crypto.HMAC(Crypto.SHA256,s,a,{asBytes:!0}),u=BigInteger.fromByteArrayUnsigned(c),l++;return u},coinjs.countObject=function(t){var e,n=0;for(e in t)t.hasOwnProperty(e)&&n++;return n},coinjs.clone=function(t){if(null==t||"object"!=typeof t)return t;var e=new t.constructor;for(var n in t)t.hasOwnProperty(n)&&(e[n]=coinjs.clone(t[n]));return e},coinjs.numToBytes=function(t,e){return void 0===e&&(e=8),0==e?[]:-1==t?Crypto.util.hexToBytes("ffffffffffffffff"):[t%256].concat(coinjs.numToBytes(Math.floor(t/256),e-1))},coinjs.numToByteArray=function(t){return t<=256?[t]:[t%256].concat(coinjs.numToByteArray(Math.floor(t/256)))},coinjs.numToVarInt=function(t){return t<253?[t]:t<65536?[253].concat(coinjs.numToBytes(t,2)):t<4294967296?[254].concat(coinjs.numToBytes(t,4)):[255].concat(coinjs.numToBytes(t,8))},coinjs.bytesToNum=function(t){return 0==t.length?0:t[0]+256*coinjs.bytesToNum(t.slice(1))},coinjs.addressDecodeWithBase32Prefix=function(t,e){if(!t.startsWith(e+":"))return!1;const n=decodeBase32AsBytes(t.slice(e.length+1));if(0==n)return!1;const i=n,r={};return 0==n[0]?(r.type="standard",r.bytes=i.slice(1),r.version=[i[0]]):8==n[0]?(r.type="multisig",r.bytes=i.slice(1),r.version=[i[0]]):(r.type="other",r.bytes=i.slice(1),r.version=[i[0]]),r},coinjs.addressDecodeStd=function(t){const e=coinjs.base58decode(t),n=e.slice(0,e.length-4),i=e.slice(e.length-4);if(Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}).slice(0,4)+""==i+""){const t={};return coinjs.arrayEquals(n.slice(0,coinjs.pub.length),coinjs.pub)?(t.type="standard",t.bytes=n.slice(coinjs.pub.length),t.version=n.slice(0,coinjs.pub.length)):coinjs.arrayEquals(n.slice(0,coinjs.multisig.length),coinjs.multisig)?(t.type="multisig",t.bytes=n.slice(coinjs.multisig.length),t.version=n.slice(0,coinjs.multisig.length)):coinjs.arrayEquals(n.slice(0,coinjs.priv.length),coinjs.priv)?(t.type="wifkey",t.bytes=n.slice(coinjs.priv.length),t.version=n.slice(0,coinjs.priv.length)):(t.type="other",t.bytes=n.slice(1),t.version=[n[0]]),t}return!1},coinjs.addressDecode=function(t){try{return""!=coinjs.base32pref&&t.startsWith(coinjs.base32pref+":")?coinjs.addressDecodeWithBase32Prefix(t,coinjs.base32pref):coinjs.addressDecodeStd(t)}catch(e){return bech32rs=coinjs.bech32redeemscript(t),!!bech32rs&&{type:"bech32",redeemscript:bech32rs}}},coinjs.base58encode=function(t){for(var e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",n=BigInteger.valueOf(58),i=BigInteger.fromByteArrayUnsigned(t),r=[];i.compareTo(n)>=0;){var o=i.mod(n);r.unshift(e[o.intValue()]),i=i.subtract(o).divide(n)}r.unshift(e[i.intValue()]);for(var s=0;s<t.length&&0==t[s];s++)r.unshift(e[0]);return r.join("")},coinjs.base58decode=function(t){for(var e=BigInteger.valueOf(58),n=BigInteger.valueOf(0),i=0,r=t.length-1;r>=0;r--){var o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".indexOf(t[r]);if(o<0)throw"Invalid character";n=n.add(BigInteger.valueOf(o).multiply(e.pow(t.length-1-r))),"1"==t[r]?i++:i=0}for(var s=n.toByteArrayUnsigned();i-- >0;)s.unshift(0);return s},coinjs.privkey2wif=function(t){var e=Crypto.util.hexToBytes(t);1==coinjs.compressed&&e.push(1),e.unshift(...coinjs.priv);var n=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(e.concat(n))},coinjs.wif2privkey=function(t){var e=!1,n=coinjs.base58decode(t),i=n.slice(0,n.length-4);return(i=i.slice(1,i.length)).length>=33&&1==i[i.length-1]&&(i=i.slice(0,i.length-1),e=!0),{privkey:Crypto.util.bytesToHex(i),compressed:e}},coinjs.pubkeys2MultisigAddressWithBackup=function(t,e,n,i){var r=coinjs.script();0==n&&0==i?(r.writeOp(82),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(82),r.writeOp(174)):(r.writeOp(99),r.writeOp(82),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(82),r.writeOp(174),r.writeOp(103),r.writeOp(99),r.writeBytes(coinjs.numToByteArray(n)),r.writeOp(177),r.writeOp(117),r.writeBytes(Crypto.util.hexToBytes(t)),r.writeOp(172),r.writeOp(103),r.writeBytes(coinjs.numToByteArray(i)),r.writeOp(177),r.writeOp(117),r.writeBytes(Crypto.util.hexToBytes(e)),r.writeOp(172),r.writeOp(104),r.writeOp(104));let o=ripemd160(Crypto.SHA256(r.buffer,{asBytes:!0}),{asBytes:!0});if(""!=coinjs.base32pref){let t=8+(o.length-20)/4;o.unshift(t);let e=Crypto.util.bytesToHex(r.buffer);return{address:coinjs.base32pref+":"+encodeBytesToBase32(o),redeemScript:e}}o.unshift(...coinjs.multisig);let s=o;s=Crypto.SHA256(Crypto.SHA256(s,{asBytes:!0}),{asBytes:!0});let a=s.slice(0,4),c=Crypto.util.bytesToHex(r.buffer);return{address:coinjs.base58encode(o.concat(a)),redeemScript:c}},coinjs.pubkeydecompress=function(t){if("string"==typeof t&&t.match(/^[a-f0-9]+$/i)){var e=EllipticCurve.getSECCurveByName("secp256k1");try{var n=e.curve.decodePointHex(t),i=n.getX().toBigInteger(),r=n.getY().toBigInteger(),o=EllipticCurve.integerToBytes(i,32);return(o=o.concat(EllipticCurve.integerToBytes(r,32))).unshift(4),Crypto.util.bytesToHex(o)}catch(t){return!1}}return!1},coinjs.pubkey2address=function(t,e){var n=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}));n.unshift(e||coinjs.pub);var i=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}).slice(0,4);return coinjs.base58encode(n.concat(i))},coinjs.verifySignature=function(t,e,n){var i,r,o;if(coinjs.isArray(e)){var s=function parseSig(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:BigInteger.fromByteArrayUnsigned(n),s:BigInteger.fromByteArrayUnsigned(i)}}(e);i=s.r,r=s.s}else{if("object"!=typeof e||!e.r||!e.s)throw"Invalid value for signature";i=e.r,r=e.s}if(!coinjs.isArray(n))throw"Invalid format for pubkey value, must be byte array";var a=EllipticCurve.getSECCurveByName("secp256k1");o=EllipticCurve.PointFp.decodeFrom(a.getCurve(),n);var c=BigInteger.fromByteArrayUnsigned(t);return coinjs.verifySignatureRaw(c,i,r,o)},coinjs.verifySignatureRaw=function(t,e,n,i){var r=EllipticCurve.getSECCurveByName("secp256k1"),o=r.getN(),s=r.getG();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(o)>=0)return!1;if(n.compareTo(BigInteger.ONE)<0||n.compareTo(o)>=0)return!1;var a=n.modInverse(o),c=t.multiply(a).mod(o),u=e.multiply(a).mod(o);return s.multiply(c).add(i.multiply(u)).getX().toBigInteger().mod(o).equals(e)};var canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function BigInteger(t,e,n){if(!(this instanceof BigInteger))return new BigInteger(t,e,n);null!=t&&("number"==typeof t?this.fromNumber(t,e,n):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}var proto=BigInteger.prototype;function nbi(){return new BigInteger(null)}function am1(t,e,n,i,r,o){for(;--o>=0;){var s=e*this[t++]+n[i]+r;r=Math.floor(s/67108864),n[i++]=67108863&s}return r}function am2(t,e,n,i,r,o){for(var s=32767&e,a=e>>15;--o>=0;){var c=32767&this[t],u=this[t++]>>15,l=a*c+u*s;r=((c=s*c+((32767&l)<<15)+n[i]+(1073741823&r))>>>30)+(l>>>15)+a*u+(r>>>30),n[i++]=1073741823&c}return r}function am3(t,e,n,i,r,o){for(var s=16383&e,a=e>>14;--o>=0;){var c=16383&this[t],u=this[t++]>>14,l=a*c+u*s;r=((c=s*c+((16383&l)<<14)+n[i]+r)>>28)+(l>>14)+a*u,n[i++]=268435455&c}return r}BigInteger.prototype.am=am1,dbits=26,BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1;var DV=BigInteger.prototype.DV=1<<dbits,BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP),BigInteger.prototype.F1=BI_FP-dbits,BigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,e){var n=BI_RC[t.charCodeAt(e)];return null==n?-1:n}function bnpCopyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+DV:this.t=0}function nbv(t){var e=nbi();return e.fromInt(t),e}function bnpFromString(t,e){var n,i=this;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void i.fromRadix(t,e);n=2}i.t=0,i.s=0;for(var r=t.length,o=!1,s=0;--r>=0;){var a=8==n?255&t[r]:intAt(t,r);a<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==s?i[i.t++]=a:s+n>i.DB?(i[i.t-1]|=(a&(1<<i.DB-s)-1)<<s,i[i.t++]=a>>i.DB-s):i[i.t-1]|=a<<s,(s+=n)>=i.DB&&(s-=i.DB))}8==n&&0!=(128&t[0])&&(i.s=-1,s>0&&(i[i.t-1]|=(1<<i.DB-s)-1<<s)),i.clamp(),o&&BigInteger.ZERO.subTo(i,i)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){var e,n=this;if(n.s<0)return"-"+n.negate().toString(t);if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return n.toRadix(t);e=2}var i,r=(1<<e)-1,o=!1,s="",a=n.t,c=n.DB-a*n.DB%e;if(a-- >0)for(c<n.DB&&(i=n[a]>>c)>0&&(o=!0,s=int2char(i));a>=0;)c<e?(i=(n[a]&(1<<c)-1)<<e-c,i|=n[--a]>>(c+=n.DB-e)):(i=n[a]>>(c-=e)&r,c<=0&&(c+=n.DB,--a)),i>0&&(o=!0),o&&(s+=int2char(i));return o?s:"0"}function bnNegate(){var t=nbi();return BigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var e=this.s-t.s;if(0!=e)return e;var n=this.t;if(0!=(e=n-t.t))return this.s<0?-e:e;for(;--n>=0;)if(0!=(e=this[n]-t[n]))return e;return 0}function nbits(t){var e,n=1;return 0!=(e=t>>>16)&&(t=e,n+=16),0!=(e=t>>8)&&(t=e,n+=8),0!=(e=t>>4)&&(t=e,n+=4),0!=(e=t>>2)&&(t=e,n+=2),0!=(e=t>>1)&&(t=e,n+=1),n}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,e){var n;for(n=this.t-1;n>=0;--n)e[n+t]=this[n];for(n=t-1;n>=0;--n)e[n]=0;e.t=this.t+t,e.s=this.s}function bnpDRShiftTo(t,e){for(var n=t;n<this.t;++n)e[n-t]=this[n];e.t=Math.max(this.t-t,0),e.s=this.s}function bnpLShiftTo(t,e){var n,i=this,r=t%i.DB,o=i.DB-r,s=(1<<o)-1,a=Math.floor(t/i.DB),c=i.s<<r&i.DM;for(n=i.t-1;n>=0;--n)e[n+a+1]=i[n]>>o|c,c=(i[n]&s)<<r;for(n=a-1;n>=0;--n)e[n]=0;e[a]=c,e.t=i.t+a+1,e.s=i.s,e.clamp()}function bnpRShiftTo(t,e){var n=this;e.s=n.s;var i=Math.floor(t/n.DB);if(i>=n.t)e.t=0;else{var r=t%n.DB,o=n.DB-r,s=(1<<r)-1;e[0]=n[i]>>r;for(var a=i+1;a<n.t;++a)e[a-i-1]|=(n[a]&s)<<o,e[a-i]=n[a]>>r;r>0&&(e[n.t-i-1]|=(n.s&s)<<o),e.t=n.t-i,e.clamp()}}function bnpSubTo(t,e){for(var n=this,i=0,r=0,o=Math.min(t.t,n.t);i<o;)r+=n[i]-t[i],e[i++]=r&n.DM,r>>=n.DB;if(t.t<n.t){for(r-=t.s;i<n.t;)r+=n[i],e[i++]=r&n.DM,r>>=n.DB;r+=n.s}else{for(r+=n.s;i<t.t;)r-=t[i],e[i++]=r&n.DM,r>>=n.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[i++]=n.DV+r:r>0&&(e[i++]=r),e.t=i,e.clamp()}function bnpMultiplyTo(t,e){var n=this.abs(),i=t.abs(),r=n.t;for(e.t=r+i.t;--r>=0;)e[r]=0;for(r=0;r<i.t;++r)e[r+n.t]=n.am(0,i[r],e,r,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&BigInteger.ZERO.subTo(e,e)}function bnpSquareTo(t){for(var e=this.abs(),n=t.t=2*e.t;--n>=0;)t[n]=0;for(n=0;n<e.t-1;++n){var i=e.am(n,e[n],t,2*n,0,1);(t[n+e.t]+=e.am(n+1,2*e[n],t,2*n+1,i,e.t-n-1))>=e.DV&&(t[n+e.t]-=e.DV,t[n+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(n,e[n],t,2*n,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,e,n){var i=this,r=t.abs();if(!(r.t<=0)){var o=i.abs();if(o.t<r.t)return null!=e&&e.fromInt(0),void(null!=n&&i.copyTo(n));null==n&&(n=nbi());var s=nbi(),a=i.s,c=t.s,u=i.DB-nbits(r[r.t-1]);u>0?(r.lShiftTo(u,s),o.lShiftTo(u,n)):(r.copyTo(s),o.copyTo(n));var l=s.t,p=s[l-1];if(0!=p){var h=p*(1<<i.F1)+(l>1?s[l-2]>>i.F2:0),f=i.FV/h,d=(1<<i.F1)/h,y=1<<i.F2,_=n.t,g=_-l,m=null==e?nbi():e;for(s.dlShiftTo(g,m),n.compareTo(m)>=0&&(n[n.t++]=1,n.subTo(m,n)),BigInteger.ONE.dlShiftTo(l,m),m.subTo(s,s);s.t<l;)s[s.t++]=0;for(;--g>=0;){var b=n[--_]==p?i.DM:Math.floor(n[_]*f+(n[_-1]+y)*d);if((n[_]+=s.am(0,b,n,g,0,l))<b)for(s.dlShiftTo(g,m),n.subTo(m,n);n[_]<--b;)n.subTo(m,n)}null!=e&&(n.drShiftTo(l,e),a!=c&&BigInteger.ZERO.subTo(e,e)),n.t=l,n.clamp(),u>0&&n.rShiftTo(u,n),a<0&&BigInteger.ZERO.subTo(n,n)}}}function bnMod(t){var e=nbi();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(BigInteger.ZERO)>0&&t.subTo(e,e),e}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function cSqrTo(t,e){t.squareTo(e),this.reduce(e)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var e=nbi();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(BigInteger.ZERO)>0&&this.m.subTo(e,e),e}function montRevert(t){var e=nbi();return t.copyTo(e),this.reduce(e),e}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var n=32767&t[e],i=n*this.mpl+((n*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=e+this.m.t]+=this.m.am(0,i,t,e,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,e){t.squareTo(e),this.reduce(e)}function montMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,e){if(t>4294967295||t<1)return BigInteger.ONE;var n=nbi(),i=nbi(),r=e.convert(this),o=nbits(t)-1;for(r.copyTo(n);--o>=0;)if(e.sqrTo(n,i),(t&1<<o)>0)e.mulTo(i,r,n);else{var s=n;n=i,i=s}return e.revert(n)}function bnModPowInt(t,e){var n;return n=t<256||e.isEven()?new Classic(e):new Montgomery(e),this.exp(t,n)}function nbi(){return new BigInteger(null)}function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),n=Math.pow(t,e),i=nbv(n),r=nbi(),o=nbi(),s="";for(this.divRemTo(i,r,o);r.signum()>0;)s=(n+o.intValue()).toString(t).substr(1)+s,r.divRemTo(i,r,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,e){var n=this;n.fromInt(0),null==e&&(e=10);for(var i=n.chunkSize(e),r=Math.pow(e,i),o=!1,s=0,a=0,c=0;c<t.length;++c){var u=intAt(t,c);u<0?"-"==t.charAt(c)&&0==n.signum()&&(o=!0):(a=e*a+u,++s>=i&&(n.dMultiply(r),n.dAddOffset(a,0),s=0,a=0))}s>0&&(n.dMultiply(Math.pow(e,s)),n.dAddOffset(a,0)),o&&BigInteger.ZERO.subTo(n,n)}function bnpFromNumber(t,e,n){var i=this;if("number"==typeof e)if(t<2)i.fromInt(1);else for(i.fromNumber(t,n),i.testBit(t-1)||i.bitwiseTo(BigInteger.ONE.shiftLeft(t-1),op_or,i),i.isEven()&&i.dAddOffset(1,0);!i.isProbablePrime(e);)i.dAddOffset(2,0),i.bitLength()>t&&i.subTo(BigInteger.ONE.shiftLeft(t-1),i);else{var r=new Array,o=7&t;r.length=1+(t>>3),e.nextBytes(r),o>0?r[0]&=(1<<o)-1:r[0]=0,i.fromString(r,256)}}function bnToByteArray(){var t=this,e=t.t,n=new Array;n[0]=t.s;var i,r=t.DB-e*t.DB%8,o=0;if(e-- >0)for(r<t.DB&&(i=t[e]>>r)!=(t.s&t.DM)>>r&&(n[o++]=i|t.s<<t.DB-r);e>=0;)r<8?(i=(t[e]&(1<<r)-1)<<8-r,i|=t[--e]>>(r+=t.DB-8)):(i=t[e]>>(r-=8)&255,r<=0&&(r+=t.DB,--e)),0!=(128&i)&&(i|=-256),0===o&&(128&t.s)!=(128&i)&&++o,(o>0||i!=t.s)&&(n[o++]=i);return n}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,e,n){var i,r,o=this,s=Math.min(t.t,o.t);for(i=0;i<s;++i)n[i]=e(o[i],t[i]);if(t.t<o.t){for(r=t.s&o.DM,i=s;i<o.t;++i)n[i]=e(o[i],r);n.t=o.t}else{for(r=o.s&o.DM,i=s;i<t.t;++i)n[i]=e(r,t[i]);n.t=t.t}n.s=e(o.s,t.s),n.clamp()}function op_and(t,e){return t&e}function bnAnd(t){var e=nbi();return this.bitwiseTo(t,op_and,e),e}function op_or(t,e){return t|e}function bnOr(t){var e=nbi();return this.bitwiseTo(t,op_or,e),e}function op_xor(t,e){return t^e}function bnXor(t){var e=nbi();return this.bitwiseTo(t,op_xor,e),e}function op_andnot(t,e){return t&~e}function bnAndNot(t){var e=nbi();return this.bitwiseTo(t,op_andnot,e),e}function bnNot(){for(var t=nbi(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var e=nbi();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function bnShiftRight(t){var e=nbi();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function lbit(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function bnBitCount(){for(var t=0,e=this.s&this.DM,n=0;n<this.t;++n)t+=cbit(this[n]^e);return t}function bnTestBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)}function bnpChangeBit(t,e){var n=BigInteger.ONE.shiftLeft(t);return this.bitwiseTo(n,e,n),n}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,e){for(var n=this,i=0,r=0,o=Math.min(t.t,n.t);i<o;)r+=n[i]+t[i],e[i++]=r&n.DM,r>>=n.DB;if(t.t<n.t){for(r+=t.s;i<n.t;)r+=n[i],e[i++]=r&n.DM,r>>=n.DB;r+=n.s}else{for(r+=n.s;i<t.t;)r+=t[i],e[i++]=r&n.DM,r>>=n.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[i++]=r:r<-1&&(e[i++]=n.DV+r),e.t=i,e.clamp()}function bnAdd(t){var e=nbi();return this.addTo(t,e),e}function bnSubtract(t){var e=nbi();return this.subTo(t,e),e}function bnMultiply(t){var e=nbi();return this.multiplyTo(t,e),e}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var e=nbi();return this.divRemTo(t,e,null),e}function bnRemainder(t){var e=nbi();return this.divRemTo(t,null,e),e}function bnDivideAndRemainder(t){var e=nbi(),n=nbi();return this.divRemTo(t,e,n),new Array(e,n)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,e,n){t.multiplyTo(e,n)}function nSqrTo(t,e){t.squareTo(e)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,e,n){var i,r=Math.min(this.t+t.t,e);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,t[r],n,r,0,this.t);for(i=Math.min(t.t,e);r<i;++r)this.am(0,t[r],n,r,0,e-r);n.clamp()}function bnpMultiplyUpperTo(t,e,n){--e;var i=n.t=this.t+t.t-e;for(n.s=0;--i>=0;)n[i]=0;for(i=Math.max(e-this.t,0);i<t.t;++i)n[this.t+i-e]=this.am(e-i,t[i],n,0,0,this.t+i-e);n.clamp(),n.drShiftTo(1,n)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=nbi();return t.copyTo(e),this.reduce(e),e}function barrettRevert(t){return t}function barrettReduce(t){var e=this;for(t.drShiftTo(e.m.t-1,e.r2),t.t>e.m.t+1&&(t.t=e.m.t+1,t.clamp()),e.mu.multiplyUpperTo(e.r2,e.m.t+1,e.q3),e.m.multiplyLowerTo(e.q3,e.m.t+1,e.r2);t.compareTo(e.r2)<0;)t.dAddOffset(1,e.m.t+1);for(t.subTo(e.r2,t);t.compareTo(e.m)>=0;)t.subTo(e.m,t)}function barrettSqrTo(t,e){t.squareTo(e),this.reduce(e)}function barrettMulTo(t,e,n){t.multiplyTo(e,n),this.reduce(n)}function bnModPow(t,e){var n,i,r=t.bitLength(),o=nbv(1);if(r<=0)return o;n=r<18?1:r<48?3:r<144?4:r<768?5:6,i=r<8?new Classic(e):e.isEven()?new Barrett(e):new Montgomery(e);var s=new Array,a=3,c=n-1,u=(1<<n)-1;if(s[1]=i.convert(this),n>1){var l=nbi();for(i.sqrTo(s[1],l);a<=u;)s[a]=nbi(),i.mulTo(l,s[a-2],s[a]),a+=2}var p,h,f=t.t-1,d=!0,y=nbi();for(r=nbits(t[f])-1;f>=0;){for(r>=c?p=t[f]>>r-c&u:(p=(t[f]&(1<<r+1)-1)<<c-r,f>0&&(p|=t[f-1]>>this.DB+r-c)),a=n;0==(1&p);)p>>=1,--a;if((r-=a)<0&&(r+=this.DB,--f),d)s[p].copyTo(o),d=!1;else{for(;a>1;)i.sqrTo(o,y),i.sqrTo(y,o),a-=2;a>0?i.sqrTo(o,y):(h=o,o=y,y=h),i.mulTo(y,s[p],o)}for(;f>=0&&0==(t[f]&1<<r);)i.sqrTo(o,y),h=o,o=y,y=h,--r<0&&(r=this.DB-1,--f)}return i.revert(o)}function bnGCD(t){var e=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(e.compareTo(n)<0){var i=e;e=n,n=i}var r=e.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return e;for(r<o&&(o=r),o>0&&(e.rShiftTo(o,e),n.rShiftTo(o,n));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=n.getLowestSetBit())>0&&n.rShiftTo(r,n),e.compareTo(n)>=0?(e.subTo(n,e),e.rShiftTo(1,e)):(n.subTo(e,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n}function bnpModInt(t){if(t<=0)return 0;var e=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==e)n=this[0]%t;else for(var i=this.t-1;i>=0;--i)n=(e*n+this[i])%t;return n}function bnModInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return BigInteger.ZERO;for(var n=t.clone(),i=this.clone(),r=nbv(1),o=nbv(0),s=nbv(0),a=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),e?(r.isEven()&&o.isEven()||(r.addTo(this,r),o.subTo(t,o)),r.rShiftTo(1,r)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;i.isEven();)i.rShiftTo(1,i),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);n.compareTo(i)>=0?(n.subTo(i,n),e&&r.subTo(s,r),o.subTo(a,o)):(i.subTo(n,i),e&&s.subTo(r,s),a.subTo(o,a))}return 0!=i.compareTo(BigInteger.ONE)?BigInteger.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,proto.copyTo=bnpCopyTo,proto.fromInt=bnpFromInt,proto.fromString=bnpFromString,proto.clamp=bnpClamp,proto.dlShiftTo=bnpDLShiftTo,proto.drShiftTo=bnpDRShiftTo,proto.lShiftTo=bnpLShiftTo,proto.rShiftTo=bnpRShiftTo,proto.subTo=bnpSubTo,proto.multiplyTo=bnpMultiplyTo,proto.squareTo=bnpSquareTo,proto.divRemTo=bnpDivRemTo,proto.invDigit=bnpInvDigit,proto.isEven=bnpIsEven,proto.exp=bnpExp,proto.toString=bnToString,proto.negate=bnNegate,proto.abs=bnAbs,proto.compareTo=bnCompareTo,proto.bitLength=bnBitLength,proto.mod=bnMod,proto.modPowInt=bnModPowInt,NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo,proto.chunkSize=bnpChunkSize,proto.toRadix=bnpToRadix,proto.fromRadix=bnpFromRadix,proto.fromNumber=bnpFromNumber,proto.bitwiseTo=bnpBitwiseTo,proto.changeBit=bnpChangeBit,proto.addTo=bnpAddTo,proto.dMultiply=bnpDMultiply,proto.dAddOffset=bnpDAddOffset,proto.multiplyLowerTo=bnpMultiplyLowerTo,proto.multiplyUpperTo=bnpMultiplyUpperTo,proto.modInt=bnpModInt,proto.clone=bnClone,proto.intValue=bnIntValue,proto.byteValue=bnByteValue,proto.shortValue=bnShortValue,proto.signum=bnSigNum,proto.toByteArray=bnToByteArray,proto.equals=bnEquals,proto.min=bnMin,proto.max=bnMax,proto.and=bnAnd,proto.or=bnOr,proto.xor=bnXor,proto.andNot=bnAndNot,proto.not=bnNot,proto.shiftLeft=bnShiftLeft,proto.shiftRight=bnShiftRight,proto.getLowestSetBit=bnGetLowestSetBit,proto.bitCount=bnBitCount,proto.testBit=bnTestBit,proto.setBit=bnSetBit,proto.clearBit=bnClearBit,proto.flipBit=bnFlipBit,proto.add=bnAdd,proto.subtract=bnSubtract,proto.multiply=bnMultiply,proto.divide=bnDivide,proto.remainder=bnRemainder,proto.divideAndRemainder=bnDivideAndRemainder,proto.modPow=bnModPow,proto.modInverse=bnModInverse,proto.pow=bnPow,proto.gcd=bnGCD,proto.square=bnSquare,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),BigInteger.valueOf=nbv,BigInteger.fromByteArrayUnsigned=function(t){return t.length?128&t[0]?new BigInteger([0].concat(t)):new BigInteger(t):new BigInteger.valueOf(0)},BigInteger.fromByteArraySigned=function(t){return 128&t[0]?(t[0]&=127,BigInteger.fromByteArrayUnsigned(t).negate()):BigInteger.fromByteArrayUnsigned(t)},BigInteger.prototype.toByteArrayUnsigned=function(){var t=this.abs().toByteArray();if(!t.length)return t;0===t[0]&&(t=t.slice(1));for(var e=0;e<t.length;++e)t[e]=t[e]<0?t[e]+256:t[e];return t},BigInteger.prototype.toByteArraySigned=function(){var t=this.toByteArrayUnsigned(),e=this.s<0;return 128&t[0]?t.unshift(e?128:0):e&&(t[0]|=128),t},("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=(255&t[n])<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var i=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,i=0;n<t.length;i=++n%4)0!=i&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n-1))&Math.pow(2,-2*i+8)-1)<<2*i|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n))>>>6-2*i);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))}};var n=t.Binary={stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary,o=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],s=t.SHA256=function(t,n){var i=e.wordsToBytes(s._sha256(t));return n&&n.asBytes?i:n&&n.asString?r.bytesToString(i):e.bytesToHex(i)};s._sha256=function(t){t.constructor==String&&(t=i.stringToBytes(t));var n,r,s,a,c,u,l,p,h,f,d,y=e.bytesToWords(t),_=8*t.length,g=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(y[_>>5]|=128<<24-_%32,y[15+(_+64>>9<<4)]=_,p=0;p<y.length;p+=16){for(_=t[0],n=t[1],r=t[2],s=t[3],a=t[4],c=t[5],u=t[6],l=t[7],h=0;h<64;h++){h<16?g[h]=y[h+p]:(f=g[h-15],d=g[h-2],g[h]=((f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3)+(g[h-7]>>>0)+((d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10)+(g[h-16]>>>0)),d=_&n^_&r^n&r;var m=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22);f=(l>>>0)+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&c^~a&u)+o[h]+(g[h]>>>0),l=u,u=c,c=a,a=s+f>>>0,s=r,r=n,n=_,_=f+(d=m+d)>>>0}t[0]+=_,t[1]+=n,t[2]+=r,t[3]+=s,t[4]+=a,t[5]+=c,t[6]+=u,t[7]+=l}return t},s._blocksize=16,s._digestsize=32}(),("undefined"==typeof Crypto||!Crypto.util)&&function(){var t,e=(t=window.Crypto={}).util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&e.rotl(t,8)|4278255360&e.rotl(t,24);for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=(255&t[n])<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var i=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,i=0;n<t.length;i=++n%4)0!=i&&e.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n-1))&Math.pow(2,-2*i+8)-1)<<2*i|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t.charAt(n))>>>6-2*i);return e}};(t=t.charenc={}).UTF8={stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))}};var n=t.Binary={stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary,o=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],s=t.SHA256=function(t,n){var i=e.wordsToBytes(s._sha256(t));return n&&n.asBytes?i:n&&n.asString?r.bytesToString(i):e.bytesToHex(i)};s._sha256=function(t){t.constructor==String&&(t=i.stringToBytes(t));var n,r,s,a,c,u,l,p,h,f,d,y=e.bytesToWords(t),_=8*t.length,g=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(y[_>>5]|=128<<24-_%32,y[15+(_+64>>9<<4)]=_,p=0;p<y.length;p+=16){for(_=t[0],n=t[1],r=t[2],s=t[3],a=t[4],c=t[5],u=t[6],l=t[7],h=0;h<64;h++){h<16?g[h]=y[h+p]:(f=g[h-15],d=g[h-2],g[h]=((f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3)+(g[h-7]>>>0)+((d<<15|d>>>17)^(d<<13|d>>>19)^d>>>10)+(g[h-16]>>>0)),d=_&n^_&r^n&r;var m=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22);f=(l>>>0)+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&c^~a&u)+o[h]+(g[h]>>>0),l=u,u=c,c=a,a=s+f>>>0,s=r,r=n,n=_,_=f+(d=m+d)>>>0}t[0]+=_,t[1]+=n,t[2]+=r,t[3]+=s,t[4]+=a,t[5]+=c,t[6]+=u,t[7]+=l}return t},s._blocksize=16,s._digestsize=32}(),function(){var t=Crypto,e=t.util,n=t.charenc,i=n.UTF8,r=n.Binary;t.HMAC=function(t,n,o,s){n.constructor==String&&(n=i.stringToBytes(n)),o.constructor==String&&(o=i.stringToBytes(o)),o.length>4*t._blocksize&&(o=t(o,{asBytes:!0}));for(var a=o.slice(0),c=(o=o.slice(0),0);c<4*t._blocksize;c++)a[c]^=92,o[c]^=54;return t=t(a.concat(t(o.concat(n),{asBytes:!0})),{asBytes:!0}),s&&s.asBytes?t:s&&s.asString?r.bytesToString(t):e.bytesToHex(t)}}(),function(){var t=window.EllipticCurve=function(){};t.FieldElementFp=function(t,e){this.x=e,this.q=t},t.FieldElementFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},t.FieldElementFp.prototype.toBigInteger=function(){return this.x},t.FieldElementFp.prototype.negate=function(){return new t.FieldElementFp(this.q,this.x.negate().mod(this.q))},t.FieldElementFp.prototype.add=function(e){return new t.FieldElementFp(this.q,this.x.add(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.subtract=function(e){return new t.FieldElementFp(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.multiply=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))},t.FieldElementFp.prototype.square=function(){return new t.FieldElementFp(this.q,this.x.square().mod(this.q))},t.FieldElementFp.prototype.divide=function(e){return new t.FieldElementFp(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))},t.FieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},t.FieldElementFp.prototype.sqrt=function(){if(!this.q.testBit(0))throw new Error("even value of q");if(this.q.testBit(1)){var e=new t.FieldElementFp(this.q,this.x.modPow(this.q.shiftRight(2).add(BigInteger.ONE),this.q));return e.square().equals(this)?e:null}var n=this.q.subtract(BigInteger.ONE),i=n.shiftRight(1);if(!this.x.modPow(i,this.q).equals(BigInteger.ONE))return null;var r,o,s=n.shiftRight(2).shiftLeft(1).add(BigInteger.ONE),a=this.x,c=a.shiftLeft(2).mod(this.q);do{var u,l=new SecureRandom;do{u=new BigInteger(this.q.bitLength(),l)}while(u.compareTo(this.q)>=0||!u.multiply(u).subtract(c).modPow(i,this.q).equals(n));var p=t.FieldElementFp.fastLucasSequence(this.q,u,a,s);if(r=p[0],(o=p[1]).multiply(o).mod(this.q).equals(c))return o.testBit(0)&&(o=o.add(this.q)),o=o.shiftRight(1),new t.FieldElementFp(this.q,o)}while(r.equals(BigInteger.ONE)||r.equals(n));return null},t.FieldElementFp.fastLucasSequence=function(t,e,n,i){for(var r=i.bitLength(),o=i.getLowestSetBit(),s=BigInteger.ONE,a=BigInteger.TWO,c=e,u=BigInteger.ONE,l=BigInteger.ONE,p=r-1;p>=o+1;--p)u=u.multiply(l).mod(t),i.testBit(p)?(l=u.multiply(n).mod(t),s=s.multiply(c).mod(t),a=c.multiply(a).subtract(e.multiply(u)).mod(t),c=c.multiply(c).subtract(l.shiftLeft(1)).mod(t)):(l=u,s=s.multiply(a).subtract(u).mod(t),c=c.multiply(a).subtract(e.multiply(u)).mod(t),a=a.multiply(a).subtract(u.shiftLeft(1)).mod(t));l=(u=u.multiply(l).mod(t)).multiply(n).mod(t),s=s.multiply(a).subtract(u).mod(t),a=c.multiply(a).subtract(e.multiply(u)).mod(t),u=u.multiply(l).mod(t);for(p=1;p<=o;++p)s=s.multiply(a).mod(t),a=a.multiply(a).subtract(u.shiftLeft(1)).mod(t),u=u.multiply(u).mod(t);return[s,a]},t.PointFp=function(t,e,n,i,r){this.curve=t,this.x=e,this.y=n,this.z=null==i?BigInteger.ONE:i,this.zinv=null,this.compressed=!!r},t.PointFp.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},t.PointFp.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(BigInteger.ZERO))},t.PointFp.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)},t.PointFp.prototype.negate=function(){return new t.PointFp(this.curve,this.x,this.y.negate(),this.z)},t.PointFp.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var n=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),i=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(i))return BigInteger.ZERO.equals(n)?this.twice():this.curve.getInfinity();var r=new BigInteger("3"),o=this.x.toBigInteger(),s=this.y.toBigInteger(),a=(e.x.toBigInteger(),e.y.toBigInteger(),i.square()),c=a.multiply(i),u=o.multiply(a),l=n.square().multiply(this.z),p=l.subtract(u.shiftLeft(1)).multiply(e.z).subtract(c).multiply(i).mod(this.curve.q),h=u.multiply(r).multiply(n).subtract(s.multiply(c)).subtract(l.multiply(n)).multiply(e.z).add(n.multiply(c)).mod(this.curve.q),f=c.multiply(this.z).multiply(e.z).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(h),f)},t.PointFp.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=new BigInteger("3"),n=this.x.toBigInteger(),i=this.y.toBigInteger(),r=i.multiply(this.z),o=r.multiply(i).mod(this.curve.q),s=this.curve.a.toBigInteger(),a=n.square().multiply(e);BigInteger.ZERO.equals(s)||(a=a.add(this.z.square().multiply(s)));var c=(a=a.mod(this.curve.q)).square().subtract(n.shiftLeft(3).multiply(o)).shiftLeft(1).multiply(r).mod(this.curve.q),u=a.multiply(e).multiply(n).subtract(o.shiftLeft(1)).shiftLeft(2).multiply(o).subtract(a.square().multiply(a)).mod(this.curve.q),l=r.square().multiply(r).shiftLeft(3).mod(this.curve.q);return new t.PointFp(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(u),l)},t.PointFp.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,n=t,i=n.multiply(new BigInteger("3")),r=this.negate(),o=this;for(e=i.bitLength()-2;e>0;--e){o=o.twice();var s=i.testBit(e);s!=n.testBit(e)&&(o=o.add(s?this:r))}return o},t.PointFp.prototype.multiplyTwo=function(t,e,n){var i;i=t.bitLength()>n.bitLength()?t.bitLength()-1:n.bitLength()-1;for(var r=this.curve.getInfinity(),o=this.add(e);i>=0;)r=r.twice(),t.testBit(i)?r=n.testBit(i)?r.add(o):r.add(this):n.testBit(i)&&(r=r.add(e)),--i;return r},t.PointFp.prototype.getEncoded=function(e){var n=this.getX().toBigInteger(),i=this.getY().toBigInteger(),r=t.integerToBytes(n,32);return e?i.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(t.integerToBytes(i,32))),r},t.PointFp.decodeFrom=function(e,n){n[0];var i=n.length-1,r=n.slice(1,1+i/2),o=n.slice(1+i/2,1+i);r.unshift(0),o.unshift(0);var s=new BigInteger(r),a=new BigInteger(o);return new t.PointFp(e,e.fromBigInteger(s),e.fromBigInteger(a))},t.PointFp.prototype.add2D=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;if(this.x.equals(e.x))return this.y.equals(e.y)?this.twice():this.curve.getInfinity();var n=e.x.subtract(this.x),i=e.y.subtract(this.y).divide(n),r=i.square().subtract(this.x).subtract(e.x),o=i.multiply(this.x.subtract(r)).subtract(this.y);return new t.PointFp(this.curve,r,o)},t.PointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=this.curve.fromBigInteger(BigInteger.valueOf(2)),n=this.curve.fromBigInteger(BigInteger.valueOf(3)),i=this.x.square().multiply(n).add(this.curve.a).divide(this.y.multiply(e)),r=i.square().subtract(this.x.multiply(e)),o=i.multiply(this.x.subtract(r)).subtract(this.y);return new t.PointFp(this.curve,r,o)},t.PointFp.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,n=t,i=n.multiply(new BigInteger("3")),r=this.negate(),o=this;for(e=i.bitLength()-2;e>0;--e){o=o.twice();var s=i.testBit(e);s!=n.testBit(e)&&(o=o.add2D(s?this:r))}return o},t.PointFp.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),n=this.curve.getA().toBigInteger(),i=this.curve.getB().toBigInteger(),r=this.curve.getQ(),o=e.multiply(e).mod(r),s=t.multiply(t).multiply(t).add(n.multiply(t)).add(i).mod(r);return o.equals(s)},t.PointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},t.PointFp.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),n=this.getY().toBigInteger();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(n.compareTo(BigInteger.ONE)<0||n.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},t.CurveFp=function(e,n,i){this.q=e,this.a=this.fromBigInteger(n),this.b=this.fromBigInteger(i),this.infinity=new t.PointFp(this,null,null),this.reducer=new Barrett(this.q)},t.CurveFp.prototype.getQ=function(){return this.q},t.CurveFp.prototype.getA=function(){return this.a},t.CurveFp.prototype.getB=function(){return this.b},t.CurveFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},t.CurveFp.prototype.getInfinity=function(){return this.infinity},t.CurveFp.prototype.fromBigInteger=function(e){return new t.FieldElementFp(this.q,e)},t.CurveFp.prototype.reduce=function(t){this.reducer.reduce(t)},t.CurveFp.prototype.decodePointHex=function(e){var n=parseInt(e.substr(0,2),16);switch(n){case 0:return this.infinity;case 2:case 3:var i=1&n,r=new BigInteger(s=e.substr(2,e.length-2),16);return this.decompressPoint(i,r);case 4:case 6:case 7:var o=(e.length-2)/2,s=e.substr(2,o),a=e.substr(o+2,o);return new t.PointFp(this,this.fromBigInteger(new BigInteger(s,16)),this.fromBigInteger(new BigInteger(a,16)));default:return null}},t.CurveFp.prototype.encodePointHex=function(t){if(t.isInfinity())return"00";var e=t.getX().toBigInteger().toString(16),n=t.getY().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;e.length<i;)e="0"+e;for(;n.length<i;)n="0"+n;return"04"+e+n},t.CurveFp.prototype.decompressPoint=function(e,n){var i=this.fromBigInteger(n),r=i.multiply(i.square().add(this.getA())).add(this.getB()).sqrt();if(null==r)throw new Error("Invalid point compression");var o=r.toBigInteger();return(o.testBit(0)?1:0)!=e&&(r=this.fromBigInteger(this.getQ().subtract(o))),new t.PointFp(this,i,r,null,!0)},t.fromHex=function(t){return new BigInteger(t,16)},t.integerToBytes=function(t,e){var n=t.toByteArrayUnsigned();if(e<n.length)n=n.slice(n.length-e);else for(;e>n.length;)n.unshift(0);return n},t.X9Parameters=function(t,e,n,i){this.curve=t,this.g=e,this.n=n,this.h=i},t.X9Parameters.prototype.getCurve=function(){return this.curve},t.X9Parameters.prototype.getG=function(){return this.g},t.X9Parameters.prototype.getN=function(){return this.n},t.X9Parameters.prototype.getH=function(){return this.h},t.secNamedCurves={secp256k1:function(){var e=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),n=BigInteger.ZERO,i=t.fromHex("7"),r=t.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),o=BigInteger.ONE,s=new t.CurveFp(e,n,i),a=s.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new t.X9Parameters(s,a,r,o)}},t.getSECCurveByName=function(e){return null==t.secNamedCurves[e]?null:t.secNamedCurves[e]()}}();var zl=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],zr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],sl=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],sr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],hl=[0,1518500249,1859775393,2400959708,2840853838],hr=[1352829926,1548603684,1836072691,2053994217,0],bytesToWords=function(t){for(var e=[],n=0,i=0;n<t.length;n++,i+=8)e[i>>>5]|=t[n]<<24-i%32;return e},wordsToBytes=function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},processBlock=function(t,e,n){for(var i=0;i<16;i++){var r=n+i,o=e[r];e[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}var s,a,c,u,l,p,h,f,d,y,_;p=s=t[0],h=a=t[1],f=c=t[2],d=u=t[3],y=l=t[4];for(i=0;i<80;i+=1)_=s+e[n+zl[i]]|0,_+=i<16?f1(a,c,u)+hl[0]:i<32?f2(a,c,u)+hl[1]:i<48?f3(a,c,u)+hl[2]:i<64?f4(a,c,u)+hl[3]:f5(a,c,u)+hl[4],_=(_=rotl(_|=0,sl[i]))+l|0,s=l,l=u,u=rotl(c,10),c=a,a=_,_=p+e[n+zr[i]]|0,_+=i<16?f5(h,f,d)+hr[0]:i<32?f4(h,f,d)+hr[1]:i<48?f3(h,f,d)+hr[2]:i<64?f2(h,f,d)+hr[3]:f1(h,f,d)+hr[4],_=(_=rotl(_|=0,sr[i]))+y|0,p=y,y=d,d=rotl(f,10),f=h,h=_;_=t[1]+c+d|0,t[1]=t[2]+u+y|0,t[2]=t[3]+l+p|0,t[3]=t[4]+s+h|0,t[4]=t[0]+a+f|0,t[0]=_};function f1(t,e,n){return t^e^n}function f2(t,e,n){return t&e|~t&n}function f3(t,e,n){return(t|~e)^n}function f4(t,e,n){return t&n|e&~n}function f5(t,e,n){return t^(e|~n)}function rotl(t,e){return t<<e|t>>>32-e}function ripemd160(t){var e=[1732584193,4023233417,2562383102,271733878,3285377520],n=bytesToWords(t),i=8*t.length,r=8*t.length;n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);for(var o=0;o<n.length;o+=16)processBlock(e,n,o);for(o=0;o<5;o++){var s=e[o];e[o]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}return wordsToBytes(e)}var ychapi={};window.ychapi=ychapi,ychapi._data={buys:{},sells:{},trades:{},markets:{}},ychapi._nnum="",ychapi._sigi_num=30,ychapi._pagesize=15,ychapi._pubkey1="",ychapi._prvkey1="",ychapi._pubkey2="",ychapi._pubkey3="",ychapi._addresses={},ychapi._locktimes1={},ychapi._locktimes2={},ychapi._asset_extra_info={},ychapi._ready_init_data=!1,console.log("ychapi init1"),ychapi._zerotxid="0000000000000000000000000000000000000000000000000000000000000000",ychapi._evm_zeroaddr="0x0000000000000000000000000000000000000000",ychapi._start=null,ychapi._call_init=null,ychapi._call_login=null,ychapi._call_logout=null,ychapi._get_coin_names=null,ychapi._get_coin_info=null,ychapi._get_markets_groups_names=null,ychapi._get_market_group=null,ychapi._get_market_group_by_coinb=null,ychapi._get_markets_names_in_group=null,ychapi._get_markets_names=null,ychapi._get_market_info=null,ychapi._get_coin_balance=null,ychapi._get_coin_usd_rate=null,ychapi._get_coin_deposits=null,ychapi._get_coin_withdrawals=null,ychapi._get_coin_txouts=null,ychapi._call_register=null,ychapi._call_get_email_from_redeem=null,ychapi._call_get_registration_login=null,ychapi._call_confirm_registration_login=null,ychapi._call_confirm_registration_2fa=null,ychapi._get_user_login_keys_v1=null,ychapi._get_user_login_pubk=null,ychapi._has_user_login_prvk=null,ychapi._get_user_signing_pubk=null,ychapi._has_user_signing_prvk=null,ychapi._set_user_login_keys=null,ychapi._has_coin_holding_address=null,ychapi._get_coin_holding_address=null,ychapi._get_coin_user_locktime=null,ychapi._get_coin_server_locktime=null,ychapi._get_coin_allowed_deposit_senders=null,ychapi._call_register_deposit_evm_address=null,ychapi._call_unregister_deposit_evm_address=null,ychapi._get_user_trading_discount=null,ychapi._get_buy_fee=null,ychapi._get_sell_fee=null,ychapi._get_user_buys=null,ychapi._get_user_sells=null,ychapi._get_user_trades=null,ychapi._get_market_buys=null,ychapi._get_market_sells=null,ychapi._get_market_trades=null,ychapi._call_buy=null,ychapi._call_sell=null,ychapi._call_buy_order_cancel=null,ychapi._call_sell_order_cancel=null,ychapi._call_get_chart_data=null,ychapi._validate_address=null,ychapi._get_withdraw_rawtx=null,ychapi._call_send=null,ychapi._create_withdraw=null,ychapi._update_withdraw=null,ychapi._set_withdraw_amount=null,ychapi._has_withdraw_inputs_stage=null,ychapi._call_withdraw_inputs_stage=null,ychapi._set_withdraw_inputs_for_debit=null,ychapi._call_withdraw=null,ychapi._call_withdraw_report_txid=null,ychapi._call_withdraw_cancel=null,ychapi._get_page_size=null,ychapi._get_evm_vault7u_abi=null,ychapi._sign_evm_vault7u_user1=null,ychapi._get_user_account_id=null,ychapi._get_user_account_login=null,ychapi._get_user_account_twofa=null,ychapi._get_user_rewards=null,ychapi._get_user_referral_invitation_code=null,ychapi._get_user_referral_invitation_title=null,ychapi._is_logged_in=null,ychapi._has_profile=null,ychapi._jsonBNparse=function(t,e){return"string"==typeof e&&/^\-?\d+n$/.test(e)?BigInt(e.slice(0,-1)):e},ychapi._ajaxcall=function(t,e,n,i){try{const r=new XMLHttpRequest;r.open(t,e,!0),r.onreadystatechange=function(){4===r.readyState&&(200===r.status?i(null,r.responseText):i(r.status+": "+r.statusText))},r.onerror=function(t){i(r.status+": "+r.statusText+" "+t)},"PUT"===t&&r.setRequestHeader("Content-Type","application/json"),r.send(n)}catch(t){i(t)}},ychapi._apicall=async function(t,e){if(null!=e&&null!=e||(e=0),"digest"in t){ychapi._init_coinjs();let e=ychapi._get_user_login_prvk();"uprvk"in t&&(e=t.uprvk);const n=ychapi._str2bytes(t.digest+ychapi._nnum),i=Crypto.SHA256(n,{asBytes:!0}),r=Crypto.SHA256(i,{asBytes:!0}),o=coinjs.privkey2wif(e),s=coinjs.signHash(o,r);t.data.usig=s}let n="PUT";return"calltype"in t&&(n=t.calltype),new Promise(((i,r)=>{ychapi._ajaxcall(n,ychapi._base_uri+t.uri,JSON.stringify(t.data,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),(function(o,s){if(o)r(o);else{const o=JSON.parse(s,ychapi._jsonBNparse);"GETRAW"==n||o.ok?i(o):0==o.ok&&"nnum"in o&&""!=o.nnum&&e<1?(ychapi._nnum=o.nnum,ychapi._apicall(t,e+1).then((function(t){i(t)})).catch((function(t){r(t)}))):r(o.error)}}))}))},ychapi._start=function(t,e){ychapi._base_uri=t,ychapi._ready_init_data=!1,ychapi._callbacks=e,ychapi._timer_reauth=setTimeout((function(){}),ychapi._timer_reauth_duration),ychapi._start_ws(),ychapi._call_init()},ychapi._do_apicall_reauth=function(){""!=ychapi._get_jwt_uid()&&ychapi._apicall({calltype:"GET",uri:"/u/reauth",data:{}}).then((function(t){document.cookie="jwt="+t.access+";SameSite=Strict",ychapi._do_ws_init()})).catch((function(t){ychapi._call_logout()}))},ychapi._get_user_login_pubk=function(){return ychapi._pubkey1},ychapi._has_user_login_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_login_prvk=function(){return ychapi._prvkey1},ychapi._get_user_signing_pubk=function(){return ychapi._pubkey1},ychapi._has_user_signing_prvk=function(){return null!=ychapi._prvkey1&&""!=ychapi._prvkey1},ychapi._get_user_signing_prvk=function(){return ychapi._prvkey1},ychapi._get_server_signing_pubk=function(){return ychapi._pubkey2},ychapi._get_credit_signing_pubk=function(){return ychapi._pubkey3},ychapi._set_user_login_keys=function(t,e){ychapi._pubkey1=t,ychapi._prvkey1=e},ychapi._get_coin_user_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes1?ychapi._locktimes1[t]:0},ychapi._get_coin_server_locktime=function(t){return null==ychapi._data.profile?0:t in ychapi._locktimes2?ychapi._locktimes2[t]:0},ychapi._get_coin_allowed_deposit_senders=function(t){return null!=ychapi._data.profile&&(t in ychapi._asset_extra_info&&"senders"in ychapi._asset_extra_info[t]?ychapi._asset_extra_info[t].senders:[])},ychapi._cleanup_email=function(t){return t.startsWith("BM-")?t:t.toLowerCase()},ychapi._get_user_login_keys_v1=function(t,e){t=ychapi._cleanup_email(t);let n=Crypto.SHA256(Crypto.SHA256(t)+Crypto.SHA256(e));return[n,ychapi._priv_to_pub(n,!0)]},ychapi._priv_to_pub=function(t,e){let n=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),i=EllipticCurve.getSECCurveByName("secp256k1").getG().multiply(n),r=i.getX().toBigInteger(),o=i.getY().toBigInteger(),s=EllipticCurve.integerToBytes(r,32);if(s=s.concat(EllipticCurve.integerToBytes(o,32)),s.unshift(4),1==e){let t=EllipticCurve.integerToBytes(r,32);return o.isEven()?t.unshift(2):t.unshift(3),Crypto.util.bytesToHex(t)}return Crypto.util.bytesToHex(s)},ychapi._init_coinjs=function(t){coinjs.pub=[111],coinjs.priv=[239],coinjs.multisig=[196],coinjs.base32pref="",coinjs.compressed=!1,coinjs.txversion=1,coinjs.shf=0,coinjs.maxrbf=0,coinjs.txExtraTimeField=0;const e=ychapi._get_coin_info(t);if(null==e)return;if("peg_t1"!=e.type&&"txout_t1"!=e.type)return;const n=e.cfg;if(""==n.pub)return;const i=Crypto.util.hexToBytes(n.pub),r=Crypto.util.hexToBytes(n.prv),o=Crypto.util.hexToBytes(n.msig);coinjs.pub=i,coinjs.priv=r,coinjs.multisig=o,coinjs.base32pref=n.pref,coinjs.compressed=n.comp,coinjs.txversion=n.txver,coinjs.txExtraTimeField=n.txtime,coinjs.shf=n.shf,coinjs.maxrbf=n.maxrbf},ychapi._get_txouts_selection=function(t,e){let n=[],i=0n,r=0n,o=0n,s=0n;if(t.forEach((function(t,e){s+=t.free})),s<e)return console.log("ych_select_txouts, free",s," is less than amount",e),[n,-1,-1,-1];for(;i<e;){for(let s=0;s<t.length;s++){let a=t[s];if(s+1==t.length){n.push(a),a.selected=a.free,i+=a.free,r+=a.orders,o+=a.filled,t=t.slice(0,s);break}if(i+a.free>=e){n.push(a),a.selected=a.free,i+=a.free,r+=a.orders,o+=a.filled,t.splice(s,1);break}if(i>=e)break}if(i<e&&0==t.length)return console.log("ych_select_txouts, no fit",i,e),[n,-1,-1,-1]}return i>e&&n.length>0&&(txout=n[0],txout.selected-=i-e),[n,i,r,o]},ychapi._sign_txout_t1=function(t){if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const e=t.coin,n=ychapi._get_coin_holding_address(e);if(""==n)return[null,"Not change address"];const i=ychapi._get_coin_info(e);if(null==i)return[null,"No coininfo"];const r=i.fee.minamount;if("txout_t1"!=i.type)return[null,"Not supported"];if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];let o=t.free-t.selected,s=t.amount-o;s<r&&(s=r),s>t.amount&&(s=t.amount),o=t.amount-s;let a=t.amount-t.filled-o;a<r&&(a=r),a>t.amount-t.filled&&(a=t.amount-t.filled),o=t.amount-t.filled-a;let c={};if(c.txid=t.txid,c.nout=t.nout,c.amnt=t.amount,c.fill=t.filled,c.usea=t.selected,o>=r){const e=ychapi._sign_txout_t1_multipos(t,n,o);return 0==e.length?[null,"Fail to sign change"]:(c.sigv=o,c.siga=n,c.sigs=e,c.sigf="",[c,null])}const u=ychapi._sign_txout_t1_full(t);return 0==u.length?[null,"Fail to sign txout"]:(c.sigv=0n,c.siga="",c.sigs=[],c.sigf=u,[c,null])},ychapi._sign_txout_t1_hash=function(t,e,n){const i=t.coin;if(""==t.txid)return[null,"Txid is empty"];if(t.nout<0)return[null,"Nout is not valid"];const r=ychapi._get_coin_info(i);if(null==r)return[null,"No coininfo "+i];if("txout_t1"==r.type){if(""==t.addr.rdsc)return[null,"Redeem script is not valid"];ychapi._init_coinjs(i);const r=1;let o=coinjs.transaction();const s=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),a=o.transactionSig(e,s,r,Crypto.util.hexToBytes(n)),c="",u=0n;return[{txid:t.txid,nout:t.nout,amnt:t.amount,fill:t.filled,usea:t.selected,sigf:a,sign:c,sigv:u},null]}return[null,"Not supported coin "+i]},ychapi._sign_txout_t1_full=function(t){const e=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];const n=ychapi._get_coin_info(e);if(null==n)return console.log("No coininfo",e),[];if("txout_t1"==n.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(e);let n=null;coinjs.maxrbf>0&&(n=coinjs.maxrbf-1);const i=130;let r=coinjs.transaction();r.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),n,t.amount);let o=r.transactionHash(0,i);if(2==t.addr.vers){o=r.transactionHashSegWitV0(0,t.addr.rdsc,i,Number(t.amount)).hash}const s=coinjs.privkey2wif(ychapi._get_user_signing_prvk());return r.transactionSig(0,s,i,Crypto.util.hexToBytes(o))}return console.log("Not supported",e),[]},ychapi._sign_txout_t1_multipos=function(t,e,n){const i=t.coin;if(""==t.txid)return console.log("Txid is empty"),[];if(t.nout<0)return console.log("Nout is not valid"),[];if(""==e)return console.log("Change address is empty"),[];if("bigint"!=typeof n)return console.log("Change need bigint",change),[];const r=ychapi._get_coin_info(i);if(null==r)return console.log("No coininfo",i),[];if("txout_t1"==r.type){if(""==t.addr.rdsc)return console.log("Redeem script is not valid"),[];ychapi._init_coinjs(i);let r=null;coinjs.maxrbf>0&&(r=coinjs.maxrbf-1);let o=coinjs.privkey2wif(ychapi._get_user_signing_prvk()),s=[];const a="e".repeat(64);for(let i=0;i<ychapi._sigi_num;i++){const c=131;let u=coinjs.transaction();for(let t=0;t<i;t++){const t=0,n=[];u.addinput(a,t,Crypto.util.hexToBytes(n),null,1n),u.addoutput(e,1n)}u.addinput(t.txid,t.nout,Crypto.util.hexToBytes(t.addr.rdsc),r,t.amount),u.addoutput(e,n);let l=u.transactionHash(i,c);if(2==t.addr.vers){l=u.transactionHashSegWitV0(i,t.addr.rdsc,c,Number(t.amount)).hash}const p=u.transactionSig(i,o,c,Crypto.util.hexToBytes(l));s.push(p)}return s}return console.log("Not supported",i),[]},ychapi._evm_vault7u_abi=[{inputs:[{internalType:"address",name:"tss_addr",type:"address"},{internalType:"address",name:"weth_addr",type:"address"},{internalType:"address[]",name:"add_coins",type:"address[]"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"bytes32",name:"state",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"}],name:"In",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"coin",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bytes32",name:"state1",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"state2",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"irev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"orev",type:"uint256"},{indexed:!1,internalType:"uint256",name:"balance",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigr",type:"uint256"},{indexed:!1,internalType:"uint256",name:"sigv",type:"uint256"}],name:"Op",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!1,internalType:"bool",name:"reg",type:"bool"}],name:"Reg",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"balances",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],internalType:"struct Vault7.Fill[]",name:"fills",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"clearance1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"coins",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"deposit1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"irevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"},{internalType:"uint256",name:"min_amount",type:"uint256"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"listCoin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"locktime1",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"locktime2",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"minamount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"orevs",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bool",name:"on",type:"bool"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"register2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"sigr",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"uint256",name:"",type:"uint256"}],name:"sigv",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"states",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"totals",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"unregister1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"sig1",type:"bytes"}],name:"unregister2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"users",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"ustate",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"dest",type:"address"},{components:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"usea",type:"uint256"},{internalType:"bytes",name:"sig1",type:"bytes"},{internalType:"uint256",name:"sigr",type:"uint256"},{internalType:"uint256",name:"sigv",type:"uint256"}],internalType:"struct Vault7.Use[]",name:"uses",type:"tuple[]"},{internalType:"bytes",name:"sig2",type:"bytes"},{internalType:"uint256",name:"tw",type:"uint256"}],name:"withdraw1",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"coin",type:"address"},{internalType:"address",name:"dest",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"sig2",type:"bytes"}],name:"withdraw3",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],ychapi._get_evm_vault7u_abi=function(){return ychapi._evm_vault7u_abi},ychapi._get_evm_vault7u_hash1=function(t,e,n,i,r){const o=_ethers.utils.arrayify(e),s=_ethers.utils.arrayify(t),a=_ethers.utils.arrayify(i),c=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(n),32),u=_ethers.utils.arrayify(c),l=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(r),32),p=_ethers.utils.arrayify(l),h=_ethers.utils.concat([s,o,u,a,p]),f=_ethers.utils.keccak256(h),d=_ethers.utils.arrayify(f),y=_ethers.utils.toUtf8Bytes("Ethereum Signed Message:\n32"),_=_ethers.utils.concat([y,d]);return _ethers.utils.keccak256(_)},ychapi._sign_evm_vault7u_user1=function(t,e,n,i,r){const o=ychapi._get_evm_vault7u_hash1(t,e,n,i,r),s=new _ethers.utils.SigningKey("0x"+ychapi._get_user_signing_prvk()).signDigest(o);return _ethers.utils.joinSignature(s)},ychapi._get_evm_vault7u_next_state1=function(t,e,n,i){const r=_ethers.utils.arrayify(t),o=_ethers.utils.arrayify(e),s=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(n),32),a=_ethers.utils.arrayify(s),c=_ethers.utils.hexZeroPad(_ethers.utils.hexValue(i),32),u=_ethers.utils.arrayify(c),l=_ethers.utils.concat([r,o,a,u]);return _ethers.utils.keccak256(l)},ychapi._call_register=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=n+t+s;ychapi._apicall({uri:"/u/register",uprvk:o,digest:a,data:{invt:n,user:t,upub:s}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_get_email_from_redeem=async function(t){return new Promise(((e,n)=>{ychapi._apicall({uri:"/u/redeem",data:{code:t}}).then((function(t){e(t.email)})).catch((function(t){n(t)}))}))},ychapi._call_get_registration_login=async function(t){return new Promise(((e,n)=>{ychapi._apicall({uri:"/u/confirmg",data:{code:t}}).then((function(t){e(t.login)})).catch((function(t){n(t)}))}))},ychapi._call_confirm_registration_login=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=n+s;ychapi._apicall({uri:"/u/confirme",uprvk:o,digest:a,data:{code:n}}).then((function(t){i(t)})).catch((function(t){r(t)}))}))},ychapi._call_confirm_registration_2fa=async function(t,e,n,i){return new Promise(((r,o)=>{const[s,a]=ychapi._get_user_login_keys_v1(t,e),c=n+i+a;ychapi._apicall({uri:"/u/confirma",uprvk:s,digest:c,data:{code:n,auth:i}}).then((function(t){r(t)})).catch((function(t){o(t)}))}))},ychapi._ready_data=!1,ychapi._call_init=async function(){return new Promise(((t,e)=>{ychapi._apicall({calltype:"GET",uri:"/u/init",data:{}}).then((function(e){ychapi._on_data_call_init(e),ychapi._ready_init_data=!0,t(e)})).catch((function(t){ychapi._ready_init_data=!1,console.log("apicall err:",t),console.log("apicall err, logout"),ychapi._callbacks.on_sync_connection_error(t),e(t)}))}))},ychapi._call_login=async function(t,e,n){return new Promise(((i,r)=>{const[o,s]=ychapi._get_user_login_keys_v1(t,e),a=t+s+n;ychapi._apicall({uri:"/u/init",uprvk:o,digest:a,data:{user:t,upub:s,code:n}}).then((function(t){if(!t.access)return void r("notoken");if("unconfirmed"==t.access)return void r("unconfirmed");document.cookie="jwt="+t.access+";SameSite=Strict",window.location.hash="";""!=ychapi._get_jwt_uid()?(ychapi._set_user_login_keys(s,o),ychapi._on_data_call_init(t),i()):r("notoken")})).catch((function(t){r(t)}))}))},ychapi._call_logout=function(){document.cookie="jwt=; expires=Thu, 01 Jan 1970 00:00:01 GMT;SameSite=Strict",ychapi._set_user_login_keys("",""),ychapi._data.profile=void 0,ychapi._callbacks.on_sync_data_update("logout",{}),ychapi._do_ws_init()},ychapi._on_data_call_init=function(t){ychapi._data=t,ychapi._nnum=t.nnum;for(const t in ychapi._data.coininfos)ychapi._callbacks.on_sync_data_update("coininfo",ychapi._data.coininfos[t]);if(null!=t.profile){ychapi._pubkey1=t.profile.pubk1,ychapi._pubkey2=t.profile.pubk2,ychapi._pubkey3=t.profile.pubk3;t.profile.assets.forEach((function(t){const e=t.coin;ychapi._addresses[e]=t.address,ychapi._locktimes1[e]=t.locktime1,ychapi._locktimes2[e]=t.locktime2,null!=t.extra&&(ychapi._asset_extra_info[e]=t.extra)})),ychapi._callbacks.on_sync_data_update("login",{})}else ychapi._call_logout();ychapi._ready_data=!0,ychapi._callbacks.on_sync_data_init(),ychapi._do_ws_init()},ychapi._get_coin_names=function(){return ychapi._data.coins},ychapi._get_coin_info=function(t){return t in ychapi._data.coininfos?ychapi._data.coininfos[t]:null},ychapi._get_coin_balance=function(t){return null==ychapi._data.profile?null:t in ychapi._data.profile.balances?ychapi._data.profile.balances[t]:null},ychapi._get_coin_usd_rate=function(t){const e=ychapi._get_coin_info(t);return null==e?0:e.ext.priceext},ychapi._get_coin_deposits=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.deposits?ychapi._data.profile.deposits[t]:[]},ychapi._get_coin_withdrawals=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.withdraws?ychapi._data.profile.withdraws[t]:[]},ychapi._get_coin_txouts=function(t){return null==ychapi._data.profile?[]:t in ychapi._data.profile.txouts?ychapi._data.profile.txouts[t]:[]},ychapi._get_markets_groups_names=function(){let t=[];return ychapi._data.groups.forEach((function(e,n){t.push(e.name)})),t},ychapi._get_market_group=function(t){for(let e in ychapi._data.groups){const n=ychapi._data.groups[e];if(n.name==t)return n}return null},ychapi._get_market_group_by_coinb=function(t){for(let e in ychapi._data.groups){const n=ychapi._data.groups[e];if(n.coinb==t)return n}return null},ychapi._get_markets_names_in_group=function(t){const e=ychapi._get_market_group(t);if(null==e)return[];let n=[];for(let t in ychapi._data.markets)n.push(ychapi._data.markets[t]);n.sort((function(t,e){return Number(t.index-e.index)}));let i=[];return n.forEach((function(t,n){t.coinb==e.coinb&&i.push(t.name)})),i},ychapi._get_markets_names=function(){let t=[];for(let e in ychapi._data.markets)t.push(ychapi._data.markets[e]);t.sort((function(t,e){return Number(t.index-e.index)}));let e=[];return t.forEach((function(t,n){e.push(t.name)})),e},ychapi._get_market_info=function(t){return t in ychapi._data.markets?ychapi._data.markets[t]:null},ychapi._get_user_account_id=function(){return null==ychapi._data.profile?"":ychapi._data.profile.uidx},ychapi._get_user_account_login=function(){return null==ychapi._data.profile?"":ychapi._data.profile.user},ychapi._get_user_account_twofa=function(){return null!=ychapi._data.profile&&ychapi._data.profile.twofa},ychapi._get_user_trading_discount=function(){return null==ychapi._data.profile?0:ychapi._data.profile.discount},ychapi._get_user_rewards=function(t){return null==ychapi._data.profile?0n:t in ychapi._data.profile.rewards?ychapi._data.profile.rewards[t]:0n},ychapi._get_user_referral_invitation_code=function(){return null==ychapi._data.profile?"":ychapi._data.profile.invt},ychapi._get_user_referral_invitation_title=function(){return null==ychapi._data.profile?"":ychapi._data.profile.title},ychapi._get_user_trades=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.trades?[]:t in ychapi._data.profile.trades?ychapi._data.profile.trades[t]:[]},ychapi._get_user_buys=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.buys?[]:t in ychapi._data.profile.buys?ychapi._data.profile.buys[t]:[]},ychapi._get_user_sells=function(t){return null==ychapi._data.profile||null==ychapi._data.profile.sells?[]:t in ychapi._data.profile.sells?ychapi._data.profile.sells[t]:[]},ychapi._get_market_trades=function(t){return null==ychapi._data.trades?[]:t in ychapi._data.trades?ychapi._data.trades[t]:[]},ychapi._get_market_buys=function(t){return null==ychapi._data.buys?[]:t in ychapi._data.buys?ychapi._data.buys[t]:[]},ychapi._get_market_sells=function(t){return null==ychapi._data.sells?[]:t in ychapi._data.sells?ychapi._data.sells[t]:[]},ychapi._get_buy_fee=function(t,e,n){const i=ychapi._get_user_trading_discount(),r=ychapi._get_coin_info(n).fee.buyfee*(100-i)/100;if(null==ychapi._data.markets)return r;if(!t in ychapi._data.markets)return r;const o=ychapi._data.markets[t];return o.fee.over?o.fee.buyfee:r},ychapi._get_sell_fee=function(t,e,n){const i=ychapi._get_user_trading_discount(),r=ychapi._get_coin_info(e).fee.sellfee*(100-i)/100;if(null==ychapi._data.markets)return r;if(!t in ychapi._data.markets)return r;const o=ychapi._data.markets[t];return o.fee.over?o.fee.sellfee:r},ychapi._is_logged_in=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");if("uid"in JSON.parse(window.atob(e)))return!0}return!1},ychapi._has_profile=function(){return null!=ychapi._data.profile&&null!=ychapi._data.profile},ychapi._call_send=function(t,e,n,i){return new Promise(((r,o)=>{if(!ychapi._has_user_login_prvk())return void o("no login key to sign");if(""==ychapi._get_coin_holding_address(t))return void o("Not available the change address");const s=ychapi._get_coin_info(t),a=s.fee.sendfee;if(BigInt(Math.floor(.5+Number(n)*a))!=i)return void o("Fee calculation error");const c=n+i;let u=0n,l=c;const p=ychapi._get_coin_balance(t);if(c>p.free)return void o("Not enough coins");if(p.debit>0){let t=p.debit-p.ordersindebit;if(t<0)return void o("Error debt usage is negative");t>=c?(u=c,l=0n):t>0&&(u=t,l=c-t)}let h=[];if(l>0){console.log("total_via_txouts",l);let e=JSON.parse(JSON.stringify(ychapi._get_coin_txouts(t),((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),jsonBNparse);ychapi._init_coinjs(t);const n=e.filter((t=>350==t.state||400==t.state||800==t.state));if(e=e.filter((t=>400==t.state)),e.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==s.type){const[t,n,i,r]=ychapi._get_txouts_selection(e,l);if(n<0n||n<l)return void o("send: not enough available coins in txouts to use "+l);console.log("selected txouts:",t,n,i,r);for(let e=0;e<t.length;e++){const n=t[e],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return void o(r);h.push(i)}}if("evm_t1"==s.type||"erc20_t1"==s.type){const e=s.cfg.unit,i=l;for(let r=0;r<n.length;r++){const o=n[r],s="0x"+o.txid,a=o.orders+o.filled+i,c=a*e,u=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),s,c,ychapi._evm_zeroaddr,o.nout+1)];let l={};l.txid=o.txid,l.nout=o.nout,l.amnt=o.amount,l.fill=o.filled,l.usea=i,l.sigf="",l.sigv=a,l.sigs=u,h.push(l)}}}let f="";h.forEach((function(t,e){f+=t.txid+":"+t.nout,f+=t.fill.toString(),f+=t.usea.toString()}));const d=t+e+n.toString()+i.toString()+u.toString()+f+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/send",digest:d,data:{coin:t,addr:e,amount:n,fee:i,usedebit:u,usetxouts:h}}).then((function(){r()})).catch((function(t){o(t)}))}))},ychapi._call_buy=async function(t,e,n,i,r,o,s){return new Promise(((a,c)=>{if(!ychapi._has_user_login_prvk())return void c("no login key to sign");if(""==ychapi._get_coin_holding_address(n))return void c("not available the change address");const u=ychapi._get_coin_info(n),l=ychapi._get_buy_fee(t,e,n);if(r*i/BigInt(1e8)!=o)return void c("amountb calculation error");if(BigInt(Math.floor(.5+Number(o)*l))!=s)return void c("feeb calculation error");const p=o+s,h=ychapi._get_coin_balance(n);let f=0n,d=p;if(h.debit>0){let t=h.debit-h.ordersindebit;if(t<0)return void c("error debt usage is negative");t>=p?(f=p,d=0):t>0&&(f=t,d=p-t)}let y=[];if(d>0){let t=JSON.parse(JSON.stringify(ychapi._get_coin_txouts(n),((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),jsonBNparse);ychapi._init_coinjs(n);const e=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==u.type){const[e,n]=ychapi._get_txouts_selection(t,d);if(n<0||n<d)return void c("not enough available coins in txouts to trade "+d);for(let t=0;t<e.length;t++){const n=e[t],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return void c(r);y.push(i)}}if("evm_t1"==u.type||"erc20_t1"==u.type){const t=u.cfg.unit,i=d;for(let r=0;r<e.length;r++){const o=e[r],s="0x"+o.txid,a=o.orders+o.filled+i,c=a*t,u=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(n),s,c,ychapi._evm_zeroaddr,o.nout+1)],l={txid:o.txid,nout:o.nout,amnt:o.amount,fill:o.filled,usea:i,sigf:"",sigv:a,sigs:u};y.push(l)}}}let _="";y.forEach((function(t){_+=t.txid+":"+t.nout,_+=t.fill.toString(),_+=t.usea.toString()}));const g=e+n+i.toString()+r.toString()+o.toString()+"0"+s.toString()+f.toString()+_+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/buy",digest:g,data:{coina:e,coinb:n,price:i,amounta:r,amountb:o,feea:0n,feeb:s,usedebit:f,usetxouts:y}}).then((function(){a()})).catch((function(t){c(t)}))}))},ychapi._call_buy_order_cancel=async function(t,e,n){return new Promise(((i,r)=>{const o=t+e+n.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nobuy",digest:o,data:{coina:t,coinb:e,index:n}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_sell=async function(t,e,n,i,r,o,s){return new Promise(((a,c)=>{if(!ychapi._has_user_login_prvk())return void c("no login key to sign");if(""==ychapi._get_coin_holding_address(e))return void c("not available the change address");const u=ychapi._get_coin_info(e),l=ychapi._get_sell_fee(t,e,n);if(r*i/BigInt(1e8)!=o)return void c("amountb calculation error");if(BigInt(Math.floor(.5+Number(r)*l))!=s)return void c("feea calculation error");const p=r+s,h=ychapi._get_coin_balance(e);let f=0n,d=p;if(h.debit>0){let t=h.debit-h.ordersindebit;if(t<0)return void c("error debt usage is negative");t>=p?(f=p,d=0n):t>0&&(f=t,d=p-t)}let y=[];if(d>0){let t=JSON.parse(JSON.stringify(ychapi._get_coin_txouts(e),((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),jsonBNparse);ychapi._init_coinjs(e);const n=t.filter((t=>350==t.state||400==t.state||800==t.state));if(t=t.filter((t=>400==t.state)),t.sort((function(t,e){return Number(t.free-e.free)})),"txout_t1"==u.type){const[e,n,i,r]=ychapi._get_txouts_selection(t,d);if(n<0||n<d){const t="not enough available coins in txouts to trade "+d;return page.show_error_sell(t),void c(t)}for(let t=0;t<e.length;t++){const n=e[t],[i,r]=ychapi._sign_txout_t1(n);if(null!=r)return page.show_error_sell(r),void c(r);y.push(i)}}if("evm_t1"==u.type||"erc20_t1"==u.type){const t=u.cfg.unit,i=d;for(let r=0;r<n.length;r++){const o=n[r],s="0x"+o.txid,a=o.orders+o.filled+i,c=a*t,u=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(e),s,c,ychapi._evm_zeroaddr,o.nout+1)],l={txid:o.txid,nout:o.nout,amnt:o.amount,fill:o.filled,usea:i,sigf:"",sigv:a,sigs:u};y.push(l)}}}let _="";y.forEach((function(t,e){_+=t.txid+":"+t.nout,_+=t.fill.toString(),_+=t.usea.toString()}));const g=e+n+i.toString()+r.toString()+o.toString()+s.toString()+"0"+f.toString()+_+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/sell",digest:g,data:{coina:e,coinb:n,price:i,amounta:r,amountb:o,feea:s,feeb:0n,usedebit:f,usetxouts:y}}).then((function(){a()})).catch((function(t){c(t)}))}))},ychapi._call_sell_order_cancel=async function(t,e,n){return new Promise(((i,r)=>{const o=t+e+n.toString()+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nosell",digest:o,data:{coina:t,coinb:e,index:n}}).then((function(){i()})).catch((function(t){r(t)}))}))},ychapi._call_get_chart_data=async function(t,e){return new Promise(((n,i)=>{ychapi._apicall({calltype:"GETRAW",uri:"/u/chart/"+t+"/"+e,data:{}}).then((function(t){n(t)})).catch((function(t){i(t)}))}))},ychapi._is_valid_evm_address=function(t){return!!/^(0x)?[0-9a-f]{40}$/i.test(t)&&(!(!/^(0x)?[0-9a-f]{40}$/.test(t)&&!/^(0x)?[0-9A-F]{40}$/.test(t))||_ethers.utils.isAddress(t))},ychapi._validate_address=function(t,e){if(""==e)return"Address is empty";const n=ychapi._get_coin_info(t);if("txout_t1"==n.type){ychapi._init_coinjs(t);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}if("peg_t1"==n.type){ychapi._init_coinjs(part.coin);try{let t=coinjs.addressDecode(e);if(0==t)return"Address is not recognized(1)";if("bech32"==t.type)return"Address type bech32 is not supported";if("other"==t.type)return"Address is not recognized(2)"}catch(t){return"Address is not recognized(3)"}}return"evm_t1"!=n.type&&"erc20_t1"!=n.type||ychapi._is_valid_evm_address(e)?null:"Address is not recognized"},ychapi._has_coin_holding_address=function(t){return null!=ychapi._data.profile&&(t in ychapi._addresses&&""!=ychapi._addresses[t])},ychapi._get_coin_holding_address=function(t){return null==ychapi._data.profile?"":t in ychapi._addresses?ychapi._addresses[t]:""},ychapi._get_coin_credit_address=function(t){if("txout_t1"!=ychapi._get_coin_info(t).type)return"";if(null==ychapi._data.profile)return"";const e=ychapi._get_credit_signing_pubk();if(null==e)return"";const n=ychapi._get_server_signing_pubk();if(null==n)return"";return coinjs.pubkeys2MultisigAddressWithBackup(e,n,0,0).address},ychapi._call_register_deposit_evm_address=function(t,e,n){return new Promise(((i,r)=>{const o="register1",s=t+o+ychapi._get_coin_holding_address(t)+e.toString()+n+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/address",digest:s,data:{coin:t,call:o,user:ychapi._get_coin_holding_address(t),blck:e,sender:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._call_unregister_deposit_evm_address=function(t,e,n){return new Promise(((i,r)=>{const o="unregister2",s=part.coin+o+ychapi._get_coin_holding_address(part.coin)+e.toString()+account_addr+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/address",digest:s,data:{coin:t,call:o,user:ychapi._get_coin_holding_address(t),blck:e,sender:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._create_withdraw=function(t,e){let n={};n.coin=t,n.scope=e,n.sendfee=0n,n.datatag=0n,n.mode="reduce",n.last_error=null;return"txout_t1"==ychapi._get_coin_info(t).type&&(n.datatag=1n),n.op1=ychapi._create_withdraw_op(),n.op2=ychapi._create_withdraw_op(),n.op3=ychapi._create_withdraw_op(),n.get_available_amount=function(){let t=0n;return n.op1.txouts.forEach((function(e){t+=e.free})),t},n.get_sendfee=function(){return n.sendfee},n.get_output_datatag_amount=function(){return 0n==n.op2.amount_out?0n:n.datatag},n.set_txouts_user=function(t){t.txouts_user=JSON.parse(JSON.stringify(ychapi._get_coin_txouts(n.coin),((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),jsonBNparse),t.txouts_user=t.txouts_user.filter((t=>400==t.state&&"allocated"!=n.scope||500==t.state&&"allocated"==n.scope)),t.txouts_user.sort((function(t,e){return Number(e.free-t.free)})),t.txouts=t.txouts_user},n.set_txouts_debit=function(t){if(t.txouts_debit=[],"allocated"==n.scope)return;const e=ychapi._get_coin_balance(n.coin);if(null==e)return;if(e.debit<=0)return;const i=ychapi._get_coin_info(n.coin);if("peg_t1"!=i.type&&"evm_t1"!=i.type&&"txout_t1"!=i.type&&"erc20_t1"!=i.type)return;0n!=e.debit-e.ordersindebit&&(t.txouts_debit=[ychapi._create_virtual_debit_txout(n.coin)],t.txouts=t.txouts.concat(t.txouts_debit))},n.select_txouts2=function(){if("reduce"==n.mode){let t=0n;n.op2.txouts.forEach((function(e){t+=e.free})),t<n.op2.amount_inp&&(n.op2.amount_inp=t)}let t=n.op2.select2(n.op2.amount_inp);return null!=t?t:("reduce"==n.mode?n.op2.reduce(n.get_output_datatag_amount()):n.op2.change-=n.get_output_datatag_amount(),null)},n.stabilize_op=function(t){n.trace("stabilize_op",t);let e=0n;const i=ychapi._get_coin_info(n.coin);"txout_t1"==i.type&&(e=i.fee.minamount);let r=t.stabilize(i,e);return n.trace("stabilize_op end",t),r},n.trace=function(t,e){},n},ychapi._update_withdraw=function(t){return t.set_txouts_user(t.op1),t.set_txouts_debit(t.op1),t.op1.make_id2idx(),t.set_txouts_user(t.op2),t.set_txouts_debit(t.op2),t.op2.make_id2idx(),err=t.last_error=ychapi._compute_withdraw_datas(t),err},ychapi._set_withdraw_amount=function(t,e,n){t.op1.amount_inp=e,t.op2.amount_inp=e;const i=Number(t.op1.amount_inp)/1e8,r=ychapi._get_coin_info(t.coin);return null==r?"Coin is not supported":(t.sendfee=BigInt(Math.floor(.5+i*r.fee.withfee*1e8)),"allocated"==t.scope&&(t.sendfee=0n),t.mode=n,"manual"==t.mode&&(t.op2.reduce_mode=!1,t.op3.reduce_mode=!0),"reduce"==t.mode&&(t.op2.reduce_mode=!0,t.op3.reduce_mode=!0),err=t.last_error=ychapi._compute_withdraw_datas(t),err)},ychapi._set_withdraw_inputs_for_debit=function(t,e){t.set_txouts_user(t.op3),t.op3.txouts_debit=e,t.op3.txouts=t.op3.txouts.concat(t.op3.txouts_debit),t.op3.make_id2idx();let n=t.op3.select3(t.op2.amount_out);return null!=n?n:(t.op3.change>0n?t.op3.change-=t.get_output_datatag_amount():t.op3.reduce(t.get_output_datatag_amount()),n=t.stabilize_op(t.op3),null!=n?n:null)},ychapi._compute_withdraw_datas=function(t){let e=t.last_error=t.op1.select1(t.get_sendfee(),t.op2);if(null!=e)return e;if(e=t.last_error=t.select_txouts2(),null!=e)return e;if(e=t.last_error=t.stabilize_op(t.op2),null!=e)return e;if(e=t.last_error=ychapi._validate_address(t.coin,ychapi._get_coin_holding_address(t.coin)),null!=e)return e;const n=ychapi._get_coin_info(t.coin);if(null==n)return"Coin is not supported";if("txout_t1"==n.type){const n=ychapi._get_coin_credit_address(t.coin);if(""==n)return"Credit address is not available";if(e=t.last_error=ychapi._validate_address(t.coin,n),null!=e)return e}return e=t.last_error=ychapi._validate_withdraw_inputs_outputs(t),null!=e?e:null},ychapi._build_txout_t1_tx=function(t,e,n){if("txout_t1"!=ychapi._get_coin_info(t).type)return null;ychapi._init_coinjs(t);let i=null;coinjs.maxrbf>0&&(i=coinjs.maxrbf-1);let r=coinjs.transaction();for(let t=0;t<e.selected.length;t++){let n=e.selected[t],o=coinjs.pubkeys2MultisigAddressWithBackup(n.addr.pub1,n.addr.pub2,n.addr.lck1,n.addr.lck2),s=i;2==n.hold&&(s=n.nseq),r.addinput(n.txid,n.nout,Crypto.util.hexToBytes(o.redeemScript),s,n.amount)}e.amount_out>0n&&r.addoutput(n,e.amount_out),e.change>0n&&r.addoutput(ychapi._get_coin_holding_address(t),e.change),e.credit>0n&&r.addoutput(ychapi._get_coin_credit_address(t),e.credit);let o=[];e.selected.forEach((function(t){let e=Crypto.util.hexToBytes(t.txid).reverse();for(let t=0;t<e.length;t++)o.push(e[t]);let n=coinjs.numToBytes(t.nout);for(let t=0;t<n.length;t++)o.push(n[t])})),o.push("L".charCodeAt(0));for(let t=0;t<n.length;t++)o.push(n.charCodeAt(t));let s=coinjs.numToBytes(Number(e.amount_out));for(let t=0;t<s.length;t++)o.push(s[t]);var a=Crypto.SHA256(Crypto.SHA256(o,{asBytes:!0}),{asBytes:!0});let c="XCH:0:"+Crypto.util.bytesToHex(a.reverse());return r.adddata(Crypto.util.bytesToHex(ychapi._str2bytes(c)),1),r},ychapi._get_withdraw_rawtx=function(t){const e=ychapi._build_txout_t1_tx(t.coin,t.op2,t.addr_send);return null==e?null:e.serialize()},ychapi._validate_withdraw_inputs_outputs=function(t){let e=0n;t.op2.selected.forEach((function(t){e+=t.amount}));let n=t.op2.amount_out+t.op2.change+t.op2.credit+t.get_output_datatag_amount()+t.op2.netfee;return e!=n?"Can not configure inputs(6), change the quantity":null},ychapi._create_virtual_debit_txout=function(t){let e=0n,n=0n;const i=ychapi._get_coin_balance(t);null!=i&&(e=i.debit,n=i.ordersindebit);let r={gidx:1,cidx:1,coin:t,hold:2,state:500,addr:{vers:1,host:"",addr:ychapi._get_coin_holding_address(t),pub1:ychapi._get_credit_signing_pubk(),pub2:ychapi._get_server_signing_pubk(),lck1:0,lck2:0,pksc:"",rdsc:"00"},txid:ychapi._zerotxid,nout:0,free:e-n,orders:0n,amount:e-n,filled:0n,selected:0n};return"peg_t1"==ychapi._get_coin_info(t).type&&(r.amount=e,r.orders=0n,r.filled=n),r},ychapi._has_withdraw_inputs_stage=function(t){return ychapi._has_withdraw_op2_inputs_stage(t.coin,t.op2)},ychapi._has_withdraw_op2_inputs_stage=function(t,e){if("txout_t1"!=ychapi._get_coin_info(t).type)return!1;for(let t=0;t<e.selected.length;t++){if(e.selected[t].txid==ychapi._zerotxid)return!0}return!1},ychapi._prepare_withdraw_call_payload=function(t,e,n,i,r){const o=ychapi._get_coin_info(t);ychapi._init_coinjs(t);const s=Math.floor((new Date).getTime()/1e3)+o.cfg.tw,a=BigInt(s);let c=[],u=[],l="",p="";if("txout_t1"==o.type){for(let t=0;t<i.selected.length;t++){const e=i.selected[t];l+=e.txid+":"+e.nout,l+=e.filled.toString(),l+=e.selected.toString();const[n,r]=ychapi._sign_txout_t1(e);if(null!=r)return[null,null,r];c.push(n)}const n=ychapi._build_txout_t1_tx(t,r,e);console.log("op2 tx:",n);for(let t=0;t<r.selected.length;t++){const e=r.selected[t];p+=e.txid+":"+e.nout,p+=e.filled.toString(),p+=e.selected.toString();const i=1;let o=n.transactionHash(t,i);if(2==e.addr.vers){o=n.transactionHashSegWitV0(t,e.addr.rdsc,i,Number(e.amount)).hash}const[s,a]=ychapi._sign_txout_t1_hash(e,t,o);if(null!=a)return[null,null,a];u.push(s)}}if("peg_t1"==o.type)for(let t=0;t<r.selected.length;t++){const e=r.selected[t];p+=e.txid+":"+e.nout,p+=e.filled.toString(),p+=e.selected.toString();const n="",i="",o=0n,s={txid:e.txid,nout:e.nout,amnt:e.amount,fill:e.filled,usea:e.selected,sigf:n,sign:i,sigv:o};u.push(s)}if("evm_t1"==o.type||"erc20_t1"==o.type){const n=o.cfg.unit;for(let e=0;e<i.selected.length;e++){const r=i.selected[e];l+=r.txid+":"+r.nout,l+=r.filled.toString(),l+=r.selected.toString();const o="0x"+r.txid,s=r.orders+r.filled+r.selected,a=s*n,u=[ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),o,a,ychapi._evm_zeroaddr,r.nout+1)],p={txid:r.txid,nout:r.nout,amnt:r.amount,fill:r.filled,usea:r.selected,sigf:"",sigv:s,sigs:u};c.push(p)}let h=0,f=0;if(r.selected.forEach((function(t,e){t.txid==ychapi._zerotxid?f++:h++})),h>1){return[null,null,"More than one state: unfinished chain operations, try later"]}if(f>1){return[null,null,"More than one debit, error"]}r.selected.forEach((function(i,r){p+=i.txid+":"+i.nout,p+=i.filled.toString(),p+=i.selected.toString();let o="",c="",l=0n;if(i.txid==ychapi._zerotxid);else{l=i.selected;const r=i.selected*n,u="0x"+i.txid;o=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),u,r,e,s);const p=(0,ychapi._get_evm_vault7u_next_state1)(u,e,r,a),h=(i.orders+i.filled)*n;c=ychapi._sign_evm_vault7u_user1(ychapi._get_coin_holding_address(t),p,h,ychapi._evm_zeroaddr,i.nout+1)}const h={txid:i.txid,nout:i.nout,amnt:i.amount,fill:i.filled,usea:i.selected,sigf:o,sign:c,sigv:l,sigs:[]};u.push(h)}))}const h=ychapi._get_coin_holding_address(t),f=ychapi._get_coin_credit_address(t);return[t+e+f+h+r.amount_out.toString()+r.debit.toString()+r.credit.toString()+r.change.toString()+r.netfee.toString()+n.toString()+l+p+ychapi._get_user_login_pubk(),{coin:t,addr_send:e,addr_credit:f,addr_change:h,value_send:r.amount_out,value_debit:r.debit,value_credit:r.credit,value_change:r.change,value_netfee:r.netfee,value_sendfee:n,usetxouts1:c,usetxouts2:u,twin:a},null]},ychapi._call_withdraw_inputs_stage=function(t){return new Promise(((e,n)=>{let i=!1;for(let e=0;e<t.op2.selected.length;e++){if(t.op2.selected[e].txid==ychapi._zerotxid){i=!0;break}}if(!i)throw new Error("No debit");if("txout_t1"!=ychapi._get_coin_info(t.coin).type)throw new Error("Invalid coin type");const[r,o,s]=ychapi._prepare_withdraw_call_payload(t.coin,t.addr_send,t.get_sendfee(),t.op1,t.op2);if(null!=s)throw s;ychapi._apicall({uri:"/u/withdraw",digest:r,data:o}).then((function(t){if(!("step"in t))throw new Error("Unexpected response without step");if("txouts"!=t.step)throw new Error("Unexpected response without txouts step: "+t.step);e(t.txouts)})).catch((function(t){n(t)}))}))},ychapi._call_withdraw=function(t,e,n,i,r){return new Promise(((o,s)=>{if(ychapi._has_withdraw_op2_inputs_stage(t,r))return void s("Debit is not filled");const[a,c,u]=ychapi._prepare_withdraw_call_payload(t,e,n,i,r);null==u?ychapi._apicall({uri:"/u/withdraw",digest:a,data:c}).then((function(t){o(t)})).catch((function(t){s(t)})):s(u)}))},ychapi._call_withdraw_report_txid=function(t,e,n){return new Promise(((i,r)=>{ychapi._apicall({uri:"/u/withdraw_evm_txid",data:{coin:t,gidx:e,txid:n}}).then((function(t){i()})).catch((function(t){r(t)}))}))},ychapi._call_withdraw_cancel=function(t,e){return new Promise(((n,i)=>{const r=withdraw.coin+withdraw.gidx+ychapi._get_user_login_pubk();ychapi._apicall({uri:"/u/nowithdraw",digest:r,data:{coin:t,gidx:e}}).then((function(t){n()})).catch((function(t){i(t)}))}))},ychapi._create_withdraw_op=function(){let t={reduce_mode:!1,amount_inp:0n,amount_out:0n,txouts:[],txouts_user:[],txouts_debit:[],txout_id_to_idx:{},selected:[],unselected:[],netfee:0n,debit:0n,change:0n,credit:0n,num_inps:0,num_outs:0,rawtx:"",select1:function(e,n){if(t.selected=[],t.txouts.forEach((function(t){t.selected=0n})),1==t.txouts_debit.length){let n=t.txouts_debit[0];if(n.free>0n){let i=n.free;i>e&&(i=e),n.selected=i,t.selected.push(n),e-=i}}if(e>0n){let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));{let t=0n;if(n.forEach((function(e,n){t+=e.free})),t<e)return console.log("txouts_free < amount",t,e),"Not enough available for withdraw"}let i=0n;for(;i<e;)for(let r=0;r<n.length;r++){let o=n[r];if(r+1==n.length){t.selected.push(o);let s=o.free;i+s>e&&(s=e-i),o.selected=s,i+=o.free,n=n.slice(0,r);break}if(i+o.free>=e){t.selected.push(o);let s=o.free;i+s>e&&(s=e-i),o.selected=s,i+=o.free,n.splice(r,1);break}if(i>=e)break}}return t.make_unselected(),t.use2credit(n),null},make_id2idx:function(){t.txout_id_to_idx={},t.txouts.forEach((function(e,n){const i=e.txid+":"+e.nout;t.txout_id_to_idx[i]=n}))},make_unselected:function(){let e={};t.selected.forEach((function(n){let i=n.txid+":"+n.nout;e[i]=!0,t.credit+=n.filled;const r=n.amount-n.selected-n.filled;t.change+=r})),t.unselected=[],t.txouts.forEach((function(n){n.txid+":"+n.nout in e||t.unselected.push(n)}))},use2credit:function(e){return t.selected.forEach((function(t,n){const i=t.txid+":"+t.nout;if(!(i in e.txout_id_to_idx))return;const r=e.txout_id_to_idx[i];let o=e.txouts[r];o.txid==ychapi._zerotxid?(o.free=t.free-t.selected,o.amount=t.amount-t.selected):(o.free=t.free-t.selected,o.filled=t.filled+t.selected)})),null},select2:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));let i=0n,r=e,o=0n;n.forEach((function(t){o+=t.free})),r>o&&(i=r-o,r=o);let s=!1;if(i>0n){let e=i;if(1==t.txouts_debit.length){let n=t.txouts_debit[0];if(n.free>0n){let i=n.free;i>e&&(i=e),n.selected=i,t.selected.push(n),e-=i,s=!0}}if(e>0n)return"Not enough available for withdraw"}let a=r,c=0n;for(;c<a;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;c+r>a&&(r=a-c),i.selected=r,c+=i.free,n=n.slice(0,e);break}if(c+i.free>=a){t.selected.push(i);let r=i.free;c+r>a&&(r=a-c),i.selected=r,c+=i.free,n.splice(e,1);break}if(c>=a)break}if(0==n.length)break}return c<a?"Not enough available for withdraw":(t.make_unselected(),null)},select3:function(e){t.selected=[],t.amount_inp=e,t.amount_out=e,t.debit=0n,t.credit=0n,t.change=0n,t.netfee=0n,t.txouts.forEach((function(t){t.selected=0n}));let n=[...t.txouts_user];n.sort((function(t,e){return Number(t.free-e.free)}));let i=0n,r=e,o=0n;n.forEach((function(t){o+=t.free})),r>o&&(i=r-o,r=o);let s=r,a=0n;for(;a<s;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n=n.slice(0,e);break}if(a+i.free>=s){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n.splice(e,1);break}if(a>=s)break}if(0==n.length)break}if(a<s)return"Not enough available for withdraw";for(n=[...t.txouts_debit],n.sort((function(t,e){return Number(t.free-e.free)})),s=i,a=0n;a<s;){for(let e=0;e<n.length;e++){let i=n[e];if(e+1==n.length){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n=n.slice(0,e);break}if(a+i.free>=s){t.selected.push(i);let r=i.free;a+r>s&&(r=s-a),i.selected=r,a+=i.free,n.splice(e,1);break}if(a>=s)break}if(0==n.length)break}return a<s?"Not enough available for withdraw":(t.make_unselected(),null)},add_more:function(e){let n=[],i=null;t.unselected.forEach((function(t){t.txid!=ychapi._zerotxid?n.push(t):i=t}));let r=[],o=0n;for(n.sort((function(t,e){return Number(t.amount-t.filled-(e.amount-e.filled))}));o<e;){for(let i=0;i<n.length;i++){let s=n[i],a=s.amount-s.filled;if(i+1==n.length){t.selected.push(s),r.push(s),s.selected=0n,o+=a,n=n.slice(0,i);break}if(o+a>=e){t.selected.push(s),r.push(s),s.selected=0n,o+=a,n.splice(i,1);break}if(o>=e)break}if(0==n.length)break}if(o<e&&null!=i){let e=i,n=e.amount-e.filled;t.selected.push(i),r.push(i),i.selected=0n,o+=n}if(o<e)return"Not enough available to select";let s={};return t.selected.forEach((function(t){let e=t.txid+":"+t.nout;s[e]=!0})),r.forEach((function(e){t.credit+=e.filled;const n=e.amount-e.selected-e.filled;t.change+=n})),t.unselected=[],t.txouts.forEach((function(e){e.txid+":"+e.nout in s||t.unselected.push(e)})),null},reduce:function(e){t.amount_out-=e;let n=t.selected;n.sort((function(t,e){return Number(t.selected-e.selected)}));for(let t=0;t<n.length;t++){let i=n[t],r=e;if(r>i.selected&&(r=i.selected),i.selected-=r,0n==(e-=r))break}},stabilize_changes:function(e){if(0n==e)return!0;if((0n==t.credit||t.credit>=e)&&(0n==t.change||t.change>=e))return!0;const n=t.change+t.credit;if(t.credit>0n&&e<=n&&n<e+e)return t.debit=t.change,t.credit=n,t.change=0n,!0;if(t.credit>0n&&t.credit<e&&n>=e+e){let n=e-t.credit;return t.debit+=n,t.credit+=n,t.change-=n,!0}return t.change>0n&&t.change<e&&n>=e+e&&(t.debit+=t.change,t.credit+=t.change,t.change=0n,!0)},stabilize_change:function(e,n){if(t.stabilize_changes(e))return null;let i=e-(t.change+t.credit),r=0n;if(t.unselected.forEach((function(t){r+=t.amount-t.filled})),i<=r){let n=t.add_more(i);if(null!=n)return n;if(t.stabilize_changes(e))return null}else if(n&&t.amount_out>i){t.reduce(i),t.change+=i;if(t.stabilize_changes(e))return null}return"Can not configure inputs(1), change the quantity"},compute_netfee:function(e){if(0n!=t.amount_inp)if("peg_t1"!=e.type)if("txout_t1"!=e.type)t.netfee=0n;else{const n=e.fee.txbytefee;t.num_inps=t.selected.length,t.num_outs=1,t.change>0n&&t.num_outs++,t.credit>0n&&t.num_outs++,t.num_outs++;let i=386*t.num_inps+34*(t.num_outs-1)+80;e.fee.txbyteround>1&&(i=Math.ceil(i/e.fee.txbyteround)*e.fee.txbyteround),t.netfee=BigInt(Math.floor(i*n*1e8+.5));const r=e.fee.mempoolminfee,o=BigInt(Math.floor(1e8*r+.5));t.netfee<o&&(t.netfee=o)}else t.netfee=10000000n;else t.netfee=0n},stabilize_netfee:function(e,n){let i=0n;"txout_t1"==e.type&&(i=e.fee.minamount);let r=0n,o=0n,s=0n;for(let a=0;a<10;a++){if(t.change+=r,t.credit+=o,t.debit+=s,r=0n,o=0n,s=0n,null!=t.stabilize_change(i,n))break;t.compute_netfee(e);let a=t.netfee,c=a;if(t.debit>0n&&t.credit>0n){let e=t.credit;if(e>t.debit&&(e=t.debit),e>c&&(e=c),t.credit-e>0n&&t.credit-e<i&&(e=t.credit-i),c-=e,o+=e,t.credit-=e,s+=e,t.debit-=e,0n==c)return null}if(t.change>0n&&t.change>=c){if(r+=c,t.change-=c,c=0n,null!=t.stabilize_change(i,n))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}t.change>0n&&t.change<c&&(r+=t.change,c-=t.change,t.change=0n);let u=0n;if(t.unselected.forEach((function(t,e){u+=t.amount-t.filled})),c<=u){if(t.add_more(c),r+=c,t.change-=c,c=0n,!t.stabilize_changes(i))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}if(n&&t.amount_out>c){if(t.reduce(c),c=0n,!t.stabilize_changes(i))break;if(t.compute_netfee(e),a!=t.netfee)continue;return null}}return"Can not configure inputs(3), change the quantity"},stabilize:function(e,n){let i=t.stabilize_change(n,t.reduce_mode);return null!=i?i:(i=t.stabilize_netfee(e,t.reduce_mode),null!=i?i:null)}};return t},ychapi._ready_wsdata=!1,ychapi._timer_reauth_duration=3e5,ychapi._ws_callbacks={},ychapi._start_ws=function(){ychapi._ready_wsdata=!1;let t="ws:";"https:"==window.location.protocol&&(t="wss:");let e=t+"//"+window.location.hostname+":"+window.location.port+"/ws";""!=ychapi._base_uri&&(e=ychapi._base_uri+"/ws"),console.log("Use sync connection: "+e),ychapi._websocket=new ReconnectingWebSocket(e),ychapi._websocket.onopen=ychapi._on_ws_onopen,ychapi._websocket.onclose=ychapi._on_ws_onclose,ychapi._websocket.onmessage=ychapi._on_ws_onmessage},ychapi._on_ws_onclose=function(t){ychapi._ready_wsdata=!1,ychapi._callbacks.on_sync_connection_lost()},ychapi._on_ws_onopen=function(t){ychapi._ready_wsdata=!0,ychapi._do_ws_init()},ychapi._do_ws_init=function(){if(ychapi._websocket.readyState!=WebSocket.OPEN)return;const t={type:"init",jwt:ychapi._get_cookie("jwt")};ychapi._websocket.send(JSON.stringify(t)),ychapi._ready_wsdata=!0,ychapi._callbacks.on_sync_connecting(),ychapi._ready_wsdata&&ychapi._ready_data&&ychapi._callbacks.on_sync_ready(),clearTimeout(ychapi._timer_reauth),ychapi._timer_reauth=setTimeout(ychapi._do_apicall_reauth,ychapi._timer_reauth_duration)},ychapi._on_ws_onmessage=function(t){if("message"==t.type){let e={};t.data.split("\n").forEach((function(t,n){try{e=JSON.parse(t,jsonBNparse)}catch(t){return}ychapi._on_ws_message(e)}))}else console.log("Received ws event, not a message: ",t)},ychapi._on_ws_message=function(t){"type"in t?(t.type in ychapi._ws_callbacks?ychapi._ws_callbacks[t.type](t):console.log("Received unknown ws event, message: ",t),ychapi._callbacks.on_sync_message(t)):console.log("Received unknown ws event, message: ",t)},ychapi._ws_callbacks.nnum=function(t){const e=t.objects[0];ychapi._nnum=e},ychapi._ws_callbacks.coininfo=function(t){const e=t.objects[0];null==ychapi._data.coininfos&&(ychapi._data.coininfos={}),ychapi._data.coininfos[e.coin]=e,ychapi._callbacks.on_sync_data_update("coininfo",e)},ychapi._ws_callbacks.market=function(t){const e=t.objects[0];ychapi._data.markets[e.name]=e,ychapi._callbacks.on_sync_data_update("market",e)},ychapi._ws_callbacks.markettradesupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.trades[n]=e.page,ychapi._callbacks.on_sync_data_update("trades",n,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.usertradesupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.trades[n]=e.page,ychapi._callbacks.on_sync_data_update("user_trades",n,e.coina,e.coinb,e.page)},ychapi._ws_callbacks.depositaddress=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coin;if(ychapi._addresses[n]=e.addr,ychapi._locktimes1[n]=e.lck1,ychapi._locktimes2[n]=e.lck2,n in ychapi._data.profile.balances){const t=ychapi._data.profile.balances[n];ychapi._callbacks.on_sync_data_update("balance",t)}},ychapi._ws_callbacks.addressesupdate1=function(t){const e=t.objects[0],n=e.coin,i=e.list;n in ychapi._asset_extra_info||(ychapi._asset_extra_info[n]={},ychapi._asset_extra_info[n].senders=[]),ychapi._asset_extra_info[n].senders=i},ychapi._ws_callbacks.adddeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.deposits[n],r=!0;i.forEach((function(t,n){t.index>=e.index&&(r=!1)})),r&&(i.unshift(e),i=i.slice(0,ychapi._get_page_size()),ychapi._data.profile.deposits[n]=i)},ychapi._ws_callbacks.regdeposit=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.deposits[n];i.forEach((function(t,n){e.index==t.index&&(i[n]=e,t=e)}))},ychapi._ws_callbacks.addwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.withdraws[n],r=!0;i.forEach((function(t,n){t.uidx>=e.uidx&&(r=!1)})),r&&(i.unshift(e),i=i.slice(0,ychapi._get_page_size()),ychapi._data.profile.withdraws[e.coin]=i)},ychapi._ws_callbacks.regwithdraw=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[1],n=e.coin;let i=ychapi._data.profile.withdraws[n];i.forEach((function(t,n){e.uidx==t.uidx&&(i[n]=e,t=e)}))},ychapi._ws_callbacks.balances=function(t){t.objects[0].forEach((function(t){ychapi._data.profile.balances[t.coin]=t,ychapi._callbacks.on_sync_data_update("balance",t)}))},ychapi._ws_callbacks.accountchange=function(t){},ychapi._ws_callbacks.newcandle=function(t){},ychapi._ws_callbacks.updatecandle=function(t){},ychapi._ws_callbacks.txoutsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=t.objects[1];ychapi._data.profile.txouts[e]=n,ychapi._callbacks.on_sync_data_update("txouts",e,n)},ychapi._ws_callbacks.buysupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.buys[n]=e.buyspage,ychapi._callbacks.on_sync_data_update("buys",n,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.sellsupdate=function(t){const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.sells[n]=e.sellspage,ychapi._callbacks.on_sync_data_update("sells",n,e.coina,e.coinb,e.sellspage)},ychapi._ws_callbacks.userbuysupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.buys[n]=e.buyspage,ychapi._callbacks.on_sync_data_update("user_buys",n,e.coina,e.coinb,e.buyspage)},ychapi._ws_callbacks.usersellsupdate=function(t){if(null==ychapi._data.profile)return;if(null==ychapi._data.profile)return;const e=t.objects[0],n=e.coina+"-"+e.coinb;ychapi._data.profile.sells[n]=e.sellspage,ychapi._callbacks.on_sync_data_update("user_sells",n,e.coina,e.coinb,e.sellspage)},ychapi._get_cookie=function(t){const e=t+"=",n=decodeURIComponent(document.cookie).split(";");for(let t=0;t<n.length;t++){let i=n[t];for(;" "==i.charAt(0);)i=i.substring(1);if(0==i.indexOf(e))return i.substring(e.length,i.length)}return""},ychapi._get_jwt_uid=function(){const t=ychapi._get_cookie("jwt").split(".");if(3==t.length){const e=t[1].replace("-","+").replace("_","/");return JSON.parse(window.atob(e)).uid}return""},ychapi._str2bytes=function(t){let e=[];for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e.push(i):i<2048?e.push(192|i>>6,128|63&i):i<55296||i>=57344?e.push(224|i>>12,128|i>>6&63,128|63&i):(n++,i=65536+((1023&i)<<10|1023&t.charCodeAt(n)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e},ychapi._get_page_size=function(){return ychapi._pagesize};
package/example1.html ADDED
@@ -0,0 +1,114 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>ychapi example 1</title>
7
+
8
+
9
+ <script src="https://cdn.jsdelivr.net/npm/reconnecting-websocket@4.4.0/dist/reconnecting-websocket-iife.min.js"></script>
10
+ <script src="/dist/ychapi.min.js"></script>
11
+ <script src="/dist/api.js"></script>
12
+
13
+ </head>
14
+
15
+ <body>
16
+
17
+ ychapi example 1
18
+ <br/>
19
+ API base: https://testnet-api.nighttrader.exchange
20
+
21
+ <br/>
22
+ <br/>
23
+ <button onclick="start()">start ychapi initialization and sync</button>
24
+
25
+ <br/>
26
+ <span id="status"></span>
27
+
28
+ <div id="login_form" style="display: none;">
29
+ <br/>
30
+ <br/>
31
+ <input type="text" id="login" placeholder="login"/><br/>
32
+ <input type="password" id="password" placeholder="password"/><br/>
33
+ <input type="text" id="otp_code" placeholder="otp_code"/><br/>
34
+ <button onclick="login()">login</button>
35
+
36
+ <br/>
37
+ <span id="login_status"></span>
38
+
39
+ <div id="user_info" style="display: none;">
40
+ <br/>
41
+ <br/>
42
+ Account ID: <span id="user_id"></span>
43
+
44
+ <br/>
45
+ <br/>
46
+ Balances:
47
+ <br/>
48
+ <span id="user_balances"></span>
49
+
50
+ </div>
51
+
52
+ </div>
53
+
54
+ <script>
55
+ function start() {
56
+ ychapi.start("https://testnet-api.nighttrader.exchange", {
57
+ on_sync_connecting: function() {
58
+ console.log("syncing...");
59
+ document.getElementById("status").textContent = "syncing...";
60
+ },
61
+ on_sync_connection_lost: function() {
62
+ console.log("sync connection lost");
63
+ document.getElementById("status").textContent = "sync connection lost";
64
+ },
65
+ on_sync_connection_error: function(err) {
66
+ console.log("sync connection error", err);
67
+ document.getElementById("status").textContent = "sync connection error";
68
+ },
69
+ on_sync_data_init: function() {
70
+ console.log("sync data init");
71
+ document.getElementById("status").textContent = "sync data init";
72
+ },
73
+ on_sync_ready: function() {
74
+ console.log("sync ready");
75
+ document.getElementById("status").textContent = "sync ready";
76
+ document.getElementById("login_form").style.display = "block";
77
+ document.getElementById("user_info").style.display = "none";
78
+ },
79
+ on_sync_message: function(message) {
80
+ console.log("sync message", message);
81
+ document.getElementById("status").textContent = "sync message";
82
+ },
83
+ on_sync_data_update: function(data) {
84
+ console.log("sync data update", data);
85
+ document.getElementById("status").textContent = "sync data update";
86
+ }
87
+ });
88
+ }
89
+
90
+ function login() {
91
+ const login = document.getElementById("login").value;
92
+ const password = document.getElementById("password").value;
93
+ const otp_code = document.getElementById("otp_code").value;
94
+ ychapi.call_login(login, password, otp_code).then(() => {
95
+ document.getElementById("login_status").textContent = "login success";
96
+ document.getElementById("user_id").textContent = "U-"+ychapi.get_user_account_id();
97
+ document.getElementById("user_info").style.display = "block";
98
+ let text = "";
99
+ const coin_names = ychapi.get_coin_names();
100
+ for (const coin_name of coin_names) {
101
+ const coin_balance = ychapi.get_coin_balance(coin_name);
102
+ text += coin_name + ": " + coin_balance.sum + "<br/>";
103
+ }
104
+
105
+ document.getElementById("user_balances").innerHTML = text;
106
+
107
+ }).catch((err) => {
108
+ document.getElementById("login_status").textContent = "login error: " + err;
109
+ });
110
+ }
111
+ </script>
112
+
113
+ </body>
114
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ychapi",
3
- "version": "0.903.0",
3
+ "version": "0.917.0",
4
4
  "description": "Walrus-compatible exchange js api layer",
5
5
  "main": "api.js",
6
6
  "scripts": {
@@ -18,5 +18,11 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/hyperwalrus/ychapi/issues"
20
20
  },
21
- "homepage": "https://github.com/hyperwalrus/ychapi#readme"
21
+ "homepage": "https://github.com/hyperwalrus/ychapi#readme",
22
+ "files": [
23
+ "dist/",
24
+ "README.md",
25
+ "LICENSE.txt",
26
+ "example1.html"
27
+ ]
22
28
  }