forked from bpancost/sila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (89 loc) · 2.46 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"fmt"
"log"
"os"
"github.com/ardanlabs/conf/v3"
"github.com/google/uuid"
"github.com/joho/godotenv"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
sila "github.com/kappapay/silaclient"
"github.com/kappapay/silaclient/domain"
)
type SilaConfig struct {
PrivateKeyHex string `conf:"env:SILA_PRIVATE_KEY_HEX,required"`
AuthHandle string `conf:"env:SILA_AUTH_HANDLE,required"`
BaseURL string `conf:"env:SILA_BASE_URL,required"`
}
func main() {
err := run()
if err != nil {
log.Fatal(err)
}
}
func run() error {
if _, err := os.Stat(".env"); err == nil {
err := godotenv.Load()
if err != nil {
return fmt.Errorf("error loading .env file: %w", err)
}
}
cfg := SilaConfig{}
_, err := conf.Parse("", &cfg)
if err != nil {
return fmt.Errorf("parsing config: %w", err)
}
client, err := sila.NewClient(cfg.PrivateKeyHex, cfg.AuthHandle, sila.Environment(cfg.BaseURL))
if err != nil {
return fmt.Errorf("error initializing client: %w", err)
}
privateKey, err := ecdsa.GenerateKey(secp256k1.S256(), rand.Reader)
if err != nil {
return err
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return fmt.Errorf("failed to get public key")
}
address := crypto.PubkeyToAddress(*publicKeyECDSA)
addressHex := address.Hex()
userHandle := uuid.NewString()
resp, err := client.Register(userHandle).
SetAddress(domain.RegistrationAddress{
StreetAddress1: "123 Brick St.",
City: "Hometown",
PostalCode: "12345",
State: "WY",
}).
SetContact("default", "+13335554444", "example@example.com").
SetCrypto("default", addressHex).
SetIndividualEntity("Don", "Wurribouttet", "1970-04-20").
SetIdentity(domain.Ssn, "333224444").
Do()
if err != nil {
return err
}
if !resp.Success {
return fmt.Errorf("sila register call failed: %v", resp)
}
userPrivateKeyHex := hex.EncodeToString(privateKey.D.Bytes())
kycResp, err := client.RequestKyc(userHandle).Do(userPrivateKeyHex)
if err != nil {
return err
}
fmt.Println("request_kyc:", kycResp)
kycResultResp, err := client.CheckKyc(userHandle).Do(userPrivateKeyHex)
if err != nil {
return err
}
fmt.Println("kyc_result:", kycResultResp)
fmt.Println("user address:", addressHex)
fmt.Printf("USER_HANDLE=%s\n", userHandle)
fmt.Printf("USER_PRIVATE_KEY_HEX=%s\n", userPrivateKeyHex)
return nil
}