-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkeys.ts
48 lines (40 loc) · 1.19 KB
/
keys.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { bbsGenerateKeyPair, bbsGeneratePublicKey, bbsGenerateSigningKey } from 'crypto-wasm-new';
import { BBSPlusPublicKeyG2 } from '../bbs-plus';
import { BBSSignatureParams } from './params';
import { BytearrayWrapper } from '../bytearray-wrapper';
/**
* `BBS` secret key.
*/
export class BBSSecretKey extends BytearrayWrapper {
generatePublicKey(params: BBSSignatureParams): BBSPublicKey {
return new BBSPublicKey(bbsGeneratePublicKey(this.value, params.value));
}
static generate(seed?: Uint8Array) {
return new this(bbsGenerateSigningKey(seed));
}
}
/**
* `BBS` public key.
*/
export class BBSPublicKey extends BBSPlusPublicKeyG2 {}
/**
* `BBS` keypair.
*/
export class BBSKeypair {
sk: BBSSecretKey;
pk: BBSPublicKey;
constructor(sk: BBSSecretKey, pk: BBSPublicKey) {
this.sk = sk;
this.pk = pk;
}
get secretKey(): BBSSecretKey {
return this.sk;
}
get publicKey(): BBSPublicKey {
return this.pk;
}
static generate(params: BBSSignatureParams, seed?: Uint8Array): BBSKeypair {
const keypair = bbsGenerateKeyPair(params.value, seed);
return new BBSKeypair(new BBSSecretKey(keypair.secret_key), new BBSPublicKey(keypair.public_key));
}
}