def frompubkey(key): self= PublicKey() if len(key)==33 and (ord(key[0])==2 or ord(key[0])==3): self.point= ecdsa.ec.decompress(convert.numfrombytes(key[1:]), ord(key[0])-2) elif len(key)==65 and ord(key[0])==4: self.point= ecdsa.ec.point(convert.numfrombytes(key[1:33]), convert.numfrombytes(key[33:65])) else: print(key.encode("hex")) raise Exception("invalid point representation") return self
def frompubkey(key): self= PublicKey() if len(key)==33 and (ord(key[0])==2 or ord(key[0])==3): self.point= ecdsa.ec.decompress(convert.numfrombytes(key[1:]), ord(key[0])-2) elif len(key)==65 and ord(key[0])==4: self.point= ecdsa.ec.point(convert.numfrombytes(key[1:33]), convert.numfrombytes(key[33:65])) else: print key.encode("hex") raise Exception("invalid point representation") return self
def fromwallet(b58): self= PrivateKey() data= base58.decode(b58) if not len(data) in (37, 38): print("wallet len != 37/38: %s" % data.encode("hex")) raise Exception("Invalid wallet length") self.version= ord(data[0:1]) self.privkey= convert.numfrombytes(data[1:33]) if len(data)==38: # todo: ?? what is this for? self.compressed= ord(data[33]) if shasha(data[:-4])[:4] != data[-4:]: print("wallet: %s: %s != %s" % (data[:33].encode("hex"), data[33:].encode("hex"), shasha(data[0:33])[:4])) raise Exception("Invalid base58 checksum") return self
def fromwallet(b58): self= PrivateKey() data= base58.decode(b58) if not len(data) in (37, 38): print "wallet len != 37/38: %s" % data.encode("hex") raise Exception("Invalid wallet length") self.version= ord(data[0]) self.privkey= convert.numfrombytes(data[1:33]) if len(data)==38: # todo: ?? what is this for? self.compressed= ord(data[33]) if shasha(data[:-4])[:4] != data[-4:]: print "wallet: %s: %s != %s" % (data[:33].encode("hex"), data[33:].encode("hex"), shasha(data[0:33])[:4]) raise Exception("Invalid base58 checksum") return self
def fromprivkey(key): self= PrivateKey() self.privkey= convert.numfrombytes(key) return self
def fromminikey(key): h= SHA256.new() h.update(key) self= PrivateKey() self.privkey= convert.numfrombytes(h.digest()) return self