-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.14 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
package main
import (
"encoding/base64"
"encoding/hex"
"fmt"
"strings"
"github.com/icon-project/goloop/common/crypto"
)
func recoverPublicKeyFromSignature(txHashHex string, signatureBase64 string) (*crypto.PublicKey, error) {
// Decode transaction hash
if strings.HasPrefix(txHashHex, "0x") {
txHashHex = txHashHex[2:]
}
txHashBytes, err := hex.DecodeString(txHashHex)
if err != nil {
return nil, err
}
// Decode Base64 signature to bytes
sigBytes, err := base64.StdEncoding.DecodeString(signatureBase64)
if err != nil {
return nil, err
}
// Parse the signature
sig, err := crypto.ParseSignature(sigBytes)
if err != nil {
return nil, err
}
// Recover the public key
return sig.RecoverPublicKey(txHashBytes)
}
func main() {
txHash := "0x516d2ecad0b5e37899900ddd6d2bfd94d7a2680b1401876214b873ce3d5c9846"
signature := "AXrPcOq5HgkKwaf0vCJ+WmKSgIDv/dpZLBkqh1G8oBVowdRLaEFNfRmj5LlQ3Lggpcdpc/cs1ZZKVZcNsIhNwQA="
pubKey, err := recoverPublicKeyFromSignature(txHash, signature)
if err != nil {
fmt.Println("Error:", err)
return
}
// Output the recovered public key
fmt.Println("Recovered Public Key:", pubKey.String())
}