feat(add-routing-info): initial commit (#773)

This commit is contained in:
Rajeh Taher
2024-05-15 18:34:37 +03:00
committed by GitHub
parent 2ae664c655
commit 0eaa5af909
4 changed files with 34 additions and 3 deletions

View File

@@ -217,5 +217,6 @@ export const initAuthCreds = (): AuthenticationCreds => {
registration: {} as never,
pairingCode: undefined,
lastPropHash: undefined,
routingInfo: undefined,
}
}

View File

@@ -18,11 +18,13 @@ export const makeNoiseHandler = ({
NOISE_HEADER,
mobile,
logger,
routingInfo
}: {
keyPair: KeyPair
NOISE_HEADER: Uint8Array
mobile: boolean
logger: Logger
routingInfo?: Buffer | undefined
}) => {
logger = logger.child({ class: 'ns' })
@@ -133,11 +135,25 @@ export const makeNoiseHandler = ({
data = encrypt(data)
}
const introSize = sentIntro ? 0 : NOISE_HEADER.length
let header: Buffer
if(routingInfo) {
header = Buffer.alloc(7)
header.write('ED', 0, 'utf8')
header.writeUint8(0, 2)
header.writeUint8(1, 3)
header.writeUint8(routingInfo.byteLength >> 16, 4)
header.writeUint16BE(routingInfo.byteLength & 65535, 5)
header = Buffer.concat([header, routingInfo, NOISE_HEADER])
} else {
header = Buffer.from(NOISE_HEADER)
}
const introSize = sentIntro ? 0 : header.length
const frame = Buffer.alloc(introSize + 3 + data.byteLength)
if(!sentIntro) {
frame.set(NOISE_HEADER)
frame.set(header)
sentIntro = true
}