mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-11-24 06:39:58 +00:00
Claims: recover the signer with @pezkuwi/util-crypto, not elliptic
recoverAddress used secp256k1/elliptic.js, which put elliptic (open advisories, no fixed version) into the shipped bundle. secp256k1Recover from @pezkuwi/util-crypto (@noble/curves, or wasm) with the 'keccak' hash type returns the same expanded key without its 0x04 prefix. The spec's signature vector had been broken by the rebrand: the signed message was rewritten from "Kusama" to "Dicle", so recovery gave another address and the test failed on the old code too (it only runs in test:all). Restored; old and new code pass it, and changing one word of the message makes it fail.
This commit is contained in:
1 parent
a5a5a6f9e0
commit
09f16d3549
4 files changed
+5
-17
No files matched your search
@@ -3,11 +3,9 @@
|
||||
|
||||
import type { EcdsaSignature, EthereumAddress, StatementKind } from '@pezkuwi/types/interfaces';
|
||||
|
||||
import secp256k1 from 'secp256k1/elliptic.js';
|
||||
|
||||
import { statics } from '@pezkuwi/react-api/statics';
|
||||
import { assert, hexToU8a, stringToU8a, u8aConcat, u8aToBuffer } from '@pezkuwi/util';
|
||||
import { keccakAsHex, keccakAsU8a } from '@pezkuwi/util-crypto';
|
||||
import { keccakAsHex, keccakAsU8a, secp256k1Recover } from '@pezkuwi/util-crypto';
|
||||
|
||||
interface RecoveredSignature {
|
||||
error: Error | null;
|
||||
@@ -74,11 +72,9 @@ export function sigToParts (_signature: string): SignatureParts {
|
||||
|
||||
// recover an address from a given message and a recover/signature combination
|
||||
export function recoverAddress (message: string, { recovery, signature }: SignatureParts): string {
|
||||
const msgHash = hashMessage(message);
|
||||
const senderPubKey = secp256k1.recover(msgHash, signature, recovery);
|
||||
|
||||
// 'keccak' returns the expanded key without its 0x04 prefix
|
||||
return publicToAddr(
|
||||
secp256k1.publicKeyConvert(senderPubKey, false).subarray(1)
|
||||
secp256k1Recover(hashMessage(message), signature, recovery, 'keccak')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user