Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest cointoolkit fixes #34

Open
wants to merge 80 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
f4ca6f3
new ledgerjs
backpacker69 Jan 17, 2022
774b840
new ledger.js
backpacker69 Jan 17, 2022
0b6d0dd
Merge branch 'gh-pages' of https://github.com/peercoin/cointoolkit in…
backpacker69 Jan 17, 2022
6eac0f3
Merge branch 'gh-pages' of github.com:backpacker69/cointoolkit into g…
backpacker69 Jan 17, 2022
7491e47
temporary bypass
backpacker69 Jan 17, 2022
12e9664
one more export
backpacker69 Jan 17, 2022
9410561
extra export
backpacker69 Jan 17, 2022
0cbb82a
export
backpacker69 Jan 17, 2022
f542cf2
another day another ledger
backpacker69 Jan 18, 2022
a6dc664
more
backpacker69 Jan 18, 2022
e9088ea
...
backpacker69 Jan 18, 2022
1df668e
...
backpacker69 Jan 18, 2022
36b5dcd
...
backpacker69 Jan 18, 2022
9659f60
...
backpacker69 Jan 18, 2022
b4a1d9e
...
backpacker69 Jan 18, 2022
f7befcf
...
backpacker69 Jan 18, 2022
3e61004
please work
backpacker69 Jan 18, 2022
038a2e5
in sunny's name
backpacker69 Jan 18, 2022
5db9836
.
backpacker69 Jan 18, 2022
62e9783
buffer
backpacker69 Jan 18, 2022
4f30af2
..
backpacker69 Jan 18, 2022
4e97b3e
?
backpacker69 Jan 19, 2022
bcca757
?
backpacker69 Jan 20, 2022
9670f72
update to named parameters
backpacker69 Jan 20, 2022
75d2782
finish it
backpacker69 Jan 20, 2022
3cc81a8
extra additionals
backpacker69 Jan 20, 2022
7a83f89
no
backpacker69 Jan 20, 2022
8f2e956
fixups
backpacker69 Jan 20, 2022
1c7b054
append hashType to signature to make it valid
backpacker69 Jan 20, 2022
e30c3e3
hmm
backpacker69 Jan 20, 2022
40d5573
maybe not
backpacker69 Jan 20, 2022
e608a75
new style for split
backpacker69 Jan 21, 2022
02e8a2a
oops
backpacker69 Jan 21, 2022
557c2bb
oops
backpacker69 Jan 21, 2022
dc5e2be
no params
backpacker69 Jan 21, 2022
b7f9ba7
extra parm
backpacker69 Jan 21, 2022
6915410
trying original hw-app-btc app
backpacker69 Jan 24, 2022
00981b7
kludge for multisig test
backpacker69 Jan 24, 2022
f9456c9
Revert "kludge for multisig test"
backpacker69 Jan 24, 2022
548c7b7
return my packages
backpacker69 Jan 25, 2022
5f2e5fc
new version
backpacker69 Jan 25, 2022
c86b650
real new version
backpacker69 Jan 25, 2022
b367d9d
real new version
backpacker69 Jan 25, 2022
80531a6
new version
backpacker69 Jan 26, 2022
8e6a2d3
new version
backpacker69 Feb 4, 2022
fd6e66d
new version
backpacker69 Feb 8, 2022
a8dfa5a
new version
backpacker69 Feb 9, 2022
a5edc93
different way to split
backpacker69 Feb 9, 2022
b62c835
try with segwit
backpacker69 Feb 9, 2022
b138a72
new version
backpacker69 Feb 9, 2022
831f620
no segwit
backpacker69 Feb 9, 2022
fa17d78
coinstake initial work
backpacker69 Feb 10, 2022
323e21a
enable pubkey outputs
backpacker69 Feb 10, 2022
afc6de5
let's specify initial timestamp only when version requires it
backpacker69 Feb 10, 2022
310e85b
correct js syntax
backpacker69 Feb 10, 2022
a57083e
correct js syntax
backpacker69 Feb 10, 2022
6366bda
let's try older hw-btc-app for time being
backpacker69 Feb 14, 2022
4c9ce90
add timestamps for peercoin
backpacker69 Feb 14, 2022
472b369
down to 6.7.0
backpacker69 Feb 14, 2022
e7dd060
speculos attempt
backpacker69 Feb 15, 2022
f6332e8
speculos transport
backpacker69 Feb 15, 2022
4eeb650
apduPort config
backpacker69 Feb 15, 2022
34804d8
wtf
backpacker69 Feb 15, 2022
9e8939d
wtf
backpacker69 Feb 15, 2022
bf0f31d
wtf
backpacker69 Feb 15, 2022
cd83483
wtf
backpacker69 Feb 16, 2022
28f4a8d
wtf
backpacker69 Feb 16, 2022
e0d3cf7
wtf
backpacker69 Feb 16, 2022
3e6431f
different module for speculos
backpacker69 Feb 16, 2022
0f8c3e1
revert speculos
backpacker69 Feb 16, 2022
6eeffe0
wtf
backpacker69 Feb 16, 2022
40f0247
fix timestamp
backpacker69 Feb 18, 2022
c3da358
wtf
backpacker69 Feb 18, 2022
26e6ae1
differnet timesmtmp
backpacker69 Feb 18, 2022
6884000
fixup parameters
backpacker69 Feb 24, 2022
27548b8
allow non multisig to sign properly
backpacker69 Feb 25, 2022
9fbdd43
allow to broadcast from sign page
backpacker69 Feb 25, 2022
88fd63d
trim inputs during signing
backpacker69 Mar 29, 2024
0134e71
throw error if transaction unchanged
backpacker69 Apr 12, 2024
0a35c38
default to version 3
backpacker69 Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ <h2>New Transaction <small>Create a new transaction</small></h2>

