-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c57105
commit 5c7b2ca
Showing
14 changed files
with
744 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package tbtc | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ipfs/go-log/v2" | ||
"github.com/keep-network/keep-core/pkg/net" | ||
"github.com/keep-network/keep-core/pkg/protocol/group" | ||
"github.com/keep-network/keep-core/pkg/tecdsa/inactivity" | ||
) | ||
|
||
type operatorInactivityNotifier struct { | ||
chain Chain | ||
signers []*signer | ||
} | ||
|
||
func newOperatorInactivityNotifier( | ||
chain Chain, | ||
signers []*signer, | ||
) *operatorInactivityNotifier { | ||
return &operatorInactivityNotifier{ | ||
chain: chain, | ||
signers: signers, | ||
} | ||
} | ||
|
||
func (oin *operatorInactivityNotifier) publishInactivityClaim( | ||
inactiveMembersIndexes []group.MemberIndex, | ||
heartbeatFailed bool, | ||
) error { | ||
// TODO: Build a claim and launch the publish function for all | ||
// the signers. | ||
|
||
return nil | ||
} | ||
|
||
func (oin *operatorInactivityNotifier) publish( | ||
ctx context.Context, | ||
inactivityLogger log.StandardLogger, | ||
seed *big.Int, | ||
memberIndex group.MemberIndex, | ||
broadcastChannel net.BroadcastChannel, | ||
groupSize int, | ||
dishonestThreshold int, | ||
membershipValidator *group.MembershipValidator, | ||
inactivityClaim *inactivity.Claim, | ||
) error { | ||
return inactivity.Publish( | ||
ctx, | ||
inactivityLogger, | ||
seed.Text(16), | ||
memberIndex, | ||
broadcastChannel, | ||
groupSize, | ||
dishonestThreshold, | ||
membershipValidator, | ||
newInactivityClaimSigner(oin.chain), | ||
newInactivityClaimSubmitter(), | ||
inactivityClaim, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package tbtc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/keep-network/keep-core/pkg/protocol/group" | ||
"github.com/keep-network/keep-core/pkg/tecdsa/inactivity" | ||
) | ||
|
||
// inactivityClaimSigner is responsible for signing the inactivity claim and | ||
// verification of signatures generated by other group members. | ||
type inactivityClaimSigner struct { | ||
chain Chain | ||
} | ||
|
||
func newInactivityClaimSigner( | ||
chain Chain, | ||
) *inactivityClaimSigner { | ||
return &inactivityClaimSigner{ | ||
chain: chain, | ||
} | ||
} | ||
|
||
func (ics *inactivityClaimSigner) SignClaim(claim *inactivity.Claim) ( | ||
*inactivity.SignedClaim, | ||
error, | ||
) { | ||
if claim == nil { | ||
return nil, fmt.Errorf("result is nil") | ||
} | ||
|
||
claimHash, err := ics.chain.CalculateInactivityClaimSignatureHash( | ||
claim.Nonce, | ||
claim.WalletPublicKey, | ||
claim.InactiveMembersIndexes, | ||
claim.HeartbeatFailed, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"inactivity claim hash calculation failed [%w]", | ||
err, | ||
) | ||
} | ||
|
||
signing := ics.chain.Signing() | ||
|
||
signature, err := signing.Sign(claimHash[:]) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"inactivity claim hash signing failed [%w]", | ||
err, | ||
) | ||
} | ||
|
||
return &inactivity.SignedClaim{ | ||
PublicKey: signing.PublicKey(), | ||
Signature: signature, | ||
ClaimHash: claimHash, | ||
}, nil | ||
} | ||
|
||
// VerifySignature verifies if the signature was generated from the provided | ||
// inactivity claim using the provided public key. | ||
func (ics *inactivityClaimSigner) VerifySignature( | ||
signedClaim *inactivity.SignedClaim, | ||
) ( | ||
bool, | ||
error, | ||
) { | ||
return ics.chain.Signing().VerifyWithPublicKey( | ||
signedClaim.ClaimHash[:], | ||
signedClaim.Signature, | ||
signedClaim.PublicKey, | ||
) | ||
} | ||
|
||
type inactivityClaimSubmitter struct { | ||
// TODO: Implement | ||
} | ||
|
||
func newInactivityClaimSubmitter() *inactivityClaimSubmitter { | ||
// TODO: Implement | ||
return &inactivityClaimSubmitter{} | ||
} | ||
|
||
func (ics *inactivityClaimSubmitter) SubmitClaim( | ||
ctx context.Context, | ||
memberIndex group.MemberIndex, | ||
claim *inactivity.Claim, | ||
signatures map[group.MemberIndex][]byte, | ||
) error { | ||
// TODO: Implement | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.