Skip to content
Snippets Groups Projects
Commit c7230a1e authored by Jonah Husson's avatar Jonah Husson
Browse files

Updates for special november commitment project

parent 7368e654
No related branches found
No related tags found
1 merge request!10Draft: November commitments
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
utils2 "gitlab.com/xx_network/primitives/utils" utils2 "gitlab.com/xx_network/primitives/utils"
) )
func SignAndTransmit(keyPath, idfPath, nominatorWallet, validatorWallet, serverAddress, serverCert, contract string) error { func SignAndTransmit(keyPath, idfPath, paymentWallet, serverAddress, serverCert, contract string) error {
var key, idfBytes []byte var key, idfBytes []byte
var err error var err error
var ep string var ep string
...@@ -51,11 +51,11 @@ func SignAndTransmit(keyPath, idfPath, nominatorWallet, validatorWallet, serverA ...@@ -51,11 +51,11 @@ func SignAndTransmit(keyPath, idfPath, nominatorWallet, validatorWallet, serverA
return errors.WithMessage(err, "Failed to write contract to hash") return errors.WithMessage(err, "Failed to write contract to hash")
} }
return signAndTransmit(key, idfBytes, h.Sum(nil), nominatorWallet, validatorWallet, serverAddress, serverCert) return signAndTransmit(key, idfBytes, h.Sum(nil), paymentWallet, serverAddress, serverCert)
} }
// SignAndTransmit creates a Client object & transmits commitment info to the server // SignAndTransmit creates a Client object & transmits commitment info to the server
func signAndTransmit(pk, idfBytes, contractBytes []byte, nominatorWallet, validatorWallet, serverAddress, serverCert string) error { func signAndTransmit(pk, idfBytes, contractBytes []byte, paymentWallet, serverAddress, serverCert string) error {
// Create new resty client // Create new resty client
cl := resty.New() cl := resty.New()
cl.SetRootCertificateFromString(serverCert) cl.SetRootCertificateFromString(serverCert)
...@@ -66,7 +66,7 @@ func signAndTransmit(pk, idfBytes, contractBytes []byte, nominatorWallet, valida ...@@ -66,7 +66,7 @@ func signAndTransmit(pk, idfBytes, contractBytes []byte, nominatorWallet, valida
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to load private key") return errors.WithMessage(err, "Failed to load private key")
} }
hashed, hash, err := utils.HashNodeInfo(nominatorWallet, validatorWallet, idfBytes, contractBytes) hashed, hash, err := utils.HashNodeInfo(paymentWallet, idfBytes, contractBytes)
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to hash node info") return errors.WithMessage(err, "Failed to hash node info")
} }
...@@ -79,8 +79,7 @@ func signAndTransmit(pk, idfBytes, contractBytes []byte, nominatorWallet, valida ...@@ -79,8 +79,7 @@ func signAndTransmit(pk, idfBytes, contractBytes []byte, nominatorWallet, valida
body := messages.Commitment{ body := messages.Commitment{
IDF: base64.URLEncoding.EncodeToString(idfBytes), IDF: base64.URLEncoding.EncodeToString(idfBytes),
Contract: base64.URLEncoding.EncodeToString(contractBytes), Contract: base64.URLEncoding.EncodeToString(contractBytes),
NominatorWallet: nominatorWallet, PaymentWallet: paymentWallet,
ValidatorWallet: validatorWallet,
Signature: base64.URLEncoding.EncodeToString(sig), Signature: base64.URLEncoding.EncodeToString(sig),
} }
resp, err := cl.R(). resp, err := cl.R().
......
...@@ -52,7 +52,6 @@ func TestSignAndTransmit(t *testing.T) { ...@@ -52,7 +52,6 @@ func TestSignAndTransmit(t *testing.T) {
t.Errorf("Failed to create sleeve: %+v", err) t.Errorf("Failed to create sleeve: %+v", err)
} }
waddr := wallet.XXNetworkAddressFromMnemonic(s.GetOutputMnemonic()) waddr := wallet.XXNetworkAddressFromMnemonic(s.GetOutputMnemonic())
waddr2 := wallet.XXNetworkAddressFromMnemonic(s.GetMnemonic())
testKeyPath := "/tmp/commitmenttestkey.key" testKeyPath := "/tmp/commitmenttestkey.key"
testIDFPath := "/tmp/testidf.json" testIDFPath := "/tmp/testidf.json"
...@@ -102,7 +101,7 @@ func TestSignAndTransmit(t *testing.T) { ...@@ -102,7 +101,7 @@ func TestSignAndTransmit(t *testing.T) {
}() }()
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
err = SignAndTransmit(testKeyPath, testIDFPath, waddr, waddr2, "http://localhost:11420", "", "") err = SignAndTransmit(testKeyPath, testIDFPath, waddr, "http://localhost:11420", "", "")
if err != nil { if err != nil {
t.Errorf("Failed to sign & transmit: %+v", err) t.Errorf("Failed to sign & transmit: %+v", err)
} }
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"strings" "strings"
) )
var logPath, keyPath, idfPath, nominatorWallet, validatorWallet string var logPath, keyPath, idfPath, paymentWallet string
// ExecuteServer adds all child commands to the root command and sets flags // ExecuteServer adds all child commands to the root command and sets flags
// appropriately. This is called by server.main(). It only needs to // appropriately. This is called by server.main(). It only needs to
...@@ -82,7 +82,7 @@ Mu7/deeXg4hfNzQoWdZnBhzgaB05MAbJI6E= ...@@ -82,7 +82,7 @@ Mu7/deeXg4hfNzQoWdZnBhzgaB05MAbJI6E=
jww.FATAL.Fatalf("You must accept the contract to continue") jww.FATAL.Fatalf("You must accept the contract to continue")
} }
err = SignAndTransmit(keyPath, idfPath, nominatorWallet, validatorWallet, address, commitmentCert, utils.Contract) err = SignAndTransmit(keyPath, idfPath, paymentWallet, address, commitmentCert, utils.Contract)
if err != nil { if err != nil {
jww.FATAL.Fatalf("Failed to sign & transmit commitment: %+v", err) jww.FATAL.Fatalf("Failed to sign & transmit commitment: %+v", err)
} }
...@@ -104,9 +104,7 @@ func init() { ...@@ -104,9 +104,7 @@ func init() {
"", "Sets a custom key file path") "", "Sets a custom key file path")
clientCmd.Flags().StringVarP(&idfPath, "idfPath", "i", clientCmd.Flags().StringVarP(&idfPath, "idfPath", "i",
"", "Sets a custom id file path") "", "Sets a custom id file path")
clientCmd.Flags().StringVarP(&nominatorWallet, "nominatorWallet", "n", clientCmd.Flags().StringVarP(&paymentWallet, "paymentWallet", "n",
"", "Sets a custom wallet")
clientCmd.Flags().StringVarP(&validatorWallet, "validatorWallet", "v",
"", "Sets a custom wallet") "", "Sets a custom wallet")
} }
......
...@@ -31,10 +31,9 @@ func SignAndTransmit(this js.Value, inputs []js.Value) interface{} { ...@@ -31,10 +31,9 @@ func SignAndTransmit(this js.Value, inputs []js.Value) interface{} {
keyPath := inputs[0].String() keyPath := inputs[0].String()
idfPath := inputs[1].String() idfPath := inputs[1].String()
contractPath := inputs[2].String() contractPath := inputs[2].String()
nominatorWallet := inputs[3].String() paymentWallet := inputs[3].String()
validatorWallet := inputs[4].String() commitmentServerAddress := inputs[4].String()
commitmentServerAddress := inputs[5].String() commitmentsCertPath := inputs[5].String()
commitmentsCertPath := inputs[6].String()
var commitmentsCert []byte var commitmentsCert []byte
// Read key file // Read key file
...@@ -48,7 +47,7 @@ func SignAndTransmit(this js.Value, inputs []js.Value) interface{} { ...@@ -48,7 +47,7 @@ func SignAndTransmit(this js.Value, inputs []js.Value) interface{} {
} }
// Sign & transmit information // Sign & transmit information
err := client.SignAndTransmit(keyPath, idfPath, contractPath, nominatorWallet, validatorWallet, string(commitmentsCert), commitmentServerAddress, utils.Contract) err := client.SignAndTransmit(keyPath, idfPath, contractPath, paymentWallet, string(commitmentsCert), commitmentServerAddress, utils.Contract)
if err != nil { if err != nil {
return map[string]interface{}{"Error": err.Error()} return map[string]interface{}{"Error": err.Error()}
} }
......
...@@ -4,8 +4,6 @@ package messages ...@@ -4,8 +4,6 @@ package messages
type Commitment struct { type Commitment struct {
IDF string `json:"idf"` IDF string `json:"idf"`
Contract string `json:"contract"` Contract string `json:"contract"`
ValidatorWallet string `json:"validator-wallet"` PaymentWallet string `json:"validator-wallet"`
NominatorWallet string `json:"nominator-wallet"`
Email string `json:"email"`
Signature string `json:"signature"` Signature string `json:"signature"`
} }
...@@ -117,26 +117,14 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error { ...@@ -117,26 +117,14 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
} }
// Validate wallets // Validate wallets
ok, err := wallet.ValidateXXNetworkAddress(msg.NominatorWallet) ok, err := wallet.ValidateXXNetworkAddress(msg.PaymentWallet)
if err != nil { if err != nil {
err = errors.WithMessage(err, "Failed to validate nominator wallet address") err = errors.WithMessage(err, "Failed to validate payment wallet address")
jww.ERROR.Println(err) jww.ERROR.Println(err)
return err return err
} }
if !ok { if !ok {
err = errors.New("Nominator wallet validation returned false") err = errors.New("Payment wallet validation returned false")
jww.ERROR.Println(err)
return err
}
ok, err = wallet.ValidateXXNetworkAddress(msg.ValidatorWallet)
if err != nil {
err = errors.WithMessage(err, "Failed to validate validator wallet address")
jww.ERROR.Println(err)
return err
}
if !ok {
err = errors.New("Validator wallet validation returned false")
jww.ERROR.Println(err) jww.ERROR.Println(err)
return err return err
} }
...@@ -168,7 +156,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error { ...@@ -168,7 +156,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
} }
// Hash node info from message // Hash node info from message
hashed, hash, err := utils.HashNodeInfo(msg.NominatorWallet, msg.ValidatorWallet, idfBytes, contractBytes) hashed, hash, err := utils.HashNodeInfo(msg.PaymentWallet, idfBytes, contractBytes)
if err != nil { if err != nil {
err = errors.WithMessage(err, "Failed to hash node info") err = errors.WithMessage(err, "Failed to hash node info")
jww.ERROR.Println(err) jww.ERROR.Println(err)
...@@ -207,9 +195,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error { ...@@ -207,9 +195,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
err = i.s.InsertCommitment(storage.Commitment{ err = i.s.InsertCommitment(storage.Commitment{
Id: m.Id, Id: m.Id,
Contract: contractBytes, Contract: contractBytes,
Wallet: "LEGACY", Wallet: msg.PaymentWallet,
NominatorWallet: msg.NominatorWallet,
ValidatorWallet: msg.ValidatorWallet,
Signature: sigBytes, Signature: sigBytes,
}) })
if err != nil { if err != nil {
...@@ -218,7 +204,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error { ...@@ -218,7 +204,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
return err return err
} }
jww.INFO.Printf("Registered commitment from %+v [Nominator: %+s, Validator: %s]", idfStruct.ID, msg.NominatorWallet, msg.ValidatorWallet) jww.INFO.Printf("Registered commitment from %+v [Nominator: %+s, Validator: %s]", idfStruct.ID, msg.PaymentWallet)
return nil return nil
} }
......
...@@ -38,8 +38,6 @@ type Commitment struct { ...@@ -38,8 +38,6 @@ type Commitment struct {
Id []byte `gorm:"primary_key"` Id []byte `gorm:"primary_key"`
Contract []byte `gorm:"not null"` Contract []byte `gorm:"not null"`
Wallet string `gorm:"not null"` Wallet string `gorm:"not null"`
NominatorWallet string `gorm:"not null"`
ValidatorWallet string `gorm:"not null"`
Email string Email string
Signature []byte `gorm:"not null"` Signature []byte `gorm:"not null"`
CreatedAt time.Time CreatedAt time.Time
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func HashNodeInfo(nominatorWallet, validatorWallet string, idfBytes, contractBytes []byte) ([]byte, crypto.Hash, error) { func HashNodeInfo(paymentWallet string, idfBytes, contractBytes []byte) ([]byte, crypto.Hash, error) {
h := crypto.BLAKE2b_512 // Define & return this here so we aren't defining hash type in 3 places for sign/verify calls h := crypto.BLAKE2b_512 // Define & return this here so we aren't defining hash type in 3 places for sign/verify calls
hasher := h.New() hasher := h.New()
_, err := hasher.Write(idfBytes) _, err := hasher.Write(idfBytes)
...@@ -23,13 +23,9 @@ func HashNodeInfo(nominatorWallet, validatorWallet string, idfBytes, contractByt ...@@ -23,13 +23,9 @@ func HashNodeInfo(nominatorWallet, validatorWallet string, idfBytes, contractByt
if err != nil { if err != nil {
return nil, h, errors.WithMessage(err, "Failed to write contract to hash") return nil, h, errors.WithMessage(err, "Failed to write contract to hash")
} }
_, err = hasher.Write([]byte(nominatorWallet)) _, err = hasher.Write([]byte(paymentWallet))
if err != nil { if err != nil {
return nil, h, errors.WithMessage(err, "Failed to write nominator wallet to hash") return nil, h, errors.WithMessage(err, "Failed to write nominator wallet to hash")
} }
_, err = hasher.Write([]byte(validatorWallet))
if err != nil {
return nil, h, errors.WithMessage(err, "Failed to write validator wallet to hash")
}
return hasher.Sum(nil), h, nil return hasher.Sum(nil), h, nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment