> For the complete documentation index, see [llms.txt](https://docs.ont.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ont.io/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md).

# API Reference

## Index

* [NewOntLoginSdk](/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md#newontloginsdk)
* [GenerateChallenge](/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md#generatechallenge)
* [ValidateClientResponse](/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md#validateclientresponse)
* [GetCredentialJson](/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md#getcredentialjson)

## `NewOntLoginSdk`

Creates an OntLoginSdk instance.

#### Parameters

**`conf *SDKConfig`**

SDK configuration

```go
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
```

```go
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
}
```

```go
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

```go
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`

```go
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.&#x20;

#### Parameters

```go
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
}
```

```go
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:

1. Verify the validity of parameters&#x20;
2. Verify if the nonce is the same as the one generated by the server
3. verify the signature
4. Verify the validity of VP and VC
5. Check if the provided VC meets the requirement &#x20;

## 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 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ont.io/decentralized-identity-and-data/ontid/ont-login/back-end-go-sdk/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
