2023-08-09 11:32:00 -04:00
package main
/ *
# include < cgo_utils . h >
* /
import "C"
2023-10-28 19:37:53 -04:00
import (
"unsafe"
"github.com/waku-org/go-waku/library"
)
2023-08-09 11:32:00 -04:00
// Decode a waku message using a 32 bytes symmetric key. The key must be a hex encoded string with "0x" prefix
//
//export waku_decode_symmetric
2023-10-28 19:37:53 -04:00
func waku_decode_symmetric ( messageJSON * C . char , symmetricKey * C . char , cb C . WakuCallBack , userData unsafe . Pointer ) C . int {
2023-12-15 10:46:21 -04:00
return singleFnExecNoCtx ( func ( ) ( string , error ) {
2023-08-09 11:32:00 -04:00
return library . DecodeSymmetric ( C . GoString ( messageJSON ) , C . GoString ( symmetricKey ) )
2023-10-28 19:37:53 -04:00
} , cb , userData )
2023-08-09 11:32:00 -04:00
}
// Decode a waku message using a secp256k1 private key. The key must be a hex encoded string with "0x" prefix
//
//export waku_decode_asymmetric
2023-10-28 19:37:53 -04:00
func waku_decode_asymmetric ( messageJSON * C . char , privateKey * C . char , cb C . WakuCallBack , userData unsafe . Pointer ) C . int {
2023-12-15 10:46:21 -04:00
return singleFnExecNoCtx ( func ( ) ( string , error ) {
2023-08-09 11:32:00 -04:00
return library . DecodeAsymmetric ( C . GoString ( messageJSON ) , C . GoString ( privateKey ) )
2023-10-28 19:37:53 -04:00
} , cb , userData )
2023-08-09 11:32:00 -04:00
}
// Encrypt a message with a secp256k1 public key.
// publicKey must be a hex string prefixed with "0x" containing a valid secp256k1 public key.
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
// The message version will be set to 1
//
//export waku_encode_asymmetric
2023-10-28 19:37:53 -04:00
func waku_encode_asymmetric ( messageJSON * C . char , publicKey * C . char , optionalSigningKey * C . char , cb C . WakuCallBack , userData unsafe . Pointer ) C . int {
2023-12-15 10:46:21 -04:00
return singleFnExecNoCtx ( func ( ) ( string , error ) {
2023-08-09 11:32:00 -04:00
return library . EncodeAsymmetric ( C . GoString ( messageJSON ) , C . GoString ( publicKey ) , C . GoString ( optionalSigningKey ) )
2023-10-28 19:37:53 -04:00
} , cb , userData )
2023-08-09 11:32:00 -04:00
}
// Encrypt a message with a 32 bytes symmetric key
// symmetricKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
// The message version will be set to 1
//
//export waku_encode_symmetric
2023-10-28 19:37:53 -04:00
func waku_encode_symmetric ( messageJSON * C . char , symmetricKey * C . char , optionalSigningKey * C . char , cb C . WakuCallBack , userData unsafe . Pointer ) C . int {
2023-12-15 10:46:21 -04:00
return singleFnExecNoCtx ( func ( ) ( string , error ) {
2023-08-09 11:32:00 -04:00
return library . EncodeSymmetric ( C . GoString ( messageJSON ) , C . GoString ( symmetricKey ) , C . GoString ( optionalSigningKey ) )
2023-10-28 19:37:53 -04:00
} , cb , userData )
2023-08-09 11:32:00 -04:00
}