Skip to content

Commit

Permalink
Update node bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Jan 6, 2025
1 parent 2d1ef2b commit 54c6a96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bindings_node/src/inbox_state.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<BigInt>,
pub id: String,
}

#[napi(object)]
Expand All @@ -30,8 +31,9 @@ impl From<AssociationState> 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(),
Expand Down
6 changes: 6 additions & 0 deletions bindings_node/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
])
Expand All @@ -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(),
])
Expand Down

0 comments on commit 54c6a96

Please sign in to comment.