static verify (signedMessage: unknown, signature: unknown, publicKey: unknown): boolean {\r
try {\r
if (!(signedMessage instanceof Uint8Array)) {\r
- throw new TypeError('Message must be Uint8Array')\r
+ throw new TypeError('Signed message must be Uint8Array')\r
}\r
if (!(signature instanceof Uint8Array)) {\r
throw new TypeError('Signature must be Uint8Array')\r
}\r
- if (!(publicKey instanceof Uint8Array)) {\r
- throw new TypeError('Public key must be Uint8Array')\r
- }\r
if (signature.byteLength !== this.crypto_sign_BYTES) {\r
throw new Error(`Signature must be ${this.crypto_sign_BYTES} bytes`)\r
}\r
- if (publicKey.byteLength !== this.crypto_sign_PUBLICKEYBYTES) {\r
- throw new Error(`Public key must be ${this.crypto_sign_PUBLICKEYBYTES} bytes`)\r
- }\r
- const msg = new Uint8Array(signedMessage)\r
- const sig = new Uint8Array(signature)\r
- const pub = new Uint8Array(publicKey)\r
- signedMessage = undefined\r
- signature = undefined\r
- publicKey = undefined\r
- const sm = new Uint8Array(this.crypto_sign_BYTES + msg.length)\r
- const m = new Uint8Array(this.crypto_sign_BYTES + msg.length)\r
- sm.set(sig, 0)\r
- sm.set(msg, this.crypto_sign_BYTES)\r
- return (this.crypto_sign_open(m, sm, sm.length, pub) >= 0)\r
+ const sm = new Uint8Array(this.crypto_sign_BYTES + signedMessage.length)\r
+ sm.set(signature, 0)\r
+ sm.set(signedMessage, this.crypto_sign_BYTES)\r
+ return (this.open(sm, publicKey as Uint8Array<ArrayBuffer>).byteLength >= 0)\r
} catch (err) {\r
throw new Error('Failed to verify signature on message with the given public key', { cause: err })\r
}\r