From 3cbf0b8797164aaae7b72b5414efa0f37d15b89b Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:19:36 -0600 Subject: [PATCH 1/8] Update WASM bindings --- bindings_wasm/src/inbox_state.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bindings_wasm/src/inbox_state.rs b/bindings_wasm/src/inbox_state.rs index d8cc3b0de..5b8bcb720 100644 --- a/bindings_wasm/src/inbox_state.rs +++ b/bindings_wasm/src/inbox_state.rs @@ -1,3 +1,4 @@ +use js_sys::Uint8Array; use wasm_bindgen::{prelude::wasm_bindgen, JsError}; use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::{AssociationState, MemberIdentifier}; @@ -7,6 +8,7 @@ use crate::client::Client; #[wasm_bindgen(getter_with_clone)] #[derive(Clone)] pub struct Installation { + pub bytes: Uint8Array, pub id: String, #[wasm_bindgen(js_name = clientTimestampNs)] pub client_timestamp_ns: Option, @@ -15,10 +17,11 @@ pub struct Installation { #[wasm_bindgen] impl Installation { #[wasm_bindgen(constructor)] - pub fn new(id: String, client_timestamp_ns: Option) -> Self { + pub fn new(bytes: Uint8Array, id: String, client_timestamp_ns: Option) -> Self { Self { - id, + bytes, client_timestamp_ns, + id, } } } @@ -63,8 +66,9 @@ impl From for InboxState { .filter_map(|m| match m.identifier { MemberIdentifier::Address(_) => None, MemberIdentifier::Installation(inst) => Some(Installation { - id: ed25519_public_key_to_address(inst.as_slice()), + bytes: Uint8Array::from(inst.as_slice()), client_timestamp_ns: m.client_timestamp_ns, + id: ed25519_public_key_to_address(inst.as_slice()), }), }) .collect(), From 2bf1c5bf116503847c426fb963b38018cbfcfc9c Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:25:37 -0600 Subject: [PATCH 2/8] Update node bindings --- bindings_node/src/inbox_state.rs | 8 +++++--- bindings_node/test/Client.test.ts | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings_node/src/inbox_state.rs b/bindings_node/src/inbox_state.rs index 2cf73a928..45575fe4c 100644 --- a/bindings_node/src/inbox_state.rs +++ b/bindings_node/src/inbox_state.rs @@ -1,4 +1,4 @@ -use napi::bindgen_prelude::{BigInt, Result}; +use napi::bindgen_prelude::{BigInt, Result, Uint8Array}; use napi_derive::napi; use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::{AssociationState, MemberIdentifier}; @@ -7,8 +7,9 @@ use crate::{client::Client, ErrorWrapper}; #[napi(object)] pub struct Installation { - pub id: String, + pub bytes: Uint8Array, pub client_timestamp_ns: Option, + pub id: String, } #[napi(object)] @@ -30,8 +31,9 @@ impl From for InboxState { .filter_map(|m| match m.identifier { MemberIdentifier::Address(_) => None, MemberIdentifier::Installation(inst) => Some(Installation { - id: ed25519_public_key_to_address(inst.as_slice()), + bytes: Uint8Array::from(inst.as_slice()), client_timestamp_ns: m.client_timestamp_ns.map(BigInt::from), + id: ed25519_public_key_to_address(inst.as_slice()), }), }) .collect(), diff --git a/bindings_node/test/Client.test.ts b/bindings_node/test/Client.test.ts index bd84e24c4..60e6ac69a 100644 --- a/bindings_node/test/Client.test.ts +++ b/bindings_node/test/Client.test.ts @@ -53,6 +53,9 @@ describe('Client', () => { expect(inboxState.inboxId).toBe(client.inboxId()) expect(inboxState.installations.length).toBe(1) expect(inboxState.installations[0].id).toBe(client.installationId()) + expect(inboxState.installations[0].bytes).toEqual( + client.installationIdBytes() + ) expect(inboxState.accountAddresses).toEqual([ user.account.address.toLowerCase(), ]) @@ -64,6 +67,9 @@ describe('Client', () => { expect(inboxState2.inboxId).toBe(client.inboxId()) expect(inboxState.installations.length).toBe(1) expect(inboxState.installations[0].id).toBe(client.installationId()) + expect(inboxState.installations[0].bytes).toEqual( + client.installationIdBytes() + ) expect(inboxState2.accountAddresses).toEqual([ user.account.address.toLowerCase(), ]) From 5d3f26791163786f9052337f818be4a911948781 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:31:16 -0600 Subject: [PATCH 3/8] Prepare node bindings release --- bindings_node/CHANGELOG.md | 4 ++++ bindings_node/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bindings_node/CHANGELOG.md b/bindings_node/CHANGELOG.md index 1c9bfbaa7..360b9cd61 100644 --- a/bindings_node/CHANGELOG.md +++ b/bindings_node/CHANGELOG.md @@ -1,5 +1,9 @@ # @xmtp/node-bindings +## 0.0.33 + +- Added installation ID `bytes` to return value of `inboxState` + ## 0.0.32 - Add ability to revoke installations from a list of installations diff --git a/bindings_node/package.json b/bindings_node/package.json index 025418985..168c5e336 100644 --- a/bindings_node/package.json +++ b/bindings_node/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/node-bindings", - "version": "0.0.32", + "version": "0.0.33", "repository": { "type": "git", "url": "git+https://git@github.com/xmtp/libxmtp.git", From 116770e733254629088fcf5a7b1df60c988eae2c Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:31:41 -0600 Subject: [PATCH 4/8] Prepare WASM bindings release --- bindings_wasm/CHANGELOG.md | 4 ++++ bindings_wasm/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bindings_wasm/CHANGELOG.md b/bindings_wasm/CHANGELOG.md index e271e80a0..89606ba3c 100644 --- a/bindings_wasm/CHANGELOG.md +++ b/bindings_wasm/CHANGELOG.md @@ -1,5 +1,9 @@ # @xmtp/wasm-bindings +## 0.0.11 + +- Added installation ID `bytes` to return value of `inboxState` + ## 0.0.10 - Add ability to revoke installations from a list of installations diff --git a/bindings_wasm/package.json b/bindings_wasm/package.json index c9e0b1467..bf7cadb4e 100644 --- a/bindings_wasm/package.json +++ b/bindings_wasm/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/wasm-bindings", - "version": "0.0.10", + "version": "0.0.11", "type": "module", "license": "MIT", "description": "WASM bindings for the libXMTP rust library", From 5a0e0f3a9605009bf404c626cbbf4cb6e864bd26 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:39:39 -0600 Subject: [PATCH 5/8] Refactor installation ID encoding (node) --- bindings_node/src/client.rs | 3 +-- bindings_node/src/conversation.rs | 3 +-- bindings_node/src/inbox_state.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bindings_node/src/client.rs b/bindings_node/src/client.rs index cbe595bd9..e66554939 100644 --- a/bindings_node/src/client.rs +++ b/bindings_node/src/client.rs @@ -11,7 +11,6 @@ use std::sync::Arc; use tokio::sync::Mutex; use tracing_subscriber::{fmt, prelude::*}; pub use xmtp_api_grpc::grpc_api_helper::Client as TonicApiClient; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::builder::SignatureRequest; use xmtp_mls::builder::ClientBuilder; use xmtp_mls::groups::scoped_client::LocalScopedGroupClient; @@ -200,7 +199,7 @@ impl Client { #[napi] pub fn installation_id(&self) -> String { - ed25519_public_key_to_address(self.inner_client.installation_public_key().as_slice()) + hex::encode(self.inner_client.installation_public_key()) } #[napi] diff --git a/bindings_node/src/conversation.rs b/bindings_node/src/conversation.rs index de1be2ee9..3c201646c 100644 --- a/bindings_node/src/conversation.rs +++ b/bindings_node/src/conversation.rs @@ -5,7 +5,6 @@ use napi::{ threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode}, JsFunction, }; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_mls::{ groups::{ group_metadata::GroupMetadata as XmtpGroupMetadata, @@ -231,7 +230,7 @@ impl Conversation { installation_ids: member .installation_ids .into_iter() - .map(|id| ed25519_public_key_to_address(id.as_slice())) + .map(|id| hex::encode(id)) .collect(), permission_level: match member.permission_level { XmtpPermissionLevel::Member => PermissionLevel::Member, diff --git a/bindings_node/src/inbox_state.rs b/bindings_node/src/inbox_state.rs index 45575fe4c..97bea8a19 100644 --- a/bindings_node/src/inbox_state.rs +++ b/bindings_node/src/inbox_state.rs @@ -1,6 +1,5 @@ use napi::bindgen_prelude::{BigInt, Result, Uint8Array}; use napi_derive::napi; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::{AssociationState, MemberIdentifier}; use crate::{client::Client, ErrorWrapper}; @@ -33,7 +32,7 @@ impl From for InboxState { MemberIdentifier::Installation(inst) => Some(Installation { bytes: Uint8Array::from(inst.as_slice()), client_timestamp_ns: m.client_timestamp_ns.map(BigInt::from), - id: ed25519_public_key_to_address(inst.as_slice()), + id: hex::encode(inst), }), }) .collect(), From 7d8297d154a645aa6253fe9825d332223de976c6 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:40:54 -0600 Subject: [PATCH 6/8] Refactor installation ID encoding (WASM) --- bindings_wasm/src/client.rs | 3 +-- bindings_wasm/src/conversation.rs | 3 +-- bindings_wasm/src/inbox_state.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bindings_wasm/src/client.rs b/bindings_wasm/src/client.rs index f00088619..8d21277d6 100644 --- a/bindings_wasm/src/client.rs +++ b/bindings_wasm/src/client.rs @@ -9,7 +9,6 @@ use tracing_subscriber::{filter, fmt::format::Pretty}; use wasm_bindgen::prelude::{wasm_bindgen, JsError}; use wasm_bindgen::JsValue; use xmtp_api_http::XmtpHttpApiClient; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::builder::SignatureRequest; use xmtp_mls::builder::ClientBuilder; use xmtp_mls::identity::IdentityStrategy; @@ -202,7 +201,7 @@ impl Client { #[wasm_bindgen(getter, js_name = installationId)] pub fn installation_id(&self) -> String { - ed25519_public_key_to_address(self.inner_client.installation_public_key().as_slice()) + hex::encode(self.inner_client.installation_public_key()) } #[wasm_bindgen(getter, js_name = installationIdBytes)] diff --git a/bindings_wasm/src/conversation.rs b/bindings_wasm/src/conversation.rs index 667fa0832..228837d4e 100644 --- a/bindings_wasm/src/conversation.rs +++ b/bindings_wasm/src/conversation.rs @@ -8,7 +8,6 @@ use crate::encoded_content::EncodedContent; use crate::messages::{ListMessagesOptions, Message}; use crate::permissions::{MetadataField, PermissionPolicy, PermissionUpdateType}; use crate::{consent_state::ConsentState, permissions::GroupPermissions}; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_mls::groups::{ group_metadata::GroupMetadata as XmtpGroupMetadata, group_mutable_metadata::MetadataField as XmtpMetadataField, @@ -230,7 +229,7 @@ impl Conversation { installation_ids: member .installation_ids .into_iter() - .map(|id| ed25519_public_key_to_address(id.as_slice())) + .map(|id| hex::encode(id)) .collect(), permission_level: match member.permission_level { XmtpPermissionLevel::Member => PermissionLevel::Member, diff --git a/bindings_wasm/src/inbox_state.rs b/bindings_wasm/src/inbox_state.rs index 5b8bcb720..82f20c001 100644 --- a/bindings_wasm/src/inbox_state.rs +++ b/bindings_wasm/src/inbox_state.rs @@ -1,6 +1,5 @@ use js_sys::Uint8Array; use wasm_bindgen::{prelude::wasm_bindgen, JsError}; -use xmtp_cryptography::signature::ed25519_public_key_to_address; use xmtp_id::associations::{AssociationState, MemberIdentifier}; use crate::client::Client; @@ -68,7 +67,7 @@ impl From for InboxState { MemberIdentifier::Installation(inst) => Some(Installation { bytes: Uint8Array::from(inst.as_slice()), client_timestamp_ns: m.client_timestamp_ns, - id: ed25519_public_key_to_address(inst.as_slice()), + id: hex::encode(inst), }), }) .collect(), From e58005ed3a7e21134b98a99e32463e8285449c56 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 14:41:16 -0600 Subject: [PATCH 7/8] Remove ed25519_public_key_to_address --- xmtp_cryptography/src/signature.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/xmtp_cryptography/src/signature.rs b/xmtp_cryptography/src/signature.rs index 0c4a454d7..ed7c3abbb 100644 --- a/xmtp_cryptography/src/signature.rs +++ b/xmtp_cryptography/src/signature.rs @@ -114,15 +114,6 @@ pub fn h160addr_to_string(bytes: H160) -> String { s.to_lowercase() } -// This should ONLY be used for ed25519 keys, not ethereum/secp256k1 keys. -// See: https://sourcegraph.com/github.com/gakonst/ethers-rs@40cc8cc54f7d36aa24147c937772600e5b119399/-/blob/ethers-core/src/types/signature.rs?L110-111 -pub fn ed25519_public_key_to_address(bytes: &[u8]) -> String { - let hash = ethers::utils::keccak256(bytes); - let mut s = String::from("x:"); // TODO verify XMTP installation addressing scheme - s.push_str(&hex::encode(&hash[12..])); - s -} - /// Check if an string is a valid ethereum address (valid hex and length 20). pub fn is_valid_ethereum_address>(address: S) -> bool { let address = address.as_ref(); From 39d70ac8d252f2df88f623fe9dfcfa2f07c5962a Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 6 Jan 2025 15:02:19 -0600 Subject: [PATCH 8/8] Fix lint --- bindings_node/src/conversation.rs | 2 +- bindings_wasm/src/conversation.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings_node/src/conversation.rs b/bindings_node/src/conversation.rs index 3c201646c..98c27179b 100644 --- a/bindings_node/src/conversation.rs +++ b/bindings_node/src/conversation.rs @@ -230,7 +230,7 @@ impl Conversation { installation_ids: member .installation_ids .into_iter() - .map(|id| hex::encode(id)) + .map(hex::encode) .collect(), permission_level: match member.permission_level { XmtpPermissionLevel::Member => PermissionLevel::Member, diff --git a/bindings_wasm/src/conversation.rs b/bindings_wasm/src/conversation.rs index 228837d4e..6509c5873 100644 --- a/bindings_wasm/src/conversation.rs +++ b/bindings_wasm/src/conversation.rs @@ -229,7 +229,7 @@ impl Conversation { installation_ids: member .installation_ids .into_iter() - .map(|id| hex::encode(id)) + .map(hex::encode) .collect(), permission_level: match member.permission_level { XmtpPermissionLevel::Member => PermissionLevel::Member,