fix: remove TS import types

This commit is contained in:
Yarmo Mackenbach 2024-01-27 17:57:46 +01:00
parent edc3f401bc
commit 2ef792fbbb
9 changed files with 90 additions and 47 deletions

View file

@ -13,8 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import axios from 'axios' import axios, * as axiosMod from 'axios'
import { decodeProtectedHeader, importJWK, compactVerify, calculateJwkThumbprint } from 'jose' import { decodeProtectedHeader, importJWK, compactVerify, calculateJwkThumbprint } from 'jose'
import * as joseMod from 'jose'
import { base32, base64url } from 'rfc4648' import { base32, base64url } from 'rfc4648'
import { Claim } from './claim.js' import { Claim } from './claim.js'
import { Persona } from './persona.js' import { Persona } from './persona.js'
@ -57,12 +58,12 @@ export async function fetchASPE (uri) {
responseType: 'text' responseType: 'text'
} }
) )
.then((/** @type {import('axios').AxiosResponse} */ response) => { .then((/** @type {axiosMod.AxiosResponse} */ response) => {
if (response.status === 200) { if (response.status === 200) {
return response return response
} }
}) })
.then((/** @type {import('axios').AxiosResponse} */ response) => response.data) .then((/** @type {axiosMod.AxiosResponse} */ response) => response.data)
} catch (e) { } catch (e) {
throw new Error(`Error fetching Keybase key: ${e.message}`) throw new Error(`Error fetching Keybase key: ${e.message}`)
} }
@ -171,7 +172,7 @@ export async function parseProfileJws (profileJws, uri) {
/** /**
* Compute the fingerprint for JWK keys * Compute the fingerprint for JWK keys
* @function * @function
* @param {import('jose').JWK} key * @param {joseMod.JWK} key
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
export async function computeJwkFingerprint (key) { export async function computeJwkFingerprint (key) {

View file

@ -18,6 +18,7 @@ import { isUri } from 'valid-url'
import mergeOptions from 'merge-options' import mergeOptions from 'merge-options'
import { fetch } from './proofs.js' import { fetch } from './proofs.js'
import { run } from './verifications.js' import { run } from './verifications.js'
import * as verificationsMod from './verifications.js'
import { list, data as _data } from './serviceProviders/index.js' import { list, data as _data } from './serviceProviders/index.js'
import { opts as _opts } from './defaults.js' import { opts as _opts } from './defaults.js'
import { ClaimStatus } from './enums.js' import { ClaimStatus } from './enums.js'
@ -71,7 +72,7 @@ export class Claim {
*/ */
this._status = ClaimStatus.INIT this._status = ClaimStatus.INIT
/** /**
* @type {import('./serviceProvider.js').ServiceProvider[]} * @type {ServiceProvider[]}
*/ */
this._matches = [] this._matches = []
} }
@ -245,6 +246,7 @@ export class Claim {
let claimData = this._matches[index] let claimData = this._matches[index]
/** @type {verificationsMod.VerificationResult} */
let verificationResult = null let verificationResult = null
let proofData = null let proofData = null
let proofFetchError let proofFetchError
@ -286,7 +288,7 @@ export class Claim {
verificationResult = verificationResult || { verificationResult = verificationResult || {
result: false, result: false,
completed: true, completed: true,
proof: {}, proof: null,
errors: [proofFetchError] errors: [proofFetchError]
} }
} }

View file

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import axios from 'axios' import axios, * as axiosMod from 'axios'
import { isUri } from 'valid-url' import { isUri } from 'valid-url'
import { readKey, PublicKey } from 'openpgp' import { readKey, PublicKey } from 'openpgp'
import HKP from '@openpgp/hkp-client' import HKP from '@openpgp/hkp-client'
@ -129,12 +129,12 @@ export async function fetchKeybase (username, fingerprint) {
responseType: 'text' responseType: 'text'
} }
) )
.then((/** @type {import('axios').AxiosResponse} */ response) => { .then((/** @type {axiosMod.AxiosResponse} */ response) => {
if (response.status === 200) { if (response.status === 200) {
return response return response
} }
}) })
.then((/** @type {import('axios').AxiosResponse} */ response) => response.data) .then((/** @type {axiosMod.AxiosResponse} */ response) => response.data)
} catch (e) { } catch (e) {
throw new Error(`Error fetching Keybase key: ${e.message}`) throw new Error(`Error fetching Keybase key: ${e.message}`)
} }

