[wip] various inconsequential changes

This commit is contained in:
2022-11-17 16:01:19 -07:00
parent ab2b816f88
commit 9589adaef8
5 changed files with 95 additions and 52 deletions
+1
View File
@@ -101,6 +101,7 @@ hum_spendtx_fields([SenderBytes,
TTLBytes,
NonceBytes,
Payload]) ->
% TODO: drop-through to make sure id humanization works
SenderStr = humanize_id(SenderBytes),
RecipStr = humanize_id(RecipBytes),
Amount = binary:decode_unsigned(AmountBytes),
+4 -4
View File
@@ -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>
+7 -7
View File
@@ -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,
+54 -12
View File
@@ -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
*/
@@ -344,12 +352,8 @@ class ConsoleLogger implements Logger
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); }
}
/**
@@ -374,12 +378,8 @@ class HttpLogger implements Logger
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,
+17 -17
View File
@@ -198,37 +198,36 @@ decompose_fields_contractcalltx(X) ->
%% general byte array
encode_ba(Bytes) -> "ba_" ++ sha64enc(Bytes).
encode_ba(Bytes) ->
"ba_" ++ sha64enc(Bytes).
%% contract byte array (see: https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md)
encode_cb(Bytes) -> "cb_" ++ sha64enc(Bytes).
encode_cb(Bytes) ->
"cb_" ++ sha64enc(Bytes).
%% See: https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
%% https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
%% ak_ account
encode_id(<<1, IdBytes:32/binary>>) -> "ak_" ++ sha58enc(IdBytes);
%% nm_ name
encode_id(<<2, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes);
%% cm_ commitment
encode_id(<<3, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes);
%% ok_ oracle
encode_id(<<4, IdBytes:32/binary>>) -> "ok_" ++ sha58enc(IdBytes);
%% ct_ contract
encode_id(<<5, IdBytes:32/binary>>) -> "ct_" ++ sha58enc(IdBytes);
%% ch_ channel
encode_id(<<6, IdBytes:32/binary>>) -> "ch_" ++ sha58enc(IdBytes).
encode_id(<<1, IdBytes:32/binary>>) -> "ak_" ++ sha58enc(IdBytes); %% ak_ account
encode_id(<<2, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); %% nm_ name
encode_id(<<3, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); %% cm_ commitment
encode_id(<<4, IdBytes:32/binary>>) -> "ok_" ++ sha58enc(IdBytes); %% ok_ oracle
encode_id(<<5, IdBytes:32/binary>>) -> "ct_" ++ sha58enc(IdBytes); %% ct_ contract
encode_id(<<6, IdBytes:32/binary>>) -> "ch_" ++ sha58enc(IdBytes). %% ch_ channel
encode_sg(Sig) -> "sg_" ++ sha58enc(Sig).
encode_sg(Sig) ->
"sg_" ++ sha58enc(Sig).
encode_tx(TxData) -> "tx_" ++ sha64enc(TxData).
encode_tx(TxData) ->
"tx_" ++ sha64enc(TxData).
@@ -245,4 +244,5 @@ sha64enc(Bytes) ->
%% tired of typing this
bdu(X) -> binary:decode_unsigned(X).
bdu(X) ->
binary:decode_unsigned(X).