Additional protocol changes for CDS v2

This commit is contained in:
Fedor Indutny 2021-11-12 21:45:30 +01:00 committed by GitHub
parent b35d330c0a
commit bb15cfc622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 20 deletions

View file

@ -91,6 +91,13 @@ export function createKeyPair(incomingKey: Uint8Array): KeyPairType {
};
}
export function prefixPublicKey(pubKey: Uint8Array): Uint8Array {
return Bytes.concatenate([
new Uint8Array([0x05]),
validatePubKeyFormat(pubKey),
]);
}
export function calculateAgreement(
pubKey: Uint8Array,
privKey: Uint8Array
@ -98,9 +105,7 @@ export function calculateAgreement(
const privKeyBuffer = Buffer.from(privKey);
const pubKeyObj = client.PublicKey.deserialize(
Buffer.from(
Bytes.concatenate([new Uint8Array([0x05]), validatePubKeyFormat(pubKey)])
)
Buffer.from(prefixPublicKey(pubKey))
);
const privKeyObj = client.PrivateKey.deserialize(privKeyBuffer);
const sharedSecret = privKeyObj.agree(pubKeyObj);