Request multiple claims
In some cases, you may need do multiple signature in single one DID Connect, which can get a smoother experience, follow this article to learn how to do multiple claims 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-claims';
module.exports = {
action,
onConnect() {
return {
signText: [
'signature',
() => {
return {
type: 'mime:text/plain',
data: getRandomMessage(),
description: 'Please sign the text',
};
},
],
signDigest: [
'signature',
() => {
return {
description: 'Please sign the digest',
digest: toBase58(hasher(data, 1)),
};
},
],
};
},
onAuth: ({ userDid, userPk, claims, updateSession }) => {
logger.info(`${action}.onAuth`, { userPk, userDid, claims });
updateSession({
result: [
{
origin: fromBase58(claims[0].origin).toString(),
sig: claims[0].sig,
},
{
origin: data,
digest: claims[1].digest,
sig: claims[1].sig,
},
],
});
},
};
Change the front-end part calling the DID Connect code to the following:
connectApi.open({
locale: 'en',
action: 'request-multiple-claims',
onSuccess({ result }) {
// multi claims data will be in result, result would be an array
},
messages: {
title: 'Request Multiple Claims',
scan: 'In this session, you will do both text signing and summary signing',
},
});