Skip to content

@lelantos-org/sdk / keys / reduceSignatureToScalar

Function: reduceSignatureToScalar() โ€‹

ts
function reduceSignatureToScalar(sigHex): bigint;

Defined in: @lelantos-org/sdk/dist/keys/metamask.d.ts:27

nsk from an EIP-712 signature, over a canonical form of that signature.

Canonicalisation matters because a wallet's whole identity hangs off this. ECDSA admits more than one valid encoding of the same signature over the same digest:

  • v is written as 27/28 by some wallets and 0/1 by others;
  • (r, s) and (r, n - s) are both valid, and only some signers normalise to the low half.

Hashing the raw 65 bytes therefore derived a different nsk โ€” a different address, and no access to the funds at the old one โ€” from wallet software that merely encoded the same signature differently. So v is dropped and s is folded into its low form before hashing.

This changes derived keys. Any address derived by an earlier version from a signature will not be reproduced here. That is the point โ€” the old derivation was not stable โ€” and it is why this belongs before a deployment rather than after one. The mnemonic and private-key sources are unaffected.

Parameters โ€‹

ParameterType
sigHexstring

Returns โ€‹

bigint

Lelantosno cookies ๐Ÿช ยท no tracking ๐Ÿ‘๏ธ ยท no accounts ๐Ÿ‘คwalletexplorer4536080GitHub