[wip] various inconsequential changes
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
<ol>
|
||||
<li>Wallet Address: <code class="pv-address"></code></li>
|
||||
<li>SpendTx Base58: <code class="pv-spendtx-base58"></code></li>
|
||||
<li>SpendTx Base64: <code class="pv-spendtx-base64"></code></li>
|
||||
</ol>
|
||||
|
||||
<!-- step 1 detect -->
|
||||
@@ -64,13 +64,13 @@ by your backend</p>
|
||||
<h5>SpendTx JS object</h5>
|
||||
<pre id="spendtx-json"></pre>
|
||||
|
||||
<h5>SpendTx Base58</h5>
|
||||
<pre class="pv-spendtx-base58"></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-base58"></pre></li>
|
||||
<li><pre class="pv-spendtx-base64"></pre></li>
|
||||
</ol>
|
||||
|
||||
<button id="sign-spendtx">Sign Transaction</button>
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as awcp from './jex_include/local-awcp-0.1.0/dist/awcp.js';
|
||||
import * as sk from './jex_include/local-sidekick-0.1.0/dist/sidekick.js';
|
||||
|
||||
var pv_address: string;
|
||||
var pv_spendtx_base58: string;
|
||||
var pv_spendtx_base64: string;
|
||||
|
||||
function
|
||||
set_pv_address
|
||||
@@ -18,12 +18,12 @@ set_pv_address
|
||||
}
|
||||
|
||||
function
|
||||
set_pv_spendtx_base58
|
||||
set_pv_spendtx_base64
|
||||
(new_address: string)
|
||||
: void
|
||||
{
|
||||
pv_spendtx_base58 = new_address;
|
||||
for (let elt of document.getElementsByClassName('pv-spendtx-base58'))
|
||||
pv_spendtx_base64 = new_address;
|
||||
for (let elt of document.getElementsByClassName('pv-spendtx-base64'))
|
||||
{
|
||||
elt.innerHTML = new_address;
|
||||
}
|
||||
@@ -175,8 +175,8 @@ form_tx
|
||||
JSON.stringify(spendtx, undefined, 4);
|
||||
let tx = await ae_node.PostSpend(ae_node.URL_TESTNET, spendtx);
|
||||
// @ts-ignore
|
||||
set_pv_spendtx_base58(tx.tx);
|
||||
//document.getElementById('spendtx-base58')!.innerHTML =
|
||||
set_pv_spendtx_base64(tx.tx);
|
||||
//document.getElementById('spendtx-base64')!.innerHTML =
|
||||
// JSON.stringify(tx, undefined, 4);
|
||||
//
|
||||
}
|
||||
@@ -187,7 +187,7 @@ sign_tx
|
||||
: Promise<void>
|
||||
{
|
||||
let sign_params = {
|
||||
tx: pv_spendtx_base58,
|
||||
tx: pv_spendtx_base64,
|
||||
// returnsigned: false tells it to propagate the transaction
|
||||
// returnsigned: true just signs it and returns the signed tx back
|
||||
returnSigned: true as true,
|
||||
|
||||
+66
-24
@@ -1,3 +1,9 @@
|
||||
// tomorrow:
|
||||
// message signing
|
||||
// examples
|
||||
// documentation
|
||||
// project organization
|
||||
|
||||
/**
|
||||
* # How to use this library
|
||||
*
|
||||
@@ -44,6 +50,7 @@
|
||||
* ## Step 2: Detect the wallet
|
||||
*
|
||||
* ```
|
||||
* // timeout error message logger
|
||||
* let maybe_detected = await sk.detect(sk.TIMEOUT_DEF_DETECT, 'detect: timeout', my_logger);
|
||||
* ```
|
||||
*
|
||||
@@ -220,6 +227,7 @@ type Error<err_t>
|
||||
error : err_t};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an `Ok` value from a pure value
|
||||
*/
|
||||
@@ -333,23 +341,19 @@ class ConsoleLogger implements Logger
|
||||
constructor() {
|
||||
let this_ptr = this;
|
||||
this.listener =
|
||||
function (e : Event) {
|
||||
// for typescript
|
||||
if (e instanceof MessageEvent) {
|
||||
this_ptr.debug(`ConsoleLogger received MessageEvent`, e.data);
|
||||
}
|
||||
};
|
||||
function (e : Event) {
|
||||
// for typescript
|
||||
if (e instanceof MessageEvent) {
|
||||
this_ptr.debug(`ConsoleLogger received MessageEvent`, e.data);
|
||||
}
|
||||
};
|
||||
}
|
||||
async debug (_msg: string, _data: object) { console.debug (_msg, _data); }
|
||||
async info (_msg: string, _data: object) { console.log (_msg, _data); }
|
||||
async warning (_msg: string, _data: object) { console.warn (_msg, _data); }
|
||||
async error (_msg: string, _data: object) { console.error (_msg, _data); }
|
||||
listen() {
|
||||
window.addEventListener('message', this.listener);
|
||||
}
|
||||
ignore () {
|
||||
window.removeEventListener('message', this.listener);
|
||||
}
|
||||
listen() { window.addEventListener('message', this.listener); }
|
||||
ignore() { window.removeEventListener('message', this.listener); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,23 +367,19 @@ class HttpLogger implements Logger
|
||||
this.post_endpoint = post_endpoint;
|
||||
let this_ptr = this;
|
||||
this.listener =
|
||||
function (e : Event) {
|
||||
// for typescript
|
||||
if (e instanceof MessageEvent) {
|
||||
this_ptr.debug(`HttpLogger received MessageEvent`, e.data);
|
||||
}
|
||||
};
|
||||
function (e : Event) {
|
||||
// for typescript
|
||||
if (e instanceof MessageEvent) {
|
||||
this_ptr.debug(`HttpLogger received MessageEvent`, e.data);
|
||||
}
|
||||
};
|
||||
}
|
||||
async debug (_msg: string, _data: object) { http_log(this.post_endpoint, 'debug', _msg, _data); }
|
||||
async info (_msg: string, _data: object) { http_log(this.post_endpoint, 'info', _msg, _data); }
|
||||
async warning (_msg: string, _data: object) { http_log(this.post_endpoint, 'warning', _msg, _data); }
|
||||
async error (_msg: string, _data: object) { http_log(this.post_endpoint, 'error', _msg, _data); }
|
||||
listen() {
|
||||
window.addEventListener('message', this.listener);
|
||||
}
|
||||
ignore () {
|
||||
window.removeEventListener('message', this.listener);
|
||||
}
|
||||
listen() { window.addEventListener('message', this.listener); }
|
||||
ignore() { window.removeEventListener('message', this.listener); }
|
||||
}
|
||||
|
||||
async function
|
||||
@@ -506,6 +506,11 @@ const TIMEOUT_DEF_TX_SIGN_NOPROP_MS = 5*MIN;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This is the first step in connecting to the wallet. Before doing anything
|
||||
* else, you have to wait for the wallet to announce itself.
|
||||
*
|
||||
* This function waits for the wallet to announce itself
|
||||
*
|
||||
* Wait for wallet to announce itself, and then return.
|
||||
*
|
||||
* Example message data:
|
||||
@@ -702,6 +707,8 @@ class CAPListener
|
||||
// API: connection
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
async function
|
||||
connect
|
||||
(id : number | string,
|
||||
@@ -728,6 +735,9 @@ connect
|
||||
// API: get address
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
async function
|
||||
address
|
||||
(id : number | string,
|
||||
@@ -750,10 +760,42 @@ address
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// API: message sign
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
async function
|
||||
msg_sign
|
||||
(id : number | string,
|
||||
account_pubkey : string,
|
||||
message : string,
|
||||
timeout_ms : number,
|
||||
timeout_msg : string,
|
||||
logger : Logger)
|
||||
: Promise<Safe<any, awcp.RpcError | SkTimeoutError>>
|
||||
{
|
||||
logger.debug('address', {id:id, params:params, timeout_ms:timeout_ms, timeout_msg:timeout_msg});
|
||||
let msgr = new MsgR(logger);
|
||||
// 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
|
||||
// Ideal:
|
||||
// let result = await msgr.send_raseev(id, awcp.METHOD_CONNECTION_OPEN, params, target, timeout_ms, timeout_msg);
|
||||
let result =
|
||||
await msgr.send_raseev
|
||||
<any, any, any>
|
||||
(id, "message.sign", {onAccount: account_pubkey, message: message}, timeout_ms, timeout_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// API: tx sign (no prop)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
async function
|
||||
tx_sign_noprop
|
||||
(id : number | string,
|
||||
|
||||
Reference in New Issue
Block a user