Refactor from crypto.SigType to types.KeyType
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
6a232e7214
commit
2b21fdef33
@ -229,7 +229,9 @@ type FullNode interface {
|
|||||||
// MethodGroup: Wallet
|
// MethodGroup: Wallet
|
||||||
|
|
||||||
// WalletNew creates a new address in the wallet with the given sigType.
|
// WalletNew creates a new address in the wallet with the given sigType.
|
||||||
WalletNew(context.Context, crypto.SigType) (address.Address, error)
|
// Available key types: bls, secp256k1, secp256k1-ledger
|
||||||
|
// Support for numerical types: 1 - secp256k1, 2 - BLS is deprecated
|
||||||
|
WalletNew(context.Context, types.KeyType) (address.Address, error)
|
||||||
// WalletHas indicates whether the given address is in the wallet.
|
// WalletHas indicates whether the given address is in the wallet.
|
||||||
WalletHas(context.Context, address.Address) (bool, error)
|
WalletHas(context.Context, address.Address) (bool, error)
|
||||||
// WalletList lists all the addresses in the wallet.
|
// WalletList lists all the addresses in the wallet.
|
||||||
|
@ -35,7 +35,7 @@ type MsgMeta struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WalletAPI interface {
|
type WalletAPI interface {
|
||||||
WalletNew(context.Context, crypto.SigType) (address.Address, error)
|
WalletNew(context.Context, types.KeyType) (address.Address, error)
|
||||||
WalletHas(context.Context, address.Address) (bool, error)
|
WalletHas(context.Context, address.Address) (bool, error)
|
||||||
WalletList(context.Context) ([]address.Address, error)
|
WalletList(context.Context) ([]address.Address, error)
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ type FullNodeStruct struct {
|
|||||||
MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"`
|
MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"`
|
||||||
MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"`
|
MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"`
|
||||||
|
|
||||||
WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"`
|
WalletNew func(context.Context, types.KeyType) (address.Address, error) `perm:"write"`
|
||||||
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
|
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
|
||||||
WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
|
WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
|
||||||
WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"`
|
WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"`
|
||||||
@ -384,7 +384,7 @@ type GatewayStruct struct {
|
|||||||
|
|
||||||
type WalletStruct struct {
|
type WalletStruct struct {
|
||||||
Internal struct {
|
Internal struct {
|
||||||
WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"`
|
WalletNew func(context.Context, types.KeyType) (address.Address, error) `perm:"write"`
|
||||||
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
|
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
|
||||||
WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
|
WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
|
||||||
WalletSign func(context.Context, address.Address, []byte, api.MsgMeta) (*crypto.Signature, error) `perm:"sign"`
|
WalletSign func(context.Context, address.Address, []byte, api.MsgMeta) (*crypto.Signature, error) `perm:"sign"`
|
||||||
@ -631,7 +631,7 @@ func (c *FullNodeStruct) ChainGetTipSetByHeight(ctx context.Context, h abi.Chain
|
|||||||
return c.Internal.ChainGetTipSetByHeight(ctx, h, tsk)
|
return c.Internal.ChainGetTipSetByHeight(ctx, h, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) WalletNew(ctx context.Context, typ crypto.SigType) (address.Address, error) {
|
func (c *FullNodeStruct) WalletNew(ctx context.Context, typ types.KeyType) (address.Address, error) {
|
||||||
return c.Internal.WalletNew(ctx, typ)
|
return c.Internal.WalletNew(ctx, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1465,7 +1465,7 @@ func (g GatewayStruct) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence
|
|||||||
return g.Internal.StateWaitMsg(ctx, msg, confidence)
|
return g.Internal.StateWaitMsg(ctx, msg, confidence)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WalletStruct) WalletNew(ctx context.Context, typ crypto.SigType) (address.Address, error) {
|
func (c *WalletStruct) WalletNew(ctx context.Context, typ types.KeyType) (address.Address, error) {
|
||||||
return c.Internal.WalletNew(ctx, typ)
|
return c.Internal.WalletNew(ctx, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ func init() {
|
|||||||
addExample(abi.RegisteredPoStProof_StackedDrgWindow32GiBV1)
|
addExample(abi.RegisteredPoStProof_StackedDrgWindow32GiBV1)
|
||||||
addExample(abi.ChainEpoch(10101))
|
addExample(abi.ChainEpoch(10101))
|
||||||
addExample(crypto.SigTypeBLS)
|
addExample(crypto.SigTypeBLS)
|
||||||
|
addExample(types.KTBLS)
|
||||||
addExample(int64(9))
|
addExample(int64(9))
|
||||||
addExample(12.3)
|
addExample(12.3)
|
||||||
addExample(123)
|
addExample(123)
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/events"
|
"github.com/filecoin-project/lotus/chain/events"
|
||||||
"github.com/filecoin-project/lotus/chain/events/state"
|
"github.com/filecoin-project/lotus/chain/events/state"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
@ -58,7 +57,7 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
bm.MineBlocks()
|
bm.MineBlocks()
|
||||||
|
|
||||||
// send some funds to register the receiver
|
// send some funds to register the receiver
|
||||||
receiverAddr, err := paymentReceiver.WalletNew(ctx, wallet.ActSigType("secp256k1"))
|
receiverAddr, err := paymentReceiver.WalletNew(ctx, types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -155,14 +155,14 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
|
|||||||
return nil, xerrors.Errorf("creating memrepo wallet failed: %w", err)
|
return nil, xerrors.Errorf("creating memrepo wallet failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
banker, err := w.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
banker, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to generate banker key: %w", err)
|
return nil, xerrors.Errorf("failed to generate banker key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
receievers := make([]address.Address, msgsPerBlock)
|
receievers := make([]address.Address, msgsPerBlock)
|
||||||
for r := range receievers {
|
for r := range receievers {
|
||||||
receievers[r], err = w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
receievers[r], err = w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to generate receiver key: %w", err)
|
return nil, xerrors.Errorf("failed to generate receiver key: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/types/mock"
|
"github.com/filecoin-project/lotus/chain/types/mock"
|
||||||
@ -232,7 +231,7 @@ func TestMessagePool(t *testing.T) {
|
|||||||
|
|
||||||
a := tma.nextBlock()
|
a := tma.nextBlock()
|
||||||
|
|
||||||
sender, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
sender, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -273,7 +272,7 @@ func TestMessagePoolMessagesInEachBlock(t *testing.T) {
|
|||||||
|
|
||||||
a := tma.nextBlock()
|
a := tma.nextBlock()
|
||||||
|
|
||||||
sender, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -323,7 +322,7 @@ func TestRevertMessages(t *testing.T) {
|
|||||||
a := tma.nextBlock()
|
a := tma.nextBlock()
|
||||||
b := tma.nextBlock()
|
b := tma.nextBlock()
|
||||||
|
|
||||||
sender, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -386,7 +385,7 @@ func TestPruningSimple(t *testing.T) {
|
|||||||
a := tma.nextBlock()
|
a := tma.nextBlock()
|
||||||
tma.applyBlock(t, a)
|
tma.applyBlock(t, a)
|
||||||
|
|
||||||
sender, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -433,7 +432,7 @@ func TestLoadLocal(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -443,7 +442,7 @@ func TestLoadLocal(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -505,7 +504,7 @@ func TestClearAll(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -515,7 +514,7 @@ func TestClearAll(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -559,7 +558,7 @@ func TestClearNonLocal(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -569,7 +568,7 @@ func TestClearNonLocal(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -620,7 +619,7 @@ func TestUpdates(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -630,7 +629,7 @@ func TestUpdates(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
@ -33,7 +33,7 @@ func TestRepubMessages(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ func TestRepubMessages(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -77,7 +76,7 @@ func TestMessageChains(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -87,7 +86,7 @@ func TestMessageChains(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -315,7 +314,7 @@ func TestMessageChainSkipping(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -325,7 +324,7 @@ func TestMessageChainSkipping(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -391,7 +390,7 @@ func TestBasicMessageSelection(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -401,7 +400,7 @@ func TestBasicMessageSelection(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -535,7 +534,7 @@ func TestMessageSelectionTrimming(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -545,7 +544,7 @@ func TestMessageSelectionTrimming(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -598,7 +597,7 @@ func TestPriorityMessageSelection(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -608,7 +607,7 @@ func TestPriorityMessageSelection(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -677,7 +676,7 @@ func TestPriorityMessageSelection2(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -687,7 +686,7 @@ func TestPriorityMessageSelection2(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -746,7 +745,7 @@ func TestPriorityMessageSelection3(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -756,7 +755,7 @@ func TestPriorityMessageSelection3(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -843,7 +842,7 @@ func TestOptimalMessageSelection1(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -853,7 +852,7 @@ func TestOptimalMessageSelection1(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -910,7 +909,7 @@ func TestOptimalMessageSelection2(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a1, err := w1.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -920,7 +919,7 @@ func TestOptimalMessageSelection2(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a2, err := w2.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -994,7 +993,7 @@ func TestOptimalMessageSelection3(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := w.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1074,7 +1073,7 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand, getPremium fu
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := w.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1344,7 +1343,7 @@ readLoop:
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := w.WalletNew(context.Background(), crypto.SigTypeSecp256k1)
|
a, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
ds_sync "github.com/ipfs/go-datastore/sync"
|
ds_sync "github.com/ipfs/go-datastore/sync"
|
||||||
@ -47,13 +46,13 @@ func TestMessageSignerSignMessage(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||||
from1, err := w.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
from1, err := w.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
from2, err := w.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
from2, err := w.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
to1, err := w.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
to1, err := w.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
to2, err := w.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
to2, err := w.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
type msgSpec struct {
|
type msgSpec struct {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -9,9 +12,50 @@ var (
|
|||||||
ErrKeyExists = fmt.Errorf("key already exists")
|
ErrKeyExists = fmt.Errorf("key already exists")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// KeyType defines a type of a key
|
||||||
|
type KeyType string
|
||||||
|
|
||||||
|
func (kt *KeyType) UnmarshalJSON(bb []byte) error {
|
||||||
|
{
|
||||||
|
// first option, try unmarshaling as string
|
||||||
|
var s string
|
||||||
|
err := json.Unmarshal(bb, &s)
|
||||||
|
if err == nil {
|
||||||
|
*kt = KeyType(s)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
var b byte
|
||||||
|
err := json.Unmarshal(bb, &b)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal KeyType either as string nor integer: %w", err)
|
||||||
|
}
|
||||||
|
bst := crypto.SigType(b)
|
||||||
|
|
||||||
|
switch bst {
|
||||||
|
case crypto.SigTypeBLS:
|
||||||
|
*kt = KTBLS
|
||||||
|
case crypto.SigTypeSecp256k1:
|
||||||
|
*kt = KTSecp256k1
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown sigtype: %d", bst)
|
||||||
|
}
|
||||||
|
log.Warnf("deprecation: integer style 'KeyType' is deprecated, switch to string style")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
KTBLS KeyType = "bls"
|
||||||
|
KTSecp256k1 KeyType = "secp256k1"
|
||||||
|
KTSecp256k1Ledger KeyType = "secp256k1-ledger"
|
||||||
|
)
|
||||||
|
|
||||||
// KeyInfo is used for storing keys in KeyStore
|
// KeyInfo is used for storing keys in KeyStore
|
||||||
type KeyInfo struct {
|
type KeyInfo struct {
|
||||||
Type string
|
Type KeyType
|
||||||
PrivateKey []byte
|
PrivateKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
"github.com/filecoin-project/lotus/chain/gen"
|
"github.com/filecoin-project/lotus/chain/gen"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -62,7 +61,7 @@ func MakeMessageSigningVectors() []vectors.MessageSigningVector {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blsk, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
blsk, err := w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -86,7 +85,7 @@ func MakeMessageSigningVectors() []vectors.MessageSigningVector {
|
|||||||
Signature: &bmsg.Signature,
|
Signature: &bmsg.Signature,
|
||||||
}
|
}
|
||||||
|
|
||||||
secpk, err := w.WalletNew(context.Background(), crypto.SigTypeBLS)
|
secpk, err := w.WalletNew(context.Background(), types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,17 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/lib/sigs"
|
"github.com/filecoin-project/lotus/lib/sigs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateKey(typ crypto.SigType) (*Key, error) {
|
func GenerateKey(typ types.KeyType) (*Key, error) {
|
||||||
pk, err := sigs.Generate(typ)
|
ctyp := ActSigType(typ)
|
||||||
|
if ctyp == crypto.SigTypeUnknown {
|
||||||
|
return nil, xerrors.Errorf("unknown key type: %s", typ)
|
||||||
|
}
|
||||||
|
pk, err := sigs.Generate(ctyp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ki := types.KeyInfo{
|
ki := types.KeyInfo{
|
||||||
Type: kstoreSigType(typ),
|
Type: typ,
|
||||||
PrivateKey: pk,
|
PrivateKey: pk,
|
||||||
}
|
}
|
||||||
return NewKey(ki)
|
return NewKey(ki)
|
||||||
@ -41,41 +45,41 @@ func NewKey(keyinfo types.KeyInfo) (*Key, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch k.Type {
|
switch k.Type {
|
||||||
case KTSecp256k1:
|
case types.KTSecp256k1:
|
||||||
k.Address, err = address.NewSecp256k1Address(k.PublicKey)
|
k.Address, err = address.NewSecp256k1Address(k.PublicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("converting Secp256k1 to address: %w", err)
|
return nil, xerrors.Errorf("converting Secp256k1 to address: %w", err)
|
||||||
}
|
}
|
||||||
case KTBLS:
|
case types.KTBLS:
|
||||||
k.Address, err = address.NewBLSAddress(k.PublicKey)
|
k.Address, err = address.NewBLSAddress(k.PublicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("converting BLS to address: %w", err)
|
return nil, xerrors.Errorf("converting BLS to address: %w", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, xerrors.Errorf("unknown key type")
|
return nil, xerrors.Errorf("unknown key type: %s", k.Type)
|
||||||
}
|
}
|
||||||
return k, nil
|
return k, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func kstoreSigType(typ crypto.SigType) string {
|
func kstoreSigType(typ crypto.SigType) types.KeyType {
|
||||||
switch typ {
|
switch typ {
|
||||||
case crypto.SigTypeBLS:
|
case crypto.SigTypeBLS:
|
||||||
return KTBLS
|
return types.KTBLS
|
||||||
case crypto.SigTypeSecp256k1:
|
case crypto.SigTypeSecp256k1:
|
||||||
return KTSecp256k1
|
return types.KTSecp256k1
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActSigType(typ string) crypto.SigType {
|
func ActSigType(typ types.KeyType) crypto.SigType {
|
||||||
switch typ {
|
switch typ {
|
||||||
case KTBLS:
|
case types.KTBLS:
|
||||||
return crypto.SigTypeBLS
|
return crypto.SigTypeBLS
|
||||||
case KTSecp256k1:
|
case types.KTSecp256k1:
|
||||||
return crypto.SigTypeSecp256k1
|
return crypto.SigTypeSecp256k1
|
||||||
default:
|
default:
|
||||||
return 0
|
return crypto.SigTypeUnknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func (lw LedgerWallet) WalletList(ctx context.Context) ([]address.Address, error
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lw LedgerWallet) WalletNew(ctx context.Context, t crypto.SigType) (address.Address, error) {
|
func (lw LedgerWallet) WalletNew(ctx context.Context, t types.KeyType) (address.Address, error) {
|
||||||
return address.Undef, fmt.Errorf("cannot create new address on ledger")
|
return address.Undef, fmt.Errorf("cannot create new address on ledger")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
type MultiWallet struct {
|
type MultiWallet struct {
|
||||||
fx.In // "constructed" with fx.In instead of normal constructor
|
fx.In // "constructed" with fx.In instead of normal constructor
|
||||||
|
|
||||||
Local *LocalWallet `optional:"true"`
|
Local *LocalWallet `optional:"true"`
|
||||||
Remote *remotewallet.RemoteWallet `optional:"true"`
|
Remote *remotewallet.RemoteWallet `optional:"true"`
|
||||||
Ledger *ledgerwallet.LedgerWallet `optional:"true"`
|
Ledger *ledgerwallet.LedgerWallet `optional:"true"`
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ func (m MultiWallet) find(ctx context.Context, address address.Address, wallets
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MultiWallet) WalletNew(ctx context.Context, sigType crypto.SigType) (address.Address, error) {
|
func (m MultiWallet) WalletNew(ctx context.Context, sigType types.KeyType) (address.Address, error) {
|
||||||
w := firstNonNil(m.Remote, m.Local)
|
w := firstNonNil(m.Remote, m.Local)
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return address.Undef, xerrors.Errorf("no wallet backends configured")
|
return address.Undef, xerrors.Errorf("no wallet backends configured")
|
||||||
@ -133,7 +133,12 @@ func (m MultiWallet) WalletExport(ctx context.Context, address address.Address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m MultiWallet) WalletImport(ctx context.Context, info *types.KeyInfo) (address.Address, error) {
|
func (m MultiWallet) WalletImport(ctx context.Context, info *types.KeyInfo) (address.Address, error) {
|
||||||
w := firstNonNil(m.Remote, m.Ledger, m.Local)
|
var local getif = m.Local
|
||||||
|
if info.Type == types.KTSecp256k1Ledger {
|
||||||
|
local = m.Ledger
|
||||||
|
}
|
||||||
|
|
||||||
|
w := firstNonNil(m.Remote, local)
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return address.Undef, xerrors.Errorf("no wallet backends configured")
|
return address.Undef, xerrors.Errorf("no wallet backends configured")
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@ const (
|
|||||||
KNamePrefix = "wallet-"
|
KNamePrefix = "wallet-"
|
||||||
KTrashPrefix = "trash-"
|
KTrashPrefix = "trash-"
|
||||||
KDefault = "default"
|
KDefault = "default"
|
||||||
KTBLS = "bls"
|
|
||||||
KTSecp256k1 = "secp256k1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LocalWallet struct {
|
type LocalWallet struct {
|
||||||
@ -236,7 +234,7 @@ func (w *LocalWallet) SetDefault(a address.Address) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *LocalWallet) WalletNew(ctx context.Context, typ crypto.SigType) (address.Address, error) {
|
func (w *LocalWallet) WalletNew(ctx context.Context, typ types.KeyType) (address.Address, error) {
|
||||||
w.lk.Lock()
|
w.lk.Lock()
|
||||||
defer w.lk.Unlock()
|
defer w.lk.Unlock()
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/events"
|
"github.com/filecoin-project/lotus/chain/events"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
|
||||||
builder "github.com/filecoin-project/lotus/node/test"
|
builder "github.com/filecoin-project/lotus/node/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -415,7 +414,7 @@ func startTwoNodesOneMiner(ctx context.Context, t *testing.T, blocktime time.Dur
|
|||||||
bm.MineBlocks()
|
bm.MineBlocks()
|
||||||
|
|
||||||
// Send some funds to register the receiver
|
// Send some funds to register the receiver
|
||||||
receiverAddr, err := paymentReceiver.WalletNew(ctx, wallet.ActSigType("secp256k1"))
|
receiverAddr, err := paymentReceiver.WalletNew(ctx, types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
|
|
||||||
types "github.com/filecoin-project/lotus/chain/types"
|
types "github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
|
||||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ var walletNew = &cli.Command{
|
|||||||
t = "secp256k1"
|
t = "secp256k1"
|
||||||
}
|
}
|
||||||
|
|
||||||
nk, err := api.WalletNew(ctx, wallet.ActSigType(t))
|
nk, err := api.WalletNew(ctx, types.KeyType(t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -329,9 +328,9 @@ var walletImport = &cli.Command{
|
|||||||
ki.PrivateKey = gk.PrivateKey
|
ki.PrivateKey = gk.PrivateKey
|
||||||
switch gk.SigType {
|
switch gk.SigType {
|
||||||
case 1:
|
case 1:
|
||||||
ki.Type = wallet.KTSecp256k1
|
ki.Type = types.KTSecp256k1
|
||||||
case 2:
|
case 2:
|
||||||
ki.Type = wallet.KTBLS
|
ki.Type = types.KTBLS
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized key type: %d", gk.SigType)
|
return fmt.Errorf("unrecognized key type: %d", gk.SigType)
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
@ -61,7 +59,7 @@ var runCmd = &cli.Command{
|
|||||||
func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Address, rate int) error {
|
func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Address, rate int) error {
|
||||||
var sendSet []address.Address
|
var sendSet []address.Address
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
naddr, err := api.WalletNew(ctx, crypto.SigTypeSecp256k1)
|
naddr, err := api.WalletNew(ctx, types.KTSecp256k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/api/test"
|
"github.com/filecoin-project/lotus/api/test"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
|
||||||
"github.com/filecoin-project/lotus/node"
|
"github.com/filecoin-project/lotus/node"
|
||||||
builder "github.com/filecoin-project/lotus/node/test"
|
builder "github.com/filecoin-project/lotus/node/test"
|
||||||
)
|
)
|
||||||
@ -53,7 +52,7 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
fmt.Println(balance)
|
fmt.Println(balance)
|
||||||
|
|
||||||
// Create a wallet on the lite node
|
// Create a wallet on the lite node
|
||||||
liteWalletAddr, err := lite.WalletNew(ctx, wallet.ActSigType("secp256k1"))
|
liteWalletAddr, err := lite.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Send some funds from the full node to the lite node
|
// Send some funds from the full node to the lite node
|
||||||
@ -77,7 +76,7 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
// Create some wallets on the lite node to use for testing multisig
|
// Create some wallets on the lite node to use for testing multisig
|
||||||
var walletAddrs []address.Address
|
var walletAddrs []address.Address
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
addr, err := lite.WalletNew(ctx, wallet.ActSigType("secp256k1"))
|
addr, err := lite.WalletNew(ctx, types.KTSecp256k1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
walletAddrs = append(walletAddrs, addr)
|
walletAddrs = append(walletAddrs, addr)
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||||
@ -30,12 +30,12 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var kt crypto.SigType
|
var kt types.KeyType
|
||||||
switch cctx.String("type") {
|
switch cctx.String("type") {
|
||||||
case "bls":
|
case "bls":
|
||||||
kt = crypto.SigTypeBLS
|
kt = types.KTBLS
|
||||||
case "secp256k1":
|
case "secp256k1":
|
||||||
kt = crypto.SigTypeSecp256k1
|
kt = types.KTSecp256k1
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized key type: %q", cctx.String("type"))
|
return fmt.Errorf("unrecognized key type: %q", cctx.String("type"))
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/zerocomm"
|
"github.com/filecoin-project/lotus/extern/sector-storage/zerocomm"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
minerAddr, err = wallet.GenerateKey(crypto.SigTypeBLS)
|
minerAddr, err = wallet.GenerateKey(types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ import (
|
|||||||
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var validTypes = []string{wallet.KTBLS, wallet.KTSecp256k1, lp2p.KTLibp2pHost}
|
var validTypes = []types.KeyType{types.KTBLS, types.KTSecp256k1, lp2p.KTLibp2pHost}
|
||||||
|
|
||||||
type keyInfoOutput struct {
|
type keyInfoOutput struct {
|
||||||
Type string
|
Type types.KeyType
|
||||||
Address string
|
Address string
|
||||||
PublicKey string
|
PublicKey string
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ var keyinfoVerifyCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("decoding key: '%s': %w", fileName, err)
|
return xerrors.Errorf("decoding key: '%s': %w", fileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(name) != keyInfo.Type {
|
if types.KeyType(name) != keyInfo.Type {
|
||||||
return fmt.Errorf("%s of type %s is incorrect", fileName, keyInfo.Type)
|
return fmt.Errorf("%s of type %s is incorrect", fileName, keyInfo.Type)
|
||||||
}
|
}
|
||||||
case modules.KTJwtHmacSecret:
|
case modules.KTJwtHmacSecret:
|
||||||
@ -98,7 +98,7 @@ var keyinfoVerifyCmd = &cli.Command{
|
|||||||
if string(name) != modules.JWTSecretName {
|
if string(name) != modules.JWTSecretName {
|
||||||
return fmt.Errorf("%s of type %s is incorrect", fileName, keyInfo.Type)
|
return fmt.Errorf("%s of type %s is incorrect", fileName, keyInfo.Type)
|
||||||
}
|
}
|
||||||
case wallet.KTSecp256k1, wallet.KTBLS:
|
case types.KTSecp256k1, types.KTBLS:
|
||||||
keystore := wallet.NewMemKeyStore()
|
keystore := wallet.NewMemKeyStore()
|
||||||
w, err := wallet.NewWallet(keystore)
|
w, err := wallet.NewWallet(keystore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,7 +214,7 @@ var keyinfoImportCmd = &cli.Command{
|
|||||||
fmt.Printf("%s\n", peerid.String())
|
fmt.Printf("%s\n", peerid.String())
|
||||||
|
|
||||||
break
|
break
|
||||||
case wallet.KTSecp256k1, wallet.KTBLS:
|
case types.KTSecp256k1, types.KTBLS:
|
||||||
w, err := wallet.NewWallet(keystore)
|
w, err := wallet.NewWallet(keystore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -317,7 +317,7 @@ var keyinfoInfoCmd = &cli.Command{
|
|||||||
kio.PublicKey = base64.StdEncoding.EncodeToString(pkBytes)
|
kio.PublicKey = base64.StdEncoding.EncodeToString(pkBytes)
|
||||||
|
|
||||||
break
|
break
|
||||||
case wallet.KTSecp256k1, wallet.KTBLS:
|
case types.KTSecp256k1, types.KTBLS:
|
||||||
kio.Type = keyInfo.Type
|
kio.Type = keyInfo.Type
|
||||||
|
|
||||||
key, err := wallet.NewKey(keyInfo)
|
key, err := wallet.NewKey(keyInfo)
|
||||||
@ -366,7 +366,7 @@ var keyinfoNewCmd = &cli.Command{
|
|||||||
return fmt.Errorf("please specify a type to generate")
|
return fmt.Errorf("please specify a type to generate")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyType := cctx.Args().First()
|
keyType := types.KeyType(cctx.Args().First())
|
||||||
flagOutput := cctx.String("output")
|
flagOutput := cctx.String("output")
|
||||||
|
|
||||||
if i := SliceIndex(len(validTypes), func(i int) bool {
|
if i := SliceIndex(len(validTypes), func(i int) bool {
|
||||||
@ -404,8 +404,8 @@ var keyinfoNewCmd = &cli.Command{
|
|||||||
keyInfo = ki
|
keyInfo = ki
|
||||||
|
|
||||||
break
|
break
|
||||||
case wallet.KTSecp256k1, wallet.KTBLS:
|
case types.KTSecp256k1, types.KTBLS:
|
||||||
key, err := wallet.GenerateKey(wallet.ActSigType(keyType))
|
key, err := wallet.GenerateKey(keyType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ var keyinfoNewCmd = &cli.Command{
|
|||||||
|
|
||||||
filename := flagOutput
|
filename := flagOutput
|
||||||
filename = strings.ReplaceAll(filename, "<addr>", keyAddr)
|
filename = strings.ReplaceAll(filename, "<addr>", keyAddr)
|
||||||
filename = strings.ReplaceAll(filename, "<type>", keyType)
|
filename = strings.ReplaceAll(filename, "<type>", string(keyType))
|
||||||
|
|
||||||
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
|
||||||
ledgerwallet "github.com/filecoin-project/lotus/chain/wallet/ledger"
|
ledgerwallet "github.com/filecoin-project/lotus/chain/wallet/ledger"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
)
|
)
|
||||||
@ -191,7 +190,7 @@ var ledgerKeyInfoCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ki types.KeyInfo
|
var ki types.KeyInfo
|
||||||
ki.Type = wallet.KTSecp256k1
|
ki.Type = types.KTSecp256k1Ledger
|
||||||
ki.PrivateKey = b
|
ki.PrivateKey = b
|
||||||
|
|
||||||
out, err := json.Marshal(ki)
|
out, err := json.Marshal(ki)
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
crypto2 "github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||||
@ -624,7 +623,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID,
|
|||||||
if cctx.String("worker") != "" {
|
if cctx.String("worker") != "" {
|
||||||
worker, err = address.NewFromString(cctx.String("worker"))
|
worker, err = address.NewFromString(cctx.String("worker"))
|
||||||
} else if cctx.Bool("create-worker-key") { // TODO: Do we need to force this if owner is Secpk?
|
} else if cctx.Bool("create-worker-key") { // TODO: Do we need to force this if owner is Secpk?
|
||||||
worker, err = api.WalletNew(ctx, crypto2.SigTypeBLS)
|
worker, err = api.WalletNew(ctx, types.KTBLS)
|
||||||
}
|
}
|
||||||
// TODO: Transfer some initial funds to worker
|
// TODO: Transfer some initial funds to worker
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,13 +19,8 @@ type LoggedWallet struct {
|
|||||||
under api.WalletAPI
|
under api.WalletAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LoggedWallet) WalletNew(ctx context.Context, typ crypto.SigType) (address.Address, error) {
|
func (c *LoggedWallet) WalletNew(ctx context.Context, typ types.KeyType) (address.Address, error) {
|
||||||
n, err := typ.Name()
|
log.Infow("WalletNew", "type", typ)
|
||||||
if err != nil {
|
|
||||||
return address.Address{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infow("WalletNew", "type", n)
|
|
||||||
|
|
||||||
return c.under.WalletNew(ctx, typ)
|
return c.under.WalletNew(ctx, typ)
|
||||||
}
|
}
|
||||||
|
@ -101,19 +101,22 @@ var runCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var w api.WalletAPI
|
lw, err := wallet.NewWallet(ks)
|
||||||
if !cctx.Bool("ledger") {
|
if err != nil {
|
||||||
w, err = wallet.NewWallet(ks)
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
var w api.WalletAPI = lw
|
||||||
} else {
|
if cctx.Bool("ledger") {
|
||||||
ds, err := lr.Datastore("/metadata")
|
ds, err := lr.Datastore("/metadata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
w = ledgerwallet.NewWallet(ds)
|
w = wallet.MultiWallet{
|
||||||
|
Local: lw,
|
||||||
|
Ledger: ledgerwallet.NewWallet(ds),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
address := cctx.String("listen")
|
address := cctx.String("listen")
|
||||||
|
@ -4710,7 +4710,7 @@ Inputs:
|
|||||||
Response:
|
Response:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"Type": "string value",
|
"Type": "bls",
|
||||||
"PrivateKey": "Ynl0ZSBhcnJheQ=="
|
"PrivateKey": "Ynl0ZSBhcnJheQ=="
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -4740,7 +4740,7 @@ Inputs:
|
|||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"Type": "string value",
|
"Type": "bls",
|
||||||
"PrivateKey": "Ynl0ZSBhcnJheQ=="
|
"PrivateKey": "Ynl0ZSBhcnJheQ=="
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -4760,6 +4760,8 @@ Response: `null`
|
|||||||
|
|
||||||
### WalletNew
|
### WalletNew
|
||||||
WalletNew creates a new address in the wallet with the given sigType.
|
WalletNew creates a new address in the wallet with the given sigType.
|
||||||
|
Available key types: bls, secp256k1, secp256k1-ledger
|
||||||
|
Support for numerical types: 1 - secp256k1, 2 - BLS is deprecated
|
||||||
|
|
||||||
|
|
||||||
Perms: write
|
Perms: write
|
||||||
@ -4767,7 +4769,7 @@ Perms: write
|
|||||||
Inputs:
|
Inputs:
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
2
|
"bls"
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
var log = logging.Logger("p2pnode")
|
var log = logging.Logger("p2pnode")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KLibp2pHost = "libp2p-host"
|
KLibp2pHost = "libp2p-host"
|
||||||
KTLibp2pHost = KLibp2pHost
|
KTLibp2pHost types.KeyType = KLibp2pHost
|
||||||
)
|
)
|
||||||
|
|
||||||
type Libp2pOpts struct {
|
type Libp2pOpts struct {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# vim: set expandtab ts=2 sw=2:
|
# vim: set expandtab ts=2 sw=2:
|
||||||
|
|
||||||
token=$(lotus auth create-token --perm admin)
|
_lotus_token=$(./lotus auth create-token --perm admin)
|
||||||
|
|
||||||
runAPI() {
|
runAPI() {
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data '{"jsonrpc":"2.0","id":2,"method":"Filecoin.'"$1"'","params":'"${2:-null}"'}' \
|
--data '{"jsonrpc":"2.0","id":2,"method":"Filecoin.'"$1"'","params":'"${2:-null}"'}' \
|
||||||
'http://127.0.0.1:1234/rpc/v0?token='"$token"
|
'http://127.0.0.1:1234/rpc/v0?token='"$_lotus_token"
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
||||||
|
|
||||||
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
@ -20,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
||||||
k, err := wallet.GenerateKey(crypto.SigTypeBLS)
|
k, err := wallet.GenerateKey(types.KTBLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user