<hr>

<label>Lock Time</label>
<p>The <a href="https://bitcoin.org/en/developer-guide#locktime-and-sequence-number">locktime</a> indicates the earliest time a transaction can be added to the block chain.</p>
<input type="text" class="form-control" value="0" id="nLockTime">
<label>Transaction Version</label>
<p>Desired version of transaction to be created.</p>
<input type="text" class="form-control" value="3" id="nVersion">

<hr>

Expand All @@ -714,6 +714,12 @@ <h2>New Transaction <small>Create a new transaction</small></h2>
<hr>
</div>

<label>Lock Time</label>
<p>The <a href="https://bitcoin.org/en/developer-guide#locktime-and-sequence-number">locktime</a> indicates the earliest time a transaction can be added to the block chain.</p>
<input type="text" class="form-control" value="0" id="nLockTime">

<hr>

<label>Network</label>
<p>The <a href="#settings">settings</a> page can be used to select alternative networks of which you can retrieve your unspent outputs and broadcast a signed transaction into.</p>

Expand Down Expand Up @@ -1440,7 +1446,7 @@ <h2>Settings</h2>
<option value="sparklecoin" rel="0x3f;0x7d;0xbf;0x0488b21e;0x0488ade4;true;true;true;true;true;false;6;SPRK;0x6;44'/239'/0'/0/0;;">Sparklecoin</option>
<option value="bitcoin" rel="0x00;0x05;0x80;0x0488b21e;0x0488ade4;false;blockr_io;blockr_io;false;false;false;8;BTC;0x0;44'/0'/0'/0/0;bc;">Bitcoin</option>
<option value="bitcoin_cash" rel="0x00;0x05;0x80;0x0488b21e;0x0488ade4;false;blockexplorer;blockexplorer;false;false;false;8;BCH;0x0;44'/0'/0'/0/0;;">Bitcoin Cash</option>
<option value="peercoin_testnet" rel="0x6f;0xc4;0xef;0x043587cf;0x04358394;false;false;false;true;true;false;6;tPPC;0x1;;tpc;">Peercoin (testnet)</option>
<option value="peercoin_testnet" rel="0x6f;0xc4;0xef;0x043587cf;0x04358394;false;false;false;true;true;false;6;tPPC;0x1;44'/1'/0'/0/0;tpc;">Peercoin (testnet)</option>
<option value="sparklecoin_testnet" rel="0x7f;0xc4;0xff;0x043587cf;0x04358394;true;true;true;true;true;false;6;tSPRK;0x1;;;">Sparklecoin (testnet)</option>
<option value="bitcoin_testnet" rel="0x6f;0xc4;0xef;0x043587cf;0x04358394;false;blockrio_bitcointestnet;false;false;false;false;8;tBTC;0x1;;tb;">Bitcoin (testnet)</option>
<option value="custom" rel="0x00;0x05;0x80;0x0488b21e;0x0488ade4;false;false;false;false;false;false;8;CUSTOM;0x0;;;">Custom</option>
Expand Down
6 changes: 3 additions & 3 deletions js/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
coinjs.priv = 0x80;
coinjs.multisig = 0x05;
coinjs.hdkey = {'prv':0x0488ade4, 'pub':0x0488b21e};
coinjs.bech32 = {'charset':'qpzry9x8gf2tvdw0s3jn54khce6mua7l', 'version':0, 'hrp':'bc'};
coinjs.bech32 = {'charset':'qpzry9x8gf2tvdw0s3jn54khce6mua7l', 'version':0, 'hrp':'pc'};
coinjs.txExtraTimeField = false;
coinjs.txExtraTimeFieldValue = false;
coinjs.txExtraUnitField = false;
Expand Down Expand Up @@ -1979,7 +1979,7 @@
var buffer = [];
buffer = buffer.concat(coinjs.numToBytes(parseInt(this.version),4));

