Skip to content

Commit

Permalink
Merge pull request #2 from obsidiansystems/jg-fix-ledger-transfer
Browse files Browse the repository at this point in the history
Fixed getWebhid to drive the page like an external signer.
  • Loading branch information
romefeller authored Dec 28, 2021
2 parents 89749d4 + b84e255 commit 2dd7619
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ ENV GIT_URL https://github.com/obsidiansystems/kadena-transfer-js.git

RUN apt-get -y update \
&& apt-get -y install git \
&& git clone -b hw-ledger-signing ${GIT_URL} \
&& git clone -b jg-fix-ledger-transfer ${GIT_URL} \
&& cp -r /kadena-transfer-js/* /usr/share/nginx/html
54 changes: 46 additions & 8 deletions docs/transfer-ledger-create.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@
// INITIATION FUNCTIONS
window.addEventListener('load', function (event) {
document.getElementById("getSig-button").addEventListener("click", async function(e){
getWebhid();
signWithLedger();
})

document.getElementById("getPubkey-button").addEventListener("click", async function(e){
getPublicKeyFromLedger();
})

document.getElementById("fromAccount").addEventListener("blur", async function(e){
Expand Down Expand Up @@ -288,19 +292,40 @@
function formIsValid(){
return $('.form').form('is valid');
}

async function getWebhid(){
var cmd = getTransferCmd();
var txn = new TextEncoder().encode(cmd.cmds[0].cmd);
console.log(txn);

async function getLedger(){
if (!window.ledger) {
var transp = await window.TranspWeb.create();
window.ledger = new window.Kadena(transp);
}
}
}

async function signWithLedger(){
getLedger();

if (document.getElementById("getPubkey-content").innerText == "") {
document.getElementById("publicKey").value = [ (await window.ledger.getPublicKey("44'/626'/0'")).publicKey ];
} else {
document.getElementById("publicKey").value = [ document.getElementById("getPubkey-content").innerText ];
}
getHash();
var cmd = document.getElementById("cmd").value
var txn = new TextEncoder().encode(cmd.cmds[0].cmd);
var signed = await window.ledger.signTransaction("m/44'/626'/0'",txn);
var sig = signed.signature;
document.getElementById("signature").value = sig;
console.log(sig);
}

async function getPublicKeyFromLedger(){
getLedger();

var publicKey = (await window.ledger.getPublicKey("44'/626'/0'")).publicKey;
document.getElementById("publicKey").value = [ publicKey ];
document.getElementById("getPubkey-content").innerText = publicKey;
let title = document.getElementById("getPubkey-button");
let content = document.getElementById("getPubkey-content");
title.classList.add('active')
content.classList.add('active')
}

function reset(){
Expand Down Expand Up @@ -984,13 +1009,26 @@ <h1>Kadena Coin Transfer</h1>
</div>
</div>
</div>
<div class="ui accordion">
<div class="title" id="getPubkey-button">
<i class="dropdown icon"></i>
Show Ledger Public Key
</div>
<div class="content" id="getPubkey-content">
<div class="ui message">
<p style="font-weight:bold;" id="hash-string"></p>
</div>
</div>
</div>
<br/>
<div class="field">
<input type="text" id="signature" placeholder="Enter Private Key or Signature">
</div>
<div id="getSig-button" class="ui submit primary button">Sign with Ledger</div>
<div id="submit-button" class="ui submit primary button">Make Transfer</div>
<div id="reset-button" class="ui button">Reset</div>
<br/>
<br/>
<div id="acct-err" class="ui center error message" hidden></div>
<div id="cmd"></div>
<div id="xchain-box" class="ui compact message hidden" hidden>
Expand Down

0 comments on commit 2dd7619

Please sign in to comment.