UNPKG

dwnpm

Version:

Decentralized Registry Package Manager (DRPM) helps developers publish, install, find and manage Decentralized Packages (DPKs) published to Decentralized Web Nodes (DWNs). DRPM does this by looking up a Decentralized Identifier (DID) to find its DID docum

40 lines 1.66 kB
import { generateMnemonic } from '@scure/bip39'; import { wordlist as english } from '@scure/bip39/wordlists/english'; import { Logger } from './logger.js'; import cuid from '@bugsnag/cuid'; export const stringifier = (data) => JSON.stringify(data, null, 2); export const hideSensitive = (data) => ({ ...data, password: '***************', recoveryPhrase: '***************' }); export const secureProfileContext = (profile) => stringifier(hideSensitive(profile)); export const profileLessName = (profile) => { const temp = Object.fromEntries(Object.entries(profile).filter(([name, _]) => name !== 'name')); delete temp.name; return temp; }; export const secureProfile = (profile) => Object.fromEntries(Object.entries(profile) .filter(([name, _]) => name !== 'name') .map(([method, data]) => [ method, hideSensitive(data) ])); export const createPassword = (n = 6) => { const mnemonic = generateMnemonic(english, 128).split(' '); const password = []; while (password.length < n && mnemonic.length > 0) { const randomIndex = Math.floor(Math.random() * mnemonic.length); password.push(mnemonic[randomIndex]); mnemonic.splice(randomIndex, 1); } return password.join(' '); }; export const scuid = ({ len, n } = { len: 25, n: 8 }) => cuid().slice(len - n, len); export const cleanEndpoint = (endpoint) => { try { const parsedEndpoint = new URL(endpoint); return parsedEndpoint.host; } catch (error) { Logger.error('Invalid Endpoint:', error); return endpoint.replace(/https?:\/\/(www\.)?([^/]+).*/, '$2'); } }; //# sourceMappingURL=misc.js.map