 {bufeq_secure,dict_merge,unix_time} = require('iced-utils').util
 kbmc                      = require('keybase-messenger-core')
 idcheckers                = kbmc.id.checkers
+pgpchecker                = kbmc.pgp.checker
 {Cipher}                  = kbmc
 
 #=============================================================================

  input_template : -> dict_merge super(), {
    chunk_zid : checkers.nnint
    msg_zid : checkers.nnint
    data : Cipher.checker
  }

  #-----------------

  _handle : (cb) ->
    q = "INSERT INTO chunks (thread_id, msg_zid, chunk_zid, data) VALUES(?,?,?,FROM_BASE64(?))"
    args = [ H(@input.i), @input.msg_zid, @input.chunk_zid, Cipher.encode_to_db(@input.data) ]
    await mm.db.update1 q, args, defer err
    cb err


exports.bind_to_app = (app) ->
  PostHeaderHandler.bind app, api_route("msg/header"), POST
  PostChunkHandler.bind app, api_route("msg/chunk"), POST
  PostSigHandler.bind app, api_route("msg/sig"), POST

#=============================================================================

