Skip to content

Commit

Permalink
Merge branch 'bip85'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Dec 28, 2023
2 parents 29421cd + 94ca26b commit 2ac5d3d
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: ci
on: [push, pull_request]
env:
GO_VERSION: "^1.20"
GOLANGCI_LINT_VERSION: "v1.52.2"
GOLANGCI_LINT_VERSION: "v1.55.2"

jobs:
lint:
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ linters:
- structcheck
- deadcode
- varcheck
- depguard
- protogetter
- gosmopolitan
- inamedparam
# could not find a way to disable float-compare: https://github.com/golangci/golangci-lint/issues/4187
- testifylint
disable-all: false

issues:
Expand Down
2 changes: 1 addition & 1 deletion api/bootloader/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestUpgradeFirmware(t *testing.T) {
sleepCalls := 0
env.device.TstSetSleep(func(d time.Duration) {
require.Equal(t, time.Second, d)
require.True(t, sleepCalls < rebootSeconds)
require.Less(t, sleepCalls, rebootSeconds)
require.True(t, currentStatus.UpgradeSuccessful)
require.Equal(t, rebootSeconds-sleepCalls, currentStatus.RebootSeconds)
sleepCalls++
Expand Down
44 changes: 44 additions & 0 deletions api/firmware/bip85.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2023 Shift Crypto AG
//
// 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 firmware

import (
"github.com/digitalbitbox/bitbox02-api-go/api/firmware/messages"
"github.com/digitalbitbox/bitbox02-api-go/util/errp"
"github.com/digitalbitbox/bitbox02-api-go/util/semver"
)

// BIP85 invokes the BIP-85 workflow on the device, letting the user select the number of words (12,
// 28, 24) and an index and display a derived BIP-39 mnemonic.
func (device *Device) BIP85() error {
if !device.version.AtLeast(semver.NewSemVer(9, 16, 0)) {
return UnsupportedError("9.16.0")
}

request := &messages.Request{
Request: &messages.Request_Bip85{
Bip85: &messages.BIP85Request{},
},
}
response, err := device.query(request)
if err != nil {
return err
}
_, ok := response.Response.(*messages.Response_Bip85)
if !ok {
return errp.New("unexpected response")
}
return nil
}
241 changes: 141 additions & 100 deletions api/firmware/messages/hww.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/firmware/messages/hww.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ message Request {
BTCRequest btc = 25;
ElectrumEncryptionKeyRequest electrum_encryption_key = 26;
CardanoRequest cardano = 27;
BIP85Request bip85 = 28;
}
}

Expand All @@ -87,5 +88,6 @@ message Response {
BTCResponse btc = 13;
ElectrumEncryptionKeyResponse electrum_encryption_key = 14;
CardanoResponse cardano = 15;
BIP85Response bip85 = 16;
}
}
110 changes: 107 additions & 3 deletions api/firmware/messages/keystore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/firmware/messages/keystore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ message ElectrumEncryptionKeyRequest {
message ElectrumEncryptionKeyResponse {
string key = 1;
}

message BIP85Request {
}

message BIP85Response {
}
2 changes: 1 addition & 1 deletion communication/u2fhid/u2fhid.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (communication *Communication) sendFrame(msg string) error {
_, err := communication.device.Write(x)
return errp.WithMessage(errp.WithStack(err), "Failed to send message")
}
readBuffer := bytes.NewBuffer([]byte(msg))
readBuffer := bytes.NewBufferString(msg)
// init frame
header := newBuffer()
if err := binary.Write(header, binary.BigEndian, cid); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions util/semver/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ func TestNewSemVer(t *testing.T) {
assert.Equal(t, semver.NewSemVer(3, 2, 4), version)

_, err = semver.NewSemVerFromString("")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("vv3.2.4")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("3.2")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("v3.2")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("3.2.")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("3.2.A")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("3.A.4")
assert.Error(t, err)
require.Error(t, err)

_, err = semver.NewSemVerFromString("3.2.4-")
assert.Error(t, err)
require.Error(t, err)
}

func TestAtLeast(t *testing.T) {
Expand All @@ -73,7 +73,7 @@ func TestString(t *testing.T) {
func TestJSON(t *testing.T) {
jsonBytes, err := json.Marshal(semver.NewSemVer(3, 2, 4))
require.NoError(t, err)
require.Equal(t, string(jsonBytes), `"3.2.4"`)
require.Equal(t, `"3.2.4"`, string(jsonBytes))

var version semver.SemVer
require.Error(t, json.Unmarshal([]byte(`123`), &version))
Expand Down

0 comments on commit 2ac5d3d

Please sign in to comment.