Skip to content

Commit

Permalink
add support of Cobo multisig (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansnigirev committed Aug 4, 2020
1 parent 439a6cf commit e189be4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
60 changes: 52 additions & 8 deletions src/cryptoadvance/specter/devices/cobo.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
import hashlib
from ..device import Device
# from ..device import Device
from .sd_card_device import SDCardDevice
from hwilib.serializations import PSBT
from binascii import a2b_base64
from .. import bcur
from .electrum import b43_encode

class Cobo(Device):
class Cobo(SDCardDevice):
def __init__(self, name, alias, device_type, keys, fullpath, manager):
super().__init__(name, alias, 'cobo', keys, fullpath, manager)
self.sd_card_support = False
self.hwi_support = False
self.sd_card_support = True
self.qr_code_support = True
self.exportable_to_wallet = True
self.wallet_export_type = 'qr'

def create_psbts(self, base64_psbt, wallet):
# TODO - convert to bc-ur
psbts = super().create_psbts(base64_psbt, wallet)
raw_psbt = a2b_base64(base64_psbt)
enc, hsh = bcur.bcur_encode(raw_psbt)
psbt = ("ur:bytes/%s/%s"% (hsh, enc)).upper()
psbts = { 'qrcode': psbt }
return psbts
if wallet.is_multisig:
qrpsbt = b43_encode(raw_psbt)
else:
enc, hsh = bcur.bcur_encode(raw_psbt)
qrpsbt = ("ur:bytes/%s/%s"% (hsh, enc)).upper()
psbts['qrcode'] = qrpsbt
return psbts

def export_wallet(self, wallet):
# Cobo uses ColdCard's style
CC_TYPES = {
'legacy': 'BIP45',
'p2sh-segwit': 'P2WSH-P2SH',
'bech32': 'P2WSH'
}
# try to find at least one derivation
# cc assume the same derivation for all keys :(
derivation = None
for k in wallet.keys:
if k.derivation != '':
derivation = k.derivation.replace("h","'")
break
if derivation is None:
return None
cc_file = """# CoboVault Multisig setup file (created on Specter Desktop)
#
Name: {}
Policy: {} of {}
Derivation: {}
Format: {}
""".format(wallet.name, wallet.sigs_required,
len(wallet.keys), derivation,
CC_TYPES[wallet.address_type]
)
for k in wallet.keys:
# cc assumes fingerprint is known
fingerprint = k.fingerprint
if fingerprint == '':
fingerprint = get_xpub_fingerprint(k.xpub).hex()
cc_file += "{}: {}\n".format(fingerprint.upper(), k.xpub)
enc, hsh = bcur.bcur_encode(cc_file.encode())
cobo_qr = ("ur:bytes/%s/%s"% (hsh, enc)).upper()
return cobo_qr
8 changes: 8 additions & 0 deletions src/cryptoadvance/specter/templates/device/new_device.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ upub5En4f7k8gaG2KDHvBeEYox...rFpJRHpiZ4DE
let str = `[${obj.MasterFingerprint}/${path}]${obj.ExtPubKey}`;
addKeys(str);
setDeviceType('cobo');
}else if( ("xfp" in obj) &&
("xpub" in obj) &&
("path" in obj)){
console.log(obj);
let path = obj.path.replace(/'/g,'h').replace("m/","");
let str = `[${obj.xfp}/${path}]${obj.xpub}`;
addKeys(str);
setDeviceType('cobo');
}else{
showError("Unknown key format");
}
Expand Down

0 comments on commit e189be4

Please sign in to comment.