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

Feature/xpubs #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 6 additions & 11 deletions src/coordinator/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def create_spending_transaction(txid, outputIndex, destination_addr, amount_sat,

return (spending_tx, script_pubkey)


def create_wallet(payload: dict, db):
if (not 'quorum' in payload):
raise Exception("[wallet] Cannot create a wallet without the 'quorum' property")
Expand Down Expand Up @@ -91,7 +90,6 @@ def get_address(payload: dict, db):
wallet_id = get_wallet_id(payload)
ec_public_keys = []

# wallet = db.get_wallet(wallet_id)
wallet_xpubs = db.get_xpubs(wallet_id)

if (wallet_xpubs == []):
Expand All @@ -102,15 +100,16 @@ def get_address(payload: dict, db):
ec_public_key = ECPubKey()

# TODO xpubs aren't working quite right. Using regular public keys for now.
# bip32_node = BIP32.from_xpub(xpub['xpub'])
# public_key = bip32_node.get_pubkey_from_path(f"m/{index}")
#e c_public_key.set(public_key)
bip32_node = BIP32.from_xpub(xpub['xpub'])
public_key = bip32_node.get_pubkey_from_path(f"m/{index}")
print("PUBKEY", public_key)
ec_public_key.set(public_key)

ec_public_key.set(bytes.fromhex(xpub['xpub']))
# ec_public_key.set(bytes.fromhex(xpub['xpub']))
ec_public_keys.append(ec_public_key)

c_map, pubkey_agg = generate_musig_key(ec_public_keys)
logging.info('[wallet] Aggregate public key: %s', pubkey_agg.get_bytes().hex())
logging.info('[wallet] Aggregate public key: %s at index: %i', pubkey_agg.get_bytes().hex(), index)

# Create a segwit v1 address (P2TR) from the aggregate key
p2tr_address = program_to_witness(0x01, pubkey_agg.get_bytes())
Expand All @@ -130,8 +129,6 @@ def start_spend(payload: dict, db):
# create an ID for this request
spend_request_id = str(uuid.uuid4())
logging.info('[wallet] Starting spend request with id %s', spend_request_id)


if (not 'txid' in payload):
raise Exception("[wallet] Cannot spend without the 'txid' property, which corresponds to the transaction ID of the output that is being spent")

Expand Down Expand Up @@ -269,5 +266,3 @@ def save_signature(payload, db):
# print("TXID", txid)

return tx_serialized_hex


12 changes: 6 additions & 6 deletions src/signer/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def handle_create_wallet(quorum, relay_manager, private_key):
def handle_create_xpub(wallet, relay_manager, private_key):
xpub = wallet.get_root_xpub()
add_xpub_payload = generate_nostr_message(
command='xpub', payload={'wallet_id': wallet.get_wallet_id(), 'xpub': wallet.get_pubkey()})
command='xpub', payload={'wallet_id': wallet.get_wallet_id(), 'xpub': xpub})
construct_and_publish_event(add_xpub_payload, private_key, relay_manager)
print("Operation Finished")

Expand Down Expand Up @@ -253,13 +253,13 @@ def run_signer(wallet_id=None, key_pair_seed=None, nonce_seed=None):

elif user_input.lower() == SignerCommands.SEND_PUBLIC_KEY.value:
logging.info("Generating and posting the public key...")
handle_create_xpub(wallet, relay_manager, nostr_private_key)

handle_create_xpub(wallet, relay_manager, private_key)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
handle_create_xpub(wallet, relay_manager, private_key)
handle_create_xpub(wallet, relay_manager, nostr_private_key)

I think this should be kept nostr_private_key? I renamed it as part of this cleanup a little over a week ago #18

elif user_input.lower() == SignerCommands.GENERATE_ADDRESS.value:
# TODO bug: you cannot sign or spend with out getting an address first
logging.info("Generating a new address...")
# TODO right now you have to manage your own address indecies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO right now you have to manage your own address indecies
# TODO right now you have to manage your own address indexes

index = int(input("Enter address index: "))
logging.info(f"Generating a new address at index {index} ...")
address_payload = handle_get_address(
wallet, 0, relay_manager, nostr_private_key)
wallet, index, relay_manager, private_key)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wallet, index, relay_manager, private_key)
wallet, index, relay_manager, nostr_private_key)


wallet.set_cmap(address_payload['cmap'])
wallet.set_pubkey_agg(address_payload['pubkey_agg'])
Expand Down