Usage
Login
Login presents a DirectAuth UI to the user and a promise to the application, which resolves with user account into when DirectAuth completes or rejects if the DirectAuth prompt is closed:
const userInfo = await embed.login();
The userInfo object contains the following:
{
activities: [], // Array
address: "<tezos address>", // Stirng
balanceUSD: 100, // Number
balanceXTZ: 100, // Number
delegate: "<contract>", // String
originatedAccounts: [] // Array
pk: "<public key", // String
pkh: "<public key hash>", // String
state: "<state>", // String
tokens: [], // Array
}
UI & params
Providers can be added as loginOptions and their appearance can change with wideButtons:
const userInfo = await embed.login({
loginOptions: ["google", "facebook"],
wideButtons: [true, false],
});
Additional auth params can be added as authParams, using an id and a nonce:
const userInfo = await embed.login({
...,
authParams: { id: "<your id>", nonce: "<your nonce>" },
});
User Status
The embed persists the user's information on login and clears it on logout. It can be accessed from the .user field and will be null if a user is not logged in:
const userInfo = embed.user
Send Tezos Operations
Send allows an application to pass a Tezos Operation to the user for approval using the Kukai UI. The payload is compatible with @airgap/beacon-sdk (see operation request docs). The application can await the returned promise to recieve the operation hash of the operation when the user approves, or the rejection should they disapprove.
The following example demonstrates how to send 1 tez. Please note that the amount is specified in mutez, where 1,000,000 mutez equals 1 tez. The send promise resolves as soon as the operation is approved, at which point the operation hash is returned. However, if the operation is rejected, it throws an error. Kukai-embed does not track the on-chain success of outgoing operations:
const operationInfo = await embed.send([{
kind: 'transaction',
destination: 'tz1NBvY7qUedReRcYx8gqV34c8fUuks8o8Nr',
amount: '1000000' // amount in mutez
}]);
If you intend to send an operation that includes a contract call, you can add a parameters field to the object above (see a full example of an entrypoint call):
kind: 'transaction',
// ...
parameters: {
entrypoint: 'set_color',
value: {
int: tokenId,
},
}
Authentication
Kukai-Embed can provide user authentication for applications based on their Tezos private key. authenticate takes an identifier for the authentication request and a challenge nonce to be signed. It returns a message which is created from the request and nonce, as well as a signature which is made using the returned message and the private key of the logged-in user. This signature can be verified using the message and the user's public key in order to prove authentication of the user.
const { message, signature } = await embed.authenticate('example request ID', 'example nonce')
Logout
Logout clears the Kukai instance of key information and returns it to a logged-out (but still initialized) state:
await embed.logout();