EOSIO / eosjs-ecc

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption
288 stars 119 forks source link

When developing a web wallet, how do you combine eosjs-ecc with eosjs to complete the signature verification process of the transaction? #13

Closed songsongMr closed 6 years ago

jcalfee commented 6 years ago

eosjs-ecc is already included in eosjs .. You'll probaby see an example that does what you want in the README..

The only reason why you want eosjs-ecc alone is if you only want to work with private keys offline..

songsongMr commented 6 years ago

what the Application scenarios of the sign of eosjs-ecc .

songsongMr commented 6 years ago

Using an account to initiate a request to eos,, it seems that eos is just to check whether his private key is in keyProvider, if in the request is successful. What is the use of signatures in ecc?

jcalfee commented 6 years ago

Signatures are used anytime your writing data to the blockchain.. Reading data is public and does not need any private key or signature.

songsongMr commented 6 years ago

I'm not sure if my understanding of the signature is correct.I hope to get your advice. Could you show me an example . Thank you so much! eos.transaction({ actions: [ { account: 'tester', name: 'reguser', authorization: [{ actor: 'tester', permission: 'active' }], //Is this the signature? it will get the key from keyProvider. if the key is in keyProvider, the process of signature is complete.I'm not sure if my understanding of the signature is correct.I hope to get your advice. data: { name: "test", wname: "w123", password: "12345",
memo:"call reguser" } } ] })

jcalfee commented 6 years ago

Is there a reason your using eos.transaction? Can you instead pull the contract and call reguser directly?

Never put a password in a transaction like this.. It will be instantly seen by the entire network.. You'll probably need to change this to use public key private key security..

eos.contract('tester').then(tester => {
    tester.reguser({
        name: "test",
        wname: "w123",
        memo:"call reguser"
    })
}, {authorization: 'tester'})
goldenfiredo commented 6 years ago

would you please show how to work with private key offline with eosjs-ecc? Thanks.

jcalfee commented 6 years ago

Anywhere you see wif in the README that is working with a private key in the API .. Do you have a more specific question?

jcalfee commented 6 years ago

All method calls are "offline" .. there are no network API requests in this package.

sehgal12 commented 6 years ago

@jcalfee Hi, One of the action in my smart contract require multiple permission(from user and admin). Can you suggest me the way to get the transaction signed by the user, receive it and sign it by admin and finally push to the blockchain?

jcalfee commented 6 years ago

All offline? Create eosjs like this and tr will contain the signature. Do this in both environments. Make sure your transaction headers have extended the expiration time well beyond 1 minute.

let key
eos = Eos({httpEndpoint: null, keyProvider: () => key})
key = wif1
await tr = eos.transaction(transaction)

Or online:

let key
eos = Eos({broadcast: false, expireInSeconds: 60 * 1024, keyProvider: () => key})
key = wif2
await tr = eos.transaction(transaction)

Print out tr and make sure you collect and combine signatures.. Send the transaction to eos.pushTransaction when your done..

frankli1224 commented 6 years ago

@jcalfee ,Hi, jcalfee

I am writing a nodejs web page to send transaction to the blockchain. My keyprovider setting is shown below: my keyprovider looks like this: keyProvider:[[ "EOS5BtL6cQsVzMhuujppUTKmVWFY6EYLrDfdraaQnA2BBJYCrxCCb", "5KCk5d5pAuack1NiqSxTiJsrAiE6wgLxYHGo6JACpMuFJb39NeG" ],[ "EOS5GQ7PHBvEPCRWhiA3rNDVrrLYtvoxh7Vvnska9xa4RjkyZvUbH", "5J38vcyy1CVR9NeAArrZfeAUzjyGEAzJZmJ7paLHqJYKQo6hQC9" ],[ "EOS5cDrz8eHLHwW94QSpSwwLFphUCRKYiCyoZ8CoySm6EVMwHCDBE", "5Jjvnup2dqUGsQ7KhvJgYyohL8jUv9zcWcECHiWyZuALxXZWT5C" ],[ "EOS5sGH7Rdch9qHaXLA98NRg1qPrH7UobrZBsdS5Nt7Qd2uJVH8G3", "5HvCUxF4AVkePfAewWjXyqiApMQ3Yy6NzGKJE2w8WQvtEGvZLqa" ],[ "EOS6AT4kMkkiYhDgUeJ8YxupBRWHzu9pLPPicqLnpPN7qViT5TFiU", "5J5RHaY31VLcZoFUhjfSudyArKu6WWFbdmocaFYojsehENAFKRQ" ],[ "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" ],[ "EOS8MHfK4v7UGHrYKq1beFbrxv8LegKvgaXk4xEcK1ynBRGDqbAvU", "5KELKQohNbdoJ2MRmHPQh6ef7tFWSpBQ1gCpcjkNKER7hWczwCZ" ] ], // Your private ke

when i click the send transaction button I got this problem: apigen.js:115 AssertionError {name: "AssertionError", actual: false, expected: true, operator: "==", message: "expecting public or private keys from keyProvider", …}

Thank you for your help!

frankli1224 commented 6 years ago

any keyprovider sample is available?

jcalfee commented 6 years ago

The keyprovider is an array of private keys only .. See the README here: https://github.com/EOSIO/eosjs

frankli1224 commented 6 years ago

@jcalfee ,Thank you! I will read the readme file. Thank you!

frankli1224 commented 6 years ago

@jcalfee , Hello again! I found this in readme file

"keyProvider [array|string|function]"

I wonder how to write the "array" for private keys, because I have give two private keys in the key provider, one for active key one for owner key

jcalfee commented 6 years ago

keyProvider = ['5KELKQohNbdoJ2MRmHPQh6ef7tFWSpBQ1gCpcjkNKER7hWczwCZ', '5J38vcyy1CVR9NeAArrZfeAUzjyGEAzJZmJ7paLHqJYKQo6hQC9']