Exemple #1
0
def genmultisig(nreq, mtotal, *pubkeys):
    '''Generate a new multisignature address and redemption script that requires `nreq' signatures to spend and provides a possible `mtotal'.
    If public keys are provided on the command line, those are used instead of generating new ones.'''

    nreq = int(nreq)
    mtotal = int(mtotal)
    pubkeys = list(pubkeys)
    assert 0 <= nreq <= mtotal
    assert len(pubkeys) <= mtotal

    # Create new keys if necessary
    while len(pubkeys) < mtotal:
        pk = pyspv.keys.PrivateKey.create_new()
        spv.wallet.add('private_key', pk, {'label': ''})
        pubkeys.append(pk.get_public_key(compressed=True).as_hex())

    pubkeys = [pyspv.keys.PublicKey.from_hex(pubkey) for pubkey in pubkeys]
    pubkeys.sort()

    # build the M-of-N multisig redemption script and add it to the wallet
    # (the p2sh monitor will notice that we added a redemption script to the
    # wallet and start watching for transactions to it

    script = pyspv.script.Script()
    script.push_int(nreq)

    for pubkey in pubkeys:
        script.push_bytes(pubkey.pubkey)

    script.push_int(len(pubkeys))
    script.push_op(pyspv.script.OP_CHECKMULTISIG)

    redemption_script = script.program
    address = pyspv.base58_check(
        spv.coin,
        spv.coin.hash160(redemption_script),
        version_bytes=spv.coin.P2SH_ADDRESS_VERSION_BYTES)

    try:
        spv.wallet.add('redemption_script', redemption_script, {})
    except pyspv.wallet.DuplicateWalletItem:
        # No worries, we already have this redemption script
        if spv.logging_level <= pyspv.INFO:
            print('[simple-wallet] Duplicate redemption script??')
        pass

    return {
        'address':
        address,
        'redemption_script':
        pyspv.bytes_to_hexstring(redemption_script, reverse=False),
        'pubkeys': [pubkey.as_hex() for pubkey in pubkeys],
        'nreq':
        nreq,
    }
Exemple #2
0
def getnewstealthaddress(label=''):
    pk = pyspv.keys.PrivateKey.create_new()
    spv.wallet.add('private_key', pk, {
        'label': label,
        'stealth_payments': True
    })
    return pyspv.base58_check(
        spv.coin,
        pk.get_public_key(True).pubkey,
        version_bytes=spv.coin.STEALTH_ADDRESS_VERSION_BYTES,
        suffix_bytes=spv.coin.STEALTH_ADDRESS_SUFFIX_BYTES)
Exemple #3
0
def genmultisig(nreq, mtotal, *pubkeys):
    '''Generate a new multisignature address and redemption script that requires `nreq' signatures to spend and provides a possible `mtotal'.
    If public keys are provided on the command line, those are used instead of generating new ones.'''

    nreq = int(nreq)
    mtotal = int(mtotal)
    pubkeys = list(pubkeys)
    assert 0 <= nreq <= mtotal
    assert len(pubkeys) <= mtotal

    # Create new keys if necessary
    while len(pubkeys) < mtotal:
        pk = pyspv.keys.PrivateKey.create_new()
        spv.wallet.add('private_key', pk, {'label': ''})
        pubkeys.append(pk.get_public_key(compressed=True).as_hex())

    pubkeys = [pyspv.keys.PublicKey.from_hex(pubkey) for pubkey in pubkeys]
    pubkeys.sort()

    # build the M-of-N multisig redemption script and add it to the wallet
    # (the p2sh monitor will notice that we added a redemption script to the 
    # wallet and start watching for transactions to it

    script = pyspv.script.Script()
    script.push_int(nreq)

    for pubkey in pubkeys:
        script.push_bytes(pubkey.pubkey)

    script.push_int(len(pubkeys))
    script.push_op(pyspv.script.OP_CHECKMULTISIG)

    redemption_script = script.program
    address = pyspv.base58_check(spv.coin, spv.coin.hash160(redemption_script), version_bytes=spv.coin.P2SH_ADDRESS_VERSION_BYTES)

    try:
        spv.wallet.add('redemption_script', redemption_script, {})
    except pyspv.wallet.DuplicateWalletItem:
        # No worries, we already have this redemption script
        if spv.logging_level <= pyspv.INFO:
            print('[simple-wallet] Duplicate redemption script??')
        pass

    return {
        'address': address,
        'redemption_script': pyspv.bytes_to_hexstring(redemption_script, reverse=False),
        'pubkeys': [ pubkey.as_hex() for pubkey in pubkeys ],
        'nreq': nreq,
    }
Exemple #4
0
def getnewstealthaddress(label=''):
    pk = pyspv.keys.PrivateKey.create_new()
    spv.wallet.add('private_key', pk, {'label': label, 'stealth_payments': True})
    return pyspv.base58_check(spv.coin, pk.get_public_key(True).pubkey, version_bytes=spv.coin.STEALTH_ADDRESS_VERSION_BYTES, suffix_bytes=spv.coin.STEALTH_ADDRESS_SUFFIX_BYTES)