base58check.js 874 B

123456789101112131415161718
  1. import { sha256 } from '@noble/hashes/sha2.js'
  2. import { makeBase58check } from './fallback/base58check.js'
  3. // Note: while API is async, we use hashSync for now until we improve webcrypto perf for hash256
  4. // Inputs to base58 are typically very small, and that makes a difference
  5. // Note: using native WebCrypto will have to have account for SharedArrayBuffer
  6. const hash256sync = (x) => sha256(sha256(x))
  7. const hash256 = hash256sync // See note at the top
  8. const b58c = /* @__PURE__ */ makeBase58check(hash256, hash256sync)
  9. export const toBase58check = /* @__PURE__ */ (() => b58c.encode)()
  10. export const fromBase58check = /* @__PURE__ */ (() => b58c.decode)()
  11. export const toBase58checkSync = /* @__PURE__ */ (() => b58c.encodeSync)()
  12. export const fromBase58checkSync = /* @__PURE__ */ (() => b58c.decodeSync)()
  13. export { makeBase58check } from './fallback/base58check.js'