Migrate to ES6 modules

This commit is contained in:
Yarmo Mackenbach 2022-02-27 22:59:17 +01:00
parent c32da606ab
commit 3b227d1ba2
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
17 changed files with 145 additions and 102 deletions

View file

@ -27,12 +27,14 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router() import express from 'express'
const { check, validationResult } = require('express-validator') import { check, validationResult } from 'express-validator'
const Ajv = require("ajv") import Ajv from 'ajv'
import { generateWKDProfile, generateHKPProfile } from '../../server/index.js'
import 'dotenv/config.js'
const router = express.Router()
const ajv = new Ajv({coerceTypes: true}) const ajv = new Ajv({coerceTypes: true})
const kx = require('../../server')
require('dotenv').config()
const apiProfileSchema = { const apiProfileSchema = {
type: "object", type: "object",
@ -251,16 +253,16 @@ router.get('/profile/fetch',
let data let data
switch (req.query.protocol) { switch (req.query.protocol) {
case 'wkd': case 'wkd':
data = await kx.generateWKDProfile(req.query.query) data = await generateWKDProfile(req.query.query)
break; break;
case 'hkp': case 'hkp':
data = await kx.generateHKPProfile(req.query.query) data = await generateHKPProfile(req.query.query)
break; break;
default: default:
if (req.query.query.includes('@')) { if (req.query.query.includes('@')) {
data = await kx.generateWKDProfile(req.query.query) data = await generateWKDProfile(req.query.query)
} else { } else {
data = await kx.generateHKPProfile(req.query.query) data = await generateHKPProfile(req.query.query)
} }
break; break;
} }
@ -329,4 +331,4 @@ router.get('/profile/verify',
} }
) )
module.exports = router export default router

View file

