EOSIO / eosjs-ecc

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

ecc.isValidPublic() return false on some valid public keys #48

Open UMU618 opened 5 years ago

UMU618 commented 5 years ago

ecc.isValidPublic('EOS5K6ag7t87u3F4jdkmt73wQtd9oprQFyJsp6vskrrwoQoPqcPdE7') return false #489

Version eosjs 20.0.0-beta3 eosjs-ecc 4.0.4

Describe the bug

  1. ecc.isValidPublic() return false on 2 public keys of account 1255gdpaftgs
  2. Point.decodeFrom() report 'Invalid sequence tag'

To Reproduce

  1. get the public keys of 1255gdpaftgs

  2. validate these keys using ecc.isValidPublic()

# umu @ UMU-MBP in ~/github/meet-one/mainnet-snapshot on git:master x [21:45:27]
$ cleos -u https://mainnet.meet.one get account 1255gdpaftgs
created: 2018-11-08T01:25:13.500
permissions:
     owner     1:    1 EOS5K6ag7t87u3F4jdkmt73wQtd9oprQFyJsp6vskrrwoQoPqcPdE7
        active     1:    1 EOS5Kkxpsx71txnR8niEmZmcG6d6AeSQqYw1qfXYQBDkgh5v4tbGxH
memory:
     quota:     5.345 KiB    used:     3.365 KiB

net bandwidth:
     staked:          0.1000 EOS           (total stake delegated from account to self)
     delegated:       0.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        79.93 KiB
     limit:            79.93 KiB

cpu bandwidth:
     staked:          0.1000 EOS           (total stake delegated from account to self)
     delegated:       0.0000 EOS           (total staked delegated to account from others)
     used:                 0 us
     available:        12.63 ms
     limit:            12.63 ms

producers:     <not voted>

# umu @ UMU-MBP in ~/github/meet-one/mainnet-snapshot on git:master x [21:45:33]
$ node
> const ecc = require('eosjs-ecc')
undefined
> ecc.isValidPublic('EOS5K6ag7t87u3F4jdkmt73wQtd9oprQFyJsp6vskrrwoQoPqcPdE7')
false
> ecc.isValidPublic('EOS5Kkxpsx71txnR8niEmZmcG6d6AeSQqYw1qfXYQBDkgh5v4tbGxH')
false

Expected behavior true, but return false.

More It seems like a bug of ecurve 1.0.5

ecc.PublicKey('EOS5Kkxpsx71txnR8niEmZmcG6d6AeSQqYw1qfXYQBDkgh5v4tbGxH')

type is 128, isValidPublic() = false

ecc.PublicKey('EOS7enq7SL9AUhBYgkYMksj34LPKtAr7iu56KKrNTcUPTRqTp5VaN')

type is 3, isValidPublic() = true

I use C++ code to validate these keys, and the test passes.

BOOST_AUTO_TEST_CASE(test_by_UMU) try {
   auto pub_str = std::string("EOS5Kkxpsx71txnR8niEmZmcG6d6AeSQqYw1qfXYQBDkgh5v4tbGxH");
   auto pub = public_key(pub_str);

   std::cout << pub_str << " => " << pub << std::endl;

   BOOST_CHECK(pub.valid());
   BOOST_CHECK_EQUAL(pub_str, std::string(pub));
} FC_LOG_AND_RETHROW();
antonio-fr commented 5 years ago

Maybe related to this ? https://github.com/EOSIO/eosjs-ecc/pull/38/files

UMU618 commented 5 years ago

Maybe related to this ? https://github.com/EOSIO/eosjs-ecc/pull/38/files

No.

The checksum of EOS8ddPoePGrH4x1mha1RHcbjU1cAWWFLWqBQF6Q35RrTsZdLouC1 is wrong, should be EOS8ddPoePGrH4x1mha1RHcbjU1cAWWFLWqBQF6Q35RrTsZdLouCm.

my issue is about unexcepted type, not checksum.