@dfinity/ckbtc 0.0.2-next-2023-03-21 → 0.0.2-next-2023-03-22

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/README.md CHANGED
@@ -96,9 +96,9 @@ Notify the minter about the bitcoin transfer.
96
96
 
97
97
  Upon successful notification, new ckBTC should be available on the targeted address.
98
98
 
99
- | Method | Type |
100
- | --------------- | ------------------------------------------------------------------------ |
101
- | `updateBalance` | `({ owner, subaccount, }: MinterParams) => Promise<UpdateBalanceResult>` |
99
+ | Method | Type |
100
+ | --------------- | -------------------------------------------------------------------- |
101
+ | `updateBalance` | `({ owner, subaccount, }: MinterParams) => Promise<UpdateBalanceOk>` |
102
102
 
103
103
  Parameters:
104
104
 
@@ -6,12 +6,19 @@ export const idlFactory = ({ IDL }) => {
6
6
  'ReadOnly' : IDL.Null,
7
7
  'GeneralAvailability' : IDL.Null,
8
8
  });
9
+ const UpgradeArgs = IDL.Record({
10
+ 'mode' : IDL.Opt(Mode),
11
+ 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
12
+ 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
13
+ 'min_confirmations' : IDL.Opt(IDL.Nat32),
14
+ });
9
15
  const BtcNetwork = IDL.Variant({
10
16
  'Mainnet' : IDL.Null,
11
17
  'Regtest' : IDL.Null,
12
18
  'Testnet' : IDL.Null,
13
19
  });
14
20
  const InitArgs = IDL.Record({
21
+ 'kyt_principal' : IDL.Opt(IDL.Principal),
15
22
  'ecdsa_key_name' : IDL.Text,
16
23
  'mode' : Mode,
17
24
  'retrieve_btc_min_amount' : IDL.Nat64,
@@ -20,6 +27,10 @@ export const idlFactory = ({ IDL }) => {
20
27
  'btc_network' : BtcNetwork,
21
28
  'min_confirmations' : IDL.Opt(IDL.Nat32),
22
29
  });
30
+ const MinterArg = IDL.Variant({
31
+ 'Upgrade' : IDL.Opt(UpgradeArgs),
32
+ 'Init' : InitArgs,
33
+ });
23
34
  const Account = IDL.Record({
24
35
  'owner' : IDL.Principal,
25
36
  'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
@@ -29,12 +40,6 @@ export const idlFactory = ({ IDL }) => {
29
40
  'value' : IDL.Nat64,
30
41
  'outpoint' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8), 'vout' : IDL.Nat32 }),
31
42
  });
32
- const UpgradeArgs = IDL.Record({
33
- 'mode' : IDL.Opt(Mode),
34
- 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
35
- 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
36
- 'min_confirmations' : IDL.Opt(IDL.Nat32),
37
- });
38
43
  const BitcoinAddress = IDL.Variant({
39
44
  'p2sh' : IDL.Vec(IDL.Nat8),
40
45
  'p2wpkh_v0' : IDL.Vec(IDL.Nat8),
@@ -62,8 +67,14 @@ export const idlFactory = ({ IDL }) => {
62
67
  'address' : BitcoinAddress,
63
68
  'amount' : IDL.Nat64,
64
69
  }),
70
+ 'checked_utxo' : IDL.Record({
71
+ 'clean' : IDL.Bool,
72
+ 'utxo' : Utxo,
73
+ 'uuid' : IDL.Text,
74
+ }),
65
75
  'removed_retrieve_btc_request' : IDL.Record({ 'block_index' : IDL.Nat64 }),
66
76
  'confirmed_transaction' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
77
+ 'ignored_utxo' : IDL.Record({ 'utxo' : Utxo }),
67
78
  });
