Skip to content

Commit

Permalink
hotfix short der signatures (#340)
Browse files Browse the repository at this point in the history
* add new test and new sig length for DER

* unused lines
  • Loading branch information
befitsandpiper authored Aug 20, 2024
1 parent ce19dd8 commit 864273f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions chain-api/src/utils/signatures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ describe("signatures", () => {
recoveryParam: undefined,
s: new BN("14d3aed3bf7e07cb3bf2ef2c06cfde6db461eea8f58827df5b0fa4185d6535", "hex")
});

// test 136 length der case:
const weirdDer = signatures.parseSecp256k1Signature(
"3042021e638cd4b430a0e3e343e30601284eaea6d929e9c660c8e11ad3fe68fe95b102207f4e7c048a36564e60e56f093e0f7353de9a6f902afa10870f77a2fb4ce0efab"
);

expect(weirdDer).toEqual({
r: new BN("638cd4b430a0e3e343e30601284eaea6d929e9c660c8e11ad3fe68fe95b1", "hex"),
recoveryParam: undefined,
s: new BN("7f4e7c048a36564e60e56f093e0f7353de9a6f902afa10870f77a2fb4ce0efab", "hex")
});
});

it("test metamask signatures vs galachain signatures", async () => {
Expand Down
4 changes: 2 additions & 2 deletions chain-api/src/utils/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export function normalizeSecp256k1Signature(s: string): Secp256k1Signature {
}

// DER format
if (s.length === 138 || s.length === 140 || s.length === 142 || s.length === 144) {
if (s.length === 136 || s.length === 138 || s.length === 140 || s.length === 142 || s.length === 144) {
return secp256k1signatureFromDERHexString(s);
}

Expand All @@ -307,7 +307,7 @@ export function normalizeSecp256k1Signature(s: string): Secp256k1Signature {
return secp256k1signatureFromDERHexString(hex);
}

const errorMessage = `Unknown signature format. Expected 88, 92, 96, 130, 132, 138, 140, 142, or 144 characters, but got ${s.length}`;
const errorMessage = `Unknown signature format. Expected 88, 92, 96, 130, 132, 136, 138, 140, 142, or 144 characters, but got ${s.length}`;
throw new InvalidSignatureFormatError(errorMessage, { signature: s });
}

Expand Down

0 comments on commit 864273f

Please sign in to comment.