@bestinslot/wallet-kit 0.7.0 → 0.8.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.
- package/dist/{balances-BQiaAIaq.js → balances-sT2p7EnF.js} +2915 -2804
- package/dist/browser.js +2 -2
- package/dist/core.js +2 -2
- package/dist/node.js +427 -423
- package/dist/types/api/brc20.d.ts +2 -0
- package/dist/types/api/wallet.node.d.ts +1 -1
- package/dist/types/core/bis_swap.d.ts +4 -0
- package/dist/types/core/brc20-inscriptions.d.ts +122 -0
- package/dist/types/lib/uniswap_ops.d.ts +8 -0
- package/dist/types/provider/local.d.ts +14 -0
- package/package.json +3 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BISWalletPurpose, PaymentOpts } from '../types/common';
|
|
2
|
+
export type { Brc20AmountOptions, Brc20DeployOptions, Brc20PredeployOptions, Brc20PredeployResult, } from '../core/brc20-inscriptions';
|
|
3
|
+
export { computeBrc20PredeployHash, deployBrc20Inscription, generateBrc20Salt, mintBrc20Inscription, predeployInscriptions, transferBrc20Inscription, } from '../core/brc20-inscriptions';
|
|
2
4
|
/**
|
|
3
5
|
* Interface representing the result of an inscription and send to OP_RETURN operation, including transaction IDs, signed transaction hexes, inscription ID, postage, and secret used in the minting process. This interface is used to encapsulate the details of the deploy, call and deposit operations in the BRC2.0 programmable module.
|
|
4
6
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { LocalWalletSource, LocalWalletType } from '../provider/local';
|
|
2
|
-
export { createWallet, saveWallet as connectLocalWallet } from '../provider/local';
|
|
2
|
+
export { createWallet, lockLocalWallet, saveWallet as connectLocalWallet } from '../provider/local';
|
|
3
3
|
export * from './wallet';
|
|
4
4
|
export type { LocalWalletSource, LocalWalletType };
|
|
@@ -502,6 +502,8 @@ export declare function getSwapResult(tokenInAddr: string, tokenOutAddr: string,
|
|
|
502
502
|
amount_out: bigint;
|
|
503
503
|
quoted_price: number;
|
|
504
504
|
price_impact_bps: bigint;
|
|
505
|
+
reserve_in: bigint;
|
|
506
|
+
reserve_out: bigint;
|
|
505
507
|
fees: SwapFees;
|
|
506
508
|
}>;
|
|
507
509
|
interface SwapOrderResponse {
|
|
@@ -533,6 +535,8 @@ export declare function getSwap2Result(tokenInAddr: string, tokenOutAddr: string
|
|
|
533
535
|
amount_in: bigint;
|
|
534
536
|
quoted_price: number;
|
|
535
537
|
price_impact_bps: bigint;
|
|
538
|
+
reserve_in: bigint;
|
|
539
|
+
reserve_out: bigint;
|
|
536
540
|
fees: SwapFees;
|
|
537
541
|
}>;
|
|
538
542
|
interface Swap2OrderResponse {
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { InscriptionDetails } from '../types/inscription';
|
|
2
|
+
/**
|
|
3
|
+
* Options shared by the deploy builders.
|
|
4
|
+
*
|
|
5
|
+
* @property tick - The BRC-20 ticker. 4 or 5 bytes for {@link deployBrc20Inscription}; 6 bytes for {@link predeployInscriptions}.
|
|
6
|
+
* @property max - Maximum supply, as a string (BRC-20 amounts are strings).
|
|
7
|
+
* @property lim - Optional per-mint limit, as a string.
|
|
8
|
+
* @property dec - Optional decimals, as a string or number (serialised as a string).
|
|
9
|
+
* @property selfMint - Optional override for the `self_mint` field. 5-byte tickers force `true`; 4-byte tickers default to omitting it unless set to `true`.
|
|
10
|
+
*/
|
|
11
|
+
export interface Brc20DeployOptions {
|
|
12
|
+
tick: string;
|
|
13
|
+
max: string;
|
|
14
|
+
lim?: string;
|
|
15
|
+
dec?: string | number;
|
|
16
|
+
selfMint?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for {@link mintBrc20Inscription} and {@link transferBrc20Inscription}.
|
|
20
|
+
*
|
|
21
|
+
* @property tick - The BRC-20 ticker (4-6 bytes).
|
|
22
|
+
* @property amt - The amount, as a string (BRC-20 amounts are strings).
|
|
23
|
+
*/
|
|
24
|
+
export interface Brc20AmountOptions {
|
|
25
|
+
tick: string;
|
|
26
|
+
amt: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for {@link predeployInscriptions}.
|
|
30
|
+
*
|
|
31
|
+
* @property tick - The 6-byte namespaced ticker (must match /^[A-Za-z0-9-]{6}$/).
|
|
32
|
+
* @property address - The deployer's Bitcoin address. Its output script (pkscript) is derived on the current network and bound into the commitment hash, so this must be the address that will receive the deploy reveal.
|
|
33
|
+
* @property salt - Optional hex salt. Generated automatically when omitted.
|
|
34
|
+
* @property max - Maximum supply, as a string.
|
|
35
|
+
* @property lim - Optional per-mint limit, as a string.
|
|
36
|
+
* @property dec - Optional decimals, as a string or number.
|
|
37
|
+
*/
|
|
38
|
+
export interface Brc20PredeployOptions {
|
|
39
|
+
tick: string;
|
|
40
|
+
address: string;
|
|
41
|
+
salt?: string;
|
|
42
|
+
max: string;
|
|
43
|
+
lim?: string;
|
|
44
|
+
dec?: string | number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of {@link predeployInscriptions}: the salt/hash used and both ready-to-inscribe payloads.
|
|
48
|
+
*
|
|
49
|
+
* @property salt - The hex salt used (echo of the input, or the auto-generated value). Keep it: the deploy reveal must reuse the same salt.
|
|
50
|
+
* @property hash - The `double_sha256(tick + salt + pkscript)` hex committed to by the predeploy.
|
|
51
|
+
* @property predeploy - The predeploy inscription (inscribe first).
|
|
52
|
+
* @property deploy - The matching deploy inscription (inscribe as a child of the predeploy after the required block delay).
|
|
53
|
+
*/
|
|
54
|
+
export interface Brc20PredeployResult {
|
|
55
|
+
salt: string;
|
|
56
|
+
hash: string;
|
|
57
|
+
predeploy: InscriptionDetails;
|
|
58
|
+
deploy: InscriptionDetails;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build a BRC-20 `deploy` inscription for a 4- or 5-byte ticker.
|
|
62
|
+
*
|
|
63
|
+
* 4-byte tickers are free to mint (no `self_mint`); 5-byte tickers are
|
|
64
|
+
* self-issuance and always carry `self_mint: "true"`. For 6-byte namespaced
|
|
65
|
+
* tickers use {@link predeployInscriptions} instead.
|
|
66
|
+
*
|
|
67
|
+
* @param opts - See {@link Brc20DeployOptions}.
|
|
68
|
+
* @returns An {@link InscriptionDetails} ready to pass to `inscribe`.
|
|
69
|
+
* @throws If the ticker is not 4 or 5 bytes, if a 6-byte ticker is supplied, or if `self_mint` is disabled for a 5-byte ticker.
|
|
70
|
+
*/
|
|
71
|
+
export declare function deployBrc20Inscription(opts: Brc20DeployOptions): InscriptionDetails;
|
|
72
|
+
/**
|
|
73
|
+
* Build a BRC-20 `mint` inscription.
|
|
74
|
+
*
|
|
75
|
+
* @param opts - See {@link Brc20AmountOptions}.
|
|
76
|
+
* @returns An {@link InscriptionDetails} ready to pass to `inscribe`.
|
|
77
|
+
* @throws If the ticker is not 4-6 bytes or the amount is not a non-empty string.
|
|
78
|
+
*/
|
|
79
|
+
export declare function mintBrc20Inscription(opts: Brc20AmountOptions): InscriptionDetails;
|
|
80
|
+
/**
|
|
81
|
+
* Build a BRC-20 `transfer` inscription.
|
|
82
|
+
*
|
|
83
|
+
* @param opts - See {@link Brc20AmountOptions}.
|
|
84
|
+
* @returns An {@link InscriptionDetails} ready to pass to `inscribe`.
|
|
85
|
+
* @throws If the ticker is not 4-6 bytes or the amount is not a non-empty string.
|
|
86
|
+
*/
|
|
87
|
+
export declare function transferBrc20Inscription(opts: Brc20AmountOptions): InscriptionDetails;
|
|
88
|
+
/**
|
|
89
|
+
* Generate a random hex salt for a 6-byte namespace predeploy.
|
|
90
|
+
*
|
|
91
|
+
* @param byteLength - Number of random bytes (default 16). The returned hex string is twice this length.
|
|
92
|
+
* @returns A lowercase hex string.
|
|
93
|
+
*/
|
|
94
|
+
export declare function generateBrc20Salt(byteLength?: number): string;
|
|
95
|
+
/**
|
|
96
|
+
* Compute the predeploy commitment hash for a 6-byte namespace ticker.
|
|
97
|
+
*
|
|
98
|
+
* The preimage is `utf8(tick) ++ hexDecode(salt) ++ hexDecode(pkscript)`, and
|
|
99
|
+
* the hash is `sha256(sha256(preimage))`. The pkscript binds the commitment to
|
|
100
|
+
* the deployer, preventing cross-wallet replay.
|
|
101
|
+
*
|
|
102
|
+
* @param tick - The 6-byte namespaced ticker (must match /^[A-Za-z0-9-]{6}$/).
|
|
103
|
+
* @param salt - The salt, as a hex string.
|
|
104
|
+
* @param pkscript - The deployer's output script, as a hex string.
|
|
105
|
+
* @returns The commitment hash, as a lowercase hex string.
|
|
106
|
+
* @throws If the ticker is not a valid 6-byte namespaced ticker, or the salt/pkscript is not valid hex.
|
|
107
|
+
*/
|
|
108
|
+
export declare function computeBrc20PredeployHash(tick: string, salt: string, pkscript: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* Build the predeploy + deploy inscription pair for a 6-byte namespace ticker.
|
|
111
|
+
*
|
|
112
|
+
* Inscribe the returned `predeploy` first, wait the required number of blocks,
|
|
113
|
+
* then inscribe `deploy` as a child of the predeploy inscription (e.g. via
|
|
114
|
+
* `inscribeWithParent(result.deploy, predeployInscriptionId, …)`). The salt is
|
|
115
|
+
* generated automatically unless supplied, and is echoed back so the pair stays
|
|
116
|
+
* consistent.
|
|
117
|
+
*
|
|
118
|
+
* @param opts - See {@link Brc20PredeployOptions}.
|
|
119
|
+
* @returns The salt, commitment hash, and both {@link InscriptionDetails} payloads.
|
|
120
|
+
* @throws If the ticker is not a valid 6-byte namespaced ticker, the address is invalid, or the salt is not valid hex.
|
|
121
|
+
*/
|
|
122
|
+
export declare function predeployInscriptions(opts: Brc20PredeployOptions): Brc20PredeployResult;
|
|
@@ -132,12 +132,16 @@ btcFee: bigint): Promise<{
|
|
|
132
132
|
success: boolean;
|
|
133
133
|
amounts: bigint[];
|
|
134
134
|
price_impact_bps: bigint;
|
|
135
|
+
reserve_in: bigint;
|
|
136
|
+
reserve_out: bigint;
|
|
135
137
|
error_message?: undefined;
|
|
136
138
|
} | {
|
|
137
139
|
success: boolean;
|
|
138
140
|
error_message: any;
|
|
139
141
|
amounts?: undefined;
|
|
140
142
|
price_impact_bps?: undefined;
|
|
143
|
+
reserve_in?: undefined;
|
|
144
|
+
reserve_out?: undefined;
|
|
141
145
|
}>;
|
|
142
146
|
/**
|
|
143
147
|
* 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.
|
|
@@ -169,12 +173,16 @@ btcFee: bigint): Promise<{
|
|
|
169
173
|
success: boolean;
|
|
170
174
|
amounts: bigint[];
|
|
171
175
|
price_impact_bps: bigint;
|
|
176
|
+
reserve_in: bigint;
|
|
177
|
+
reserve_out: bigint;
|
|
172
178
|
error_message?: undefined;
|
|
173
179
|
} | {
|
|
174
180
|
success: boolean;
|
|
175
181
|
error_message: any;
|
|
176
182
|
amounts?: undefined;
|
|
177
183
|
price_impact_bps?: undefined;
|
|
184
|
+
reserve_in?: undefined;
|
|
185
|
+
reserve_out?: undefined;
|
|
178
186
|
}>;
|
|
179
187
|
/**
|
|
180
188
|
* 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.
|
|
@@ -36,4 +36,18 @@ export declare function saveWallet(privKeyWIF: string, network: BISNetwork, wall
|
|
|
36
36
|
export declare function createWallet(network: BISNetwork, walletType?: LocalWalletType, sourceWallet?: LocalWalletSource): Promise<BISWallet & {
|
|
37
37
|
wif: string;
|
|
38
38
|
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Locks the local (WIF) wallet by evicting all in-memory key material and
|
|
41
|
+
* clearing the connected session. After calling this, no private key remains
|
|
42
|
+
* resident in the process: `getSession()` returns `null`, and any subsequent
|
|
43
|
+
* sign/send call will fail until a wallet is reconnected via {@link saveWallet}
|
|
44
|
+
* (`connectLocalWallet`) or {@link createWallet}. (The exact error depends on the
|
|
45
|
+
* call path — e.g. a missing key or, if the network was also cleared, a network
|
|
46
|
+
* check — so callers should not rely on a specific error message.)
|
|
47
|
+
*
|
|
48
|
+
* This is intended for callers (e.g. an MCP server) that want to hold a key
|
|
49
|
+
* only for the duration of a single approved operation rather than keep it
|
|
50
|
+
* resident for the life of the process.
|
|
51
|
+
*/
|
|
52
|
+
export declare function lockLocalWallet(): void;
|
|
39
53
|
export declare const LOCAL: BISProvider;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bestinslot/wallet-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "A lightweight JavaScript library for connecting Bitcoin wallets with a unified API.",
|
|
7
7
|
"exports": {
|
|
@@ -120,6 +120,8 @@
|
|
|
120
120
|
"lint": "eslint",
|
|
121
121
|
"lint:fix": "prettier --write . && eslint --fix",
|
|
122
122
|
"test": "vitest run",
|
|
123
|
+
"release": "node scripts/release.mjs",
|
|
124
|
+
"release:tag": "node scripts/release.mjs --tag",
|
|
123
125
|
"verify:bundles": "node scripts/verify-build-flavours.mjs",
|
|
124
126
|
"test:signet": "vitest run tests/signet/ --config vitest.signet.config.ts",
|
|
125
127
|
"test:mainnet": "vitest run tests/mainnet/ --config vitest.mainnet.config.ts",
|