Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
group = "com.cakewallet.bitbox_flutter"
version = "1.0-SNAPSHOT"



buildscript {
ext.kotlin_version = "1.8.22"
repositories {
Expand All @@ -25,7 +27,6 @@ allprojects {
rootProject.allprojects {
repositories {
flatDir {
// dirs file('libs')
dirs project(':bitbox_flutter').file('libs')
}
}
Expand Down Expand Up @@ -76,3 +77,27 @@ android {
}
}
}

import java.nio.file.Paths
import org.apache.tools.ant.taskdefs.condition.Os

task goBind {
def path = Paths.get("${buildscript.sourceFile.parent}", "..", "run_build_tool_android.sh");
def goPath = Paths.get("${buildscript.sourceFile.parent}", "..", "go", "api");
def outPath = Paths.get("${buildscript.sourceFile.parent}", "libs",);

if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
project.exec {
commandLine 'chmod', '+x', path
}
}

def outPathDir = new File("$outPath");
outPathDir.mkdirs();

project.exec {
workingDir goPath
executable path
args "$outPath/api.aar"
}
}
1 change: 0 additions & 1 deletion android/libs/api.aar

This file was deleted.

2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'bitbox_flutter'
include ':src', ':api'
include ':src'
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.StandardMethodCodec

class BitboxFlutterPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel : MethodChannel
Expand All @@ -35,7 +36,8 @@ class BitboxFlutterPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var bitboxManager: BitboxManager

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(binding.getBinaryMessenger(), "bitbox_usb")
val taskQueue = binding.binaryMessenger.makeBackgroundTaskQueue()
channel = MethodChannel(binding.binaryMessenger, "bitbox_usb", StandardMethodCodec.INSTANCE, taskQueue)
channel.setMethodCallHandler(this)
context = binding.getApplicationContext()
usbManager = context.getSystemService(Context.USB_SERVICE) as UsbManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class GoDeviceInfo(private val device: UsbDevice?, var usbManager: UsbManager) :
@Throws(Exception::class)
override fun read(n: Long): ByteArray {
val result = ByteArray(n.toInt())
connection.bulkTransfer(endpointIn, result, result.size, 5000000)
connection.bulkTransfer(endpointIn, result, result.size, 10_000)
return result
}

@Throws(Exception::class)
override fun write(p0: ByteArray): Long {
return connection.bulkTransfer(endpointOut, p0, p0.size, 5000000).toLong()
return connection.bulkTransfer(endpointOut, p0, p0.size, 10_000).toLong()
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions build_bindings.sh

This file was deleted.

46 changes: 44 additions & 2 deletions go/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"strings"
"time"

"github.com/BitBoxSwiss/bitbox02-api-go/api/common"
"github.com/BitBoxSwiss/bitbox02-api-go/api/firmware"
"github.com/BitBoxSwiss/bitbox02-api-go/api/firmware/mocks"
"github.com/BitBoxSwiss/bitbox02-api-go/util/semver"
"github.com/konstantinullrich/bitbox_flutter/u2fhid"
)

Expand Down Expand Up @@ -107,6 +109,44 @@ func GetDevice(device GoReadWriteCloserInterface) {
bitbox = firmware.NewDevice(nil, nil, &mocks.Config{}, comm, &mocks.Logger{})
}

// GetDeviceWithInfo is like GetDevice but accepts version and product info for Bluetooth connections.
// version should be like "v9.25.0", product should be like "bb02p-multi" or "bb02p-btconly".
//
//export GetDeviceWithInfo
func GetDeviceWithInfo(device GoReadWriteCloserInterface, versionStr string, productStr string) {
const bitboxCMD = 0x80 + 0x40 + 0x01
comm := u2fhid.NewCommunication(readWriteCloser{device}, bitboxCMD)

// Parse version string (e.g., "v9.25.0" -> semver)
version, err := semver.NewSemVerFromString(strings.TrimPrefix(versionStr, "v"))
if err != nil {
panic(fmt.Sprintf("invalid version: %s", versionStr))
}

// Map product string to common.Product
// bb02p-* are BitBox02 Plus (Nova) products — must use Plus variants
var product common.Product
switch productStr {
case "bb02p-multi", "BitBox02 Nova Multi":
product = common.ProductBitBox02PlusMulti
case "bb02p-btconly", "BitBox02 Nova BTC-only":
product = common.ProductBitBox02PlusBTCOnly
case "bb02p-bl-multi", "BitBox02 Nova Multi bl":
product = common.ProductBitBox02PlusMulti
case "bb02p-bl-btconly", "BitBox02 Nova BTC-only bl":
product = common.ProductBitBox02PlusBTCOnly
// Original BitBox02 (non-Nova) products
case "BitBox02Multi":
product = common.ProductBitBox02Multi
case "BitBox02BTCOnly":
product = common.ProductBitBox02BTCOnly
default:
product = common.ProductBitBox02PlusMulti
}

bitbox = firmware.NewDevice(version, &product, &mocks.Config{}, comm, &mocks.Logger{})
}

//export GetChannelHash
func GetChannelHash() string {
hash, _ := bitbox.ChannelHash()
Expand All @@ -119,11 +159,13 @@ func ChannelHashVerify(ok bool) {
}

//export InitDevice
func InitDevice() {
func InitDevice() bool {
err := bitbox.Init()
if err != nil {
panic(err)
fmt.Println("[InitDevice] error:", err)
return false
}
return true
}

//export SupportsETH
Expand Down
44 changes: 44 additions & 0 deletions ios/Api.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>Api.framework/Api</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>Api.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>Api.framework/Api</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>Api.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Binary file added ios/Api.xcframework/ios-arm64/Api.framework/Api
Binary file not shown.
13 changes: 13 additions & 0 deletions ios/Api.xcframework/ios-arm64/Api.framework/Headers/Api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// Objective-C API for talking to the following Go packages
//
// github.com/konstantinullrich/bitbox_flutter/api
//
// File is generated by gomobile bind. Do not edit.
#ifndef __Api_FRAMEWORK_H__
#define __Api_FRAMEWORK_H__

#include "Api.objc.h"
#include "Universe.objc.h"

#endif
120 changes: 120 additions & 0 deletions ios/Api.xcframework/ios-arm64/Api.framework/Headers/Api.objc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Objective-C API for talking to github.com/konstantinullrich/bitbox_flutter/api Go package.
// gobind -lang=objc github.com/konstantinullrich/bitbox_flutter/api
//
// File is generated by gobind. Do not edit.

#ifndef __Api_H__
#define __Api_H__

@import Foundation;
#include "ref.h"
#include "Universe.objc.h"


@protocol ApiGoDeviceInfoInterface;
@class ApiGoDeviceInfoInterface;
@protocol ApiGoReadWriteCloserInterface;
@class ApiGoReadWriteCloserInterface;

@protocol ApiGoDeviceInfoInterface <NSObject>
- (NSString* _Nonnull)identifier;
- (long)interface;
- (BOOL)isBluetooth;
- (id<ApiGoReadWriteCloserInterface> _Nullable)open:(NSError* _Nullable* _Nullable)error;
- (NSString* _Nonnull)product;
- (long)productID;
- (NSString* _Nonnull)serial;
- (long)usagePage;
- (long)vendorID;
@end

@protocol ApiGoReadWriteCloserInterface <NSObject>
- (BOOL)close:(NSError* _Nullable* _Nullable)error;
- (NSData* _Nullable)read:(long)n error:(NSError* _Nullable* _Nullable)error;
- (BOOL)write:(NSData* _Nullable)p0 n:(long* _Nullable)n error:(NSError* _Nullable* _Nullable)error;
@end

FOUNDATION_EXPORT NSData* _Nullable ApiBTCSignMessage(long coinType, NSString* _Nullable keypath, NSData* _Nullable msg);

FOUNDATION_EXPORT NSString* _Nonnull ApiBTCSignPSBT(long coinType, NSString* _Nullable psbtStr);

FOUNDATION_EXPORT NSString* _Nonnull ApiBTCXPub(long coinType, NSString* _Nullable keypath, long addressType, BOOL display);

FOUNDATION_EXPORT void ApiChannelHashVerify(BOOL ok);

// skipped function DeviceInfo with unsupported parameter or return types


FOUNDATION_EXPORT NSString* _Nonnull ApiETHGetAddress(long chainId, NSString* _Nullable keypath, long outputType, BOOL display, NSData* _Nullable contractAddress);

FOUNDATION_EXPORT NSData* _Nullable ApiETHSignEIP1559(long chainId, NSString* _Nullable keypath, long nonce, NSString* _Nullable maxPriorityFeePerGas, NSString* _Nullable maxFeePerGas, long gasLimit, NSData* _Nullable recipient, NSString* _Nullable value, NSData* _Nullable data, long recipientAddressCase);

FOUNDATION_EXPORT NSData* _Nullable ApiETHSignMessage(long chainId, NSString* _Nullable keypath, NSData* _Nullable msg);

FOUNDATION_EXPORT NSData* _Nullable ApiETHSignRPLTx(long chainId, NSString* _Nullable keypath, NSString* _Nullable encodedTx, BOOL isEIP1559);

FOUNDATION_EXPORT NSData* _Nullable ApiETHSignTransaction(long chainId, NSString* _Nullable keypath, long nonce, NSString* _Nullable gasPrice, long gasLimit, NSData* _Nullable recipient, NSString* _Nullable value, NSData* _Nullable data, long recipientAddressCase);

FOUNDATION_EXPORT NSData* _Nullable ApiETHSignTypedMessage(long chainId, NSString* _Nullable keypath, NSData* _Nullable jsonMsg);

FOUNDATION_EXPORT NSString* _Nonnull ApiGetChannelHash(void);

FOUNDATION_EXPORT void ApiGetDevice(id<ApiGoReadWriteCloserInterface> _Nullable device);

/**
* GetDeviceWithInfo is like GetDevice but accepts version and product info for Bluetooth connections.
version should be like "v9.25.0", product should be like "bb02p-multi" or "bb02p-btconly".
*/
FOUNDATION_EXPORT void ApiGetDeviceWithInfo(id<ApiGoReadWriteCloserInterface> _Nullable device, NSString* _Nullable versionStr, NSString* _Nullable productStr);

FOUNDATION_EXPORT NSData* _Nullable ApiGetMasterFingerprint(void);

FOUNDATION_EXPORT BOOL ApiInitDevice(void);

FOUNDATION_EXPORT BOOL ApiSupportsBluetooth(void);

FOUNDATION_EXPORT BOOL ApiSupportsERC20(NSString* _Nullable contractAddress);

FOUNDATION_EXPORT BOOL ApiSupportsETH(long chainId);

FOUNDATION_EXPORT BOOL ApiSupportsLTC(void);

@class ApiGoDeviceInfoInterface;

@class ApiGoReadWriteCloserInterface;

/**
* GoDeviceInfoInterface adapts usb.DeviceInfo's Open method to return the adapted ReadWriteCloser.
*/
@interface ApiGoDeviceInfoInterface : NSObject <goSeqRefInterface, ApiGoDeviceInfoInterface> {
}
@property(strong, readonly) _Nonnull id _ref;

- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (NSString* _Nonnull)identifier;
- (long)interface;
- (BOOL)isBluetooth;
- (id<ApiGoReadWriteCloserInterface> _Nullable)open:(NSError* _Nullable* _Nullable)error;
- (NSString* _Nonnull)product;
- (long)productID;
- (NSString* _Nonnull)serial;
- (long)usagePage;
- (long)vendorID;
@end

/**
* GoReadWriteCloserInterface adapts io.ReadWriteCloser's Read method to return the byte read byte slice
instead of the .Read([]byte) pattern. This is as gomobile bind seems to make a copy of passed
slices instead of writing directly to it, so the byte slice never makes it back to Go-land.
*/
@interface ApiGoReadWriteCloserInterface : NSObject <goSeqRefInterface, ApiGoReadWriteCloserInterface> {
}
@property(strong, readonly) _Nonnull id _ref;

- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (BOOL)close:(NSError* _Nullable* _Nullable)error;
- (NSData* _Nullable)read:(long)n error:(NSError* _Nullable* _Nullable)error;
- (BOOL)write:(NSData* _Nullable)p0 n:(long* _Nullable)n error:(NSError* _Nullable* _Nullable)error;
@end

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Objective-C API for talking to Go package.
// gobind -lang=objc
//
// File is generated by gobind. Do not edit.

#ifndef __Universe_H__
#define __Universe_H__

@import Foundation;
#include "ref.h"

@protocol Universeerror;
@class Universeerror;

@protocol Universeerror <NSObject>
- (NSString* _Nonnull)error;
@end

@class Universeerror;

@interface Universeerror : NSError <goSeqRefInterface, Universeerror> {
}
@property(strong, readonly) _Nonnull id _ref;

- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (NSString* _Nonnull)error;
@end

#endif
Loading