status-im / specs

Specifications for Status clients.
https://specs.status.im/
MIT License
14 stars 14 forks source link

Document detailing the status-go binding API #136

Open Samyoul opened 4 years ago

Samyoul commented 4 years ago

The compiled status-go binary exposes a number of endpoints that are consumed by desktop and mobile implementations of the Status app.

API endpoints are specified in code her https://github.com/status-im/status-go/tree/develop/mobile

C bindings are generated here https://github.com/status-im/status-go/tree/develop/cmd/library

// Code generated by cmd/library to keep in sync with mobile. DO NOT EDIT.
package main

// #include <stdlib.h>
import "C"
import "unsafe"
import mobile "github.com/status-im/status-go/mobile"

func main() {}
//export MultiAccountDeriveAddresses
func MultiAccountDeriveAddresses (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountDeriveAddresses(C.GoString(paramsJSON)))
}

//export MultiAccountStoreDerivedAccounts
func MultiAccountStoreDerivedAccounts (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountStoreDerivedAccounts(C.GoString(paramsJSON)))
}

//export MultiAccountGenerate
func MultiAccountGenerate (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountGenerate(C.GoString(paramsJSON)))
}

//export MultiAccountGenerateAndDeriveAddresses
func MultiAccountGenerateAndDeriveAddresses (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountGenerateAndDeriveAddresses(C.GoString(paramsJSON)))
}

//export MultiAccountStoreAccount
func MultiAccountStoreAccount (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountStoreAccount(C.GoString(paramsJSON)))
}

//export MultiAccountLoadAccount
func MultiAccountLoadAccount (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountLoadAccount(C.GoString(paramsJSON)))
}

//export MultiAccountReset
func MultiAccountReset () *C.char {
return C.CString(mobile.MultiAccountReset())
}

//export MultiAccountImportPrivateKey
func MultiAccountImportPrivateKey (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountImportPrivateKey(C.GoString(paramsJSON)))
}

//export MultiAccountImportMnemonic
func MultiAccountImportMnemonic (paramsJSON *C.char) *C.char {
return C.CString(mobile.MultiAccountImportMnemonic(C.GoString(paramsJSON)))
}

//export InitKeystore
func InitKeystore (keydir *C.char) *C.char {
return C.CString(mobile.InitKeystore(C.GoString(keydir)))
}

//export LoginWithKeycard
func LoginWithKeycard (accountData *C.char, password *C.char, keyHex *C.char) *C.char {
return C.CString(mobile.LoginWithKeycard(C.GoString(accountData), C.GoString(password), C.GoString(keyHex)))
}

//export SignMessage
func SignMessage (rpcParams *C.char) *C.char {
return C.CString(mobile.SignMessage(C.GoString(rpcParams)))
}

//export AddPeer
func AddPeer (enode *C.char) *C.char {
return C.CString(mobile.AddPeer(C.GoString(enode)))
}

//export SetSignalEventCallback
func SetSignalEventCallback (cb unsafe.Pointer) {
mobile.SetSignalEventCallback(cb)}

//export CompressPublicKey
func CompressPublicKey (key *C.char, outBase *C.char) *C.char {
return C.CString(mobile.CompressPublicKey(C.GoString(key), C.GoString(outBase)))
}

//export CallRPC
func CallRPC (inputJSON *C.char) *C.char {
return C.CString(mobile.CallRPC(C.GoString(inputJSON)))
}

//export ImportOnboardingAccount
func ImportOnboardingAccount (id *C.char, password *C.char) *C.char {
return C.CString(mobile.ImportOnboardingAccount(C.GoString(id), C.GoString(password)))
}

//export Recover
func Recover (rpcParams *C.char) *C.char {
return C.CString(mobile.Recover(C.GoString(rpcParams)))
}

//export StopCPUProfiling
func StopCPUProfiling () *C.char {
return C.CString(mobile.StopCPUProfiling())
}

//export AppStateChange
func AppStateChange (state *C.char) {
mobile.AppStateChange(C.GoString(state))}

//export GenerateAlias
func GenerateAlias (pk *C.char) *C.char {
return C.CString(mobile.GenerateAlias(C.GoString(pk)))
}

//export CreateAccount
func CreateAccount (password *C.char) *C.char {
return C.CString(mobile.CreateAccount(C.GoString(password)))
}

//export ValidateMnemonic
func ValidateMnemonic (mnemonic *C.char) *C.char {
return C.CString(mobile.ValidateMnemonic(C.GoString(mnemonic)))
}

//export DecompressPublicKey
func DecompressPublicKey (key *C.char, outBase *C.char) *C.char {
return C.CString(mobile.DecompressPublicKey(C.GoString(key), C.GoString(outBase)))
}

//export SignTypedData
func SignTypedData (data *C.char, address *C.char, password *C.char) *C.char {
return C.CString(mobile.SignTypedData(C.GoString(data), C.GoString(address), C.GoString(password)))
}

//export CallPrivateRPC
func CallPrivateRPC (inputJSON *C.char) *C.char {
return C.CString(mobile.CallPrivateRPC(C.GoString(inputJSON)))
}

//export StartOnboarding
func StartOnboarding (n C.int, mnemonicPhraseLength C.int) *C.char {
return C.CString(mobile.StartOnboarding(int(n), int(mnemonicPhraseLength)))
}

