mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add helper function to find a contact by public key prefix
This commit is contained in:
parent
565453a123
commit
166762dc31
1 changed files with 13 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue