code: def handle_offchain_secretreveal(
          initiator_state: InitiatorTransferState,
          state_change: ReceiveSecretReveal,
          channel_state: NettingChannelState,
          pseudo_random_generator: random.Random,
  ) -> TransitionResult[InitiatorTransferState]:
      
      iteration: TransitionResult[InitiatorTransferState]
      valid_reveal = is_valid_secret_reveal(
          state_change=state_change,
          transfer_secrethash=initiator_state.transfer_description.secrethash,
          secret=state_change.secret,
      )
      sent_by_partner = state_change.sender == channel_state.partner_state.address
      is_channel_open = channel.get_status(channel_state) == CHANNEL_STATE_OPENED
  
      if valid_reveal and is_channel_open and sent_by_partner:
          events = events_for_unlock_lock(
              initiator_state=initiator_state,
              channel_state=channel_state,
              secret=state_change.secret,
              secrethash=state_change.secrethash,
              pseudo_random_generator=pseudo_random_generator,
          )
          iteration = TransitionResult(None, events)
      else:
          events = list()
          iteration = TransitionResult(initiator_state, events)
  
      return iteration
docs: Once the next hop proves it knows the secret, the initiator can unlock
      the mediated transfer.
  
      This will validate the secret, and if valid a new balance proof is sent to
      the next hop with the current lock removed from the merkle tree and the
      transferred amount updated.