brix / crypto-js

JavaScript library of crypto standards.
Other
15.88k stars 2.39k forks source link

Question regarding the verify method after upgrade to 4.1.1 #461

Closed advapiIT closed 1 year ago

advapiIT commented 1 year ago

Hello, I'm in the middle of an Angular update version from 9 to 16 and I'm getting this error when I updated crypto-js from 4.0.0 to 4.1.1

The original code was

  verifySignature(payload: string, signature: string, key: string): boolean {
    this.crypto.setPublicKey(key);
    const result = this.crypto.verify(payload, signature,CryptoJS.SHA256);

    return result;
  }

but It was giving this error

Error: src/app/shared/services/crypto.service.ts:47:59 - error TS2345: Argument of type 'HasherHelper' is not assignable to parameter of type '(str: string) => string'. Type 'WordArray' is not assignable to type 'string'.

47 const result = this.crypto.verify(payload, signature, CryptoJS.SHA256);

Is this enough to replace the code with

  verifySignature(payload: string, signature: string, key: string): boolean {
    this.crypto.setPublicKey(key);
    const result = this.crypto.verify(payload, signature,(_)=> CryptoJS.SHA256.name);

    return result;
  }

or is there a correct and better way? At the moment I cannot create a unit test for this since the solution is not compiling

Any help appreciated, Thanks