Skip to content

Commit

Permalink
Merge branch 'api-go'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Feb 13, 2025
2 parents de972b3 + 084bfbd commit 52f56f9
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 57 deletions.
13 changes: 9 additions & 4 deletions backend/devices/bitbox02/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,15 @@ func (handlers *Handlers) postSetMnemonicPassphraseEnabled(r *http.Request) inte
func (handlers *Handlers) getVersionHandler(_ *http.Request) interface{} {
currentVersion := handlers.device.Version()
newVersion := bitbox02bootloader.BundledFirmwareVersion(handlers.device.Product())

var newVersionStr string
var canUpgrade bool
if newVersion != nil {
newVersionStr = newVersion.String()
canUpgrade = newVersion.AtLeast(currentVersion) && currentVersion.String() != newVersion.String()
}
return struct {
CurrentVersion string `json:"currentVersion"`
NewVersion string `json:"newVersion"`
NewVersion string `json:"newVersion,omitempty"`
CanUpgrade bool `json:"canUpgrade"`
CanGotoStartupSettings bool `json:"canGotoStartupSettings"`
// If true, creating a backup using the mnemonic recovery words instead of the microSD card
Expand All @@ -309,8 +314,8 @@ func (handlers *Handlers) getVersionHandler(_ *http.Request) interface{} {
CanBIP85 bool `json:"canBIP85"`
}{
CurrentVersion: currentVersion.String(),
NewVersion: newVersion.String(),
CanUpgrade: newVersion.AtLeast(currentVersion) && currentVersion.String() != newVersion.String(),
NewVersion: newVersionStr,
CanUpgrade: canUpgrade,
CanGotoStartupSettings: currentVersion.AtLeast(semver.NewSemVer(9, 6, 0)),
CanBackupWithRecoveryWords: currentVersion.AtLeast(semver.NewSemVer(9, 13, 0)),
CanCreate12Words: currentVersion.AtLeast(semver.NewSemVer(9, 6, 0)),
Expand Down
5 changes: 3 additions & 2 deletions backend/devices/bitbox02bootloader/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ var bundledFirmwares = map[bitbox02common.Product][]firmwareInfo{
},
}

// BundledFirmwareVersion returns the version of newest bundled firmware.
// BundledFirmwareVersion returns the version of newest bundled firmware. Returns nil if none is
// available.
func BundledFirmwareVersion(product bitbox02common.Product) *semver.SemVer {
firmwares, ok := bundledFirmwares[product]
if !ok {
panic("unrecognized product")
return nil
}

return firmwares[len(firmwares)-1].version
Expand Down
16 changes: 10 additions & 6 deletions backend/devices/usb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ func isBitBox(deviceInfo DeviceInfo) bool {
}

func isBitBox02(deviceInfo DeviceInfo) bool {
return (deviceInfo.Product() == bitbox02common.FirmwareHIDProductStringStandard ||
deviceInfo.Product() == bitbox02common.FirmwareHIDProductStringBTCOnly) &&
return (deviceInfo.Product() == bitbox02common.FirmwareDeviceProductStringBitBox02Multi ||
deviceInfo.Product() == bitbox02common.FirmwareDeviceProductStringBitBox02BTCOnly ||
deviceInfo.Product() == bitbox02common.FirmwareDeviceProductStringBitBox02PlusMulti ||
deviceInfo.Product() == bitbox02common.FirmwareDeviceProductStringBitBox02PlusBTCOnly) &&
deviceInfo.VendorID() == bitbox02VendorID &&
deviceInfo.ProductID() == bitbox02ProductID &&
(deviceInfo.UsagePage() == 0xffff || deviceInfo.Interface() == 0)
}

func isBitBox02Bootloader(deviceInfo DeviceInfo) bool {
return (deviceInfo.Product() == bitbox02common.BootloaderHIDProductStringStandard ||
deviceInfo.Product() == bitbox02common.BootloaderHIDProductStringBTCOnly) &&
return (deviceInfo.Product() == bitbox02common.BootloaderDeviceProductStringBitBox02Multi ||
deviceInfo.Product() == bitbox02common.BootloaderDeviceProductStringBitBox02BTCOnly ||
deviceInfo.Product() == bitbox02common.BootloaderDeviceProductStringBitBox02PlusMulti ||
deviceInfo.Product() == bitbox02common.BootloaderDeviceProductStringBitBox02PlusBTCOnly) &&
deviceInfo.VendorID() == bitbox02VendorID &&
deviceInfo.ProductID() == bitbox02ProductID &&
(deviceInfo.UsagePage() == 0xffff || deviceInfo.Interface() == 0)
Expand Down Expand Up @@ -198,7 +202,7 @@ func (manager *Manager) makeBitBox02(deviceInfo DeviceInfo) (*bitbox02.Device, e
if err != nil {
return nil, err
}
product, err := bitbox02common.ProductFromHIDProductString(deviceInfo.Product())
product, err := bitbox02common.ProductFromDeviceProductString(deviceInfo.Product())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -226,7 +230,7 @@ func (manager *Manager) makeBitBox02Bootloader(deviceInfo DeviceInfo) (
if err != nil {
return nil, err
}
product, err := bitbox02common.ProductFromHIDProductString(deviceInfo.Product())
product, err := bitbox02common.ProductFromDeviceProductString(deviceInfo.Product())
if err != nil {
return nil, err
}
Expand Down
34 changes: 18 additions & 16 deletions frontends/web/src/api/bitbox02.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,25 @@ export const setDeviceName = (
});
};

export type VersionInfo = {
newVersion: string;
currentVersion: string;
canUpgrade: boolean;
canGotoStartupSettings: boolean;
// If true, creating a backup using the mnemonic recovery words instead of the microSD card
// is supported in the initial setup.
//
// If false, the backup must be performed using the microSD card in the initial setup.
//
// This has no influence over whether one can display the recovery words after the initial
// setup - that is always possible regardless of this value.
canBackupWithRecoveryWords: boolean;
canCreate12Words: boolean;
canBIP85: boolean;
type VersionInfoCommon = {
currentVersion: string;
canGotoStartupSettings: boolean;
// If true, creating a backup using the mnemonic recovery words instead of the microSD card
// is supported in the initial setup.
//
// If false, the backup must be performed using the microSD card in the initial setup.
//
// This has no influence over whether one can display the recovery words after the initial
// setup - that is always possible regardless of this value.
canBackupWithRecoveryWords: boolean;
canCreate12Words: boolean;
canBIP85: boolean;
}

export type VersionInfo = VersionInfoCommon & (
{ canUpgrade: true, newVersion: string; } |
{ canUpgrade: false; })

export const getVersion = (
deviceID: string
): Promise<VersionInfo> => {
Expand Down Expand Up @@ -184,4 +186,4 @@ export const invokeBIP85 = (deviceID: string): Promise<SuccessResponse | FailRes

export const gotoStartupSettings = (deviceID: string) => {
return apiPost(`devices/bitbox02/${deviceID}/goto-startup-settings`);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const UpgradeDialog = ({
onClose
}: TUpgradeDialogProps) => {
const { t } = useTranslation();
if (!versionInfo.canUpgrade) {
return null;
}
return (
<Dialog onClose={onClose} open={open} title={t('upgradeFirmware.title')}>
{confirming ? t('confirmOnDevice') : (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/BitBoxSwiss/bitbox-wallet-app
go 1.22

require (
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20240925080402-a2115fee878e
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20250212204931-2b90fadfc774
github.com/BitBoxSwiss/block-client-go v0.0.0-20241009081439-924dde98b9c1
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20240925080402-a2115fee878e h1:wEIIFhiZ58RsVjoKfwSBBD0i75uZ7KATOI/elaBWOOY=
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20240925080402-a2115fee878e/go.mod h1:Spf6hQRSylrvdjd7Cv4Tc8rFwlcamJAC8EuA61ARy7U=
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20250212204931-2b90fadfc774 h1:lMa0mZs7llEvMZd/hce7G+wypZekmeuXN0HpPmbFc10=
github.com/BitBoxSwiss/bitbox02-api-go v0.0.0-20250212204931-2b90fadfc774/go.mod h1:lyYwD22hA6TQ8XNXx37VE75Exp6qYdgZgUAO4+lyhSU=
github.com/BitBoxSwiss/block-client-go v0.0.0-20241009081439-924dde98b9c1 h1:5hjP8mYSVKFibesrz8L6U0Vp5zSJt0LwXB3DSZGhnSo=
github.com/BitBoxSwiss/block-client-go v0.0.0-20241009081439-924dde98b9c1/go.mod h1:SJTiQZU9ggBzVKMni97rpNS9GddPKErndFXNSDrfEGc=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
Expand Down

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

56 changes: 43 additions & 13 deletions vendor/github.com/BitBoxSwiss/bitbox02-api-go/api/common/common.go

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

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

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

Loading

0 comments on commit 52f56f9

Please sign in to comment.