@bcts/provenance-mark 1.0.0-alpha.18 → 1.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  let _bcts_dcbor = require("@bcts/dcbor");
2
3
  let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
3
4
  let _noble_hashes_hkdf_js = require("@noble/hashes/hkdf.js");
@@ -743,6 +744,12 @@ var ProvenanceSeed = class ProvenanceSeed {
743
744
  //#endregion
744
745
  //#region src/utils.ts
745
746
  /**
747
+ * Utility functions for byte array conversions.
748
+ *
749
+ * These functions provide cross-platform support for common byte manipulation
750
+ * operations needed in provenance mark encoding.
751
+ */
752
+ /**
746
753
  * Convert a Uint8Array to a lowercase hexadecimal string.
747
754
  *
748
755
  * @param data - The byte array to convert
@@ -760,18 +767,9 @@ function bytesToHex(data) {
760
767
  * @returns A base64-encoded string
761
768
  */
762
769
  function toBase64(data) {
763
- const globalBtoa = globalThis.btoa;
764
- if (typeof globalBtoa === "function") {
765
- let binary = "";
766
- for (const byte of data) binary += String.fromCharCode(byte);
767
- return globalBtoa(binary);
768
- }
769
- const requireFn = require;
770
- if (typeof requireFn === "function") {
771
- const { Buffer: NodeBuffer } = requireFn("buffer");
772
- return NodeBuffer.from(data).toString("base64");
773
- }
774
- throw new Error("btoa not available and require is not defined");
770
+ let binary = "";
771
+ for (const byte of data) binary += String.fromCharCode(byte);
772
+ return btoa(binary);
775
773
  }
776
774
  /**
777
775
  * Convert a base64-encoded string to a Uint8Array.
@@ -782,19 +780,10 @@ function toBase64(data) {
782
780
  * @returns The decoded byte array
783
781
  */
784
782
  function fromBase64(base64) {
785
- const globalAtob = globalThis.atob;
786
- if (typeof globalAtob === "function") {
787
- const binary = globalAtob(base64);
788
- const bytes = new Uint8Array(binary.length);
789
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
790
- return bytes;
791
- }
792
- const requireFn = require;
793
- if (typeof requireFn === "function") {
794
- const { Buffer: NodeBuffer } = requireFn("buffer");
795
- return new Uint8Array(NodeBuffer.from(base64, "base64"));
796
- }
797
- throw new Error("atob not available and require is not defined");
783
+ const binary = atob(base64);
784
+ const bytes = new Uint8Array(binary.length);
785
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
786
+ return bytes;
798
787
  }
799
788
 
800
789
  //#endregion