[wip] add primitive message sign functionality

This commit is contained in:
2022-11-18 18:23:02 -07:00
parent 9589adaef8
commit a3cc4cdddc
3 changed files with 46 additions and 47 deletions
+4 -14
View File
@@ -42,46 +42,36 @@
<pre id="address-info"></pre> <pre id="address-info"></pre>
<h1>4. Sign a transaction</h1> <h1>4. Sign a transaction</h1>
<h2>4.1 Transaction info (information needed from you)</h2> <h2>4.1 Transaction info (information needed from you)</h2>
<ol> <ol>
<li>Source address (step 3): <code class="pv-address"></code></li> <li>Source address (step 3): <code class="pv-address"></code></li>
<li>Target address: <input type="text" id="tx-info-target" value="ak_wM8yFU8eSETXU7VSN48HMDmevGoCMiuveQZgkPuRn1nTiRqyv"></input></li> <li>Target address: <input type="text" id="tx-info-target" value="ak_wM8yFU8eSETXU7VSN48HMDmevGoCMiuveQZgkPuRn1nTiRqyv"></input></li>
<li>Amount (aettos): <input type="text" id="tx-info-amount" value="10"></input></li> <li>Amount (aettos): <input type="text" id="tx-info-amount" value="10"></input></li>
<li>Network: (FIXME: radio buttons)</li> <li>Network: (FIXME: radio buttons)</li>
</ol> </ol>
<h2>4.2 Form transaction (using parasite)</h2> <h2>4.2 Form transaction (using parasite)</h2>
<p>This uses a shim JavaScript library called parasite to form the transaction <p>This uses a shim JavaScript library called parasite to form the transaction
data for the wallet to sign. In a commercial application, this should be done data for the wallet to sign. In a commercial application, this should be done
by your backend</p> by your backend</p>
<button id='mk-spendtx'>Make SpendTx</button> <button id='mk-spendtx'>Make SpendTx</button>
<h5>SpendTx JS object</h5> <h5>SpendTx JS object</h5>
<pre id="spendtx-json"></pre> <pre id="spendtx-json"></pre>
<h5>SpendTx Base64</h5> <h5>SpendTx Base64</h5>
<pre class="pv-spendtx-base64"></pre> <pre class="pv-spendtx-base64"></pre>
<h2>4.3 Sign the transaction (sidekick)</h2> <h2>4.3 Sign the transaction (sidekick)</h2>
<ol> <ol>
<li><pre class="pv-spendtx-base64"></pre></li> <li><pre class="pv-spendtx-base64"></pre></li>
</ol> </ol>
<button id="sign-spendtx">Sign Transaction</button> <button id="sign-spendtx">Sign Transaction</button>
<h5>Result:</h5> <h5>Result:</h5>
<pre id="sign-spendtx-result"></pre> <pre id="sign-spendtx-result"></pre>
<h2>4.4 Propagate the transaction (parasite)</h2> <h2>4.4 Propagate the transaction (parasite)</h2>
<h2>4.5 Verify the transaction was propagated (parasite)</h2> <h2>4.5 Verify the transaction was propagated (parasite)</h2>
<h1>5. Sign a message</h1>
<button id="sign-message">Sign Message</button>
<!-- script --> <!-- script -->
<script type="module" src="dist/connection.js"></script> <script type="module" src="dist/connection.js"></script>
</body> </body>
+8
View File
@@ -197,6 +197,13 @@ sign_tx
document.getElementById("sign-spendtx-result")!.innerHTML = JSON.stringify(signedTx, undefined, 4); document.getElementById("sign-spendtx-result")!.innerHTML = JSON.stringify(signedTx, undefined, 4);
} }
async function sign_msg(logger: sk.Logger): Promise<void> {
console.log('poop');
let acc_pubkey : string = pv_address;
let signed_msg = await sk.msg_sign('sk-msg-sign-1', acc_pubkey, 'I make stinky poo poo', sk.TIMEOUT_DEF_TX_SIGN_NOPROP_MS, 'stinky poo poo too long', logger);
console.log('signed message:', signed_msg);
}
function function
main main
() ()
@@ -212,6 +219,7 @@ main
document.getElementById('address')!.onclick = function() { address(logger); }; document.getElementById('address')!.onclick = function() { address(logger); };
document.getElementById('mk-spendtx')!.onclick = function() { form_tx(logger); }; document.getElementById('mk-spendtx')!.onclick = function() { form_tx(logger); };
document.getElementById('sign-spendtx')!.onclick = function() { sign_tx(logger); }; document.getElementById('sign-spendtx')!.onclick = function() { sign_tx(logger); };
document.getElementById('sign-message')!.onclick = function() { sign_msg(logger); };
//set_pv_address("ak_2XhCkjzTwcq1coXSSzHJoMZkUzTwnjH88zmPGkkowUsFNTo9UE"); //set_pv_address("ak_2XhCkjzTwcq1coXSSzHJoMZkUzTwnjH88zmPGkkowUsFNTo9UE");
} }
+2 -1
View File
@@ -170,6 +170,7 @@ export {
connect, connect,
address, address,
tx_sign_noprop, tx_sign_noprop,
msg_sign,
// internals // internals
sleep, sleep,
@@ -777,7 +778,7 @@ msg_sign
logger : Logger) logger : Logger)
: Promise<Safe<any, awcp.RpcError | SkTimeoutError>> : Promise<Safe<any, awcp.RpcError | SkTimeoutError>>
{ {
logger.debug('address', {id:id, params:params, timeout_ms:timeout_ms, timeout_msg:timeout_msg}); logger.debug('address', {id:id, account_pubkey:account_pubkey, message:message, timeout_ms:timeout_ms, timeout_msg:timeout_msg});
let msgr = new MsgR(logger); let msgr = new MsgR(logger);
// FIXME: for type purposes, making the correct RPC message should be up here // FIXME: for type purposes, making the correct RPC message should be up here
// this way we can enforce that it's a correct RPC call with typescript // this way we can enforce that it's a correct RPC call with typescript