Example #1
0
 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
Example #2
0
 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
Example #3
0
    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
Example #4
0
    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
Example #5
0
 def fromprivkey(key):
     self= PrivateKey()
     self.privkey= convert.numfrombytes(key)
     return self
Example #6
0
 def fromminikey(key):
     h= SHA256.new()
     h.update(key)
     self= PrivateKey()
     self.privkey= convert.numfrombytes(h.digest())
     return self
Example #7
0
 def fromprivkey(key):
     self= PrivateKey()
     self.privkey= convert.numfrombytes(key)
     return self
Example #8
0
 def fromminikey(key):
     h= SHA256.new()
     h.update(key)
     self= PrivateKey()
     self.privkey= convert.numfrombytes(h.digest())
     return self