@arcblock/did-auth
Version:
Helper function to setup DID authentication support on a node.js web server
57 lines (52 loc) • 1.71 kB
JavaScript
const { Joi } = require('@arcblock/validator');
const createClaimsSchema = require('./claims');
const chainInfo = Joi.object({
type: Joi.string().optional().valid('arcblock', 'ethereum', 'solona').default('arcblock'),
id: Joi.any()
.when('type', { is: 'arcblock', then: Joi.string().optional().default('none') })
.when('type', {
is: 'ethereum',
then: Joi.string()
.required()
.pattern(/^[0-9]+$/, 'numbers'),
})
.when('type', {
is: 'solona',
then: Joi.string()
.required()
.pattern(/^[0-9]+$/, 'numbers'),
}),
host: Joi.string()
.when('type', { is: 'ethereum', then: Joi.string().optional().allow('') })
.when('type', { is: 'solona', then: Joi.string().optional().allow('') })
.when('type', {
is: 'arcblock',
then: Joi.string()
.uri({ scheme: ['http', 'https'] })
.allow('none')
.default('none'),
}),
}).options({ stripUnknown: true, noDefaults: false });
const appInfo = Joi.object({
name: Joi.string().required(),
description: Joi.string().required(),
icon: Joi.string()
.uri({ scheme: ['http', 'https'] })
.required(),
link: Joi.string()
.uri({ scheme: ['http', 'https'] })
.optional(),
path: Joi.string()
.uri({ scheme: ['http', 'https'] })
.default('https://abtwallet.io/i/'),
publisher: Joi.DID().optional(),
updateSubEndpoint: Joi.boolean().optional(),
subscriptionEndpoint: Joi.string().optional(),
nodeDid: Joi.DID().optional(),
agentDid: Joi.DID().optional(),
}).options({ stripUnknown: false, noDefaults: false });
module.exports = Object.freeze({
chainInfo,
appInfo,
claims: createClaimsSchema(chainInfo),
});