if (coinjs.txExtraTimeField) {
if (coinjs.txExtraTimeField && (['tPPC','PPC'].includes(coinjs.symbol) && this.version<3)) {
buffer = buffer.concat(coinjs.numToBytes(parseInt(this.nTime),4));
}

Expand Down Expand Up @@ -2064,7 +2064,7 @@

obj.version = readAsInt(4);

if (coinjs.txExtraTimeField) {
if (coinjs.txExtraTimeField && (['tPPC','PPC'].includes(coinjs.symbol) && obj.version<3)) {
obj.nTime = readAsInt(4);
}

Expand Down
50 changes: 43 additions & 7 deletions js/cointoolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ $(document).ready(function() {
h += '<td class="col-xs-1">'+(o.value/("1e"+coinjs.decimalPlaces)).toFixed(coinjs.decimalPlaces)+'</td>';
h += '<td class="col-xs-2"><input class="form-control" type="text" value="'+Crypto.util.bytesToHex(o.script.buffer)+'" readonly></td>';
h += '</tr>';
} else if(o.script.chunks.length==0) {
h += '<tr>';
h += '<td><input type="text" class="form-control" value="coinstake" readonly></td>';
h += '<td></td>'; // to account for known address value
h += '<td class="col-xs-1">0.0000000</td>';
h += '<td class="col-xs-2"><input class="form-control" type="text" value="" readonly></td>';
h += '</tr>';
} else {

var addr = '';
Expand All @@ -382,6 +389,9 @@ $(document).ready(function() {
});
} else if((o.script.chunks.length==2) && o.script.chunks[0]==0){
addr = coinjs.bech32_encode(coinjs.bech32.hrp, [coinjs.bech32.version].concat(coinjs.bech32_convert(o.script.chunks[1], 8, 5, true)));
} else if((o.script.chunks.length==2) && o.script.chunks[1]==172){
var pubKey = Crypto.util.bytesToHex(o.script.chunks[0])
addr = coinjs.pubkey2address(pubKey, coinjs.pub);
} else {
var scriptHash = Crypto.util.bytesToHex(o.script.chunks[1]);
addr = coinjs.scripthash2address(scriptHash, coinjs.multisig);
Expand Down Expand Up @@ -707,11 +717,12 @@ $(document).ready(function() {
{verify: false, format: "legacy"}
);

var hasTimestamp = isPeercoin && currenttransaction.version < 3;
var publicKey = result.publicKey;
var path = coinjs.ledgerPath;

console.log("path",path,"address",result.bitcoinAddress,"pubkey",result.publicKey);
var txn = appBtc.splitTransaction(currenttransaction.serialize(),false,isPeercoin);
var txn = appBtc.splitTransaction(currenttransaction.serialize(),false,hasTimestamp,false);
var outputsBuffer = Crypto.util.bytesToHex(appBtc.serializeTransactionOutputs(txn));

var inputs = [];
Expand All @@ -729,7 +740,8 @@ $(document).ready(function() {
for (var i = 0; i < currenttransaction.ins.length; i++) {
var result = providers[$("#coinSelector").val()].getTransaction[toolkit.getTransaction](currenttransaction.ins[i].outpoint.hash,i,async function(result) {
// todo replace !isPeercoin with proper segwit support flag from coinjs params
inputs.push([result[1],appBtc.splitTransaction(result[0],!isPeercoin,isPeercoin),currenttransaction.ins[result[1]].outpoint.index,script]);
hasTimestamp = isPeercoin && ['1','2'].includes(result[0][1])
inputs.push([result[1],appBtc.splitTransaction(result[0],false,hasTimestamp,false),currenttransaction.ins[result[1]].outpoint.index,script]);
paths.push(path);
if (inputs.length == currenttransaction.ins.length) {
// we are ready
Expand All @@ -748,14 +760,18 @@ $(document).ready(function() {
var result=false;
if (currenttransaction.ins[0].script.buffer.slice(-1) == coinjs.opcode.OP_CHECKMULTISIG) {
// check if public key is part of multisig
result = await appBtc.signP2SHTransaction(inputs, paths, outputsBuffer, undefined, hashType, false, undefined, timeStamp);
var params = {inputs:inputs, associatedKeysets:paths, outputScriptHex:outputsBuffer, transactionVersion:currenttransaction.version, sigHashType: hashType, segwit:false};
if (timeStamp) {
params.initialTimestamp = timeStamp;
}
result = await appBtc.signP2SHTransaction(params);

var success=false;

console.log("signature result",result);
$.each(result, function(idx,itm) {
var signature = Crypto.util.hexToBytes(itm);
if (currenttransaction.signmultisig(idx,undefined,signature.slice(-1)[0]*1,signature)) {
var signature = Crypto.util.hexToBytes(itm+hashType.toString(16));
if (currenttransaction.signmultisig(idx,undefined,hashType*1,signature)) {
success=true;
}
});
Expand All @@ -767,7 +783,12 @@ $(document).ready(function() {
}
}
else {
result = await appBtc.createPaymentTransactionNew(inputs, paths, undefined, outputsBuffer, undefined, undefined, undefined, timeStamp);
var params = {inputs:inputs, associatedKeysets:paths, outputScriptHex:outputsBuffer, transactionVersion:currenttransaction.version, sigHashType: hashType, segwit:false};
if (timeStamp) {
params.initialTimestamp = timeStamp;
}

result = await appBtc.createPaymentTransactionNew(params);
callback(result);
}
}
Expand Down Expand Up @@ -2164,6 +2185,10 @@ $(document).ready(function() {
tx.lock_time = $("#nLockTime").val()*1;
}

if(($("#nVersion").val()).match(/^[0-9]+$/g)){
tx.version = $("#nVersion").val()*1;
}

if(($("#nTime").val()).match(/^[0-9]+$/g)){
tx.nTime = $("#nTime").val()*1;
}
Expand Down Expand Up @@ -2349,6 +2374,14 @@ $(document).ready(function() {
$(this).val($(this).val().replace(/\s/g, ""));
});

$("#signPrivateKey").focusout(function(){
$(this).val($(this).val().replace(/\s/g, ""));
});

$("#signTransaction").focusout(function(){
$(this).val($(this).val().replace(/\s/g, ""));
});

/* redeem from button code */
$("#redeemFromBtn").click(function(){
var redeem = redeemingFrom($("#redeemFrom").val());
Expand Down Expand Up @@ -2466,6 +2499,9 @@ $(document).ready(function() {

// var signed = t.sign(wifkey.val());
var signed = t.sign(wifkey.val(), $("#sighashType option:selected").val());
if (script.val() == signed) {
throw("transaction unchanged");
}
$("#signedData textarea").val(signed);
$("#signedData .txSize").html(t.size());
$("#signedData").removeClass('hidden').fadeIn();
Expand Down Expand Up @@ -2526,7 +2562,7 @@ $(document).ready(function() {
});

$("#signedData .signedToBroadcast").on( "click", function() {
$("#broadcast #rawTransaction").val(signed).fadeOut().fadeIn();
$("#broadcast #rawTransaction").val($("#signedData textarea").val()).fadeOut().fadeIn();
window.location.hash = "#broadcast";
});
} catch(e) {
Expand Down
Loading