コード例 #1
0
	def new(self):
		ecdsaPrivkey = ecdsa.SigningKey.generate(curve=ecdsa.curves.SECP256k1)
		ecdsaPubkey = ecdsaPrivkey.get_verifying_key()

		rawPrivkey = ecdsaPrivkey.to_string()
		rawPubkey = "\x00" + util.ripemd160(util.sha256("\x04" + ecdsaPubkey.to_string()))
		pubkeyChecksum = util.sha256(util.sha256(rawPubkey))[:4]
		rawPubkey += pubkeyChecksum

		pubkey = util.b58encode(rawPubkey)
		privkey = "\x80" + rawPrivkey
		privkeyChecksum = util.sha256(util.sha256(privkey))[:4]
		privkey = util.b58encode(privkey + privkeyChecksum)

		return self(pubkey, privkey, rawPubkey, rawPrivkey)
コード例 #2
0
    def from_privkey(cls, ecdsaPrivkey):
        ecdsaPubkey = ecdsaPrivkey.get_verifying_key()

        rawPrivkey = ecdsaPrivkey.to_string()
        rawPubkey = cls.PUBLIC_KEY_PREFIX + ripemd160(
            sha256("\x04" + ecdsaPubkey.to_string()))
        pubkeyChecksum = sha256(sha256(rawPubkey))[:4]
        rawPubkey += pubkeyChecksum

        pubkey = util.b58encode(rawPubkey)
        privkey = cls.PRIVATE_KEY_PREFIX + rawPrivkey
        privkeyChecksum = sha256(sha256(privkey))[:4]
        privkey = util.b58encode(privkey + privkeyChecksum)

        return cls(pubkey, privkey, rawPubkey, rawPrivkey)
コード例 #3
0
ファイル: meat.py プロジェクト: Ademan/ngcccbase
    def from_privkey(cls, ecdsaPrivkey):
        ecdsaPubkey = ecdsaPrivkey.get_verifying_key()

        rawPrivkey = ecdsaPrivkey.to_string()
        rawPubkey = cls.PUBLIC_KEY_PREFIX + ripemd160(
            sha256("\x04" + ecdsaPubkey.to_string()))
        pubkeyChecksum = sha256(sha256(rawPubkey))[:4]
        rawPubkey += pubkeyChecksum

        pubkey = util.b58encode(rawPubkey)
        privkey = cls.PRIVATE_KEY_PREFIX + rawPrivkey
        privkeyChecksum = sha256(sha256(privkey))[:4]
        privkey = util.b58encode(privkey + privkeyChecksum)

        return cls(pubkey, privkey, rawPubkey, rawPrivkey)
コード例 #4
0
    def new(self):
        ecdsaPrivkey = ecdsa.SigningKey.generate(curve=ecdsa.curves.SECP256k1)
        ecdsaPubkey = ecdsaPrivkey.get_verifying_key()

        rawPrivkey = ecdsaPrivkey.to_string()
        rawPubkey = "\x00" + ripemd160(
            sha256("\x04" + ecdsaPubkey.to_string()))
        pubkeyChecksum = sha256(sha256(rawPubkey))[:4]
        rawPubkey += pubkeyChecksum

        pubkey = util.b58encode(rawPubkey)
        privkey = "\x80" + rawPrivkey
        privkeyChecksum = sha256(sha256(privkey))[:4]
        privkey = util.b58encode(privkey + privkeyChecksum)

        return self(pubkey, privkey, rawPubkey, rawPrivkey)
コード例 #5
0
ファイル: meat.py プロジェクト: domtancredi/ngcccbase
    def new(cls):
        # Generates warner ECDSA objects
        ecdsaPrivkey = ecdsa.SigningKey.generate(curve=ecdsa.curves.SECP256k1)
        ecdsaPubkey = ecdsaPrivkey.get_verifying_key()

        rawPrivkey = ecdsaPrivkey.to_string()
        rawPubkey = "\x00" + ripemd160(sha256("\x04" + ecdsaPubkey.to_string()))
        pubkeyChecksum = sha256(sha256(rawPubkey))[:4]
        rawPubkey += pubkeyChecksum

        pubkey = util.b58encode(rawPubkey)
        privkey = "\x80" + rawPrivkey
        privkeyChecksum = sha256(sha256(privkey))[:4]
        privkey = util.b58encode(privkey + privkeyChecksum)

        return cls(pubkey, privkey, rawPubkey, rawPrivkey)
コード例 #6
0
    def post(self):
        conn = self.application.settings['db_connection']
        state = unicode(self.request.body, 'utf_8')
        state_hash = buffer(hashlib.sha1(state.encode('utf_8')).digest())
        row = conn.execute("select id from states where state_hash=?", (state_hash,)).fetchone()
        stateid = row[0] if row else conn.execute("insert into states(state, state_hash) values (?, ?)", (state, state_hash)).lastrowid

        self.set_header("Content-Type", "text/plain")
        self.write(util.b58encode(stateid))
コード例 #7
0
ファイル: ui_server.py プロジェクト: DajunKou/firefly
def shorten(state, db_conn):
    """Returns the b58encoded id of the provided full firefly
    state description. Creates a new entry for state if one
    doesn't already exist in the db.
    """
    state = unicode(state, 'utf_8')
    state_hash = buffer(hashlib.sha1(state.encode('utf_8')).digest())
    row = db_conn.execute("select id from states where state_hash=?", (state_hash,)).fetchone()
    stateid = row[0] if row else db_conn.execute("insert into states(state, state_hash) values (?, ?)", (state, state_hash)).lastrowid
    return util.b58encode(stateid)
コード例 #8
0
ファイル: ui_server.py プロジェクト: DajunKou/firefly
    def get(self, name):
        conn = self.application.settings['db_connection']
        stateid = conn.execute("select stateid from names where name = ?", (name,)).fetchone()

        if stateid:
            b58id = util.b58encode(stateid[0])
            url = self.application.settings['url_path_prefix']
            self.redirect('%s?incoming=%s#!%s' % (url, name, b58id))
        else:
            self.redirect('/')
コード例 #9
0
    def get(self, name):
        conn = self.application.settings['db_connection']
        stateid = conn.execute("select stateid from names where name = ?",
                               (name, )).fetchone()

        if stateid:
            b58id = util.b58encode(stateid[0])
            url = self.application.settings['url_path_prefix']
            self.redirect('%s?incoming=%s#!%s' % (url, name, b58id))
        else:
            self.redirect('/')
コード例 #10
0
def shorten(state, db_conn):
    """Returns the b58encoded id of the provided full firefly
    state description. Creates a new entry for state if one
    doesn't already exist in the db.
    """
    state = unicode(state, 'utf_8')
    state_hash = buffer(hashlib.sha1(state.encode('utf_8')).digest())
    row = db_conn.execute("select id from states where state_hash=?",
                          (state_hash, )).fetchone()
    stateid = row[0] if row else db_conn.execute(
        "insert into states(state, state_hash) values (?, ?)",
        (state, state_hash)).lastrowid
    return util.b58encode(stateid)