-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (66 loc) · 1.78 KB
/
main.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"regexp"
"strings"
mpcsigner "github.com/capsule-org/go-sdk/signer"
)
func main() {
fmt.Println("\n\n---------------- Generating private key with backup share ----------------\n")
userShare := os.Args[1]
capsuleShareConfig := os.Args[2]
// if userShare is the snaps recovery secret, extract the share from everything after the "|" character
if strings.Contains(userShare, "|") {
splitUserShare := strings.SplitN(userShare, "|", 2)
decodedUserShare, err := base64.RawStdEncoding.DecodeString(splitUserShare[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
userShare = string(decodedUserShare)
}
userSigner, err := mpcsigner.DKLSDeserializeSigner(userShare, "")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// regex to replace non base64 characters with "ff" as it's encoded incorrectly in the pdf
reg, err := regexp.Compile("[^A-Za-z0-9+/=]+")
if err != nil {
fmt.Println("error compiling regex:", err)
os.Exit(1)
}
cleanCapsuleShareConfig := reg.ReplaceAllString(
strings.ReplaceAll(capsuleShareConfig, " ", ""),
"ff",
)
capsuleShare := fmt.Sprintf(
`{"walletId":"%s","id":"%s","otherId":"%s","receiverConfig":"%s","senderConfig":"%s","isReceiver":%t,"disableWebSockets":%t}`,
userSigner.GetWalletId(),
"CAPSULE",
"USER",
cleanCapsuleShareConfig,
"9g==",
true,
false,
)
capsuleSigner, err := mpcsigner.DKLSDeserializeSigner(capsuleShare, "")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
sk1 := userSigner.GetPrivateKey()
sk2 := capsuleSigner.GetPrivateKey()
sk := sk1.Add(sk2)
skBytes, err := sk.MarshalBinary()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
skHex := hex.EncodeToString(skBytes)
fmt.Println("private key hex:")
fmt.Println("0x" + skHex)
}