@dfinity/ckbtc 6.0.0 → 6.0.1

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 (2) hide show
  1. package/README.md +5 -329
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,6 +4,9 @@ A library for interfacing with [ckBTC](https://github.com/dfinity/ic/tree/master
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@dfinity/ckbtc.svg?logo=npm)](https://www.npmjs.com/package/@dfinity/ckbtc) [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
6
 
7
+ > [!TIP]
8
+ > Still using `@dfinity/ckbtc`? Upgrade to [`@icp-sdk/canisters/ckbtc`](https://js.icp.build/canisters/latest/upgrading/v1/)!
9
+
7
10
  ## Table of contents
8
11
 
9
12
  - [Installation](#installation)
@@ -45,336 +48,9 @@ const { getBtcAddress } = CkBTCMinterCanister.create({
45
48
  const btcAddress = await getBtcAddress({});
46
49
  ```
47
50
 
48
- ## Features
49
-
50
- `ckbtc-js` implements following features:
51
-
52
- <!-- TSDOC_START -->
53
-
54
- ### :toolbox: Functions
55
-
56
- - [parseBtcAddress](#gear-parsebtcaddress)
57
-
58
- #### :gear: parseBtcAddress
59
-
60
- Parse a Bitcoin address.
61
-
62
- Parse implementation follows strategy implemented in [Minter canister](https://github.com/dfinity/ic/blob/a8da3aa23dc6f8f4708cb0cb8edce84c5bd8f225/rs/bitcoin/ckbtc/minter/src/address.rs#L54).
63
-
64
- Credits: Parts of JavaScript code and test values from [bitcoin-address-validation](https://github.com/ruigomeseu/bitcoin-address-validation).
65
-
66
- | Function | Type |
67
- | ----------------- | ------------------------------------------------------- |
68
- | `parseBtcAddress` | `({ address, network, }: BtcAddress) => BtcAddressInfo` |
69
-
70
- Parameters:
71
-
72
- - `params`: The Bitcoin address and network to parse
73
- - `params.network`: Optional. Default BtcNetwork is Mainnet
74
-
75
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/utils/btc.utils.ts#L195)
76
-
77
- ### :factory: CkBTCMinterCanister
78
-
79
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L42)
80
-
81
- #### Static Methods
82
-
83
- - [create](#gear-create)
84
-
85
- ##### :gear: create
86
-
87
- | Method | Type |
88
- | -------- | ------------------------------------------------------------------ |
89
- | `create` | `(options: CkBTCCanisterOptions<_SERVICE>) => CkBTCMinterCanister` |
90
-
91
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L43)
92
-
93
- #### Methods
94
-
95
- - [getBtcAddress](#gear-getbtcaddress)
96
- - [updateBalance](#gear-updatebalance)
97
- - [getWithdrawalAccount](#gear-getwithdrawalaccount)
98
- - [retrieveBtc](#gear-retrievebtc)
99
- - [retrieveBtcWithApproval](#gear-retrievebtcwithapproval)
100
- - [retrieveBtcStatus](#gear-retrievebtcstatus)
101
- - [retrieveBtcStatusV2ByAccount](#gear-retrievebtcstatusv2byaccount)
102
- - [estimateWithdrawalFee](#gear-estimatewithdrawalfee)
103
- - [getMinterInfo](#gear-getminterinfo)
104
- - [getKnownUtxos](#gear-getknownutxos)
105
-
106
- ##### :gear: getBtcAddress
107
-
108
- Returns a BTC address for a given account.
109
-
110
- Note: an update call is required by the Minter canister.
111
-
112
- | Method | Type |
113
- | --------------- | ----------------------------------------------------------- |
114
- | `getBtcAddress` | `({ owner, subaccount, }: MinterParams) => Promise<string>` |
115
-
116
- Parameters:
117
-
118
- - `params`: The parameters for which a BTC address should be resolved.
119
- - `params.owner`: The owner for which the BTC address should be generated. If not provided, the `caller` will be use instead.
120
- - `params.subaccount`: An optional subaccount to compute the address.
121
-
122
- Returns:
123
-
124
- The BTC address of the given account.
125
-
126
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L64)
127
-
128
- ##### :gear: updateBalance
129
-
130
- Notify the minter about the bitcoin transfer.
131
-
132
- Upon successful notification, new ckBTC should be available on the targeted address.
133
-
134
- | Method | Type |
135
- | --------------- | -------------------------------------------------------------------- |
136
- | `updateBalance` | `({ owner, subaccount, }: MinterParams) => Promise<UpdateBalanceOk>` |
137
-
138
- Parameters:
139
-
140
- - `params`: The parameters are the address to which bitcoin where transferred.
141
- - `params.owner`: The owner of the address. If not provided, the `caller` will be use instead.
142
- - `params.subaccount`: An optional subaccount of the address.
143
-
144
- Returns:
145
-
146
- The result of the balance update.
147
-
148
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L83)
149
-
150
- ##### :gear: getWithdrawalAccount
151
-
152
- Returns the account to which the caller should deposit ckBTC before withdrawing BTC using the [retrieveBtc] endpoint.
153
-
154
- | Method | Type |
155
- | ---------------------- | ------------------------ |
156
- | `getWithdrawalAccount` | `() => Promise<Account>` |
157
-
158
- Returns:
159
-
160
- The account to which ckBTC needs to be transferred. Provide corresponding information to map an Icrc1 account.
161
-
162
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L106)
163
-
164
- ##### :gear: retrieveBtc
165
-
166
- Submits a request to convert ckBTC to BTC.
167
-
168
- Note:
169
-
170
- The BTC retrieval process is slow. Instead of synchronously waiting for a BTC transaction to settle, this method returns a request ([block_index]) that the caller can use to query the request status.
171
-
172
- Preconditions:
173
-
174
- The caller deposited the requested amount in ckBTC to the account that the [getWithdrawalAccount] endpoint returns.
175
-
176
- | Method | Type |
177
- | ------------- | ------------------------------------------------------- |
178
- | `retrieveBtc` | `(params: RetrieveBtcParams) => Promise<RetrieveBtcOk>` |
179
-
180
- Parameters:
181
-
182
- - `params`: The parameters are the bitcoin address and amount to convert.
183
- - `params.address`: The bitcoin address.
184
- - `params.amount`: The ckBTC amount.
185
-
186
- Returns:
187
-
188
- The result or the operation.
189
-
190
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L125)
191
-
192
- ##### :gear: retrieveBtcWithApproval
193
-
194
- Submits a request to convert ckBTC to BTC after making an ICRC-2 approval.
195
-
196
- # Note
197
-
198
- The BTC retrieval process is slow. Instead of synchronously waiting for a BTC transaction to settle, this method returns a request ([block_index]) that the caller can use to query the request status.
199
-
200
- # Preconditions
201
-
202
- The caller allowed the minter's principal to spend its funds using
203
- [icrc2_approve] on the ckBTC ledger.
204
-
205
- | Method | Type |
206
- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
207
- | `retrieveBtcWithApproval` | `({ address, amount, fromSubaccount, }: { address: string; amount: bigint; fromSubaccount?: Uint8Array<ArrayBufferLike> or undefined; }) => Promise<RetrieveBtcOk>` |
208
-
209
- Parameters:
210
-
211
- - `params.address`: The bitcoin address.
212
- - `params.amount`: The ckBTC amount.
213
- - `params.fromSubaccount`: An optional subaccount from which
214
- the ckBTC should be transferred.
215
-
216
- Returns:
217
-
218
- The result or the operation.
219
-
220
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L155)
221
-
222
- ##### :gear: retrieveBtcStatus
223
-
224
- Returns the status of a specific BTC withdrawal based on the transaction ID
225
- of the corresponding burn transaction.
226
-
227
- | Method | Type |
228
- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
229
- | `retrieveBtcStatus` | `({ transactionId, certified, }: { transactionId: bigint; certified: boolean; }) => Promise<RetrieveBtcStatus>` |
230
-
231
- Parameters:
232
-
233
- - `transactionId`: The ID of the corresponding burn transaction.
234
- - `certified`: query or update call
235
-
236
- Returns:
237
-
238
- The status of the BTC retrieval request.
239
-
240
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L187)
241
-
242
- ##### :gear: retrieveBtcStatusV2ByAccount
243
-
244
- Returns the status of all BTC withdrawals for an account.
245
-
246
- | Method | Type |
247
- | ------------------------------ | ------------------------------------------------------------------------------------------------------- |
248
- | `retrieveBtcStatusV2ByAccount` | `({ account, certified, }: RetrieveBtcStatusV2ByAccountParams) => Promise<RetrieveBtcStatusV2WithId[]>` |
249
-
250
- Parameters:
251
-
252
- - `certified`: query or update call
253
- - `account`: an optional account to retrieve the statuses. If not provided, statuses for the caller are retrieved.
254
-
255
- Returns:
256
-
257
- The statuses of the BTC retrieval requests.
258
-
259
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L205)
260
-
261
- ##### :gear: estimateWithdrawalFee
262
-
263
- Returns an estimation of the user's fee (in Satoshi) for a retrieve_btc request based on the current status of the Bitcoin network and the fee related to the minter.
264
-
265
- | Method | Type |
266
- | ----------------------- | ----------------------------------------------------------------------------------------- |
267
- | `estimateWithdrawalFee` | `({ certified, amount, }: EstimateWithdrawalFeeParams) => Promise<EstimateWithdrawalFee>` |
268
-
269
- Parameters:
270
-
271
- - `params`: The parameters to estimate the fee.
272
- - `params.certified`: query or update call
273
- - `params.amount`: The optional amount for which the fee should be estimated.
274
-
275
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L239)
276
-
277
- ##### :gear: getMinterInfo
278
-
279
- Returns internal minter parameters such as the minimal amount to retrieve BTC, minimal number of confirmations or KYT fee.
280
-
281
- | Method | Type |
282
- | --------------- | ----------------------------------------------------- |
283
- | `getMinterInfo` | `({ certified }: QueryParams) => Promise<MinterInfo>` |
284
-
285
- Parameters:
286
-
287
- - `params`: The parameters to get the minter info.
288
- - `params.certified`: query or update call
289
-
290
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L253)
291
-
292
- ##### :gear: getKnownUtxos
293
-
294
- Returns UTXOs of the given account known by the minter.
295
-
296
- | Method | Type |
297
- | --------------- | ----------------------------------------------------------------------------- |
298
- | `getKnownUtxos` | `({ owner, subaccount, certified, }: GetKnownUtxosParams) => Promise<Utxo[]>` |
299
-
300
- Parameters:
301
-
302
- - `params`: The parameters for which the known utxos should be resolved.
303
- - `params.owner`: The owner of the account. Note that if not provided, the `caller` would be used by the minter instead.
304
- - `params.subaccount`: An optional subaccount.
305
-
306
- Returns:
307
-
308
- The known utxos (with no guarantee in the ordering).
309
-
310
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/minter.canister.ts#L266)
311
-
312
- ### :factory: BitcoinCanister
313
-
314
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/bitcoin.canister.ts#L17)
315
-
316
- #### Static Methods
317
-
318
- - [create](#gear-create)
319
-
320
- ##### :gear: create
321
-
322
- | Method | Type |
323
- | -------- | -------------------------------------------------------------- |
324
- | `create` | `(options: CkBTCCanisterOptions<_SERVICE>) => BitcoinCanister` |
325
-
326
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/bitcoin.canister.ts#L18)
327
-
328
- #### Methods
329
-
330
- - [getUtxosQuery](#gear-getutxosquery)
331
- - [getBalanceQuery](#gear-getbalancequery)
332
-
333
- ##### :gear: getUtxosQuery
334
-
335
- Given a `get_utxos_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns all unspent transaction outputs (UTXOs) associated with the provided address in the specified Bitcoin network based on the current view of the Bitcoin blockchain available to the Bitcoin component.
336
-
337
- ⚠️ Note that this method does not support certified calls because only canisters are allowed to get UTXOs via update calls.
338
-
339
- | Method | Type |
340
- | --------------- | ---------------------------------------------------------------- |
341
- | `getUtxosQuery` | `({ ...params }: GetUtxosParams) => Promise<get_utxos_response>` |
342
-
343
- Parameters:
344
-
345
- - `params.network`: Tesnet or mainnet.
346
- - `params.filter`: The optional filter parameter can be used to restrict the set of returned UTXOs, either providing a minimum number of confirmations or a page reference when pagination is used for addresses with many UTXOs.
347
- - `params.address`: A Bitcoin address.
348
-
349
- Returns:
350
-
351
- The UTXOs are returned sorted by block height in descending order.
352
-
353
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/bitcoin.canister.ts#L42)
354
-
355
- ##### :gear: getBalanceQuery
356
-
357
- Given a `get_balance_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns the current balance of this address in `Satoshi` (10^8 Satoshi = 1 Bitcoin) in the specified Bitcoin network.
358
-
359
- ⚠️ Note that this method does not support certified calls because only canisters are allowed to get Bitcoin balance via update calls.
360
-
361
- | Method | Type |
362
- | ----------------- | ------------------------------------------------------ |
363
- | `getBalanceQuery` | `({ ...params }: GetBalanceParams) => Promise<bigint>` |
364
-
365
- Parameters:
366
-
367
- - `params.network`: Tesnet or mainnet.
368
- - `params.min_confirmations`: The optional filter parameter can be used to limit the set of considered UTXOs for the calculation of the balance to those with at least the provided number of confirmations in the same manner as for the `bitcoin_get_utxos` call.
369
- - `params.address`: A Bitcoin address.
370
-
371
- Returns:
372
-
373
- The balance is returned in `Satoshi` (10^8 Satoshi = 1 Bitcoin).
374
-
375
- [:link: Source](https://github.com/dfinity/icp-js-canisters/tree/main/packages/ckbtc/src/bitcoin.canister.ts#L64)
51
+ ## Documentation
376
52
 
377
- <!-- TSDOC_END -->
53
+ You can find the API docs [here](https://js.icp.build/canisters/latest/api/ckbtc/).
378
54
 
379
55
  ## Resources
380
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/ckbtc",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "A library for interfacing with ckBTC.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",