diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ab178..4c1cc62 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: + - `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",