From 6e59e1265e60acf3f42ba23a229db95b2f74bfe1 Mon Sep 17 00:00:00 2001 From: "Jonathan D.K. Gibbons" Date: Tue, 28 Dec 2021 09:40:35 -0500 Subject: [PATCH 1/3] Fixed getWebhid to drive the page like an external signer. This has the side effect of showing the transaction hash onscreen, which does have the benefit of letting the user compare the one the ledger shows with the one onscreen. --- docs/transfer-ledger-create.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/transfer-ledger-create.html b/docs/transfer-ledger-create.html index aba9d6c..db98ad0 100644 --- a/docs/transfer-ledger-create.html +++ b/docs/transfer-ledger-create.html @@ -290,17 +290,17 @@ } async function getWebhid(){ - var cmd = getTransferCmd(); - var txn = new TextEncoder().encode(cmd.cmds[0].cmd); - console.log(txn); 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 ]; + 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); } function reset(){ From 5f43b3bf9c2e99e1dd0a8677115ae3851b5078df Mon Sep 17 00:00:00 2001 From: "Jonathan D.K. Gibbons" Date: Tue, 28 Dec 2021 10:24:47 -0500 Subject: [PATCH 2/3] Add "show ledger public key" dropdown. --- docs/transfer-ledger-create.html | 42 +++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/transfer-ledger-create.html b/docs/transfer-ledger-create.html index db98ad0..8ed61e3 100644 --- a/docs/transfer-ledger-create.html +++ b/docs/transfer-ledger-create.html @@ -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){ @@ -289,12 +293,16 @@ 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); @@ -302,6 +310,21 @@ 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() @@ -984,6 +1007,17 @@

Kadena Coin Transfer

+
+
+ + Show Ledger Public Key +
+
+
+

+
+
+

@@ -991,6 +1025,8 @@

Kadena Coin Transfer

Sign with Ledger
Make Transfer
Reset
+
+