mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: update "generateSignalPubKey" function
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto'
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto'
|
||||||
import * as curveJs from 'curve25519-js'
|
import * as curveJs from 'curve25519-js'
|
||||||
import HKDF from 'futoin-hkdf'
|
import HKDF from 'futoin-hkdf'
|
||||||
|
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
||||||
import { KeyPair } from '../Types'
|
import { KeyPair } from '../Types'
|
||||||
|
|
||||||
export const Curve = {
|
export const Curve = {
|
||||||
@@ -22,12 +23,14 @@ export const Curve = {
|
|||||||
return curveJs.verify(pubKey, message, signature)
|
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) => {
|
export const signedKeyPair = (keyPair: KeyPair, keyId: number) => {
|
||||||
const signKeys = Curve.generateKeyPair()
|
const signKeys = Curve.generateKeyPair()
|
||||||
const pubKey = new Uint8Array(33)
|
const pubKey = generateSignalPubKey(keyPair.public)
|
||||||
pubKey.set([5], 0)
|
|
||||||
pubKey.set(signKeys.public, 1)
|
|
||||||
|
|
||||||
const signature = Curve.sign(keyPair.private, pubKey)
|
const signature = Curve.sign(keyPair.private, pubKey)
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,9 @@ import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage, SenderK
|
|||||||
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
||||||
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalAuthState, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth'
|
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 { 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'
|
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]
|
const jidToSignalAddress = (jid: string) => jid.split('@')[0]
|
||||||
|
|
||||||
export const jidToSignalProtocolAddress = (jid: string) => {
|
export const jidToSignalProtocolAddress = (jid: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user