Skip to content

Commit

Permalink
fix: correct u256 packing
Browse files Browse the repository at this point in the history
  • Loading branch information
8e8b2c committed Jul 17, 2024
1 parent 4489226 commit 7c1eea8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/authority/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 5 additions & 7 deletions packages/authority/src/evm-bytes-signer/bytes-signer.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 10 additions & 11 deletions packages/e2e/tests/signing-offer.test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,7 +30,8 @@ describe("signing-offer", () => {
{
type: "Jq",
input_var_names: { type: "List", var_names: [] },
program: '["f39Fd6e51aad88F6F4ce6aB8827279cffFb92266", 123]',
program:
'[1, "06f05b59d3b20000", "1B5f0EaE225491eE0b629A2f70761E3288f18E08"]',
},
],
],
Expand All @@ -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" }],
},
}),
});
Expand Down Expand Up @@ -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",
});
Expand Down

0 comments on commit 7c1eea8

Please sign in to comment.