API Reference
Index
NewOntLoginSdk
NewOntLoginSdk
Creates an OntLoginSdk instance.
Parameters
conf *SDKConfig
SDK configuration
type SDKConfig struct {
Chain []string // Supported chain, e.g."ONT","ETH","BSC"
Alg []string // Signature scheme such as "ES256","Ed25519"
ServerInfo *modules.ServerInfo // Server configuration info, see details below
VCFilters map[int][]*modules.VCFilter // VCFilter info for authentication/authorization, see details below
type ServerInfo struct {
Name string `json:"name"` // Server name
Icon string `json:"icon,omitempty"` // Icon, optional
Url string `json:"url"` // Server URL
Did string `json:"did,omitempty"` // Server DID, optional
VerificationMethod string `json:"verificationMethod,omitempty"` // Verification method, optional
}
type VCFilter struct {
Type string `json:"type"` // Type of VC, e.g. "DegreeCredential"
Express []string `json:"express,omitempty"` // List of expressions for zero-knowledge proof
TrustRoots []string `json:"trust_roots"` // List of trusted VC issuer DIDs
Required bool `json:"required"` // If it's required
processors map[string]did.DidProcessor
DID processor map
nonceFunc func(int) string
Function to generate nonce
getActionByNonce func(string) (int,error)
Gets action by nonce
Returns
Field
Description
*OntLoginSdk
Instantiation successful
error
Instantiation failed
GenerateChallenge
Generates the challenge.
Parameters
type ClientHello struct {
Ver string `json:"ver"` // Version number
Type string `json:"type"` // "ClientHello" for this message
Action int `json:"action"` // 0: Authentication, 1: Authorization
ClientChallenge *ClientChallenge `json:"ClientChallenge,omitempty"` // Challenge sent from the client for mutual authentication, optional
}
Returns
*modules.ServerHello
type ServerHello struct {
Ver string `json:"ver"` // Version number
Type string `json:"type"` // "ServerHello" for this message
Nonce string `json:"nonce"` // String of nonce
Server *ServerInfo `json:"server"` // Server info
Chain []string `json:"chain"` // List of supported chains
Alg []string `json:"alg"` // List of supported signature schemes
VCFilters []*VCFilter `json:"VCFilters,omitempty"` // List of VCFilters, optional
ServerProof *ServerProof `json:"ServerProof,omitempty"` // Challenge response sent from the server for mutual authentication, optional
Extension *Extension `json:"extension,omitempty"` // Extension, optional
}
ValidateClientResponse
Validates the response from the client.
Parameters
type ClientResponse struct {
Ver string `json:"ver"` // Version number
Type string `json:"type"` // "ClientResponse" for this message
Did string `json:"did"` // User DID
Nonce string `json:"nonce"` // String of nonce generated by the server
Proof *Proof `json:"proof"` // Signature info sent from the client, see details below
VPs []string `json:"VPs,omitempty"` // List of verifiable presentations, optional
}
type Proof struct {
Type string `json:"type"` // Signature scheme
VerificationMethod string `json:"verificationMethod"` // DID & key index,e.g."did:ont:alice#key-1"
Created uint64 `json:"created"` // Unix timestamp
Value string `json:"value"` // HEX string of signature
}
Returns
Field
Description
null
Validation successful
error
Validation failed
Validation Process:
Verify the validity of parameters
Verify if the nonce is the same as the one generated by the server
verify the signature
Verify the validity of VP and VC
Check if the provided VC meets the requirement
GetCredentialJson
Gets JSON string of VC from VP.
Parameters
Parameter
Description
chain
Chain name
presentation
VP string
Returns
Field
Description
[]string
JSON string of VC
error
Fail to get VC string
Last updated
Was this helpful?