@ -27,13 +27,19 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const express = require('express') import express from 'express'
const fs = require('fs') import { readFileSync } from 'fs'
const app = express() import { stringReplace } from 'string-replace-middleware'
const { stringReplace } = require('string-replace-middleware') import 'dotenv/config.js'
require('dotenv').config()
const packageData = JSON.parse(fs.readFileSync('package.json')) import apiRoute from './routes/api.js'
import mainRoute from './routes/main.js'
import profileRoute from './routes/profile.js'
import staticRoute from './routes/static.js'
import utilRoute from './routes/util.js'
const app = express()
const packageData = JSON.parse(readFileSync('package.json'))
app.set('env', process.env.NODE_ENV || "production") app.set('env', process.env.NODE_ENV || "production")
app.set('view engine', 'pug') app.set('view engine', 'pug')
@ -65,12 +71,14 @@ app.use(stringReplace({
app.use('/favicon.svg', express.static('favicon.svg')) app.use('/favicon.svg', express.static('favicon.svg'))
app.use('/robots.txt', express.static('robots.txt')) app.use('/robots.txt', express.static('robots.txt'))
app.use('/', require('./routes/main')) app.use('/', mainRoute)
app.use('/api', require('./routes/api')) app.use('/api', apiRoute)
app.use('/static', require('./routes/static')) app.use('/static', staticRoute)
app.use('/util', require('./routes/util')) app.use('/util', utilRoute)
app.use('/', require('./routes/profile')) app.use('/', profileRoute)
app.listen(app.get('port'), () => { app.listen(app.get('port'), () => {
console.log(`Node server listening at http://localhost:${app.get('port')}`) console.log(`Node server listening at http://localhost:${app.get('port')}`)
}) })
export default app

View file

@ -3,6 +3,7 @@
"version": "3.2.0", "version": "3.2.0",
"description": "A modern, secure and privacy-friendly platform to establish your decentralized online identity", "description": "A modern, secure and privacy-friendly platform to establish your decentralized online identity",
"main": "index.js", "main": "index.js",
"type": "module",
"dependencies": { "dependencies": {
"ajv": "^8.6.3", "ajv": "^8.6.3",
"bent": "^7.3.12", "bent": "^7.3.12",

View file

@ -27,8 +27,11 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router() import express from 'express'
import apiRouter0 from '../api/v0/index.js'
router.use('/0', require('../api/v0/index.js')) const router = express.Router()
module.exports = router router.use('/0', apiRouter0)
export default router

View file

@ -27,9 +27,13 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router() import express from 'express'
const md = require('markdown-it')({typographer: true}) import markdownImport from 'markdown-it'
const fs = require('fs') import { readFileSync } from 'fs'
import demoData from '../server/demo.js'
const router = express.Router()
const md = markdownImport({typographer: true})
router.get('/', (req, res) => { router.get('/', (req, res) => {
let highlights = [] let highlights = []
@ -44,13 +48,13 @@ router.get('/', (req, res) => {
} }
} }
res.render('index', { highlights: highlights, demoData: require('../server/demo.js').data }) res.render('index', { highlights: highlights, demoData: demoData })
}) })
router.get('/privacy', (req, res) => { router.get('/privacy', (req, res) => {
let rawContent = fs.readFileSync(`./content/privacy-policy.md`, "utf8") let rawContent = readFileSync(`./content/privacy-policy.md`, "utf8")
const content = md.render(rawContent) const content = md.render(rawContent)
res.render(`article`, { title: `Privacy policy`, content: content }) res.render(`article`, { title: `Privacy policy`, content: content })
}) })
module.exports = router export default router

View file

@ -27,53 +27,56 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router() import express from 'express'
const bodyParser = require('body-parser').urlencoded({ extended: false }) import bodyParserImport from 'body-parser'
const kx = require('../server') import { generateSignatureProfile, utils, generateWKDProfile, generateHKPProfile, generateKeybaseProfile } from '../server/index.js'
const router = express.Router()
const bodyParser = bodyParserImport.urlencoded({ extended: false })
router.get('/sig', (req, res) => { router.get('/sig', (req, res) => {
res.render('profile', { isSignature: true, signature: null }) res.render('profile', { isSignature: true, signature: null })
}) })
router.post('/sig', bodyParser, async (req, res) => { router.post('/sig', bodyParser, async (req, res) => {
const data = await kx.generateSignatureProfile(req.body.signature) const data = await generateSignatureProfile(req.body.signature)
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data, isSignature: true, signature: req.body.signature }) res.render('profile', { title: title, data: data, isSignature: true, signature: req.body.signature })
}) })
router.get('/wkd/:id', async (req, res) => { router.get('/wkd/:id', async (req, res) => {
const data = await kx.generateWKDProfile(req.params.id) const data = await generateWKDProfile(req.params.id)
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data }) res.render('profile', { title: title, data: data })
}) })
router.get('/hkp/:id', async (req, res) => { router.get('/hkp/:id', async (req, res) => {
const data = await kx.generateHKPProfile(req.params.id) const data = await generateHKPProfile(req.params.id)
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data }) res.render('profile', { title: title, data: data })
}) })
router.get('/hkp/:server/:id', async (req, res) => { router.get('/hkp/:server/:id', async (req, res) => {
const data = await kx.generateHKPProfile(req.params.id, req.params.server) const data = await generateHKPProfile(req.params.id, req.params.server)
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data }) res.render('profile', { title: title, data: data })
}) })
router.get('/keybase/:username/:fingerprint', async (req, res) => { router.get('/keybase/:username/:fingerprint', async (req, res) => {
const data = await kx.generateKeybaseProfile(req.params.username, req.params.fingerprint) const data = await generateKeybaseProfile(req.params.username, req.params.fingerprint)
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data }) res.render('profile', { title: title, data: data })
}) })
router.get('/:id', async (req, res) => { router.get('/:id', async (req, res) => {
let data let data
if (req.params.id.includes('@')) { if (req.params.id.includes('@')) {
data = await kx.generateWKDProfile(req.params.id) data = await generateWKDProfile(req.params.id)
} else { } else {
data = await kx.generateHKPProfile(req.params.id) data = await generateHKPProfile(req.params.id)
} }
const title = kx.utils.generatePageTitle('profile', data) const title = utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data }) res.render('profile', { title: title, data: data })
}) })
module.exports = router export default router

View file

@ -27,9 +27,10 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const express = require('express') import express from 'express'
const router = require('express').Router()
const router = express.Router()
router.use('/', express.static('static')) router.use('/', express.static('static'))
module.exports = router export default router

View file

