This is a proposed fix to issue #79, with all the necessary changes made. Based on https://github.com/Hexagon/webauthn but ported back to fido2-lib directory structure and code conventions.
Provided on a take-it-or-leave-it basis, if you include it, I'll continue to support fido2-lib, else i will continue the work on hexagon/webauthn as my main interest is Deno support.
Changes
Made all code portable between node/deno/browser, code base moved from lib/ to lib/common. For example Buffer -> ArrayBuffer/Uint8Array
Upgraded all code to more recent standards (replaced var with letor const etc.)
Moved external (platform dependent) dependencies and utilities to separate toolboxes lib/node/toolbox.js and lib/deno/toolbox.js, which are available to the library as a global variable accessed from utils.tools()
Deleted old commonjs entrypoint index.js - as the package is converted to module, .js files is not usable for commonjs, so it's not possible to keep it for commonjs imports.
Added build step to package.json which uses rollup to generate new commonjs entrypoint dist/node/main.cjs, this need to be run before publishing. This build step runs lint and test before building.
New platform specific ESM-entrypoints lib/node/main.js and lib/deno/main.js
Moved fixtures/ to test/fixtures
Moved all fixture-likes in test/ to test/fixtures
Added Deno-specific tests (not complete coverage, but as almost all code is common, Node tests will cover the rest)
New manual steps before release
Run npm run build, which lints and test source, then build the commonjs entrypoint.
Run npm test deno, which tests Deno compability.
New procedure for managing dependencies
Note: Dependencies that can be used by both Node and Deno with the same code base can be bundled, to avoid duplicate code. Such dependencies is placed in /lib/common/tools
Production dependencies
External dependencies is served to the library by a Node and Deno-specific toolbox, see lib/node/toolbox.js and lib/deno/toolbox.js.
Deno dependency versions are managed directly in lib/deno/toolbox.js
Node dependency versions are managed by package.json as ususal.
Testing dependencies
Deno dev-dependency versions are managed directly in test/deno/common/deps.js
Node dev-dependency versions are managed by package.json as usual.
If adding or upgrading an external dependency, please make sure to include it in both Node and Deno toolbox.
Comments
All current tests pass, but certain parts of the library has low test coverage (tpm and u2f attestation for example)
Deno tests added for basic sanity check, and Deno-specific tools.
The basic interface has not changed much (if any) but this should really be released as a new major if accepted.
Added npm scripts
test:deno
lint:deno
lint:deno:fix
build
Dependency changes
Removed npm deps
cose-to-jwk (modified and bundled)
mockery (not used?)
bytestream (not used?)
pvutils (not used directly)
psl (not esm-compilant, replaced by tldts + punycode + new utility functions - validEtldPlusOne and validDomainName)
cbor (not esm-compilant, replaced by cbor-x)
Updated npm deps
sinon ^7 -> ^13
eslint ^8.7 -> ^8.13
@peculiar/webcrypto ^1.2 -> ^1.3
Added npm deps
tldts (replacement for psl)
punycode (for domain name checking, previously part of psl)
cbor-x (replacement for cbor)
rollup (dev-dependency for building commonjs module)
Bundled dependencies
cose-to-jwk (needed modification to be portable, so I modified and bundled it)
@hexagon/base64 is bundled, as it supports all uses cases, both cjs and esm, Node and Deno. And since base64 is used "everywhere" - I bundled it insted of having separate inclusions through the toolboxes.
Overview
This is a proposed fix to issue #79, with all the necessary changes made. Based on https://github.com/Hexagon/webauthn but ported back to fido2-lib directory structure and code conventions.
Provided on a take-it-or-leave-it basis, if you include it, I'll continue to support fido2-lib, else i will continue the work on hexagon/webauthn as my main interest is Deno support.
Changes
lib/
tolib/common
. For exampleBuffer
->ArrayBuffer
/Uint8Array
var
withlet
orconst
etc.)lib/node/toolbox.js
andlib/deno/toolbox.js
, which are available to the library as a global variable accessed fromutils.tools()
index.js
- as the package is converted to module,.js
files is not usable for commonjs, so it's not possible to keep it for commonjs imports.package.json
which uses rollup to generate new commonjs entrypointdist/node/main.cjs
, this need to be run before publishing. This build step runs lint and test before building.lib/node/main.js
andlib/deno/main.js
fixtures/
totest/fixtures
test/
totest/fixtures
New manual steps before release
npm run build
, which lints and test source, then build the commonjs entrypoint.npm test deno
, which tests Deno compability.New procedure for managing dependencies
Note: Dependencies that can be used by both Node and Deno with the same code base can be bundled, to avoid duplicate code. Such dependencies is placed in
/lib/common/tools
Production dependencies
lib/node/toolbox.js
andlib/deno/toolbox.js
.lib/deno/toolbox.js
package.json
as ususal.Testing dependencies
test/deno/common/deps.js
package.json
as usual.If adding or upgrading an external dependency, please make sure to include it in both Node and Deno toolbox.
Comments
Added npm scripts
Dependency changes
Removed npm deps
Updated npm deps
Added npm deps
Bundled dependencies