diff --git a/go.mod b/go.mod index fd864cf223..108e697191 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/labstack/echo/v4 v4.11.2 github.com/labstack/gommon v0.4.0 github.com/libp2p/go-libp2p v0.30.0 + github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multiaddr v0.11.0 github.com/pangpanglabs/echoswagger/v2 v2.4.1 @@ -49,6 +50,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 github.com/wasmerio/wasmer-go v1.0.4 + github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98 go.dedis.ch/kyber/v3 v3.1.0 go.uber.org/atomic v1.11.0 go.uber.org/dig v1.17.1 @@ -216,4 +218,4 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index df2bee5642..1a56782a0f 100644 --- a/go.sum +++ b/go.sum @@ -1072,4 +1072,4 @@ rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= -sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= +sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= \ No newline at end of file diff --git a/tools/wasp-cli/cli/config/config.go b/tools/wasp-cli/cli/config/config.go index 3be7e2be02..198539564f 100644 --- a/tools/wasp-cli/cli/config/config.go +++ b/tools/wasp-cli/cli/config/config.go @@ -205,6 +205,10 @@ func GetChain(name string) isc.ChainID { return chainID } +func GetUseLegacyDerivation() bool { + return viper.GetBool("wallet.useLegacyDerivation") +} + func GetWalletSchemeString() string { return viper.GetString("wallet.scheme") } diff --git a/tools/wasp-cli/cli/wallet/providers/keychain.go b/tools/wasp-cli/cli/wallet/providers/keychain.go index 8ba9838e99..fd70ebac15 100644 --- a/tools/wasp-cli/cli/wallet/providers/keychain.go +++ b/tools/wasp-cli/cli/wallet/providers/keychain.go @@ -27,7 +27,8 @@ func LoadKeyChain(addressIndex uint32) wallets.Wallet { seed, err := config.GetKeyChain().GetSeed() log.Check(err) - keyPair := cryptolib.KeyPairFromSeed(seed.SubSeed(uint64(addressIndex))) + useLegacyDerivation := config.GetUseLegacyDerivation() + keyPair := cryptolib.KeyPairFromSeed(cryptolib.SubSeed(seed[:], uint64(addressIndex), useLegacyDerivation)) return newInMemoryWallet(keyPair, addressIndex) } diff --git a/tools/wasp-cli/cli/wallet/providers/stronghold.go b/tools/wasp-cli/cli/wallet/providers/stronghold.go index 568fcd8767..d21bc9d025 100644 --- a/tools/wasp-cli/cli/wallet/providers/stronghold.go +++ b/tools/wasp-cli/cli/wallet/providers/stronghold.go @@ -73,9 +73,12 @@ func MigrateToStrongholdWallet(sdk *walletsdk.IOTASDK, seed cryptolib.Seed) { unlockPassword := cli.ReadPasswordFromStdin() log.Printf("\n") - s := seed.SubSeed(0) + useLegacyDerivation := config.GetUseLegacyDerivation() + s := cryptolib.SubSeed(seed[:], 0, useLegacyDerivation) + mnemonicStr, err := bip39.NewMnemonic(s[:]) log.Check(err) + mnemonic := memguard.NewEnclave([]byte(mnemonicStr)) createNewStrongholdWallet(sdk, mnemonic, unlockPassword) diff --git a/tools/wasp-cli/cli/wallet/wallet.go b/tools/wasp-cli/cli/wallet/wallet.go index a98c77aabc..db220a582f 100644 --- a/tools/wasp-cli/cli/wallet/wallet.go +++ b/tools/wasp-cli/cli/wallet/wallet.go @@ -96,19 +96,6 @@ func Load() wallets.Wallet { } return nil - seedHex := viper.GetString("wallet.seed") - - useLegacyDerivation := viper.GetBool("wallet.useLegacyDerivation") - if seedHex == "" { - log.Fatal("call `init` first") - } - - masterSeed, err := iotago.DecodeHex(seedHex) - log.Check(err) - - kp := cryptolib.KeyPairFromSeed(cryptolib.SubSeed(masterSeed, uint64(AddressIndex), useLegacyDerivation)) - - return &Wallet{KeyPair: kp, AddressIndex: AddressIndex} } func InitWallet() { diff --git a/tools/wasp-cli/go.mod b/tools/wasp-cli/go.mod index 243a0fcc5f..eb24ff1676 100644 --- a/tools/wasp-cli/go.mod +++ b/tools/wasp-cli/go.mod @@ -146,6 +146,7 @@ require ( github.com/miekg/dns v1.1.55 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect + github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -204,6 +205,7 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/wasmerio/wasmer-go v1.0.4 // indirect + github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.dedis.ch/fixbuf v1.0.3 // indirect go.dedis.ch/kyber/v3 v3.1.0 // indirect