diff --git a/Gopkg.lock b/Gopkg.lock index 4e70658..07b4ac7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,20 +2,28 @@ [[projects]] - digest = "1:0e3c4434de19ab6378518212ae289f32a93b58fe3cbadef8d5e18c4430ade1a9" + digest = "1:b73f5e117bc7c6e8fc47128f20db48a873324ad5cfeeebfc505e85c58682b5e4" + name = "github.com/ZondaX/hid" + packages = ["."] + pruneopts = "T" + revision = "302fd402163c34626286195dfa9adac758334acc" + version = "v0.9.0" + +[[projects]] + digest = "1:312416a870d6ef9941e1ea7893480ff1e6627cc66517ce2760bf97af427d8f8c" name = "github.com/ZondaX/ledger-go" packages = ["."] pruneopts = "UT" - revision = "5271d68c0c1fa7718e5781fea56169bba82942f6" - version = "v0.5.0" + revision = "6c752dfd14666393766f120c0c3ae940b5aaa8d5" + version = "v0.6.0" [[projects]] branch = "master" - digest = "1:c0decf632843204d2b8781de7b26e7038584e2dcccc7e2f401e88ae85b1df2b7" + digest = "1:093bf93a65962e8191e3e8cd8fc6c363f83d43caca9739c906531ba7210a9904" name = "github.com/btcsuite/btcd" packages = ["btcec"] pruneopts = "UT" - revision = "67e573d211ace594f1366b4ce9d39726c4b19bd0" + revision = "ed77733ec07dfc8a513741138419b8d9d3de9d2d" [[projects]] digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" @@ -38,12 +46,12 @@ version = "v0.6.0" [[projects]] - digest = "1:31a18dae27a29aa074515e43a443abfd2ba6deb6d69309d8d7ce789c45f34659" + digest = "1:4062bc6de62d73e2be342243cf138cf499b34d558876db8d9430e2149388a4d8" name = "github.com/go-logfmt/logfmt" packages = ["."] pruneopts = "UT" - revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5" - version = "v0.3.0" + revision = "07c9b44f60d7ffdfb7d8efe1ad539965737836dc" + version = "v0.4.0" [[projects]] digest = "1:586ea76dbd0374d6fb649a91d70d652b7fe0ccffb8910a77468e7702e7901f3d" @@ -73,14 +81,6 @@ revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" version = "v1.1.0" -[[projects]] - branch = "master" - digest = "1:447562773a19dc1719359c2cd70d275c62c0b89f79d763f41d5deedb0e69873f" - name = "github.com/karalabe/hid" - packages = ["."] - pruneopts = "T" - revision = "d815e0c1a2e2082a287a2806bc90bc8fc7b276a9" - [[projects]] branch = "master" digest = "1:a64e323dc06b73892e5bb5d040ced475c4645d456038333883f58934abbf6f72" @@ -90,12 +90,12 @@ revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0" [[projects]] - digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" + digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b" name = "github.com/pkg/errors" packages = ["."] pruneopts = "UT" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" + revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" + version = "v0.8.1" [[projects]] digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" @@ -106,18 +106,18 @@ version = "v1.0.0" [[projects]] - digest = "1:c40d65817cdd41fac9aa7af8bed56927bb2d6d47e4fea566a74880f5c2b1c41e" + digest = "1:5da8ce674952566deae4dbc23d07c85caafc6cfa815b0b3e03e41979cedb8750" name = "github.com/stretchr/testify" packages = [ "assert", "require", ] pruneopts = "UT" - revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" - version = "v1.2.2" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" [[projects]] - digest = "1:19d11835d904acb49bf5f1144f7bcd5bb93f629360e6d110377ead3dbb4e2469" + digest = "1:2368474e3f263be379e783a0bdac7f5f825f844252d7e9d6efa8f27bb79ff2fb" name = "github.com/tendermint/tendermint" packages = [ "crypto", @@ -126,11 +126,11 @@ "libs/log", ] pruneopts = "UT" - revision = "22dcc92232cd04ce7381043e09d85dd536ae3b96" - version = "v0.26.3" + revision = "4d7b29cd8f8ef998cf8f7141f3a100b0a4fa718d" + version = "v0.29.1" [[projects]] - digest = "1:446c58ba05d3c14faf33e87b81b2fdf68c235e1d89259860d3eae588c8005f9c" + digest = "1:578bbe25849cdc707dfa01cd316556198df9df317fc1608fd2bbbf8967af9785" name = "golang.org/x/crypto" packages = [ "chacha20poly1305", @@ -140,16 +140,15 @@ "ripemd160", ] pruneopts = "UT" - revision = "3764759f34a542a3aef74d6b02e35be7ab893bba" - source = "github.com/tendermint/crypto" + revision = "505ab145d0a99da450461ae2c1a9f6cd10d1f447" [[projects]] branch = "master" - digest = "1:8392490b249a3602a13813be12324d3b16eca044ae185ff32cdd9e267706e208" + digest = "1:d64643374306ef30390ca9ddebc920b87ff1d8044f14eea405a2f060131d20f4" name = "golang.org/x/sys" packages = ["cpu"] pruneopts = "UT" - revision = "ec83556a53fe16b65c452a104ea9d1e86a671852" + revision = "302c3dd5f1cc82baae8e44d9c3178e89b6e2b345" [solve-meta] analyzer-name = "dep" diff --git a/Gopkg.toml b/Gopkg.toml index 69a934f..b154c61 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,10 +1,10 @@ [[constraint]] name = "github.com/ZondaX/ledger-go" - version = "v0.5.0" + version = "v0.6.0" [prune] go-tests = true unused-packages = true [[prune.project]] - name = "github.com/karalabe/hid" + name = "github.com/ZondaX/hid" unused-packages = false diff --git a/user_app_test.go b/user_app_test.go index a85f99c..842c941 100644 --- a/user_app_test.go +++ b/user_app_test.go @@ -19,6 +19,7 @@ package ledger_cosmos_go import ( + "encoding/hex" "fmt" secp256k1 "github.com/btcsuite/btcd/btcec" "github.com/stretchr/testify/assert" @@ -28,10 +29,19 @@ import ( "testing" ) +func Test_UserFindLedger(t *testing.T) { + userApp, err := FindLedgerCosmosUserApp() + if err != nil { + t.Fatalf(err.Error()) + } + + assert.NotNil(t, userApp) +} + func Test_UserGetVersion(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf( err.Error()) + t.Fatalf(err.Error()) } userApp.api.Logging = true @@ -49,7 +59,7 @@ func Test_UserGetVersion(t *testing.T) { func Test_UserGetPublicKey(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf( err.Error()) + t.Fatalf(err.Error()) } userApp.api.Logging = true @@ -75,6 +85,55 @@ func Test_UserGetPublicKey(t *testing.T) { // Ledger Test Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young +func Test_UserPK_HDPaths(t *testing.T) { + userApp, err := FindLedgerCosmosUserApp() + if err != nil { + t.Fatalf(err.Error()) + } + + userApp.api.Logging = true + + path := []uint32{44, 118, 0, 0, 0} + + expected := []string{ + "044fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe877bff8521bf5243e80be922e51cee0faa8346b113fdec822c4d902e42b22bc345", + "0460d0487a3dfce9228eee2d0d83a40f6131f551526c8e52066fe7fe1e4a509666d60da24e97777510db9b238870e184891b580610ec6dafaf12c7abffed3670c6", + "04a2670393d02b162d0ed06a08041e80d86be36c0564335254df7462447eb69ab3f5a54ab07a8622ab23c28e9240ce58f4015ec401d95b08221b74e2a4a209ba6d", + "043222fc61795077791665544a90740e8ead638a391a3b8f9261f4a226b396c042a118bb64eccd89941d73de7cb12beed5a47de61049c7fc0d4708a4a0f5637957", + "04f577473348d7b01e7af2f245e36b98d181bc935ec8b552cde5932b646dc7be0415b9fd94af37dc295e25e35d3840fdd3cb1d0baa411bdc00d15dca427abdff3f", + "0422b1a5486be0a2d5f3c5866be46e05d1bde8cda5ea1c4c77a9bc48d2fa2753bcbb49b6c9d4be25bed7fb75c2e0c43c25175e88893c4f7963398a5aac3230c79e", + "0477a1c826d3a03ca4ee94fc4dea6bccb2bac5f2ac0419a128c29f8e88f1ff295ac6a16c770d38ee0e55bec83e8d8e3f1b1616ce77055a928255919340053a477d", + "041b75c84453935ab76f8c8d0b6566c3fcc101cc5c59d7000bfc9101961e9308d9228b0af378c4e6a38eeaf18175d2b2a7ab3fad9c9a4b117775f2e4a4ac633aff", + "048905a42433b1d677cc8afd36861430b9a8529171b0616f733659f131c3f80221e222d162dbcde7c77be3d82b4f666c2acc1e25aaeb3e4fadfb8c7c6b1282374b", + "048be7f348902d8c20bc88d32294f4f3b819284548122229decd1adf1a7eb0848bc4fbd7ac5bae3a854f2bcb0831c4550f48752f630a33a088d0fd166d8d3435d9", + } + + for i := uint32(0); i < 10; i++ { + path[4] = i + + pubKey, err := userApp.GetPublicKeySECP256K1(path) + if err != nil { + t.Fatalf("Detected error, err: %s\n", err.Error()) + } + + assert.Equal( + t, + 65, + len(pubKey), + "Public key has wrong length: %x, expected length: %x\n", pubKey, 65) + + assert.Equal( + t, + expected[i], + hex.EncodeToString(pubKey), + "Public key 44'/118'/0'/0/%d does not match\n", i) + + _, err = secp256k1.ParsePubKey(pubKey[:], secp256k1.S256()) + require.Nil(t, err, "Error parsing public key err: %s\n", err) + + } +} + func getDummyTx() []byte { dummyTx := `{ "account_number": 1, @@ -102,7 +161,7 @@ func Test_UserSign(t *testing.T) { userApp.api.Logging = true - path := []uint32{44, 118, 0, 0, 0} + path := []uint32{44, 118, 0, 0, 5} message := getDummyTx() signature, err := userApp.SignSECP256K1(path, message) @@ -117,25 +176,25 @@ func Test_UserSign(t *testing.T) { } if err != nil { - t.Fatalf( "[GetPK] Error: " + err.Error()) + t.Fatalf("[GetPK] Error: " + err.Error()) return } pub__, err := secp256k1.ParsePubKey(pubKey[:], secp256k1.S256()) if err != nil { - t.Fatalf( "[ParsePK] Error: " + err.Error()) + t.Fatalf("[ParsePK] Error: " + err.Error()) return } sig__, err := secp256k1.ParseDERSignature(signature[:], secp256k1.S256()) if err != nil { - t.Fatalf( "[ParseSig] Error: " + err.Error()) + t.Fatalf("[ParseSig] Error: " + err.Error()) return } verified := sig__.Verify(crypto.Sha256(message), pub__) if !verified { - t.Fatalf( "[VerifySig] Error verifying signature: " + err.Error()) + t.Fatalf("[VerifySig] Error verifying signature: " + err.Error()) return } }