diff --git a/bindings/erlang/src/vanth.erl b/bindings/erlang/src/vanth.erl index 0d31bc3..6a639c9 100644 --- a/bindings/erlang/src/vanth.erl +++ b/bindings/erlang/src/vanth.erl @@ -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), diff --git a/sidekick/examples/connection.html b/sidekick/examples/connection.html index be48b7e..61a1f73 100644 --- a/sidekick/examples/connection.html +++ b/sidekick/examples/connection.html @@ -21,7 +21,7 @@
  1. Wallet Address:
  2. -
  3. SpendTx Base58:
  4. +
  5. SpendTx Base64:
@@ -64,13 +64,13 @@ by your backend

SpendTx JS object

 
-
SpendTx Base58
-

+
SpendTx Base64
+

 
 

4.3 Sign the transaction (sidekick)

    -
  1. +
diff --git a/sidekick/examples/src/connection.ts b/sidekick/examples/src/connection.ts index 145e339..7d6630d 100644 --- a/sidekick/examples/src/connection.ts +++ b/sidekick/examples/src/connection.ts @@ -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 { 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, diff --git a/sidekick/src/sidekick.ts b/sidekick/src/sidekick.ts index 5a3517a..06aff63 100644 --- a/sidekick/src/sidekick.ts +++ b/sidekick/src/sidekick.ts @@ -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 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> +{ + 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 + + (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, diff --git a/utils/vw/src/vd.erl b/utils/vw/src/vd.erl index e0b7ad1..1343f44 100644 --- a/utils/vw/src/vd.erl +++ b/utils/vw/src/vd.erl @@ -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).