Git Product home page Git Product logo

tiny-webcrypto's Introduction

Tiny WebCrypto

A tiny isomorphic WebCrypto object, it just gives you the native one the current platform provides.

Install

npm install --save tiny-webcrypto

Usage

import WebCrypto from 'tiny-webcrypto';

WebCrypto.randomUUID (); // => '43e16416-7a2a-4c00-b2e8-1ea7a57adfb9'

License

MIT © Fabio Spampinato

tiny-webcrypto's People

Contributors

fabiospampinato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tiny-webcrypto's Issues

Issues using tiny-webcrypto in CommonJS Node libraries

First off, thank you for offering a potentially easier path forward for writing isomorphic libraries using the WebCrypto API.

I'm having an issue with a large rewrite of my @simplewebauthn/server Node library, trying to make it work in more than just Node. Unfortunately, after outputting a CommonJS build of my library, attempts to use my library error out because tiny-webcrypto's build seems to only output ESM:

/Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/iso/isoCrypto/digest.js:7
const tiny_webcrypto_1 = __importDefault(require("tiny-webcrypto"));
                                         ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/matt/Developer/simplewebauthn/packages/server/
  node_modules/tiny-webcrypto/dist/node.js from /Users/matt/Developer/simplewebauthn/packages/server/
  dist/helpers/iso/isoCrypto/digest.js not supported.
Instead change the require of node.js in /Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/iso/
  isoCrypto/digest.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/iso/isoCrypto/digest.js:7:42)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/iso/isoCrypto/index.js:4:16)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/iso/index.js:36:34)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/helpers/generateChallenge.js:4:15)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/registration/generateRegistrationOptions.js:4:29)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/packages/server/dist/index.js:8:39)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/example/index.ts:43:18)
    at Module.m._compile (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/index.js:791:29)
    at Object.require.extensions.<computed> [as .ts] (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/index.js:793:16)
    at phase4 (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/bin.js:407:16)
    at bootstrap (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/bin.js:49:12)
    at main (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/bin.js:32:12)
    at Object.<anonymous> (/Users/matt/Developer/simplewebauthn/example/node_modules/ts-node/dist/bin.js:519:5) {
  code: 'ERR_REQUIRE_ESM'
}

I'd rather not refactor my WebCrypto-consuming code to use await import() as suggested in the error because doing so would drastically change the API of methods that are currently synchronous by requiring they become asynchronous, and force methods that consume those methods to update their method signatures to become asynchronous as well. I'm trying to avoid making too many breaking changes like that with this rewrite.

Do you have any recommendations for how I might work past this? Is there any chance of this project including a CommonJS version for those TypeScript projects building with "module": "commonjs" in their package.json?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.