-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement session keys * implement cosmos for sk * fix merge * fix merge * refactor * addres pr comments * addres pr comments
- Loading branch information
1 parent
cb0cc3c
commit 65e25e0
Showing
18 changed files
with
635 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/crypto/ecies" | ||
"github.com/ten-protocol/go-ten/go/common/viewingkey" | ||
"golang.org/x/exp/maps" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// GWSessionKey - an account key-pair registered for a user | ||
type GWSessionKey struct { | ||
Account *GWAccount | ||
PrivateKey *ecies.PrivateKey // the private key corresponding to the account | ||
} | ||
|
||
type GWAccount struct { | ||
User *GWUser | ||
Address *common.Address | ||
Signature []byte | ||
Signature []byte // the signature by the account over the userId - which is derived from the VK | ||
SignatureType viewingkey.SignatureType | ||
} | ||
|
||
type GWUser struct { | ||
UserID []byte | ||
Accounts map[common.Address]*GWAccount | ||
UserKey []byte | ||
ID []byte | ||
Accounts map[common.Address]*GWAccount | ||
UserKey []byte | ||
SessionKey *GWSessionKey | ||
ActiveSK bool // the session key is active, and it must be used to sign all incoming transactions, and used as the preferred account | ||
} | ||
|
||
func (u GWUser) AllAccounts() map[common.Address]*GWAccount { | ||
res := maps.Clone(u.Accounts) | ||
if u.SessionKey != nil { | ||
res[*u.SessionKey.Account.Address] = u.SessionKey.Account | ||
} | ||
return res | ||
} | ||
|
||
func (u GWUser) GetAllAddresses() []common.Address { | ||
return maps.Keys(u.Accounts) | ||
return maps.Keys(u.AllAccounts()) | ||
} |
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
Oops, something went wrong.