Skip to content

Commit

Permalink
add PublicKey.mul(SecretKey)
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Sep 9, 2024
1 parent 4487233 commit be8f0c5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/bls.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ const _blsSetupFactory = (createModule) => {
add (rhs) {
this._update(mod._blsPublicKeyAdd, rhs)
}
mul (rhs) {
this._update(mod._blsPublicKeyMul, rhs)
}
share (mpk, id) {
callShare(mod._blsPublicKeyShare, this, BLS_PUBLICKEY_SIZE, mpk, id)
}
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare class PublicKeyType extends Common {
deserializeUncompressed (s: Uint8Array): void;
serializeUncompressed (): Uint8Array;
add(rhs: this): void;
mul(rhs: SecretKey): void;
share(mpk: PublicKeyType[], id: Id): void;
recover(secVec: PublicKeyType[], idVec: Id[]): void;
isValidOrder(): boolean;
Expand Down
40 changes: 40 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const curveTest = (curveType, name) => {
serializeTest()
zeroTest()
signatureTest()
opTest()
miscTest()
shareTest()
addTest()
Expand Down Expand Up @@ -95,6 +96,45 @@ function signatureTest () {
assert(pub.verify(sig, msg))
}

function opTest () {
console.log('opTest')
const sec1 = new bls.SecretKey()
const sec2 = new bls.SecretKey()
sec1.setByCSPRNG()
sec2.setByCSPRNG()
const pub1 = sec1.getPublicKey()
const pub2 = sec2.getPublicKey()
sec1.dump('sec1 ')
sec2.dump('sec2 ')
pub1.dump('pub1 ')
pub2.dump('pub2 ')

const msg = 'doremifa'
const sig1 = sec1.sign(msg)
const sig2 = sec2.sign(msg)
assert(pub1.verify(sig1, msg))
assert(pub2.verify(sig2, msg))
// add
{
const sec = sec1.clone()
sec.add(sec2)
sec.dump('sec ')
const pub = pub1.clone()
pub.add(pub2)
pub.dump('pub ')
const sig = sig1.clone()
sig.add(sig2)
sig.dump('sig ')
assert(pub.verify(sig, msg))
}
// mul
pub1.mul(sec2)
pub1.dump('pub1*sec2 ')
pub2.mul(sec1)
pub2.dump('pub2*sec1 ')
assert(pub1.isEqual(pub2))
}

function bench (label, count, func) {
const start = performance.now()
for (let i = 0; i < count; i++) {
Expand Down

0 comments on commit be8f0c5

Please sign in to comment.