forked from privacy-scaling-explorations/maci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenMaciPubkey.ts
42 lines (36 loc) · 1005 Bytes
/
genMaciPubkey.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
import {
PubKey,
PrivKey,
} from 'maci-domainobjs'
import {
genPubKey,
} from 'maci-crypto'
const configureSubparser = (subparsers: any) => {
const genMaciPubkeyParser = subparsers.addParser(
'genMaciPubkey',
{ addHelp: true },
)
genMaciPubkeyParser.addArgument(
['-sk', '--privkey'],
{
required: true,
action: 'store',
type: 'string',
help: 'This command will output the serialized public key associated with this serialized private key.',
}
)
}
const genMaciPubkey = async (args: any) => {
const isValid = PrivKey.isValidSerializedPrivKey(args.privkey)
if (!isValid) {
console.error('Error: invalid private key')
return
}
const unserialisedPrivkey = PrivKey.unserialize(args.privkey)
const pubkey = new PubKey(genPubKey(unserialisedPrivkey.rawPrivKey))
console.log(pubkey.serialize())
}
export {
genMaciPubkey,
configureSubparser,
}