def verify_signature(self, originatorid=None): """Uses the signature to verify that a message came from an originator. Often this is simply used to initialize the originatorid field for the message. Args: originatorid (str): The address of the originator of the object. Returns: bool: True if the passed in originatorid is equal to the originator of the object OR if the originatorid passed in is None. False otherwise. """ try: assert self.Signature if not self._verifyingkey: serialized = self.serialize(signable=True) self._verifyingkey = get_verifying_key(serialized, self.Signature) self._originatorid = pybitcointools.pubtoaddr( self._verifyingkey) return originatorid is None or self._originatorid == originatorid except: logger.exception('unable to verify transaction signature') return False
def _recover_verifying_address(self): assert self.Signature if not self._originator_id: self._originator_id = \ self.signature_cache[self.Signature] if not self._originator_id: self._originator_id = \ pybitcointools.pubtoaddr(self.originator_public_key) self.signature_cache[self.Signature] = self._originator_id
def generate_identifier(signingkey): """Generates encoded version of the public key associated with signingkey. Args: signingkey (str): A private key. Returns: str: An encoded 'address' associated with the public key. """ return pybitcointools.pubtoaddr(pybitcointools.privtopub(signingkey))
def _recover_verifying_address(self): assert self.Signature if not self._originator_id: self._originator_id = \ self.signature_cache[self.Signature] if not self._originator_id: serialized = self.serialize(signable=True) verifying_key = get_verifying_key(serialized, self.Signature) self._originator_id = pybitcointools.pubtoaddr(verifying_key) self.signature_cache[self.Signature] = self._originator_id
def OriginatorID(self): """Return the address of the object originator based on the verifying key derived from the object's signature. Returns: str: The address of the signer of the object. """ assert self.Signature if not self._verifyingkey: serialized = self.serialize(signable=True) self._verifyingkey = get_verifying_key(serialized, self.Signature) self._originatorid = pybitcointools.pubtoaddr(self._verifyingkey) return self._originatorid
def sign_object(self, signingkey): """Generates a string signature for the object using the signing key. Args: signingkey (str): hex encoded private key """ serialized = self.serialize(signable=True) self.Signature = pybitcointools.ecdsa_sign(serialized, signingkey) if not self._verifyingkey: self._verifyingkey = get_verifying_key(serialized, self.Signature) self._originatorid = pybitcointools.pubtoaddr(self._verifyingkey) self._identifier = hashlib.sha256(self.Signature).hexdigest()
def __init__(self, base_url, store_name=None, name='SawtoothClient', txntype_name=None, msgtype_name=None, keystring=None, keyfile=None, disable_client_validation=False): self._base_url = base_url self._message_type = msgtype_name self._transaction_type = txntype_name # an explicit store name takes precedence over a store name # implied by the transaction type self._store_name = None if store_name is not None: self._store_name = store_name.strip('/') elif txntype_name is not None: self._store_name = txntype_name.strip('/') self._communication = _Communication(base_url) self._last_transaction = None self._signing_key = None self._identifier = None self._update_batch = None self._disable_client_validation = disable_client_validation if keystring: LOGGER.debug("set signing key from string\n%s", keystring) self._signing_key = pybitcointools.decode_privkey(keystring, 'wif') elif keyfile: LOGGER.debug("set signing key from file %s", keyfile) try: self._signing_key = pybitcointools.decode_privkey( open(keyfile, "r").read().strip(), 'wif') except IOError as ex: raise ClientException("Failed to load key file: {}".format( str(ex))) if self._signing_key is not None: self._identifier = pybitcointools.pubtoaddr( pybitcointools.privtopub(self._signing_key))
def pair(complexity=512): se = hashlib.sha256(os.urandom(complexity)).hexdigest() priv = privateKeyToWif(se) pub = pybitcointools.privtopub(priv) addr = pybitcointools.pubtoaddr(pub) return priv, pub, addr
if output['scriptPubKey']['type'] == 'multisig' or output['scriptPubKey']['type'] == 'nulldata': data_output.append(output) #grab msigs #extract compressed keys scriptkeys = [] for output in data_output: split_script = output['scriptPubKey']['asm'].split(' ') for val in split_script: if len(val) == 66 or len(val) == 46: scriptkeys.append(val) #filter keys that are ref nonrefkeys = [] for datahex in scriptkeys: if len(datahex) == 66: if pybitcointools.pubtoaddr(datahex, magicbyte) != source and pybitcointools.pubtoaddr(datahex, magicbyte) != compressed: nonrefkeys.append(datahex) else: nonrefkeys.append(datahex) packets = nonrefkeys import Crypto.Cipher.ARC4 key = Crypto.Cipher.ARC4.new(binascii.unhexlify(inputs[0]['txid'])) long_packet = [] for packet in packets: packet = binascii.hexlify(key.decrypt(binascii.unhexlify(packet))) print 'Encoded packet Found : ' + packet long_packet += binascii.unhexlify(packet)[1:]
data_output.append(output) # grab msigs # extract compressed keys scriptkeys = [] for output in data_output: split_script = output["scriptPubKey"]["asm"].split(" ") for val in split_script: if len(val) == 66 or len(val) == 46: scriptkeys.append(val) # filter keys that are ref nonrefkeys = [] for datahex in scriptkeys: if len(datahex) == 66: if ( pybitcointools.pubtoaddr(datahex, magicbyte) != source and pybitcointools.pubtoaddr(datahex, magicbyte) != compressed ): nonrefkeys.append(datahex) else: nonrefkeys.append(datahex) packets = nonrefkeys import Crypto.Cipher.ARC4 key = Crypto.Cipher.ARC4.new(binascii.unhexlify(inputs[0]["txid"])) long_packet = [] for packet in packets: packet = binascii.hexlify(key.decrypt(binascii.unhexlify(packet)))
def generate_identifier(pubkey): return pybitcointools.pubtoaddr(pubkey)
for output in transaction.vout: if output['scriptPubKey']['type'] == 'multisig': multisig_output.append(output) #grab msigs #extract compressed keys scriptkeys = [] for output in multisig_output: #seqnums start at 1, so adjust range split_script = output['scriptPubKey']['asm'].split(' ') for val in split_script: if len(val) == 66: scriptkeys.append(val) #filter keys that are ref nonrefkeys = [] for compressedkey in scriptkeys: if pybitcointools.pubtoaddr( compressedkey) != reference and pybitcointools.pubtoaddr( compressedkey) != compressed: nonrefkeys.append(compressedkey) max_seqnum = len(nonrefkeys) sha_keys = [hashlib.sha256(reference).digest().encode('hex').upper() ] #first sha256 of ref addr, see class B for more info for i in range(max_seqnum): if i < (max_seqnum - 1): sha_keys.append( hashlib.sha256(sha_keys[i]).digest().encode( 'hex').upper()) #keep sha'ing to generate more packets pairs = [] for i in range(len(nonrefkeys)): pairs.append((nonrefkeys[i], sha_keys[i]))
def signing_address(self): return pybitcointools.pubtoaddr( pybitcointools.privtopub(self.SigningKey))
def decode(rawhex): rawBTC = decoderawtransaction(rawhex)['result'] sia = 0 reference = "" inputs = getinputs(rawBTC) senders = inputs['inputs'] for sender in senders: if senders[sender] > sia: reference = sender sia = senders[sender] if reference == "": retval = { "Error": "Can\'t decode MP TX. No valid sending address found." } return { 'Sender': reference, 'BTC': rawBTC, 'MP': retval, 'inputs': senders } if inputs['invalid']: retval = {"Error": "Can\'t decode MP TX. Invalid input type detected"} return { 'Sender': reference, 'BTC': rawBTC, 'MP': retval, 'inputs': senders } #senders = rawtx['result']['vout'][rawBTC['vin'][0]['vout']]['scriptPubKey']['addresses'] #reference = senders[0] #get all multisigs multisig_output = [] dest = "" for output in rawBTC['vout']: if output['scriptPubKey']['type'] == 'multisig': multisig_output.append(output) #grab msigs elif output['scriptPubKey']['type'] in ['pubkeyhash', 'scripthash']: try: for address in output['scriptPubKey']['addresses']: if address not in [ '1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P', 'mpexoDuSkGGqvqrkrjiFng38QPkJQVFyqv' ] and address not in reference: dest = address #return on first successful dest address per spec (highest vout) break except KeyError: pass #extract compressed keys scriptkeys = [] for output in multisig_output: #seqnums start at 1, so adjust range split_script = output['scriptPubKey']['asm'].split(' ') for val in split_script: if len(val) == 66: scriptkeys.append(val) #filter keys that are ref nonrefkeys = [] #check for testnet addresses if reference[:1] in ['2', 'm', 'n']: #testnet address offset = 111 else: offset = 0 for compressedkey in scriptkeys: if pybitcointools.pubtoaddr(compressedkey, offset) not in senders: nonrefkeys.append(compressedkey) max_seqnum = len(nonrefkeys) sha_keys = [hashlib.sha256(reference).digest().encode('hex').upper() ] #first sha256 of ref addr, see class B for more info for i in range(max_seqnum): if i < (max_seqnum - 1): sha_keys.append( hashlib.sha256(sha_keys[i]).digest().encode( 'hex').upper()) #keep sha'ing to generate more packets pairs = [] for i in range(len(nonrefkeys)): pairs.append((nonrefkeys[i], sha_keys[i])) packets = [] for pair in pairs: obpacket = pair[0].upper()[2:-2] shaaddress = pair[1][:-2] print 'Obfus/SHA', obpacket, shaaddress datapacket = '' for i in range(len(obpacket)): if obpacket[i] == shaaddress[i]: datapacket = datapacket + '0' else: bin_ob = int('0x' + obpacket[i], 16) bin_sha = int('0x' + shaaddress[i], 16) xored = hex(bin_ob ^ bin_sha)[2:].upper() datapacket = datapacket + xored packets.append(datapacket) long_packet = '' for packet in packets: print 'Decoded packet #' + str(packet[0:2]) + ' : ' + packet long_packet += packet[2:] retval = "" if long_packet[4:8] == '0032': #Create Fixed Issuance spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5]) + '0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Create Fixed Issuance', 'Ecosystem': int(long_packet[8:10], 16), 'Property Type': int(long_packet[10:14], 16), 'Previous Property ID': int(long_packet[14:22], 16), 'Property Category': spare_bytes.split('00')[0].decode('hex') if len(spare_bytes.split('00')[0]) % 2 == 0 else (spare_bytes.split('00')[0] + "0").decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex') if len(spare_bytes.split('00')[1]) % 2 == 0 else (spare_bytes.split('00')[1] + "0").decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex') if len(spare_bytes.split('00')[2]) % 2 == 0 else (spare_bytes.split('00')[2] + "0").decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex') if len(spare_bytes.split('00')[3]) % 2 == 0 else (spare_bytes.split('00')[3] + "0").decode('hex'), 'Property Data': spare_bytes.split('00')[4].decode('hex') if len(spare_bytes.split('00')[4]) % 2 == 0 else (spare_bytes.split('00')[4] + "0").decode('hex'), 'Number of Properties: ': int(str(int(spare_bytes[len_var_fields:len_var_fields + 16], 16))) } if long_packet[4:8] == '0033': #Create Variable issuance (Crowdsale) spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5]) + '0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Create Variable Issuance (Crowdsale)', 'Ecosystem': int(long_packet[8:10], 16), 'Property Type': int(long_packet[10:14], 16), 'Previous Property ID': int(long_packet[14:22], 16), 'Property Category': spare_bytes.split('00')[0].decode('hex') if len(spare_bytes.split('00')[0]) % 2 == 0 else (spare_bytes.split('00')[0] + "0").decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex') if len(spare_bytes.split('00')[1]) % 2 == 0 else (spare_bytes.split('00')[1] + "0").decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex') if len(spare_bytes.split('00')[2]) % 2 == 0 else (spare_bytes.split('00')[2] + "0").decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex') if len(spare_bytes.split('00')[3]) % 2 == 0 else (spare_bytes.split('00')[3] + "0").decode('hex'), 'Property Data': spare_bytes.split('00')[4].decode('hex') if len(spare_bytes.split('00')[4]) % 2 == 0 else (spare_bytes.split('00')[4] + "0").decode('hex'), 'PropertyID Desired': str(int(spare_bytes[len_var_fields:len_var_fields + 8], 16)), 'Number of Properties': str( int(spare_bytes[len_var_fields + 8:len_var_fields + 8 + 16], 16)), 'Deadline': str( int( spare_bytes[len_var_fields + 8 + 16:len_var_fields + 8 + 16 + 16], 16)), 'Earlybird Bonus': str( int( spare_bytes[len_var_fields + 8 + 16 + 16:len_var_fields + 8 + 16 + 16 + 2], 16)), 'Percentage for Issuer': str( int( spare_bytes[len_var_fields + 8 + 16 + 16 + 2:len_var_fields + 8 + 16 + 16 + 2 + 2], 16)) } if long_packet[4:8] == '0000': #simple send retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Simple Send', 'PropertyID': int(long_packet[8:16], 16), 'Amount': int(long_packet[16:32], 16) } if long_packet[4:8] == '0003': #STO retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Send To Owners', 'PropertyID': int(long_packet[8:16], 16), 'Amount': int(long_packet[16:32], 16) } if long_packet[4:8] == '0014': #DEx Sell Offer retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'DEx Sell Offer', 'PropertyID': int(long_packet[8:16], 16), 'Amount': int(long_packet[16:32], 16), 'BTCDesired': int(long_packet[32:48], 16), 'TimePeriod': int(long_packet[48:50], 16), 'FeeRequired': int(long_packet[50:66], 16), 'Action': int(long_packet[66:68], 16) } if long_packet[4:8] == '0035': #Close Crowdsale Manually retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Close Crowdsale Manually', 'PropertyID': int(long_packet[8:16], 16) } if long_packet[4:8] == '0036': #grant properties #Create Fixed Issuance spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5]) + '0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Create New Grant Property', 'Ecosystem': int(long_packet[8:10], 16), 'Property Type': int(long_packet[10:14], 16), 'Previous Property ID': int(long_packet[14:22], 16), 'Property Category': spare_bytes.split('00')[0].decode('hex') if len(spare_bytes.split('00')[0]) % 2 == 0 else (spare_bytes.split('00')[0] + "0").decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex') if len(spare_bytes.split('00')[1]) % 2 == 0 else (spare_bytes.split('00')[1] + "0").decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex') if len(spare_bytes.split('00')[2]) % 2 == 0 else (spare_bytes.split('00')[2] + "0").decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex') if len(spare_bytes.split('00')[3]) % 2 == 0 else (spare_bytes.split('00')[3] + "0").decode('hex'), 'Property Data': spare_bytes.split('00')[4].decode('hex') if len(spare_bytes.split('00')[4]) % 2 == 0 else (spare_bytes.split('00')[4] + "0").decode('hex') } #'Number of Properties: ': int(str(int(spare_bytes[len_var_fields:len_var_fields+16],16))) if long_packet[4:8] == '0037': #grant properties spare_bytes = ''.join(long_packet[32:]) retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Grant Properties', 'PropertyID': int(long_packet[8:16], 16), 'Amount': int(long_packet[16:32], 16), 'Memo': spare_bytes.split('00')[0].decode('hex') } if long_packet[4:8] == '0038': #revoke properties spare_bytes = ''.join(long_packet[32:]) retval = { 'TxVersion': int(long_packet[0:4], 16), 'TxType': int(long_packet[4:8], 16), 'TxTypeString': 'Revoke Properties', 'PropertyID': int(long_packet[8:16], 16), 'Amount': int(long_packet[16:32], 16), 'Memo': spare_bytes.split('00')[0].decode('hex') } if retval == "": retval = {"Error": "Can\'t decode MP TX"} dest = "" print retval return { 'Sender': reference, 'Receiver': dest, 'MP': retval, 'BTC': rawBTC, 'inputs': senders }
def decode(rawhex, reference): #sort out whether using local or remote API conn = bitcoinrpc.connect_to_local() #conn = bitcoinrpc.connect_to_remote('btcrpc_username','btcrpc_secret',host='127.0.0.1', port=8332) rawBTC = conn.decoderawtransaction(rawhex) if reference == "": retval = {"Error":"Can\'t decode MP TX. No valid sending address found."} return {'Sender':reference,'BTC':rawBTC, 'MP':retval} #get all multisigs multisig_output = [] dest="" for output in rawBTC['vout']: if output['scriptPubKey']['type'] == 'multisig': multisig_output.append(output) #grab msigs elif output['scriptPubKey']['type'] in ['pubkeyhash','scripthash']: try: for address in output['scriptPubKey']['addresses']: if address not in ['1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P','mpexoDuSkGGqvqrkrjiFng38QPkJQVFyqv'] and address not in reference: dest=address #return on first successful dest address per spec (highest vout) break except KeyError: pass #extract compressed keys scriptkeys = [] for output in multisig_output: #seqnums start at 1, so adjust range split_script = output['scriptPubKey']['asm'].split(' ') for val in split_script: if len(val) == 66: scriptkeys.append(val) #filter keys that are ref nonrefkeys = [] #check for testnet addresses if reference[:1] in ['2','m','n']: #testnet address offset=111 else: offset=0 for compressedkey in scriptkeys: if pybitcointools.pubtoaddr(compressedkey,offset) not in reference : nonrefkeys.append(compressedkey) max_seqnum = len(nonrefkeys) sha_keys = [ hashlib.sha256(reference).digest().encode('hex').upper()] #first sha256 of ref addr, see class B for more info for i in range(max_seqnum): if i < (max_seqnum-1): sha_keys.append(hashlib.sha256(sha_keys[i]).digest().encode('hex').upper()) #keep sha'ing to generate more packets pairs = [] for i in range(len(nonrefkeys)): pairs.append((nonrefkeys[i], sha_keys[i] )) packets = [] for pair in pairs: obpacket = pair[0].upper()[2:-2] shaaddress = pair[1][:-2] print 'Obfus/SHA', obpacket, shaaddress datapacket = '' for i in range(len(obpacket)): if obpacket[i] == shaaddress[i]: datapacket = datapacket + '0' else: bin_ob = int('0x' + obpacket[i], 16) bin_sha = int('0x' + shaaddress[i], 16) xored = hex(bin_ob ^ bin_sha)[2:].upper() datapacket = datapacket + xored packets.append(datapacket) long_packet = '' for packet in packets: print 'Decoded packet #' + str(packet[0:2]) + ' : ' + packet long_packet += packet[2:] retval="" #DEBUG print long_packet[4:8] if long_packet[4:8] == '0032': #Create Fixed Issuance spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5])+'0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Create Fixed Issuance', 'Ecosystem': int(long_packet[8:10],16), 'Property Type': int(long_packet[10:14],16), 'Previous Property ID': int(long_packet[14:22],16), 'Property Category': spare_bytes.split('00')[0].decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex'), 'Property Data': ''.join(spare_bytes.split('00')[4]).decode('hex'), 'Number of Properties: ': int(str(int(spare_bytes[len_var_fields:len_var_fields+16],16))) } if long_packet[4:8] == '0033': #Create Variable issuance (Crowdsale) spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5])+'0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Create Variable Issuance (Crowdsale)', 'Ecosystem': int(long_packet[8:10],16), 'Property Type': int(long_packet[10:14],16), 'Previous Property ID': int(long_packet[14:22],16), 'Property Category': spare_bytes.split('00')[0].decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex'), 'Property Data': ''.join(spare_bytes.split('00')[4]).decode('hex'), 'PropertyID Desired': str(int(spare_bytes[len_var_fields:len_var_fields+8],16)), 'Number of Properties': str(int(spare_bytes[len_var_fields+8:len_var_fields+8+16],16)), 'Deadline': str(int(spare_bytes[len_var_fields+8+16:len_var_fields+8+16+16],16)), 'Earlybird Bonus': str(int(spare_bytes[len_var_fields+8+16+16:len_var_fields+8+16+16+2],16)), 'Percentage for Issuer': str(int(spare_bytes[len_var_fields+8+16+16+2:len_var_fields+8+16+16+2+2],16)) } if long_packet[4:8] == '0000': #simple send retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Simple Send', 'PropertyID': int(long_packet[8:16],16), 'Amount': int(long_packet[16:32],16) } if long_packet[4:8] == '0003': #STO retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Send To Owners', 'PropertyID': int(long_packet[8:16],16), 'Amount': int(long_packet[16:32],16) } if long_packet[4:8] == '0014': #DEx Sell Offer retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'DEx Sell Offer', 'PropertyID': int(long_packet[8:16],16), 'Amount': int(long_packet[16:32],16), 'BTCDesired': int(long_packet[32:48],16), 'TimePeriod': int(long_packet[48:50],16), 'FeeRequired': int(long_packet[50:66],16), 'Action': int(long_packet[66:68],16) } if long_packet[4:8] == '0035': #Close Crowdsale Manually retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Close Crowdsale Manually', 'PropertyID': int(long_packet[8:16],16) } if long_packet[4:8] == '0036': #grant properties #Create Fixed Issuance spare_bytes = ''.join(long_packet[22:]) #DEBUG print spare_bytes.split('00') len_var_fields = len(''.join(spare_bytes.split('00')[0:5])+'0000000000') #DEBUG print len_var_fields, spare_bytes[len_var_fields:len_var_fields+16],spare_bytes retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Create New Grant Property', 'Ecosystem': int(long_packet[8:10],16), 'Property Type': int(long_packet[10:14],16), 'Previous Property ID': int(long_packet[14:22],16), 'Property Category': spare_bytes.split('00')[0].decode('hex'), 'Property Subcategory': spare_bytes.split('00')[1].decode('hex'), 'Property Name': spare_bytes.split('00')[2].decode('hex'), 'Property URL': spare_bytes.split('00')[3].decode('hex'), 'Property Data': ''.join(spare_bytes.split('00')[4]).decode('hex') } #'Number of Properties: ': int(str(int(spare_bytes[len_var_fields:len_var_fields+16],16))) if long_packet[4:8] == '0037': #grant properties retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Grant Properties', 'PropertyID': int(long_packet[8:16],16), 'Amount': int(long_packet[16:32],16) } if long_packet[4:8] == '0038': #revoke properties retval = { 'TxVersion': int(long_packet[0:4],16), 'TxType': int(long_packet[4:8],16), 'TxTypeString': 'Revoke Properties', 'PropertyID': int(long_packet[8:16],16), 'Amount': int(long_packet[16:32],16) } if retval == "": retval = {"Error":"Can\'t decode MP TX"} dest = "" retval['sender']=reference retval['recipient']=dest print json.dumps(retval, indent=2)
for output in transaction.vout: if output['scriptPubKey']['type'] == 'multisig': multisig_output.append(output) #grab msigs #extract compressed keys scriptkeys = [] for output in multisig_output: #seqnums start at 1, so adjust range split_script = output['scriptPubKey']['asm'].split(' ') for val in split_script: if len(val) == 66: scriptkeys.append(val) #filter keys that are ref nonrefkeys = [] for compressedkey in scriptkeys: if pybitcointools.pubtoaddr(compressedkey) != reference and pybitcointools.pubtoaddr(compressedkey) != compressed: nonrefkeys.append(compressedkey) max_seqnum = len(nonrefkeys) sha_keys = [ hashlib.sha256(reference).digest().encode('hex').upper()] #first sha256 of ref addr, see class B for more info for i in range(max_seqnum): if i < (max_seqnum-1): sha_keys.append(hashlib.sha256(sha_keys[i]).digest().encode('hex').upper()) #keep sha'ing to generate more packets pairs = [] for i in range(len(nonrefkeys)): pairs.append((nonrefkeys[i], sha_keys[i] )) #DEBUG #print pairs
def is_pubkey_valid(pubkey): try: return encoding.is_valid_bitcoin_address(pubtoaddr(pubkey)) except: return False
def warp(passphrase, salt=""): s1 = _scrypt(passphrase, salt="") s2 = _pbkdf2(passphrase, salt="") key = binascii.hexlify(xor(s1, s2)) return key, bitcoin.pubtoaddr(bitcoin.privtopub(key))
def signing_address(self): return pybitcointools.pubtoaddr(self.public_key())
def get_user_id(user_pub_key, network_code): return pybitcointools.pubtoaddr(user_pub_key, network_code)