 (ns caesium.crypto.sign
   (:refer-clojure :exclude [bytes])
-  (:require [caesium.binding :refer [defconsts sodium]]
+  (:require [caesium.binding :as b]
             [caesium.byte-bufs :refer [buflen]]))
 
-(defconsts [bytes seedbytes publickeybytes secretkeybytes primitive])
+(b/defconsts [bytes seedbytes publickeybytes secretkeybytes primitive])
 
 (defn keypair!
   "Generate a public-key and secret-key for signing with

  ([pk sm]
   (let [smlen (buflen sm)
         m (byte-array (- smlen bytes))
         res (.crypto_sign_open sodium m nil sm smlen pk)]
     (if (zero? res)
       m
       (throw (RuntimeException. "Signature validation failed")))))
  ([pk msg sig]
   (let [mlen (buflen msg)
         res (.crypto_sign_verify_detached sodium sig msg mlen pk)]
     (when-not (zero? res)
       (throw (RuntimeException. "Signature validation failed"))))))

  ([]
   (let [pk (byte-array publickeybytes)
         sk (byte-array secretkeybytes)]
     (.crypto_sign_keypair b/sodium pk sk)
     {:public pk
      :secret sk}))
  ([seed]
   (let [pk (byte-array publickeybytes)
         sk (byte-array secretkeybytes)]
     (.crypto_sign_seed_keypair b/sodium pk sk seed)
     {:public pk
      :secret sk})))

