-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateProof.ts
More file actions
60 lines (47 loc) · 1.48 KB
/
Copy pathcreateProof.ts
File metadata and controls
60 lines (47 loc) · 1.48 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
import {
generateBls12381G2KeyPair,
BbsSignRequest,
BlsBbsSignRequest,
sign,
bls12381toBbs,
BBS_SIGNATURE_LENGTH,
BbsKeyPair,
blsSign,
BlsKeyPair,
} from "@mattrglobal/bbs-signatures";
import { base64Encode, base64Decode, stringToBytes } from "./utility";
async function createProof(
pk: string,
sk: string,
messages: string[]) : Promise<string>{
/* Setup for messages, pk, and sk */
const messages_ = [];
for (const message of messages) {
messages_.push(Uint8Array.from(Buffer.from(message, "utf-8")));
}
const pk_d = base64Decode(pk);
const sk_d = base64Decode(sk);
//const keyPair3 = await generateBls12381G2KeyPair(); //A test in case that the key pair is generated here.
/* Setup for the BlsKeyPair */
const blsKeyPair: BlsKeyPair = {
publicKey: pk_d,
secretKey: sk_d,
//publicKey: keyPair3.publicKey,
//secretKey: keyPair3.secretKey,
};
/* Generating a BbsKeyPair using the BlsKeyPair & messageCount */
const bbsKeyPair: BbsKeyPair = await bls12381toBbs({
keyPair: blsKeyPair,
messageCount: messages.length,
});
//console.log(bbsKeyPair);
/* Setting the request format */
const request: BbsSignRequest = {
keyPair: bbsKeyPair,
messages: messages_,
};
/* Forecast the request to the API sign() function & obtain the result */
const proof = await sign(request);
return base64Encode(proof);
}
export default createProof;