Skip to content

Commit 1f69854

Browse files
committed
remove uint8arrays
1 parent b5e9025 commit 1f69854

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

bun.lockb

-726 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"@noble/curves": "^1.2.0",
8282
"@noble/hashes": "^1.3.2",
8383
"@scure/base": "^1.1.3",
84-
"bech32": "^2.0.0",
85-
"uint8arrays": "^4.0.6"
84+
"bech32": "^2.0.0"
8685
}
8786
}

src/coin/bcn.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { keccak_256 } from "@noble/hashes/sha3";
23
import { concatBytes } from "@noble/hashes/utils";
34
import { utils } from "@scure/base";
4-
import { equals } from "uint8arrays";
55
import type { Coin } from "../types.js";
66
import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js";
77

@@ -21,8 +21,8 @@ export const decodeBcnAddress = (source: string): Uint8Array => {
2121

2222
if (
2323
decoded.length < 68 ||
24-
(!equals(tag, new Uint8Array([0x06])) &&
25-
!equals(tag, new Uint8Array([0xce, 0xf6, 0x22])))
24+
(!equalBytes(tag, new Uint8Array([0x06])) &&
25+
!equalBytes(tag, new Uint8Array([0xce, 0xf6, 0x22])))
2626
)
2727
throw new Error("Unrecognised address format");
2828

src/coin/fil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { blake2b } from "@noble/hashes/blake2b";
23
import { concatBytes } from "@noble/hashes/utils";
3-
import { equals } from "uint8arrays";
44
import type { Coin } from "../types.js";
55
import {
66
base32Decode,
@@ -65,7 +65,7 @@ export const decodeFilAddress = (source: string): Uint8Array => {
6565
const decoded = concatBytes(protocolByte, payload);
6666

6767
const newChecksum = filChecksum(decoded);
68-
if (!equals(checksum, newChecksum))
68+
if (!equalBytes(checksum, newChecksum))
6969
throw new Error("Unrecognised address format");
7070

7171
return decoded;

src/coin/sc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { blake2b } from "@noble/hashes/blake2b";
23
import { concatBytes } from "@noble/hashes/utils";
3-
import { equals } from "uint8arrays";
44
import type { Coin } from "../types.js";
55
import {
66
bytesToHexWithoutPrefix,
@@ -28,7 +28,7 @@ export const decodeScAddress = (source: string): Uint8Array => {
2828
const checksum = decoded.slice(-checksumLength);
2929
const newChecksum = scChecksum(payload);
3030

31-
if (!equals(checksum, newChecksum))
31+
if (!equalBytes(checksum, newChecksum))
3232
throw new Error("Unrecognised address format");
3333

3434
return payload;

src/coin/stx.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { sha256 } from "@noble/hashes/sha256";
23
import { concatBytes } from "@noble/hashes/utils";
3-
import { equals } from "uint8arrays";
44
import type { Coin } from "../types.js";
55
import {
66
base32Decode,
@@ -29,10 +29,12 @@ export const encodeStxAddress = (source: Uint8Array): string => {
2929
let version: string;
3030
let encoded: string;
3131

32-
if (equals(checksum, stxChecksum(concatBytes(p2pkhVersion, hash160)))) {
32+
if (equalBytes(checksum, stxChecksum(concatBytes(p2pkhVersion, hash160)))) {
3333
version = "P";
3434
encoded = base32Encode(source, crockfordBase32Options);
35-
} else if (equals(checksum, stxChecksum(concatBytes(p2shVersion, hash160)))) {
35+
} else if (
36+
equalBytes(checksum, stxChecksum(concatBytes(p2shVersion, hash160)))
37+
) {
3638
version = "M";
3739
encoded = base32Encode(source, crockfordBase32Options);
3840
} else throw new Error("Unrecognised address format");
@@ -56,7 +58,7 @@ export const decodeStxAddress = (source: string): Uint8Array => {
5658
const checksum = payload.slice(-checkumLength);
5759
const newChecksum = stxChecksum(concatBytes(versionBytes, decoded));
5860

59-
if (!equals(checksum, newChecksum))
61+
if (!equalBytes(checksum, newChecksum))
6062
throw new Error("Unrecognised address format");
6163

6264
return payload;

src/coin/vsys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { blake2b } from "@noble/hashes/blake2b";
23
import { keccak_256 } from "@noble/hashes/sha3";
3-
import { equals } from "uint8arrays";
44
import type { Coin } from "../types.js";
55
import { base58DecodeNoCheck, base58EncodeNoCheck } from "../utils/base58.js";
66

@@ -15,7 +15,7 @@ const vsysChecksum = (source: Uint8Array): boolean => {
1515
const newChecksum = keccak_256(
1616
blake2b(source.slice(0, -4), { dkLen: 32 })
1717
).slice(0, 4);
18-
if (!equals(checksum, newChecksum)) return false;
18+
if (!equalBytes(checksum, newChecksum)) return false;
1919
return true;
2020
};
2121

src/coin/xlm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { concatBytes } from "@noble/hashes/utils";
2-
import { equals } from "uint8arrays";
33
import type { Coin } from "../types.js";
44
import { base32Decode, base32Encode } from "../utils/base32.js";
55
import { hexWithoutPrefixToBytes } from "../utils/bytes.js";
@@ -48,7 +48,7 @@ export const decodeXlmAddress = (source: string): Uint8Array => {
4848
throw new Error("Unrecognised address format");
4949

5050
const newChecksum = xlmChecksum(payload);
51-
if (!equals(checksum, newChecksum))
51+
if (!equalBytes(checksum, newChecksum))
5252
throw new Error("Unrecognised address format");
5353

5454
return output;

src/coin/zen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { equals } from "uint8arrays/equals";
1+
import { equalBytes } from "@noble/curves/abstract/utils";
22
import type { Coin } from "../types.js";
33
import { base58Decode, base58Encode } from "../utils/base58.js";
44

@@ -15,7 +15,7 @@ const validPrefixes = [
1515

1616
export const encodeZenAddress = (source: Uint8Array): string => {
1717
const prefix = source.slice(0, 2);
18-
if (!validPrefixes.some((x) => equals(x, prefix)))
18+
if (!validPrefixes.some((x) => equalBytes(x, prefix)))
1919
throw new Error("Invalid prefix");
2020

2121
return base58Encode(source);
@@ -24,7 +24,7 @@ export const decodeZenAddress = (source: string): Uint8Array => {
2424
const decoded = base58Decode(source);
2525
const prefix = decoded.slice(0, 2);
2626

27-
if (!validPrefixes.some((x) => equals(x, prefix)))
27+
if (!validPrefixes.some((x) => equalBytes(x, prefix)))
2828
throw new Error("Invalid prefix");
2929

3030
return decoded;

src/utils/dot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { equalBytes } from "@noble/curves/abstract/utils";
12
import { blake2b } from "@noble/hashes/blake2b";
23
import { concatBytes } from "@noble/hashes/utils";
3-
import { equals } from "uint8arrays";
44
import { base58DecodeNoCheck, base58EncodeNoCheck } from "./base58.js";
55

66
const prefixStringBytes = new Uint8Array([
@@ -27,7 +27,7 @@ export const createDotAddressDecoder =
2727

2828
const checksum = decoded.slice(33, 35);
2929
const newChecksum = dotChecksum(decoded.slice(0, 33));
30-
if (!equals(checksum, newChecksum))
30+
if (!equalBytes(checksum, newChecksum))
3131
throw new Error("Unrecognized address format");
3232

3333
return decoded.slice(1, 33);

0 commit comments

Comments
 (0)