From a150d7ccf4a980d4d587187c9b9d08a185d27067 Mon Sep 17 00:00:00 2001 From: 8e8b2c <138928994+8e8b2c@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:56:25 +0100 Subject: [PATCH] feat: Support AgentPubKey b64 string in signing offer (#60) --- crates/holoom_types/src/evm_signing_offer.rs | 1 + .../src/evm_signing_offer.rs | 9 +++++++++ packages/e2e/tests/signing-offer.test.js | 15 +++++++++++---- packages/types/src/EvmU256Item.ts | 5 ++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/holoom_types/src/evm_signing_offer.rs b/crates/holoom_types/src/evm_signing_offer.rs index d54ffcf..277e2b6 100644 --- a/crates/holoom_types/src/evm_signing_offer.rs +++ b/crates/holoom_types/src/evm_signing_offer.rs @@ -10,6 +10,7 @@ use crate::{EvmAddress, EvmSignature}; pub enum EvmU256Item { Uint, Hex, + HoloAgent, } #[hdk_entry_helper] diff --git a/crates/username_registry_coordinator/src/evm_signing_offer.rs b/crates/username_registry_coordinator/src/evm_signing_offer.rs index f8120ab..fc8b42f 100644 --- a/crates/username_registry_coordinator/src/evm_signing_offer.rs +++ b/crates/username_registry_coordinator/src/evm_signing_offer.rs @@ -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() ))), diff --git a/packages/e2e/tests/signing-offer.test.js b/packages/e2e/tests/signing-offer.test.js index 0c181b6..f461fd2 100644 --- a/packages/e2e/tests/signing-offer.test.js +++ b/packages/e2e/tests/signing-offer.test.js @@ -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"]', }, ], ], @@ -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" }, + ], }, }), }); @@ -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({ diff --git a/packages/types/src/EvmU256Item.ts b/packages/types/src/EvmU256Item.ts index 5685173..c4bcae6 100644 --- a/packages/types/src/EvmU256Item.ts +++ b/packages/types/src/EvmU256Item.ts @@ -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" };