@ -27,7 +27,9 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router() import express from 'express'
const router = express.Router()
router.get('/profile-url', function(req, res) { router.get('/profile-url', function(req, res) {
res.render('util/profile-url') res.render('util/profile-url')
@ -57,4 +59,4 @@ router.get('/wkd/:input', function(req, res) {
res.render('util/wkd', { input: req.params.input }) res.render('util/wkd', { input: req.params.input })
}) })
module.exports = router export default router

View file

@ -27,7 +27,7 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
exports.data = { export default {
"claimVersion": 1, "claimVersion": 1,
"uri": "https://fosstodon.org/@keyoxide", "uri": "https://fosstodon.org/@keyoxide",
"fingerprint": "9f0048ac0b23301e1f77e994909f6bd6f80f485d", "fingerprint": "9f0048ac0b23301e1f77e994909f6bd6f80f485d",

View file

@ -27,14 +27,14 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const doip = require('doipjs') import * as doipjs from 'doipjs'
const keys = require('./keys') import { fetchWKD, fetchHKP, fetchSignature, fetchKeybase } from './keys.js'
const libravatar = require('libravatar') import libravatar from 'libravatar'
const generateWKDProfile = async (id) => { const generateWKDProfile = async (id) => {
return keys.fetchWKD(id) return fetchWKD(id)
.then(async key => { .then(async key => {
let keyData = await doip.keys.process(key.publicKey) let keyData = await doipjs.keys.process(key.publicKey)
keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}` keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}`
keyData.key.fetchMethod = 'wkd' keyData.key.fetchMethod = 'wkd'
keyData.key.uri = key.fetchURL keyData.key.uri = key.fetchURL
@ -59,9 +59,9 @@ const generateWKDProfile = async (id) => {
} }
const generateHKPProfile = async (id, keyserverDomain) => { const generateHKPProfile = async (id, keyserverDomain) => {
return keys.fetchHKP(id, keyserverDomain) return fetchHKP(id, keyserverDomain)
.then(async key => { .then(async key => {
let keyData = await doip.keys.process(key.publicKey) let keyData = await doipjs.keys.process(key.publicKey)
keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}` keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}`
keyData.key.fetchMethod = 'hkp' keyData.key.fetchMethod = 'hkp'
keyData.key.uri = key.fetchURL keyData.key.uri = key.fetchURL
@ -86,7 +86,7 @@ const generateHKPProfile = async (id, keyserverDomain) => {
} }
const generateSignatureProfile = async (signature) => { const generateSignatureProfile = async (signature) => {
return keys.fetchSignature(signature) return fetchSignature(signature)
.then(async key => { .then(async key => {
let keyData = key.keyData let keyData = key.keyData
keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}` keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}`
@ -112,9 +112,9 @@ const generateSignatureProfile = async (signature) => {
} }
const generateKeybaseProfile = async (username, fingerprint) => { const generateKeybaseProfile = async (username, fingerprint) => {
return keys.fetchKeybase(id, keyserverDomain) return fetchKeybase(id, keyserverDomain)
.then(async key => { .then(async key => {
let keyData = await doip.keys.process(key.publicKey) let keyData = await doipjs.keys.process(key.publicKey)
keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}` keyData.openpgp4fpr = `openpgp4fpr:${keyData.fingerprint.toLowerCase()}`
keyData.key.fetchMethod = 'hkp' keyData.key.fetchMethod = 'hkp'
keyData.key.uri = key.fetchURL keyData.key.uri = key.fetchURL
@ -142,7 +142,7 @@ const processKeyData = (keyData) => {
keyData.users.forEach(user => { keyData.users.forEach(user => {
// Remove faulty claims // Remove faulty claims
user.claims = user.claims.filter(claim => { user.claims = user.claims.filter(claim => {
return claim instanceof doip.Claim return claim instanceof doipjs.Claim
}) })
// Match claims // Match claims
@ -178,9 +178,9 @@ const computeExtraData = async (key, keyData) => {
} }
} }
exports.generateWKDProfile = generateWKDProfile export { generateWKDProfile }
exports.generateHKPProfile = generateHKPProfile export { generateHKPProfile }
exports.generateKeybaseProfile = generateKeybaseProfile export { generateKeybaseProfile }
exports.generateSignatureProfile = generateSignatureProfile export { generateSignatureProfile }
exports.utils = require('./utils') export * as utils from './utils.js'

View file

@ -27,10 +27,10 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const got = require('got') import got from 'got'
const doip = require('doipjs') import * as doipjs from 'doipjs'
const openpgp = require('openpgp') import { readKey, readCleartextMessage, verify } from 'openpgp'
const utils = require('./utils') import { computeWKDLocalPart } from './utils.js'
const fetchWKD = (id) => { const fetchWKD = (id) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
@ -47,7 +47,7 @@ const fetchWKD = (id) => {
if (!localPart || !domain) { if (!localPart || !domain) {
reject(new Error(`The WKD identifier "${id}" is invalid`)); reject(new Error(`The WKD identifier "${id}" is invalid`));
} }
const localEncoded = await utils.computeWKDLocalPart(localPart) const localEncoded = await computeWKDLocalPart(localPart)
const urlAdvanced = `https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${localEncoded}` const urlAdvanced = `https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${localEncoded}`
const urlDirect = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}` const urlDirect = `https://${domain}/.well-known/openpgpkey/hu/${localEncoded}`
let plaintext let plaintext
@ -81,7 +81,7 @@ const fetchWKD = (id) => {
} }
try { try {
output.publicKey = await openpgp.readKey({ output.publicKey = await readKey({
binaryKey: plaintext binaryKey: plaintext
}) })
} catch(error) { } catch(error) {
@ -113,7 +113,7 @@ const fetchHKP = (id, keyserverDomain) => {
} }
try { try {
output.publicKey = await doip.keys.fetchHKP(id, keyserverDomain) output.publicKey = await doipjs.keys.fetchHKP(id, keyserverDomain)
output.fetchURL = `https://${keyserverDomain}/pks/lookup?op=get&options=mr&search=${query}` output.fetchURL = `https://${keyserverDomain}/pks/lookup?op=get&options=mr&search=${query}`
} catch(error) { } catch(error) {
reject(new Error(`No public keys could be fetched using HKP`)) reject(new Error(`No public keys could be fetched using HKP`))
@ -138,7 +138,7 @@ const fetchSignature = (signature) => {
// Check validity of signature // Check validity of signature
let signatureData let signatureData
try { try {
signatureData = await openpgp.readCleartextMessage({ signatureData = await readCleartextMessage({
cleartextMessage: signature cleartextMessage: signature
}) })
} catch (error) { } catch (error) {
@ -147,7 +147,7 @@ const fetchSignature = (signature) => {
// Process the signature // Process the signature
try { try {
output.keyData = await doip.signatures.process(signature) output.keyData = await doipjs.signatures.process(signature)
output.publicKey = output.keyData.key.data output.publicKey = output.keyData.key.data
// TODO Find the URL to the key // TODO Find the URL to the key
output.fetchURL = null output.fetchURL = null
@ -161,7 +161,7 @@ const fetchSignature = (signature) => {
} }
// Check validity of signature // Check validity of signature
const verified = await openpgp.verify({ const verified = await verify({
message: signatureData, message: signatureData,
verificationKeys: output.publicKey verificationKeys: output.publicKey
}) })
@ -182,7 +182,7 @@ const fetchKeybase = (username, fingerprint) => {
} }
try { try {
output.publicKey = await doip.keys.fetchKeybase(username, fingerprint) output.publicKey = await doipjs.keys.fetchKeybase(username, fingerprint)
output.fetchURL = `https://keybase.io/${username}/pgp_keys.asc?fingerprint=${fingerprint}` output.fetchURL = `https://keybase.io/${username}/pgp_keys.asc?fingerprint=${fingerprint}`
} catch(error) { } catch(error) {
reject(new Error(`No public keys could be fetched from Keybase`)) reject(new Error(`No public keys could be fetched from Keybase`))
@ -196,7 +196,11 @@ const fetchKeybase = (username, fingerprint) => {
}) })
} }
exports.fetchWKD = fetchWKD const _fetchWKD = fetchWKD
exports.fetchHKP = fetchHKP export { _fetchWKD as fetchWKD }
exports.fetchSignature = fetchSignature const _fetchHKP = fetchHKP
exports.fetchKeybase = fetchKeybase export { _fetchHKP as fetchHKP }
const _fetchSignature = fetchSignature
export { _fetchSignature as fetchSignature }
const _fetchKeybase = fetchKeybase
export { _fetchKeybase as fetchKeybase }

View file

@ -27,15 +27,15 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const crypto = require('crypto').webcrypto import { webcrypto as crypto } from 'crypto'
exports.computeWKDLocalPart = async (localPart) => { export async function computeWKDLocalPart(localPart) {
const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase()); const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase());
const localPartHashed = new Uint8Array(await crypto.subtle.digest('SHA-1', localPartEncoded)); const localPartHashed = new Uint8Array(await crypto.subtle.digest('SHA-1', localPartEncoded));
return encodeZBase32(localPartHashed); return encodeZBase32(localPartHashed);
} }
exports.generatePageTitle = (type, data) => { export function generatePageTitle(type, data) {
switch (type) { switch (type) {
case 'profile': case 'profile':
try { try {

View file

@ -28,11 +28,11 @@ if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
// Import JS libraries // Import JS libraries
import * as kx from'./keyoxide' import * as kx from './keyoxide.js'
import * as kxKey from'./kx-key' import * as kxKey from './kx-key.js'
import * as kxClaim from'./kx-claim' import * as kxClaim from './kx-claim.js'
import * as ui from'./ui' import * as ui from './ui.js'
import * as utils from'./utils' import * as utils from './utils.js'
// Import CSS files // Import CSS files
import './styles.css' import './styles.css'

View file

@ -27,7 +27,7 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
import * as doip from "doipjs" import * as doipjs from 'doipjs';
export class Claim extends HTMLElement { export class Claim extends HTMLElement {
// Specify the attributes to observe // Specify the attributes to observe
@ -45,7 +45,7 @@ export class Claim extends HTMLElement {
} }
async verify() { async verify() {
const claim = new doip.Claim(JSON.parse(this.getAttribute('data-claim'))); const claim = new doipjs.Claim(JSON.parse(this.getAttribute('data-claim')));
await claim.verify({ await claim.verify({
proxy: { proxy: {
policy: 'adaptive', policy: 'adaptive',
@ -57,7 +57,7 @@ export class Claim extends HTMLElement {
updateContent(value) { updateContent(value) {
const root = this; const root = this;
const claim = new doip.Claim(JSON.parse(value)); const claim = new doipjs.Claim(JSON.parse(value));
switch (claim.matches[0].serviceprovider.name) { switch (claim.matches[0].serviceprovider.name) {
case 'dns': case 'dns':

View file

@ -30,7 +30,7 @@ more information on this, and how to apply and follow the GNU AGPL, see <https:/
import dialogPolyfill from 'dialog-polyfill' import dialogPolyfill from 'dialog-polyfill'
import QRCode from 'qrcode' import QRCode from 'qrcode'
import * as openpgp from 'openpgp' import * as openpgp from 'openpgp'
import * as utils from './utils' import * as utils from './utils.js'
// Prepare element selectors // Prepare element selectors
const elFormSignatureProfile = document.body.querySelector("#formGenerateSignatureProfile") const elFormSignatureProfile = document.body.querySelector("#formGenerateSignatureProfile")

View file

@ -29,11 +29,18 @@ more information on this, and how to apply and follow the GNU AGPL, see <https:/
*/ */
import * as openpgp from 'openpgp' import * as openpgp from 'openpgp'
import QRCode from 'qrcode' import QRCode from 'qrcode'
let _crypto = (typeof window === 'undefined') ? null : crypto
if (!_crypto) {
_crypto = import('crypto').then((crypto) => {
return crypto.webcrypto
})
// import { webcrypto as crypto } from 'crypto'
}
// Compute local part of Web Key Directory URL // Compute local part of Web Key Directory URL
export async function computeWKDLocalPart(localPart) { export async function computeWKDLocalPart(localPart) {
const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase()); const localPartEncoded = new TextEncoder().encode(localPart.toLowerCase());
const localPartHashed = new Uint8Array(await crypto.subtle.digest('SHA-1', localPartEncoded)); const localPartHashed = new Uint8Array(await _crypto.subtle.digest('SHA-1', localPartEncoded));
return encodeZBase32(localPartHashed); return encodeZBase32(localPartHashed);
} }

View file

@ -1,8 +1,11 @@
const path = require('path') import { dirname, resolve } from 'path'
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin import { fileURLToPath } from 'url'
const MiniCssExtractPlugin = require("mini-css-extract-plugin") import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import MiniCssExtractPlugin from "mini-css-extract-plugin"
module.exports = (env) => { const __dirname = dirname(fileURLToPath(import.meta.url));
export default (env) => {
let config let config
if (env.static) { if (env.static) {
config = { config = {
@ -16,7 +19,7 @@ module.exports = (env) => {
}, },
output: { output: {
filename: '[name].js', filename: '[name].js',
path: path.resolve(__dirname, 'static'), path: resolve(__dirname, 'static'),
}, },
watch: env.mode == "development", watch: env.mode == "development",
module: { module: {
@ -30,6 +33,11 @@ module.exports = (env) => {
} }
] ]
}, },
resolve: {
fallback: {
crypto: false,
}
},
plugins: [ plugins: [
new MiniCssExtractPlugin(), new MiniCssExtractPlugin(),
], ],