Skip to content

Commit

Permalink
fix keystore chaintypes
Browse files Browse the repository at this point in the history
  • Loading branch information
calvwang9 committed Dec 23, 2024
1 parent 3c241fd commit 490a247
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions core/services/keystore/chaintype/chaintype.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func NewChainType(typ uint8) (ChainType, error) {
return StarkNet, nil
case 5:
return Aptos, nil
case 6:
return Tron, nil
default:
return "", fmt.Errorf("unexpected chaintype.ChainType: %#v", typ)
}
Expand All @@ -67,6 +69,8 @@ func (c ChainType) Type() (uint8, error) {
return 4, nil
case Aptos:
return 5, nil
case Tron:
return 6, nil
default:
return 0, fmt.Errorf("unexpected chaintype.ChainType: %#v", c)
}
Expand Down
2 changes: 2 additions & 0 deletions core/services/keystore/keys/ocr2key/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func FromEncryptedJSON(keyJSON []byte, password string) (KeyBundle, error) {
kb = newKeyBundle(new(starkkey.OCR2Key))
case chaintype.Aptos:
kb = newKeyBundle(new(aptosKeyring))
case chaintype.Tron:
kb = newKeyBundle(new(evmKeyring))
default:
return nil, chaintype.NewErrInvalidChainType(export.ChainType)
}
Expand Down
1 change: 1 addition & 0 deletions core/services/keystore/keys/ocr2key/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestExport(t *testing.T) {
{chain: chaintype.Solana},
{chain: chaintype.StarkNet},
{chain: chaintype.Aptos},
{chain: chaintype.Tron},
}
for _, tc := range tt {
tc := tc
Expand Down
6 changes: 6 additions & 0 deletions core/services/keystore/keys/ocr2key/key_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func New(chainType chaintype.ChainType) (KeyBundle, error) {
return newKeyBundleRand(chaintype.StarkNet, starkkey.NewOCR2Key)
case chaintype.Aptos:
return newKeyBundleRand(chaintype.Aptos, newAptosKeyring)
case chaintype.Tron:
return newKeyBundleRand(chaintype.Tron, newEVMKeyring)
}
return nil, chaintype.NewErrInvalidChainType(chainType)
}
Expand All @@ -76,6 +78,8 @@ func MustNewInsecure(reader io.Reader, chainType chaintype.ChainType) KeyBundle
return mustNewKeyBundleInsecure(chaintype.StarkNet, starkkey.NewOCR2Key, reader)
case chaintype.Aptos:
return mustNewKeyBundleInsecure(chaintype.Aptos, newAptosKeyring, reader)
case chaintype.Tron:
return mustNewKeyBundleInsecure(chaintype.Tron, newEVMKeyring, reader)
}
panic(chaintype.NewErrInvalidChainType(chainType))
}
Expand Down Expand Up @@ -126,6 +130,8 @@ func (raw Raw) Key() (kb KeyBundle) {
kb = newKeyBundle(new(starkkey.OCR2Key))
case chaintype.Aptos:
kb = newKeyBundle(new(aptosKeyring))
case chaintype.Tron:
kb = newKeyBundle(new(evmKeyring))
default:
return nil
}
Expand Down
9 changes: 1 addition & 8 deletions core/services/keystore/keys/tronkey/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ type Key struct {
}

func New() (Key, error) {
privKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
if err != nil {
return Key{}, err
}
return Key{
privKey: privKeyECDSA,
pubKey: &privKeyECDSA.PublicKey,
}, nil
return newFrom(rand.Reader)
}

// MustNewInsecure return Key if no error
Expand Down

0 comments on commit 490a247

Please sign in to comment.