Skip to content

Commit

Permalink
feat: Support AgentPubKey b64 string in signing offer (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
8e8b2c authored Aug 1, 2024
1 parent 42a67d9 commit a150d7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/holoom_types/src/evm_signing_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{EvmAddress, EvmSignature};
pub enum EvmU256Item {
Uint,
Hex,
HoloAgent,
}

#[hdk_entry_helper]
Expand Down
9 changes: 9 additions & 0 deletions crates/username_registry_coordinator/src/evm_signing_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ fn ingest_evm_signature_over_recipe_execution_request(
Ok(EvmU256::from(*value))
}
}
(Val::Str(b64_string), EvmU256Item::HoloAgent) => {
let hash = AgentPubKey::try_from(b64_string.as_str()).map_err(|_| {
wasm_error!(WasmErrorInner::Guest(
"Invalid AgentPubKey b64 string".into()
))
})?;
let value = EvmU256::from_be_slice(hash.get_raw_32());
Ok(value)
}
_ => Err(wasm_error!(WasmErrorInner::Guest(
"Invalid U256 array element".into()
))),
Expand Down
15 changes: 11 additions & 4 deletions packages/e2e/tests/signing-offer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("signing-offer", () => {
type: "Jq",
input_var_names: { type: "List", var_names: [] },
program:
'[1, "016345785d8a0000", "48509e384C66FDa5cFDF12A360B9eF2367158938"]',
'[1, "016345785d8a0000", "48509e384C66FDa5cFDF12A360B9eF2367158938", "uhCAknOsaM2At-JjiUzHGuk_YXuNwQDYcPK-Pyq_feS3n6oLc_C2N"]',
},
],
],
Expand All @@ -51,7 +51,12 @@ describe("signing-offer", () => {
identifier: "123",
evm_signing_offer: {
recipe_ah,
u256_items: [{ type: "Uint" }, { type: "Hex" }, { type: "Hex" }],
u256_items: [
{ type: "Uint" },
{ type: "Hex" },
{ type: "Hex" },
{ type: "HoloAgent" },
],
},
}),
});
Expand Down Expand Up @@ -115,14 +120,16 @@ describe("signing-offer", () => {
debug("Executed recipe and received signature for it");

const packed = encodePacked(
["uint256", "uint256", "uint256"],
["uint256", "uint256", "uint256", "uint256"],
[
1,
(10n * 10n ** 18n) / 100n,
"0x48509e384C66FDa5cFDF12A360B9eF2367158938",
// Big endian u256 read of raw 32 of uhCAknOsaM2At-JjiUzHGuk_YXuNwQDYcPK-Pyq_feS3n6oLc_C2N
70976194269703664889787012553258964581971848280304479022442879760825621932674n
]
);
const raw = keccak256(packed)
const raw = keccak256(packed);
const signatureHex = bytesToHex(new Uint8Array(signature));

const isValid = await verifyMessage({
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/EvmU256Item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type EvmU256Item = { type: "Uint" } | { type: "Hex" };
export type EvmU256Item =
| { type: "Uint" }
| { type: "Hex" }
| { type: "HoloAgent" };

0 comments on commit a150d7c

Please sign in to comment.