diff --git a/src/Utils/crypto.ts b/src/Utils/crypto.ts index cb9a385..b85de0d 100644 --- a/src/Utils/crypto.ts +++ b/src/Utils/crypto.ts @@ -1,6 +1,7 @@ import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto' import * as curveJs from 'curve25519-js' import HKDF from 'futoin-hkdf' +import { KEY_BUNDLE_TYPE } from '../Defaults' import { KeyPair } from '../Types' export const Curve = { @@ -22,12 +23,14 @@ export const Curve = { return curveJs.verify(pubKey, message, signature) } } +/** prefix version byte to the pub keys, required for some curve crypto functions */ +export const generateSignalPubKey = (pubKey: Uint8Array | Buffer) => ( + Buffer.concat([ KEY_BUNDLE_TYPE, pubKey ]) +) export const signedKeyPair = (keyPair: KeyPair, keyId: number) => { const signKeys = Curve.generateKeyPair() - const pubKey = new Uint8Array(33) - pubKey.set([5], 0) - pubKey.set(signKeys.public, 1) + const pubKey = generateSignalPubKey(keyPair.public) const signature = Curve.sign(keyPair.private, pubKey) diff --git a/src/Utils/signal.ts b/src/Utils/signal.ts index 09ef5bb..10ca261 100644 --- a/src/Utils/signal.ts +++ b/src/Utils/signal.ts @@ -4,16 +4,9 @@ import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage, SenderK import { KEY_BUNDLE_TYPE } from '../Defaults' import { AuthenticationCreds, AuthenticationState, KeyPair, SignalAuthState, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth' import { assertNodeErrorFree, BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, jidDecode, JidWithDevice, S_WHATSAPP_NET } from '../WABinary' -import { Curve } from './crypto' +import { Curve, generateSignalPubKey } from './crypto' import { encodeBigEndian } from './generics' -export const generateSignalPubKey = (pubKey: Uint8Array | Buffer) => { - const newPub = Buffer.alloc(33) - newPub.set([5], 0) - newPub.set(pubKey, 1) - return newPub -} - const jidToSignalAddress = (jid: string) => jid.split('@')[0] export const jidToSignalProtocolAddress = (jid: string) => {