def verify_signtures_on_payments(inputs, outputs, signatures, verifier, *extra_fields_for_signing): correct_sigs_from = [] for inp, sig in zip(inputs, signatures): try: sig = base58.b58decode(sig) except Exception as ex: raise InvalidSignatureFormat from ex new_data = [inp, outputs] new_data.extend(extra_fields_for_signing) idr = inp[ADDRESS] ser = serialize_msg_for_signing(new_data) try: verkey = address_to_verkey(idr) except ValueError: continue vr = verifier(verkey) if vr.verify(sig, ser): correct_sigs_from.append(idr) if len(correct_sigs_from) != len(inputs): # All inputs should have signatures present raise InsufficientCorrectSignatures(len(correct_sigs_from), len(inputs)) return correct_sigs_from
def getVerkey(self, identifier): if len(identifier) not in (21, 22): vk = address_to_verkey(identifier) if len(vk) in (43, 44): # Address is the 32 byte verkey return vk return super().getVerkey(identifier)
def test_address_to_verkey_and_vice_versa(): for _ in range(100): signer = SimpleSigner() assert len(signer.naclSigner.verraw) == 32 address = verkey_to_address(signer.verkey) assert len(b58decode(address)) == 36 verkey = address_to_verkey(address) assert len(b58decode(verkey)) == 32 assert signer.naclSigner.verraw == b58decode(verkey) assert signer.verkey == verkey
def xfer_request(inputs, outputs, extra_data=None): payload = { TXN_TYPE: XFER_PUBLIC, OUTPUTS: outputs, EXTRA: extra_data, SIGS: [] } wallet, address, seq_no = inputs[0] request = wallet.sign_using_output(address, seq_no, op=payload) for wallet, address, seq_no in inputs[1:]: wallet.sign_using_output(address, seq_no, request=request) # Setting the `_identifier` to conform to the `Request` structure request._identifier = address_to_verkey(address) return request
def transfer(self, inputs, outputs, extra=None): """ Builds a transfer request. """ payment_signatures = self.payment_signatures(inputs, outputs) outputs_ready = self._prepare_outputs(outputs) inputs_ready = self._prepare_inputs(inputs) first_address = inputs_ready[0][ADDRESS] payload = { TXN_TYPE: XFER_PUBLIC, OUTPUTS: outputs_ready, INPUTS: inputs_ready, EXTRA: extra, SIGS: payment_signatures } identifier = address_to_verkey(first_address) request = self._create_request(payload, identifier) return request