diff --git a/src/utils/signature.ts b/src/utils/signature.ts index d3b40c8..7258a1f 100644 --- a/src/utils/signature.ts +++ b/src/utils/signature.ts @@ -1,5 +1,6 @@ import { Hash } from "viem"; import { JSONRPCResponse } from "../types/rpc"; +import { MPCSignature } from "../types/types"; export async function signatureFromTxHash( nodeUrl: string, @@ -7,7 +8,7 @@ export async function signatureFromTxHash( /// 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 { const payload = { jsonrpc: "2.0", id: "dontcare", @@ -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."); } diff --git a/tests/unit/utils.signature.test.ts b/tests/unit/utils.signature.test.ts index 525b36e..b78380b 100644 --- a/tests/unit/utils.signature.test.ts +++ b/tests/unit/utils.signature.test.ts @@ -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(