diff --git a/dist/index.d.ts b/dist/index.d.ts index 4329dbf..c3bd86c 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -6,8 +6,9 @@ */ import * as rdf from '@rdfjs/types'; import { KeyData, VerificationResult } from './lib/types'; -export { KeyData, VerificationResult, KeyMetadata, Cryptosuites } from './lib/types'; -export { generateKey, KeyDetails } from './lib/crypto_utils'; +export type { KeyData, VerificationResult, KeyMetadata, Cryptosuites } from './lib/types'; +export type { KeyDetails } from './lib/crypto_utils'; +export { generateKey } from './lib/crypto_utils'; /** * Generate a (separate) proof graph (or graphs), per the DI spec. The signature is stored in * multibase format, using base64url encoding. Keys are accepted, and stored in JWK format. diff --git a/dist/index.js b/dist/index.js index 3fdc692..9930aab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6,14 +6,11 @@ * @packageDocumentation */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.verifyEmbeddedProofGraph = exports.embedProofGraph = exports.verifyProofGraph = exports.generateProofGraph = exports.generateKey = exports.Cryptosuites = void 0; +exports.verifyEmbeddedProofGraph = exports.embedProofGraph = exports.verifyProofGraph = exports.generateProofGraph = exports.generateKey = void 0; const n3 = require("n3"); const types = require("./lib/types"); const utils_1 = require("./lib/utils"); const proof_utils_1 = require("./lib/proof_utils"); -/* This file is also the "top level", so a number of exports are put here to be more friendly to users */ -var types_1 = require("./lib/types"); -Object.defineProperty(exports, "Cryptosuites", { enumerable: true, get: function () { return types_1.Cryptosuites; } }); var crypto_utils_1 = require("./lib/crypto_utils"); Object.defineProperty(exports, "generateKey", { enumerable: true, get: function () { return crypto_utils_1.generateKey; } }); // n3.DataFactory is a namespace with some functions... diff --git a/dist/lib/crypto_utils.js b/dist/lib/crypto_utils.js index 447d8f5..bdd35a4 100644 --- a/dist/lib/crypto_utils.js +++ b/dist/lib/crypto_utils.js @@ -47,13 +47,6 @@ const RsaAlgs = { */ function algorithmData(report, key) { switch (key.kty) { - case "EC": { - return { - name: "ECDSA", - namedCurve: key.crv, - hash: DEFAULT_HASH - }; - } case "RSA": { try { return RsaAlgs[key.alg]; @@ -63,6 +56,14 @@ function algorithmData(report, key) { return null; } } + case "EC": + default: { + return { + name: "ECDSA", + namedCurve: key.crv, + hash: DEFAULT_HASH + }; + } } } /** @@ -221,13 +222,18 @@ function cryptosuiteId(report, keyPair) { return null; } const alg = algorithmData(report, keyPair.public); - switch (alg.name) { - case "ECDSA": return types_1.Cryptosuites.ecdsa; - case "RSA-PSS": return types_1.Cryptosuites.rsa_pss; - case "RSASSA-PKCS1-v1_5": return types_1.Cryptosuites.rsa_ssa; - default: { - report.errors.push(new types.Invalid_Verification_Method(`Unknown alg (${alg.name} in:\n ${JSON.stringify(keyPair, null, 4)})`)); - return null; + if (alg === null) { + return null; + } + else { + switch (alg.name) { + case "ECDSA": return types_1.Cryptosuites.ecdsa; + case "RSA-PSS": return types_1.Cryptosuites.rsa_pss; + case "RSASSA-PKCS1-v1_5": return types_1.Cryptosuites.rsa_ssa; + default: { + report.errors.push(new types.Invalid_Verification_Method(`Unknown alg (${alg.name} in:\n ${JSON.stringify(keyPair, null, 4)})`)); + return null; + } } } } diff --git a/dist/lib/proof_utils.js b/dist/lib/proof_utils.js index 88cfed9..961f9aa 100644 --- a/dist/lib/proof_utils.js +++ b/dist/lib/proof_utils.js @@ -76,7 +76,15 @@ async function generateAProofGraph(report, hashValue, keyData) { retval.add(quad(keyResource, exports.sec_revoked, literal(keyData.revoked, exports.xsd_datetime))); return retval; }; - return createProofGraph(await (0, crypto_utils_1.sign)(report, hashValue, keyData.private)); + const signature = await (0, crypto_utils_1.sign)(report, hashValue, keyData.private); + if (signature === null) { + // An error has occurred during signature; details are in the report. + // No proof graph is generated + return new n3.Store(); + } + else { + return createProofGraph(signature); + } } exports.generateAProofGraph = generateAProofGraph; ; @@ -230,6 +238,7 @@ async function verifyAProofGraph(report, hash, proof, proofId) { */ async function verifyProofGraphs(report, hash, proofs) { const allErrors = []; + // deno-lint-ignore require-await const singleVerification = async (pr) => { const singleReport = { errors: [], warnings: [] }; allErrors.push(singleReport); diff --git a/dist/lib/utils.js b/dist/lib/utils.js index 208b2cc..8de7ba4 100644 --- a/dist/lib/utils.js +++ b/dist/lib/utils.js @@ -106,6 +106,7 @@ exports.DatasetMap = DatasetMap; * @param obj * @returns */ +// deno-lint-ignore no-explicit-any function isDatasetCore(obj) { return obj.add !== undefined && obj.delete !== undefined && @@ -119,6 +120,7 @@ exports.isDatasetCore = isDatasetCore; * @param obj * @returns */ +// deno-lint-ignore no-explicit-any function isKeyData(obj) { return obj.public !== undefined && obj.private !== undefined; } @@ -180,6 +182,7 @@ function write_quads(dataset) { const writer = new n3.Writer({ prefixes: prefixes }); for (const q of dataset) writer.addQuad(q); - writer.end((error, result) => console.log(result)); + // deno-lint-ignore no-explicit-any + writer.end((_error, result) => console.log(result)); } exports.write_quads = write_quads;