@bestinslot/wallet-kit 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +108 -0
  2. package/dist/balances-BQiaAIaq.js +9627 -0
  3. package/dist/browser.js +205 -0
  4. package/dist/core.js +39 -0
  5. package/dist/mint-BXVHw4CQ.js +70722 -0
  6. package/dist/node.js +1787 -0
  7. package/dist/react.js +14 -0
  8. package/dist/register-browser-providers-CLLT6W6P.js +499 -0
  9. package/dist/types/adapters/react/use-network.d.ts +8 -0
  10. package/dist/types/adapters/react/use-wallet.d.ts +15 -0
  11. package/dist/types/adapters/vue/use-network.d.ts +12 -0
  12. package/dist/types/api/balances.d.ts +52 -0
  13. package/dist/types/api/brc20.d.ts +110 -0
  14. package/dist/types/api/helpers.d.ts +3 -0
  15. package/dist/types/api/mint.d.ts +57 -0
  16. package/dist/types/api/modal.d.ts +3 -0
  17. package/dist/types/api/swap.d.ts +122 -0
  18. package/dist/types/api/wallet.browser.d.ts +2 -0
  19. package/dist/types/api/wallet.d.ts +6 -0
  20. package/dist/types/api/wallet.node.d.ts +4 -0
  21. package/dist/types/browser.d.ts +10 -0
  22. package/dist/types/components/Dev.vue.d.ts +11 -0
  23. package/dist/types/components/connect-modal-view.d.ts +28 -0
  24. package/dist/types/components/dev/BRC20.vue.d.ts +2 -0
  25. package/dist/types/components/dev/Button.vue.d.ts +17 -0
  26. package/dist/types/components/dev/Input.vue.d.ts +12 -0
  27. package/dist/types/components/dev/Label.vue.d.ts +17 -0
  28. package/dist/types/components/dev/Select.vue.d.ts +17 -0
  29. package/dist/types/components/dev/SessionInfo.vue.d.ts +6 -0
  30. package/dist/types/core/bis.d.ts +21 -0
  31. package/dist/types/core/bis_swap.d.ts +622 -0
  32. package/dist/types/core/brc20.d.ts +229 -0
  33. package/dist/types/core/connect-modal.d.ts +15 -0
  34. package/dist/types/core/helpers.d.ts +212 -0
  35. package/dist/types/core/mint.d.ts +364 -0
  36. package/dist/types/core/modal.d.ts +21 -0
  37. package/dist/types/core/providers.d.ts +90 -0
  38. package/dist/types/core/register-browser-providers.d.ts +1 -0
  39. package/dist/types/core/register-local-provider.d.ts +1 -0
  40. package/dist/types/core/storage.d.ts +19 -0
  41. package/dist/types/core/store-network.d.ts +20 -0
  42. package/dist/types/core/store.d.ts +39 -0
  43. package/dist/types/core.d.ts +10 -0
  44. package/dist/types/lib/bitcoin.d.ts +8 -0
  45. package/dist/types/lib/dev-worker.d.ts +1 -0
  46. package/dist/types/lib/dev.d.ts +9 -0
  47. package/dist/types/lib/swap-constants.d.ts +7 -0
  48. package/dist/types/lib/swap-reporting.d.ts +80 -0
  49. package/dist/types/lib/uniswap_ops.d.ts +238 -0
  50. package/dist/types/lib/web3.d.ts +7 -0
  51. package/dist/types/node.d.ts +9 -0
  52. package/dist/types/provider/api.d.ts +97 -0
  53. package/dist/types/provider/leather.d.ts +2 -0
  54. package/dist/types/provider/local.d.ts +39 -0
  55. package/dist/types/provider/okx.d.ts +2 -0
  56. package/dist/types/provider/unisat.d.ts +2 -0
  57. package/dist/types/provider/xverse.d.ts +2 -0
  58. package/dist/types/react.d.ts +3 -0
  59. package/dist/types/types/common.d.ts +33 -0
  60. package/dist/types/types/global.d.ts +26 -0
  61. package/dist/types/types/inscription.d.ts +147 -0
  62. package/dist/types/types/vite-env.d.ts +7 -0
  63. package/dist/types/types/wallet.d.ts +50 -0
  64. package/dist/types/vue.d.ts +2 -0
  65. package/dist/vue.js +13 -0
  66. package/package.json +133 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Classifies a swap as a buy or sell relative to WBTC (the quote asset): you
