Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in documentation & how to use the client with the rust server #59

Closed
et4te opened this issue Sep 6, 2017 · 3 comments
Closed

Bugs in documentation & how to use the client with the rust server #59

et4te opened this issue Sep 6, 2017 · 3 comments

Comments

@et4te
Copy link

et4te commented Sep 6, 2017

Hey peeps,

Thanks for providing such great open source libraries. Found some issues.

Documentation has bugs e.g:

var SendFunds = Exonum.newMessage({
    size: 24,
    network_id: 0,
    protocol_version: 0,
    service_id: 0,
    message_id: 0,
    signature: '07038584a4a77510ea5eced45f54dc030f5864ab6a5a2190666b47c676bcf15a' +
     '1f2f07703c5bcafb5749aa735ce8b7c366752be882314f5bbbc9a6af2ae634fc',
    fields: {
        from: {type: Exonum.Hash, size: 8, from: 0, to: 8},
        to: {type: Exonum.Hash, size: 8, from: 8, to: 16},
        amount: {type: Exonum.Uint64, size: 8, from: 16, to: 24}
    }
});

Where Exonum.Hash seems to actually be 32-bytes rather than 8 and thus the actual size is wrong and causes a runtime error.

There is no mention of where the above signature actually comes from nor any mention of the primitives required to form a keyPair (even though it is mandatory to know that tweetnacl is the underlying cryptographic library being used). If you use Exonums default way of signing the body and follow the docs the result doesn't work:

         var keyA = Exonum.keyPair();

         var walletType = Exonum.newType({
             size: 40,
             fields: {
                 pub_key: {type: Exonum.PublicKey, size: 32, from: 0, to: 32},
                 name: {type: Exonum.String, size: 8, from: 32, to: 40}
             }
         });

         var walletData = {
             pub_key: keyA.publicKey,
             name: "Someone"
         };

         var walletSignature = Exonum.sign(keyA.secretKey, walletData, walletType);

         var walletJson = {
             body: walletData,
             network_id: 0,
             protocol_version: 0,
             service_id: 1,
             message_id: 1,
             signature: walletSignature
         };

         fetch('http://127.0.0.1:8000/api/services/some_chain/v1/wallets/transaction', {method: 'POST', body: JSON.stringify(walletJson)})
             .then(result => {
                 console.log(result);
             })
             .catch(error => {
                 console.log(error);
             });

Which begs the question how do you form the signature as per the curl requests in the documentation in order to match what is expected?

@boguslavsky
Copy link
Contributor

Hi @et4te.
Thanks for pointing out wrong length of from and to fields. Of course both of them should be 32-bytes length long. Readme will be fixed soon.

As for your question about signature. If you declare and sign transaction there is no need to declare walletType of newType. Here is what i mean:

         var keyA = Exonum.keyPair();

         var CreateWalletTransaction = Exonum.newMessage({
             network_id: 0,
             protocol_version: 0,
             service_id: 1,
             message_id: 1,
             size: 40,
             fields: {
                 pub_key: {type: Exonum.PublicKey, size: 32, from: 0, to: 32},
                 name: {type: Exonum.String, size: 8, from: 32, to: 40}
             }
         });

         var walletData = {
             pub_key: keyA.publicKey,
             name: "Someone"
         };

         var transactionSignature = Exonum.sign(keyA.secretKey, walletData, CreateWalletTransaction);

         var walletJson = {
             network_id: 0,
             protocol_version: 0,
             service_id: 1,
             message_id: 1,
             body: walletData,
             signature: transactionSignature
         };

         fetch('http://127.0.0.1:8000/api/services/some_chain/v1/wallets/transaction', {method: 'POST', body: JSON.stringify(walletJson)})
             .then(result => {
                 console.log(result);
             })
             .catch(error => {
                 console.log(error);
             });

Let us know whether this helped you.

@et4te
Copy link
Author

et4te commented Sep 7, 2017

Thanks for the quick reply. This solves all the problems and the code works when changed to use newMessage instead of newType.

@boguslavsky
Copy link
Contributor

fixed in #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants