From 50cac48f99344c7d256273ca11e50e5700caa597 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Wed, 19 Jul 2023 00:38:03 -0600 Subject: [PATCH 1/2] [wip] updating sidekick --- libs/awcp/jex.eterms | 2 +- libs/awcp/src/awcp.ts | 155 +++++++++++++++++++++++++++++++++++++-- sidekick/jex.eterms | 4 +- sidekick/src/sidekick.ts | 40 +++++++++- site/index.html | 43 ++++++++--- 5 files changed, 220 insertions(+), 24 deletions(-) diff --git a/libs/awcp/jex.eterms b/libs/awcp/jex.eterms index ef329f8..79587b0 100644 --- a/libs/awcp/jex.eterms +++ b/libs/awcp/jex.eterms @@ -1,5 +1,5 @@ {type, library}. {realm, local}. {name, awcp}. -{version, "0.2.1"}. +{version, "0.2.2"}. {deps, []}. diff --git a/libs/awcp/src/awcp.ts b/libs/awcp/src/awcp.ts index 6e3b9d1..75034f6 100644 --- a/libs/awcp/src/awcp.ts +++ b/libs/awcp/src/awcp.ts @@ -257,13 +257,13 @@ export { RpcResp_W2A_address_subscribe, EventData_A2W_address_subscribe, EventData_W2A_address_subscribe, - //// transaction.sign (propagate) - //Params_A2W_tx_sign_yesprop, - //Result_W2A_tx_sign_yesprop, - //RpcCall_A2W_tx_sign_yesprop, - //RpcResp_W2A_tx_sign_yesprop, - //EventData_A2W_tx_sign_yesprop, - //EventData_W2A_tx_sign_yesprop, + // transaction.sign (propagate) + Params_A2W_tx_sign_yesprop, + Result_W2A_tx_sign_yesprop, + RpcCall_A2W_tx_sign_yesprop, + RpcResp_W2A_tx_sign_yesprop, + EventData_A2W_tx_sign_yesprop, + EventData_W2A_tx_sign_yesprop, // transaction.sign (do not propagate) Params_A2W_tx_sign_noprop, Result_W2A_tx_sign_noprop, @@ -1110,6 +1110,147 @@ type EventData_W2A_address_subscribe +//---------------------------------------------------------------------------- +// transaction.sign (do propagate) +//---------------------------------------------------------------------------- + +/** + * Parameters for "transaction.sign" (do propagate) + * + * If `returnSigned` is `false`, then Superhero will propagate the transaction. + * + * (layer 4) + * + * @example + * ```json + * { + * "tx": "tx_+FgMAaEBuzbuuWjOzR7ecjOY8+u7HdNk0KoxTQcCDerZELEQ+UShAXtm5sMFBwg25Ol5IFI9w+pZy7/YbFi6BwPqi80KuKdsCoYPJvVhyAAAAYdoYWluYW5h9uAnNQ==", + * "returnSigned": false, + * "networkId": "ae_uat" + * } + * ``` + */ +type Params_A2W_tx_sign_yesprop + = {tx : string, + returnSigned : false, + networkId : string} + + + +/** + * Success result type for "transaction.sign" (do propagate) + * + * (layer 4) + * + * @example + * { + * "signedTransaction": "tx_+KILAfhCuEDxWnvffMvyrkFWnrImYej38rh99vM9f6pORl/yWTvU97nvUcY8/ck8lgtPA8w5odGSDb9LGY/JSZXsmsXhgKkHuFr4WAwBoQG7Nu65aM7NHt5yM5jz67sd02TQqjFNBwIN6tkQsRD5RKEBe2bmwwUHCDbk6XkgUj3D6lnLv9hsWLoHA+qLzQq4p2wKhg8m9WHIAAABh2hhaW5hbmF7X54G" + * } + */ +type Result_W2A_tx_sign_yesprop + = {signedTransaction : string}; + + +/** + * Request type for "transaction.sign" (do propagate) + * + * (layer 3) + * + * @example + * ```json + * { + * "jsonrpc": "2.0", + * "id": "sk-tx-sign-1", + * "method": "transaction.sign", + * "params": { + * "tx": "tx_+FgMAaEBuzbuuWjOzR7ecjOY8+u7HdNk0KoxTQcCDerZELEQ+UShAXtm5sMFBwg25Ol5IFI9w+pZy7/YbFi6BwPqi80KuKdsCoYPJvVhyAAAAYdoYWluYW5h9uAnNQ==", + * "returnSigned": true, + * "networkId": "ae_uat" + * } + * } + * ``` + */ +type RpcCall_A2W_tx_sign_yesprop + = RpcCall<"transaction.sign", + Params_A2W_tx_sign_yesprop>; + + + +/** + * Response type for "transaction.sign" (do propagate) + * + * (layer 3) + * + * @example + * ```json + * { + * "jsonrpc": "2.0", + * "id": "sk-tx-sign-1", + * "method": "transaction.sign", + * "result": { + * "signedTransaction": "tx_+KILAfhCuEDxWnvffMvyrkFWnrImYej38rh99vM9f6pORl/yWTvU97nvUcY8/ck8lgtPA8w5odGSDb9LGY/JSZXsmsXhgKkHuFr4WAwBoQG7Nu65aM7NHt5yM5jz67sd02TQqjFNBwIN6tkQsRD5RKEBe2bmwwUHCDbk6XkgUj3D6lnLv9hsWLoHA+qLzQq4p2wKhg8m9WHIAAABh2hhaW5hbmF7X54G" + * } + * } + * ``` + */ +type RpcResp_W2A_tx_sign_yesprop + = RpcResp<"transaction.sign", + Result_W2A_tx_sign_yesprop>; + + + +/** + * Event data for aepp-to-waellet "transaction.sign" (do propagate) message + * + * (layer 2) + * + * @example + * ```json + * { + * "type": "to_waellet", + * "data": { + * "jsonrpc": "2.0", + * "id": "sk-tx-sign-1", + * "method": "transaction.sign", + * "params": { + * "tx": "tx_+FgMAaEBuzbuuWjOzR7ecjOY8+u7HdNk0KoxTQcCDerZELEQ+UShAXtm5sMFBwg25Ol5IFI9w+pZy7/YbFi6BwPqi80KuKdsCoYPJvVhyAAAAYdoYWluYW5h9uAnNQ==", + * "returnSigned": false, + * "networkId": "ae_uat" + * } + * } + * } + * ``` + */ +type EventData_A2W_tx_sign_yesprop + = EventData_A2W; + + + +/** + * Event data for waellet-to-aepp "transaction.sign" (do propagate) response + * + * (layer 2) + * + * @example + * ```json + * { + * "type": "to_aepp", + * "data": { + * "jsonrpc": "2.0", + * "id": "sk-tx-sign-1", + * "method": "transaction.sign", + * "result": { + * "signedTransaction": "tx_+KILAfhCuEDxWnvffMvyrkFWnrImYej38rh99vM9f6pORl/yWTvU97nvUcY8/ck8lgtPA8w5odGSDb9LGY/JSZXsmsXhgKkHuFr4WAwBoQG7Nu65aM7NHt5yM5jz67sd02TQqjFNBwIN6tkQsRD5RKEBe2bmwwUHCDbk6XkgUj3D6lnLv9hsWLoHA+qLzQq4p2wKhg8m9WHIAAABh2hhaW5hbmF7X54G" + * } + * } + * } + * ``` + */ +type EventData_W2A_tx_sign_yesprop + = EventData_W2A; + + + //---------------------------------------------------------------------------- // transaction.sign (do not propagate) //---------------------------------------------------------------------------- diff --git a/sidekick/jex.eterms b/sidekick/jex.eterms index a0ca55f..5904558 100644 --- a/sidekick/jex.eterms +++ b/sidekick/jex.eterms @@ -1,5 +1,5 @@ {type, library}. {realm, local}. {name, sidekick}. -{version, "0.2.1"}. -{deps, ["local-awcp-0.2.1"]}. +{version, "0.2.2"}. +{deps, ["local-awcp-0.2.2"]}. diff --git a/sidekick/src/sidekick.ts b/sidekick/src/sidekick.ts index 4a0ab40..5837727 100644 --- a/sidekick/src/sidekick.ts +++ b/sidekick/src/sidekick.ts @@ -92,7 +92,7 @@ export { // IMPORTS //----------------------------------------------------------------------------- -import * as awcp from './jex_include/local-awcp-0.2.1/dist/awcp.js'; +import * as awcp from './jex_include/local-awcp-0.2.2/dist/awcp.js'; //----------------------------------------------------------------------------- @@ -1038,8 +1038,44 @@ msg_sign //----------------------------------------------------------------------------- -// API: tx sign (no prop) +// API: tx sign (do prop) //----------------------------------------------------------------------------- + +/** + * Ask the wallet to sign the transaction and propagate it into the network + */ +async function +tx_sign_yesprop + (id : number | string, + params : awcp.Params_A2W_tx_sign_yesprop, + 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 + <"transaction.sign", awcp.Params_A2W_tx_sign_yesprop, awcp.Result_W2A_tx_sign_yesprop> + (id, "transaction.sign", params, timeout_ms, timeout_msg); + return result; +} + + + +//----------------------------------------------------------------------------- +// API: tx sign (do not propagate transaction) +//----------------------------------------------------------------------------- + +/** + * Ask the wallet to sign the transaction but do not propagate the transaction, + * instead just return the signed data + */ async function tx_sign_noprop (id : number | string, diff --git a/site/index.html b/site/index.html index d52a879..50b5c98 100644 --- a/site/index.html +++ b/site/index.html @@ -95,12 +95,14 @@ TypeScript stuff (hurray).

Vanillae started as our own internal toolset that we developed in the - process of making Aegora.jp. In - particular, Craig developed Vanillae.erl because talking to the blockchain - was needlessly annoying, and Peter developed Sidekick because the Æternity - JavaScript SDK was (is) impossible to use. We then open-sourced our - tooling, and the Æternity Foundation decided to pay us to continue to - develop it and expand it.

+ process of making Aegora.jp. Aegora is a + normal, vanilla, e-commerce site. We just happen to use Æternity as the + payment backend. In particular, Craig developed Vanillae.erl because + talking to the blockchain from the server backend was needlessly annoying, + and Peter developed Sidekick because the Æternity JavaScript SDK was (is) + impossible to use. We then open-sourced our "talk to Æternity" tooling, + and the Æternity Foundation decided to pay us to continue to develop it and + expand it.

Aegora is the first normal e-commerce platform that utilizes any form of cryptocurrency. We would like if Aegora made us billionaires, but really @@ -120,17 +122,34 @@

Our hypothesis is that most cryptocurrencies (i.e. every coin except Æternity) are technically deficient to the point that they are totally - useless in the space of Things That Actually Have To Work (i.e. - business).

+ useless in The Space Of Things That Actually Have To Work (e.g. + non-scam commerce). To test this hypothesis, our goal is to make Æternity + easily usable and see if people start using it in The Space Of Things That + Actually Have To Work.

+ +

As of July 2023, Æternity is still in the same usability class as Arch + Linux. Our goal with this project to get to like Debian.

+ +

From our personal experience building Aegora, once you understand how + to use it, Æternity is by far the easiest electronic + payment system to use in a commercial application. It is the genuine + manifestation of Satoshi's dream.

4. Vanillae.erl

-

- This is an Erlang application that smooths over the rough edges - involved in talking to Æternity nodes. -

+

This is an Erlang application that smooths over the rough edges + involved in talking to Æternity nodes from an Erlang program.

+ +

Vanillae.erl is also a standard that is meant to be mimicked in other + languages. The idea is to have a "library" (Erlangers: it's an Erlang + application) of Erlang function calls that return natural Erlang data + structures. The API is designed in such a way that the API should + generalize to other languages. We would like there to be a Vanillae.py for + instance (Python 2 of course), which would maybe require startup or + something, maybe the natural idiom would be whatever you do to make `with` + syntax work, whatever. The point is, there should be a

From 6e1189a7891f8e23b2713b3f9aff9e2db9f2379a Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Thu, 20 Jul 2023 14:34:19 -0600 Subject: [PATCH 2/2] version bump sk/awcp/parasite to add tx_sign_yesprop There is now an explicit function to have superhero sign the transaction *and* propagate it into the network. JR will simply reject these requests. --- libs/awcp/src/awcp.ts | 38 ++++++++++++++++++++++++++--- libs/parasite/jex.eterms | 2 +- libs/parasite/src/ae_node.ts | 2 +- sidekick/src/sidekick.ts | 1 + sidekick_examples/connection.html | 12 ++++++--- sidekick_examples/jex.eterms | 8 +++--- sidekick_examples/src/connection.ts | 26 +++++++++++++++++--- sidekick_examples/src/hello.ts | 2 +- 8 files changed, 74 insertions(+), 17 deletions(-) diff --git a/libs/awcp/src/awcp.ts b/libs/awcp/src/awcp.ts index 75034f6..5c24b6f 100644 --- a/libs/awcp/src/awcp.ts +++ b/libs/awcp/src/awcp.ts @@ -1143,12 +1143,42 @@ type Params_A2W_tx_sign_yesprop * (layer 4) * * @example - * { - * "signedTransaction": "tx_+KILAfhCuEDxWnvffMvyrkFWnrImYej38rh99vM9f6pORl/yWTvU97nvUcY8/ck8lgtPA8w5odGSDb9LGY/JSZXsmsXhgKkHuFr4WAwBoQG7Nu65aM7NHt5yM5jz67sd02TQqjFNBwIN6tkQsRD5RKEBe2bmwwUHCDbk6XkgUj3D6lnLv9hsWLoHA+qLzQq4p2wKhg8m9WHIAAABh2hhaW5hbmF7X54G" - * } + * ```json + * "transactionHash": { + * "blockHash": "mh_uJZ65APpLtiagJKjTNPZL1g1LJ7oqc2uG44qVqp1gVWwWUgLb", + * "blockHeight": 806313, + * "hash": "th_o3cudpezVywd99a7VMef9Yg7XPixTFueaCqGjdsnqLM99a78t", + * "signatures": [ + * "sg_U36NDTFJFP4QEWCdjyhELDUDxsVGZNkq3DrcBCxby4NPUsPjQsFDG7VHN9s7TNUsEAd7qdC5aEjZKrqsKyfqA8apNrotz" + * ], + * "tx": { + * "amount": 10, + * "fee": 16800000000000, + * "nonce": 13, + * "payload": "ba_aGFpbmFuYWbkNu8=", + * "recipientId": "ak_wM8yFU8eSETXU7VSN48HMDmevGoCMiuveQZgkPuRn1nTiRqyv", + * "senderId": "ak_2XhCkjzTwcq1coXSSzHJoMZkUzTwnjH88zmPGkkowUsFNTo9UE", + * "type": "SpendTx", + * "version": 1 + * }, + * "rawTx": "tx_+KILAfhCuEDOpyHRaYj8MnRwqOzMyRJSh4qud6jRK01wiAWfRHBDo/4e9klk7MsvM0Cr0ENaNkqKfwCDcaga/iDnogN5cukNuFr4WAwBoQHJY35GAOerO8Lmf8ZA6CN2RET0MFXaXVV4pJo3WvoY3KEBe2bmwwUHCDbk6XkgUj3D6lnLv9hsWLoHA+qLzQq4p2wKhg9HjghAAAANh2hhaW5hbmHkTCSc" + * } + * ``` */ type Result_W2A_tx_sign_yesprop - = {signedTransaction : string}; + = {transactionHash : {blockHash : string, + blockHeight : number, + hash : string, + signatures : Array, + tx : {amount : number, + fee : number, + nonce : number, + payload : string, + recipientId : string, + senderId : string, + type : string, + version : number}, + rawTx : string}}; /** diff --git a/libs/parasite/jex.eterms b/libs/parasite/jex.eterms index 9d84a44..d763a25 100644 --- a/libs/parasite/jex.eterms +++ b/libs/parasite/jex.eterms @@ -1,5 +1,5 @@ {type, library}. {realm, local}. {name, parasite}. -{version, "0.2.0"}. +{version, "0.2.2"}. {deps, []}. diff --git a/libs/parasite/src/ae_node.ts b/libs/parasite/src/ae_node.ts index 5ecc783..6e62662 100644 --- a/libs/parasite/src/ae_node.ts +++ b/libs/parasite/src/ae_node.ts @@ -23,7 +23,7 @@ import * as ae_compiler from './ae_compiler.js' // CONSTANTS //------------------------------------------------------------------- -export const MIN_FEE = 16660000000000; +export const MIN_FEE = 16800000000000; export const MIN_CONTRACT_FEE = 79080000000000; export const MIN_GAS_PRICE = 1000000000; export const URL_MAINNET = "https://mainnet.aeternity.io/v3"; diff --git a/sidekick/src/sidekick.ts b/sidekick/src/sidekick.ts index 5837727..a306ced 100644 --- a/sidekick/src/sidekick.ts +++ b/sidekick/src/sidekick.ts @@ -79,6 +79,7 @@ export { // connect connect, address, + tx_sign_yesprop, tx_sign_noprop, msg_sign, diff --git a/sidekick_examples/connection.html b/sidekick_examples/connection.html index e48ad9e..798c3b1 100644 --- a/sidekick_examples/connection.html +++ b/sidekick_examples/connection.html @@ -62,11 +62,17 @@
- + +
Result:

-    

4.4 Propagate the transaction (parasite)

-

4.5 Verify the transaction was propagated (parasite)

+ +
+ +
Result:
+

+    

4.4 Propagate the transaction (parasite) FIXME

+

4.5 Verify the transaction was propagated (parasite) FIXME

5. Sign a message

diff --git a/sidekick_examples/jex.eterms b/sidekick_examples/jex.eterms index 48888e9..02cfab3 100644 --- a/sidekick_examples/jex.eterms +++ b/sidekick_examples/jex.eterms @@ -1,7 +1,7 @@ {type, library}. {realm, local}. {name, sidekick_examples}. -{version, "0.1.0"}. -{deps, ["local-awcp-0.2.1", - "local-parasite-0.2.0", - "local-sidekick-0.2.1"]}. +{version, "0.2.2"}. +{deps, ["local-awcp-0.2.2", + "local-parasite-0.2.2", + "local-sidekick-0.2.2"]}. diff --git a/sidekick_examples/src/connection.ts b/sidekick_examples/src/connection.ts index 0d6f5b4..3de5edc 100644 --- a/sidekick_examples/src/connection.ts +++ b/sidekick_examples/src/connection.ts @@ -1,6 +1,6 @@ -import * as ae_node from './jex_include/local-parasite-0.2.0/dist/ae_node.js'; -import * as awcp from './jex_include/local-awcp-0.2.1/dist/awcp.js'; -import * as sk from './jex_include/local-sidekick-0.2.1/dist/sidekick.js'; +import * as ae_node from './jex_include/local-parasite-0.2.2/dist/ae_node.js'; +import * as awcp from './jex_include/local-awcp-0.2.2/dist/awcp.js'; +import * as sk from './jex_include/local-sidekick-0.2.2/dist/sidekick.js'; var pv_address: string; var pv_spendtx_base64: string; @@ -181,6 +181,7 @@ form_tx // } + async function sign_tx (logger: sk.Logger) @@ -197,6 +198,24 @@ sign_tx document.getElementById("sign-spendtx-result")!.innerHTML = JSON.stringify(signedTx, undefined, 4); } + +async function +sign_tx_prop + (logger: sk.Logger) + : Promise +{ + let sign_params = { + tx: pv_spendtx_base64, + // returnsigned: false tells it to propagate the transaction + // returnsigned: true just signs it and returns the signed tx back + returnSigned: false as false, + networkId: "ae_uat" + }; + let signedTx = await sk.tx_sign_yesprop('sk-tx-sign-2', sign_params, sk.TIMEOUT_DEF_TX_SIGN_NOPROP_MS, 'sign transaction timed out', logger); + document.getElementById("sign-spendtx-prop-result")!.innerHTML = JSON.stringify(signedTx, undefined, 4); +} + + async function sign_msg (logger: sk.Logger) @@ -224,6 +243,7 @@ main document.getElementById('address')!.onclick = function() { address(logger); }; document.getElementById('mk-spendtx')!.onclick = function() { form_tx(logger); }; document.getElementById('sign-spendtx')!.onclick = function() { sign_tx(logger); }; + document.getElementById('sign-spendtx-prop')!.onclick = function() { sign_tx_prop(logger); }; document.getElementById('sign-message')!.onclick = function() { sign_msg(logger); }; //set_pv_address("ak_2XhCkjzTwcq1coXSSzHJoMZkUzTwnjH88zmPGkkowUsFNTo9UE"); diff --git a/sidekick_examples/src/hello.ts b/sidekick_examples/src/hello.ts index a0d980f..b78f53f 100644 --- a/sidekick_examples/src/hello.ts +++ b/sidekick_examples/src/hello.ts @@ -1,3 +1,3 @@ -import * as sk from './jex_include/local-sidekick-0.2.1/dist/sidekick.js'; +import * as sk from './jex_include/local-sidekick-0.2.2/dist/sidekick.js'; sk.hello();