diff --git a/packages/sdk/src/browser-wallets/internal/sats-connect/index.ts b/packages/sdk/src/browser-wallets/internal/sats-connect/index.ts index 99e227a2..5b5ad86c 100644 --- a/packages/sdk/src/browser-wallets/internal/sats-connect/index.ts +++ b/packages/sdk/src/browser-wallets/internal/sats-connect/index.ts @@ -45,10 +45,6 @@ async function satsConnectWalletGetAddresses( getProvider: () => Promise, network: BrowserWalletNetwork = "mainnet", ): Promise { - if (network === "signet") { - throw new OrditSDKError("signet network is not supported"); - } - const result: WalletAddress[] = []; const handleOnFinish = (response: GetAddressResponse) => { @@ -120,9 +116,6 @@ async function satsConnectWalletSignPsbt( inputsToSign, }: SatsConnectSignPSBTOptions = { network: "mainnet", inputsToSign: [] }, ): Promise { - if (network === "signet") { - throw new OrditSDKError("signet network is not supported"); - } if (!finalize && extractTx) { throw new BrowserWalletExtractTxFromNonFinalizedPsbtError(); } @@ -220,9 +213,6 @@ async function satsConnectWalletSignMessage( address: string, network: BrowserWalletNetwork = "mainnet", ): Promise { - if (network === "signet") { - throw new OrditSDKError("signet network is not supported"); - } if (!message || !network || !address) { throw new OrditSDKError("Invalid options provided"); } diff --git a/packages/sdk/src/browser-wallets/unisat/__tests__/index.spec.ts b/packages/sdk/src/browser-wallets/unisat/__tests__/index.spec.ts index 8093a965..f2a388af 100644 --- a/packages/sdk/src/browser-wallets/unisat/__tests__/index.spec.ts +++ b/packages/sdk/src/browser-wallets/unisat/__tests__/index.spec.ts @@ -76,10 +76,24 @@ describe("Unisat Wallet", () => { expect(getAddresses("testnet")).resolves.toEqual([mockData]); }); - test("should return error from signet", () => { - expect(getAddresses("signet")).rejects.toThrowError( - "signet network is not supported", - ); + test("should return address from signet", () => { + const mockData: WalletAddress = { + publicKey: + "02e522672eb584da7a5b5d61db1601584e7937471416388e4f43d69c720d62fe0f", + address: + "tb1p8mkym678ltgdyda5lkd0vqtqyps5mlthkpee6q43hhqmevjxzzyqrc4pfg", + format: "taproot", + }; + const network = "signet"; + + vi.stubGlobal("unisat", { + getNetwork: vi + .fn() + .mockResolvedValue(NETWORK_TO_UNISAT_NETWORK[network]), + requestAccounts: vi.fn().mockResolvedValue([mockData.address]), + getPublicKey: vi.fn().mockResolvedValue(mockData.publicKey), + }); + expect(getAddresses("signet")).resolves.toEqual([mockData]); }); test("should return address from fractal bitcoin mainnet", () => { diff --git a/packages/sdk/src/browser-wallets/unisat/index.ts b/packages/sdk/src/browser-wallets/unisat/index.ts index 53adbb5f..8303f084 100644 --- a/packages/sdk/src/browser-wallets/unisat/index.ts +++ b/packages/sdk/src/browser-wallets/unisat/index.ts @@ -45,10 +45,6 @@ async function getAddresses( options: UnisatGetAddressesOptions = {}, ): Promise { const { readOnly = false } = options; - - if (network === "signet") { - throw new OrditSDKError("signet network is not supported"); - } if (!isInstalled()) { throw new BrowserWalletNotInstalledError("Unisat not installed"); } diff --git a/packages/sdk/src/browser-wallets/xverse/__tests__/index.spec.ts b/packages/sdk/src/browser-wallets/xverse/__tests__/index.spec.ts index 7411d39b..06aeea90 100644 --- a/packages/sdk/src/browser-wallets/xverse/__tests__/index.spec.ts +++ b/packages/sdk/src/browser-wallets/xverse/__tests__/index.spec.ts @@ -159,15 +159,57 @@ describe("Xverse Wallet", () => { expect(getAddresses("testnet")).resolves.toEqual(mockData); }); - test("should throw error on signet", () => { + test("should return address from signet", () => { + const mockData: WalletAddress[] = [ + { + address: + "tb1pygh40yljmeknedr3cgwgyyjnh20g6zghqkzufz5z7d5njjsgx8ts8x4kzs", + publicKey: + "02b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717", + format: "taproot", + }, + { + // https://allprivatekeys.com/bitcoin-address-format + address: "2MwFLsoQMCRKaXkwT7j2PZ4pdZfhH9jXhQz", + publicKey: + "028a045950a789ff01350b95cd17544c5574f8b023aedce30ba6d0893ec119092f", + format: "p2sh-p2wpkh", + }, + ]; + const mockResponse: GetAddressResponse = { + addresses: [ + { + address: + "tb1pygh40yljmeknedr3cgwgyyjnh20g6zghqkzufz5z7d5njjsgx8ts8x4kzs", + publicKey: + "02b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717", + purpose: satsConnect.AddressPurpose.Ordinals, + addressType: satsConnect.AddressType.p2tr, + }, + { + address: "2MwFLsoQMCRKaXkwT7j2PZ4pdZfhH9jXhQz", + publicKey: + "028a045950a789ff01350b95cd17544c5574f8b023aedce30ba6d0893ec119092f", + purpose: satsConnect.AddressPurpose.Payment, + addressType: satsConnect.AddressType.p2wpkh, + }, + ], + }; + vi.stubGlobal("window", { XverseProviders: { BitcoinProvider: {}, }, }); - expect(getAddresses("signet")).rejects.toThrowError( - "signet network is not supported", - ); + + const getAddressSpy = vi.spyOn(satsConnect, "getAddress"); + + getAddressSpy.mockImplementation((options: GetAddressOptions) => { + options.onFinish(mockResponse); + return Promise.resolve(); + }); + expect(typeof window).not.toBeUndefined(); + expect(getAddresses("signet")).resolves.toEqual(mockData); }); test("should throw error on user cancel", () => {