Skip to content

Commit

Permalink
support all addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarkhatov authored and jrwbabylonlab committed Dec 13, 2024
1 parent 7856d71 commit 681745c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
13 changes: 1 addition & 12 deletions src/app/context/wallet/BTCWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {

import { useError } from "@/app/context/Error/ErrorContext";
import { ErrorState } from "@/app/types/errors";
import {
getPublicKeyNoCoord,
isSupportedAddressType,
toNetwork,
} from "@/utils/wallet";
import { getPublicKeyNoCoord, toNetwork } from "@/utils/wallet";
import {
Fees,
InscriptionIdentifier,
Expand Down Expand Up @@ -96,15 +92,8 @@ export const BTCWalletProvider = ({ children }: PropsWithChildren) => {
async (walletProvider: IBTCProvider | null) => {
if (!walletProvider) return;

const supportedNetworkMessage =
"Only Native SegWit and Taproot addresses are supported. Please switch the address type in your wallet and try again.";

try {
const address = await walletProvider.getAddress();
const supported = isSupportedAddressType(address);
if (!supported) {
throw new Error(supportedNetworkMessage);
}

const publicKeyNoCoord = getPublicKeyNoCoord(
await walletProvider.getPublicKeyHex(),
Expand Down
21 changes: 0 additions & 21 deletions src/config/network.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,3 @@ export function getNetworkConfig(): NetworkConfig {
return config.signet;
}
}

export function validateAddress(network: Network, address: string): void {
if (network === Network.MAINNET && !address.startsWith("bc1")) {
throw new Error(
"Incorrect address prefix for Mainnet. Expected address to start with 'bc1'.",
);
} else if (
[Network.SIGNET, Network.TESTNET].includes(network) &&
!address.startsWith("tb1")
) {
throw new Error(
"Incorrect address prefix for Testnet / Signet. Expected address to start with 'tb1'.",
);
} else if (
![Network.MAINNET, Network.SIGNET, Network.TESTNET].includes(network)
) {
throw new Error(
`Unsupported network: ${network}. Please provide a valid network.`,
);
}
}
8 changes: 0 additions & 8 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { networks } from "bitcoinjs-lib";

import { Network, UTXO } from "./btc_wallet_provider";

const nativeSegwitAddressLength = 42;
const taprootAddressLength = 62;
export const LOW_VALUE_UTXO_THRESHOLD = 10000;

Expand All @@ -18,13 +17,6 @@ export const toNetwork = (network: Network): networks.Network => {
}
};

export const isSupportedAddressType = (address: string): boolean => {
return (
address.length === nativeSegwitAddressLength ||
address.length === taprootAddressLength
);
};

export const isTaproot = (address: string): boolean => {
return address.length === taprootAddressLength;
};
Expand Down
23 changes: 1 addition & 22 deletions tests/utils/wallet/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { networks } from "bitcoinjs-lib";

import {
getPublicKeyNoCoord,
isSupportedAddressType,
isTaproot,
toNetwork,
} from "@/utils/wallet";
import { getPublicKeyNoCoord, isTaproot, toNetwork } from "@/utils/wallet";
import { Network } from "@/utils/wallet/btc_wallet_provider";

import { testingNetworks } from "../../helper";
Expand Down Expand Up @@ -36,22 +31,6 @@ describe("toNetwork", () => {
});
});

describe("isSupportedAddressType", () => {
it("should return true for native SegWit address length", () => {
expect(isSupportedAddressType(nativeSegWitAddress)).toBe(true);
});

it("should return true for Taproot address length", () => {
expect(isSupportedAddressType(taprootAddress)).toBe(true);
});

it("should return false for unsupported address length", () => {
expect(isSupportedAddressType(legacyAddress)).toBe(false);
expect(isSupportedAddressType(nestedSegWitAddress)).toBe(false);
expect(isSupportedAddressType("a".repeat(40))).toBe(false);
});
});

describe("isTaproot", () => {
it("should return true for Taproot address length", () => {
expect(isTaproot(taprootAddress)).toBe(true);
Expand Down

0 comments on commit 681745c

Please sign in to comment.