Skip to content

Commit

Permalink
remove uint8arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Sep 27, 2023
1 parent b5e9025 commit 1f69854
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 22 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions src/coin/bcn.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions src/coin/fil.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/coin/sc.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/coin/stx.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/coin/vsys.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/coin/xlm.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/coin/zen.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/dot.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand All @@ -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);
Expand Down

0 comments on commit 1f69854

Please sign in to comment.