fix js-waku utils

This commit is contained in:
Felicio Mununga 2022-05-25 14:42:47 +02:00
parent 093010a844
commit 5069563f1f
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 6 additions and 5 deletions

View File

@ -1,10 +1,9 @@
import { BN } from 'bn.js'
import { derive } from 'ecies-geth'
import { ec } from 'elliptic'
import { bufToHex } from 'js-waku/build/main/lib/utils'
import { idToContentTopic } from './contentTopic'
import { hexToBuf } from './utils'
import { bufToHex, hexToBuf } from './utils'
import type { Identity } from '.'
@ -40,7 +39,7 @@ export async function getNegotiatedTopic(
const key = EC.keyFromPublic(publicKey.slice(2), 'hex')
const sharedSecret = await derive(
Buffer.from(identity.privateKey),
hexToBuf(key.getPublic('hex'))
Buffer.concat([hexToBuf(key.getPublic('hex'))])
)
return idToContentTopic(bufToHex(sharedSecret))
}

View File

@ -8,14 +8,16 @@ import type { Waku } from 'js-waku'
const EC = new ec('secp256k1')
const hexToBuf = utils.hexToBuf
// TODO: rename
const hexToBuf = utils.hexToBytes
export { hexToBuf }
// TODO: rename
/**
* Return hex string with 0x prefix (commonly used for string format of a community id/public key.
*/
export function bufToHex(buf: Uint8Array): string {
return '0x' + utils.bufToHex(buf)
return '0x' + utils.bytesToHex(buf)
}
export function compressPublicKey(key: Uint8Array): string {