コード例 #1
0
ファイル: deserialize.py プロジェクト: phikaa/openblockchain
def extract_hash160(bytes, version='\x00'):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except struct.error:
        return "(None)"

    # non-generated TxIn transactions push a signature
    # (seventy-something bytes) and then their public key
    # (33 or 65 bytes) onto the stack:
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        return hash_160(decoded[1][1])

    # The Genesis Block, self-payments, and pay-by-IP-address payments look like:
    # 65 BYTES:... CHECKSIG
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return hash_160(decoded[0][1])

    # Pay-by-Bitcoin-address TxOuts look like:
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [
        opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4,
        opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG
    ]
    if match_decoded(decoded, match):
        return decoded[2][1]

    # BIP11 TxOuts look like one of these:
    multisigs = [[
        opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_1,
        opcodes.OP_CHECKMULTISIG
    ],
                 [
                     opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
                     opcodes.OP_PUSHDATA4, opcodes.OP_2,
                     opcodes.OP_CHECKMULTISIG
                 ],
                 [
                     opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
                     opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_3,
                     opcodes.OP_CHECKMULTISIG
                 ]]
    for match in multisigs:
        if match_decoded(decoded, match):
            return "[" + ','.join(
                [hash_160(decoded[i][1])
                 for i in range(1,
                                len(decoded) - 2)]) + "]"

    # BIP16 TxOuts look like:
    # HASH160 20 BYTES:... EQUAL
    match = [opcodes.OP_HASH160, 0x14, opcodes.OP_EQUAL]
    if match_decoded(decoded, match):
        return decoded[1][1]

    return "(None)"
コード例 #2
0
def print_info(key, chain):
  
  prv_key = key.to_extended_key(include_prv=key.prvkey())
  pub_key = key.to_extended_key()

  desc ='  * [Chain m'
  for c in chain:
    if c&0x80000000:
      desc = desc + '/%d\'' % (c & ~0x80000000)
    else:
      desc = desc + '/%d' % c
  desc = desc + ']'

  print desc

  print '    * Identifier'
  print '      * (hex):       %s' % base58.hash_160(point_compress(key.point())).encode('hex')
  print '      * (fpr):       0x%s' % key.fingerprint().encode('hex')
  print '      * (main addr): %s' % key.address()
  print '    * Secret key'
  print '      * (hex):       %s' % key.prvkey().encode('hex')
  print '      * (wif):       %s' % SecretToASecret(key.prvkey(), True)
  print '    * Public key'
  print '      * (hex):       %s' % point_compress(key.point()).encode('hex')
  print '    * Chain code'
  print '      * (hex):       %s' % key.chain().encode('hex')
  print '    * Serialized'
  print '      * (pub hex):   %s' % base58.b58decode(pub_key, None).encode('hex')
  print '      * (prv hex):   %s' % base58.b58decode(prv_key, None).encode('hex')
  print '      * (pub b58):   %s' % pub_key
  print '      * (prv b58):   %s' % prv_key
コード例 #3
0
def print_info(key, chain):

    prv_key = key.to_extended_key(include_prv=key.prvkey())
    pub_key = key.to_extended_key()

    desc = '  * [Chain m'
    for c in chain:
        if c & 0x80000000:
            desc = desc + '/%d\'' % (c & ~0x80000000)
        else:
            desc = desc + '/%d' % c
    desc = desc + ']'

    print desc

    print '    * Identifier'
    print '      * (hex):       %s' % base58.hash_160(
        point_compress(key.point())).encode('hex')
    print '      * (fpr):       0x%s' % key.fingerprint().encode('hex')
    print '      * (main addr): %s' % key.address()
    print '    * Secret key'
    print '      * (hex):       %s' % key.prvkey().encode('hex')
    print '      * (wif):       %s' % SecretToASecret(key.prvkey(), True)
    print '    * Public key'
    print '      * (hex):       %s' % point_compress(key.point()).encode('hex')
    print '    * Chain code'
    print '      * (hex):       %s' % key.chain().encode('hex')
    print '    * Serialized'
    print '      * (pub hex):   %s' % base58.b58decode(pub_key,
                                                       None).encode('hex')
    print '      * (prv hex):   %s' % base58.b58decode(prv_key,
                                                       None).encode('hex')
    print '      * (pub b58):   %s' % pub_key
    print '      * (prv b58):   %s' % prv_key
