@stellot/crypto
Version:
Crypto libraries for front and backend
24 lines (23 loc) • 586 B
JavaScript
import { ed25519 } from './index';
import { randomScalar } from './utils';
export default class SignerSession {
constructor(secretKey) {
const keypair = ed25519.keyFromSecret(secretKey);
this.x = keypair.priv();
this.P = keypair.pub();
this.k = randomScalar();
this.R = ed25519.curve.g.mul(this.k);
}
publicKey() {
return this.P;
}
publicNonce() {
return this.R;
}
sign(challenge) {
return this.x
.mul(challenge)
.add(this.k)
.umod(ed25519.curve.n);
}
}