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

Descriptor urtype account #426

Merged
merged 4 commits into from
Jul 30, 2024
Merged
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
9 changes: 9 additions & 0 deletions src/krux/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ def parse_wallet(wallet_data, allow_assumption=None):
except:
pass

# Try to parse as a Crypto-Account type
try:
account = urtypes.crypto.Account.from_cbor(
wallet_data.cbor
).output_descriptors[0]
return Descriptor.from_string(account.descriptor()), None
except:
pass

# Treat the UR as a generic UR bytes object and extract the data for further processing
wallet_data = urtypes.Bytes.from_cbor(wallet_data.cbor).data

Expand Down
57 changes: 57 additions & 0 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from ur.ur_decoder import URDecoder


@pytest.fixture
Expand Down Expand Up @@ -979,3 +980,59 @@ def test_derivation_to_script_wrapper():

for _case in cases:
assert derivation_to_script_wrapper(_case[0]) == _case[1]


def test_parse_wallet_via_ur_output(mocker, m5stickv):
from krux.wallet import parse_wallet

# sparrow uses this ur format
QRDATA = [
# testnet legacy p2pkh
"UR:CRYPTO-OUTPUT/TAADMUTAADDLOSAOWKAXHDCLAXJPDPECBNTOVEKOVOADIHWDDIBKHTHYAECWBSWPDEYTMSLEDRBSPMAMDEVAURWFDWAAHDCXKKSGMELBWMKOFRDMOEDAUEMUQDVDVANEBGVOMYGLKOVSFDSKDEJYKOGDGTINETTOAHTAADEHOEADAEAOADAMTAADDYOTADLNCSDWYKADYKAEYKAOCYTBFSSSOSAXAXAYCYLBZMISPFASIMGUIHIHIEGUINIOJTIHJPMEZMDWFY",
# testnet nested segwit
"UR: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7taNiKGbEWGY1fxEyWQgvCCQRGNBz87qej9XuyMXpTCtDbbKP6fXGtio1))",
"wpkh([d63dc4a7/84h/1h/0h]tpubDCka9mfAaAN3cit16QqK2RCRVBpA2B7b8RFWUCLdyKR8eA48pjX7kZ5RAM6bSdwD9ivwh33KES7Q4DcqzNwkNUyyadZTTLf36Xp955vUBdf)",
"tr([d63dc4a7/86h/1h/1h]tpubDDDs2UVFbhXBRTW4EJEH74qDcdVetqn5pF2AMcpMCfwvU561GJiY4BZoLPSpw4d6cb7wVHyu1JNa3dVjhKgmTKZ6m8M4L6wv763gHjhYAfd)",
]

for i, QRDATUM in enumerate(QRDATA):
wallet_data = URDecoder().decode(QRDATUM)
descriptor, label = parse_wallet(wallet_data)
assert str(descriptor) == DESCRIPTORS[i]
print(DESCRIPTORS[i])


def test_parse_wallet_via_ur_account(mocker, m5stickv):
from krux.wallet import parse_wallet

# seedsigner uses this ur format when exporting for sparrow
QRDATA = [
# mainnet legacy p2pkh
"UR:CRYPTO-ACCOUNT/OEADCYTBFSSSOSAOLYTAADMUTAADDLOXAXHDCLAODNLFAHCFGUJOYLESGDYNVANSDRGYTISWRTMWTTIAGUADAMPLONLAAEKPZOLGHSPMAAHDCXOLEOFRMSGELTHFPRJNVEECBBHDGOONEHMHBBTDVDAMCXVDMDROBZCWUYLDRERNHSAMTAADDYOTADLNCSDWYKAEYKAEYKAOCYTBFSSSOSAXAXAYCYBTWMBGPTAXUOCEVY",
# mainnet nested segwit
"UR:CRYPTO-ACCOUNT/OEADCYTBFSSSOSAOLYTAADMHTAADMWTAADDLOXAXHDCLAOFNVAJKFZAXCPCMJSAYYNYLCHEYESNLWDISVTVODAVTFZVEWLAMWYLDBNNTBEKECTAAHDCXSPYLEYCFMSHKJLGOMTTTEHCMNEPYSEIADTKPNBPMPKONIEWYAHPRADWDONYNGMSKAMTAADDYOTADLNCSEHYKAEYKAEYKAOCYTBFSSSOSAXAXAYCYVEZSGMCXTKYTCMKN",
# mainnet native segwit
"U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byNeM4xxXKSa45TcHxLhQKPh)",
]

for i, QRDATUM in enumerate(QRDATA):
wallet_data = URDecoder().decode(QRDATUM)
descriptor, label = parse_wallet(wallet_data)
assert str(descriptor) == DESCRIPTORS[i]
print(DESCRIPTORS[i])