From 6c663f89c8931c01df4a7f7e1c01200ef85b09ca Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 8 Oct 2025 13:48:25 -0400 Subject: [PATCH 1/2] Eliminate dependencies. --- CHANGELOG.md | 9 +++++++++ lib/httpDigest.js | 3 +-- lib/util-browser.js | 19 +++++++++++++++++++ lib/util.js | 10 ++++++++++ package.json | 7 +++---- 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 lib/util-browser.js create mode 100644 lib/util.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ab178..60f26b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # @digitalbazaar/http-digest-header Changelog +## 2.2.0 - 2025-10-dd + +### Changed +- Eliminate dependencies in favor of native platform support for simple + (and rarely used) polyfill fallbacks which may be removed in future + versions. Dependencies removed: + - `@digitalbazaar/base64url-universal` + - `js-base64`. + ## 2.1.0 - 2025-10-07 ### Added diff --git a/lib/httpDigest.js b/lib/httpDigest.js index bc8ff47..c6550e8 100644 --- a/lib/httpDigest.js +++ b/lib/httpDigest.js @@ -1,8 +1,7 @@ /*! * Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved. */ -import {fromUint8Array as base64Encode} from 'js-base64'; -import {encode as base64urlEncode} from 'base64url-universal'; +import {base64Encode, base64urlEncode} from './util.js'; const {crypto} = globalThis; diff --git a/lib/util-browser.js b/lib/util-browser.js new file mode 100644 index 0000000..6dacf1b --- /dev/null +++ b/lib/util-browser.js @@ -0,0 +1,19 @@ +/*! + * Copyright (c) 2021-2025 Digital Bazaar, Inc. All rights reserved. + */ +export function base64Encode(bytes) { + if(bytes.toBase64) { + return bytes.toBase64(); + } + return btoa(Array.from(bytes, b => String.fromCodePoint(b)).join('')); +} + +export function base64urlEncode(bytes) { + if(bytes.toBase64) { + return bytes.toBase64({alphabet: 'base64url', omitPadding: true}); + } + return base64Encode(bytes) + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replaceAll('=', ''); +} diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..c524a16 --- /dev/null +++ b/lib/util.js @@ -0,0 +1,10 @@ +/*! + * Copyright (c) 2021-2025 Digital Bazaar, Inc. All rights reserved. + */ +export function base64Encode(bytes) { + return Buffer.from(bytes).toString('base64'); +} + +export function base64urlEncode(bytes) { + return Buffer.from(bytes).toString('base64url'); +} diff --git a/package.json b/package.json index 2318e27..32b8d68 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,12 @@ }, "type": "module", "exports": "./lib/index.js", + "browser": { + "./lib/util.js": "./lib/util-browser.js" + }, "files": [ "lib/**/*.js" ], - "dependencies": { - "base64url-universal": "^2.0.0", - "js-base64": "^3.7.2" - }, "devDependencies": { "c8": "^10.1.3", "chai": "^4.3.6", From 9ca8f23e5ce5d5cf1b3f4af8295ea86fa2434952 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 8 Oct 2025 14:09:43 -0400 Subject: [PATCH 2/2] Fix changelog entry. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f26b9..4c1cc62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Eliminate dependencies in favor of native platform support for simple (and rarely used) polyfill fallbacks which may be removed in future versions. Dependencies removed: - - `@digitalbazaar/base64url-universal` + - `base64url-universal` - `js-base64`. ## 2.1.0 - 2025-10-07