Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | 1x 1x 32x 32x 1x 31x 30x 30x 1x 29x 1x 28x 28x 27x 1x | /**
* @file MFKDF UUID Factor Setup
* @copyright Multifactor, Inc. 2022–2025
*
* @description
* Setup UUID factor for multi-factor key derivation
*
* @author Vivek Nair (https://nair.me) <vivek@nair.me>
*/
const defaults = require('../../defaults')
const {
v4: uuidv4,
validate: uuidValidate,
parse: uuidParse
} = require('uuid')
/**
* Setup an MFKDF UUID factor
*
* @example
* // setup key with uuid factor
* const setup = await mfkdf.setup.key([
* await mfkdf.setup.factors.uuid({ uuid: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' })
* ])
*
* // derive key with uuid factor
* const derive = await mfkdf.derive.key(setup.policy, {
* uuid: mfkdf.derive.factors.uuid('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d')
* })
*
* setup.key.toString('hex') // -> 01d0…2516
* derive.key.toString('hex') // -> 01d0…2516
*
* @param {Object} [options] - Configuration options
* @param {string} [options.uuid] - UUID to use for this factor; random v4 uuid default
* @param {string} [options.id='uuid'] - Unique identifier for this factor
* @returns {MFKDFFactor} MFKDF factor information
* @author Vivek Nair (https://nair.me) <vivek@nair.me>
* @since 0.9.0
* @async
* @memberof setup.factors
*/
async function uuid (options) {
options = Object.assign(Object.assign({}, defaults.uuid), options)
if (typeof options.id !== 'string') {
throw new TypeError('id must be a string')
}
if (options.id.length === 0) throw new RangeError('id cannot be empty')
if (typeof options.uuid === 'undefined') options.uuid = uuidv4()
if (typeof options.uuid !== 'string') {
throw new TypeError('uuid must be a string')
}
if (!uuidValidate(options.uuid)) {
throw new TypeError('uuid is not a valid uuid')
}
return {
type: 'uuid',
id: options.id,
entropy: 122,
data: Buffer.from(uuidParse(options.uuid)),
params: async () => {
return {}
},
output: async () => {
return { uuid: options.uuid }
}
}
}
module.exports.uuid = uuid
|