Skip to main content

Authentication and Oraclization

1. Create a Public Signature

A public signature is a signature string that is safe to publish. It consists of a "string you want to prove (e.g., user ID)" and an "authentication method namespace (defined by the user)", signed with your Ethereum account address. This allows anyone to verify the signer using the Ethereum account address.

To generate a new public signature, send the signature generated by the user's Ethereum wallet, the signed message, a secret message (e.g., an access token), and the authentication method namespace to the Khaos RESTful API.

You can easily make this request using the Khaos Kit. The following example demonstrates how to create a public signature for the Dev Protocol's GitHub Market Contract.

import { sign } from '@devprotocol/khaos-kit'

sign(
'github-market',
'mainnet'
)({
message: 'dev-protocol/protocol',
signature: 'SIGNATURE',
secret: 'SECRET',
}).then((res) => {
console.log(res.publicSignature) // => Generated public signature
console.log(res.address) // => Signed address
})

2. Emit on-chain event

Emit a smart contract event. Khaos monitors these events and initiates the oraclization process upon detection. The smart contract address to monitor is defined in a user-defined Khaos function. If the event data includes a public signature with the key publicSignature, Khaos retrieves the stored secret information and passes it to the oraclize method, which is also declared in the user-defined Khaos function.

info

You can quickly develop user-defined Khaos functions with the Khaos Starter Kit. https://github.com/dev-protocol/khaos-starter-kit

The event name and data structure can be customized using user-defined Khaos functions. An example is shown below.

event Query(string foo, string publicSignature, address user);

function query(string calldata _foo, string calldata _publicSignature) external {
emit Query(_foo, _publicSignature, msg.sender);
}

When Khaos completes the oraclization process, it executes a callback function. The callback is sent to the same smart contract address that emitted the event.

You can customize the callback function name and arguments using user-defined Khaos functions. An example is shown below.

info

We recommend verifying that the callback function is called by Khaos. This can be done by checking the caller's address or by including a unique key known only to Khaos as an argument.

function callback(bool _result) external {
require(msg.sender == khaos, "sender isn't khaos");
// Some processing that depends on oracle...
}

3. Wait for callback

All that's left is to wait for the callback from Khaos! 🎉