mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-21 23:48:05 +00:00
63781f8889
- Published from build/ directories for correct npm structure - Updated wasm dependencies to 7.5.17 - All packages now have index.js at root level
18 lines
707 B
JavaScript
18 lines
707 B
JavaScript
import { getSharedSecret } from '@pezkuwi/scure-sr25519';
|
|
import { u8aToU8a } from '@pezkuwi/util';
|
|
/**
|
|
* @name sr25519Agreement
|
|
* @description Key agreement between other's public key and self secret key
|
|
*/
|
|
export function sr25519Agreement(secretKey, publicKey) {
|
|
const secretKeyU8a = u8aToU8a(secretKey);
|
|
const publicKeyU8a = u8aToU8a(publicKey);
|
|
if (publicKeyU8a.length !== 32) {
|
|
throw new Error(`Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
|
|
}
|
|
else if (secretKeyU8a.length !== 64) {
|
|
throw new Error(`Invalid secretKey, received ${secretKeyU8a.length} bytes, expected 64`);
|
|
}
|
|
return getSharedSecret(secretKeyU8a, publicKeyU8a);
|
|
}
|