Skip to content

Commit 86c9e9b

Browse files
komodo2662astaphobia
authored andcommitted
#80 implementation for proof of ownership (#90)
* #80 add core node admin services * improve generate proof of ownership function * on progress proof of ownership validation * node message conversion from byte * add nodeAdminCoreService test * add config owner acc address * recompiled schema after refactoring ProofOfOwnership protobuf Refactored signature.go: changed method name from SignBlock to SignByNode (to generalise message that are signed using node pri key) Added GetBlockHash to blockUtil.go Refactored nodeAdminCoreService.GenerateProofOfOwnership: now reusing methods from other service and packages to reduce duplication of business logic added helpers interface and injected into NodeAdmin stuct to make its methods mockable refactored unit test for GenerateProofOfOwnership * added GetBlockByHeight to blockService and creted unit test refactored ValidateProofOfOwnership method to reuse already (previously) implemented methods * finished refactoring ValidateProofOfOwnership moved all helper (mockable) methods to NodeAdminServiceHelpersInterface fixed bug in GetSize for accountType (min size in bytes for an integer in protobuf v3 is 4, so we cannot have 2 or 1 byte fields) * fixed loading config params: using configuration already loaded in main.go fixed relative unit tests * injected BlockService into NodeAdminService to make it mockable and refactored relative code/tests * simplified unit tests by removing unecessary mocked queries (since now we mock direclty the blockservice, which is the one where queries needed to be mocked)
1 parent 3e49292 commit 86c9e9b

20 files changed

+720
-281
lines changed

common/constant/node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package constant
2+
3+
var (
4+
// ProofOfOwnershipExpiration number of blocks after a proof of ownership message 'expires' (is considered invalid)
5+
ProofOfOwnershipExpiration uint32 = 100
6+
)

common/crypto/signature.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type (
99
SignatureInterface interface {
1010
Sign(payload []byte, accountType uint32, accountAddress, seed string) []byte
11-
SignBlock(payload []byte, nodeSeed string) []byte
11+
SignByNode(payload []byte, nodeSeed string) []byte
1212
VerifySignature(payload, signature []byte, accountType uint32, accountAddress string) bool
1313
}
1414

@@ -37,8 +37,8 @@ func (sig *Signature) Sign(payload []byte, accountType uint32, accountAddress, s
3737
}
3838
}
3939

40-
// SignBlock special method for signing block only, there will be no multiple signature options
41-
func (*Signature) SignBlock(payload []byte, nodeSeed string) []byte {
40+
// SignByNode special method for signing block only, there will be no multiple signature options
41+
func (*Signature) SignByNode(payload []byte, nodeSeed string) []byte {
4242
nodePrivateKey := ed25519GetPrivateKeyFromSeed(nodeSeed)
4343
return ed25519.Sign(nodePrivateKey, payload)
4444
}

common/crypto/signature_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestSignature_SignBlock(t *testing.T) {
8383
want []byte
8484
}{
8585
{
86-
name: "SignBlock:success",
86+
name: "SignByNode:success",
8787
args: args{
8888
payload: []byte{12, 43, 65, 65, 12, 123, 43, 12, 1, 24, 5, 5, 12, 54},
8989
nodeSeed: "concur vocalist rotten busload gap quote stinging undiluted surfer goofiness deviation starved",
@@ -96,8 +96,8 @@ func TestSignature_SignBlock(t *testing.T) {
9696
for _, tt := range tests {
9797
t.Run(tt.name, func(t *testing.T) {
9898
s := &Signature{}
99-
if got := s.SignBlock(tt.args.payload, tt.args.nodeSeed); !reflect.DeepEqual(got, tt.want) {
100-
t.Errorf("Signature.SignBlock() = %v, want %v", got, tt.want)
99+
if got := s.SignByNode(tt.args.payload, tt.args.nodeSeed); !reflect.DeepEqual(got, tt.want) {
100+
t.Errorf("Signature.SignByNode() = %v, want %v", got, tt.want)
101101
}
102102
})
103103
}

common/model/host.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/model/nodeRegistration.pb.go

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)