Repository navigation
feat(signatures): sign P256 entries in signFrameTx - #6
ayushsingh82 wants to merge 1 commit into
Conversation
signFrameTx only signed SECP256K1 entries; a P256 entry had to be built and normalized by hand (README:70), even though DESIGN §3 already spells out the low-s rule scheme 2 needs. - add normalizeP256Signature(sig): rewrite r||s||qx||qy to low-s form, s -> n - s when s > n/2. ECDSA is malleable, so (r, n - s) is a valid signature against the same key; it is also the form consensus requires, and WebAuthn / passkey signers routinely emit high s. Exported for building the bytes by hand. Malformed input (wrong length, r or s outside (0, n)) throws rather than being repaired. - FrameAccount gains an optional signP256 returning r||s||qx||qy for a raw digest. signFrameTx signs empty-msg P256 entries with it, normalizing s, and refuses on a resolved-signer mismatch the same way it does for SECP256K1. A P256 entry with no signP256 available is left untouched, like an ARBITRARY entry. - signFrameTx no longer requires `sign` unconditionally: an account with only signP256 can now sign a P256 transaction, and a SECP256K1 entry without a `sign` method fails per-entry rather than up front. signFrameTx does not verify a P256 signature — scheme 2 has no address recovery — so the signer owns r, s and the embedded key; the library owns the wire form. Bounds in the tests are pinned to the published SECP256R1 group order.
f57375f to
ceec1dc
Compare
|
Rebased onto main (past #4 / #5 / v0.0.2). Conflicts were the DESIGN status line and the P256 test block that #5 also added — kept #5's |
|
Thanks for this, and sorry it sat for so long. P-256 signing landed in #50 (released in v0.5.0): |
signFrameTxonly ever signed SECP256K1 entries. A P256 entry had to be assembled and normalized by hand — the README said as much — even though DESIGN §3 already spells out the low-srule scheme 2 needs, and the reason it needs it:P256VERIFYaccepts highs, so WebAuthn and passkey signers (which routinely emit it) produce transactions the chain rejects unless someone foldssdown first.So this teaches
signFrameTxto do that fold, and to sign P256 entries.normalizeP256Signature(sig)— new, exported. Takesr || s || qx || qy(128 bytes, anys) and rewrites it to low-s:s → n - swhens > n/2. ECDSA is malleable, so(r, n - s)verifies against the same key — the embeddedqx || qyis untouched — and it's the form consensus wants. Structurally malformed input (wrong length,rorsoutside(0, n)) throws rather than being silently repaired. Also useful standalone for anyone building the bytes by hand.FrameAccount.signP256— a new optional field, a raw-digest signer returning the 128-byte tuple.signFrameTxsigns empty-msgP256 entries with it, normalizess, and refuses on a resolved-signer mismatch exactly as it does for SECP256K1. A P256 entry with nosignP256available is left untouched, same as an ARBITRARY entry.signFrameTxno longer requiressignunconditionally. An account with onlysignP256— a passkey wrapper — can now sign a P256 transaction. A SECP256K1 entry with nosignmethod fails per-entry with a specific message instead of up front. An account with neither is still refused. The existing/raw 32-byte digest/error path is unchanged.signFrameTxdoes not verify a P256 signature — scheme 2 has no address recovery — so the signer ownsr,sand the embedded key; the library owns the wire form only. That's the same line the rest of the P256 path already draws (assertCanonicalSignaturerange-checks scheme 2 but never touches the curve).Tests (
test/signatures.test.ts)normalizeP256Signature: low-suntouched byte for byte, high-sfolded ton - s, then/2boundary and then/2 + 1fold-back, the flipped result passes the canonical check, the public key survives, malformed input rejected. Bounds pinned toSECP256R1_N.signFrameTxwith asignP256: fills and normalizes a scheme-2 entry, a P256-only account works, resolved-signer mismatch refused, a P256-only account refuses a SECP256K1 entry, neither-signer refused, explicit-msgP256 left untouched, P256 left untouched when the account has nosignP256, and a SECP256K1 + P256 pair signed in one pass.bun run typecheck,bun run test(247 pass),bun run build,bunx @arethetypeswrong/cli --pack .all clean.