Skip to content

Commit

Permalink
feature(signet): add signet support (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedoublejay authored Nov 22, 2024
1 parent 7157a54 commit e2f4f72
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions apps/docs/docs/api/browser-wallets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function connectToWallet() {
throw new Error("Wallet is not installed");
}

const addresses = await getAddresses("mainnet"); // mainnet or testnet
const addresses = await getAddresses("mainnet"); // mainnet, testnet or signet
console.log(addresses);
// Example output of addresses:
//
Expand Down Expand Up @@ -139,7 +139,7 @@ Gets a list of addresses for the browser wallet if authorized.

**Parameters**:

- `network` : `"mainnet" | "testnet"` (defaults to `mainnet`) - Network
- `network` : `"mainnet" | "testnet" | "signet"` (defaults to `mainnet`) - Network
- `chain` : `"bitcoin" | "fractal-bitcoin"` (defaults to `bitcoin`) - Chain
- `options` : `object` (optional)
- `readOnly` : `boolean` (defaults to `false`) - Read only. When set to `true`, the wallet modal appears for Unisat.
Expand Down Expand Up @@ -177,7 +177,7 @@ Signs a Partially Signed Bitcoin Transaction (PSBT) and returns a signature.
- `options` : `object` (optional)
- `extractTx` : Extract transaction (defaults to `true`)
- `finalize` : Finalize signing (defaults to `true`)
- `network` (for Xverse only) : `"mainnet" | "testnet"` (defaults to `mainnet`)
- `network` (for Xverse only) : `"mainnet" | "testnet" | "signet"` (defaults to `mainnet`)
- `inputsToSign` (for Xverse only) : List of inputs and signing indexes to sign

Note: Extracting a transaction is only possible when all transactions on the PSBT are finalized. Hence, when `extractTx` is `true`, `finalize` must also be `true` and all other inputs must have been finalized.
Expand Down Expand Up @@ -227,7 +227,7 @@ Signs a message and returns a signature.

- `message` : `string`
- `address` (for Xverse only) : `string` - Wallet address to sign message
- `network` (for Xverse only) : `"mainnet" | "testnet"` (defaults to `mainnet`) - Network
- `network` (for Xverse only) : `"mainnet" | "testnet" | "signet"` (defaults to `mainnet`) - Network
- `type` (for Unisat only) : `"bip322-simple" | "ecdsa"` (defaults to `ecdsa`)

**Returns**: `Promise<BrowserWalletSignResponse>`
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/api/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This class creates a PSBTBuilder object and encapsulates a `Psbt`.
- `feeRate` : `number` - Fee rate in sats per byte
- `address` : `string` - Address of sender of transaction
- `outputs` : `Output[]` - Recipients of transaction
- `network` : `'mainnet' | 'testnet' | 'regtest'` (optional) (defaults to `mainnet`)
- `network` : `'mainnet' | 'testnet' | 'signet' | 'regtest'` (optional) (defaults to `mainnet`)

**Returns**: `PSBTBuilder`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { BitcoinNetworkType } from "sats-connect";
import type { BrowserWalletNetwork } from "../../../config/types";

export const NETWORK_TO_BITCOIN_NETWORK_TYPE: Record<
Extract<BrowserWalletNetwork, "mainnet" | "testnet">,
Extract<BrowserWalletNetwork, "mainnet" | "testnet" | "signet">,
BitcoinNetworkType
> = {
mainnet: BitcoinNetworkType.Mainnet,
testnet: BitcoinNetworkType.Testnet,
signet: BitcoinNetworkType.Signet,
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function satsConnectWalletSignPsbt(
*
* @param message Message to be signed
* @param address Address to sign with
* @param network Network (mainnet or testnet)
* @param network Network (mainnet, testnet, signet)
* @returns An object containing `base64` and `hex`.
* @throws {BrowserWalletNotInstalledError} Wallet is not installed
* @throws {BrowserWalletSigningError} Failed to sign with selected wallet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserWalletNetwork } from "../../../config/types";
import { InputsToSign } from "../../../inscription/types";

export type SatsConnectNetwork = "Mainnet" | "Testnet";
export type SatsConnectNetwork = "Mainnet" | "Testnet" | "Signet";

export type SatsConnectSignPSBTOptions = {
finalize?: boolean;
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/browser-wallets/unisat/constants.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import type { BrowserWalletNetwork, Chain } from "../../config/types";

export const NETWORK_TO_UNISAT_NETWORK: Record<
Extract<BrowserWalletNetwork, "mainnet" | "testnet">,
Extract<BrowserWalletNetwork, "mainnet" | "testnet" | "signet">,
UnisatNetwork
> = {
mainnet: "livenet",
testnet: "testnet",
signet: "testnet",
} as const;

export const CHAIN_TO_UNISAT_CHAIN: Record<
Chain,
Record<Extract<BrowserWalletNetwork, "mainnet" | "testnet">, UnisatChainType>
Record<
Extract<BrowserWalletNetwork, "mainnet" | "testnet" | "signet">,
UnisatChainType
>
> = {
bitcoin: {
mainnet: "BITCOIN_MAINNET",
testnet: "BITCOIN_TESTNET",
signet: "BITCOIN_SIGNET",
},
"fractal-bitcoin": {
mainnet: "FRACTAL_BITCOIN_MAINNET",
testnet: "FRACTAL_BITCOIN_TESTNET",
signet: "FRACTAL_BITCOIN_TESTNET",
},
};
1 change: 1 addition & 0 deletions packages/sdk/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type MessageSignatureTypes = "bip322-simple" | "ecdsa";
type UnisatChainType =
| "BITCOIN_MAINNET"
| "BITCOIN_TESTNET"
| "BITCOIN_SIGNET"
| "FRACTAL_BITCOIN_MAINNET"
| "FRACTAL_BITCOIN_TESTNET";

Expand Down

0 comments on commit e2f4f72

Please sign in to comment.