add helper function to find a contact by public key prefix

This commit is contained in:
liamcottle 2025-03-04 17:29:14 +13:00
parent 565453a123
commit 166762dc31

View file

@ -654,6 +654,19 @@ class Connection extends EventEmitter {
});
}
async findContactByPublicKeyPrefix(pubKeyPrefix) {
// get contacts
const contacts = await this.getContacts();
// find first contact matching pub key prefix
return contacts.find((contact) => {
const contactPubKeyPrefix = contact.publicKey.subarray(0, pubKeyPrefix.length);
return BufferUtils.areBuffersEqual(pubKeyPrefix, contactPubKeyPrefix);
});
}
sendTextMessage(contactPublicKey, text, type) {
return new Promise(async (resolve, reject) => {
try {