Skip to content

Commit

Permalink
Update Signature Recovery Return Type (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored May 21, 2024
1 parent c388d76 commit c674abf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/utils/signature.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Hash } from "viem";
import { JSONRPCResponse } from "../types/rpc";
import { MPCSignature } from "../types/types";

export async function signatureFromTxHash(
nodeUrl: string,
txHash: string,
/// This field doesn't appear to be necessary although (possibly for efficiency),
/// the docs mention that it is "used to determine which shard to query for transaction".
accountId: string = "non-empty"
): Promise<[string, string]> {
): Promise<MPCSignature> {
const payload = {
jsonrpc: "2.0",
id: "dontcare",
Expand All @@ -31,7 +32,8 @@ export async function signatureFromTxHash(
if (base64Sig) {
// Decode from base64
const decodedValue = Buffer.from(base64Sig, "base64").toString("utf-8");
return JSON.parse(decodedValue);
const [big_r, big_s] = JSON.parse(decodedValue);
return { big_r, big_s };
} else {
throw new Error("No valid values found in the array.");
}
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/utils.signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ describe("utility: get Signature", () => {

it("successful: signatureFromTxHash", async () => {
const sig = await signatureFromTxHash(url, successHash);
expect(sig).toEqual([
"03EA06CECA2B7D71F6F4DA729A681B4DE44C6402F5F5BB9FC88C6706959D4FEDD4",
"67986E234DEC5D51CF6AED452FE1C4544924218AC20B009F81BAAE53C02AFE76",
]);
expect(sig).toEqual({
big_r:
"03EA06CECA2B7D71F6F4DA729A681B4DE44C6402F5F5BB9FC88C6706959D4FEDD4",
big_s: "67986E234DEC5D51CF6AED452FE1C4544924218AC20B009F81BAAE53C02AFE76",
});
});
it("failed: signatureFromTxHash", async () => {
await expect(signatureFromTxHash(url, failedHash)).rejects.toThrow(
Expand Down

0 comments on commit c674abf

Please sign in to comment.