From a3cc4cdddc00fcbdf6356f803a538884582c6190 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Fri, 18 Nov 2022 18:23:02 -0700 Subject: [PATCH] [wip] add primitive message sign functionality --- sidekick/examples/connection.html | 82 +++++++++++++---------------- sidekick/examples/src/connection.ts | 8 +++ sidekick/src/sidekick.ts | 3 +- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/sidekick/examples/connection.html b/sidekick/examples/connection.html index 61a1f73..6b2dfd4 100644 --- a/sidekick/examples/connection.html +++ b/sidekick/examples/connection.html @@ -27,60 +27,50 @@

1. Detect wallet

- -

not detected

-

+    
+    

not detected

+

 
 

2. Connect to wallet

- -

not connected

-

+    
+    

not connected

+

 
 

3. Get the wallet address

- -

not addressed

-

+    
+    

not addressed

+

 
 

4. Sign a transaction

- -

4.1 Transaction info (information needed from you)

- -
    -
  1. Source address (step 3):
  2. -
  3. Target address:
  4. -
  5. Amount (aettos):
  6. -
  7. Network: (FIXME: radio buttons)
  8. -
+

4.1 Transaction info (information needed from you)

+
    +
  1. Source address (step 3):
  2. +
  3. Target address:
  4. +
  5. Amount (aettos):
  6. +
  7. Network: (FIXME: radio buttons)
  8. +
+

4.2 Form transaction (using parasite)

+

This uses a shim JavaScript library called parasite to form the transaction + data for the wallet to sign. In a commercial application, this should be done + by your backend

+ +
SpendTx JS object
+

+        
SpendTx Base64
+

+    

4.3 Sign the transaction (sidekick)

+
    +
  1. +
+ +
Result:
+

+    

4.4 Propagate the transaction (parasite)

+

4.5 Verify the transaction was propagated (parasite)

-

4.2 Form transaction (using parasite)

- -

This uses a shim JavaScript library called parasite to form the transaction -data for the wallet to sign. In a commercial application, this should be done -by your backend

- - - -
SpendTx JS object
-

-
-
SpendTx Base64
-

-
-

4.3 Sign the transaction (sidekick)

- -
    -
  1. -
- - - -
Result:
-

-
-

4.4 Propagate the transaction (parasite)

- -

4.5 Verify the transaction was propagated (parasite)

+

5. Sign a message

+ diff --git a/sidekick/examples/src/connection.ts b/sidekick/examples/src/connection.ts index 7d6630d..189c882 100644 --- a/sidekick/examples/src/connection.ts +++ b/sidekick/examples/src/connection.ts @@ -197,6 +197,13 @@ sign_tx document.getElementById("sign-spendtx-result")!.innerHTML = JSON.stringify(signedTx, undefined, 4); } +async function sign_msg(logger: sk.Logger): Promise { + console.log('poop'); + let acc_pubkey : string = pv_address; + let signed_msg = await sk.msg_sign('sk-msg-sign-1', acc_pubkey, 'I make stinky poo poo', sk.TIMEOUT_DEF_TX_SIGN_NOPROP_MS, 'stinky poo poo too long', logger); + console.log('signed message:', signed_msg); +} + function main () @@ -212,6 +219,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-message')!.onclick = function() { sign_msg(logger); }; //set_pv_address("ak_2XhCkjzTwcq1coXSSzHJoMZkUzTwnjH88zmPGkkowUsFNTo9UE"); } diff --git a/sidekick/src/sidekick.ts b/sidekick/src/sidekick.ts index 06aff63..31f2c06 100644 --- a/sidekick/src/sidekick.ts +++ b/sidekick/src/sidekick.ts @@ -170,6 +170,7 @@ export { connect, address, tx_sign_noprop, + msg_sign, // internals sleep, @@ -777,7 +778,7 @@ msg_sign logger : Logger) : Promise> { - logger.debug('address', {id:id, params:params, timeout_ms:timeout_ms, timeout_msg:timeout_msg}); + logger.debug('address', {id:id, account_pubkey:account_pubkey, message:message, 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