View file

@ -27,7 +27,7 @@ import { Claim } from './claim.js'
export class Persona { export class Persona {
/** /**
* @param {string} name * @param {string} name
* @param {import('./claim.js').Claim[]} claims * @param {Claim[]} claims
*/ */
constructor (name, claims) { constructor (name, claims) {
/** /**
@ -68,7 +68,7 @@ export class Persona {
this.themeColor = null this.themeColor = null
/** /**
* List of identity claims * List of identity claims
* @type {import('./claim.js').Claim[]} * @type {Claim[]}
* @public * @public
*/ */
this.claims = claims this.claims = claims
@ -145,7 +145,7 @@ export class Persona {
/** /**
* @function * @function
* @param {import('./claim.js').Claim} claim * @param {Claim} claim
*/ */
addClaim (claim) { addClaim (claim) {
this.claims.push(claim) this.claims.push(claim)

View file

@ -13,13 +13,22 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { PublicKeyFetchMethod, PublicKeyEncoding, PublicKeyType } from './enums.js' import { PublicKey } from 'openpgp'
import * as joseMod from 'jose'
import { PublicKeyFetchMethod, PublicKeyEncoding, PublicKeyType, ProfileType } from './enums.js'
import { Persona } from './persona.js' import { Persona } from './persona.js'
/**
* The online verifier instance of identity profiles like Keyoxide's web interface
* @typedef {Object} ProfileVerifier
* @property {string} name - Name of the profile verifier
* @property {string} url - URL to the profile verifier
*/
/** /**
* A profile of personas with identity claims * A profile of personas with identity claims
* @function * @function
* @param {Array<import('./persona.js').Persona>} personas * @param {Array<Persona>} personas
* @public * @public
* @example * @example
* const claim = Claim('https://alice.tld', '123'); * const claim = Claim('https://alice.tld', '123');
@ -30,9 +39,9 @@ export class Profile {
/** /**
* Create a new profile * Create a new profile
* @function * @function
* @param {import('./enums.js').ProfileType} profileType * @param {ProfileType} profileType
* @param {string} identifier * @param {string} identifier
* @param {Array<import('./persona.js').Persona>} personas * @param {Array<Persona>} personas
* @public * @public
*/ */
constructor (profileType, identifier, personas) { constructor (profileType, identifier, personas) {
@ -44,7 +53,7 @@ export class Profile {
this.profileVersion = 2 this.profileVersion = 2
/** /**
* Profile version * Profile version
* @type {import('./enums.js').ProfileType} * @type {ProfileType}
* @public * @public
*/ */
this.profileType = profileType this.profileType = profileType
@ -56,7 +65,7 @@ export class Profile {
this.identifier = identifier this.identifier = identifier
/** /**
* List of personas * List of personas
* @type {Array<import('./persona.js').Persona>} * @type {Array<Persona>}
* @public * @public
*/ */
this.personas = personas || [] this.personas = personas || []
@ -98,7 +107,7 @@ export class Profile {
encodedKey: null, encodedKey: null,
/** /**
* The raw cryptographic key as object (to be removed during toJSON()) * The raw cryptographic key as object (to be removed during toJSON())
* @type {import('openpgp').PublicKey | import('jose').JWK | null} * @type {PublicKey | joseMod.JWK | null}
* @public * @public
*/ */
key: null, key: null,
@ -130,7 +139,7 @@ export class Profile {
} }
/** /**
* List of verifier URLs * List of verifier URLs
* @type {{name: string, url: string}[]} * @type {ProfileVerifier[]}
* @public * @public
*/ */
this.verifiers = [] this.verifiers = []

View file

@ -17,6 +17,7 @@ import { isNode } from 'browser-or-node'
import { fetcher } from './index.js' import { fetcher } from './index.js'
import { generateProxyURL } from './utils.js' import { generateProxyURL } from './utils.js'
import { ProxyPolicy, ProofAccessRestriction } from './enums.js' import { ProxyPolicy, ProofAccessRestriction } from './enums.js'
import { ServiceProvider } from './serviceProvider.js'
/** /**
* @module proofs * @module proofs
@ -29,7 +30,7 @@ import { ProxyPolicy, ProofAccessRestriction } from './enums.js'
* choose the right approach to fetch the proof. An error will be thrown if no * choose the right approach to fetch the proof. An error will be thrown if no
* approach is possible. * approach is possible.
* @async * @async
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */
@ -42,7 +43,7 @@ export async function fetch (data, opts) {
} }
/** /**
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */
@ -85,7 +86,7 @@ const handleBrowserRequests = (data, opts) => {
} }
/** /**
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */
@ -106,7 +107,7 @@ const handleNodeRequests = (data, opts) => {
} }
/** /**
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */
@ -132,7 +133,7 @@ const createDefaultRequestPromise = (data, opts) => {
} }
/** /**
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */
@ -171,7 +172,7 @@ const createProxyRequestPromise = (data, opts) => {
} }
/** /**
* @param {import('./serviceProvider.js').ServiceProvider} data - Data from a claim definition * @param {ServiceProvider} data - Data from a claim definition
* @param {object} opts - Options to enable the request * @param {object} opts - Options to enable the request
* @returns {Promise<object|string>} * @returns {Promise<object|string>}
*/ */

View file

@ -13,6 +13,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { ClaimFormat, ClaimRelation, EntityEncodingFormat, ProofAccessRestriction, ProofFormat } from "./enums"
/**
* The method to find the proof inside the response data
* @typedef {Object} ProofTarget
* @property {ClaimFormat} format - How the response data is formatted
* @property {EntityEncodingFormat} encoding - How the response data is encoded
* @property {ClaimRelation} relation - How the proof is related to the response data
* @property {string[]} path - Path to the proof inside the response data object
*/
/** /**
* A service provider matched to an identity claim * A service provider matched to an identity claim
* @class * @class
@ -104,7 +115,7 @@ export class ServiceProvider {
fetcher: spObj.proof.request.fetcher, fetcher: spObj.proof.request.fetcher,
/** /**
* Type of access restriction * Type of access restriction
* @type {import('./enums.js').ProofAccessRestriction} * @type {ProofAccessRestriction}
*/ */
accessRestriction: spObj.proof.request.accessRestriction, accessRestriction: spObj.proof.request.accessRestriction,
/** /**
@ -120,13 +131,13 @@ export class ServiceProvider {
response: { response: {
/** /**
* Expected format of the proof * Expected format of the proof
* @type {import('./enums.js').ProofFormat} * @type {ProofFormat}
*/ */
format: spObj.proof.response.format format: spObj.proof.response.format
}, },
/** /**
* Details about the target located in the response * Details about the target located in the response
* @type {{format: import('./enums.js').ClaimFormat, encoding: import('./enums.js').EntityEncodingFormat, relation: import('./enums.js').ClaimRelation, path: string[]}[]} * @type {ProofTarget[]}
*/ */
target: spObj.proof.target target: spObj.proof.target
} }

View file

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { readCleartextMessage, verify } from 'openpgp' import { CleartextMessage, PublicKey, readCleartextMessage, verify } from 'openpgp'
import { Claim } from './claim.js' import { Claim } from './claim.js'
import { fetchURI } from './openpgp.js' import { fetchURI } from './openpgp.js'
import { Profile } from './profile.js' import { Profile } from './profile.js'
@ -28,10 +28,10 @@ import { Persona } from './persona.js'
* Extract the profile from a signature and fetch the associated key * Extract the profile from a signature and fetch the associated key
* @async * @async
* @param {string} signature - The plaintext signature to parse * @param {string} signature - The plaintext signature to parse
* @returns {Promise<import('./profile.js').Profile>} * @returns {Promise<Profile>}
*/ */
export async function parse (signature) { export async function parse (signature) {
/** @type {import('openpgp').CleartextMessage} */ /** @type {CleartextMessage} */
let sigData let sigData
// Read the signature // Read the signature
@ -84,7 +84,7 @@ export async function parse (signature) {
if (sigKeys.length > 0) { if (sigKeys.length > 0) {
try { try {
obtainedKey.query = sigKeys[0] obtainedKey.query = sigKeys[0]
/** @type {import('openpgp').PublicKey} */ /** @type {PublicKey} */
obtainedKey.data = (await fetchURI(obtainedKey.query)).publicKey.key obtainedKey.data = (await fetchURI(obtainedKey.query)).publicKey.key
obtainedKey.method = obtainedKey.query.split(':')[0] obtainedKey.method = obtainedKey.query.split(':')[0]
} catch (e) {} } catch (e) {}

View file

@ -17,20 +17,42 @@ import { generateClaim, getUriFromString } from './utils.js'
import { ClaimFormat, EntityEncodingFormat, ClaimRelation, ProofFormat } from './enums.js' import { ClaimFormat, EntityEncodingFormat, ClaimRelation, ProofFormat } from './enums.js'
import { bcryptVerify, argon2Verify } from 'hash-wasm' import { bcryptVerify, argon2Verify } from 'hash-wasm'
import { decodeHTML, decodeXML } from 'entities' import { decodeHTML, decodeXML } from 'entities'
import { ServiceProvider } from './serviceProvider.js'
/** /**
* @module verifications * @module verifications
* @ignore * @ignore
*/ */
/**
* Parameters needed to perform the proof verification
* @typedef {object} VerificationParams
* @property {string} target
* @property {ClaimFormat} claimFormat
* @property {EntityEncodingFormat} proofEncodingFormat
* @property {ClaimRelation} [claimRelation]
*/
/**
* Result of the proof verification
* @typedef {Object} VerificationResult
* @property {boolean} result
* @property {boolean} completed
* @property {VerificationResultProof} [proof]
* @property {any[]} errors
*/
/**
* Information about the proof in the proof verification result
* @typedef {Object} VerificationResultProof
* @property {string} fetcher
* @property {boolean} viaProxy
*/
/** /**
* @function * @function
* @param {string} data * @param {string} data
* @param {object} params * @param {VerificationParams} params
* @param {string} params.target
* @param {string} params.claimFormat
* @param {string} params.proofEncodingFormat
* @param {string} [params.claimRelation]
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
const containsProof = async (data, params) => { const containsProof = async (data, params) => {
@ -218,11 +240,7 @@ const containsProof = async (data, params) => {
* @function * @function
* @param {any} proofData * @param {any} proofData
* @param {string[]} checkPath * @param {string[]} checkPath
* @param {object} params * @param {VerificationParams} params
* @param {string} params.target
* @param {string} params.claimFormat
* @param {string} params.proofEncodingFormat
* @param {string} [params.claimRelation]
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
const runJSON = async (proofData, checkPath, params) => { const runJSON = async (proofData, checkPath, params) => {
@ -272,12 +290,13 @@ const runJSON = async (proofData, checkPath, params) => {
/** /**
* Run the verification by finding the formatted fingerprint in the proof * Run the verification by finding the formatted fingerprint in the proof
* @async * @async
* @param {object} proofData - The proof data * @param {object} proofData - The proof data
* @param {import('./serviceProvider.js').ServiceProvider} claimData - The claim data * @param {ServiceProvider} claimData - The claim data
* @param {string} fingerprint - The fingerprint * @param {string} fingerprint - The fingerprint
* @returns {Promise<object>} * @returns {Promise<VerificationResult>}
*/ */
export async function run (proofData, claimData, fingerprint) { export async function run (proofData, claimData, fingerprint) {
/** @type {VerificationResult} */
const res = { const res = {
result: false, result: false,
completed: false, completed: false,