forked from coinables/segwitaddress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
758 lines (671 loc) · 25.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
<!DOCTYPE html>
<html>
<head>
<title>SegWit Paper Wallet</title>
<meta name="description" content="Create Segregated Witness (SegWit) Addresses in your browser that can be ran offline to create paper wallets or bulk addresses.">
<meta name="keywords" content="Bitcoin, SegWit Paper, SegWit Address, P2WPKH generator, P2WPKH wallet, javascript, pay to witness">
<style>
body, html {
padding: 12px;
font-family: "Verdana", "sans-serif";
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
#share{
color: green;
font-size: 28px;
font-weight: bold;
}
#keep{
color: red;
font-size: 28px;
font-weight: bold;
}
#sweepcont{
width: 60%;
}
#wit{
background-color: black;
color: #ffeeff;
}
.label-default{
padding: 3px;
border: 1px solid #ccc;
border-radius: 2px;
text-decoration: none;
color: #222;
}
.label-primary{
padding: 3px;
border: 1px solid #0088ff;
background-color: #0088ff;
border-radius: 2px;
text-decoration: none;
color: white;
}
.label-success{
padding: 3px;
border: 1px solid #52BE80;
background-color: #52BE80;
border-radius: 2px;
text-decoration: none;
color: white;
}
.label-reference{
padding: 3px;
border: 1px solid #333;
background-color: grey;
border-radius: 2px;
text-decoration: none;
color: white;
}
#qrcam{
display: none;
}
#entropyCanvas{
display: none;
}
#entropyRef{
border: 1px solid #0088ff;
background-color: #0088ff;
color: #fff;
padding: 5px;
}
#sweepkey{
background-color: #52BE80;
color: #fff;
}
#btnBulk{
background-color: #F1C40F;
color: #fff;
}
#clearBulk{
background-color: #EC7063;
color: #fff;
}
#qrnotify{
display: none;
}
#qrnotify2{
display: none;
}
.hr {
height: 6px;
border: 0;
box-shadow: inset 0 6px 6px -6px rgba(0, 0, 0, 1);
}
.well{
padding: 16px;
border: 2px solid #aaa;
border-radius: 3px;
background-color: #ddd;
color: #000;
box-shadow: 0 6px 6px -6px rgba(0, 0, 0, 1);
}
input{
width: 60%;
border-radius: 4px;
background-color: #eee;
padding: 7px;
font-size: 21px;
border: 1px solid #999;
}
.btn{
border-radius: 4px;
background-color: #fff;
padding: 7px;
font-size: 21px;
border: 1px solid #999;
box-shadow: 0 6px 6px -6px rgba(0, 0, 0, 1);
}
#progbar{
background-color: #5DADE2;
height: 20px;
}
.panel-primary{
border: 2px solid #5DADE2;
border-radius: 3px;
}
.panel-heading{
background-color: #5DADE2;
color: #fff;
padding: 5px;
}
.panel-danger{
border: 2px solid #EC7063;
border-radius: 3px;
}
.panel-headingd{
background-color: #EC7063;
color: #fff;
padding: 5px;
}
.panel-body{
padding: 3px;
}
#detailsAddr{
text-align: right;
}
#detailsAddrQr{
display: block;
width: 140px;
float: right;
}
</style>
<!-- jQuery -->
<script src="js/jquery-3.2.1.min.js"></script>
<!-- QRCode Webcam Scanner -->
<script src="js/instascan.min.js"></script>
<!-- load bitcoinjs-lib -->
<script src="js/bitcoinjs-lib-3.1.1.js"></script>
<!-- big integer for mouse entropy -->
<script src="js/metropy.js"></script>
<!-- QRCode lib -->
<script type="text/javascript" src="js/qrcode.js"></script>
<!-- Network specific methods -->
<script type="text/javascript" src="js/network.js"></script>
</head>
<body>
<script type="text/javascript">document.write(headerHtml())</script>
<!-- introduction -->
<br>
<div class="well">Segwitaddress.org is an <a href="https://github.com/coinables/segwitaddress"><span class="label label-primary">OPEN SOURCE</span></a> bitcoin paper wallet generator that utilizes Segregated Witness (SegWit) Pay To Witness Public Key Hash wrapped in a Pay to Script Hash (P2SH-P2WPKH) addresses. Segwitaddress.org uses the <a href="https://github.com/bitcoinjs/bitcoinjs-lib"><span class="label label-success">BitcoinJS</span></a> library.
<br>
<br>
All of the functions on this page can be ran offline, by <a href="https://github.com/coinables/segwitaddress/releases">saving this site</a> and running the index.html file, except for the sweep function which requires internet access to check the UTXOs and broadcast to the network.
<br>
<br>
You can enable testnet mode by adding <span class="label label-reference">?testnet=true</span> to the end of the url.
</div>
<!-- Create Segwit Address -->
<br>
<a href="#entropyRef"><button id="entropyRef" onClick="return btnCreate();" class="btn btn-primary">Generate New SegWit Address</button></a>
<br>
<!-- mouse entropy canvas -->
<canvas id="entropyCanvas" width="800" height="200" style="border: 1px solid black;"></canvas>
<div class="progress progress-striped">
<div class="progress-bar progress-bar-info" style="width: 0%" id="progbar"></div>
</div>
<div id="canvasCounter"></div>
<!-- QR Code Output -->
<table width="100%">
<tr>
<td width="50%"><span id="share">OK TO SHARE</span></td>
<td align="right"><span id="keep">KEEP PRIVATE</span></td>
</tr>
<tr>
<td>
<div id="qrcode"></div>
<div id="swaddr"></div>
</td>
<td align="right">
<div id="qrcodepk"></div>
<div id="swpk"></div>
</td>
</tr>
</table>
<br>
<hr class="hr">
<br>
<!-- Sweep Key -->
<h2>Sweep SegWit Private Key</h2>
<div id="sweepcont">
<input type="password" class="form-control input-lg" placeholder="SegWit Private Key" id="wifprivatekey">
<button class="btn btn-default" onClick="return turnOnWC();">SCAN WITH WEBCAM</button><span id="qrnotify" class="label label-success">QR CODE SCANNED</span>
<video id="qrcam"></video>
<br>
<input type="text" class="form-control input-lg" placeholder="Destination Address" id="toaddress">
<button class="btn btn-default" onClick="return turnOnWC2();">SCAN WITH WEBCAM</button><span id="qrnotify2" class="label label-success">QR CODE SCANNED</span>
<br>
<textarea id="inputdata" cols="100" rows="7"></textarea>
<input type="number" class="form-control input-lg" id="satperbyte"> <small>Miner Fee Satoshis Per Byte</small>
<br>
<br>
<button class="btn btn-success" id="sweepkey">TRANSFER ALL FUNDS</button>
<br>
</div>
<!-- Sweep Transaction Output -->
<div id="results"></div>
<br>
<hr class="hr">
<br>
<!-- Bulk Keys Generator -->
<h2>Bulk Keys</h2>
<small>Prints in CSV format. 300 will take about 10 seconds.</small>
<br>
<h4>Amount to Generate:</h4>
<input type="number" id="bulknum">
<br>
<button id="btnBulk" onClick="return bulkAddress();" class="btn btn-warning">Bulk Generate</button> <button class="btn btn-danger" id="clearBulk">Clear</button>
<br>
<br>
<div id="bulkkeys" class="well well-lg"></div>
<br>
<br>
<hr class="hr">
<br>
<!-- Brain Wallet -->
<h2>Brain Wallet</h2>
<p>A brain wallet is a private key derived from some arbitrary data provided by the user. Brain wallets come with a high risk of losing funds through brute forcing. Some people use books, birth dates, poems or song lyrics -- these people lose all their money. Don't lose your money.</p>
<p>Brain Wallet Input: <input type="text" id="brainWalletInput" ></p>
<a href="#entropyRef"><button id="brainBtn" class="btn btn-info">Create</button></a>
<br>
<br>
<hr class="hr">
<br>
<!-- Details Section -->
<h2>Details</h2>
<p>Enter a WIF private key to generate its corresponding segwit address.</p>
<p>WIF Private Key: <input type="text" id="detailsWIF" ></p>
<button id="detailsBtn" class="btn btn-info">Show Details</button>
<br>
<div id="detailsOutput" class="well well-lg"></div>
<br>
<br>
<br>
<br>
<!-- footer -->
<a href="https://bitcoincore.org/en/segwit_adoption/"><span class="label-default"><span id="wit">SEG</span>WIT</span></a>
<a href="https://github.com/coinables/segwitaddress"><span class="label-primary">OPEN SOURCE</span></a>
<a href="https://github.com/bitcoinjs/bitcoinjs-lib"><span class="label-success">BITCOINJS</span></a>
<script>
function generateNewKeyPair(){
var NETWORK = currentNetwork();
var wif = bitcoin.ECPair.makeRandom({network: NETWORK}).toWIF();
var keyPair = bitcoin.ECPair.fromWIF(wif, NETWORK);
var pubKey = keyPair.getPublicKeyBuffer();
var pubKeyHash = bitcoin.crypto.hash160(pubKey);
var redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(pubKeyHash);
var redeemScriptHash = bitcoin.crypto.hash160(redeemScript);
var scriptPubKey = bitcoin.script.scriptHash.output.encode(redeemScriptHash);
var newaddy = bitcoin.address.fromOutputScript(scriptPubKey, NETWORK);
return {
wifPrivateK: wif,
swAddress: newaddy
};
}
function btnCreate(){
$("#entropyCanvas").css("display","block");
$("#entropywell").css("display","block");
//get mouse position to use for randomness
function getMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
}
var entropy = "";
var canvas = document.getElementById('entropyCanvas');
var c2d = canvas.getContext("2d");
c2d.font = "30px Arial";
c2d.fillText("Move Your Mouse Around Here For Randomness",10,50);
canvas.addEventListener('mousemove', function(evt) {
//append until a length of 8192
if(entropy.length < 8192){
var mousePos = getMousePos(canvas, evt);
//append mouse position to entropy source
entropy += mousePos.x + mousePos.y;
//update progress bar
entropyCalcBar = entropy.length / 8192;
entropyPercent = entropyCalcBar * 100;
entropyPercentFixed = entropyPercent.toFixed(0);
entropyBar = "width: "+entropyPercentFixed+"%";
document.getElementsByTagName('div')[2].setAttribute("style", entropyBar);
document.getElementById("canvasCounter").innerHTML = entropy.length+"/8192";
} else {
//length requirement met, hide entropy canvas
$("#entropyCanvas").css("display","none");
$("#entropywell").css("display","none");
$("#canvasCounter").html("");
//create a key pair based on the 8192 random integers through sha256 hash with the addMouseEntropy function
me.addMouseEntropy(entropy, currentNetwork(), function(maddr, mpk){
document.getElementById("swaddr").innerHTML = "<br><div class='panel panel-primary'><div class='panel-heading'><h3 class='panel-title'>Segwit Address</h2></div><div class='panel-body'>" + maddr + "</div></div>";
//blank out any existing qr code
document.getElementById("qrcode").innerHTML = "";
//create new qrcode with segwit address
new QRCode(document.getElementById("qrcode"), maddr);
document.getElementById("swpk").innerHTML = "<br><div class='panel panel-danger'><div class='panel-headingd'><h3 class='panel-title'>Segwit Private Key</h2></div><div class='panel-body'>" + mpk + "</div></div>";
//blank out any exisitng private key qr code
document.getElementById("qrcodepk").innerHTML = "";
//create new qrcode with private key
new QRCode(document.getElementById("qrcodepk"), mpk);
//zero out entropy source
entropy = "";
});
}
}, false);
}
function brainWalletCreate(){
//fetch user input
var brainInput = $("#brainWalletInput").val();
//create a key pair based on the sha256 hash of the users input
me.addMouseEntropy(brainInput, currentNetwork(), function(maddr, mpk){
document.getElementById("swaddr").innerHTML = "<br><div class='panel panel-primary'><div class='panel-heading'><h3 class='panel-title'>Segwit Address</h2></div><div class='panel-body'>" + maddr + "</div></div>";
//blank out any existing qr code
document.getElementById("qrcode").innerHTML = "";
//create new qrcode with segwit address
new QRCode(document.getElementById("qrcode"), maddr);
document.getElementById("swpk").innerHTML = "<br><div class='panel panel-danger'><div class='panel-headingd'><h3 class='panel-title'>Segwit Private Key</h2></div><div class='panel-body'>" + mpk + "</div></div>";
//blank out any exisitng private key qr code
document.getElementById("qrcodepk").innerHTML = "";
//create new qrcode with private key
new QRCode(document.getElementById("qrcodepk"), mpk);
//zero out brain wallet input
brainInput = "";
});
}
function details(){
//fetch private key from input
var wifPrivateKey= $("#detailsWIF").val();
//remove any spaces
wifPrivateKey = wifPrivateKey.trim();
var NETWORK = currentNetwork();
var wif = wifPrivateKey;
var keyPair = bitcoin.ECPair.fromWIF(wif, NETWORK);
var pubKey = keyPair.getPublicKeyBuffer();
var pubKeyHash = bitcoin.crypto.hash160(pubKey);
var pubKeyHex = pubKey.toString('hex');
var redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(pubKeyHash);
var redeemScriptHex = redeemScript.toString('hex');
var redeemScriptHash = bitcoin.crypto.hash160(redeemScript);
var scriptPubKey = bitcoin.script.scriptHash.output.encode(redeemScriptHash);
var newaddy = bitcoin.address.fromOutputScript(scriptPubKey, NETWORK);
//output details
$("#detailsOutput").html("<p>WIF: "+ wif + "<div id='detailsPK'></div></p><div id='detailsAddr'>Address: "+newaddy+"</div><br><div id='detailsAddrQr'></div><br><p></p><p>Public Key: "+pubKeyHex+"</p><p>Redeem Script: "+redeemScriptHex+"</p><br>");
//create details private key qrcode
new QRCode(document.getElementById("detailsPK"), {
text: wif,
width: 128,
height: 128
});
//create details address qrcode
new QRCode(document.getElementById("detailsAddrQr"), {
text: newaddy,
width: 128,
height: 128
});
}
function bulkAddress(){
var keynum = document.getElementById("bulknum").value;
if(keynum < 1001){
for(i=0; i < keynum; i++){
var keys = generateNewKeyPair();
var swaddress = keys.swAddress;
var pkey = keys.wifPrivateK;
var visualnum = i +1;
$("#bulkkeys").append("<p>"+ visualnum + ", ""+swaddress+"", ""+pkey+""</p>");
}
} else {
alert("1000 is the max bro");
}
}
function clearBulk(){
$("#bulkkeys").html("");
}
function sweepKey() {
var DOUBLE_TX = false
var NETWORK = currentNetwork();
var API_DOMAIN = apiDomain();
var EXPLORER_DOMAIN = explorerDomain();
var Buffer = null
//fetch private key from input
var WIF = $("#wifprivatekey").val();
WIF = WIF.trim();
//check if empty
if (WIF == "") {
alert("The WIF Private key must be entered to send!");
return;
};
//check address filled out
var toAddress = $("#toaddress").val();
toAddress = toAddress.trim();
if (toAddress == "") {
alert("Please Enter Address to send to!");
return;
};
//convert private key to address
var keyPair = bitcoin.ECPair.fromWIF(WIF, NETWORK);
var pubKey = keyPair.getPublicKeyBuffer();
var pubKeyHash = bitcoin.crypto.hash160(pubKey);
var redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(pubKeyHash);
var redeemScriptHash = bitcoin.crypto.hash160(redeemScript);
var scriptPubKey = bitcoin.script.scriptHash.output.encode(redeemScriptHash);
var P2SHAddress = bitcoin.address.fromOutputScript(scriptPubKey, NETWORK);
//console.log(P2SHAddress);
//get UTXOs for address of private key
var data
$.ajax({
async: true,
type: "GET",
url: API_DOMAIN + "/v1/blockchain/address/" + P2SHAddress + "/unspent",
success: function(result) {
console.log(result.unspent.length + " utxos found");
data = result.unspent.map(function(item){
return {
"txid": item.txid,
"vout": item.n,
"satoshis": item.value_int
}
})
//output response into the inputdata element
$("#inputdata").val(JSON.stringify(data, null, 2))
}
});
//validate key
try {
var keyPair = bitcoin.ECPair.fromWIF(WIF, NETWORK)
} catch (e) {
alert('Invalid WIF private key.')
return
}
//check UTXO
var inputData = $("#inputdata").val()
if (inputData == "") {
alert("Fetching UTXOs, click TRANSFER again to finalize and sweep.")
return
}
inputData = JSON.parse(inputData)
//fetch to address
var toAddressBox = $("#toaddress").val();
var toAddress = toAddressBox;
//check if address fileld out
if (toAddress == "") {
alert("Please Enter Address to send to!")
return
} else {
try {
var toAddressObj = bitcoin.address.fromBase58Check(toAddress)
} catch(e) {
alert("To Address was not a valid Bitcoin address!")
return
}
}
//get fee rate from input
var satPerByte = $("#satperbyte").val()
if (satPerByte == "") {
alert("Please enter Satoshi Per Byte Fee Rate!")
return
}
satPerByte = parseFloat(satPerByte)
var pubKey = keyPair.getPublicKeyBuffer()
var pubKeyHash = bitcoin.crypto.hash160(pubKey)
var redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(pubKeyHash)
var redeemScriptHash = bitcoin.crypto.hash160(redeemScript)
var scriptPubKey = bitcoin.script.scriptHash.output.encode(redeemScriptHash)
//build transaction from utxo set
var txb = new bitcoin.TransactionBuilder(NETWORK)
for (var i = 0; i < inputData.length; i++) {
txb.addInput(inputData[i].txid,
inputData[i].vout,
0xffffffff,
scriptPubKey)
}
//calculate tx size and fee
var estimatedByteCount = getByteCountSegwitP2SH(inputData.length, 1)
var estimatedFeeSatoshis = Math.ceil(estimatedByteCount * satPerByte)
var totalSatoshis = inputData.reduce(function(total, item){return total += item.satoshis}, 0)
var totalSatoshisMinusFee = totalSatoshis - estimatedFeeSatoshis
if (DOUBLE_TX) {
if (NETWORK.scriptHash == toAddressObj.version) {
alert("Can't double Transaction to P2SH, please send to P2PKH")
return
}
var sendToScriptPubkey = redeemScript
} else if (NETWORK.pubKeyHash == toAddressObj.version) {
var sendToScriptPubkey = bitcoin.script.pubKeyHash.output.encode(toAddressObj.hash)
} else if (NETWORK.scriptHash == toAddressObj.version) {
var sendToScriptPubkey = bitcoin.script.scriptHash.output.encode(toAddressObj.hash)
}
//add output
txb.addOutput(sendToScriptPubkey,
totalSatoshisMinusFee)
//sign all inputs
for (var i = 0; i < inputData.length; i++) {
txb.sign(i, keyPair, redeemScript, null, inputData[i].satoshis)
}
var tx = txb.build()
var tx_txid = tx.getId()
var tx_raw = tx.toHex()
if (DOUBLE_TX) {
var secondTxInput = {
txid: tx_txid,
vout: 0,
satoshis: totalSatoshisMinusFee
}
var txb2 = new bitcoin.TransactionBuilder(NETWORK)
var sendAmountMinusFees = secondTxInput.satoshis - Math.ceil(142 * satPerByte)
if (secondTxInput.satoshis - Math.ceil(142 * satPerByte) < 0) {
alert('Not enough funds to pay for Double TX fees.')
return
}
if (parseInt(sendAmountMinusFees / 2) < 546) {
alert('Not enough funds to pay for Double TX fees. Would create dust.')
return
}
txb2.addInput(secondTxInput.txid,
secondTxInput.vout,
0xffffffff,
redeemScript)
txb2.tx.ins[0].prevOutType = bitcoin.script.types.P2WPKH
txb2.addOutput(sendToScriptPubkey,
parseInt(sendAmountMinusFees / 2))
txb2.addOutput(sendToScriptPubkey,
parseInt(sendAmountMinusFees / 2))
txb2.sign(0, keyPair, null, null, secondTxInput.satoshis)
var tx2 = txb2.build()
var tx2_txid = tx2.getId()
var tx2_raw = tx2.toHex()
console.log()
setTimeout(function(){
$.ajax({
async: true,
type: "POST",
url: API_DOMAIN + "/v1/blockchain/pushtx",
contentType: 'application/json',
dataType: "json",
data: JSON.stringify({hex: tx2_raw}),
success: function(result) {
console.log("Transaction #2 sent!");
}
});
},1500)
}
$.ajax({
async: true,
type: "POST",
url: API_DOMAIN + "/v1/blockchain/pushtx",
contentType: 'application/json',
dataType: "json",
data: JSON.stringify({hex: tx_raw}),
success: function(result) {
console.log("Transaction sent!");
}
});
$("#results").html(
"Transaction ID:<br><a href=\"" + EXPLORER_DOMAIN + "/tx/" + tx_txid + "\" target=\"_blank\">" +
tx_txid + "</a><br>" +
"Raw Transaction:<br><textarea cols=\"150\" rows=\"10\">" +
tx_raw + "</textarea>" +
(!DOUBLE_TX ? "" : "<br><br>Transaction #2 ID: (Raw Segwit inputs and outputs)<br><a href=\"" + EXPLORER_DOMAIN + "/tx/" + tx2_txid + "\" target=\"_blank\">" +
tx2_txid + "</a><br>" +
"Raw Transaction:<br><textarea cols=\"150\" rows=\"10\">" +
tx2_raw + "</textarea>")
);
}
function getByteCountSegwitP2SH(inputCount,outputCount,isMultisig,m,n) {
var inputSize = isMultisig ? ((73 * m) + (34 * n) + 6 + (76 * 4)) : 108 + (64 * 4)
var outputSize = 34 * 4
var estimatedWeight = inputSize * inputCount + outputSize * outputCount + 10 * 4
return Math.ceil(estimatedWeight / 4)
}
$(document).ready( function() {
$("#sweepkey").on('click', sweepKey);
$("#detailsBtn").on('click', details);
$("#brainBtn").on('click', brainWalletCreate);
$("#clearBulk").on('click', clearBulk);
Buffer = bitcoin.script.compile([]).constructor;
$.ajax({
async: true,
type: "GET",
url: "https://bws.bitpay.com/bws/api/v2/feelevels",
success: function(result) {
var satPerByte = Math.ceil(result.filter(function(item){ return item.level == "superEconomy" })[0].feePerKb / 1000)
var calcSat = satPerByte / 2;
$("#satperbyte").val(calcSat.toFixed(0));
}
});
});
</script>
<script>
function turnOnWC(){
$("#qrcam").css("display","block");
var qr = new Instascan.Scanner({
video: document.getElementById("qrcam")
});
qr.addListener('scan', function(data){
document.getElementById("wifprivatekey").value = data;
if(document.getElementById("wifprivatekey").value.length > 20){
qr.stop();
$("#qrcam").css("display","none");
$("#qrnotify").css("display","block");
}
});
Instascan.Camera.getCameras().then(function(cams){
qr.start(cams[0]);
}).catch(function(err){
console.log(err);
});
}
function turnOnWC2(){
$("#qrcam").css("display","block");
var qr = new Instascan.Scanner({
video: document.getElementById("qrcam")
});
qr.addListener('scan', function(data){
document.getElementById("toaddress").value = data;
if(document.getElementById("toaddress").value.length > 20){
qr.stop();
$("#qrcam").css("display","none");
$("#qrnotify2").css("display","block");
}
});
Instascan.Camera.getCameras().then(function(cams){
qr.start(cams[0]);
}).catch(function(err){
console.log(err);
});
}
</script>
<script>
//redirect https if not local
if (window.location.host.indexOf('github.io') > -1 && window.location.protocol != "https:"){
window.location.protocol = "https";
}
</script>
</body>
</html>