eos icon indicating copy to clipboard operation
eos copied to clipboard

How to convert public key string to eosio::public_key type in the system contract?

Open yhc166188 opened this issue 7 years ago • 3 comments

I have a public key string, but I don't know how to convert eosio::public_key type in the system contract

yhc166188 avatar Dec 06 '18 03:12 yhc166188

You can take a look at function DecodeBase58 in /eos/libraries/fc/src/crypto/base58.cpp to convert the public key string into binary format. However, porting the big math library into smart contract doesn't seem to be a good idea. I guess a better way is to convert the public key into binary format off-chain then push its hex format as data into smart contract, so that you only need a simple conversion from hex string to binary in your smart contract. So, public key string(base58) => binary => hex string(base 16) => push into smart contract => binary

taokayan avatar Dec 06 '18 09:12 taokayan

You can take a look at function DecodeBase58 in /eos/libraries/fc/src/crypto/base58.cpp to convert the public key string into binary format. However, porting the big math library into smart contract doesn't seem to be a good idea. I guess a better way is to convert the public key into binary format off-chain then push its hex format as data into smart contract, so that you only need a simple conversion from hex string to binary in your smart contract. So, public key string(base58) => binary => hex string(base 16) => push into smart contract => binary

Can be converted to eosio::public_key type?

yhc166188 avatar Dec 06 '18 11:12 yhc166188

Yes. eosio::public_key includes a constructor explicit public_key(const string& base58str); which invokes ``std::vector from_base58( const std::string& base58_str )which invokesinline bool DecodeBase58(const char* psz, std::vector& vchRet)` as suggested by taokayan.

Note that eosio::public_key is not provided by eosiolib, so you will need to copy it into your contract as well.

If you still need help and wish to discuss further, please post it in https://eosio.stackexchange.com. To keep things organized, Github issues are intended for bug reporting and feature tracking, and Stack Exchange is the right place for any technical support discussions. Thanks!

jgiszczak avatar Dec 06 '18 21:12 jgiszczak