Request multiple steps
Similar to , you can do multiple signature in single one DID Connect, but there are some different features, follow this article to learn how to do multiple steps with DID Connect.
The basic process is consistent with the "Quick Start" chapter, change the code in the handler as follows:
const { fromBase58, toBase58 } = require('@ocap/util');
const { getHasher, types } = require('@ocap/mcrypto');
const { getRandomMessage } = require('../../libs/utils');
const logger = require('../../libs/logger');
const hasher = getHasher(types.HashType.SHA3);
const data = 'abcdefghijklmnopqrstuvwxyz'.repeat(32);
const action = 'request-multiple-steps';
module.exports = {
action,
onConnect() {
return [
{
signature: () => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
},
},
{
signature: () => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
},
];
},
onAuth: ({ userDid, userPk, claims, step, req, updateSession }) => {
logger.info(`${action}.onAuth`, { step, userPk, userDid, claims });
const result = req?.context?.store?.result || [];
const claim = claims.find((x) => x.type === 'signature');
if (step === 1) {
result.push({
step,
origin: fromBase58(claim.origin).toString(),
sig: claim.sig,
});
} else if (step === 2) {
result.push({
step,
origin: data,
digest: claim.digest,
sig: claim.sig,
});
}
updateSession({
result,
});
},
};
onConnect
field must return an array- Will not see
Prev
button in the DID Connect process, because each claim item is independent onAuth
callback will be called multiple times, which means you can get results from the previous DID Connect, this is the biggest difference with
Change the front-end part calling the DID Connect code to the following:
connectApi.open({
locale: 'en',
action: 'request-multiple-steps',
onSuccess({ result }) {
// multi claims data will be in result, result would be an array
},
messages: {
title: 'Request Multiple Steps',
scan: 'In this session, you will do a text signature followed by a summary signature',
},
});