//export Login
func Login (accountData *C.char, password *C.char) *C.char {
return C.CString(mobile.Login(C.GoString(accountData), C.GoString(password)))
}

//export SaveAccountAndLogin
func SaveAccountAndLogin (accountData *C.char, password *C.char, settingsJSON *C.char, configJSON *C.char, subaccountData *C.char) *C.char {
return C.CString(mobile.SaveAccountAndLogin(C.GoString(accountData), C.GoString(password), C.GoString(settingsJSON), C.GoString(configJSON), C.GoString(subaccountData)))
}

//export SendTransaction
func SendTransaction (txArgsJSON *C.char, password *C.char) *C.char {
return C.CString(mobile.SendTransaction(C.GoString(txArgsJSON), C.GoString(password)))
}

//export StartCPUProfile
func StartCPUProfile (dataDir *C.char) *C.char {
return C.CString(mobile.StartCPUProfile(C.GoString(dataDir)))
}

//export SignHash
func SignHash (hexEncodedHash *C.char) *C.char {
return C.CString(mobile.SignHash(C.GoString(hexEncodedHash)))
}

//export OpenAccounts
func OpenAccounts (datadir *C.char) *C.char {
return C.CString(mobile.OpenAccounts(C.GoString(datadir)))
}

//export RemoveOnboarding
func RemoveOnboarding () {
mobile.RemoveOnboarding()}

//export VerifyAccountPassword
func VerifyAccountPassword (keyStoreDir *C.char, address *C.char, password *C.char) *C.char {
return C.CString(mobile.VerifyAccountPassword(C.GoString(keyStoreDir), C.GoString(address), C.GoString(password)))
}

//export Logout
func Logout () *C.char {
return C.CString(mobile.Logout())
}

//export HashTransaction
func HashTransaction (txArgsJSON *C.char) *C.char {
return C.CString(mobile.HashTransaction(C.GoString(txArgsJSON)))
}

//export GetNodesFromContract
func GetNodesFromContract (rpcEndpoint *C.char, contractAddress *C.char) *C.char {
return C.CString(mobile.GetNodesFromContract(C.GoString(rpcEndpoint), C.GoString(contractAddress)))
}

//export ChaosModeUpdate
func ChaosModeUpdate (on C.int) *C.char {
return C.CString(mobile.ChaosModeUpdate(on == 1))
}

//export ValidateNodeConfig
func ValidateNodeConfig (configJSON *C.char) *C.char {
return C.CString(mobile.ValidateNodeConfig(C.GoString(configJSON)))
}

//export SendTransactionWithSignature
func SendTransactionWithSignature (txArgsJSON *C.char, sigString *C.char) *C.char {
return C.CString(mobile.SendTransactionWithSignature(C.GoString(txArgsJSON), C.GoString(sigString)))
}

//export ConnectionChange
func ConnectionChange (typ *C.char, expensive C.int) {
mobile.ConnectionChange(C.GoString(typ), int(expensive))}

//export Identicon
func Identicon (pk *C.char) *C.char {
return C.CString(mobile.Identicon(C.GoString(pk)))
}

//export RecoverAccount
func RecoverAccount (password *C.char, mnemonic *C.char) *C.char {
return C.CString(mobile.RecoverAccount(C.GoString(password), C.GoString(mnemonic)))
}

//export HashMessage
func HashMessage (message *C.char) *C.char {
return C.CString(mobile.HashMessage(C.GoString(message)))
}

//export HashTypedData
func HashTypedData (data *C.char) *C.char {
return C.CString(mobile.HashTypedData(C.GoString(data)))
}

//export SignGroupMembership
func SignGroupMembership (content *C.char) *C.char {
return C.CString(mobile.SignGroupMembership(C.GoString(content)))
}

//export ResetChainData
func ResetChainData () *C.char {
return C.CString(mobile.ResetChainData())
}

//export SaveAccountAndLoginWithKeycard
func SaveAccountAndLoginWithKeycard (accountData *C.char, password *C.char, settingsJSON *C.char, configJSON *C.char, subaccountData *C.char, keyHex *C.char) *C.char {
return C.CString(mobile.SaveAccountAndLoginWithKeycard(C.GoString(accountData), C.GoString(password), C.GoString(settingsJSON), C.GoString(configJSON), C.GoString(subaccountData), C.GoString(keyHex)))
}

//export WriteHeapProfile
func WriteHeapProfile (dataDir *C.char) *C.char {
return C.CString(mobile.WriteHeapProfile(C.GoString(dataDir)))
}

//export ExportNodeLogs
func ExportNodeLogs () *C.char {
return C.CString(mobile.ExportNodeLogs())
}

//export ExtractGroupMembershipSignatures
func ExtractGroupMembershipSignatures (signaturePairsStr *C.char) *C.char {
return C.CString(mobile.ExtractGroupMembershipSignatures(C.GoString(signaturePairsStr)))
}
arnetheduck commented 4 years ago

Hm, writing a spec for this seems both a bit early and a bit like busy work - ie this would be a natural part of the API documentation of the library itself, and it's probably too early to formalize it into a spec per se

Samyoul commented 4 years ago

You are probably right. We need somewhere to document the API, and on reflection in the spec may not be the correct place. I believe that some global document would be a better location than in the library directly as, although the lib exposes the API, the various Status clients are dependant on the API and each need to implement calls to the methods.