UNPKG

@dfinity/ckbtc

Version:

A library for interfacing with ckBTC.

3 lines (2 loc) • 16 kB
import{Canister as D,createServices as tt,fromNullable as et,isNullish as rt,toNullable as o}from"@dfinity/utils";var H=({IDL:t})=>{let e=t.Variant({RestrictedTo:t.Vec(t.Principal),DepositsRestrictedTo:t.Vec(t.Principal),ReadOnly:t.Null,GeneralAvailability:t.Null}),r=t.Record({get_utxos_cache_expiration_seconds:t.Opt(t.Nat64),kyt_principal:t.Opt(t.Principal),mode:t.Opt(e),retrieve_btc_min_amount:t.Opt(t.Nat64),max_time_in_queue_nanos:t.Opt(t.Nat64),check_fee:t.Opt(t.Nat64),btc_checker_principal:t.Opt(t.Principal),min_confirmations:t.Opt(t.Nat32),kyt_fee:t.Opt(t.Nat64)}),c=t.Variant({Mainnet:t.Null,Regtest:t.Null,Testnet:t.Null}),i=t.Record({get_utxos_cache_expiration_seconds:t.Opt(t.Nat64),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:c,check_fee:t.Opt(t.Nat64),btc_checker_principal:t.Opt(t.Principal),min_confirmations:t.Opt(t.Nat32),kyt_fee:t.Opt(t.Nat64)}),R=t.Variant({Upgrade:t.Opt(r),Init:i}),u=t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),x=t.Variant({controllers:t.Null,public:t.Null,allowed_viewers:t.Vec(t.Principal)}),v=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:x,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),b=t.Record({response_payload_bytes_total:t.Nat,num_instructions_total:t.Nat,num_calls_total:t.Nat,request_payload_bytes_total:t.Nat}),y=t.Record({status:u,memory_size:t.Nat,cycles:t.Nat,settings:v,query_stats:b,idle_cycles_burned_per_day:t.Nat,module_hash:t.Opt(t.Vec(t.Nat8)),reserved_cycles:t.Nat}),n=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),a=t.Record({height:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),s=t.Variant({CallFailed:t.Null,TaintedDestination:t.Record({kyt_fee:t.Nat64,kyt_provider:t.Principal})}),_=t.Variant({ValueTooSmall:t.Null,Quarantined:t.Null}),f=t.Variant({p2wsh_v0:t.Vec(t.Nat8),p2tr_v1:t.Vec(t.Nat8),p2sh:t.Vec(t.Nat8),p2wpkh_v0:t.Vec(t.Nat8),p2pkh:t.Vec(t.Nat8)}),g=t.Variant({received_utxos:t.Record({to_account:n,mint_txid:t.Opt(t.Nat64),utxos:t.Vec(a)}),schedule_deposit_reimbursement:t.Record({burn_block_index:t.Nat64,account:n,amount:t.Nat64,reason:s}),sent_transaction:t.Record({fee:t.Opt(t.Nat64),change_output:t.Opt(t.Record({value:t.Nat64,vout:t.Nat32})),txid:t.Vec(t.Nat8),utxos:t.Vec(a),requests:t.Vec(t.Nat64),submitted_at:t.Nat64}),distributed_kyt_fee:t.Record({block_index:t.Nat64,amount:t.Nat64,kyt_provider:t.Principal}),init:i,upgrade:r,retrieve_btc_kyt_failed:t.Record({block_index:t.Nat64,owner:t.Principal,uuid:t.Text,address:t.Text,amount:t.Nat64,kyt_provider:t.Principal}),suspended_utxo:t.Record({utxo:a,account:n,reason:_}),accepted_retrieve_btc_request:t.Record({received_at:t.Nat64,block_index:t.Nat64,address:f,reimbursement_account:t.Opt(n),amount:t.Nat64,kyt_provider:t.Opt(t.Principal)}),checked_utxo:t.Record({clean:t.Bool,utxo:a,uuid:t.Text,kyt_provider:t.Opt(t.Principal)}),removed_retrieve_btc_request:t.Record({block_index:t.Nat64}),confirmed_transaction:t.Record({txid:t.Vec(t.Nat8)}),replaced_transaction:t.Record({fee:t.Nat64,change_output:t.Record({value:t.Nat64,vout:t.Nat32}),old_txid:t.Vec(t.Nat8),new_txid:t.Vec(t.Nat8),submitted_at:t.Nat64}),checked_utxo_v2:t.Record({utxo:a,account:n}),ignored_utxo:t.Record({utxo:a}),checked_utxo_mint_unknown:t.Record({utxo:a,account:n}),reimbursed_failed_deposit:t.Record({burn_block_index:t.Nat64,mint_block_index:t.Nat64})}),O=t.Record({timestamp:t.Opt(t.Nat64),payload:g}),V=t.Record({retrieve_btc_min_amount:t.Nat64,min_confirmations:t.Nat32,kyt_fee:t.Nat64}),k=t.Record({address:t.Text,amount:t.Nat64}),p=t.Record({block_index:t.Nat64}),h=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})}),w=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.Record({account:n,amount:t.Nat64,reason:s}),T=t.Record({account:n,mint_block_index:t.Nat64,amount:t.Nat64,reason:s}),N=t.Variant({Signing:t.Null,Confirmed:t.Record({txid:t.Vec(t.Nat8)}),Sending:t.Record({txid:t.Vec(t.Nat8)}),AmountTooLow:t.Null,WillReimburse:P,Unknown:t.Null,Submitted:t.Record({txid:t.Vec(t.Nat8)}),Reimbursed:T,Pending:t.Null}),B=t.Record({from_subaccount:t.Opt(t.Vec(t.Nat8)),address:t.Text,amount:t.Nat64}),A=t.Variant({MalformedAddress:t.Text,GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,InsufficientAllowance:t.Record({allowance:t.Nat64}),AlreadyProcessing:t.Null,AmountTooLow:t.Nat64,InsufficientFunds:t.Record({balance:t.Nat64})}),U=t.Variant({ValueTooSmall:a,Tainted:a,Minted:t.Record({minted_amount:t.Nat64,block_index:t.Nat64,utxo:a}),Checked:a}),S=t.Nat64,F=t.Record({utxo:a,earliest_retry:S,reason:_}),q=t.Record({confirmations:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),C=t.Variant({GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,NoNewUtxos:t.Record({suspended_utxos:t.Opt(t.Vec(F)),required_confirmations:t.Nat32,pending_utxos:t.Opt(t.Vec(q)),current_confirmations:t.Opt(t.Nat32)})});return t.Service({estimate_withdrawal_fee:t.Func([t.Record({amount:t.Opt(t.Nat64)})],[t.Record({minter_fee:t.Nat64,bitcoin_fee:t.Nat64})],[]),get_btc_address:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Text],[]),get_canister_status:t.Func([],[y],[]),get_deposit_fee:t.Func([],[t.Nat64],[]),get_events:t.Func([t.Record({start:t.Nat64,length:t.Nat64})],[t.Vec(O)],[]),get_known_utxos:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Vec(a)],[]),get_minter_info:t.Func([],[V],[]),get_withdrawal_account:t.Func([],[n],[]),retrieve_btc:t.Func([k],[t.Variant({Ok:p,Err:h})],[]),retrieve_btc_status:t.Func([t.Record({block_index:t.Nat64})],[w],[]),retrieve_btc_status_v2:t.Func([t.Record({block_index:t.Nat64})],[N],[]),retrieve_btc_status_v2_by_account:t.Func([t.Opt(n)],[t.Vec(t.Record({block_index:t.Nat64,status_v2:t.Opt(N)}))],[]),retrieve_btc_with_approval:t.Func([B],[t.Variant({Ok:p,Err:A})],[]),update_balance:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Variant({Ok:t.Vec(U),Err:C})],[])})};var X=({IDL:t})=>{let e=t.Variant({RestrictedTo:t.Vec(t.Principal),DepositsRestrictedTo:t.Vec(t.Principal),ReadOnly:t.Null,GeneralAvailability:t.Null}),r=t.Record({get_utxos_cache_expiration_seconds:t.Opt(t.Nat64),kyt_principal:t.Opt(t.Principal),mode:t.Opt(e),retrieve_btc_min_amount:t.Opt(t.Nat64),max_time_in_queue_nanos:t.Opt(t.Nat64),check_fee:t.Opt(t.Nat64),btc_checker_principal:t.Opt(t.Principal),min_confirmations:t.Opt(t.Nat32),kyt_fee:t.Opt(t.Nat64)}),c=t.Variant({Mainnet:t.Null,Regtest:t.Null,Testnet:t.Null}),i=t.Record({get_utxos_cache_expiration_seconds:t.Opt(t.Nat64),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:c,check_fee:t.Opt(t.Nat64),btc_checker_principal:t.Opt(t.Principal),min_confirmations:t.Opt(t.Nat32),kyt_fee:t.Opt(t.Nat64)}),R=t.Variant({Upgrade:t.Opt(r),Init:i}),u=t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),x=t.Variant({controllers:t.Null,public:t.Null,allowed_viewers:t.Vec(t.Principal)}),v=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:x,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),b=t.Record({response_payload_bytes_total:t.Nat,num_instructions_total:t.Nat,num_calls_total:t.Nat,request_payload_bytes_total:t.Nat}),y=t.Record({status:u,memory_size:t.Nat,cycles:t.Nat,settings:v,query_stats:b,idle_cycles_burned_per_day:t.Nat,module_hash:t.Opt(t.Vec(t.Nat8)),reserved_cycles:t.Nat}),n=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),a=t.Record({height:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),s=t.Variant({CallFailed:t.Null,TaintedDestination:t.Record({kyt_fee:t.Nat64,kyt_provider:t.Principal})}),_=t.Variant({ValueTooSmall:t.Null,Quarantined:t.Null}),f=t.Variant({p2wsh_v0:t.Vec(t.Nat8),p2tr_v1:t.Vec(t.Nat8),p2sh:t.Vec(t.Nat8),p2wpkh_v0:t.Vec(t.Nat8),p2pkh:t.Vec(t.Nat8)}),g=t.Variant({received_utxos:t.Record({to_account:n,mint_txid:t.Opt(t.Nat64),utxos:t.Vec(a)}),schedule_deposit_reimbursement:t.Record({burn_block_index:t.Nat64,account:n,amount:t.Nat64,reason:s}),sent_transaction:t.Record({fee:t.Opt(t.Nat64),change_output:t.Opt(t.Record({value:t.Nat64,vout:t.Nat32})),txid:t.Vec(t.Nat8),utxos:t.Vec(a),requests:t.Vec(t.Nat64),submitted_at:t.Nat64}),distributed_kyt_fee:t.Record({block_index:t.Nat64,amount:t.Nat64,kyt_provider:t.Principal}),init:i,upgrade:r,retrieve_btc_kyt_failed:t.Record({block_index:t.Nat64,owner:t.Principal,uuid:t.Text,address:t.Text,amount:t.Nat64,kyt_provider:t.Principal}),suspended_utxo:t.Record({utxo:a,account:n,reason:_}),accepted_retrieve_btc_request:t.Record({received_at:t.Nat64,block_index:t.Nat64,address:f,reimbursement_account:t.Opt(n),amount:t.Nat64,kyt_provider:t.Opt(t.Principal)}),checked_utxo:t.Record({clean:t.Bool,utxo:a,uuid:t.Text,kyt_provider:t.Opt(t.Principal)}),removed_retrieve_btc_request:t.Record({block_index:t.Nat64}),confirmed_transaction:t.Record({txid:t.Vec(t.Nat8)}),replaced_transaction:t.Record({fee:t.Nat64,change_output:t.Record({value:t.Nat64,vout:t.Nat32}),old_txid:t.Vec(t.Nat8),new_txid:t.Vec(t.Nat8),submitted_at:t.Nat64}),checked_utxo_v2:t.Record({utxo:a,account:n}),ignored_utxo:t.Record({utxo:a}),checked_utxo_mint_unknown:t.Record({utxo:a,account:n}),reimbursed_failed_deposit:t.Record({burn_block_index:t.Nat64,mint_block_index:t.Nat64})}),O=t.Record({timestamp:t.Opt(t.Nat64),payload:g}),V=t.Record({retrieve_btc_min_amount:t.Nat64,min_confirmations:t.Nat32,kyt_fee:t.Nat64}),k=t.Record({address:t.Text,amount:t.Nat64}),p=t.Record({block_index:t.Nat64}),h=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})}),w=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.Record({account:n,amount:t.Nat64,reason:s}),T=t.Record({account:n,mint_block_index:t.Nat64,amount:t.Nat64,reason:s}),N=t.Variant({Signing:t.Null,Confirmed:t.Record({txid:t.Vec(t.Nat8)}),Sending:t.Record({txid:t.Vec(t.Nat8)}),AmountTooLow:t.Null,WillReimburse:P,Unknown:t.Null,Submitted:t.Record({txid:t.Vec(t.Nat8)}),Reimbursed:T,Pending:t.Null}),B=t.Record({from_subaccount:t.Opt(t.Vec(t.Nat8)),address:t.Text,amount:t.Nat64}),A=t.Variant({MalformedAddress:t.Text,GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,InsufficientAllowance:t.Record({allowance:t.Nat64}),AlreadyProcessing:t.Null,AmountTooLow:t.Nat64,InsufficientFunds:t.Record({balance:t.Nat64})}),U=t.Variant({ValueTooSmall:a,Tainted:a,Minted:t.Record({minted_amount:t.Nat64,block_index:t.Nat64,utxo:a}),Checked:a}),S=t.Nat64,F=t.Record({utxo:a,earliest_retry:S,reason:_}),q=t.Record({confirmations:t.Nat32,value:t.Nat64,outpoint:t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32})}),C=t.Variant({GenericError:t.Record({error_message:t.Text,error_code:t.Nat64}),TemporarilyUnavailable:t.Text,AlreadyProcessing:t.Null,NoNewUtxos:t.Record({suspended_utxos:t.Opt(t.Vec(F)),required_confirmations:t.Nat32,pending_utxos:t.Opt(t.Vec(q)),current_confirmations:t.Opt(t.Nat32)})});return t.Service({estimate_withdrawal_fee:t.Func([t.Record({amount:t.Opt(t.Nat64)})],[t.Record({minter_fee:t.Nat64,bitcoin_fee: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_canister_status:t.Func([],[y],[]),get_deposit_fee:t.Func([],[t.Nat64],["query"]),get_events:t.Func([t.Record({start:t.Nat64,length:t.Nat64})],[t.Vec(O)],["query"]),get_known_utxos:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Vec(a)],["query"]),get_minter_info:t.Func([],[V],["query"]),get_withdrawal_account:t.Func([],[n],[]),retrieve_btc:t.Func([k],[t.Variant({Ok:p,Err:h})],[]),retrieve_btc_status:t.Func([t.Record({block_index:t.Nat64})],[w],["query"]),retrieve_btc_status_v2:t.Func([t.Record({block_index:t.Nat64})],[N],["query"]),retrieve_btc_status_v2_by_account:t.Func([t.Opt(n)],[t.Vec(t.Record({block_index:t.Nat64,status_v2:t.Opt(N)}))],["query"]),retrieve_btc_with_approval:t.Func([B],[t.Variant({Ok:p,Err:A})],[]),update_balance:t.Func([t.Record({owner:t.Opt(t.Principal),subaccount:t.Opt(t.Vec(t.Nat8))})],[t.Variant({Ok:t.Vec(U),Err:C})],[])})};import{fromNullable as L,nonNullish as K}from"@dfinity/utils";var d=class extends Error{},E=class extends d{},W=class extends d{},m=class extends d{},M=class extends m{pendingUtxos;requiredConfirmations;constructor({pending_utxos:e,required_confirmations:r}){super(),this.pendingUtxos=L(e)??[],this.requiredConfirmations=r}},l=class extends d{},G=class extends l{},$=class extends l{},Q=class extends l{},z=class extends l{},J=t=>{if("GenericError"in t){let{GenericError:{error_message:e,error_code:r}}=t;return new d(`${e} (${r})`)}if("TemporarilyUnavailable"in t)return new E(t.TemporarilyUnavailable);if("AlreadyProcessing"in t)return new W},Y=t=>{let e=J(t);return K(e)?e:"NoNewUtxos"in t?new M(t.NoNewUtxos):new m(`Unsupported response type in minter.updateBalance ${JSON.stringify(t)}`)},j=t=>{let e=J(t);return K(e)?e:"MalformedAddress"in t?new G(t.MalformedAddress):"AmountTooLow"in t?new $(`${t.AmountTooLow}`):"InsufficientFunds"in t?new Q(`${t.InsufficientFunds.balance}`):new l(`Unsupported response type in minter.retrieveBtc ${JSON.stringify(t)}`)},Z=t=>{let e=J(t);return K(e)?e:"InsufficientAllowance"in t?new z(`${t.InsufficientAllowance.allowance}`):j(t)};var I=class t extends D{static create(e){let{service:r,certifiedService:c,canisterId:i}=tt({options:e,idlFactory:X,certifiedIdlFactory:H});return new t(i,r,c)}getBtcAddress=({owner:e,subaccount:r})=>this.caller({certified:!0}).get_btc_address({owner:o(e),subaccount:o(r)});updateBalance=async({owner:e,subaccount:r})=>{let c=await this.caller({certified:!0}).update_balance({owner:o(e),subaccount:o(r)});if("Err"in c)throw Y(c.Err);return c.Ok};getWithdrawalAccount=()=>this.caller({certified:!0}).get_withdrawal_account();retrieveBtc=async e=>{let r=await this.caller({certified:!0}).retrieve_btc(e);if("Err"in r)throw j(r.Err);return r.Ok};retrieveBtcWithApproval=async({address:e,amount:r,fromSubaccount:c})=>{let i=await this.caller({certified:!0}).retrieve_btc_with_approval({address:e,amount:r,from_subaccount:o(c)});if("Err"in i)throw Z(i.Err);return i.Ok};retrieveBtcStatus=({transactionId:e,certified:r})=>this.caller({certified:r}).retrieve_btc_status({block_index:e});retrieveBtcStatusV2ByAccount=async({account:e,certified:r})=>{let{retrieve_btc_status_v2_by_account:c}=this.caller({certified:r});return(await c(rt(e)?[]:[{owner:e.owner,subaccount:o(e.subaccount)}])).map(({block_index:R,status_v2:u})=>({id:R,status:et(u)}))};estimateWithdrawalFee=({certified:e,amount:r})=>this.caller({certified:e}).estimate_withdrawal_fee({amount:o(r)});getMinterInfo=({certified:e})=>this.caller({certified:e}).get_minter_info();getKnownUtxos=({owner:e,subaccount:r,certified:c})=>{let{get_known_utxos:i}=this.caller({certified:c});return i({owner:o(e),subaccount:o(r)})}};export{d as a,E as b,W as c,m as d,M as e,l as f,G as g,$ as h,Q as i,z as j,Y as k,j as l,Z as m,I as n}; //# sourceMappingURL=chunk-HAU7JR75.js.map