Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: shamir secret sharing #1343

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions messages/hww.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "eth.proto";
import "keystore.proto";
import "mnemonic.proto";
import "system.proto";
import "shamir.proto";

import "perform_attestation.proto";

Expand Down Expand Up @@ -67,6 +68,9 @@ message Request {
ElectrumEncryptionKeyRequest electrum_encryption_key = 26;
CardanoRequest cardano = 27;
BIP85Request bip85 = 28;
ShowShamirRequest show_shamir = 29;
RestoreFromShamirRequest restore_from_shamir = 30;

}
}

Expand Down
23 changes: 23 additions & 0 deletions messages/shamir.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 Shift Cryptosecurity 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.

syntax = "proto3";
package shiftcrypto.bitbox02;

message ShowShamirRequest {
}
message RestoreFromShamirRequest {
uint32 timestamp = 1;
int32 timezone_offset = 2;
}
2 changes: 1 addition & 1 deletion py/bitbox02/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

OUT_DIR=bitbox02/communication/generated

PROTO_FILES=hww.proto common.proto backup_commands.proto bitbox02_system.proto btc.proto cardano.proto eth.proto mnemonic.proto system.proto perform_attestation.proto keystore.proto antiklepto.proto
PROTO_FILES=hww.proto common.proto backup_commands.proto bitbox02_system.proto btc.proto cardano.proto eth.proto mnemonic.proto system.proto perform_attestation.proto keystore.proto antiklepto.proto shamir.proto

TARGETS=$(addprefix ${OUT_DIR}/, $(PROTO_FILES:.proto=_pb2.py))

Expand Down
25 changes: 25 additions & 0 deletions py/bitbox02/bitbox02/bitbox02/bitbox02.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from bitbox02.communication.generated import btc_pb2 as btc
from bitbox02.communication.generated import cardano_pb2 as cardano
from bitbox02.communication.generated import mnemonic_pb2 as mnemonic
from bitbox02.communication.generated import shamir_pb2 as shamir
from bitbox02.communication.generated import bitbox02_system_pb2 as bitbox02_system
from bitbox02.communication.generated import backup_commands_pb2 as backup
from bitbox02.communication.generated import common_pb2 as common
Expand Down Expand Up @@ -259,6 +260,17 @@ def show_mnemonic(self) -> None:
request.show_mnemonic.CopyFrom(mnemonic.ShowMnemonicRequest())
self._msg_query(request, expected_response="success")

def show_shamir(self) -> None:
"""
Returns True if shamir mnemonics were successfully shown and confirmed.
Raises a Bitbox02Exception on failure.
"""
# self._require_atleast(semver.VersionInfo(9, 16, 0)) TODO
# pylint: disable=no-member
request = hww.Request()
request.show_shamir.CopyFrom(shamir.ShowShamirRequest())
self._msg_query(request, expected_response="success")

def _btc_msg_query(
self, btc_request: btc.BTCRequest, expected_response: Optional[str] = None
) -> btc.BTCResponse:
Expand Down Expand Up @@ -1136,6 +1148,19 @@ def restore_from_mnemonic(self) -> None:
)
self._msg_query(request)

def restore_from_shamir(self) -> None:
"""
Restore from shamir backup. Raises a Bitbox02Exception on failure.
"""
request = hww.Request()
# pylint: disable=no-member
request.restore_from_shamir.CopyFrom(
shamir.RestoreFromShamirRequest(
timestamp=int(time.time()), timezone_offset=time.localtime().tm_gmtoff
)
)
self._msg_query(request)

def _cardano_msg_query(
self, cardano_request: cardano.CardanoRequest, expected_response: Optional[str] = None
) -> cardano.CardanoResponse:
Expand Down
19 changes: 10 additions & 9 deletions py/bitbox02/bitbox02/communication/generated/hww_pb2.py

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

Loading
Loading