3
+ * "buy" the other token when you spend WBTC, and "sell" it when you receive WBTC.
4
+ *
5
+ * For a swap activity entry (`type` 'swap1' | 'swap2'), `token_1` is the input
6
+ * and `token_2` the output, so `swapSide(entry.token_1, entry.token_2, wbtc)`
7
+ * gives its side. (Don't apply it to liquidity entries, where token_1/token_2 are
8
+ * the pair's two tokens, not a direction.)
9
+ *
10
+ * @param tokenInAddress The input token address (what's spent).
11
+ * @param tokenOutAddress The output token address (what's received).
12
+ * @param wbtcAddress The WBTC token address.
13
+ * @returns 'buy' or 'sell', or null for a non-WBTC (token-to-token) swap.
14
+ */
15
+ export declare function swapSide(tokenInAddress: string, tokenOutAddress: string, wbtcAddress: string): 'buy' | 'sell' | null;
16
+ /**
17
+ * Converts a sat amount to BTC. Throws on values beyond JS safe-integer
18
+ * precision (~90,000 BTC) rather than silently rounding.
19
+ *
20
+ * @param sats The amount in satoshis.
21
+ * @returns The amount in BTC.
22
+ */
23
+ export declare function satsToBtc(sats: bigint): number;
24
+ /**
25
+ * Converts a sat amount to USD using a caller-supplied BTC/USD rate, keeping the
26
+ * library oracle-free.
27
+ *
28
+ * @param sats The amount in satoshis.
29
+ * @param btcUsd The BTC→USD price.
30
+ * @returns The amount in USD.
31
+ */
32
+ export declare function satsToUsd(sats: bigint, btcUsd: number): number;
33
+ /**
34
+ * The fees a swap quote costs, broken out so a UI can show the real total instead
35
+ * of guessing at it. Only the pool fee is baked into the quoted amounts; the rest
36
+ * is charged on top of them — see each field, and the swap guide for a worked
37
+ * example of totalling them up.
38
+ */
39
+ export interface SwapFees {
40
+ /**
41
+ * The constant-product pool fee, in bps. This one is already reflected in the
42
+ * quote: it is taken on the way through the pool, so the quoted amount is net
43
+ * of it and it must not be subtracted again.
44
+ */
45
+ pool_fee_bps: bigint;
46
+ /** The protocol fee charged on the input leg, in bps. */
47
+ token_in_fee_bps: bigint;
48
+ /**
49
+ * `token_in_fee_bps` applied to the input amount, in input-token units. Debited
50
+ * on top of the input, so the swap really costs `amount_in + token_in_fee`.
51
+ */
52
+ token_in_fee: bigint;
53
+ /** The protocol fee charged on the output leg, in bps. */
54
+ token_out_fee_bps: bigint;
55
+ /**
56
+ * `token_out_fee_bps` applied to the output amount, in output-token units.
57
+ * Deducted from the output, so you really receive `amount_out - token_out_fee`.
58
+ */
59
+ token_out_fee: bigint;
60
+ /**
61
+ * The miner fee, in WBTC sats. A flat amount rather than a rate — don't fold it
62
+ * into a bps figure. Debited in WBTC separately from both legs.
63
+ */
64
+ miner_fee_sats: bigint;
65
+ }
66
+ /**
67
+ * Assembles the fee breakdown for a swap quote from the inputs the quote path
68
+ * already has. The bps → amount arithmetic mirrors `swapRequest`/`swap2Request`
69
+ * exactly, floor division included, so the reported amounts are the ones that
70
+ * will actually be debited rather than a rounded-off approximation.
71
+ *
72
+ * @param amountIn The input leg amount, whether quoted or requested.
73
+ * @param amountOut The output leg amount, whether quoted or requested.
74
+ * @param token1FeeBps The protocol fee on the input leg, in bps.
75
+ * @param token2FeeBps The protocol fee on the output leg, in bps.
76
+ * @param btcFee The miner fee in WBTC sats.
77
+ *
78
+ * @returns The fee breakdown for the quote.
79
+ */
80
+ export declare function buildSwapFees(amountIn: bigint, amountOut: bigint, token1FeeBps: bigint, token2FeeBps: bigint, btcFee: bigint): SwapFees;
@@ -0,0 +1,238 @@
1
+ export interface UniswapInfoProxy {
2
+ balanceOf: (pubkey: string, token_address: string) => Promise<bigint | null>;
3
+ reservesOf: (pair_address: string) => Promise<{
4
+ reserveA: bigint;
5
+ reserveB: bigint;
6
+ total_supply: bigint;
7
+ } | null>;
8
+ }
9
+ /**
10
+ * Saves the Bis Swap information, including the WBTC address and factory address. The saveInfo function takes two string parameters, wbtcAddr and factory, which represent the WBTC token address and the Bis Swap factory address, respectively. It assigns these values to the module-level variables wbtcAddress and factoryAddr, allowing other functions in the module to access this information when needed for operations such as calculating pair addresses or fetching reserves. This function is essential for initializing the Bis Swap-related operations with the correct contract addresses.
11
+ *
12
+ * @param wbtcAddr The WBTC token address as a string. This address is used in Bis Swap operations to identify the WBTC token when calculating pair addresses, fetching reserves, or performing swaps involving WBTC.
13
+ * @param factory The Bis Swap factory address as a string. This address is used to calculate pair addresses and to interact with the Bis Swap protocol for operations such as fetching reserves or performing swaps. By saving this information, the module can ensure that all Bis Swap-related functions have access to the necessary contract addresses for their operations.
14
+ */
15
+ export declare function saveInfo(wbtcAddr: string, factory: string): void;
16
+ /**
17
+ * Calculates the pair address for two given token addresses using the Uniswap V2 formula. The calculatePairAddress function takes two token addresses as input and computes the corresponding pair address based on the Uniswap V2 deterministic address generation method. It first ensures that the token addresses are ordered correctly (the lower address is tokenA and the higher address is tokenB) to maintain consistency. Then, it uses the factory address, the keccak256 hash of the packed token addresses, and a fixed init code hash to compute the final pair address. This function is essential for interacting with the Uniswap protocol, as it allows you to determine the correct pair address for any two tokens, which is necessary for fetching reserves, performing swaps, or adding liquidity.
18
+ *
19
+ * @param tokenAAddr The address of the first token as a string. This should be a valid Ethereum address in hexadecimal format. The function will ensure that this address is ordered correctly with respect to the second token address to maintain consistency in pair address generation.
20
+ * @param tokenBAddr The address of the second token as a string. This should also be a valid Ethereum address in hexadecimal format. The function will compare this address with the first token address to determine the correct ordering for pair address generation, ensuring that the lower address is always tokenA and the higher address is tokenB.
21
+ *
22
+ * @returns The calculated pair address as a string in hexadecimal format. This address is derived using the Uniswap V2 formula, which involves hashing the factory address, the ordered token addresses, and a fixed init code hash. The resulting pair address can be used to interact with the Uniswap protocol for operations such as fetching reserves, performing swaps, or adding liquidity for the given token pair.
23
+ */
24
+ export declare function calculatePairAddress(tokenAAddr: string, tokenBAddr: string): string;
25
+ /**
26
+ * Handles the add liquidity request for a Uniswap-like decentralized exchange. The addLiquidityRequest function takes various parameters including the user's public key, token addresses, amounts, minimum amounts, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it calculates the actual amounts of tokens to be added to the liquidity pool based on the desired amounts and the current reserves. If the signature is valid and the amounts are sufficient, it updates the internal state of balances and reserves accordingly. Finally, it returns a success response with the actual amounts added and liquidity tokens minted, or an error message if any step fails.
27
+ *
28
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
29
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the add liquidity request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully adding liquidity.
30
+ * @param token1Addr The address of the first token in the liquidity pair as a hexadecimal string. This address is used to identify the token being added to the liquidity pool and to fetch its current balance and reserves. The function will also use this address to calculate the pair address and to update the user's balance after adding liquidity.
31
+ * @param token2Addr The address of the second token in the liquidity pair as a hexadecimal string. Similar to token1Addr, this address is used to identify the second token being added to the liquidity pool, to fetch its current balance and reserves, and to calculate the pair address for updating the user's balance after adding liquidity.
32
+ * @param amt1 The desired amount of the first token to be added to the liquidity pool as a bigint. This amount is used in the calculation of how much of each token will actually be added based on the current reserves and the desired amounts. The function will ensure that this amount meets the minimum requirements and will update the user's balance accordingly after adding liquidity.
33
+ * @param amt2 The desired amount of the second token to be added to the liquidity pool as a bigint. Similar to amt1, this amount is used in the calculation of how much of each token will actually be added based on the current reserves and the desired amounts. The function will ensure that this amount meets the minimum requirements and will update the user's balance accordingly after adding liquidity.
34
+ * @param minamt1 The minimum acceptable amount of the first token to be added to the liquidity pool as a bigint. This parameter is used to ensure that the user receives at least this amount of the first token when adding liquidity, even if the actual amount calculated based on the desired amounts and current reserves is higher. If the calculated amount of the first token is less than this minimum, the function will throw an error and not proceed with adding liquidity.
35
+ * @param minamt2 The minimum acceptable amount of the second token to be added to the liquidity pool as a bigint. Similar to minamt1, this parameter is used to ensure that the user receives at least this amount of the second token when adding liquidity. If the calculated amount of the second token is less than this minimum, the function will throw an error and not proceed with adding liquidity.
36
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the add liquidity request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with adding liquidity, ensuring that only authorized requests are processed.
37
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each add liquidity request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
38
+ * @param token1FeeBps The fee for the first token in basis points (bps) as a bigint. This fee is applied to the amount of the first token being added to the liquidity pool and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after adding liquidity.
39
+ * @param token2FeeBps The fee for the second token in basis points (bps) as a bigint. Similar to token1FeeBps, this fee is applied to the amount of the second token being added to the liquidity pool and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after adding liquidity.
40
+ * @param btcFee The fee in BTC as a bigint that is applied to the add liquidity request. This fee is deducted from the user's balance in WBTC and is used to cover the costs associated with processing the request. The function will ensure that this fee is properly accounted for in the user's balance updates after adding liquidity.
41
+ *
42
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the actual amounts of tokens added to the liquidity pool and the amount of liquidity tokens minted. If there is an error, the object contains an error message describing the issue that occurred during the add liquidity process.
43
+ */
44
+ export declare function addLiquidityRequest(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
45
+ token1Addr: string, // hex string token1 address
46
+ token2Addr: string, // hex string token2 address
47
+ amt1: bigint, // bigint token1 amount
48
+ amt2: bigint, // bigint token2 amount
49
+ minamt1: bigint, // bigint min token1 amount
50
+ minamt2: bigint, // bigint min token2 amount
51
+ blsSignature: string, // hex string BLS signature
52
+ nonce: bigint, // unique request nonce
53
+ token1FeeBps: bigint, // bigint token1 fee in bps
54
+ token2FeeBps: bigint, // bigint token2 fee in bps
55
+ btcFee: bigint): Promise<{
56
+ success: boolean;
57
+ data?: {
58
+ amountA: bigint;
59
+ amountB: bigint;
60
+ liquidity: bigint;
61
+ };
62
+ error_message?: string;
63
+ }>;
64
+ /**
65
+ * Handles the remove liquidity request for BiS Swap. The removeLiquidityRequest function takes various parameters including the user's public key, token addresses, liquidity amount, minimum amounts, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it verifies that the user has sufficient liquidity balance to burn. If the signature is valid and the balance is sufficient, it calculates the actual amounts of tokens to be removed from the liquidity pool based on the liquidity amount and current reserves. Finally, it updates the internal state of balances and reserves accordingly and returns a success response with the actual amounts removed, or an error message if any step fails.
66
+ *
67
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
68
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the remove liquidity request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully removing liquidity.
69
+ * @param token1Addr The address of the first token in the liquidity pair as a hexadecimal string. This address is used to identify the token being removed from the liquidity pool and to fetch its current balance and reserves. The function will also use this address to calculate the pair address and to update the user's balance after removing liquidity.
70
+ * @param token2Addr The address of the second token in the liquidity pair as a hexadecimal string. Similar to token1Addr, this address is used to identify the second token being removed from the liquidity pool, to fetch its current balance and reserves, and to calculate the pair address for updating the user's balance after removing liquidity.
71
+ * @param liquidity The amount of liquidity tokens to be burned as a bigint. This amount is used in the calculation of how much of each underlying token will be removed from the liquidity pool based on the current reserves and total supply. The function will ensure that this amount meets the minimum requirements and will update the user's balance accordingly after removing liquidity.
72
+ * @param minamt1 The minimum acceptable amount of the first token to be removed from the liquidity pool as a bigint. This parameter is used to ensure that the user receives at least this amount of the first token when removing liquidity, even if the actual amount calculated based on the liquidity burned and current reserves is higher. If the calculated amount of the first token is less than this minimum, the function will throw an error and not proceed with removing liquidity.
73
+ * @param minamt2 The minimum acceptable amount of the second token to be removed from the liquidity pool as a bigint. Similar to minamt1, this parameter is used to ensure that the user receives at least this amount of the second token when removing liquidity. If the calculated amount of the second token is less than this minimum, the function will throw an error and not proceed with removing liquidity.
74
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the remove liquidity request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with removing liquidity, ensuring that only authorized requests are processed.
75
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each remove liquidity request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
76
+ * @param token1FeeBps The fee for the first token in basis points (bps) as a bigint. This fee is applied to the amount of the first token being removed from the liquidity pool and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after removing liquidity.
77
+ * @param token2FeeBps The fee for the second token in basis points (bps) as a bigint. Similar to token1FeeBps, this fee is applied to the amount of the second token being removed from the liquidity pool and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after removing liquidity.
78
+ * @param btcFee The fee in BTC as a bigint that is applied to the remove liquidity request. This fee is deducted from the user's balance in WBTC and is used to cover the costs associated with processing the request. The function will ensure that this fee is properly accounted for in the user's balance updates after removing liquidity.
79
+ *
80
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the actual amounts of tokens removed from the liquidity pool and the amount of liquidity tokens burned. If there is an error, the object contains an error message describing the issue that occurred during the remove liquidity process.
81
+ */
82
+ export declare function removeLiquidityRequest(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
83
+ token1Addr: string, // hex string token1 address
84
+ token2Addr: string, // hex string token2 address
85
+ liquidity: bigint, // bigint lp token amount
86
+ minamt1: bigint, // bigint min token1 amount
87
+ minamt2: bigint, // bigint min token2 amount
88
+ blsSignature: string, // hex string BLS signature
89
+ nonce: bigint, // unique request nonce
90
+ token1FeeBps: bigint, // bigint token1 fee in bps
91
+ token2FeeBps: bigint, // bigint token2 fee in bps
92
+ btcFee: bigint): Promise<{
93
+ success: boolean;
94
+ data: {
95
+ amountA: bigint;
96
+ amountB: bigint;
97
+ liquidity: bigint;
98
+ };
99
+ error_message?: undefined;
100
+ } | {
101
+ success: boolean;
102
+ error_message: any;
103
+ data?: undefined;
104
+ }>;
105
+ /**
106
+ * Handles the swap request for BiS Swap. The swapRequest function takes various parameters including the user's public key, token addresses, input amount, minimum output amount, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it verifies that the user has sufficient balance of the input token. If the signature is valid and the balance is sufficient, it calculates the output amount based on the current reserves and the input amount. Finally, it updates the internal state of balances and reserves accordingly and returns a success response with the output amount and price impact, or an error message if any step fails.
107
+ *
108
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
109
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the swap request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully executing the swap.
110
+ * @param token1Addr The address of the input token as a hexadecimal string. This address is used to identify the token being swapped from and to fetch its current balance and reserves. The function will also use this address to calculate the pair address and to update the user's balance after executing the swap.
111
+ * @param token2Addr The address of the output token as a hexadecimal string. Similar to token1Addr, this address is used to identify the token being swapped to, to fetch its current balance and reserves, and to calculate the pair address for updating the user's balance after executing the swap.
112
+ * @param inAmt The amount of the input token to be swapped as a bigint. This amount is used in the calculation of how much of the output token will be received based on the current reserves and the swap formula. The function will ensure that this amount meets the minimum requirements and will update the user's balance accordingly after executing the swap.
113
+ * @param minOutAmt The minimum acceptable amount of the output token to be received from the swap as a bigint. This parameter is used to ensure that the user receives at least this amount of the output token when executing the swap, even if the actual amount calculated based on the input amount and current reserves is higher. If the calculated amount of the output token is less than this minimum, the function will throw an error and not proceed with executing the swap.
114
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the swap request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with executing the swap, ensuring that only authorized requests are processed.
115
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each swap request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
116
+ * @param token1FeeBps The fee for the input token in basis points (bps) as a bigint. This fee is applied to the amount of the input token being swapped and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after executing the swap.
117
+ * @param token2FeeBps The fee for the output token in basis points (bps) as a bigint. This fee is applied to the amount of the output token being received and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after executing the swap.
118
+ * @param btcFee The miner fee as a bigint, denominated in WBTC sats. It is a flat amount, not a rate: the function debits exactly this much WBTC from the user's balance on top of the swap, so it is not reflected in the amounts returned.
119
+ *
120
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the actual amount of the output token received from the swap and the price impact of the swap. If there is an error, the object contains an error message describing the issue that occurred during the swap process.
121
+ */
122
+ export declare function swapRequest(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
123
+ token1Addr: string, // hex string token in address
124
+ token2Addr: string, // hex string token out address
125
+ inAmt: bigint, // bigint token in amount
126
+ minOutAmt: bigint, // bigint min token out amount
127
+ blsSignature: string, // hex string BLS signature
128
+ nonce: bigint, // unique request nonce
129
+ token1FeeBps: bigint, // bigint token1 fee in bps
130
+ token2FeeBps: bigint, // bigint token2 fee in bps
131
+ btcFee: bigint): Promise<{
132
+ success: boolean;
133
+ amounts: bigint[];
134
+ price_impact_bps: bigint;
135
+ error_message?: undefined;
136
+ } | {
137
+ success: boolean;
138
+ error_message: any;
139
+ amounts?: undefined;
140
+ price_impact_bps?: undefined;
141
+ }>;
142
+ /**
143
+ * Handles the swap request with specified output amount for BiS Swap. The swap2Request function takes various parameters including the user's public key, token addresses, maximum input amount, desired output amount, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it verifies that the user has sufficient balance of the input token and that the maximum input amount is sufficient to receive the desired output amount based on the current reserves. If the signature is valid and the balance is sufficient, it calculates the actual input amount required to receive the desired output amount based on the current reserves and the swap formula. Finally, it updates the internal state of balances and reserves accordingly and returns a success response with the actual input amount used and price impact, or an error message if any step fails.
144
+ *
145
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
146
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the swap request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully executing the swap.
147
+ * @param token1Addr The address of the input token as a hexadecimal string. This address is used to identify the token being swapped from and to fetch its current balance and reserves. The function will also use this address to calculate the pair address and to update the user's balance after executing the swap.
148
+ * @param token2Addr The address of the output token as a hexadecimal string. Similar to token1Addr, this address is used to identify the token being swapped to, to fetch its current balance and reserves, and to calculate the pair address for updating the user's balance after executing the swap.
149
+ * @param maxInAmt The maximum amount of the input token that the user is willing to swap as a bigint. This amount is used to ensure that the user does not spend more than this amount of the input token when trying to receive the desired output amount. The function will check that the actual input amount required to receive the desired output amount does not exceed this maximum, and if it does, the function will throw an error and not proceed with executing the swap.
150
+ * @param outAmt The desired amount of the output token to be received from the swap as a bigint. This amount is used in the calculation of how much of the input token will be required based on the current reserves and the swap formula. The function will ensure that this amount meets the minimum requirements and will update the user's balance accordingly after executing the swap.
151
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the swap request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with executing the swap, ensuring that only authorized requests are processed.
152
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each swap request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
153
+ * @param token1FeeBps The fee for the input token in basis points (bps) as a bigint. This fee is applied to the amount of the input token being swapped and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after executing the swap.
154
+ * @param token2FeeBps The fee for the output token in basis points (bps) as a bigint. This fee is applied to the amount of the output token being received and is deducted from the user's balance. The function will calculate the fee based on this value and ensure that it is properly accounted for in the user's balance updates after executing the swap.
155
+ * @param btcFee The miner fee as a bigint, denominated in WBTC sats. It is a flat amount, not a rate: the function debits exactly this much WBTC from the user's balance on top of the swap, so it is not reflected in the amounts returned.
156
+ *
157
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the actual amount of the input token used for the swap and the price impact of the swap. If there is an error, the object contains an error message describing the issue that occurred during the swap process.
158
+ */
159
+ export declare function swap2Request(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
160
+ token1Addr: string, // hex string token in address
161
+ token2Addr: string, // hex string token out address
162
+ maxInAmt: bigint, // bigint max token in amount
163
+ outAmt: bigint, // bigint token out amount
164
+ blsSignature: string, // hex string BLS signature
165
+ nonce: bigint, // unique request nonce
166
+ token1FeeBps: bigint, // bigint token1 fee in bps
167
+ token2FeeBps: bigint, // bigint token2 fee in bps
168
+ btcFee: bigint): Promise<{
169
+ success: boolean;
170
+ amounts: bigint[];
171
+ price_impact_bps: bigint;
172
+ error_message?: undefined;
173
+ } | {
174
+ success: boolean;
175
+ error_message: any;
176
+ amounts?: undefined;
177
+ price_impact_bps?: undefined;
178
+ }>;
179
+ /**
180
+ * Handles the withdraw request for BiS Swap. The withdrawRequest function takes various parameters including the user's public key, token address, target address, amount to withdraw, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it verifies that the user has sufficient balance of the specified token to withdraw. If the signature is valid and the balance is sufficient, it updates the internal state of balances accordingly and returns a success response with the withdrawn amount, or an error message if any step fails.
181
+ *
182
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
183
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the withdraw request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully executing the withdraw.
184
+ * @param tokenAddr The address of the token to be withdrawn as a hexadecimal string. This address is used to identify the token being withdrawn and to fetch its current balance. The function will also use this address to update the user's balance after successfully executing the withdraw.
185
+ * @param targetAddr The target address where the withdrawn tokens will be sent as a hexadecimal string. This address is used to specify the destination of the withdrawn tokens. The function will ensure that this address is valid and will include it in the message for BLS signature verification to ensure the authenticity of the request.
186
+ * @param amt The amount of the token to be withdrawn as a bigint. This amount is used to check if the user has sufficient balance of the specified token to withdraw. The function will also include this amount in the message for BLS signature verification and will update the user's balance accordingly after successfully executing the withdraw.
187
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the withdraw request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with executing the withdraw, ensuring that only authorized requests are processed.
188
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each withdraw request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
189
+ * @param btcFee The miner fee as a bigint, denominated in WBTC sats. It is a flat amount, not a rate: the function debits exactly this much WBTC from the user's balance on top of the withdraw, so it is not reflected in the amounts returned.
190
+ *
191
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the amount of the token that was withdrawn. If there is an error, the object contains an error message describing the issue that occurred during the withdraw process.
192
+ */
193
+ export declare function withdrawRequest(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
194
+ tokenAddr: string, // hex string token address
195
+ targetAddr: string, // hex string target address
196
+ amt: bigint, // bigint token amount
197
+ blsSignature: string, // hex string BLS signature
198
+ nonce: bigint, // unique request nonce
199
+ btcFee: bigint): Promise<{
200
+ success: boolean;
201
+ data: {
202
+ amt: bigint;
203
+ };
204
+ error_message?: undefined;
205
+ } | {
206
+ success: boolean;
207
+ error_message: any;
208
+ data?: undefined;
209
+ }>;
210
+ /**
211
+ * Handles the unwrap request for BiS Swap. The unwrapRequest function takes various parameters including the user's public key, pkscript, amount to unwrap, fees, and a BLS signature for authentication. It first checks the validity of the BLS signature to ensure that the request is authorized. Then, it verifies that the user has sufficient balance of the wrapped token (WBTC) to unwrap. If the signature is valid and the balance is sufficient, it updates the internal state of balances accordingly and returns a success response with the unwrapped amount, or an error message if any step fails.
212
+ *
213
+ * @param proxy An instance of UniswapInfoProxy that provides methods to fetch balances and reserves. This proxy is used to interact with the underlying data source for token balances and liquidity pool reserves, allowing the function to perform necessary calculations and updates based on the current state of the Uniswap-like exchange.
214
+ * @param pubkey The user's public key as a hexadecimal string. This public key is used to identify the user making the unwrap request and to verify the BLS signature for authentication. The function will use this public key to fetch the user's current balances and to update them after successfully executing the unwrap.
215
+ * @param pkscript The pkscript as a hexadecimal string that specifies the script for the unwrapped Bitcoin. This pkscript is used in the construction of the message for BLS signature verification to ensure the authenticity of the request. The function will also use this pkscript to determine the destination of the unwrapped Bitcoin and to include it in the message for signature verification.
216
+ * @param amt The amount of the wrapped token (WBTC) to be unwrapped as a bigint. This amount is used to check if the user has sufficient balance of WBTC to unwrap. The function will also include this amount in the message for BLS signature verification and will update the user's balance accordingly after successfully executing the unwrap.
217
+ * @param blsSignature The BLS signature as a hexadecimal string that is used to authenticate the unwrap request. This signature is generated by the user using their private key and is verified against the public key and the message constructed from the request parameters. The function will check the validity of this signature before proceeding with executing the unwrap, ensuring that only authorized requests are processed.
218
+ * @param nonce A unique nonce as a bigint that is used in the construction of the message for BLS signature verification. This nonce helps to prevent replay attacks by ensuring that each unwrap request has a unique message, even if all other parameters are the same. The function will include this nonce in the message that is hashed and verified against the BLS signature to ensure the authenticity of the request.
219
+ * @param btcFee The miner fee as a bigint, denominated in WBTC sats. It is a flat amount, not a rate: the function debits exactly this much WBTC from the user's balance on top of the unwrap, so it is not reflected in the amounts returned.
220
+ *
221
+ * @returns A promise that resolves to an object indicating the success of the operation. If successful, the object contains the amount of the wrapped token that was unwrapped. If there is an error, the object contains an error message describing the issue that occurred during the unwrap process.
222
+ */
223
+ export declare function unwrapRequest(proxy: UniswapInfoProxy, pubkey: string, // hex string bls pubkey
224
+ pkscript: string, // hex string pkscript
225
+ amt: bigint, // bigint token amount
226
+ blsSignature: string, // hex string BLS signature
227
+ nonce: bigint, // unique request nonce
228
+ btcFee: bigint): Promise<{
229
+ success: boolean;
230
+ data: {
231
+ amt: bigint;
232
+ };
233
+ error_message?: undefined;
234
+ } | {
235
+ success: boolean;
236
+ error_message: any;
237
+ data?: undefined;
238
+ }>;
@@ -0,0 +1,7 @@
1
+ import { default as Web3 } from 'web3';
2
+ /**
3
+ * Provides a singleton instance of the Web3 library. The getWeb3 function checks if a Web3 instance already exists and returns it if available. If not, it creates a new instance of Web3 and stores it in the web3 variable for future use. This ensures that only one instance of Web3 is created throughout the application, allowing for efficient resource usage and consistent access to the Web3 functionality.
4
+ *
5
+ * @returns {Web3} A singleton instance of the Web3 library, which can be used to interact with the Ethereum blockchain. This instance is created on demand and reused for subsequent calls to getWeb3, ensuring that only one instance exists throughout the application.
6
+ */
7
+ export declare function getWeb3(): Web3;
@@ -0,0 +1,9 @@
1
+ export * as wallet from './api/wallet.node';
2
+ export * as swap from './api/swap';
3
+ export * as brc20 from './api/brc20';
4
+ export * as mint from './api/mint';
5
+ export * as balances from './api/balances';
6
+ export * from './api/helpers';
7
+ export type { PaymentOpts } from './types/common';
8
+ export * as bitcoinjs from 'bitcoinjs-lib';
9
+ export * as Buff from '@cmdcode/buff-utils';
@@ -0,0 +1,97 @@
1
+ import { BISWallet, BISWalletPurpose } from '../types/common';
2
+ /**
3
+ * Defines the structure of the response returned by the sign function in the BISProvider interface. The SignResponse interface includes a transaction ID (txId) as a string and the signed PSBT (Partially Signed Bitcoin Transaction) in hexadecimal format as a string. This structure allows developers to easily access the results of the signing process, including the transaction ID for tracking purposes and the signed PSBT for further processing or broadcasting to the network.
4
+ *
5
+ * txId: A string representing the transaction ID (txid) of the signed transaction. This value is useful for tracking the transaction on the blockchain after it has been signed and potentially broadcasted.
6
+ * signedPsbtHex: A string containing the signed PSBT in hexadecimal format. This value can be used for further processing, such as broadcasting the transaction to the network or extracting information from the signed PSBT.
7
+ */
8
+ export interface SignResponse {
9
+ txId: string;
10
+ signedTxHex: string;
11
+ }
12
+ /**
13
+ * Defines the structure of a signature response that includes both the signature and the address associated with the signature. The SignatureWithAddress interface includes a signature as a string and an address as a string. This structure allows developers to easily access both the signature and the corresponding address when signing messages or transactions using the BISProvider interface.
14
+ *
15
+ * signature: A string representing the signature generated by the provider when signing a message or transaction. This value can be used for verification or other purposes where the signature is required.
16
+ * address: A string representing the address associated with the signature. This value can be used to identify which wallet or address was used for signing, which can be important for verification or tracking purposes.
17
+ */
18
+ export interface SignatureWithAddress {
19
+ signature: string;
20
+ address: string;
21
+ }
22
+ /**
23
+ * Defines the type for the sign function used in the BISProvider interface. The SignFunction type specifies the parameters and return type for a function that signs a PSBT (Partially Signed Bitcoin Transaction) with specific handling for inscriptions. The function takes an unsigned PSBT in hexadecimal format, payment and ordinal addresses, indexes for inputs to sign, and optional parameters for tweaking and excluding certain indexes from signing. It returns a promise that resolves to an object containing the signed PSBT as a hexadecimal string and optionally the transaction ID (txid) if the transaction was broadcasted. This type definition ensures that any implementation of the sign function adheres to the expected structure and behavior when used within the BISProvider interface.
24
+ *
25
+ * @param unsignedPsbtHex The unsigned PSBT to be signed, provided in hexadecimal format as a string. This PSBT will be processed and sent to the provider for signing.
26
+ * @param paymentAddr The payment address associated with the PSBT, provided as a string. This address is used in the signing process to identify the relevant inputs and outputs in the PSBT.
27
+ * @param ordAddr The ordinal address associated with the PSBT, provided as a string. This address is used in the signing process to identify the relevant inputs and outputs in the PSBT, particularly for inscriptions.
28
+ * @param ordAddrIdxes An array of indexes for the ordinal address inputs that should be signed. This array specifies which inputs in the PSBT are associated with the ordinal address and should be included in the signing process.
29
+ * @param useTweakSignerIdxes An array of indexes for inputs that should use a tweaked signer during the signing process. This allows for specific inputs to be signed with additional security measures, if supported by the provider.
30
+ * @param noSignIdxes An array of indexes for inputs that should be excluded from signing. This allows for specific inputs to be left unsigned, which can be useful in certain scenarios where not all inputs should be signed.
31
+ *
32
+ * @returns A promise that resolves to an object containing the signed PSBT as a hexadecimal string and optionally the transaction ID (txid) if the transaction was broadcasted. This allows developers to use the signed PSBT for further processing or to track the transaction on the blockchain. If there is an error in signing the PSBT, the promise will be rejected with a descriptive error message.
33
+ */
34
+ export type SignFunction = (unsignedPsbtHex: string, paymentAddr: string, ordAddr: string, ordAddrIdxes: number[], useTweakSignerIdxes?: number[], noSignIdxes?: number[]) => Promise<SignResponse>;
35
+ /**
36
+ * Defines the interface for a BISProvider, which includes methods for retrieving wallets, signing messages, and sending Bitcoin. The BISProvider interface specifies the structure that any wallet provider must implement to be compatible with the BIS Wallet Kit. This includes methods for getting the list of wallets, signing messages in both standard and deterministic ways, sending Bitcoin transactions, and signing PSBTs (Partially Signed Bitcoin Transactions). By adhering to this interface, different wallet providers can be integrated into the BIS Wallet Kit while ensuring a consistent API for developers using the kit.
37
+ */
38
+ export interface BISProvider {
39
+ /**
40
+ * Checks the current network of the provider. The checkNetwork method is an optional function that, when implemented, allows the provider to verify and update its network status. This can be useful for providers that need to ensure they are connected to the correct Bitcoin network (e.g., mainnet, testnet) before performing operations such as signing messages or sending transactions. If the provider implements this method, it should return a promise that resolves when the network check is complete, allowing developers to handle any necessary updates or error handling related to network changes.
41
+ *
42
+ * @returns A promise that resolves when the network check is complete. This allows developers to handle any necessary updates or error handling related to network changes. If the provider does not implement this method, it can be safely ignored, and the provider will be assumed to be on the correct network by default.
43
+ */
44
+ checkNetwork?: () => Promise<void>;
45
+ /**
46
+ * Retrieves the wallets associated with the provider. The getWallets method returns a promise that resolves to an array of BISWallet objects, each representing a wallet associated with the provider. This method allows developers to access the wallets available through the provider, enabling them to perform operations such as signing messages or sending transactions using those wallets.
47
+ *
48
+ * @returns A promise that resolves to an array of BISWallet objects, each representing a wallet associated with the provider. This allows developers to access the wallets available through the provider and perform various operations with them. If there is an error in retrieving the wallets, the promise will be rejected with an appropriate error message.
49
+ */
50
+ getWallets: () => Promise<BISWallet[]>;
51
+ /**
52
+ * Signs a message using the provider. The signMessage method takes a message as a string and returns a promise that resolves to the signature of the message as a hexadecimal string. This method allows developers to sign messages using the wallets associated with the provider, enabling functionalities such as authentication or transaction signing. If there is an error in signing the message, the promise will be rejected with an appropriate error message.
53
+ *
54
+ * @param message The message to be signed as a string. This message will be sent to the provider for signing, and the resulting signature will be returned as a hexadecimal string.
55
+ * @returns A promise that resolves to the signature of the message as a hexadecimal string. This allows developers to use the signature for verification or other purposes. If there is an error in signing the message, the promise will be rejected with a descriptive error message.
56
+ */
57
+ signMessage: (message: string, walletType: BISWalletPurpose, walletAddress: string) => Promise<string>;
58
+ /**
59
+ * Signs a message using the provider with a deterministic signing method. The signMessageDeterministic method takes a message as a string and returns a promise that resolves to an object containing the signature of the message as a hexadecimal string and the address of the wallet used for signing. This method allows developers to sign messages in a deterministic way, which can be useful for certain applications where the same message should produce the same signature. If there is an error in signing the message, the promise will be rejected with an appropriate error message.
60
+ *
61
+ * @param message The message to be signed as a string. This message will be sent to the provider for signing using a deterministic method, and the resulting signature and signing address will be returned.
62
+ * @returns A promise that resolves to an object containing the signature of the message as a hexadecimal string and the address of the wallet used for signing. This allows developers to use the signature for verification or other purposes, along with the address of the signing wallet. If there is an error in signing the message, the promise will be rejected with a descriptive error message.
63
+ */
64
+ signMessageDeterministic: (message: string) => Promise<SignatureWithAddress>;
65
+ /**
66
+ * Sends Bitcoin using the provider. The sendBTC method takes the amount of Bitcoin to send in satoshis and the address to which the Bitcoin should be sent, and returns a promise that resolves to the transaction ID (txid) of the sent transaction as a string. This method allows developers to send Bitcoin transactions using the wallets associated with the provider. If there is an error in sending the Bitcoin, such as if the sending request fails, the promise will be rejected with an appropriate error message.
67
+ *
68
+ * @param amountSats The amount of Bitcoin to send in satoshis. This value will be sent to the provider to initiate the transaction.
69
+ * @param toAddress The address to which the Bitcoin should be sent. This value will be sent to the provider along with the amount to initiate the transaction.
70
+ * @param feeRate Optional fee rate in satoshis per virtual byte (sat/vB). Extension providers estimate the fee themselves and ignore this value; the local (WIF) provider builds the transaction in-process and requires it.
71
+ * @returns A promise that resolves to the transaction ID (txid) of the sent transaction as a string. This allows developers to track the transaction on the blockchain. If there is an error in sending the Bitcoin, the promise will be rejected with a descriptive error message.
72
+ */
73
+ sendBTC: (amountSats: number, toAddress: string, feeRate?: number) => Promise<string>;
74
+ /**
75
+ * Signs a PSBT (Partially Signed Bitcoin Transaction) with specific handling for inscriptions using the provider. The signPSBT method takes an unsigned PSBT in hexadecimal format, a boolean indicating whether to broadcast the transaction after signing, and an array of input objects that specify which inputs in the PSBT should be signed along with any specific options for signing those inputs. It returns a promise that resolves to the signed PSBT as a hexadecimal string if broadcast is false, or the transaction ID (txid) of the broadcasted transaction if broadcast is true. This method allows developers to sign PSBTs with various input configurations and optionally broadcast them to the network. If there is an error in signing the PSBT or broadcasting it, the promise will be rejected with an appropriate error message.
76
+ *
77
+ * @param psbtBase64 The unsigned PSBT to be signed, provided in Base64 format as a string. This PSBT will be processed and sent to the provider for signing.
78
+ * @param broadcast A boolean indicating whether the signed PSBT should be broadcasted to the network after signing. If true, the function will attempt to push the signed PSBT to the network using the provider's method for broadcasting transactions.
79
+ * @param inputsToSign An array of input objects that specify which inputs in the PSBT should be signed, along with any specific options for signing those inputs. Each input object can include the address associated with the input, the indexes of the inputs to sign, and whether to use a tweaked signer for those inputs. This information is used to construct the signing request sent to the provider, allowing for flexible signing of PSBTs with various input configurations.
80
+ *
81
+ * @returns A promise that resolves to the signed PSBT as a hexadecimal string if broadcast is false, or the transaction ID (txid) of the broadcasted transaction if broadcast is true. This allows developers to use the signed PSBT for further processing or to track the transaction on the blockchain. If there is an error in signing the PSBT or broadcasting it, the promise will be rejected with a descriptive error message.
82
+ */
83
+ signPSBT: (psbtBase64: string, broadcast: boolean, inputsToSign: any[], message?: string) => Promise<string>;
84
+ /**
85
+ * Signs a PSBT (Partially Signed Bitcoin Transaction) with specific handling for inscriptions using the provider. The sign function takes an unsigned PSBT in hexadecimal format, payment and ordinal addresses, indexes for inputs to sign, and optional parameters for tweaking and excluding certain indexes from signing. It constructs the necessary data for signing the PSBT with the provider and returns the signed transaction details, including the transaction ID and signed transaction hex. If the provider is not found or if the signing process fails, the function throws an error with an appropriate message.
86
+ *
87
+ * @param unsignedPsbtHex The unsigned PSBT to be signed, provided in hexadecimal format as a string. This PSBT will be processed and sent to the provider for signing.
88
+ * @param paymentAddr The payment address associated with the PSBT, provided as a string. This address is used in the signing process to identify the relevant inputs and outputs in the PSBT.
89
+ * @param ordAddr The ordinal address associated with the PSBT, provided as a string. This address is used in the signing process to identify the relevant inputs and outputs in the PSBT, particularly for inscriptions.
90
+ * @param ordAddrIdxes An array of indexes for the ordinal address inputs that should be signed. This array specifies which inputs in the PSBT are associated with the ordinal address and should be included in the signing process.
91
+ * @param useTweakSignerIdxes An array of indexes for inputs that should use a tweaked signer during the signing process. This allows for specific inputs to be signed with additional security measures, if supported by the provider.
92
+ * @param noSignIdxes An array of indexes for inputs that should be excluded from signing. This allows for specific inputs to be left unsigned, which can be useful in certain scenarios where not all inputs should be signed.
93
+ *
94
+ * @returns A promise that resolves to an object containing the signed PSBT as a hexadecimal string and optionally the transaction ID (txid) if the transaction was broadcasted. This allows developers to use the signed PSBT for further processing or to track the transaction on the blockchain. If there is an error in signing the PSBT, the promise will be rejected with a descriptive error message.
95
+ */
96
+ sign: SignFunction;
97
+ }
@@ -0,0 +1,2 @@
1
+ import { BISProvider } from './api';
2
+ export declare const LEATHER: BISProvider;
@@ -0,0 +1,39 @@
1
+ import { BISNetwork, BISWallet } from '../types/common';
2
+ import { BISProvider } from './api';
3
+ export type LocalWalletSource = 'unisat' | 'okx';
4
+ export type LocalWalletType = 'p2wpkh' | 'p2tr';
5
+ /**
6
+ * Saves the wallet information to memory. The saveWallet function takes the private key, network, wallet type, and source wallet as parameters and stores this information in the local wallet storage. It also updates the wallet's network setting and saves the wallet information using the saveWalletInfo function. This function is crucial for allowing users to store their wallet information locally and retrieve it later for signing messages or sending transactions. It includes error handling to ensure that only valid wallet types and sources are accepted, and it throws an error if there is an issue with saving the wallet information.
7
+ *
8
+ * @param privKeyWIF The private key of the wallet as a string in WIF format. This is the key that will be used for signing messages and transactions, and it should be kept secure and not shared with others.
9
+ * @param network The network associated with the wallet, such as 'mainnet' or 'testnet'. This information is important for ensuring that the wallet is used on the correct blockchain network and for deriving the correct addresses and transaction formats.
10
+ * @param walletType The type of wallet being saved, which can be either 'p2wpkh' (Pay-to-Witness-Public-Key-Hash) or 'p2tr' (Pay-to-Taproot). This determines the address format and signing method used by the wallet.
11
+ * @param sourceWallet The source of the wallet, which can be either 'unisat' or 'okx'. This information can be used to identify where the wallet information originated from and may be useful for debugging or analytics purposes.
12
+ *
13
+ * @returns A promise that resolves when the wallet information has been successfully saved to memory. If there is an error during the saving process, such as an invalid wallet type or source, the function will throw an error with a descriptive message.
14
+ */
15
+ export declare function saveWallet(privKeyWIF: string, network: BISNetwork, walletType?: LocalWalletType, sourceWallet?: LocalWalletSource): Promise<BISWallet>;
16
+ /**
17
+ * Generates a brand-new single-key Bitcoin wallet and connects it, returning
18
+ * the private key alongside the derived address. This is the counterpart to
19
+ * {@link saveWallet}: instead of importing an existing WIF, it produces a fresh
20
+ * random key (via secp256k1) for the given network and wallet type, then loads
21
+ * it through the same path so the returned address is guaranteed to re-import
22
+ * to the same key. It is intended for headless agents that need to create a
23
+ * fundable address on the fly.
24
+ *
25
+ * The wallet is a single (non-HD) key — there is no mnemonic or derivation
26
+ * path. The returned WIF is the ONLY secret; the caller is solely responsible
27
+ * for storing it. This function does not persist the key anywhere beyond the
28
+ * in-memory session used by the current process.
29
+ *
30
+ * @param network The network the wallet is for, e.g. 'mainnet' or 'testnet'. This determines the WIF version and address format.
31
+ * @param walletType The address type to derive, either 'p2wpkh' (default) or 'p2tr'.
32
+ * @param sourceWallet The source label recorded for the session, either 'unisat' (default) or 'okx'.
33
+ *
34
+ * @returns A promise resolving to the connected wallet ({ address, pubkey, purpose }) plus the generated `wif` private key. Throws if the wallet type or source is invalid.
35
+ */
36
+ export declare function createWallet(network: BISNetwork, walletType?: LocalWalletType, sourceWallet?: LocalWalletSource): Promise<BISWallet & {
37
+ wif: string;
38
+ }>;
39
+ export declare const LOCAL: BISProvider;
@@ -0,0 +1,2 @@
1
+ import { BISProvider } from './api';
2
+ export declare const OKX: BISProvider;
@@ -0,0 +1,2 @@
1
+ import { BISProvider } from './api';
2
+ export declare const UNISAT: BISProvider;
@@ -0,0 +1,2 @@
1
+ import { BISProvider } from './api';
2
+ export declare const XVERSE: BISProvider;
@@ -0,0 +1,3 @@
1
+ export { useNetwork } from './adapters/react/use-network';
2
+ export { useWallet } from './adapters/react/use-wallet';
3
+ export type { BISNetwork, BISSession, BISWallet, BISWalletProvider } from './types/common';
@@ -0,0 +1,33 @@
1
+ export type ModalState = 'connect' | 'confirm_connection' | 'error';
2
+ export type ModalTheme = 'light' | 'dark' | 'system';
3
+ export type BISNetwork = 'mainnet' | 'testnet' | 'signet';
4
+ export interface ConnectCallbacks {
5
+ onSelect: (session: BISSession) => void;
6
+ onError: (error: Error) => void;
7
+ }
8
+ export type BISWalletProvider = 'okx' | 'unisat' | 'xverse' | 'leather' | 'local';
9
+ export type BISWalletPurpose = 'ordinals' | 'payment' | 'all';
10
+ export interface BISSession {
11
+ provider: BISWalletProvider;
12
+ wallets: BISWallet[];
13
+ signature: string | null;
14
+ }
15
+ export interface BISWallet {
16
+ address: string;
17
+ pubkey: string | null;
18
+ purpose: BISWalletPurpose;
19
+ }
20
+ /**
21
+ * An optional extra payment output attached to a transaction (e.g. a service
22
+ * fee). When `paymentAmount` is greater than 0, the transaction includes an
23
+ * output sending that many sats to `paymentAddress`, funded by the connected
24
+ * wallet — this is a destination the funds go *to*, not an alternate funding
25
+ * source. A non-positive amount adds no output.
26
+ *
27
+ * @property paymentAddress - The destination address that receives the payment output.
28
+ * @property paymentAmount - The amount sent to `paymentAddress`, in sats. Must be greater than 0 to add the output.
29
+ */
30
+ export interface PaymentOpts {
31
+ paymentAddress: string;
32
+ paymentAmount: number;
33
+ }
@@ -0,0 +1,26 @@
1
+ import { ListenFn, RequestFn } from '@leather-wallet/types';
2
+ declare global {
3
+ interface Window {
4
+ // Providers
5
+ unisat?: UniSat
6
+ LeatherProvider?: {
7
+ request: RequestFn
8
+ listen: ListenFn
9
+ }
10
+ okxwallet?: any
11
+ XverseProviders?: any
12
+ }
13
+ }
14
+
15
+ interface UniSat {
16
+ requestAccounts: () => Promise<string[]>
17
+ getNetwork: () => Promise<'livenet' | 'testnet'>
18
+ switchNetwork: (network: string) => Promise<void>
19
+ signMessage: (message: string, type?: 'ecdsa' | 'bip322-simple') => Promise<string>
20
+ signPsbt: (psbt: any, options?: any) => Promise<string>
21
+ pushPsbt: (psbt: any) => Promise<string>
22
+ getPublicKey: () => Promise<string>
23
+ sendBitcoin: (toAddress: string, amountSats: number) => Promise<string>
24
+ }
25
+
26
+ export {}