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