Skip to content

Commit

Permalink
Migrate BIP44 additions to the keychain funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoe committed Nov 10, 2023
1 parent 90f592f commit 299a1a2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
4 changes: 4 additions & 0 deletions tools/wasp-cli/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion tools/wasp-cli/cli/wallet/providers/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion tools/wasp-cli/cli/wallet/providers/stronghold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions tools/wasp-cli/cli/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions tools/wasp-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 299a1a2

Please sign in to comment.