diff --git a/.circleci/config.yml b/.circleci/config.yml index f5e02ec..42ff3e2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,12 +3,12 @@ jobs: build: docker: - image: golang:1.10 - working_directory: /go/src/zondax/ledger-goclient + working_directory: /go/src/zondax/ledger-cosmos-go steps: - checkout - run: go get -v -u github.com/golang/dep/cmd/dep - run: dep ensure -v - - run: go build ledger.go apduWrapper.go + - run: go build *.go - run: go test workflows: version: 2 diff --git a/common.go b/common.go index ad813d8..f5a8196 100644 --- a/common.go +++ b/common.go @@ -37,8 +37,7 @@ func getBip32bytes(bip32Path []uint32, hardenCount int) ([]byte, error) { for index, element := range bip32Path { pos := 1 + index*4 value := element - // Harden 0, 1, 2 - if index <= hardenCount { + if index < hardenCount { value = 0x80000000 | element } binary.LittleEndian.PutUint32(message[pos:], value) diff --git a/common_test.go b/common_test.go new file mode 100644 index 0000000..c5a3fcf --- /dev/null +++ b/common_test.go @@ -0,0 +1,95 @@ +/******************************************************************************* +* (c) 2018 ZondaX GmbH +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +********************************************************************************/ + +package ledger_cosmos_go + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +func Test_PathGeneration0(t *testing.T) { + bip32Path := []uint32{44, 100, 0, 0, 0} + + pathBytes, err := getBip32bytes(bip32Path, 0) + + if err != nil { + assert.FailNow(t, "Detected error, err: %s\n", err.Error()) + } + + fmt.Printf("Path: %x\n", pathBytes) + + assert.Equal( + t, + 41, + len(pathBytes), + "PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41) + + assert.Equal( + t, + "052c000000640000000000000000000000000000000000000000000000000000000000000000000000", + fmt.Sprintf("%x", pathBytes), + "Unexpected PathBytes\n") +} + +func Test_PathGeneration2(t *testing.T) { + bip32Path := []uint32{44, 118, 0, 0, 0} + + pathBytes, err := getBip32bytes(bip32Path, 2) + + if err != nil { + assert.FailNow(t, "Detected error, err: %s\n", err.Error()) + } + + fmt.Printf("Path: %x\n", pathBytes) + + assert.Equal( + t, + 41, + len(pathBytes), + "PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41) + + assert.Equal( + t, + "052c000080760000800000000000000000000000000000000000000000000000000000000000000000", + fmt.Sprintf("%x", pathBytes), + "Unexpected PathBytes\n") +} + +func Test_PathGeneration3(t *testing.T) { + bip32Path := []uint32{44, 118, 0, 0, 0} + + pathBytes, err := getBip32bytes(bip32Path, 3) + + if err != nil { + assert.FailNow(t, "Detected error, err: %s\n", err.Error()) + } + + fmt.Printf("Path: %x\n", pathBytes) + + assert.Equal( + t, + 41, + len(pathBytes), + "PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41) + + assert.Equal( + t, + "052c000080760000800000008000000000000000000000000000000000000000000000000000000000", + fmt.Sprintf("%x", pathBytes), + "Unexpected PathBytes\n") +} diff --git a/user_app_test.go b/user_app_test.go index 074f019..4d1f164 100644 --- a/user_app_test.go +++ b/user_app_test.go @@ -1,3 +1,5 @@ +// +build ledger_device + /******************************************************************************* * (c) 2018 ZondaX GmbH * @@ -41,7 +43,7 @@ func Test_UserGetVersion(t *testing.T) { assert.Equal(t, uint8(0x0), version.AppMode, "TESTING MODE ENABLED!!") assert.Equal(t, uint8(0x1), version.Major, "Wrong Major version") assert.Equal(t, uint8(0x0), version.Minor, "Wrong Minor version") - assert.Equal(t, uint8(0x0), version.Patch, "Wrong Patch version") + assert.Equal(t, uint8(0x1), version.Patch, "Wrong Patch version") } func Test_UserGetPublicKey(t *testing.T) { @@ -65,10 +67,14 @@ func Test_UserGetPublicKey(t *testing.T) { len(pubKey), "Public key has wrong length: %x, expected length: %x\n", pubKey, 65) + fmt.Printf("PUBLIC KEY: %x\n", pubKey) + _, err = secp256k1.ParsePubKey(pubKey[:], secp256k1.S256()) require.Nil(t, err, "Error parsing public key err: %s\n", err) } +// Ledger Test Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young + func getDummyTx() []byte { dummyTx := `{ "account_number": 1, diff --git a/validator_app_test.go b/validator_app_test.go index 5556355..292eb8e 100644 --- a/validator_app_test.go +++ b/validator_app_test.go @@ -1,3 +1,5 @@ +// +build ledger_device + /******************************************************************************* * (c) 2018 ZondaX GmbH *