def _kyc_data_result( self, action: str, ret: ActionResultType, command: offchain.PaymentCommand ) -> offchain.Command: if ret == ActionResult.PASS: if command.is_receiver(): return self._send_kyc_data_and_receipient_signature(command) return command.new_command(status=offchain.Status.ready_for_settlement) return command.new_command( status=offchain.Status.abort, abort_code=offchain.AbortCode.reject_kyc_data, abort_message=f"{action}: {ret}", )
def _ready_for_settlement( self, account_id: str, cmd: offchain.PaymentCommand) -> offchain.Command: if cmd.is_sender(): return cmd.new_command(status=Status.ready_for_settlement) sig_msg = cmd.travel_rule_metadata_signature_message( self.app.diem_account.hrp) sig = self.app.diem_account.sign_by_compliance_key(sig_msg).hex() kyc_data = self.app.store.find(Account, id=account_id).kyc_data_object() return cmd.new_command(recipient_signature=sig, kyc_data=kyc_data, status=Status.ready_for_settlement)
def _offchain_action_clear_soft_match( self, account_id: str, cmd: offchain.PaymentCommand) -> offchain.Command: account = self.app.store.find(Account, id=account_id) if account.reject_additional_kyc_data_request: return self._new_reject_kyc_data(cmd, "no need additional KYC data") return cmd.new_command(additional_kyc_data="{%r: %r}" % ("account_id", account_id))
def _send_kyc_data_and_receipient_signature( command: offchain.PaymentCommand, ) -> offchain.PaymentCommand: sig_msg = command.travel_rule_metadata_signature_message(_hrp()) user_id = get_account_id_from_subaddr( command.receiver_subaddress(_hrp()).hex()) return command.new_command( recipient_signature=_compliance_private_key().sign(sig_msg).hex(), kyc_data=_user_kyc_data(user_id), status=offchain.Status.ready_for_settlement, )
def _send_kyc_data_and_receipient_signature( self, command: offchain.PaymentCommand, ) -> offchain.PaymentCommand: sig_msg = command.travel_rule_metadata_signature_message(self.hrp) subaddress = command.receiver_subaddress(self.hrp) user = self._find_user_by_subaddress(subaddress) return command.new_command( recipient_signature=self.compliance_key.sign(sig_msg).hex(), kyc_data=user.kyc_data(), status=offchain.Status.ready_for_settlement, )
def _offchain_action_evaluate_kyc_data( self, account_id: str, cmd: offchain.PaymentCommand) -> offchain.Command: op_kyc_data = cmd.counterparty_actor_obj().kyc_data if op_kyc_data is None or self.app.kyc_sample.match_kyc_data( "reject", op_kyc_data): return self._new_reject_kyc_data(cmd, "KYC data is rejected") elif self.app.kyc_sample.match_any_kyc_data( ["soft_match", "soft_reject"], op_kyc_data): return cmd.new_command(status=Status.soft_match) elif self.app.kyc_sample.match_kyc_data("minimum", op_kyc_data): return self._ready_for_settlement(account_id, cmd) else: return self._new_reject_kyc_data(cmd, "KYC data is not from samples")
def _new_reject_kyc_data(self, cmd: offchain.PaymentCommand, msg: str) -> offchain.Command: return cmd.new_command(status=Status.abort, abort_code=AbortCode.reject_kyc_data, abort_message=msg)