-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into subnet-implementation2
Signed-off-by: sukantoraymond <[email protected]>
- Loading branch information
Showing
25 changed files
with
854 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,115 @@ | ||
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package key | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/ava-labs/avalanchego/utils/cb58" | ||
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1" | ||
) | ||
|
||
const ewoqPChainAddr = "P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p" | ||
|
||
func TestNewKeyEwoq(t *testing.T) { | ||
t.Parallel() | ||
|
||
m, err := NewSoft( | ||
WithPrivateKeyEncoded(EwoqPrivateKey), | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pAddr, err := m.P("custom") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if pAddr != ewoqPChainAddr { | ||
t.Fatalf("unexpected P-Chain address %q, expected %q", pAddr, ewoqPChainAddr) | ||
} | ||
|
||
keyPath := filepath.Join(t.TempDir(), "key.pk") | ||
if err := m.Save(keyPath); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
m2, err := LoadSoft(keyPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !bytes.Equal(m.PrivKeyRaw(), m2.PrivKeyRaw()) { | ||
t.Fatalf("loaded key unexpected %v, expected %v", m2.PrivKeyRaw(), m.PrivKeyRaw()) | ||
} | ||
} | ||
|
||
func TestNewKey(t *testing.T) { | ||
t.Parallel() | ||
|
||
skBytes, err := cb58.Decode(rawEwoqPk) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ewoqPk, err := secp256k1.ToPrivateKey(skBytes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
privKey2, err := secp256k1.NewPrivateKey() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
tt := []struct { | ||
name string | ||
opts []SOpOption | ||
expErr error | ||
}{ | ||
{ | ||
name: "test", | ||
opts: nil, | ||
expErr: nil, | ||
}, | ||
{ | ||
name: "ewop with WithPrivateKey", | ||
opts: []SOpOption{ | ||
WithPrivateKey(ewoqPk), | ||
}, | ||
expErr: nil, | ||
}, | ||
{ | ||
name: "ewop with WithPrivateKeyEncoded", | ||
opts: []SOpOption{ | ||
WithPrivateKeyEncoded(EwoqPrivateKey), | ||
}, | ||
expErr: nil, | ||
}, | ||
{ | ||
name: "ewop with WithPrivateKey/WithPrivateKeyEncoded", | ||
opts: []SOpOption{ | ||
WithPrivateKey(ewoqPk), | ||
WithPrivateKeyEncoded(EwoqPrivateKey), | ||
}, | ||
expErr: nil, | ||
}, | ||
{ | ||
name: "ewop with invalid WithPrivateKey", | ||
opts: []SOpOption{ | ||
WithPrivateKey(privKey2), | ||
WithPrivateKeyEncoded(EwoqPrivateKey), | ||
}, | ||
expErr: ErrInvalidPrivateKey, | ||
}, | ||
} | ||
for i, tv := range tt { | ||
_, err := NewSoft(tv.opts...) | ||
if !errors.Is(err, tv.expErr) { | ||
t.Fatalf("#%d(%s): unexpected error %v, expected %v", i, tv.name, err, tv.expErr) | ||
} | ||
} | ||
} |
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,78 @@ | ||
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package key | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/vms/components/avax" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/txs" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
) | ||
|
||
var _ Key = &LedgerKey{} | ||
|
||
type LedgerKey struct { | ||
index uint32 | ||
} | ||
|
||
// ledger device should be connected | ||
func NewLedger(index uint32) LedgerKey { | ||
return LedgerKey{ | ||
index: index, | ||
} | ||
} | ||
|
||
// LoadLedger loads the ledger key info from disk and creates the corresponding LedgerKey. | ||
func LoadLedger(_ string) (*LedgerKey, error) { | ||
return nil, fmt.Errorf("not implemented") | ||
} | ||
|
||
// LoadLedgerFromBytes loads the ledger key info from bytes and creates the corresponding LedgerKey. | ||
func LoadLedgerFromBytes(_ []byte) (*SoftKey, error) { | ||
return nil, fmt.Errorf("not implemented") | ||
} | ||
|
||
func (*LedgerKey) C() string { | ||
return "" | ||
} | ||
|
||
// Returns the KeyChain | ||
func (*LedgerKey) KeyChain() *secp256k1fx.Keychain { | ||
return nil | ||
} | ||
|
||
// Saves the key info to disk | ||
func (*LedgerKey) Save(_ string) error { | ||
return fmt.Errorf("not implemented") | ||
} | ||
|
||
func (*LedgerKey) P(_ string) (string, error) { | ||
return "", fmt.Errorf("not implemented") | ||
} | ||
|
||
func (*LedgerKey) X(_ string) (string, error) { | ||
return "", fmt.Errorf("not implemented") | ||
} | ||
|
||
func (*LedgerKey) Spends(_ []*avax.UTXO, _ ...OpOption) ( | ||
totalBalanceToSpend uint64, | ||
inputs []*avax.TransferableInput, | ||
signers [][]ids.ShortID, | ||
) { | ||
return 0, nil, nil | ||
} | ||
|
||
func (*LedgerKey) Addresses() []ids.ShortID { | ||
return nil | ||
} | ||
|
||
func (*LedgerKey) Sign(_ *txs.Tx, _ [][]ids.ShortID) error { | ||
return fmt.Errorf("not implemented") | ||
} | ||
|
||
func (*LedgerKey) Match(_ *secp256k1fx.OutputOwners, _ uint64) ([]uint32, []ids.ShortID, bool) { | ||
return nil, nil, false | ||
} |
Oops, something went wrong.