def sign_all_inputs(self, tx, secret): signatures = [] key = obelisk.EllipticCurveKey() key.set_secret(secret) for i, input in enumerate(tx.inputs): sighash = generate_signature_hash(tx, i, self.script) # Add sighash::all to end of signature. signature = key.sign(sighash) + "\x01" signatures.append(signature) return signatures
def respond_pubkey_if_mine(self, nickname, ident_pubkey): if ident_pubkey != PUBKEY: print "Not my ident." return pubkey = self._myself.get_pubkey() ec_key = obelisk.EllipticCurveKey() ec_key.set_secret(SECRET) digest = obelisk.Hash(pubkey) signature = ec_key.sign(digest) self.send(response_pubkey(nickname, pubkey, signature))
def sign_all_inputs(self, transaction, secret): signatures = [] key = obelisk.EllipticCurveKey() key.set_secret(secret) for i, _ in enumerate(transaction.inputs): sighash = generate_signature_hash(transaction, i, self.script) # Add sighash::all to end of signature. signature = key.sign(sighash) + "\x01" signatures.append(signature.encode('hex')) return signatures
def respond_pubkey_if_mine(self, nickname, ident_pubkey): if ident_pubkey != PUBKEY: print "Public key does not match your identity" return # Return signed pubkey pubkey = self._myself.get_pubkey() ec_key = obelisk.EllipticCurveKey() ec_key.set_secret(SECRET) digest = obelisk.Hash(pubkey) signature = ec_key.sign(digest) # Send array of nickname, pubkey, signature to transport layer self.send(proto_response_pubkey(nickname, pubkey, signature))
def respond_pubkey_if_mine(self, nickname, ident_pubkey): if ident_pubkey != self.pubkey: self.log.info("Public key does not match your identity") return # Return signed pubkey pubkey = self.cryptor.pubkey # XXX: A Cryptor does not have such a field. ec_key = obelisk.EllipticCurveKey() ec_key.set_secret(self.secret) digest = obelisk.Hash(pubkey) signature = ec_key.sign(digest) # Send array of nickname, pubkey, signature to transport layer self.send(proto_response_pubkey(nickname, pubkey, signature))
def build_actual_tx(unspent, root_hash): print "Building...", root_hash.encode("hex") fee = 10000 optimal_outputs = obelisk.select_outputs(unspent, fee) tx = obelisk.Transaction() for output in optimal_outputs.points: add_input(tx, output.point) add_return_output(tx, root_hash) change = optimal_outputs.change add_output(tx, address, change) key = obelisk.EllipticCurveKey() key.set_secret(secret) for i, output in enumerate(optimal_outputs.points): obelisk.sign_transaction_input(tx, i, key) broadcast.broadcast(tx) tx_hash = hash_transaction(tx) return tx_hash
def main(argv): tx = obelisk.Transaction() for switch, param in zip(argv[1::2], argv[2::2]): if switch == "-i": tx_hash, tx_index = param.split(":") tx_hash = tx_hash.decode("hex") tx_index = int(tx_index) add_input(tx, tx_hash, tx_index) elif switch == "-o": address, value = param.split(":") value = D(value) add_output(tx, address, value) # initialize signing key key = obelisk.EllipticCurveKey() secret = "59cd7a1d11ef24a1687b7c20bdb9f3bb" \ "1cb93908401c503f8d69521dbfcd1c6d".decode("hex") assert len(secret) == 32 key.set_secret(secret) # sign input 0 obelisk.sign_transaction_input(tx, 0, key) print tx print tx.serialize().encode("hex")
import obelisk secret = "6aa6f40c1ad36825bf7be87226f42a72" \ "f5ae28e7daa737611c8c971e4d462a18".decode("hex") key = obelisk.EllipticCurveKey() key.set_secret(secret) digest = obelisk.Hash("message") signature = key.sign(digest) assert key.verify(digest, signature)
def generate_change_key(self, n): key = obelisk.EllipticCurveKey() secret = self.wallet.branch_prime(n).secret assert len(secret) == 32 key.set_secret(secret) return key
def current_change_address(self): key = obelisk.EllipticCurveKey() return self.wallet.branch_prime(self.key_index).address