[wip] add primitive message sign functionality
This commit is contained in:
@@ -27,60 +27,50 @@
|
|||||||
<!-- step 1 detect -->
|
<!-- step 1 detect -->
|
||||||
|
|
||||||
<h1>1. Detect wallet</h1>
|
<h1>1. Detect wallet</h1>
|
||||||
<button id="detect">Detect</button>
|
<button id="detect">Detect</button>
|
||||||
<h4 id="detected" style="color: red;">not detected</h4>
|
<h4 id="detected" style="color: red;">not detected</h4>
|
||||||
<pre id="detect-info"></pre>
|
<pre id="detect-info"></pre>
|
||||||
|
|
||||||
<h1>2. Connect to wallet</h1>
|
<h1>2. Connect to wallet</h1>
|
||||||
<button id="connect">Connect</button>
|
<button id="connect">Connect</button>
|
||||||
<h4 id="connected" style="color: red;">not connected</h4>
|
<h4 id="connected" style="color: red;">not connected</h4>
|
||||||
<pre id="connect-info"></pre>
|
<pre id="connect-info"></pre>
|
||||||
|
|
||||||
<h1>3. Get the wallet address</h1>
|
<h1>3. Get the wallet address</h1>
|
||||||
<button id="address">Address</button>
|
<button id="address">Address</button>
|
||||||
<h4 id="addressed" style="color: red;">not addressed</h4>
|
<h4 id="addressed" style="color: red;">not addressed</h4>
|
||||||
<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>
|
||||||
|
<li>Source address (step 3): <code class="pv-address"></code></li>
|
||||||
<ol>
|
<li>Target address: <input type="text" id="tx-info-target" value="ak_wM8yFU8eSETXU7VSN48HMDmevGoCMiuveQZgkPuRn1nTiRqyv"></input></li>
|
||||||
<li>Source address (step 3): <code class="pv-address"></code></li>
|
<li>Amount (aettos): <input type="text" id="tx-info-amount" value="10"></input></li>
|
||||||
<li>Target address: <input type="text" id="tx-info-target" value="ak_wM8yFU8eSETXU7VSN48HMDmevGoCMiuveQZgkPuRn1nTiRqyv"></input></li>
|
<li>Network: (FIXME: radio buttons)</li>
|
||||||
<li>Amount (aettos): <input type="text" id="tx-info-amount" value="10"></input></li>
|
</ol>
|
||||||
<li>Network: (FIXME: radio buttons)</li>
|
<h2>4.2 Form transaction (using parasite)</h2>
|
||||||
</ol>
|
<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
|
||||||
|
by your backend</p>
|
||||||
|
<button id='mk-spendtx'>Make SpendTx</button>
|
||||||
|
<h5>SpendTx JS object</h5>
|
||||||
|
<pre id="spendtx-json"></pre>
|
||||||
|
<h5>SpendTx Base64</h5>
|
||||||
|
<pre class="pv-spendtx-base64"></pre>
|
||||||
|
<h2>4.3 Sign the transaction (sidekick)</h2>
|
||||||
|
<ol>
|
||||||
|
<li><pre class="pv-spendtx-base64"></pre></li>
|
||||||
|
</ol>
|
||||||
|
<button id="sign-spendtx">Sign Transaction</button>
|
||||||
|
<h5>Result:</h5>
|
||||||
|
<pre id="sign-spendtx-result"></pre>
|
||||||
|
<h2>4.4 Propagate the transaction (parasite)</h2>
|
||||||
|
<h2>4.5 Verify the transaction was propagated (parasite)</h2>
|
||||||
|
|
||||||
|
|
||||||
<h2>4.2 Form transaction (using parasite)</h2>
|
<h1>5. Sign a message</h1>
|
||||||
|
<button id="sign-message">Sign Message</button>
|
||||||
<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
|
|
||||||
by your backend</p>
|
|
||||||
|
|
||||||
<button id='mk-spendtx'>Make SpendTx</button>
|
|
||||||
|
|
||||||
<h5>SpendTx JS object</h5>
|
|
||||||
<pre id="spendtx-json"></pre>
|
|
||||||
|
|
||||||
<h5>SpendTx Base64</h5>
|
|
||||||
<pre class="pv-spendtx-base64"></pre>
|
|
||||||
|
|
||||||
<h2>4.3 Sign the transaction (sidekick)</h2>
|
|
||||||
|
|
||||||
<ol>
|
|
||||||
<li><pre class="pv-spendtx-base64"></pre></li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<button id="sign-spendtx">Sign Transaction</button>
|
|
||||||
|
|
||||||
<h5>Result:</h5>
|
|
||||||
<pre id="sign-spendtx-result"></pre>
|
|
||||||
|
|
||||||
<h2>4.4 Propagate the transaction (parasite)</h2>
|
|
||||||
|
|
||||||
<h2>4.5 Verify the transaction was propagated (parasite)</h2>
|
|
||||||
|
|
||||||
<!-- script -->
|
<!-- script -->
|
||||||
<script type="module" src="dist/connection.js"></script>
|
<script type="module" src="dist/connection.js"></script>
|
||||||
|
|||||||
@@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user