Documentation ¶
Index ¶
- Constants
- Variables
- func DecryptAES(sharedKey []byte, ciphertext string) ([]byte, error)
- func EncryptAES(sharedKey []byte, plaintext []byte) (string, error)
- func GetErrorCode(err error) uint16
- func GetMethodParams(method Method) (implementation MethodType, param []ParamType)
- type Method
- type MethodType
- type NetworkParams
- type NetworkType
- type ParamType
- type PrivateKey
Constants ¶
const ( // WelcomeText is an easter egg placed in the code for cryptography enthusiasts // to attempt solving. // Should you be successful in decrypting it, please do what it says! WelcomeText = "Pi encrypted 715b48145c501951595355505d194050475a135a5d4251595d5d" + "40021301705647585b5d600c7d527f615760417f63477d5a696045610348437f470d790757" // FullDateFormat defines the full date format supported for user display. FullDateFormat = "Mon 15:04:05 2006-01-02" // FilePerm defines the file permission used to manage the application data. FilePerm = os.FileMode(0o0700) // JSONRPCVersion defines the JSON version supportted for all the backend requests // recieved by the server. JSONRPCVersion = "2.0" )
const ( // Uint8Type defines unsigned integer parameter value type of uint8. Uint8Type ParamType = "uint8" // Uint16Type defines unsigned integer parameter value type of uint16. Uint16Type ParamType = "uint16" // Uint32Type defines unsigned integer parameter value type of uint32. Uint32Type ParamType = "uint32" // Uint64Type defines unsigned integer parameter value type of uint64. Uint64Type ParamType = "uint64" // AddressType defines the address type as supportted in ethereum types. AddressType ParamType = "address" // StringType defines a string value type. StringType ParamType = "string" // LimitType defines unsigned LIMIT integer parameter of value type uint8. LimitType ParamType = "uint8_LIMIT" // MaxLimit restricts the max limit that can be set into 100 when querying // more than 1 record. MaxLimit = uint(100) // UnsupportedType defines all other types not classified as int, float or string UnsupportedType ParamType = "unsupported" LocalType MethodType = iota // Locally implemented ContractType // Implemented by the contracts ServerKeyType // Method for route /serverpubkey UnknownType // method not supported CreateBond Method = "createBond" AddMessage Method = "addMessage" SignBondStatus Method = "signBondStatus" UpdateBodyInfo Method = "updateBodyInfo" UpdateBondHolder Method = "updateBondHolder" UpdateBondStatus Method = "updateBondStatus" GetServerPubKey Method = "getServerPubKey" GetBonds Method = "getBonds" GetBondByAddress Method = "getBondByAddress" GetChats Method = "getChats" GetLastSyncedBlock Method = "getLastSyncedBlock" UpdateBondBodyTerms Method = "updateBondBodyTerms" UpdateBondMotivation Method = "updateBondMotivation" UpdateHolder Method = "updateHolder" UpdateLastStatus Method = "updateLastStatus" InsertNewBondCreated Method = "insertNewBondCreated" InsertNewChatMessage Method = "insertNewchatMsg" InsertStatusChange Method = "insertStatusChange" InsertStatusSigned Method = "insertStatusSigned" )
const UnitTestNet = "unittest"
UnitTestNet is the sapphire wrapper network set when running tests on a mocked wrapper instance.
Variables ¶
var ( // ErrCorruptedConfig error is returned if one of the deployment configs // doesn't match the expected values. ErrCorruptedConfig = errors.New("deployment config has been corrupted. Regenerate it") // ErrInvalidPriKey returns if private key validation fails. ErrInvalidPriKey = errors.New("Invalid private key used to sign transactions") // ErrInvalidJSON returned if an error occurred while parsing the request JSON // due to a malformed request data used. ErrInvalidJSON = errors.New("parse error") // ErrInvalidReq is returned if the JSON version doesn't match the supported. ErrInvalidReq = errors.New("invalid request") // ErrInternalFailure is returned if an unexpected error is returned while // processing the received request. ErrInternalFailure = errors.New("internal error") // ErrMethodMissing is returned if a request with a method is received. ErrMethodMissing = errors.New("method missing") // ErrSenderAddrMissing is returned if the sender's address is missing. ErrSenderAddrMissing = errors.New("sender address missing") // ErrExpiredServerKey is returned if a sender takes too long to use the server // key sent. ErrExpiredServerKey = errors.New("server key expired") // ErrSignerKeyMissing is returned if the sender's signer key is missing. ErrSignerKeyMissing = errors.New("sender signer key missing") // ErrMissingParams is returned if one or more of the expected parameters is // missing. Or more than required parameters are returned. ErrMissingParams = errors.New("excess or missing param(s)") // ErrUnknownMethod is returned if the method provided in the request is // not currently supported. ErrUnknownMethod = errors.New("unknown method") // ErrUnknownParam is returned if one or more of the provided parameters // contains unexpected data. ErrUnknownParam = errors.New("unknown param(s)") // ErrInvalidSigningKey is return if decrypting the actual key from the // provided signing key string results into an error. ErrInvalidSigningKey = errors.New("invalid client signing key") // ErrMissingServerKey is returned if a sender doesn't request for the public // server keys before accessing the contract backend. ErrMissingServerKey = errors.New("missing server key") )
Functions ¶
func DecryptAES ¶
Decode the ciphertext first into a bytes array. The decoded output returned is in bytes form
func EncryptAES ¶
Its outputs a hexutils encode string and an error
func GetErrorCode ¶
GetErrorCode returns the set error code if it exists or max(uint16) if otherwise.
func GetMethodParams ¶
func GetMethodParams(method Method) (implementation MethodType, param []ParamType)
GetMethodParams returns the parameters of the method provided if supported.
Types ¶
type MethodType ¶
type MethodType int
MethodType defines type in relation to how the method is implemented
type NetworkParams ¶
func GetNetworkConfig ¶
func GetNetworkConfig(net NetworkType) (*NetworkParams, error)
GetNetworkConfig returns the configured sapphire network params.
type NetworkType ¶
type NetworkType int
const ( SapphireMainnet NetworkType = iota SapphireTestnet SapphireLocalnet LocalTesting UnsupportedNet )
func ToNetType ¶
func ToNetType(net string) NetworkType
ToNetType maps a network type to the user network type input either in in camel case or snake case.
func (NetworkType) String ¶
func (n NetworkType) String() string
String defines the default stringer for NetworkType.
type PrivateKey ¶
type PrivateKey struct {
*ecdh.PrivateKey
}
PrivateKey is generated using elliptic curve diffie-hellman algorithm. This is used to share sensitive information between the server and the client i.e signer key.
func GeneratePrivKey ¶
func GeneratePrivKey(randGen io.Reader) (PrivateKey, error)
GeneratePrivKey generates a private key using a P256 curve. P256 is used because it provides keys of size 32 bit which are the maximum allowed by AES.
func (*PrivateKey) ComputeSharedKey ¶
func (p *PrivateKey) ComputeSharedKey(remotePubKey string) ([]byte, error)
ComputeSharedKey computes the shared key between the remote and the local instances.
func (*PrivateKey) PubKeyToHexString ¶
func (p *PrivateKey) PubKeyToHexString() string
PubKeyToHexString converts the public key associated with the provided private key to a hex text.