mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
* refactor: migrate WASignalGroup to TypeScript and remove deprecated files * chore: remove WASignalGroup JavaScript files from package.json * refactor: update SenderKeyStore and SenderKeyStateStructure interfaces to export and add deserialize method. Fix types * chore: lint issue * refactor: improve constructor type checking and getSeed method in SenderChainKey * refactor: update key handling to use Buffer for improved consistency * signal: consistent naming and dir structure + add some missing types * fix: lint issues --------- Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { calculateMAC } from 'libsignal/src/crypto'
|
|
import { SenderMessageKey } from './sender-message-key'
|
|
|
|
export class SenderChainKey {
|
|
private readonly MESSAGE_KEY_SEED: Uint8Array = Buffer.from([0x01])
|
|
private readonly CHAIN_KEY_SEED: Uint8Array = Buffer.from([0x02])
|
|
private readonly iteration: number
|
|
private readonly chainKey: Buffer
|
|
|
|
constructor(iteration: number, chainKey: any) {
|
|
this.iteration = iteration
|
|
if (chainKey instanceof Buffer) {
|
|
this.chainKey = chainKey
|
|
} else {
|
|
this.chainKey = Buffer.from(chainKey || [])
|
|
}
|
|
}
|
|
|
|
public getIteration(): number {
|
|
return this.iteration
|
|
}
|
|
|
|
public getSenderMessageKey(): SenderMessageKey {
|
|
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey))
|
|
}
|
|
|
|
public getNext(): SenderChainKey {
|
|
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey))
|
|
}
|
|
|
|
public getSeed(): Uint8Array {
|
|
return this.chainKey
|
|
}
|
|
|
|
private getDerivative(seed: Uint8Array, key: Buffer): Uint8Array {
|
|
return calculateMAC(key, seed)
|
|
}
|
|
}
|