コード例 #4
0
ファイル: deserialize.py プロジェクト: haobtc/openblockchain
def extract_hash160(bytes, version='\x00'):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except struct.error:
        return "(None)"

    # non-generated TxIn transactions push a signature
    # (seventy-something bytes) and then their public key
    # (33 or 65 bytes) onto the stack:
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        return hash_160(decoded[1][1])

    # The Genesis Block, self-payments, and pay-by-IP-address payments look like:
    # 65 BYTES:... CHECKSIG
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return hash_160(decoded[0][1])

    # Pay-by-Bitcoin-address TxOuts look like:
    # DUP HASH160 20 BYTES:... EQUALVERIFY CHECKSIG
    match = [opcodes.OP_DUP, opcodes.OP_HASH160, opcodes.OP_PUSHDATA4,
             opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
    if match_decoded(decoded, match):
        return decoded[2][1]

    # BIP11 TxOuts look like one of these:
    multisigs = [
        [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_1,
         opcodes.OP_CHECKMULTISIG], [
             opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
             opcodes.OP_2, opcodes.OP_CHECKMULTISIG
         ], [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4,
             opcodes.OP_PUSHDATA4, opcodes.OP_3, opcodes.OP_CHECKMULTISIG]
    ]
    for match in multisigs:
        if match_decoded(decoded, match):
            return "[" + ','.join([hash_160(decoded[i][1])
                                   for i in range(1, len(decoded) - 2)]) + "]"

    # BIP16 TxOuts look like:
    # HASH160 20 BYTES:... EQUAL
    match = [opcodes.OP_HASH160, 0x14, opcodes.OP_EQUAL]
    if match_decoded(decoded, match):
        return decoded[1][1]

    return "(None)"
コード例 #5
0
ファイル: wallet.py プロジェクト: radare/bitcointools
 def item_callback(type, d):
   should_write = False
   if type in [ 'version', 'name', 'acc' ]:
     should_write = True
   if type in [ 'key', 'wkey', 'ckey' ] and hash_160(d['public_key']) in pubkeys:
     should_write = True
   if pre_put_callback is not None:
     should_write = pre_put_callback(type, d, pubkeys)
   if should_write:
     db_out.put(d["__key__"], d["__value__"])
コード例 #6
0
 def item_callback(type, d):
   should_write = False
   if type in [ 'version', 'name', 'acc' ]:
     should_write = True
   if type in [ 'key', 'wkey', 'ckey' ] and hash_160(d['public_key']) in pubkeys:
     should_write = True
   if pre_put_callback is not None:
     should_write = pre_put_callback(type, d, pubkeys)
   if should_write:
     db_out.put(d["__key__"], d["__value__"])
コード例 #7
0
ファイル: wallet.py プロジェクト: ppcoin/peercointools
 def item_callback(type, d):
     should_write = False
     if type in ["version", "name", "acc"]:
         should_write = True
     if type in ["key", "wkey", "ckey"] and hash_160(d["public_key"]) in pubkeys:
         should_write = True
     if pre_put_callback is not None:
         should_write = pre_put_callback(type, d, pubkeys)
     if should_write:
         db_out.put(d["__key__"], d["__value__"])
コード例 #8
0
 def fingerprint(self):
     return base58.hash_160(point_compress(self.point()))[:4]
コード例 #9
0
	def fingerprint(self):
		return base58.hash_160(point_compress(self.point()))[:4]
コード例 #10
0
ファイル: bitcoin.py プロジェクト: martexcoin/encompass
def hash_160(public_key):
    """Deprecated."""
    return base58.hash_160(public_key)