Skip to content

Commit

Permalink
Add "show ledger public key" dropdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonored committed Dec 28, 2021
1 parent 6e59e12 commit 5f43b3b
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 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 @@ -289,19 +293,38 @@
return $('.form').form('is valid');
}

async function getWebhid(){
async function signWithLedger(){
if (!window.ledger) {
var transp = await window.TranspWeb.create();
window.ledger = new window.Kadena(transp);
}
document.getElementById("publicKey").value = [ (await window.ledger.getPublicKey("44'/626'/0'")).publicKey ];
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;
}

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

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(){
clearError()
Expand Down Expand Up @@ -984,13 +1007,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 5f43b3b

Please sign in to comment.