예제 #1
0
 def parse(cls, s):
     '''Returns a HDPublicKey from an extended key string'''
     # get the bytes from the base58 using raw_decode_base58
     raw = raw_decode_base58(s)
     # check that the length of the raw is 78 bytes, otherwise raise ValueError
     if len(raw) != 78:
         raise ValueError('Not a proper extended key')
     # create a stream
     stream = BytesIO(raw)
     # return the raw parsing of the stream
     return cls.raw_parse(stream)
예제 #2
0
 def parse(cls, wif):
     '''Converts WIF to a PrivateKey object'''
     raw = raw_decode_base58(wif)
     if len(raw) == 34:  # compressed
         if raw[-1] != 1:
             raise ValueError('Invalid WIF')
         raw = raw[:-1]
     secret = big_endian_to_int(raw[1:])
     if raw[0] == 0xef:
         testnet = True
     elif raw[0] == 0x80:
         testnet = False
     else:
         raise ValueError('Invalid WIF')
     return cls(secret, testnet=testnet)
예제 #3
0
 def parse(cls, s):
     raw = raw_decode_base58(s.read(111), num_bytes=82)
     version = raw[:4]
     if version in (TESTNET_XPUB, TESTNET_YPUB, TESTNET_ZPUB):
         testnet = True
     elif version in (MAINNET_XPUB, MAINNET_YPUB, MAINNET_ZPUB):
         testnet = False
     else:
         raise ValueError('not an xpub, ypub or zpub: {}'.format(version))
     depth = raw[4]
     fingerprint = raw[5:9]
     child_number = int.from_bytes(raw[9:13], 'big')
     chain_code = raw[13:45]
     point = S256Point.parse(raw[45:])
     return cls(
         point=point,
         chain_code=chain_code,
         depth=depth,
         fingerprint=fingerprint,
         child_number=child_number,
         testnet=testnet,
     )
예제 #4
0
 def parse(cls, s):
     raw = raw_decode_base58(s.read(111), num_bytes=82)
     version = raw[:4]
     if version in (TESTNET_XPRV, TESTNET_YPRV, TESTNET_ZPRV):
         testnet = True
     elif version in (MAINNET_XPRV, MAINNET_YPRV, MAINNET_ZPRV):
         testnet = False
     else:
         raise ValueError('not an xprv, yprv or zprv: {}'.format(version))
     depth = raw[4]
     fingerprint = raw[5:9]
     child_number = int.from_bytes(raw[9:13], 'big')
     chain_code = raw[13:45]
     private_key = PrivateKey(secret=int.from_bytes(raw[46:], 'big'))
     return cls(
         private_key=private_key,
         chain_code=chain_code,
         depth=depth,
         fingerprint=fingerprint,
         child_number=child_number,
         testnet=testnet,
     )
예제 #5
0
def xpub_parse(cls, s):
    raw = raw_decode_base58(s)
    if len(raw) != 78:
        raise ValueError('Not a proper extended key')
    stream = BytesIO(raw)
    return cls.raw_parse(stream)