68
79
  const RetrieveBtcArgs = IDL.Record({
69
80
  'address' : IDL.Text,
@@ -90,9 +101,15 @@ export const idlFactory = ({ IDL }) => {
90
101
  'Submitted' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
91
102
  'Pending' : IDL.Null,
92
103
  });
93
- const UpdateBalanceResult = IDL.Record({
94
- 'block_index' : IDL.Nat64,
95
- 'amount' : IDL.Nat64,
104
+ const UtxoStatus = IDL.Variant({
105
+ 'ValueTooSmall' : Utxo,
106
+ 'Tainted' : Utxo,
107
+ 'Minted' : IDL.Record({
108
+ 'minted_amount' : IDL.Nat64,
109
+ 'block_index' : IDL.Nat64,
110
+ 'utxo' : Utxo,
111
+ }),
112
+ 'Checked' : Utxo,
96
113
  });
97
114
  const UpdateBalanceError = IDL.Variant({
98
115
  'GenericError' : IDL.Record({
@@ -147,7 +164,7 @@ export const idlFactory = ({ IDL }) => {
147
164
  ],
148
165
  [
149
166
  IDL.Variant({
150
- 'Ok' : UpdateBalanceResult,
167
+ 'Ok' : IDL.Vec(UtxoStatus),
151
168
  'Err' : UpdateBalanceError,
152
169
  }),
153
170
  ],
@@ -162,12 +179,19 @@ export const init = ({ IDL }) => {
162
179
  'ReadOnly' : IDL.Null,
163
180
  'GeneralAvailability' : IDL.Null,
164
181
  });
182
+ const UpgradeArgs = IDL.Record({
183
+ 'mode' : IDL.Opt(Mode),
184
+ 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
185
+ 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
186
+ 'min_confirmations' : IDL.Opt(IDL.Nat32),
187
+ });
165
188
  const BtcNetwork = IDL.Variant({
166
189
  'Mainnet' : IDL.Null,
167
190
  'Regtest' : IDL.Null,
168
191
  'Testnet' : IDL.Null,
169
192
  });
170
193
  const InitArgs = IDL.Record({
194
+ 'kyt_principal' : IDL.Opt(IDL.Principal),
171
195
  'ecdsa_key_name' : IDL.Text,
172
196
  'mode' : Mode,
173
197
  'retrieve_btc_min_amount' : IDL.Nat64,
@@ -176,5 +200,9 @@ export const init = ({ IDL }) => {
176
200
  'btc_network' : BtcNetwork,
177
201
  'min_confirmations' : IDL.Opt(IDL.Nat32),
178
202
  });
179
- return [InitArgs];
203
+ const MinterArg = IDL.Variant({
204
+ 'Upgrade' : IDL.Opt(UpgradeArgs),
205
+ 'Init' : InitArgs,
206
+ });
207
+ return [MinterArg];
180
208
  };
@@ -36,9 +36,12 @@ export type Event =
36
36
  amount: bigint;
37
37
  };
38
38
  }
39
+ | { checked_utxo: { clean: boolean; utxo: Utxo; uuid: string } }
39
40
  | { removed_retrieve_btc_request: { block_index: bigint } }
40
- | { confirmed_transaction: { txid: Uint8Array } };
41
+ | { confirmed_transaction: { txid: Uint8Array } }
42
+ | { ignored_utxo: { utxo: Utxo } };
41
43
  export interface InitArgs {
44
+ kyt_principal: [] | [Principal];
42
45
  ecdsa_key_name: string;
43
46
  mode: Mode;
44
47
  retrieve_btc_min_amount: bigint;
@@ -47,6 +50,7 @@ export interface InitArgs {
47
50
  btc_network: BtcNetwork;
48
51
  min_confirmations: [] | [number];
49
52
  }
53
+ export type MinterArg = { Upgrade: [] | [UpgradeArgs] } | { Init: InitArgs };
50
54
  export type Mode =
51
55
  | { RestrictedTo: Array<Principal> }
52
56
  | { DepositsRestrictedTo: Array<Principal> }
@@ -86,10 +90,6 @@ export type UpdateBalanceError =
86
90
  current_confirmations: [] | [number];
87
91
  };
88
92
  };
89
- export interface UpdateBalanceResult {
90
- block_index: bigint;
91
- amount: bigint;
92
- }
93
93
  export interface UpgradeArgs {
94
94
  mode: [] | [Mode];
95
95
  retrieve_btc_min_amount: [] | [bigint];
@@ -101,6 +101,17 @@ export interface Utxo {
101
101
  value: bigint;
102
102
  outpoint: { txid: Uint8Array; vout: number };
103
103
  }
104
+ export type UtxoStatus =
105
+ | { ValueTooSmall: Utxo }
106
+ | { Tainted: Utxo }
107
+ | {
108
+ Minted: {
109
+ minted_amount: bigint;
110
+ block_index: bigint;
111
+ utxo: Utxo;
112
+ };
113
+ }
114
+ | { Checked: Utxo };
104
115
  export interface _SERVICE {
105
116
  estimate_fee: ActorMethod<[{ amount: [] | [bigint] }], bigint>;
106
117
  get_btc_address: ActorMethod<
@@ -119,6 +130,6 @@ export interface _SERVICE {
119
130
  >;
120
131
  update_balance: ActorMethod<
121
132
  [{ owner: [] | [Principal]; subaccount: [] | [Uint8Array] }],
122
- { Ok: UpdateBalanceResult } | { Err: UpdateBalanceError }
133
+ { Ok: Array<UtxoStatus> } | { Err: UpdateBalanceError }
123
134
  >;
124
135
  }
@@ -1,4 +1,4 @@
1
- // Generated from IC repo commit 87eb51bc9aab91fb17a2b4d60ee7b719dba117dc 'rs/bitcoin/ckbtc/minter/ckbtc_minter.did' by import-candid
1
+ // Generated from IC repo commit cd8058402b0f65c9fd502f9bb19dff114592ff03 'rs/bitcoin/ckbtc/minter/ckbtc_minter.did' by import-candid
2
2
  // Represents an account on the ckBTC ledger.
3
3
  type Account = record { owner : principal; subaccount : opt blob };
4
4
 
@@ -38,11 +38,24 @@ type RetrieveBtcOk = record {
38
38
  };
39
39
 
40
40
  // The result of an [update_balance] call.
41
- type UpdateBalanceResult = record {
42
- // Returns the identifier of the mint transaction on the ckBTC ledger.
43
- block_index : nat64;
44
- // Returns the amount of newly minted ckBTC tokens.
45
- amount : nat64;
41
+ type UtxoStatus = variant {
42
+ // The minter ignored this UTXO because UTXO's value is too small to pay
43
+ // the KYT fees. This state is final, retrying [update_balance] call will
44
+ // have no effect on this UTXO.
45
+ ValueTooSmall : Utxo;
46
+ // The KYT provider considered this UTXO to be tained. This UTXO state is
47
+ // final, retrying [update_balance] call will have no effect on this UTXO.
48
+ Tainted : Utxo;
49
+ // The UTXO passed the KYT check, but the minter failed to mint ckBTC
50
+ // because the Ledger was unavailable. Retrying the [update_balance] call
51
+ // should eventually advance the UTXO to the [Minted] state.
52
+ Checked : Utxo;
53
+ // The UTXO passed the KYT check, and ckBTC has been minted.
54
+ Minted : record {
55
+ block_index : nat64;
56
+ minted_amount : nat64;
57
+ utxo : Utxo;
58
+ };
46
59
  };
47
60
 
48
61
  type UpdateBalanceError = variant {
@@ -107,6 +120,9 @@ type InitArgs = record {
107
120
 
108
121
  /// The minter's operation mode.
109
122
  mode : Mode;
123
+
124
+ /// The canister id of the KYT canister.
125
+ kyt_principal: opt principal;
110
126
  };
111
127
 
112
128
  // The upgrade parameters of the minter canister.
@@ -158,7 +174,7 @@ type RetrieveBtcStatus = variant {
158
174
  };
159
175
 
160
176
  type Utxo = record {
161
- outpoint : record { txid : blob; vout : nat32 };
177
+ outpoint : record { txid : vec nat8; vout : nat32 };
162
178
  value : nat64;
163
179
  height : nat32;
164
180
  };
@@ -188,9 +204,20 @@ type Event = variant {
188
204
  submitted_at : nat64;
189
205
  };
190
206
  confirmed_transaction : record { txid : blob };
207
+ checked_utxo : record {
208
+ utxo : Utxo;
209
+ uuid : text;
210
+ clean : bool;
211
+ };
212
+ ignored_utxo : record { utxo: Utxo; };
191
213
  };
192
214
 
193
- service : (InitArgs) -> {
215
+ type MinterArg = variant {
216
+ Init : InitArgs;
217
+ Upgrade : opt UpgradeArgs;
218
+ }
219
+
220
+ service : (minter_arg : MinterArg) -> {
194
221
  // Section "Convert BTC to ckBTC" {{{
195
222
 
196
223
  // Returns the bitcoin address to which the owner should send BTC
@@ -208,14 +235,14 @@ service : (InitArgs) -> {
208
235
  //
209
236
  // * The owner deposited some BTC to the address that the
210
237
  // [get_btc_address] endpoint returns.
211
- update_balance : (record { owner: opt principal; subaccount : opt blob }) -> (variant { Ok : UpdateBalanceResult; Err : UpdateBalanceError });
238
+ update_balance : (record { owner: opt principal; subaccount : opt blob }) -> (variant { Ok : vec UtxoStatus; Err : UpdateBalanceError });
212
239
 
213
240
  // }}} Section "Convert BTC to ckBTC"
214
241
 
215
242
  // Section "Convert ckBTC to BTC" {{{
216
243
 
217
- /// Returns an estimation of the user's fee (in Satoshi) for a
218
- /// retrive_btc request based on the current status of the Bitcoin network.
244
+ /// Returns an estimate of the user's fee (in Satoshi) for a
245
+ /// retrieve_btc request based on the current status of the Bitcoin network.
219
246
  estimate_fee : (record { amount : opt nat64 }) -> (nat64) query;
220
247
 
221
248
  // Returns the account to which the caller should deposit ckBTC
@@ -6,12 +6,19 @@ export const idlFactory = ({ IDL }) => {
6
6
  'ReadOnly' : IDL.Null,
7
7
  'GeneralAvailability' : IDL.Null,
8
8
  });
9
+ const UpgradeArgs = IDL.Record({
10
+ 'mode' : IDL.Opt(Mode),
11
+ 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
12
+ 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
13
+ 'min_confirmations' : IDL.Opt(IDL.Nat32),
14
+ });
9
15
  const BtcNetwork = IDL.Variant({
10
16
  'Mainnet' : IDL.Null,
11
17
  'Regtest' : IDL.Null,
12
18
  'Testnet' : IDL.Null,
13
19
  });
14
20
  const InitArgs = IDL.Record({
21
+ 'kyt_principal' : IDL.Opt(IDL.Principal),
15
22
  'ecdsa_key_name' : IDL.Text,
16
23
  'mode' : Mode,
17
24
  'retrieve_btc_min_amount' : IDL.Nat64,
@@ -20,6 +27,10 @@ export const idlFactory = ({ IDL }) => {
20
27
  'btc_network' : BtcNetwork,
21
28
  'min_confirmations' : IDL.Opt(IDL.Nat32),
22
29
  });
30
+ const MinterArg = IDL.Variant({
31
+ 'Upgrade' : IDL.Opt(UpgradeArgs),
32
+ 'Init' : InitArgs,
33
+ });
23
34
  const Account = IDL.Record({
24
35
  'owner' : IDL.Principal,
25
36
  'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
@@ -29,12 +40,6 @@ export const idlFactory = ({ IDL }) => {
29
40
  'value' : IDL.Nat64,
30
41
  'outpoint' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8), 'vout' : IDL.Nat32 }),
31
42
  });
32
- const UpgradeArgs = IDL.Record({
33
- 'mode' : IDL.Opt(Mode),
34
- 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
35
- 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
36
- 'min_confirmations' : IDL.Opt(IDL.Nat32),
37
- });
38
43
  const BitcoinAddress = IDL.Variant({
39
44
  'p2sh' : IDL.Vec(IDL.Nat8),
40
45
  'p2wpkh_v0' : IDL.Vec(IDL.Nat8),
@@ -62,8 +67,14 @@ export const idlFactory = ({ IDL }) => {
62
67
  'address' : BitcoinAddress,
63
68
  'amount' : IDL.Nat64,
64
69
  }),
70
+ 'checked_utxo' : IDL.Record({
71
+ 'clean' : IDL.Bool,
72
+ 'utxo' : Utxo,
73
+ 'uuid' : IDL.Text,
74
+ }),
65
75
  'removed_retrieve_btc_request' : IDL.Record({ 'block_index' : IDL.Nat64 }),
66
76
  'confirmed_transaction' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
77
+ 'ignored_utxo' : IDL.Record({ 'utxo' : Utxo }),
67
78
  });
68
79
  const RetrieveBtcArgs = IDL.Record({
69
80
  'address' : IDL.Text,
@@ -90,9 +101,15 @@ export const idlFactory = ({ IDL }) => {
90
101
  'Submitted' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
91
102
  'Pending' : IDL.Null,
92
103
  });
93
- const UpdateBalanceResult = IDL.Record({
94
- 'block_index' : IDL.Nat64,
95
- 'amount' : IDL.Nat64,
104
+ const UtxoStatus = IDL.Variant({
105
+ 'ValueTooSmall' : Utxo,
106
+ 'Tainted' : Utxo,
107
+ 'Minted' : IDL.Record({
108
+ 'minted_amount' : IDL.Nat64,
109
+ 'block_index' : IDL.Nat64,
110
+ 'utxo' : Utxo,
111
+ }),
112
+ 'Checked' : Utxo,
96
113
  });
97
114
  const UpdateBalanceError = IDL.Variant({
98
115
  'GenericError' : IDL.Record({
@@ -147,7 +164,7 @@ export const idlFactory = ({ IDL }) => {
147
164
  ],
148
165
  [
149
166
  IDL.Variant({
150
- 'Ok' : UpdateBalanceResult,
167
+ 'Ok' : IDL.Vec(UtxoStatus),
151
168
  'Err' : UpdateBalanceError,
152
169
  }),
153
170
  ],
@@ -162,12 +179,19 @@ export const init = ({ IDL }) => {
162
179
  'ReadOnly' : IDL.Null,
163
180
  'GeneralAvailability' : IDL.Null,
164
181
  });
182
+ const UpgradeArgs = IDL.Record({
183
+ 'mode' : IDL.Opt(Mode),
184
+ 'retrieve_btc_min_amount' : IDL.Opt(IDL.Nat64),
185
+ 'max_time_in_queue_nanos' : IDL.Opt(IDL.Nat64),
186
+ 'min_confirmations' : IDL.Opt(IDL.Nat32),
187
+ });
165
188
  const BtcNetwork = IDL.Variant({
166
189
  'Mainnet' : IDL.Null,
167
190
  'Regtest' : IDL.Null,
168
191
  'Testnet' : IDL.Null,
169
192
  });
170
193
  const InitArgs = IDL.Record({
194
+ 'kyt_principal' : IDL.Opt(IDL.Principal),
171
195
  'ecdsa_key_name' : IDL.Text,
172
196
  'mode' : Mode,
173
197
  'retrieve_btc_min_amount' : IDL.Nat64,
@@ -176,5 +200,9 @@ export const init = ({ IDL }) => {
176
200
  'btc_network' : BtcNetwork,
177
201
  'min_confirmations' : IDL.Opt(IDL.Nat32),
178
202
  });
179
- return [InitArgs];
203
+ const MinterArg = IDL.Variant({
204
+ 'Upgrade' : IDL.Opt(UpgradeArgs),
205
+ 'Init' : InitArgs,
206
+ });
207
+ return [MinterArg];
180
208
  };
@@ -1,4 +1,4 @@
1
- "use strict";var Se=Object.create;var P=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var F=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ce=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ee(t))!ye.call(e,i)&&i!==n&&P(e,i,{get:()=>t[i],enumerable:!(r=we(t,i))||r.enumerable});return e};var $=(e,t,n)=>(n=e!=null?Se(ve(e)):{},ae(t||!e||!e.__esModule?P(n,"default",{value:e,enumerable:!0}):n,e)),ge=e=>ae(P({},"__esModule",{value:!0}),e);var J=F((it,ce)=>{"use strict";var Oe="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";ce.exports=Oe});var de=F((st,he)=>{"use strict";var Be=J(),Te=e=>{if(!e||typeof e!="string")throw new Error(`Expected base58 string but got \u201C${e}\u201D`);if(e.match(/[IOl0]/gmu))throw new Error(`Invalid base58 character \u201C${e.match(/[IOl0]/gmu)}\u201D`);let t=e.match(/^1+/gmu),n=t?t[0].length:0,r=(e.length-n)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(n),...e.match(/.{1}/gmu).map(i=>Be.indexOf(i)).reduce((i,o)=>(i=i.map(s=>{let a=s*58+o;return o=a>>8,a}),i),new Uint8Array(r)).reverse().filter((i=>o=>i=i||o)(!1))])};he.exports=Te});var fe=F((ct,le)=>{"use strict";var ue=J(),ke=()=>{let e=Array(256).fill(-1);for(let t=0;t<ue.length;++t)e[ue.charCodeAt(t)]=t;return e};le.exports=ke});var _e=F((ht,pe)=>{"use strict";var xe=J(),Ve=fe(),Xe=Ve(),Pe=e=>{let t=[];for(let n of e){let r=n;for(let i=0;i<t.length;++i){let o=(Xe[t[i]]<<8)+r;t[i]=xe.charCodeAt(o%58),r=o/58|0}for(;r;)t.push(xe.charCodeAt(r%58)),r=r/58|0}for(let n of e){if(n)break;t.push("1".charCodeAt(0))}return t.reverse(),String.fromCharCode(...t)};pe.exports=Pe});var Re=F(ee=>{"use strict";ee.base58_to_binary=de();ee.binary_to_base58=_e()});var Fe=F(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.bech32m=y.bech32=void 0;var j="qpzry9x8gf2tvdw0s3jn54khce6mua7l",be={};for(let e=0;e<j.length;e++){let t=j.charAt(e);be[t]=e}function v(e){let t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function me(e){let t=1;for(let n=0;n<e.length;++n){let r=e.charCodeAt(n);if(r<33||r>126)return"Invalid prefix ("+e+")";t=v(t)^r>>5}t=v(t);for(let n=0;n<e.length;++n){let r=e.charCodeAt(n);t=v(t)^r&31}return t}function te(e,t,n,r){let i=0,o=0,s=(1<<n)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],o+=t;o>=n;)o-=n,a.push(i>>o&s);if(r)o>0&&a.push(i<<n-o&s);else{if(o>=t)return"Excess padding";if(i<<n-o&s)return"Non-zero padding"}return a}function Ue(e){return te(e,8,5,!0)}function Me(e){let t=te(e,5,8,!1);if(Array.isArray(t))return t}function qe(e){let t=te(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Ae(e){let t;e==="bech32"?t=1:t=734539939;function n(s,a,c){if(c=c||90,s.length+7+a.length>c)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let d=me(s);if(typeof d=="string")throw new Error(d);let u=s+"1";for(let l=0;l<a.length;++l){let f=a[l];if(f>>5)throw new Error("Non 5-bit word");d=v(d)^f,u+=j.charAt(f)}for(let l=0;l<6;++l)d=v(d);d^=t;for(let l=0;l<6;++l){let f=d>>(5-l)*5&31;u+=j.charAt(f)}return u}function r(s,a){if(a=a||90,s.length<8)return s+" too short";if(s.length>a)return"Exceeds length limit";let c=s.toLowerCase(),d=s.toUpperCase();if(s!==c&&s!==d)return"Mixed-case string "+s;s=c;let u=s.lastIndexOf("1");if(u===-1)return"No separator character for "+s;if(u===0)return"Missing prefix for "+s;let l=s.slice(0,u),f=s.slice(u+1);if(f.length<6)return"Data too short";let h=me(l);if(typeof h=="string")return h;let x=[];for(let p=0;p<f.length;++p){let R=f.charAt(p),b=be[R];if(b===void 0)return"Unknown character "+R;h=v(h)^b,!(p+6>=f.length)&&x.push(b)}return h!==t?"Invalid checksum for "+s:{prefix:l,words:x}}function i(s,a){let c=r(s,a);if(typeof c=="object")return c}function o(s,a){let c=r(s,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:o,encode:n,toWords:Ue,fromWordsUnsafe:Me,fromWords:qe}}y.bech32=Ae("bech32");y.bech32m=Ae("bech32m")});var Ne=F((exports,module)=>{(function(){"use strict";var ERROR="input is invalid type",WINDOW=typeof window=="object",root=WINDOW?window:{};root.JS_SHA256_NO_WINDOW&&(WINDOW=!1);var WEB_WORKER=!WINDOW&&typeof self=="object",NODE_JS=!root.JS_SHA256_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;NODE_JS?root=global:WEB_WORKER&&(root=self);var COMMON_JS=!root.JS_SHA256_NO_COMMON_JS&&typeof module=="object"&&module.exports,AMD=typeof define=="function"&&define.amd,ARRAY_BUFFER=!root.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",HEX_CHARS="0123456789abcdef".split(""),EXTRA=[-2147483648,8388608,32768,128],SHIFT=[24,16,8,0],K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],OUTPUT_TYPES=["hex","array","digest","arrayBuffer"],blocks=[];(root.JS_SHA256_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}),ARRAY_BUFFER&&(root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer});var createOutputMethod=function(e,t){return function(n){return new Sha256(t,!0).update(n)[e]()}},createMethod=function(e){var t=createOutputMethod("hex",e);NODE_JS&&(t=nodeWrap(t,e)),t.create=function(){return new Sha256(e)},t.update=function(i){return t.create().update(i)};for(var n=0;n<OUTPUT_TYPES.length;++n){var r=OUTPUT_TYPES[n];t[r]=createOutputMethod(r,e)}return t},nodeWrap=function(method,is224){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),algorithm=is224?"sha224":"sha256",nodeMethod=function(e){if(typeof e=="string")return crypto.createHash(algorithm).update(e,"utf8").digest("hex");if(e==null)throw new Error(ERROR);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer?crypto.createHash(algorithm).update(new Buffer(e)).digest("hex"):method(e)};return nodeMethod},createHmacOutputMethod=function(e,t){return function(n,r){return new HmacSha256(n,t,!0).update(r)[e]()}},createHmacMethod=function(e){var t=createHmacOutputMethod("hex",e);t.create=function(i){return new HmacSha256(i,e)},t.update=function(i,o){return t.create(i).update(o)};for(var n=0;n<OUTPUT_TYPES.length;++n){var r=OUTPUT_TYPES[n];t[r]=createHmacOutputMethod(r,e)}return t};function Sha256(e,t){t?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=e}Sha256.prototype.update=function(e){if(!this.finalized){var t,n=typeof e;if(n!=="string"){if(n==="object"){if(e===null)throw new Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw new Error(ERROR)}else throw new Error(ERROR);t=!0}for(var r,i=0,o,s=e.length,a=this.blocks;i<s;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)for(o=this.start;i<s&&o<64;++i)a[o>>2]|=e[i]<<SHIFT[o++&3];else for(o=this.start;i<s&&o<64;++i)r=e.charCodeAt(i),r<128?a[o>>2]|=r<<SHIFT[o++&3]:r<2048?(a[o>>2]|=(192|r>>6)<<SHIFT[o++&3],a[o>>2]|=(128|r&63)<<SHIFT[o++&3]):r<55296||r>=57344?(a[o>>2]|=(224|r>>12)<<SHIFT[o++&3],a[o>>2]|=(128|r>>6&63)<<SHIFT[o++&3],a[o>>2]|=(128|r&63)<<SHIFT[o++&3]):(r=65536+((r&1023)<<10|e.charCodeAt(++i)&1023),a[o>>2]|=(240|r>>18)<<SHIFT[o++&3],a[o>>2]|=(128|r>>12&63)<<SHIFT[o++&3],a[o>>2]|=(128|r>>6&63)<<SHIFT[o++&3],a[o>>2]|=(128|r&63)<<SHIFT[o++&3]);this.lastByteIndex=o,this.bytes+=o-this.start,o>=64?(this.block=a[16],this.start=o-64,this.hash(),this.hashed=!0):this.start=o}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Sha256.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>2]|=EXTRA[t&3],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},Sha256.prototype.hash=function(){var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,o=this.h5,s=this.h6,a=this.h7,c=this.blocks,d,u,l,f,h,x,p,R,b,Y,X;for(d=16;d<64;++d)h=c[d-15],u=(h>>>7|h<<25)^(h>>>18|h<<14)^h>>>3,h=c[d-2],l=(h>>>17|h<<15)^(h>>>19|h<<13)^h>>>10,c[d]=c[d-16]+u+c[d-7]+l<<0;for(X=t&n,d=0;d<64;d+=4)this.first?(this.is224?(R=300032,h=c[0]-1413257819,a=h-150054599<<0,r=h+24177077<<0):(R=704751109,h=c[0]-210244248,a=h-1521486534<<0,r=h+143694565<<0),this.first=!1):(u=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),l=(i>>>6|i<<26)^(i>>>11|i<<21)^(i>>>25|i<<7),R=e&t,f=R^e&n^X,p=i&o^~i&s,h=a+l+p+K[d]+c[d],x=u+f,a=r+h<<0,r=h+x<<0),u=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),l=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),b=r&e,f=b^r&t^R,p=a&i^~a&o,h=s+l+p+K[d+1]+c[d+1],x=u+f,s=n+h<<0,n=h+x<<0,u=(n>>>2|n<<30)^(n>>>13|n<<19)^(n>>>22|n<<10),l=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7),Y=n&r,f=Y^n&e^b,p=s&a^~s&i,h=o+l+p+K[d+2]+c[d+2],x=u+f,o=t+h<<0,t=h+x<<0,u=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),l=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),X=t&n,f=X^t&r^Y,p=o&s^~o&a,h=i+l+p+K[d+3]+c[d+3],x=u+f,i=e+h<<0,e=h+x<<0;this.h0=this.h0+e<<0,this.h1=this.h1+t<<0,this.h2=this.h2+n<<0,this.h3=this.h3+r<<0,this.h4=this.h4+i<<0,this.h5=this.h5+o<<0,this.h6=this.h6+s<<0,this.h7=this.h7+a<<0},Sha256.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,o=this.h5,s=this.h6,a=this.h7,c=HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[e&15]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[t&15]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[n&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[r&15]+HEX_CHARS[i>>28&15]+HEX_CHARS[i>>24&15]+HEX_CHARS[i>>20&15]+HEX_CHARS[i>>16&15]+HEX_CHARS[i>>12&15]+HEX_CHARS[i>>8&15]+HEX_CHARS[i>>4&15]+HEX_CHARS[i&15]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[o&15]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[s&15];return this.is224||(c+=HEX_CHARS[a>>28&15]+HEX_CHARS[a>>24&15]+HEX_CHARS[a>>20&15]+HEX_CHARS[a>>16&15]+HEX_CHARS[a>>12&15]+HEX_CHARS[a>>8&15]+HEX_CHARS[a>>4&15]+HEX_CHARS[a&15]),c},Sha256.prototype.toString=Sha256.prototype.hex,Sha256.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,o=this.h5,s=this.h6,a=this.h7,c=[e>>24&255,e>>16&255,e>>8&255,e&255,t>>24&255,t>>16&255,t>>8&255,t&255,n>>24&255,n>>16&255,n>>8&255,n&255,r>>24&255,r>>16&255,r>>8&255,r&255,i>>24&255,i>>16&255,i>>8&255,i&255,o>>24&255,o>>16&255,o>>8&255,o&255,s>>24&255,s>>16&255,s>>8&255,s&255];return this.is224||c.push(a>>24&255,a>>16&255,a>>8&255,a&255),c},Sha256.prototype.array=Sha256.prototype.digest,Sha256.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),t.setUint32(20,this.h5),t.setUint32(24,this.h6),this.is224||t.setUint32(28,this.h7),e};function HmacSha256(e,t,n){var r,i=typeof e;if(i==="string"){var o=[],s=e.length,a=0,c;for(r=0;r<s;++r)c=e.charCodeAt(r),c<128?o[a++]=c:c<2048?(o[a++]=192|c>>6,o[a++]=128|c&63):c<55296||c>=57344?(o[a++]=224|c>>12,o[a++]=128|c>>6&63,o[a++]=128|c&63):(c=65536+((c&1023)<<10|e.charCodeAt(++r)&1023),o[a++]=240|c>>18,o[a++]=128|c>>12&63,o[a++]=128|c>>6&63,o[a++]=128|c&63);e=o}else if(i==="object"){if(e===null)throw new Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw new Error(ERROR)}else throw new Error(ERROR);e.length>64&&(e=new Sha256(t,!0).update(e).array());var d=[],u=[];for(r=0;r<64;++r){var l=e[r]||0;d[r]=92^l,u[r]=54^l}Sha256.call(this,t,n),this.update(u),this.oKeyPad=d,this.inner=!0,this.sharedMemory=n}HmacSha256.prototype=new Sha256,HmacSha256.prototype.finalize=function(){if(Sha256.prototype.finalize.call(this),this.inner){this.inner=!1;var e=this.array();Sha256.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(e),Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports,exports.sha224=createMethod(!0),exports.sha256.hmac=createHmacMethod(),exports.sha224.hmac=createHmacMethod(!0),COMMON_JS?module.exports=exports:(root.sha256=exports.sha256,root.sha224=exports.sha224,AMD&&define(function(){return exports}))})()});var Qe={};Ce(Qe,{BtcAddressType:()=>Z,BtcNetwork:()=>Q,CkBTCMinterCanister:()=>E,MinterAlreadyProcessingError:()=>M,MinterAmountTooLowError:()=>z,MinterGenericError:()=>A,MinterInsufficientFundsError:()=>G,MinterMalformedAddressError:()=>W,MinterNoNewUtxosError:()=>q,MinterRetrieveBtcError:()=>H,MinterTemporaryUnavailableError:()=>U,MinterUpdateBalanceError:()=>k,ParseBtcAddressBadWitnessLengthError:()=>g,ParseBtcAddressError:()=>_,ParseBtcAddressInvalidError:()=>S,ParseBtcAddressMalformedAddressError:()=>N,ParseBtcAddressNoDataError:()=>C,ParseBtcAddressUnexpectedHumanReadablePartError:()=>B,ParseBtcAddressUnsupportedAddressTypeError:()=>w,ParseBtcAddressUnsupportedWitnessVersionError:()=>O,ParseBtcAddressWrongNetworkError:()=>T,createRetrieveBtcError:()=>L,createUpdateBalanceError:()=>D,parseBtcAddress:()=>$e});module.exports=ge(Qe);var Q=(r=>(r[r.Mainnet=0]="Mainnet",r[r.Regtest=1]="Regtest",r[r.Testnet=2]="Testnet",r))(Q||{}),Z=(r=>(r[r.P2wpkhV0=0]="P2wpkhV0",r[r.P2pkh=1]="P2pkh",r[r.P2sh=2]="P2sh",r))(Z||{});var _=class extends Error{},S=class extends _{},C=class extends _{},w=class extends _{},g=class extends _{},O=class extends _{},B=class extends _{},N=class extends _{},T=class extends _{};var I=require("@dfinity/utils"),A=class extends Error{},U=class extends A{},M=class extends A{},k=class extends A{},q=class extends k{},H=class extends A{},W=class extends H{},z=class extends H{},G=class extends H{},ne=e=>{if("GenericError"in e){let{GenericError:{error_message:t,error_code:n}}=e;return new A(`${t} (${n})`)}if("TemporarilyUnavailable"in e)return new U(e.TemporarilyUnavailable);if("AlreadyProcessing"in e)return new M},D=e=>{let t=ne(e);return(0,I.nonNullish)(t)?t:"NoNewUtxos"in e?new q:new k(`Unsupported response type in minter.updateBalance ${JSON.stringify(e)}`)},L=e=>{let t=ne(e);return(0,I.nonNullish)(t)?t:"MalformedAddress"in e?new W(e.MalformedAddress):"AmountTooLow"in e?new z(`${e.AmountTooLow}`):"InsufficientFunds"in e?new G(`${e.InsufficientFunds.balance}`):new H(`Unsupported response type in minter.retrieveBtc ${JSON.stringify(e)}`)};var m=require("@dfinity/utils");var ie=({IDL:e})=>{let t=e.Variant({RestrictedTo:e.Vec(e.Principal),DepositsRestrictedTo:e.Vec(e.Principal),ReadOnly:e.Null,GeneralAvailability:e.Null}),n=e.Variant({Mainnet:e.Null,Regtest:e.Null,Testnet:e.Null}),r=e.Record({ecdsa_key_name:e.Text,mode:t,retrieve_btc_min_amount:e.Nat64,ledger_id:e.Principal,max_time_in_queue_nanos:e.Nat64,btc_network:n,min_confirmations:e.Opt(e.Nat32)}),i=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),o=e.Record({height:e.Nat32,value:e.Nat64,outpoint:e.Record({txid:e.Vec(e.Nat8),vout:e.Nat32})}),s=e.Record({mode:e.Opt(t),retrieve_btc_min_amount:e.Opt(e.Nat64),max_time_in_queue_nanos:e.Opt(e.Nat64),min_confirmations:e.Opt(e.Nat32)}),a=e.Variant({p2sh:e.Vec(e.Nat8),p2wpkh_v0:e.Vec(e.Nat8),p2pkh:e.Vec(e.Nat8)}),c=e.Variant({received_utxos:e.Record({to_account:i,utxos:e.Vec(o)}),sent_transaction:e.Record({change_output:e.Opt(e.Record({value:e.Nat64,vout:e.Nat32})),txid:e.Vec(e.Nat8),utxos:e.Vec(o),requests:e.Vec(e.Nat64),submitted_at:e.Nat64}),init:r,upgrade:s,accepted_retrieve_btc_request:e.Record({received_at:e.Nat64,block_index:e.Nat64,address:a,amount:e.Nat64}),removed_retrieve_btc_request:e.Record({block_index:e.Nat64}),confirmed_transaction:e.Record({txid:e.Vec(e.Nat8)})}),d=e.Record({address:e.Text,amount:e.Nat64}),u=e.Record({block_index:e.Nat64}),l=e.Variant({MalformedAddress:e.Text,GenericError:e.Record({error_message:e.Text,error_code:e.Nat64}),TemporarilyUnavailable:e.Text,AlreadyProcessing:e.Null,AmountTooLow:e.Nat64,InsufficientFunds:e.Record({balance:e.Nat64})}),f=e.Variant({Signing:e.Null,Confirmed:e.Record({txid:e.Vec(e.Nat8)}),Sending:e.Record({txid:e.Vec(e.Nat8)}),AmountTooLow:e.Null,Unknown:e.Null,Submitted:e.Record({txid:e.Vec(e.Nat8)}),Pending:e.Null}),h=e.Record({block_index:e.Nat64,amount:e.Nat64}),x=e.Variant({GenericError:e.Record({error_message:e.Text,error_code:e.Nat64}),TemporarilyUnavailable:e.Text,AlreadyProcessing:e.Null,NoNewUtxos:e.Record({required_confirmations:e.Nat32,current_confirmations:e.Opt(e.Nat32)})});return e.Service({estimate_fee:e.Func([e.Record({amount:e.Opt(e.Nat64)})],[e.Nat64],[]),get_btc_address:e.Func([e.Record({owner:e.Opt(e.Principal),subaccount:e.Opt(e.Vec(e.Nat8))})],[e.Text],[]),get_events:e.Func([e.Record({start:e.Nat64,length:e.Nat64})],[e.Vec(c)],[]),get_withdrawal_account:e.Func([],[i],[]),retrieve_btc:e.Func([d],[e.Variant({Ok:u,Err:l})],[]),retrieve_btc_status:e.Func([e.Record({block_index:e.Nat64})],[f],[]),update_balance:e.Func([e.Record({owner:e.Opt(e.Principal),subaccount:e.Opt(e.Vec(e.Nat8))})],[e.Variant({Ok:h,Err:x})],[])})};var se=({IDL:e})=>{let t=e.Variant({RestrictedTo:e.Vec(e.Principal),DepositsRestrictedTo:e.Vec(e.Principal),ReadOnly:e.Null,GeneralAvailability:e.Null}),n=e.Variant({Mainnet:e.Null,Regtest:e.Null,Testnet:e.Null}),r=e.Record({ecdsa_key_name:e.Text,mode:t,retrieve_btc_min_amount:e.Nat64,ledger_id:e.Principal,max_time_in_queue_nanos:e.Nat64,btc_network:n,min_confirmations:e.Opt(e.Nat32)}),i=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),o=e.Record({height:e.Nat32,value:e.Nat64,outpoint:e.Record({txid:e.Vec(e.Nat8),vout:e.Nat32})}),s=e.Record({mode:e.Opt(t),retrieve_btc_min_amount:e.Opt(e.Nat64),max_time_in_queue_nanos:e.Opt(e.Nat64),min_confirmations:e.Opt(e.Nat32)}),a=e.Variant({p2sh:e.Vec(e.Nat8),p2wpkh_v0:e.Vec(e.Nat8),p2pkh:e.Vec(e.Nat8)}),c=e.Variant({received_utxos:e.Record({to_account:i,utxos:e.Vec(o)}),sent_transaction:e.Record({change_output:e.Opt(e.Record({value:e.Nat64,vout:e.Nat32})),txid:e.Vec(e.Nat8),utxos:e.Vec(o),requests:e.Vec(e.Nat64),submitted_at:e.Nat64}),init:r,upgrade:s,accepted_retrieve_btc_request:e.Record({received_at:e.Nat64,block_index:e.Nat64,address:a,amount:e.Nat64}),removed_retrieve_btc_request:e.Record({block_index:e.Nat64}),confirmed_transaction:e.Record({txid:e.Vec(e.Nat8)})}),d=e.Record({address:e.Text,amount:e.Nat64}),u=e.Record({block_index:e.Nat64}),l=e.Variant({MalformedAddress:e.Text,GenericError:e.Record({error_message:e.Text,error_code:e.Nat64}),TemporarilyUnavailable:e.Text,AlreadyProcessing:e.Null,AmountTooLow:e.Nat64,InsufficientFunds:e.Record({balance:e.Nat64})}),f=e.Variant({Signing:e.Null,Confirmed:e.Record({txid:e.Vec(e.Nat8)}),Sending:e.Record({txid:e.Vec(e.Nat8)}),AmountTooLow:e.Null,Unknown:e.Null,Submitted:e.Record({txid:e.Vec(e.Nat8)}),Pending:e.Null}),h=e.Record({block_index:e.Nat64,amount:e.Nat64}),x=e.Variant({GenericError:e.Record({error_message:e.Text,error_code:e.Nat64}),TemporarilyUnavailable:e.Text,AlreadyProcessing:e.Null,NoNewUtxos:e.Record({required_confirmations:e.Nat32,current_confirmations:e.Opt(e.Nat32)})});return e.Service({estimate_fee:e.Func([e.Record({amount:e.Opt(e.Nat64)})],[e.Nat64],["query"]),get_btc_address:e.Func([e.Record({owner:e.Opt(e.Principal),subaccount:e.Opt(e.Vec(e.Nat8))})],[e.Text],[]),get_events:e.Func([e.Record({start:e.Nat64,length:e.Nat64})],[e.Vec(c)],["query"]),get_withdrawal_account:e.Func([],[i],[]),retrieve_btc:e.Func([d],[e.Variant({Ok:u,Err:l})],[]),retrieve_btc_status:e.Func([e.Record({block_index:e.Nat64})],[f],["query"]),update_balance:e.Func([e.Record({owner:e.Opt(e.Principal),subaccount:e.Opt(e.Vec(e.Nat8))})],[e.Variant({Ok:h,Err:x})],[])})};var E=class extends m.Canister{constructor(){super(...arguments);this.getBtcAddress=({owner:n,subaccount:r})=>this.caller({certified:!0}).get_btc_address({owner:(0,m.toNullable)(n),subaccount:(0,m.toNullable)(r)});this.updateBalance=async({owner:n,subaccount:r})=>{let i=await this.caller({certified:!0}).update_balance({owner:(0,m.toNullable)(n),subaccount:(0,m.toNullable)(r)});if("Err"in i)throw D(i.Err);return i.Ok};this.getWithdrawalAccount=()=>this.caller({certified:!0}).get_withdrawal_account();this.retrieveBtc=async n=>{let r=await this.caller({certified:!0}).retrieve_btc(n);if("Err"in r)throw L(r.Err);return r.Ok};this.estimateFee=async({certified:n,amount:r})=>this.caller({certified:n}).estimate_fee({amount:(0,m.toNullable)(r)})}static create(n){let{service:r,certifiedService:i,canisterId:o}=(0,m.createServices)({options:n,idlFactory:se,certifiedIdlFactory:ie});return new E(o,r,i)}};var oe=require("@dfinity/utils"),He=$(Re()),V=$(Fe()),re=$(Ne());var We=0,ze=5,Ge=111,Je=196,je={[We]:{type:1,networks:[0]},[Ge]:{type:1,networks:[2,1]},[ze]:{type:2,networks:[0]},[Je]:{type:2,networks:[2,1]}},Ye=({address:e,network:t})=>{let r=(u=>{try{return(0,He.base58_to_binary)(u)}catch{throw new S}})(e),{length:i}=r;if(i!==25)throw new N(`Expected the address to be 25 bytes, got ${i}.`);(u=>{let l=u.slice(i-4,i),f=u.slice(0,i-4),h=re.sha256.create();h.update(f);let x=re.sha256.create();x.update(h.digest());let p=x.array().slice(0,4);if(l.some((R,b)=>R!==p[b]))throw new N(`Checksum mismatch expected ${l}, got ${p}.`)})(r);let s=r[0],a=je[s];if((0,oe.isNullish)(a))throw new w;let{type:c,networks:d}=a;if(!d.includes(t))throw new T;return{address:e,network:t,type:c,parser:"base58"}},Ke=({address:e,network:t})=>{let n=u=>{try{return u.startsWith("bc1p")||u.startsWith("tb1p")||u.startsWith("bcrt1p")?V.bech32m.decode(u):V.bech32.decode(u)}catch{throw new N}},{prefix:r,words:i}=n(e),s={bc:0,tb:2,bcrt:1}[r];if((0,oe.isNullish)(s))throw new S;if(s!==t)throw new B;let[a,...c]=i;if(a!==0)throw new O;if(V.bech32.fromWords(c).length!==20)throw new g;return{address:e,network:t,type:0,parser:"bip-173"}},$e=({address:e,network:t=0})=>{switch(e.charAt(0)){case"1":case"2":case"3":case"m":case"n":return Ye({address:e,network:t});case"b":case"B":case"t":case"T":return Ke({address:e,network:t});case"":throw new C;default:throw new w}};0&&(module.exports={BtcAddressType,BtcNetwork,CkBTCMinterCanister,MinterAlreadyProcessingError,MinterAmountTooLowError,MinterGenericError,MinterInsufficientFundsError,MinterMalformedAddressError,MinterNoNewUtxosError,MinterRetrieveBtcError,MinterTemporaryUnavailableError,MinterUpdateBalanceError,ParseBtcAddressBadWitnessLengthError,ParseBtcAddressError,ParseBtcAddressInvalidError,ParseBtcAddressMalformedAddressError,ParseBtcAddressNoDataError,ParseBtcAddressUnexpectedHumanReadablePartError,ParseBtcAddressUnsupportedAddressTypeError,ParseBtcAddressUnsupportedWitnessVersionError,ParseBtcAddressWrongNetworkError,createRetrieveBtcError,createUpdateBalanceError,parseBtcAddress});
1
+ "use strict";var St=Object.create;var U=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var Et=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,vt=Object.prototype.hasOwnProperty;var F=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),gt=(t,e)=>{for(var a in e)U(t,a,{get:e[a],enumerable:!0})},at=(t,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Et(e))!vt.call(t,i)&&i!==a&&U(t,i,{get:()=>e[i],enumerable:!(r=wt(e,i))||r.enumerable});return t};var $=(t,e,a)=>(a=t!=null?St(yt(t)):{},at(e||!t||!t.__esModule?U(a,"default",{value:t,enumerable:!0}):a,t)),Ot=t=>at(U({},"__esModule",{value:!0}),t);var J=F((ie,st)=>{"use strict";var Ct="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";st.exports=Ct});var dt=F((ce,ht)=>{"use strict";var Tt=J(),kt=t=>{if(!t||typeof t!="string")throw new Error(`Expected base58 string but got \u201C${t}\u201D`);if(t.match(/[IOl0]/gmu))throw new Error(`Invalid base58 character \u201C${t.match(/[IOl0]/gmu)}\u201D`);let e=t.match(/^1+/gmu),a=e?e[0].length:0,r=(t.length-a)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(a),...t.match(/.{1}/gmu).map(i=>Tt.indexOf(i)).reduce((i,n)=>(i=i.map(c=>{let o=c*58+n;return n=o>>8,o}),i),new Uint8Array(r)).reverse().filter((i=>n=>i=i||n)(!1))])};ht.exports=kt});var ft=F((se,lt)=>{"use strict";var ut=J(),Bt=()=>{let t=Array(256).fill(-1);for(let e=0;e<ut.length;++e)t[ut.charCodeAt(e)]=e;return t};lt.exports=Bt});var _t=F((he,pt)=>{"use strict";var xt=J(),Vt=ft(),Pt=Vt(),Ut=t=>{let e=[];for(let a of t){let r=a;for(let i=0;i<e.length;++i){let n=(Pt[e[i]]<<8)+r;e[i]=xt.charCodeAt(n%58),r=n/58|0}for(;r;)e.push(xt.charCodeAt(r%58)),r=r/58|0}for(let a of t){if(a)break;e.push("1".charCodeAt(0))}return e.reverse(),String.fromCharCode(...e)};pt.exports=Ut});var Rt=F(tt=>{"use strict";tt.base58_to_binary=dt();tt.binary_to_base58=_t()});var Ft=F(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.bech32m=v.bech32=void 0;var j="qpzry9x8gf2tvdw0s3jn54khce6mua7l",bt={};for(let t=0;t<j.length;t++){let e=j.charAt(t);bt[e]=t}function y(t){let e=t>>25;return(t&33554431)<<5^-(e>>0&1)&996825010^-(e>>1&1)&642813549^-(e>>2&1)&513874426^-(e>>3&1)&1027748829^-(e>>4&1)&705979059}function mt(t){let e=1;for(let a=0;a<t.length;++a){let r=t.charCodeAt(a);if(r<33||r>126)return"Invalid prefix ("+t+")";e=y(e)^r>>5}e=y(e);for(let a=0;a<t.length;++a){let r=t.charCodeAt(a);e=y(e)^r&31}return e}function et(t,e,a,r){let i=0,n=0,c=(1<<a)-1,o=[];for(let s=0;s<t.length;++s)for(i=i<<e|t[s],n+=e;n>=a;)n-=a,o.push(i>>n&c);if(r)n>0&&o.push(i<<a-n&c);else{if(n>=e)return"Excess padding";if(i<<a-n&c)return"Non-zero padding"}return o}function Xt(t){return et(t,8,5,!0)}function Mt(t){let e=et(t,5,8,!1);if(Array.isArray(e))return e}function qt(t){let e=et(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function At(t){let e;t==="bech32"?e=1:e=734539939;function a(c,o,s){if(s=s||90,c.length+7+o.length>s)throw new TypeError("Exceeds length limit");c=c.toLowerCase();let d=mt(c);if(typeof d=="string")throw new Error(d);let u=c+"1";for(let l=0;l<o.length;++l){let f=o[l];if(f>>5)throw new Error("Non 5-bit word");d=y(d)^f,u+=j.charAt(f)}for(let l=0;l<6;++l)d=y(d);d^=e;for(let l=0;l<6;++l){let f=d>>(5-l)*5&31;u+=j.charAt(f)}return u}function r(c,o){if(o=o||90,c.length<8)return c+" too short";if(c.length>o)return"Exceeds length limit";let s=c.toLowerCase(),d=c.toUpperCase();if(c!==s&&c!==d)return"Mixed-case string "+c;c=s;let u=c.lastIndexOf("1");if(u===-1)return"No separator character for "+c;if(u===0)return"Missing prefix for "+c;let l=c.slice(0,u),f=c.slice(u+1);if(f.length<6)return"Data too short";let h=mt(l);if(typeof h=="string")return h;let p=[];for(let x=0;x<f.length;++x){let R=f.charAt(x),b=bt[R];if(b===void 0)return"Unknown character "+R;h=y(h)^b,!(x+6>=f.length)&&p.push(b)}return h!==e?"Invalid checksum for "+c:{prefix:l,words:p}}function i(c,o){let s=r(c,o);if(typeof s=="object")return s}function n(c,o){let s=r(c,o);if(typeof s=="object")return s;throw new Error(s)}return{decodeUnsafe:i,decode:n,encode:a,toWords:Xt,fromWordsUnsafe:Mt,fromWords:qt}}v.bech32=At("bech32");v.bech32m=At("bech32m")});var Nt=F((exports,module)=>{(function(){"use strict";var ERROR="input is invalid type",WINDOW=typeof window=="object",root=WINDOW?window:{};root.JS_SHA256_NO_WINDOW&&(WINDOW=!1);var WEB_WORKER=!WINDOW&&typeof self=="object",NODE_JS=!root.JS_SHA256_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;NODE_JS?root=global:WEB_WORKER&&(root=self);var COMMON_JS=!root.JS_SHA256_NO_COMMON_JS&&typeof module=="object"&&module.exports,AMD=typeof define=="function"&&define.amd,ARRAY_BUFFER=!root.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",HEX_CHARS="0123456789abcdef".split(""),EXTRA=[-2147483648,8388608,32768,128],SHIFT=[24,16,8,0],K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],OUTPUT_TYPES=["hex","array","digest","arrayBuffer"],blocks=[];(root.JS_SHA256_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(t){return Object.prototype.toString.call(t)==="[object Array]"}),ARRAY_BUFFER&&(root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer});var createOutputMethod=function(t,e){return function(a){return new Sha256(e,!0).update(a)[t]()}},createMethod=function(t){var e=createOutputMethod("hex",t);NODE_JS&&(e=nodeWrap(e,t)),e.create=function(){return new Sha256(t)},e.update=function(i){return e.create().update(i)};for(var a=0;a<OUTPUT_TYPES.length;++a){var r=OUTPUT_TYPES[a];e[r]=createOutputMethod(r,t)}return e},nodeWrap=function(method,is224){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),algorithm=is224?"sha224":"sha256",nodeMethod=function(t){if(typeof t=="string")return crypto.createHash(algorithm).update(t,"utf8").digest("hex");if(t==null)throw new Error(ERROR);return t.constructor===ArrayBuffer&&(t=new Uint8Array(t)),Array.isArray(t)||ArrayBuffer.isView(t)||t.constructor===Buffer?crypto.createHash(algorithm).update(new Buffer(t)).digest("hex"):method(t)};return nodeMethod},createHmacOutputMethod=function(t,e){return function(a,r){return new HmacSha256(a,e,!0).update(r)[t]()}},createHmacMethod=function(t){var e=createHmacOutputMethod("hex",t);e.create=function(i){return new HmacSha256(i,t)},e.update=function(i,n){return e.create(i).update(n)};for(var a=0;a<OUTPUT_TYPES.length;++a){var r=OUTPUT_TYPES[a];e[r]=createHmacOutputMethod(r,t)}return e};function Sha256(t,e){e?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=t}Sha256.prototype.update=function(t){if(!this.finalized){var e,a=typeof t;if(a!=="string"){if(a==="object"){if(t===null)throw new Error(ERROR);if(ARRAY_BUFFER&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!Array.isArray(t)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(t)))throw new Error(ERROR)}else throw new Error(ERROR);e=!0}for(var r,i=0,n,c=t.length,o=this.blocks;i<c;){if(this.hashed&&(this.hashed=!1,o[0]=this.block,o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),e)for(n=this.start;i<c&&n<64;++i)o[n>>2]|=t[i]<<SHIFT[n++&3];else for(n=this.start;i<c&&n<64;++i)r=t.charCodeAt(i),r<128?o[n>>2]|=r<<SHIFT[n++&3]:r<2048?(o[n>>2]|=(192|r>>6)<<SHIFT[n++&3],o[n>>2]|=(128|r&63)<<SHIFT[n++&3]):r<55296||r>=57344?(o[n>>2]|=(224|r>>12)<<SHIFT[n++&3],o[n>>2]|=(128|r>>6&63)<<SHIFT[n++&3],o[n>>2]|=(128|r&63)<<SHIFT[n++&3]):(r=65536+((r&1023)<<10|t.charCodeAt(++i)&1023),o[n>>2]|=(240|r>>18)<<SHIFT[n++&3],o[n>>2]|=(128|r>>12&63)<<SHIFT[n++&3],o[n>>2]|=(128|r>>6&63)<<SHIFT[n++&3],o[n>>2]|=(128|r&63)<<SHIFT[n++&3]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.block=o[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Sha256.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[16]=this.block,t[e>>2]|=EXTRA[e&3],this.block=t[16],e>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},Sha256.prototype.hash=function(){var t=this.h0,e=this.h1,a=this.h2,r=this.h3,i=this.h4,n=this.h5,c=this.h6,o=this.h7,s=this.blocks,d,u,l,f,h,p,x,R,b,Y,P;for(d=16;d<64;++d)h=s[d-15],u=(h>>>7|h<<25)^(h>>>18|h<<14)^h>>>3,h=s[d-2],l=(h>>>17|h<<15)^(h>>>19|h<<13)^h>>>10,s[d]=s[d-16]+u+s[d-7]+l<<0;for(P=e&a,d=0;d<64;d+=4)this.first?(this.is224?(R=300032,h=s[0]-1413257819,o=h-150054599<<0,r=h+24177077<<0):(R=704751109,h=s[0]-210244248,o=h-1521486534<<0,r=h+143694565<<0),this.first=!1):(u=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),l=(i>>>6|i<<26)^(i>>>11|i<<21)^(i>>>25|i<<7),R=t&e,f=R^t&a^P,x=i&n^~i&c,h=o+l+x+K[d]+s[d],p=u+f,o=r+h<<0,r=h+p<<0),u=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),l=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),b=r&t,f=b^r&e^R,x=o&i^~o&n,h=c+l+x+K[d+1]+s[d+1],p=u+f,c=a+h<<0,a=h+p<<0,u=(a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10),l=(c>>>6|c<<26)^(c>>>11|c<<21)^(c>>>25|c<<7),Y=a&r,f=Y^a&t^b,x=c&o^~c&i,h=n+l+x+K[d+2]+s[d+2],p=u+f,n=e+h<<0,e=h+p<<0,u=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),l=(n>>>6|n<<26)^(n>>>11|n<<21)^(n>>>25|n<<7),P=e&a,f=P^e&r^Y,x=n&c^~n&o,h=i+l+x+K[d+3]+s[d+3],p=u+f,i=t+h<<0,t=h+p<<0;this.h0=this.h0+t<<0,this.h1=this.h1+e<<0,this.h2=this.h2+a<<0,this.h3=this.h3+r<<0,this.h4=this.h4+i<<0,this.h5=this.h5+n<<0,this.h6=this.h6+c<<0,this.h7=this.h7+o<<0},Sha256.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,a=this.h2,r=this.h3,i=this.h4,n=this.h5,c=this.h6,o=this.h7,s=HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[t&15]+HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[e&15]+HEX_CHARS[a>>28&15]+HEX_CHARS[a>>24&15]+HEX_CHARS[a>>20&15]+HEX_CHARS[a>>16&15]+HEX_CHARS[a>>12&15]+HEX_CHARS[a>>8&15]+HEX_CHARS[a>>4&15]+HEX_CHARS[a&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[r&15]+HEX_CHARS[i>>28&15]+HEX_CHARS[i>>24&15]+HEX_CHARS[i>>20&15]+HEX_CHARS[i>>16&15]+HEX_CHARS[i>>12&15]+HEX_CHARS[i>>8&15]+HEX_CHARS[i>>4&15]+HEX_CHARS[i&15]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[n&15]+HEX_CHARS[c>>28&15]+HEX_CHARS[c>>24&15]+HEX_CHARS[c>>20&15]+HEX_CHARS[c>>16&15]+HEX_CHARS[c>>12&15]+HEX_CHARS[c>>8&15]+HEX_CHARS[c>>4&15]+HEX_CHARS[c&15];return this.is224||(s+=HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[o&15]),s},Sha256.prototype.toString=Sha256.prototype.hex,Sha256.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,a=this.h2,r=this.h3,i=this.h4,n=this.h5,c=this.h6,o=this.h7,s=[t>>24&255,t>>16&255,t>>8&255,t&255,e>>24&255,e>>16&255,e>>8&255,e&255,a>>24&255,a>>16&255,a>>8&255,a&255,r>>24&255,r>>16&255,r>>8&255,r&255,i>>24&255,i>>16&255,i>>8&255,i&255,n>>24&255,n>>16&255,n>>8&255,n&255,c>>24&255,c>>16&255,c>>8&255,c&255];return this.is224||s.push(o>>24&255,o>>16&255,o>>8&255,o&255),s},Sha256.prototype.array=Sha256.prototype.digest,Sha256.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),e=new DataView(t);return e.setUint32(0,this.h0),e.setUint32(4,this.h1),e.setUint32(8,this.h2),e.setUint32(12,this.h3),e.setUint32(16,this.h4),e.setUint32(20,this.h5),e.setUint32(24,this.h6),this.is224||e.setUint32(28,this.h7),t};function HmacSha256(t,e,a){var r,i=typeof t;if(i==="string"){var n=[],c=t.length,o=0,s;for(r=0;r<c;++r)s=t.charCodeAt(r),s<128?n[o++]=s:s<2048?(n[o++]=192|s>>6,n[o++]=128|s&63):s<55296||s>=57344?(n[o++]=224|s>>12,n[o++]=128|s>>6&63,n[o++]=128|s&63):(s=65536+((s&1023)<<10|t.charCodeAt(++r)&1023),n[o++]=240|s>>18,n[o++]=128|s>>12&63,n[o++]=128|s>>6&63,n[o++]=128|s&63);t=n}else if(i==="object"){if(t===null)throw new Error(ERROR);if(ARRAY_BUFFER&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!Array.isArray(t)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(t)))throw new Error(ERROR)}else throw new Error(ERROR);t.length>64&&(t=new Sha256(e,!0).update(t).array());var d=[],u=[];for(r=0;r<64;++r){var l=t[r]||0;d[r]=92^l,u[r]=54^l}Sha256.call(this,e,a),this.update(u),this.oKeyPad=d,this.inner=!0,this.sharedMemory=a}HmacSha256.prototype=new Sha256,HmacSha256.prototype.finalize=function(){if(Sha256.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();Sha256.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports,exports.sha224=createMethod(!0),exports.sha256.hmac=createHmacMethod(),exports.sha224.hmac=createHmacMethod(!0),COMMON_JS?module.exports=exports:(root.sha256=exports.sha256,root.sha224=exports.sha224,AMD&&define(function(){return exports}))})()});var Qt={};gt(Qt,{BtcAddressType:()=>Z,BtcNetwork:()=>Q,CkBTCMinterCanister:()=>E,MinterAlreadyProcessingError:()=>M,MinterAmountTooLowError:()=>z,MinterGenericError:()=>A,MinterInsufficientFundsError:()=>G,MinterMalformedAddressError:()=>W,MinterNoNewUtxosError:()=>q,MinterRetrieveBtcError:()=>H,MinterTemporaryUnavailableError:()=>X,MinterUpdateBalanceError:()=>B,ParseBtcAddressBadWitnessLengthError:()=>O,ParseBtcAddressError:()=>_,ParseBtcAddressInvalidError:()=>S,ParseBtcAddressMalformedAddressError:()=>N,ParseBtcAddressNoDataError:()=>g,ParseBtcAddressUnexpectedHumanReadablePartError:()=>T,ParseBtcAddressUnsupportedAddressTypeError:()=>w,ParseBtcAddressUnsupportedWitnessVersionError:()=>C,ParseBtcAddressWrongNetworkError:()=>k,createRetrieveBtcError:()=>L,createUpdateBalanceError:()=>D,parseBtcAddress:()=>$t});module.exports=Ot(Qt);var Q=(r=>(r[r.Mainnet=0]="Mainnet",r[r.Regtest=1]="Regtest",r[r.Testnet=2]="Testnet",r))(Q||{}),Z=(r=>(r[r.P2wpkhV0=0]="P2wpkhV0",r[r.P2pkh=1]="P2pkh",r[r.P2sh=2]="P2sh",r))(Z||{});var _=class extends Error{},S=class extends _{},g=class extends _{},w=class extends _{},O=class extends _{},C=class extends _{},T=class extends _{},N=class extends _{},k=class extends _{};var I=require("@dfinity/utils"),A=class extends Error{},X=class extends A{},M=class extends A{},B=class extends A{},q=class extends B{},H=class extends A{},W=class extends H{},z=class extends H{},G=class extends H{},nt=t=>{if("GenericError"in t){let{GenericError:{error_message:e,error_code:a}}=t;return new A(`${e} (${a})`)}if("TemporarilyUnavailable"in t)return new X(t.TemporarilyUnavailable);if("AlreadyProcessing"in t)return new M},D=t=>{let e=nt(t);return(0,I.nonNullish)(e)?e:"NoNewUtxos"in t?new q:new B(`Unsupported response type in minter.updateBalance ${JSON.stringify(t)}`)},L=t=>{let e=nt(t);return(0,I.nonNullish)(e)?e:"MalformedAddress"in t?new W(t.MalformedAddress):"AmountTooLow"in t?new z(`${t.AmountTooLow}`):"InsufficientFunds"in t?new G(`${t.InsufficientFunds.balance}`):new H(`Unsupported response type in minter.retrieveBtc ${JSON.stringify(t)}`)};var m=require("@dfinity/utils");var it=({IDL:t})=>{let e=t.Variant({RestrictedTo:t.Vec(t.Principal),DepositsRestrictedTo:t.Vec(t.Principal),ReadOnly:t.Null,GeneralAvailability:t.Null}),a=t.Record({mode:t.Opt(e),retrieve_btc_min_amount:t.Opt(t.Nat64),max_time_in_queue_nanos:t.Opt(t.Nat64),min_confirmations:t.Opt(t.Nat32)}),r=t.Variant({Mainnet:t.Null,Regtest:t.Null,Testnet:t.Null}),i=t.Record({kyt_principal:t.Opt(t.Principal),ecdsa_key_name:t.Text,mode:e,retrieve_btc_min_amount:t.Nat64,ledger_id:t.Principal,max_time_in_queue_nanos:t.Nat64,btc_network:r,min_confirmations:t.Opt(t.Nat32)}),n=t.Variant({Upgrade:t.Opt(a),Init:i}),c=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),o=t.Record({height:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),s=t.Variant({p2sh:t.Vec(t.Nat8),p2wpkh_v0:t.Vec(t.Nat8),p2pkh:t.Vec(t.Nat8)}),d=t.Variant({received_utxos:t.Record({to_account:c,utxos:t.Vec(o)}),sent_transaction:t.Record({change_output:t.Opt(t.Record({value:t.Nat64,vout:t.Nat32})),txid:t.Vec(t.Nat8),utxos:t.Vec(o),requests:t.Vec(t.Nat64),submitted_at:t.Nat64}),init:i,upgrade:a,accepted_retrieve_btc_request:t.Record({received_at:t.Nat64,block_index:t.Nat64,address:s,amount:t.Nat64}),checked_utxo:t.Record({clean:t.Bool,utxo:o,uuid:t.Text}),removed_retrieve_btc_request:t.Record({block_index:t.Nat64}),confirmed_transaction:t.Record({txid:t.Vec(t.Nat8)}),ignored_utxo:t.Record({utxo:o})}),u=t.Record({address:t.Text,amount:t.Nat64}),l=t.Record({block_index:t.Nat64}),f=t.Variant({MalformedAddress:t.Text,GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,AmountTooLow:t.Nat64,InsufficientFunds:t.Record({balance:t.Nat64})}),h=t.Variant({Signing:t.Null,Confirmed:t.Record({txid:t.Vec(t.Nat8)}),Sending:t.Record({txid:t.Vec(t.Nat8)}),AmountTooLow:t.Null,Unknown:t.Null,Submitted:t.Record({txid:t.Vec(t.Nat8)}),Pending:t.Null}),p=t.Variant({ValueTooSmall:o,Tainted:o,Minted:t.Record({minted_amount:t.Nat64,block_index:t.Nat64,utxo:o}),Checked:o}),x=t.Variant({GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,NoNewUtxos:t.Record({required_confirmations:t.Nat32,current_confirmations:t.Opt(t.Nat32)})});return t.Service({estimate_fee:t.Func([t.Record({amount:t.Opt(t.Nat64)})],[t.Nat64],[]),get_btc_address:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Text],[]),get_events:t.Func([t.Record({start:t.Nat64,length:t.Nat64})],[t.Vec(d)],[]),get_withdrawal_account:t.Func([],[c],[]),retrieve_btc:t.Func([u],[t.Variant({Ok:l,Err:f})],[]),retrieve_btc_status:t.Func([t.Record({block_index:t.Nat64})],[h],[]),update_balance:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Variant({Ok:t.Vec(p),Err:x})],[])})};var ct=({IDL:t})=>{let e=t.Variant({RestrictedTo:t.Vec(t.Principal),DepositsRestrictedTo:t.Vec(t.Principal),ReadOnly:t.Null,GeneralAvailability:t.Null}),a=t.Record({mode:t.Opt(e),retrieve_btc_min_amount:t.Opt(t.Nat64),max_time_in_queue_nanos:t.Opt(t.Nat64),min_confirmations:t.Opt(t.Nat32)}),r=t.Variant({Mainnet:t.Null,Regtest:t.Null,Testnet:t.Null}),i=t.Record({kyt_principal:t.Opt(t.Principal),ecdsa_key_name:t.Text,mode:e,retrieve_btc_min_amount:t.Nat64,ledger_id:t.Principal,max_time_in_queue_nanos:t.Nat64,btc_network:r,min_confirmations:t.Opt(t.Nat32)}),n=t.Variant({Upgrade:t.Opt(a),Init:i}),c=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),o=t.Record({height:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),s=t.Variant({p2sh:t.Vec(t.Nat8),p2wpkh_v0:t.Vec(t.Nat8),p2pkh:t.Vec(t.Nat8)}),d=t.Variant({received_utxos:t.Record({to_account:c,utxos:t.Vec(o)}),sent_transaction:t.Record({change_output:t.Opt(t.Record({value:t.Nat64,vout:t.Nat32})),txid:t.Vec(t.Nat8),utxos:t.Vec(o),requests:t.Vec(t.Nat64),submitted_at:t.Nat64}),init:i,upgrade:a,accepted_retrieve_btc_request:t.Record({received_at:t.Nat64,block_index:t.Nat64,address:s,amount:t.Nat64}),checked_utxo:t.Record({clean:t.Bool,utxo:o,uuid:t.Text}),removed_retrieve_btc_request:t.Record({block_index:t.Nat64}),confirmed_transaction:t.Record({txid:t.Vec(t.Nat8)}),ignored_utxo:t.Record({utxo:o})}),u=t.Record({address:t.Text,amount:t.Nat64}),l=t.Record({block_index:t.Nat64}),f=t.Variant({MalformedAddress:t.Text,GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,AmountTooLow:t.Nat64,InsufficientFunds:t.Record({balance:t.Nat64})}),h=t.Variant({Signing:t.Null,Confirmed:t.Record({txid:t.Vec(t.Nat8)}),Sending:t.Record({txid:t.Vec(t.Nat8)}),AmountTooLow:t.Null,Unknown:t.Null,Submitted:t.Record({txid:t.Vec(t.Nat8)}),Pending:t.Null}),p=t.Variant({ValueTooSmall:o,Tainted:o,Minted:t.Record({minted_amount:t.Nat64,block_index:t.Nat64,utxo:o}),Checked:o}),x=t.Variant({GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,NoNewUtxos:t.Record({required_confirmations:t.Nat32,current_confirmations:t.Opt(t.Nat32)})});return t.Service({estimate_fee:t.Func([t.Record({amount:t.Opt(t.Nat64)})],[t.Nat64],["query"]),get_btc_address:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Text],[]),get_events:t.Func([t.Record({start:t.Nat64,length:t.Nat64})],[t.Vec(d)],["query"]),get_withdrawal_account:t.Func([],[c],[]),retrieve_btc:t.Func([u],[t.Variant({Ok:l,Err:f})],[]),retrieve_btc_status:t.Func([t.Record({block_index:t.Nat64})],[h],["query"]),update_balance:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Variant({Ok:t.Vec(p),Err:x})],[])})};var E=class extends m.Canister{constructor(){super(...arguments);this.getBtcAddress=({owner:a,subaccount:r})=>this.caller({certified:!0}).get_btc_address({owner:(0,m.toNullable)(a),subaccount:(0,m.toNullable)(r)});this.updateBalance=async({owner:a,subaccount:r})=>{let i=await this.caller({certified:!0}).update_balance({owner:(0,m.toNullable)(a),subaccount:(0,m.toNullable)(r)});if("Err"in i)throw D(i.Err);return i.Ok};this.getWithdrawalAccount=()=>this.caller({certified:!0}).get_withdrawal_account();this.retrieveBtc=async a=>{let r=await this.caller({certified:!0}).retrieve_btc(a);if("Err"in r)throw L(r.Err);return r.Ok};this.estimateFee=async({certified:a,amount:r})=>this.caller({certified:a}).estimate_fee({amount:(0,m.toNullable)(r)})}static create(a){let{service:r,certifiedService:i,canisterId:n}=(0,m.createServices)({options:a,idlFactory:ct,certifiedIdlFactory:it});return new E(n,r,i)}};var ot=require("@dfinity/utils"),Ht=$(Rt()),V=$(Ft()),rt=$(Nt());var Wt=0,zt=5,Gt=111,Jt=196,jt={[Wt]:{type:1,networks:[0]},[Gt]:{type:1,networks:[2,1]},[zt]:{type:2,networks:[0]},[Jt]:{type:2,networks:[2,1]}},Yt=({address:t,network:e})=>{let r=(u=>{try{return(0,Ht.base58_to_binary)(u)}catch{throw new S}})(t),{length:i}=r;if(i!==25)throw new N(`Expected the address to be 25 bytes, got ${i}.`);(u=>{let l=u.slice(i-4,i),f=u.slice(0,i-4),h=rt.sha256.create();h.update(f);let p=rt.sha256.create();p.update(h.digest());let x=p.array().slice(0,4);if(l.some((R,b)=>R!==x[b]))throw new N(`Checksum mismatch expected ${l}, got ${x}.`)})(r);let c=r[0],o=jt[c];if((0,ot.isNullish)(o))throw new w;let{type:s,networks:d}=o;if(!d.includes(e))throw new k;return{address:t,network:e,type:s,parser:"base58"}},Kt=({address:t,network:e})=>{let a=u=>{try{return u.startsWith("bc1p")||u.startsWith("tb1p")||u.startsWith("bcrt1p")?V.bech32m.decode(u):V.bech32.decode(u)}catch{throw new N}},{prefix:r,words:i}=a(t),c={bc:0,tb:2,bcrt:1}[r];if((0,ot.isNullish)(c))throw new S;if(c!==e)throw new T;let[o,...s]=i;if(o!==0)throw new C;if(V.bech32.fromWords(s).length!==20)throw new O;return{address:t,network:e,type:0,parser:"bip-173"}},$t=({address:t,network:e=0})=>{switch(t.charAt(0)){case"1":case"2":case"3":case"m":case"n":return Yt({address:t,network:e});case"b":case"B":case"t":case"T":return Kt({address:t,network:e});case"":throw new g;default:throw new w}};0&&(module.exports={BtcAddressType,BtcNetwork,CkBTCMinterCanister,MinterAlreadyProcessingError,MinterAmountTooLowError,MinterGenericError,MinterInsufficientFundsError,MinterMalformedAddressError,MinterNoNewUtxosError,MinterRetrieveBtcError,MinterTemporaryUnavailableError,MinterUpdateBalanceError,ParseBtcAddressBadWitnessLengthError,ParseBtcAddressError,ParseBtcAddressInvalidError,ParseBtcAddressMalformedAddressError,ParseBtcAddressNoDataError,ParseBtcAddressUnexpectedHumanReadablePartError,ParseBtcAddressUnsupportedAddressTypeError,ParseBtcAddressUnsupportedWitnessVersionError,ParseBtcAddressWrongNetworkError,createRetrieveBtcError,createUpdateBalanceError,parseBtcAddress});
2
2
  /*! Bundled license information:
3
3
 
4
4
  js-sha256/src/sha256.js: