mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 14:12:30 +00:00
Remove signing early data payload and prefix
This commit is contained in:
parent
8f92180611
commit
ebb7483109
27
src/utils.ts
27
src/utils.ts
@ -29,24 +29,24 @@ export async function getPayload(
|
|||||||
earlyData?: bytes,
|
earlyData?: bytes,
|
||||||
): Promise<bytes> {
|
): Promise<bytes> {
|
||||||
const signedPayload = await signPayload(localPeer, getHandshakePayload(staticPublicKey));
|
const signedPayload = await signPayload(localPeer, getHandshakePayload(staticPublicKey));
|
||||||
const signedEarlyDataPayload = await signEarlyDataPayload(localPeer, earlyData || Buffer.alloc(0));
|
const earlyDataPayload = earlyData || Buffer.alloc(0);
|
||||||
|
|
||||||
return await createHandshakePayload(
|
return await createHandshakePayload(
|
||||||
localPeer.marshalPubKey(),
|
localPeer.marshalPubKey(),
|
||||||
signedPayload,
|
signedPayload,
|
||||||
signedEarlyDataPayload
|
earlyDataPayload
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createHandshakePayload(
|
export async function createHandshakePayload(
|
||||||
libp2pPublicKey: bytes,
|
libp2pPublicKey: bytes,
|
||||||
signedPayload: bytes,
|
signedPayload: bytes,
|
||||||
signedEarlyData?: EarlyDataPayload,
|
earlyData?: bytes,
|
||||||
): Promise<bytes> {
|
): Promise<bytes> {
|
||||||
const NoiseHandshakePayload = await loadPayloadProto();
|
const NoiseHandshakePayload = await loadPayloadProto();
|
||||||
const earlyDataPayload = signedEarlyData ?
|
const earlyDataPayload = earlyData ?
|
||||||
{
|
{
|
||||||
data: signedEarlyData.libp2pData,
|
data: earlyData,
|
||||||
} : {};
|
} : {};
|
||||||
|
|
||||||
const payloadInit = NoiseHandshakePayload.create({
|
const payloadInit = NoiseHandshakePayload.create({
|
||||||
@ -63,25 +63,8 @@ export async function signPayload(peerId: PeerId, payload: bytes): Promise<bytes
|
|||||||
return peerId.privKey.sign(payload);
|
return peerId.privKey.sign(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
type EarlyDataPayload = {
|
|
||||||
libp2pData: bytes;
|
|
||||||
libp2pDataSignature: bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function signEarlyDataPayload(peerId: PeerId, earlyData: bytes): Promise<EarlyDataPayload> {
|
|
||||||
const payload = getEarlyDataPayload(earlyData);
|
|
||||||
const signedPayload = await signPayload(peerId, payload);
|
|
||||||
|
|
||||||
return {
|
|
||||||
libp2pData: payload,
|
|
||||||
libp2pDataSignature: signedPayload,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getHandshakePayload = (publicKey: bytes ) => Buffer.concat([Buffer.from("noise-libp2p-static-key:"), publicKey]);
|
export const getHandshakePayload = (publicKey: bytes ) => Buffer.concat([Buffer.from("noise-libp2p-static-key:"), publicKey]);
|
||||||
|
|
||||||
export const getEarlyDataPayload = (earlyData: bytes) => Buffer.concat([Buffer.from("noise-libp2p-early-data:"), earlyData]);
|
|
||||||
|
|
||||||
async function isValidPeerId(peerId: bytes, publicKeyProtobuf: bytes) {
|
async function isValidPeerId(peerId: bytes, publicKeyProtobuf: bytes) {
|
||||||
const generatedPeerId = await PeerId.createFromPubKey(publicKeyProtobuf);
|
const generatedPeerId = await PeerId.createFromPubKey(publicKeyProtobuf);
|
||||||
return generatedPeerId.id.equals(peerId);
|
return generatedPeerId.id.equals(peerId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user