sarvalabs / js-moi-sdk

JavaScript library to interact with MOI Protocol via RPC API
https://js-moi-sdk.docs.moi.technology/
Apache License 2.0
24 stars 2 forks source link

Verification Failure with Wallet and ECDSA_SECP256K1 Signing Algorithm #82

Closed sarvalabs-harshrastogi closed 1 month ago

sarvalabs-harshrastogi commented 3 months ago

When signing a message using a randomly generated wallet with the ECDSA_SECP256K1 signing algorithm, verification fails. However, slicing the first two characters of the public key makes verification successful.

Below is the code how to reproduce it

import { Wallet } from 'js-moi-sdk';

const wallet = Wallet.createRandomSync();
const message = 'Hello World';
const buffmessage = Buffer.from(message, 'utf-8');

const signed = wallet.sign(buffmessage, wallet.signingAlgorithms.ecdsa_secp256k1);

But when i tried to verify the string it retuned be false

const isVerified = wallet.verify(buffmessage, signed, wallet.publicKey
console.log(isVerified); // >> false

But if the slice of starting two characters of public key it works

const isVerified = wallet.verify(buffmessage, signed, wallet.publicKey.slice(2)
console.log(isVerified); // >> true
sarvalabs-harshrastogi commented 1 month ago

closed in #83