diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 93% rename from .eslintrc.js rename to .eslintrc.cjs index fab9b28..d51d4d7 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -4,7 +4,7 @@ module.exports = { parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint', 'prettier'], parserOptions: { - project: './tsconfig.json' + project: './tsconfig.esm.json' }, ignorePatterns: ['dist/', 'test'], rules: { diff --git a/CHANGELOG.md b/CHANGELOG.md index 2771855..3e74e54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # security-document-loader Changelog +## 7.0.0 - 2025-04-30 +### Changed +- switch to `@digitalcredentials/did-method-web` from `@interop/did-web-resolver` for did-web resolution +- rework build process +- update dependencies +- **BREAKING**: remove cjs build + ## 6.0.1 - 2024-11-12 ### Fixed - Fix Typescript types declaration ([PR #17](https://github.com/digitalcredentials/security-document-loader/pull/17/files)). diff --git a/build-dist.sh b/build-dist.sh deleted file mode 100755 index 8501e09..0000000 --- a/build-dist.sh +++ /dev/null @@ -1,12 +0,0 @@ -mkdir ./dist/esm -cat >dist/esm/index.js <dist/esm/package.json <=16.0" }, diff --git a/src/declarations.d.ts b/src/declarations.d.ts index 66db07a..48ec2cc 100644 --- a/src/declarations.d.ts +++ b/src/declarations.d.ts @@ -5,6 +5,8 @@ declare module '@digitalcredentials/vc'; declare module '@digitalbazaar/vc-bitstring-status-list-context'; declare module '@digitalcredentials/vc-status-list'; declare module '@digitalbazaar/vc-status-list-context'; +declare module '@digitalcredentials/did-method-web'; +declare module '@digitalcredentials/ed25519-multikey'; declare module '@digitalcredentials/vpqr'; declare module '@digitalbazaar/data-integrity-context'; declare module '@digitalcredentials/ed25519-verification-key-2020'; diff --git a/src/documentLoader.ts b/src/documentLoader.ts index f4ebde4..93d7387 100644 --- a/src/documentLoader.ts +++ b/src/documentLoader.ts @@ -2,37 +2,43 @@ * Copyright (c) 2021 Interop Alliance and Dmitri Zagidulin. All rights reserved. */ import * as didKey from '@digitalcredentials/did-method-key'; -import * as didWeb from '@interop/did-web-resolver'; +import * as didWeb from '@digitalcredentials/did-method-web'; import * as vc2Context from '@digitalcredentials/credentials-v2-context'; import * as vcBitstringStatusListContext from '@digitalbazaar/vc-bitstring-status-list-context'; import vc1Context from 'credentials-context'; import vcStatusListContext from '@digitalbazaar/vc-status-list-context'; import dataIntegrityContext from '@digitalbazaar/data-integrity-context'; -import { Ed25519VerificationKey2020 } - from '@digitalcredentials/ed25519-verification-key-2020'; -import { X25519KeyAgreementKey2020 } - from '@digitalcredentials/x25519-key-agreement-key-2020'; +import * as Ed25519Multikey from '@digitalcredentials/ed25519-multikey'; +// import { Ed25519VerificationKey2020 } + // from '@digitalcredentials/ed25519-verification-key-2020'; +// import { X25519KeyAgreementKey2020 } + // from '@digitalcredentials/x25519-key-agreement-key-2020'; import { CachedResolver } from '@digitalcredentials/did-io'; import dccContext from '@digitalcredentials/dcc-context'; import didContext from 'did-context'; import ed25519Context from 'ed25519-signature-2020-context'; import x25519Context from 'x25519-key-agreement-2020-context'; import { JsonLdDocumentLoader } from 'jsonld-document-loader'; -import { CryptoLD } from '@digitalcredentials/crypto-ld'; import obContext from '@digitalcredentials/open-badges-context'; import { httpClient } from '@digitalcredentials/http-client'; -import { parseResponseBody } from './parseResponse'; +import { parseResponseBody } from './parseResponse.js'; -const cryptoLd = new CryptoLD(); -cryptoLd.use(Ed25519VerificationKey2020); -cryptoLd.use(X25519KeyAgreementKey2020); -const didWebDriver = didWeb.driver({ cryptoLd }); - -const didKeyDriver = didKey.driver(); const resolver = new CachedResolver(); +const didKeyDriver = didKey.driver(); +const didWebDriver = didWeb.driver(); resolver.use(didKeyDriver); resolver.use(didWebDriver); +didWebDriver.use({ + multibaseMultikeyHeader: 'z6Mk', + fromMultibase: Ed25519Multikey.from +}); + +didKeyDriver.use({ + multibaseMultikeyHeader: 'z6Mk', + fromMultibase: Ed25519Multikey.from +}); + export const httpClientHandler = { /** * @param {object} options - Options hashmap. diff --git a/src/index.ts b/src/index.ts index 381932e..eee940d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ /*! * Copyright (c) 2021 Interop Alliance and Dmitri Zagidulin. All rights reserved. */ -export { securityLoader, httpClientHandler } from './documentLoader' +export { httpClientHandler, securityLoader } from './documentLoader.js' + diff --git a/test/documentLoader.spec.ts b/test/documentLoader.spec.ts index 2444ba3..b14ed11 100644 --- a/test/documentLoader.spec.ts +++ b/test/documentLoader.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { httpClientHandler, securityLoader } from '../src'; +import { httpClientHandler, securityLoader } from '../src/index.js'; describe('documentLoader', () => { it('should load a document', async () => { @@ -31,6 +31,23 @@ describe('documentLoader', () => { const result = await documentLoader(url); expect(result.document).to.exist; }); + + it('should load a did:web document from web', async () => { + const documentLoader = securityLoader({fetchRemoteContexts: true}).build(); + const url = 'https://digitalcredentials.github.io/dcc-did-web/did.json'; + const result = await documentLoader(url); + expect(result.document).to.exist; + expect(result.document.assertionMethod.type === 'Ed25519VerificationKey2020') + }); + + it('should load a multikey did:web document from web', async () => { + const documentLoader = securityLoader({fetchRemoteContexts: true}).build(); + const url = 'https://digitalcredentials.github.io/dcc-did-web/multikey/did.json'; + const result = await documentLoader(url); + expect(result.document).to.exist; + expect(result.document.verificationMethod.type === 'Multkey') + }); + it('supports beta OBv3 context', async () => { const load = securityLoader().build() diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..f60d22e --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2022", + "lib": ["es2022", "dom"], + "module": "es2022", + "moduleResolution": "nodenext", + "outDir": "dist", + "noImplicitAny": true, + "removeComments": false, + "preserveConstEnums": true, + "baseUrl": ".", + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "resolveJsonModule": true + }, + "ts-node": { "files": true }, + "include": [ + "src/**/*", + ".eslintrc.js", + "karma.conf.js" + ], + "exclude": ["node_modules", "dist", "test"] +} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 5ccf6c9..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "include": [ - "src/**/*", - ".eslintrc.js", - "karma.conf.js" - ], - "exclude": [ - "./test/", - "./node_modules/", - "./dist/" - ], - "ts-node": { - "files": true - }, - "files": [ - "src/declarations.d.ts" - ], - "compileOnSave": true, - "compilerOptions": { - /* Basic Options */ - "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": ["esnext", "dom"], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ - "declarationDir": "./dist", - "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist", /* Redirect output structure to the directory. */ - "rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - "resolveJsonModule": true, - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - "skipDefaultLibCheck": true, - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // https://github.com/microsoft/TypeScript/wiki/Performance#controlling-types-inclusion: - "types": ["mocha", "node"], /* Type declaration files to be included in compilation. */ - "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - // Prevent developers on different OSes from running into problems: - "forceConsistentCasingInFileNames": true, - - /* Advanced Options */ - "stripInternal": true, /* Do not emit declarations for code that has an @internal annotation in it’s JSDoc comment. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - } -} diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..81578aa --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2022", + "lib": ["es2022", "dom"], + "module": "es2022", + "moduleResolution": "nodenext", + "outDir": "dist", + "noImplicitAny": true, + "removeComments": false, + "preserveConstEnums": true, + "baseUrl": ".", + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "resolveJsonModule": true + }, + "ts-node": {"files": true}, + "include": ["src/**/*", "test/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..6ec87b1 --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2022", + "lib": ["es2022", "dom"], + "module": "es2022", + "moduleResolution": "nodenext", + "outDir": "dist", + "noImplicitAny": true, + "removeComments": false, + "preserveConstEnums": true, + "baseUrl": ".", + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "declaration": true, + "emitDeclarationOnly": true, + "declarationDir": "dist" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test"] +}