From 3de5690added3e2b5e545430e606546bcc57e60e Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 4 Oct 2023 13:51:14 -0400 Subject: [PATCH 1/2] add buffer polyfill for webauthn-stamper --- packages/webauthn-stamper/package.json | 3 +++ packages/webauthn-stamper/src/index.ts | 1 + packages/webauthn-stamper/src/universal.ts | 9 +++++++++ pnpm-lock.yaml | 14 +++++++------- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 packages/webauthn-stamper/src/universal.ts diff --git a/packages/webauthn-stamper/package.json b/packages/webauthn-stamper/package.json index db5990916..7b143eb56 100644 --- a/packages/webauthn-stamper/package.json +++ b/packages/webauthn-stamper/package.json @@ -39,5 +39,8 @@ }, "engines": { "node": ">=16.0.0" + }, + "dependencies": { + "buffer": "^6.0.3" } } diff --git a/packages/webauthn-stamper/src/index.ts b/packages/webauthn-stamper/src/index.ts index 48e3fad02..016671663 100644 --- a/packages/webauthn-stamper/src/index.ts +++ b/packages/webauthn-stamper/src/index.ts @@ -1,5 +1,6 @@ /// import { get as webauthnCredentialGet } from "./webauthn-json"; +import { buffer as Buffer } from "./universal"; // Header name for a webauthn stamp const stampHeaderName = "X-Stamp-Webauthn"; diff --git a/packages/webauthn-stamper/src/universal.ts b/packages/webauthn-stamper/src/universal.ts new file mode 100644 index 000000000..f3c3bee79 --- /dev/null +++ b/packages/webauthn-stamper/src/universal.ts @@ -0,0 +1,9 @@ +let buffer: typeof globalThis.Buffer; + +if (typeof globalThis?.Buffer !== "undefined") { + buffer = globalThis.Buffer; +} else { + buffer = require("buffer"); +} + +export { buffer }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9f255b23d..b9a8ab2b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -619,7 +619,11 @@ importers: specifier: ^1.10.0 version: 1.10.0(typescript@5.1.3) - packages/webauthn-stamper: {} + packages/webauthn-stamper: + dependencies: + buffer: + specifier: ^6.0.3 + version: 6.0.3 packages: @@ -4480,7 +4484,7 @@ packages: /@types/bn.js@5.1.2: resolution: {integrity: sha512-dkpZu0szUtn9UXTmw+e0AJFd4D2XAxDnsCLdc05SfqpqzPEBft8eQr8uaFitfo/dUUOZERaLec2hHMG87A4Dxg==} dependencies: - '@types/node': 20.6.2 + '@types/node': 16.18.12 dev: false /@types/connect@3.4.35: @@ -4545,10 +4549,6 @@ packages: resolution: {integrity: sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==} dev: false - /@types/node@20.6.2: - resolution: {integrity: sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==} - dev: false - /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} dev: true @@ -4590,7 +4590,7 @@ packages: /@types/readable-stream@2.3.15: resolution: {integrity: sha512-oM5JSKQCcICF1wvGgmecmHldZ48OZamtMxcGGVICOJA8o8cahXC1zEVAif8iwoc5j8etxFaRFnf095+CDsuoFQ==} dependencies: - '@types/node': 20.6.2 + '@types/node': 16.18.12 safe-buffer: 5.1.2 dev: false From a96c30fc0341564ae663202ef95b9e0c6c20fa99 Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 4 Oct 2023 15:50:57 -0400 Subject: [PATCH 2/2] use subproperty --- packages/webauthn-stamper/src/universal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webauthn-stamper/src/universal.ts b/packages/webauthn-stamper/src/universal.ts index f3c3bee79..127f02a70 100644 --- a/packages/webauthn-stamper/src/universal.ts +++ b/packages/webauthn-stamper/src/universal.ts @@ -3,7 +3,7 @@ let buffer: typeof globalThis.Buffer; if (typeof globalThis?.Buffer !== "undefined") { buffer = globalThis.Buffer; } else { - buffer = require("buffer"); + buffer = require("buffer").Buffer; } export { buffer };