diff --git a/bindings_node/CHANGELOG.md b/bindings_node/CHANGELOG.md index 4c2dbe669..426caf777 100644 --- a/bindings_node/CHANGELOG.md +++ b/bindings_node/CHANGELOG.md @@ -1,5 +1,9 @@ # @xmtp/node-bindings +## 0.0.21 + +- Added `installation_id_bytes` to `Client` + ## 0.0.20 - Fixed argument types for new signing methods diff --git a/bindings_node/package.json b/bindings_node/package.json index 9939f3844..65db63a12 100644 --- a/bindings_node/package.json +++ b/bindings_node/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/node-bindings", - "version": "0.0.20", + "version": "0.0.21", "repository": { "type": "git", "url": "git+https://git@github.com/xmtp/libxmtp.git", diff --git a/bindings_node/src/client.rs b/bindings_node/src/client.rs index d2158b57c..3f042e501 100644 --- a/bindings_node/src/client.rs +++ b/bindings_node/src/client.rs @@ -201,6 +201,11 @@ impl Client { ed25519_public_key_to_address(self.inner_client.installation_public_key().as_slice()) } + #[napi] + pub fn installation_id_bytes(&self) -> Uint8Array { + self.inner_client.installation_public_key().into() + } + #[napi] pub async fn can_message(&self, account_addresses: Vec) -> Result> { let results: HashMap = self diff --git a/bindings_wasm/CHANGELOG.md b/bindings_wasm/CHANGELOG.md index ae7da1394..69994bd9e 100644 --- a/bindings_wasm/CHANGELOG.md +++ b/bindings_wasm/CHANGELOG.md @@ -1,5 +1,10 @@ # @xmtp/wasm-bindings +## 0.0.6 + +- Added `installation_id_bytes` to `Client` +- Added `sign_with_installation_key`, `verify_signed_with_installation_key`, and `verify_signed_with_public_key` to `Client` + ## 0.0.5 - Filtered out group membership messages from DM groups diff --git a/bindings_wasm/package.json b/bindings_wasm/package.json index e799e8cf2..d963f21e1 100644 --- a/bindings_wasm/package.json +++ b/bindings_wasm/package.json @@ -1,6 +1,6 @@ { "name": "@xmtp/wasm-bindings", - "version": "0.0.5", + "version": "0.0.6", "type": "module", "license": "MIT", "description": "WASM bindings for the libXMTP rust library", diff --git a/bindings_wasm/src/client.rs b/bindings_wasm/src/client.rs index 7b3711d79..13451ce22 100644 --- a/bindings_wasm/src/client.rs +++ b/bindings_wasm/src/client.rs @@ -11,6 +11,7 @@ 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_id::associations::verify_signed_with_public_context; use xmtp_mls::builder::ClientBuilder; use xmtp_mls::groups::scoped_client::ScopedGroupClient; use xmtp_mls::identity::IdentityStrategy; @@ -203,6 +204,11 @@ impl Client { ed25519_public_key_to_address(self.inner_client.installation_public_key().as_slice()) } + #[wasm_bindgen(getter, js_name = installationIdBytes)] + pub fn installation_id_bytes(&self) -> Uint8Array { + Uint8Array::from(self.inner_client.installation_public_key().as_slice()) + } + #[wasm_bindgen(js_name = canMessage)] pub async fn can_message(&self, account_addresses: Vec) -> Result { let results: HashMap = self @@ -278,4 +284,50 @@ impl Client { pub fn conversations(&self) -> Conversations { Conversations::new(self.inner_client.clone()) } + + #[wasm_bindgen(js_name = signWithInstallationKey)] + pub fn sign_with_installation_key(&self, signature_text: String) -> Result { + let result = self + .inner_client + .context() + .sign_with_public_context(signature_text) + .map_err(|e| JsError::new(format!("{}", e).as_str()))?; + + Ok(Uint8Array::from(result.as_slice())) + } + + #[wasm_bindgen(js_name = verifySignedWithInstallationKey)] + pub fn verify_signed_with_installation_key( + &self, + signature_text: String, + signature_bytes: Uint8Array, + ) -> Result<(), JsError> { + let public_key = self.inner_client().installation_public_key(); + self.verify_signed_with_public_key( + signature_text, + signature_bytes, + Uint8Array::from(public_key.as_slice()), + ) + } + + #[wasm_bindgen(js_name = verifySignedWithPublicKey)] + pub fn verify_signed_with_public_key( + &self, + signature_text: String, + signature_bytes: Uint8Array, + public_key: Uint8Array, + ) -> Result<(), JsError> { + let signature_bytes = signature_bytes.to_vec(); + let signature_bytes: [u8; 64] = signature_bytes + .try_into() + .map_err(|_| JsError::new("signature_bytes is not 64 bytes long."))?; + + let public_key = public_key.to_vec(); + let public_key: [u8; 32] = public_key + .try_into() + .map_err(|_| JsError::new("public_key is not 32 bytes long."))?; + + verify_signed_with_public_context(signature_text, &signature_bytes, &public_key) + .map_err(|e| JsError::new(format!("{}", e).as_str())) + } }