def verify (self, index): outpoint, script, sequence = self.inputs[index] if outpoint == NULL_OUTPOINT: # generation is considered verified - I assume by virtue of its hash value? return 1 else: hash, sig, pubkey = self.get_ecdsa_hash (index) k = KEY() k.set_pubkey (pubkey) return k.verify (hash, sig)
def verify1 (self, pub_key, sig, vhash): if building_txmap: return 1 else: k = KEY() #W ('pub_key=%r\n' % (pub_key,)) k.set_pubkey (pub_key) r = k.verify (vhash, sig) #print 'ecdsa verify...', r return r
def verify1(self, pub_key, sig, vhash): if building_txmap: return 1 else: k = KEY() #W ('pub_key=%r\n' % (pub_key,)) k.set_pubkey(pub_key) r = k.verify(vhash, sig) #print 'ecdsa verify...', r return r
def new_key (self): k = KEY() k.generate() key = k.get_privkey() size = struct.pack ('<Q', len(key)) file = open (self.path, 'ab') file.write (size) file.write (key) file.close() pubkey = k.get_pubkey() addr = key_to_address (rhash (pubkey)) self.addrs[addr] = pubkey self.keys[pubkey] = key self.value[addr] = {} self.write_value_cache() return addr
def verify (self, index): hash, sig, pubkey = self.get_ecdsa_hash (index) k = KEY() k.set_pubkey (pubkey) return k.verify (hash, sig)
def __getitem__ (self, addr): pubkey = self.addrs[addr] key = self.keys[pubkey] k = KEY() k.set_privkey (key) return k
def rhash (s): h1 = hashlib.new ('ripemd160') h1.update (sha256(s).digest()) return h1.digest() def key_to_address (s): checksum = dhash ('\x00' + s)[:4] return '1' + base58_encode ( int ('0x' + (s + checksum).encode ('hex'), 16) ) def pkey_to_address (s): s = '\x80' + s checksum = dhash (s)[:4] return base58_encode ( int ((s + checksum).encode ('hex'), 16) ) if __name__ == '__main__': import sys if len(sys.argv) > 1: nkeys = int (sys.argv[1]) else: nkeys = 1 for i in range (nkeys): k = KEY() k.generate() pri, pub = get_keys (k.get_privkey()) print 'private:', pkey_to_address (pri) print 'public:', key_to_address (rhash (pub))