diff --git a/packages/authority/package.json b/packages/authority/package.json index b3c6a9c..a145b58 100644 --- a/packages/authority/package.json +++ b/packages/authority/package.json @@ -1,6 +1,6 @@ { "name": "@holoom/authority", - "version": "0.1.0-dev.6", + "version": "0.1.0-dev.7", "description": "Helpers for interacting with a holoom network authority agent", "type": "module", "license": "MIT", diff --git a/packages/authority/src/evm-bytes-signer/bytes-signer.ts b/packages/authority/src/evm-bytes-signer/bytes-signer.ts index daf7559..cb77c21 100644 --- a/packages/authority/src/evm-bytes-signer/bytes-signer.ts +++ b/packages/authority/src/evm-bytes-signer/bytes-signer.ts @@ -1,4 +1,4 @@ -import { Hex, hexToBytes } from "viem"; +import { bytesToBigInt, encodePacked, Hex, hexToBytes } from "viem"; import { privateKeyToAccount, PrivateKeyAccount } from "viem/accounts"; import { formatEvmSignature } from "./utils.js"; @@ -12,13 +12,11 @@ export class BytesSigner { async sign(u256_array: Uint8Array[]) { console.log("signing u256_array", u256_array); - const packed = new Uint8Array( - u256_array.flatMap((u256) => Array.from(u256)) + const message = encodePacked( + ["uint256[]"], + [u256_array.map((u256) => bytesToBigInt(u256))] ); - if (packed.length !== 32 * u256_array.length) { - throw Error("Bad packing of u256_array"); - } - const hex = await this.account.signMessage({ message: { raw: packed } }); + const hex = await this.account.signMessage({ message }); return formatEvmSignature(hex); } } diff --git a/packages/client/package.json b/packages/client/package.json index c213766..32a21d4 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@holoom/client", - "version": "0.1.0-dev.6", + "version": "0.1.0-dev.7", "description": "Helpers for interacting with a holoom network agent", "type": "module", "license": "MIT", diff --git a/packages/e2e/tests/signing-offer.test.js b/packages/e2e/tests/signing-offer.test.js index c32c6b4..ca6a578 100644 --- a/packages/e2e/tests/signing-offer.test.js +++ b/packages/e2e/tests/signing-offer.test.js @@ -1,6 +1,6 @@ const { startTestContainers } = require("./utils/testcontainers"); const { loadPageAndRegister } = require("./utils/holo"); -const { verifyMessage, bytesToHex } = require("viem"); +const { verifyMessage, bytesToHex, encodePacked } = require("viem"); describe("signing-offer", () => { let testContainers; @@ -30,7 +30,8 @@ describe("signing-offer", () => { { type: "Jq", input_var_names: { type: "List", var_names: [] }, - program: '["f39Fd6e51aad88F6F4ce6aB8827279cffFb92266", 123]', + program: + '[1, "06f05b59d3b20000", "1B5f0EaE225491eE0b629A2f70761E3288f18E08"]', }, ], ], @@ -50,7 +51,7 @@ describe("signing-offer", () => { identifier: "123", evm_signing_offer: { recipe_ah, - u256_items: [{ type: "Hex" }, { type: "Uint" }], + u256_items: [{ type: "Uint" }, { type: "Hex" }, { type: "Hex" }], }, }), }); @@ -113,15 +114,13 @@ describe("signing-offer", () => { ); debug("Executed recipe and received signature for it"); + const message = encodePacked( + ["uint256", "uint256", "uint256"], + [1, "0x06f05b59d3b20000", "0x1B5f0EaE225491eE0b629A2f70761E3288f18E08"] + ); + const isValid = await verifyMessage({ - message: { - raw: new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243, 159, 214, 229, 26, 173, 136, - 246, 244, 206, 106, 184, 130, 114, 121, 207, 255, 185, 34, 102, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 123, - ]), - }, + message, signature: bytesToHex(new Uint8Array(signature)), address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", });