[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, TTLBytes,
NonceBytes, NonceBytes,
Payload]) -> Payload]) ->
% TODO: drop-through to make sure id humanization works
SenderStr = humanize_id(SenderBytes), SenderStr = humanize_id(SenderBytes),
RecipStr = humanize_id(RecipBytes), RecipStr = humanize_id(RecipBytes),
Amount = binary:decode_unsigned(AmountBytes), Amount = binary:decode_unsigned(AmountBytes),
+4 -4
View File
@@ -21,7 +21,7 @@
<ol> <ol>
<li>Wallet Address: <code class="pv-address"></code></li> <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> </ol>
<!-- step 1 detect --> <!-- step 1 detect -->
@@ -64,13 +64,13 @@ by your backend</p>
<h5>SpendTx JS object</h5> <h5>SpendTx JS object</h5>
<pre id="spendtx-json"></pre> <pre id="spendtx-json"></pre>
<h5>SpendTx Base58</h5> <h5>SpendTx Base64</h5>
<pre class="pv-spendtx-base58"></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-base58"></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>
+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'; import * as sk from './jex_include/local-sidekick-0.1.0/dist/sidekick.js';
var pv_address: string; var pv_address: string;
var pv_spendtx_base58: string; var pv_spendtx_base64: string;
function function
set_pv_address set_pv_address
@@ -18,12 +18,12 @@ set_pv_address
} }
function function
set_pv_spendtx_base58 set_pv_spendtx_base64
(new_address: string) (new_address: string)
: void : void
{ {
pv_spendtx_base58 = new_address; pv_spendtx_base64 = new_address;
for (let elt of document.getElementsByClassName('pv-spendtx-base58')) for (let elt of document.getElementsByClassName('pv-spendtx-base64'))
{ {
elt.innerHTML = new_address; elt.innerHTML = new_address;
} }
@@ -175,8 +175,8 @@ form_tx
JSON.stringify(spendtx, undefined, 4); JSON.stringify(spendtx, undefined, 4);
let tx = await ae_node.PostSpend(ae_node.URL_TESTNET, spendtx); let tx = await ae_node.PostSpend(ae_node.URL_TESTNET, spendtx);
// @ts-ignore // @ts-ignore
set_pv_spendtx_base58(tx.tx); set_pv_spendtx_base64(tx.tx);
//document.getElementById('spendtx-base58')!.innerHTML = //document.getElementById('spendtx-base64')!.innerHTML =
// JSON.stringify(tx, undefined, 4); // JSON.stringify(tx, undefined, 4);
// //
} }
@@ -187,7 +187,7 @@ sign_tx
: Promise<void> : Promise<void>
{ {
let sign_params = { let sign_params = {
tx: pv_spendtx_base58, tx: pv_spendtx_base64,
// returnsigned: false tells it to propagate the transaction // returnsigned: false tells it to propagate the transaction
// returnsigned: true just signs it and returns the signed tx back // returnsigned: true just signs it and returns the signed tx back
returnSigned: true as true, returnSigned: true as true,
+66 -24
View File
@@ -1,3 +1,9 @@
// tomorrow:
// message signing
// examples
// documentation
// project organization
/** /**
* # How to use this library * # How to use this library
* *
@@ -44,6 +50,7 @@
* ## Step 2: Detect the wallet * ## Step 2: Detect the wallet
* *
* ``` * ```
* // timeout error message logger
* let maybe_detected = await sk.detect(sk.TIMEOUT_DEF_DETECT, 'detect: timeout', my_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}; error : err_t};
/** /**
* Constructs an `Ok` value from a pure value * Constructs an `Ok` value from a pure value
*/ */
@@ -333,23 +341,19 @@ class ConsoleLogger implements Logger
constructor() { constructor() {
let this_ptr = this; let this_ptr = this;
this.listener = this.listener =
function (e : Event) { function (e : Event) {
// for typescript // for typescript
if (e instanceof MessageEvent) { if (e instanceof MessageEvent) {
this_ptr.debug(`ConsoleLogger received MessageEvent`, e.data); this_ptr.debug(`ConsoleLogger received MessageEvent`, e.data);
} }
}; };
} }
async debug (_msg: string, _data: object) { console.debug (_msg, _data); } async debug (_msg: string, _data: object) { console.debug (_msg, _data); }
async info (_msg: string, _data: object) { console.log (_msg, _data); } async info (_msg: string, _data: object) { console.log (_msg, _data); }
async warning (_msg: string, _data: object) { console.warn (_msg, _data); } async warning (_msg: string, _data: object) { console.warn (_msg, _data); }
async error (_msg: string, _data: object) { console.error (_msg, _data); } async error (_msg: string, _data: object) { console.error (_msg, _data); }
listen() { listen() { window.addEventListener('message', this.listener); }
window.addEventListener('message', this.listener); ignore() { window.removeEventListener('message', this.listener); }
}
ignore () {
window.removeEventListener('message', this.listener);
}
} }
/** /**
@@ -363,23 +367,19 @@ class HttpLogger implements Logger
this.post_endpoint = post_endpoint; this.post_endpoint = post_endpoint;
let this_ptr = this; let this_ptr = this;
this.listener = this.listener =
function (e : Event) { function (e : Event) {
// for typescript // for typescript
if (e instanceof MessageEvent) { if (e instanceof MessageEvent) {
this_ptr.debug(`HttpLogger received MessageEvent`, e.data); this_ptr.debug(`HttpLogger received MessageEvent`, e.data);
} }
}; };
} }
async debug (_msg: string, _data: object) { http_log(this.post_endpoint, 'debug', _msg, _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 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 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); } async error (_msg: string, _data: object) { http_log(this.post_endpoint, 'error', _msg, _data); }
listen() { listen() { window.addEventListener('message', this.listener); }
window.addEventListener('message', this.listener); ignore() { window.removeEventListener('message', this.listener); }
}
ignore () {
window.removeEventListener('message', this.listener);
}
} }
async function 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. * Wait for wallet to announce itself, and then return.
* *
* Example message data: * Example message data:
@@ -702,6 +707,8 @@ class CAPListener
// API: connection // API: connection
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
async function async function
connect connect
(id : number | string, (id : number | string,
@@ -728,6 +735,9 @@ connect
// API: get address // API: get address
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
async function async function
address address
(id : number | string, (id : number | string,
@@ -750,10 +760,42 @@ address
return result; 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) // API: tx sign (no prop)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
async function async function
tx_sign_noprop tx_sign_noprop
(id : number | string, (id : number | string,
+17 -17
View File
@@ -198,37 +198,36 @@ decompose_fields_contractcalltx(X) ->
%% general byte array %% 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) %% 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 %% 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 %% https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
%% ak_ account
encode_id(<<1, IdBytes:32/binary>>) -> "ak_" ++ sha58enc(IdBytes); encode_id(<<1, IdBytes:32/binary>>) -> "ak_" ++ sha58enc(IdBytes); %% ak_ account
%% nm_ name encode_id(<<2, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); %% nm_ name
encode_id(<<2, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); encode_id(<<3, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); %% cm_ commitment
%% cm_ commitment encode_id(<<4, IdBytes:32/binary>>) -> "ok_" ++ sha58enc(IdBytes); %% ok_ oracle
encode_id(<<3, IdBytes:32/binary>>) -> "nm_" ++ sha58enc(IdBytes); encode_id(<<5, IdBytes:32/binary>>) -> "ct_" ++ sha58enc(IdBytes); %% ct_ contract
%% ok_ oracle encode_id(<<6, IdBytes:32/binary>>) -> "ch_" ++ sha58enc(IdBytes). %% ch_ channel
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_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 %% tired of typing this
bdu(X) -> binary:decode_unsigned(X). bdu(X) ->
binary:decode_unsigned(X).