forge-js icon indicating copy to clipboard operation
forge-js copied to clipboard

mcrypto.secp256k1 may generate keypair that produce different signature than elixir

Open wangshijun opened this issue 7 years ago • 2 comments

Since this is not a stable/critical issue, create a backlog here:

/* eslint no-console:"off" */
const { fromRandom, WalletType } = require('@arcblock/forge-wallet');
const Mcrypto = require('@arcblock/mcrypto');
const { hexToBytes } = require('@arcblock/forge-util');
const GraphqlClient = require('@arcblock/forge-graphql-client');

const client = new GraphqlClient('http://localhost:8210/api'); // local

const type = WalletType({
  role: Mcrypto.types.RoleType.ROLE_ACCOUNT,
  // pk: Mcrypto.types.KeyType.ED25519,
  pk: Mcrypto.types.KeyType.SECP256K1,
  hash: Mcrypto.types.HashType.SHA3,
});

(async () => {
  try {
    const wallet = fromRandom(type);
    console.log(wallet.toJSON().type);
    const res = await client.sendDeclareTx({
      data: {
        moniker: `wangshijun_${Math.round(Math.random() * 1000)}`,
        pk: Buffer.from(hexToBytes(wallet.publicKey)),
        type,
        issuer: '',
        data: null,
      },
      wallet,
    });

    console.log(res);
  } catch (err) {
    console.error(err);
  }
})();

wangshijun avatar Mar 13 '19 08:03 wangshijun

I tested with fromSecretKey and fromRandom to generate wallet, they all behave the same, some random keys cannot produce elixir verifiable signatures.

wangshijun avatar Mar 13 '19 08:03 wangshijun

https://github.com/ArcBlock/arc-wallet-android/issues/843

NateRobinson avatar Mar 05 '21 10:03 NateRobinson