46 lines
900 B
Go
46 lines
900 B
Go
package "mcaptcha_pow_go"
|
|
|
|
/*
|
|
#cgo LDFLAGS: ./lib/libmcaptcha_pow_ffi.a -ldl
|
|
#include "./mcaptcha-pow-ffi/mcaptcha_pow_ffi.h"
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
import "fmt"
|
|
|
|
type ProofOfWork struct {
|
|
nonce uint64
|
|
result string
|
|
}
|
|
|
|
func ProveWork(salt string, phrase string, difficulty uint) ProofOfWork {
|
|
res := C.prove_work(C.CString(salt),
|
|
C.CString(phrase), C.uint(difficulty))
|
|
|
|
return ProofOfWork{
|
|
nonce: uint64(res.nonce),
|
|
result: C.GoString(res.result),
|
|
}
|
|
|
|
}
|
|
|
|
func (v ProofOfWork) IsSufficientDifficulty(salt string, difficulty uint) bool {
|
|
res := C.is_sufficient_difficulty(
|
|
C.ulong(v.nonce),
|
|
C.CString(v.result),
|
|
C.CString(salt),
|
|
C.uint(difficulty))
|
|
return bool(res)
|
|
|
|
}
|
|
|
|
func (v ProofOfWork) IsValidProof(phrase string, salt string) bool {
|
|
res := C.is_valid_proof(
|
|
C.ulong(v.nonce),
|
|
C.CString(v.result),
|
|
C.CString(phrase),
|
|
C.CString(salt))
|
|
return bool(res)
|
|
|
|
}
|