diff --git a/bun.lockb b/bun.lockb index a082c303..f107a5b2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b3f2ba09..777a92ba 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "@noble/curves": "^1.2.0", "@noble/hashes": "^1.3.2", "@scure/base": "^1.1.3", - "bech32": "^2.0.0", - "uint8arrays": "^4.0.6" + "bech32": "^2.0.0" } } diff --git a/src/coin/bcn.ts b/src/coin/bcn.ts index 863f76d0..81de7503 100644 --- a/src/coin/bcn.ts +++ b/src/coin/bcn.ts @@ -1,7 +1,7 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { keccak_256 } from "@noble/hashes/sha3"; import { concatBytes } from "@noble/hashes/utils"; import { utils } from "@scure/base"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js"; @@ -21,8 +21,8 @@ export const decodeBcnAddress = (source: string): Uint8Array => { if ( decoded.length < 68 || - (!equals(tag, new Uint8Array([0x06])) && - !equals(tag, new Uint8Array([0xce, 0xf6, 0x22]))) + (!equalBytes(tag, new Uint8Array([0x06])) && + !equalBytes(tag, new Uint8Array([0xce, 0xf6, 0x22]))) ) throw new Error("Unrecognised address format"); diff --git a/src/coin/fil.ts b/src/coin/fil.ts index e5a354af..0439e84d 100644 --- a/src/coin/fil.ts +++ b/src/coin/fil.ts @@ -1,6 +1,6 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { concatBytes } from "@noble/hashes/utils"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { base32Decode, @@ -65,7 +65,7 @@ export const decodeFilAddress = (source: string): Uint8Array => { const decoded = concatBytes(protocolByte, payload); const newChecksum = filChecksum(decoded); - if (!equals(checksum, newChecksum)) + if (!equalBytes(checksum, newChecksum)) throw new Error("Unrecognised address format"); return decoded; diff --git a/src/coin/sc.ts b/src/coin/sc.ts index 3a789a5c..dd4686ae 100644 --- a/src/coin/sc.ts +++ b/src/coin/sc.ts @@ -1,6 +1,6 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { concatBytes } from "@noble/hashes/utils"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { bytesToHexWithoutPrefix, @@ -28,7 +28,7 @@ export const decodeScAddress = (source: string): Uint8Array => { const checksum = decoded.slice(-checksumLength); const newChecksum = scChecksum(payload); - if (!equals(checksum, newChecksum)) + if (!equalBytes(checksum, newChecksum)) throw new Error("Unrecognised address format"); return payload; diff --git a/src/coin/stx.ts b/src/coin/stx.ts index 84472d7a..947b7da8 100644 --- a/src/coin/stx.ts +++ b/src/coin/stx.ts @@ -1,6 +1,6 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { sha256 } from "@noble/hashes/sha256"; import { concatBytes } from "@noble/hashes/utils"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { base32Decode, @@ -29,10 +29,12 @@ export const encodeStxAddress = (source: Uint8Array): string => { let version: string; let encoded: string; - if (equals(checksum, stxChecksum(concatBytes(p2pkhVersion, hash160)))) { + if (equalBytes(checksum, stxChecksum(concatBytes(p2pkhVersion, hash160)))) { version = "P"; encoded = base32Encode(source, crockfordBase32Options); - } else if (equals(checksum, stxChecksum(concatBytes(p2shVersion, hash160)))) { + } else if ( + equalBytes(checksum, stxChecksum(concatBytes(p2shVersion, hash160))) + ) { version = "M"; encoded = base32Encode(source, crockfordBase32Options); } else throw new Error("Unrecognised address format"); @@ -56,7 +58,7 @@ export const decodeStxAddress = (source: string): Uint8Array => { const checksum = payload.slice(-checkumLength); const newChecksum = stxChecksum(concatBytes(versionBytes, decoded)); - if (!equals(checksum, newChecksum)) + if (!equalBytes(checksum, newChecksum)) throw new Error("Unrecognised address format"); return payload; diff --git a/src/coin/vsys.ts b/src/coin/vsys.ts index fb9e7f22..b28fc8c1 100644 --- a/src/coin/vsys.ts +++ b/src/coin/vsys.ts @@ -1,6 +1,6 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { keccak_256 } from "@noble/hashes/sha3"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { base58DecodeNoCheck, base58EncodeNoCheck } from "../utils/base58.js"; @@ -15,7 +15,7 @@ const vsysChecksum = (source: Uint8Array): boolean => { const newChecksum = keccak_256( blake2b(source.slice(0, -4), { dkLen: 32 }) ).slice(0, 4); - if (!equals(checksum, newChecksum)) return false; + if (!equalBytes(checksum, newChecksum)) return false; return true; }; diff --git a/src/coin/xlm.ts b/src/coin/xlm.ts index 166cdfdb..5782549f 100644 --- a/src/coin/xlm.ts +++ b/src/coin/xlm.ts @@ -1,5 +1,5 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { concatBytes } from "@noble/hashes/utils"; -import { equals } from "uint8arrays"; import type { Coin } from "../types.js"; import { base32Decode, base32Encode } from "../utils/base32.js"; import { hexWithoutPrefixToBytes } from "../utils/bytes.js"; @@ -48,7 +48,7 @@ export const decodeXlmAddress = (source: string): Uint8Array => { throw new Error("Unrecognised address format"); const newChecksum = xlmChecksum(payload); - if (!equals(checksum, newChecksum)) + if (!equalBytes(checksum, newChecksum)) throw new Error("Unrecognised address format"); return output; diff --git a/src/coin/zen.ts b/src/coin/zen.ts index 1d70fffc..180aed95 100644 --- a/src/coin/zen.ts +++ b/src/coin/zen.ts @@ -1,4 +1,4 @@ -import { equals } from "uint8arrays/equals"; +import { equalBytes } from "@noble/curves/abstract/utils"; import type { Coin } from "../types.js"; import { base58Decode, base58Encode } from "../utils/base58.js"; @@ -15,7 +15,7 @@ const validPrefixes = [ export const encodeZenAddress = (source: Uint8Array): string => { const prefix = source.slice(0, 2); - if (!validPrefixes.some((x) => equals(x, prefix))) + if (!validPrefixes.some((x) => equalBytes(x, prefix))) throw new Error("Invalid prefix"); return base58Encode(source); @@ -24,7 +24,7 @@ export const decodeZenAddress = (source: string): Uint8Array => { const decoded = base58Decode(source); const prefix = decoded.slice(0, 2); - if (!validPrefixes.some((x) => equals(x, prefix))) + if (!validPrefixes.some((x) => equalBytes(x, prefix))) throw new Error("Invalid prefix"); return decoded; diff --git a/src/utils/dot.ts b/src/utils/dot.ts index 96056111..07b21747 100644 --- a/src/utils/dot.ts +++ b/src/utils/dot.ts @@ -1,6 +1,6 @@ +import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { concatBytes } from "@noble/hashes/utils"; -import { equals } from "uint8arrays"; import { base58DecodeNoCheck, base58EncodeNoCheck } from "./base58.js"; const prefixStringBytes = new Uint8Array([ @@ -27,7 +27,7 @@ export const createDotAddressDecoder = const checksum = decoded.slice(33, 35); const newChecksum = dotChecksum(decoded.slice(0, 33)); - if (!equals(checksum, newChecksum)) + if (!equalBytes(checksum, newChecksum)) throw new Error("Unrecognized address format"); return decoded.slice(1, 33);