MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 137 forks source link

crypto dependency fails when use in the edge #386

Closed jadedevin13 closed 1 year ago

jadedevin13 commented 1 year ago
Import trace for requested module:
build: node:crypto
build: ./node_modules/@simplewebauthn/iso-webcrypto/dist/node.js
build: ./node_modules/@simplewebauthn/server/dist/helpers/iso/isoCrypto/verifyEC2.js
build: ./node_modules/@simplewebauthn/server/dist/metadata/verifyJWT.js
build: ./node_modules/@simplewebauthn/server/dist/services/metadataService.js
build: ./node_modules/@simplewebauthn/server/dist/index.js
MasterKale commented 1 year ago

Hello @jadedevin13, please fill out the issue template. And because you mentioned "edge", please include the cloud runtime and a code sample to reproduce the issue.

MasterKale commented 1 year ago

SimpleWebAuthn isn't yet supported for use in ESM-only environments. I'm working on this though. See #338 and #366.

jadedevin13 commented 1 year ago

I'll try to test the following codes over the weekend.


// Import webcrypto
import * as platformCrypto from "crypto";
import * as peculiarCrypto from "@peculiar/webcrypto";
let webcrypto;
if ((typeof self !== "undefined") && "crypto" in self) {
    // Always use crypto if available natively (browser / Deno)
    webcrypto = self.crypto;

} else {
    // Always use node webcrypto if available ( >= 16.0 )
    if(platformCrypto && platformCrypto.webcrypto) {
        webcrypto = platformCrypto.webcrypto;

    } else {
        // Fallback to @peculiar/webcrypto
        webcrypto = new peculiarCrypto.Crypto();
    }
}