feat: add doc comments

This commit is contained in:
Aravinth Manivannan 2024-01-08 05:01:55 +05:30
parent 2877f6bd2c
commit d423669265
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -1,3 +1,5 @@
// Go library that implements mCaptcha PoW.
// It is a wrapper over [mcaptcha_pow_sha256](https://crates.io/crates/mcaptcha_pow_sha256).
package gomcaptcha package gomcaptcha
/* /*
@ -7,11 +9,15 @@ package gomcaptcha
*/ */
import "C" import "C"
// Struct representing Proof-of-Work
type ProofOfWork struct { type ProofOfWork struct {
Nonce uint64 Nonce uint64
Result string Result string
} }
// Compute Proof-of-Work over the challenge parameters presented by mCaptcha.
// All input data will be supplied by the mCaptcha instance.
// Outputs Proof-of-Work.
func ProveWork(salt string, phrase string, difficulty uint) ProofOfWork { func ProveWork(salt string, phrase string, difficulty uint) ProofOfWork {
res := C.prove_work(C.CString(salt), res := C.prove_work(C.CString(salt),
C.CString(phrase), C.uint(difficulty)) C.CString(phrase), C.uint(difficulty))
@ -23,6 +29,8 @@ func ProveWork(salt string, phrase string, difficulty uint) ProofOfWork {
} }
// / Check if Proof-of-Work is of sufficient difficulty. Use same salt and difficulty
// values used to compute PoW.
func (v ProofOfWork) IsSufficientDifficulty(salt string, difficulty uint) bool { func (v ProofOfWork) IsSufficientDifficulty(salt string, difficulty uint) bool {
res := C.is_sufficient_difficulty( res := C.is_sufficient_difficulty(
C.ulong(v.Nonce), C.ulong(v.Nonce),
@ -33,6 +41,8 @@ func (v ProofOfWork) IsSufficientDifficulty(salt string, difficulty uint) bool {
} }
// / Check if Proof-of-Work is valid. Use same challenge phrase and salt values
// used to compute PoW.
func (v ProofOfWork) IsValidProof(phrase string, salt string) bool { func (v ProofOfWork) IsValidProof(phrase string, salt string) bool {
res := C.is_valid_proof( res := C.is_valid_proof(
C.ulong(v.Nonce), C.ulong(v.Nonce),