Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Signature.sign() returns wrong signature #781

@fabian-emilius

Description

@fabian-emilius

Version of EOSJS
21.0.2

Describe the bug
sign() function in eosjs-ecc-migration returns wrong signature (basically Signature.sign()) in the browser. The signature can be verified by eosjs correctly but verification fails in the old eosjs-ecc module or in a smart contract, so it seems wrong.

To Reproduce
Steps to reproduce the behavior:
Private Key: PVT_K1_z6FmcRrEYH5MMK4Htfvo1y6cDf3MpnBkvTSmcBsr6KfaAoSXB
Signing value: pink
Expected and verifiable signature by eosjs-ecc: SIG_K1_KWejfkk6FefopiaSsfBJnjn2XK2L1zVBF5ZWaq3YkVpbmK2voCXDPcnKfm79RU12bepm7yDqit8xxZnFm3ydfTr5PReRsW
Actual signature: SIG_K1_KA1PzVjXmwaQApnrdaV7cZqoakGunT7jyNde3f9Fs759EtXCWGcWtLeSCmu5Dpzm4tTMy4gLZiavsY1DbbyGemx2M2k12u

  1. Create signature with eosjs 21 (actual signature)
  2. Verify / Recover signature in eosjs-ecc or a smart contract will fail
const {ecc} = require('eosjs/dist/eosjs-ecc-migration')
const eccLegacy = require('eosjs-ecc')
const {PrivateKey} = require('eosjs/dist/eosjs-jssig');

const privateKey = PrivateKey.fromString('PVT_K1_z6FmcRrEYH5MMK4Htfvo1y6cDf3MpnBkvTSmcBsr6KfaAoSXB');
const publicKey = privateKey.getPublicKey();

const signingValue = 'pink';

const actualSignature = ecc.sign(signingValue, privateKey, 'utf8');
const expectedSignature = eccLegacy.sign(signingValue, privateKey.toLegacyString(), 'utf8');

const actualRecoveredKey = eccLegacy.recover(actualSignature, signingValue, 'utf8');
const expectedRecoveredKey = eccLegacy.recover(expectedSignature, signingValue, 'utf8');

// different keys
console.log('Public Key', publicKey.toLegacyString());
console.log('')
console.log('Actual Recovered Key', actualRecoveredKey);
console.log('Expected Recovered Key', expectedRecoveredKey);
console.log('')
// different signatures (not a problem in general but actual signature cant be verified)
console.log('Actual Signature', actualSignature);
console.log('Expected Signature', expectedSignature);

Environment

  • Browser: Chrome 84
  • OS: OSX 10.15

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions