pmcrypto icon indicating copy to clipboard operation
pmcrypto copied to clipboard

Refactor (and consider moving) base64 and utf8 utils

Open larabr opened this issue 2 years ago • 1 comments

We should review if these utils are needed in the library, otherwise move them over to the clients monorepo.

Regardless, the following refactoring should be done:

  • Remove the binary string variants encodeUtf8 and decodeUtf8
  • Accept/return Uint8Arrays for base64 encoding/decoding
  • Remove encodeUtf8Base64 and decodeUtf8Base64 (they can just chain two functions)

decodeBase64 (or base64ToBytes/Array) should return a Uint8Array, and then utf8BytesToString should take a Uint8Array and return a string, so that utf8BytesToString ∘ base64ToBytes == decodeUtf8Base64.

And then if binary strings are needed in some cases, binaryStringToArray / arrayToBinaryString can be used.

larabr avatar Jul 21 '22 11:07 larabr

just use scure-base which is independently audited, minimal, 0-dep base64 lib.

paulmillr avatar Feb 28 '23 18:02 paulmillr