code: def set_offchain_secret(
          state: MediatorTransferState,
          channelidentifiers_to_channels: ChannelMap,
          secret: Secret,
          secrethash: SecretHash,
  ) -> List[Event]:
      
      state.secret = secret
  
      for pair in state.transfers_pair:
          payer_channel = channelidentifiers_to_channels.get(
              pair.payer_transfer.balance_proof.channel_identifier,
          )
          if payer_channel:
              channel.register_offchain_secret(
                  payer_channel,
                  secret,
                  secrethash,
              )
  
          payee_channel = channelidentifiers_to_channels.get(
              pair.payee_transfer.balance_proof.channel_identifier,
          )
          if payee_channel:
              channel.register_offchain_secret(
                  payee_channel,
                  secret,
                  secrethash,
              )
  
      # The secret should never be revealed if `waiting_transfer` is not None.
      # For this to happen this node must have received a transfer, which it did
      # *not* mediate, and neverthless the secret was revealed.
      #
      # This can only be possible if the initiator reveals the secret without the
      # target's secret request, or if the node which sent the `waiting_transfer`
      # has sent another transfer which reached the target (meaning someone along
      # the path will lose tokens).
      if state.waiting_transfer:
          payer_channel = channelidentifiers_to_channels.get(
              state.waiting_transfer.transfer.balance_proof.channel_identifier,
          )
          if payer_channel:
              channel.register_offchain_secret(
                  payer_channel,
                  secret,
                  secrethash,
              )
  
          unexpected_reveal = EventUnexpectedSecretReveal(
              secrethash=secrethash,
              reason='The mediator has a waiting transfer.',
          )
          return [unexpected_reveal]
  
      return list()
docs: Set the secret to all mediated transfers.