API Reference
Please find the SDK here.
Installation
You can start with importing the @ont-dev/ont-tag
package by running npm command below.
You can now use the following import
statement to bring in all the modules from the @ont-dev/ont-tag
package.
The following require
statement can also be used to load the modules.
To use the methods in a browser, you must use the compiled version of the library. The browser.js
file is located in the lib
directory. You can include it in your project using a script
tag as follows.
Everything will now be available under the VC
variable. For instance, to fetch the list of available regions, you can invoke:
Usage
Method list
Method name | Description |
Sends authentication request to the trust anchor service with user's KYC details | |
Fetch URL to initiate social media platform authentication | |
Fetches any issued credentials for previously sent authentication requests | |
Returns a list of countries and regions with their respective aliases | |
Returns a list of valid authentication types | |
Returns the list of supported chains | |
Generates a valid ONT ID using a wallet addresses | |
Serializes the passed object data to generate a | |
Generates a presentation for the passed credential data payload | |
Deserializes the passed |
Sending an Authentication Request
This method is used to send authentication requests for a user's KYC data. It takes two parameters. The first one is an object literal with the KYC info. as defined below, and the second one is your API key.
Note: Both the
frontDoc
andbackDoc
images need to be passed asbase64
encoded strings.
The region
field takes the respective alias for each region. Use the areaList
utility method to obtain the list of countries and their aliases.
The ownerDid
field takes an ONT ID. You can generate one using the generateId
utility method.
The authType
field specifies the type of document sent for authentication. Use the authType
utility method to fetch the list of valid documents.
Call the method with the user info and your API key to send an authentication request.
It returns true
for a successful request and an error message if an exception occurs.
Error Message | Description |
SUCCESS | Authentication successful |
APP_NOT_FOUND | Passed |
REQUEST_LIMIT_EXCEEDED | Request limit for a user exceeded |
SIG_VERIFY_FAILED | Invalid API signature |
INTERNAL_ERROR | Internal error occurred |
Note: Each application (identified with the combination of their appid and API key) is limited to sending 10 requests for a user's particular document/authentication method (identified with a user's DID context). Also, in case of an internal error, please get in touch with the Ontology team.
Fetch Third Party Authentication Link
Invoking this method returns a URL that can be used to prompt user authentication for a social media platform.
It takes four parameters.
ownerDid
: User's DIDauthType
: The authentication method (social media platform). See hereapiKey
: Your API keyappId
: Your app ID
The method returns a URL that triggers OAuth authentication for a particular platform.
Once successfully authorized, a credential will be issued that can be used to prove the relationship between a social media account and a DID.
Fetching Credentials
You can use this method to fetch the issued credentials for a user after having sent a data authentication request.
This method takes two parameters, the DID of the user (or owner in the context of a credential), and the ID document type.
If the authentication was successful, the encryptOriginData
field will contain serialized credential data.
Status | Description |
1 | Authentication successful |
2 | Authentication failed |
0 | Verification in progress |
Note: The user needs to sign this data to authorize access and prove their relationship with the credential data. After fetching the credential data, you can proceed with generating a presentation with the signed credential data as its payload. The resultant token can then be used for signature verification and access control.
Utility Methods
utils
class contains multiple methods that can be used to perform specific tasks. Each method is described below.
areaList
areaList
Invoking this method returns an array of all the supported countries and regions with their respective aliases.
The response is structured as follows.
authType
authType
This method returns the list of supported documents and authentication types as an object.
The response is of the following form.
chainType
chainType
This method returns an object containing valid chain type names.
The response is as follows.
generateId
generateId
Invoking this method with a wallet address prefixes it with the appropriate DID method based on the passed chainType
and returns a valid ONT ID as a string. For e.g., did:etho:0xdc6...974a9
.
serializeSignMessage
serializeSignMessage
This method returns a serialized base64
JWT string. It takes the following parameters:
jwtStr
- The credential JWT stringaudienceId
- DID of the credential consumerownerDid
- DID of the Credential ownereffectiveTime
- Validity period of the presentation (in seconds). For e.g., 1 day = 86400
The parameters are of the following form.
createPresentation
createPresentation
Invoke this method to generate a presentation with credential data signed by the user. It returns the presentation as a JWT string.
It takes an object parameter containing:
signMessage
- Serialized JWT string (usingserializeSignMessage
)signature
- Serialized JWT string that has been signed by the user
The parameter object is of the following form.
Presentation data can be obtained by deserializing this token. You can perform signature verification and message decryption using the Java SDK. Follow this link for reference.
deserialize
deserialize
You can obtain the user's verified KYC data by deserializing the encryptOriginData
string in the credential object received here.
This method takes the serialized JWT string as parameter and returns an object containing credential data.
The response object is of the following form.
Last updated