def sign_message(message, secret): signature = MessageSignature() message = DataChunk(message) assert isinstance(secret, EcPrivate) if lib.bc_sign_message(signature._obj, message._obj, secret._obj) != 1: return None return signature.data
def from_data(cls, encoded, prefix): data = DataChunk(encoded) self = cls() result = lib.bc_script__from_data(self._obj, data._obj, prefix) == 1 if not result: return None return self
def from_data(cls, uncoded, minimal=True): data = DataChunk(uncoded) if minimal: obj = lib.bc_create_operation_Data(data._obj) else: obj = lib.bc_create_operation_Data_nominimal(data._obj) return cls(obj)
def verify_message(message, address, signature): message = DataChunk(message) if isinstance(address, str): address = PaymentAddress(address) assert isinstance(address, PaymentAddress) signature = MessageSignature.from_bytes(signature) return lib.bc_verify_message(message._obj, address._obj, signature._obj) \ == 1
def check_signature(signature, sighash_type, public_key, script_code, tx, input_index): public_key = DataChunk(public_key) return lib.bc_script__check_signature(signature._obj, sighash_type.value, public_key._obj, script_code._obj, tx._obj, input_index) == 1
def from_data(cls, data, wire=True): data = DataChunk(data) self = cls() if wire: result = lib.bc_transaction__from_data(self._obj, data._obj) else: result = lib.bc_transaction__from_data_nowire(self._obj, data._obj) if result != 1: return None return self
def create_mnemonic(entropy, lexicon=None): """Create a new mnenomic (list of words) from provided entropy and a dictionary selection. The mnemonic can later be converted to a seed for use in wallet creation. Entropy byte count must be evenly divisible by 4.""" entropy = DataChunk(entropy) if lexicon is None: obj = lib.bc_create_mnemonic(entropy._obj) else: obj = lib.bc_create_mnemonic_Dict(entropy._obj, lexicon._obj) return [str(word) for word in StringList(obj)]
def to_null_data_pattern(data): data = DataChunk(data) obj = lib.bc_script__to_null_data_pattern(data._obj) return list(OperationList(obj))
def to_chunk(self): obj = lib.bc_stealth_address__to_chunk(self._obj) return DataChunk(obj).data
def blocks(self): obj = lib.bc_binary__blocks(self._obj) return DataChunk(obj).data
def to_data(self): obj = lib.bc_point__to_data(self._obj) return DataChunk(obj)
def from_data(cls, decoded): decoded = DataChunk(decoded) obj = lib.bc_create_stealth_address_Data(decoded._obj) return cls(obj)
def data(self): obj = lib.bc_operation__data(self._obj) return DataChunk(obj).data
def from_data(cls, data): data = DataChunk(data) obj = lib.bc_point__factory_from_data(data._obj) return cls(obj)
def from_data(cls, size, blocks): blocks = DataChunk(blocks) obj = lib.bc_create_binary_Blocks(size, blocks._obj) return cls(obj)
def encode(self): out = DataChunk() if lib.bc_encode_signature(out._obj, self._obj) == 0: return None return out.data
def from_seed(cls, seed, prefixes): seed = DataChunk(seed) obj = lib.bc_create_hd_private_Seed(seed._obj, prefixes) return cls(obj)
def create_ephemeral_key(seed): out_secret = EcSecret() seed = DataChunk(seed) if lib.bc_create_ephemeral_key(out_secret._obj, seed._obj) != 1: return None return out_secret
def hash_message(message): message = DataChunk(message) return lib.hash_message(message._obj)
def bitcoin_hash(data): data = DataChunk(data) obj = lib.bc_bitcoin_hash(data._obj) return HashDigest(obj)
def to_data(self): obj = lib.bc_header__to_data(self._obj) return DataChunk(obj).data
def to_pay_public_key_pattern(data): data = DataChunk(data) obj = lib.bc_script__to_pay_public_key_pattern(data._obj) return list(OperationList(obj))
def data(self): obj = lib.bc_machine_number__data(self._obj) return DataChunk(obj).data
def find_and_delete(self, endorsements): stack = DataStack() for endorse in endorsements: endorse = DataChunk(endorse) stack.append(endorse) lib.bc_script__find_and_delete(self._obj, stack._obj)
def to_data(self): obj = lib.bc_output__to_data(self._obj) return DataChunk(obj).data
def to_data(self, prefix): obj = lib.bc_script__to_data(self._obj, prefix) return DataChunk(obj).data
def to_data(self, wire=True): if wire: obj = lib.bc_transaction__to_data(self._obj) else: obj = lib.bc_transaction__to_data_nowire(self._obj) return DataChunk(obj).data
def create_stealth_data(filter_, seed): out_stealth_data = DataChunk() out_secret = EcSecret() #TODO: unsure how to work with filter and binary type assert False
def from_der(cls, data, strict): der = DataChunk(data) out = EcSignature() if lib.bc_parse_signature(out._obj, der._obj, strict) == 0: return None return out