@dfinity/ledger-icrc 2.1.1 → 2.1.2

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.
@@ -1,2 +1,2 @@
1
- "use strict";var L=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var _t=(t,a)=>{for(var c in a)L(t,c,{get:a[c],enumerable:!0})},ft=(t,a,c,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of dt(a))!ut.call(t,e)&&e!==c&&L(t,e,{get:()=>a[e],enumerable:!(r=mt(a,e))||r.enumerable});return t};var Nt=t=>ft(L({},"__esModule",{value:!0}),t);var yt={};_t(yt,{IcrcIndexCanister:()=>F,IcrcLedgerCanister:()=>v,IcrcMetadataResponseEntries:()=>pt,IcrcTransferError:()=>x,IndexError:()=>b,decodeIcrcAccount:()=>xt,decodePayment:()=>Rt,encodeIcrcAccount:()=>Tt});module.exports=Nt(yt);var b=class extends Error{};var x=class extends Error{constructor({msg:c,errorType:r}){super(c);this.errorType=r}};var h=require("@dfinity/utils");var et=({IDL:t})=>{let a=t.Record({ledger_id:t.Principal}),c=t.Nat,r=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),e=t.Record({max_results:t.Nat,start:t.Opt(c),account:r}),i=t.Record({from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),p=t.Record({to:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat}),_=t.Record({fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(t.Nat64),spender:r}),f=t.Record({to:r,fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),y=t.Record({burn:t.Opt(i),kind:t.Text,mint:t.Opt(p),approve:t.Opt(_),timestamp:t.Nat64,transfer:t.Opt(f)}),s=t.Record({id:c,transaction:y}),N=t.Record({transactions:t.Vec(s),oldest_tx_id:t.Opt(c)}),u=t.Record({message:t.Text}),O=t.Variant({Ok:N,Err:u}),d=t.Vec(t.Nat8),g=t.Record({owner:t.Principal,start:t.Opt(d)});return t.Service({get_account_transactions:t.Func([e],[O],[]),ledger_id:t.Func([],[t.Principal],[]),list_subaccounts:t.Func([g],[t.Vec(d)],[])})};var rt=({IDL:t})=>{let a=t.Record({ledger_id:t.Principal}),c=t.Nat,r=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),e=t.Record({max_results:t.Nat,start:t.Opt(c),account:r}),i=t.Record({from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),p=t.Record({to:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat}),_=t.Record({fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(t.Nat64),spender:r}),f=t.Record({to:r,fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),y=t.Record({burn:t.Opt(i),kind:t.Text,mint:t.Opt(p),approve:t.Opt(_),timestamp:t.Nat64,transfer:t.Opt(f)}),s=t.Record({id:c,transaction:y}),N=t.Record({transactions:t.Vec(s),oldest_tx_id:t.Opt(c)}),u=t.Record({message:t.Text}),O=t.Variant({Ok:N,Err:u}),d=t.Vec(t.Nat8),g=t.Record({owner:t.Principal,start:t.Opt(d)});return t.Service({get_account_transactions:t.Func([e],[O],[]),ledger_id:t.Func([],[t.Principal],["query"]),list_subaccounts:t.Func([g],[t.Vec(d)],["query"])})};var D=require("@dfinity/utils"),Ot=({owner:t,subaccount:a})=>({owner:t,subaccount:(0,D.toNullable)(a)}),ct=({account:t,max_results:a,start:c})=>({account:Ot(t),max_results:a,start:(0,D.toNullable)(c)});var F=class t extends h.Canister{constructor(){super(...arguments);this.getTransactions=async c=>{let r=await this.caller({certified:!0}).get_account_transactions(ct(c));if("Err"in r)throw new b(r.Err.message);return r.Ok}}static create(c){let{service:r,certifiedService:e,canisterId:i}=(0,h.createServices)({options:c,idlFactory:rt,certifiedIdlFactory:et});return new t(i,r,e)}};var R=require("@dfinity/utils");var at=({IDL:t})=>{let a=t.Rec(),c=t.Variant({Int:t.Int,Nat:t.Nat,Blob:t.Vec(t.Nat8),Text:t.Text}),r=t.Vec(t.Nat8),e=t.Record({owner:t.Principal,subaccount:t.Opt(r)}),i=t.Variant({SetTo:e,Unset:t.Null}),p=t.Record({icrc2:t.Bool}),_=t.Record({token_symbol:t.Opt(t.Text),transfer_fee:t.Opt(t.Nat),metadata:t.Opt(t.Vec(t.Tuple(t.Text,c))),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),change_fee_collector:t.Opt(i),max_memo_length:t.Opt(t.Nat16),token_name:t.Opt(t.Text),feature_flags:t.Opt(p)}),f=t.Record({decimals:t.Opt(t.Nat8),token_symbol:t.Text,transfer_fee:t.Nat,metadata:t.Vec(t.Tuple(t.Text,c)),minting_account:e,initial_balances:t.Vec(t.Tuple(e,t.Nat)),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),fee_collector_account:t.Opt(e),archive_options:t.Record({num_blocks_to_archive:t.Nat64,max_transactions_per_response:t.Opt(t.Nat64),trigger_threshold:t.Nat64,max_message_size_bytes:t.Opt(t.Nat64),cycles_for_archive_creation:t.Opt(t.Nat64),node_max_memory_size_bytes:t.Opt(t.Nat64),controller_id:t.Principal}),max_memo_length:t.Opt(t.Nat16),token_name:t.Text,feature_flags:t.Opt(p)}),y=t.Variant({Upgrade:t.Opt(_),Init:f}),s=t.Nat,N=t.Record({block_range_end:s,canister_id:t.Principal,block_range_start:s}),u=t.Record({start:s,length:t.Nat}),O=t.Vec(t.Tuple(t.Text,a));a.fill(t.Variant({Int:t.Int,Map:O,Nat:t.Nat,Nat64:t.Nat64,Blob:t.Vec(t.Nat8),Text:t.Text,Array:t.Vec(a)}));let d=a,g=t.Record({blocks:t.Vec(d)}),w=t.Func([u],[g],[]),P=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),first_index:s,blocks:t.Vec(d),chain_length:t.Nat64,archived_blocks:t.Vec(t.Record({callback:w,start:s,length:t.Nat}))}),B=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),hash_tree:t.Vec(t.Nat8)}),T=t.Nat,A=t.Record({start:T,length:t.Nat}),o=t.Nat64,E=t.Record({from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),S=t.Record({to:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat}),G=t.Record({fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),C=t.Record({to:e,fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),V=t.Record({burn:t.Opt(E),kind:t.Text,mint:t.Opt(S),approve:t.Opt(G),timestamp:o,transfer:t.Opt(C)}),q=t.Record({transactions:t.Vec(V)}),U=t.Func([A],[q],[]),M=t.Record({first_index:T,log_length:t.Nat,transactions:t.Vec(V),archived_transactions:t.Vec(t.Record({callback:U,start:T,length:t.Nat}))}),n=t.Nat,z=t.Record({url:t.Text,name:t.Text}),Q=t.Record({to:e,fee:t.Opt(n),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(r),created_at_time:t.Opt(o),amount:n}),H=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),W=t.Variant({Ok:s,Err:H}),Z=t.Record({account:e,spender:e}),$=t.Record({allowance:t.Nat,expires_at:t.Opt(o)}),X=t.Record({fee:t.Opt(t.Nat),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),j=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:t.Nat}),AllowanceChanged:t.Record({current_allowance:t.Nat}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,Expired:t.Record({ledger_time:o}),InsufficientFunds:t.Record({balance:t.Nat})}),Y=t.Variant({Ok:s,Err:j}),J=t.Record({to:e,fee:t.Opt(n),spender_subaccount:t.Opt(r),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:n}),K=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,InsufficientAllowance:t.Record({allowance:n}),BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),I=t.Variant({Ok:s,Err:K});return t.Service({archives:t.Func([],[t.Vec(N)],[]),get_blocks:t.Func([u],[P],[]),get_data_certificate:t.Func([],[B],[]),get_transactions:t.Func([A],[M],[]),icrc1_balance_of:t.Func([e],[n],[]),icrc1_decimals:t.Func([],[t.Nat8],[]),icrc1_fee:t.Func([],[n],[]),icrc1_metadata:t.Func([],[t.Vec(t.Tuple(t.Text,c))],[]),icrc1_minting_account:t.Func([],[t.Opt(e)],[]),icrc1_name:t.Func([],[t.Text],[]),icrc1_supported_standards:t.Func([],[t.Vec(z)],[]),icrc1_symbol:t.Func([],[t.Text],[]),icrc1_total_supply:t.Func([],[n],[]),icrc1_transfer:t.Func([Q],[W],[]),icrc2_allowance:t.Func([Z],[$],[]),icrc2_approve:t.Func([X],[Y],[]),icrc2_transfer_from:t.Func([J],[I],[])})};var ot=({IDL:t})=>{let a=t.Rec(),c=t.Variant({Int:t.Int,Nat:t.Nat,Blob:t.Vec(t.Nat8),Text:t.Text}),r=t.Vec(t.Nat8),e=t.Record({owner:t.Principal,subaccount:t.Opt(r)}),i=t.Variant({SetTo:e,Unset:t.Null}),p=t.Record({icrc2:t.Bool}),_=t.Record({token_symbol:t.Opt(t.Text),transfer_fee:t.Opt(t.Nat),metadata:t.Opt(t.Vec(t.Tuple(t.Text,c))),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),change_fee_collector:t.Opt(i),max_memo_length:t.Opt(t.Nat16),token_name:t.Opt(t.Text),feature_flags:t.Opt(p)}),f=t.Record({decimals:t.Opt(t.Nat8),token_symbol:t.Text,transfer_fee:t.Nat,metadata:t.Vec(t.Tuple(t.Text,c)),minting_account:e,initial_balances:t.Vec(t.Tuple(e,t.Nat)),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),fee_collector_account:t.Opt(e),archive_options:t.Record({num_blocks_to_archive:t.Nat64,max_transactions_per_response:t.Opt(t.Nat64),trigger_threshold:t.Nat64,max_message_size_bytes:t.Opt(t.Nat64),cycles_for_archive_creation:t.Opt(t.Nat64),node_max_memory_size_bytes:t.Opt(t.Nat64),controller_id:t.Principal}),max_memo_length:t.Opt(t.Nat16),token_name:t.Text,feature_flags:t.Opt(p)}),y=t.Variant({Upgrade:t.Opt(_),Init:f}),s=t.Nat,N=t.Record({block_range_end:s,canister_id:t.Principal,block_range_start:s}),u=t.Record({start:s,length:t.Nat}),O=t.Vec(t.Tuple(t.Text,a));a.fill(t.Variant({Int:t.Int,Map:O,Nat:t.Nat,Nat64:t.Nat64,Blob:t.Vec(t.Nat8),Text:t.Text,Array:t.Vec(a)}));let d=a,g=t.Record({blocks:t.Vec(d)}),w=t.Func([u],[g],["query"]),P=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),first_index:s,blocks:t.Vec(d),chain_length:t.Nat64,archived_blocks:t.Vec(t.Record({callback:w,start:s,length:t.Nat}))}),B=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),hash_tree:t.Vec(t.Nat8)}),T=t.Nat,A=t.Record({start:T,length:t.Nat}),o=t.Nat64,E=t.Record({from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),S=t.Record({to:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat}),G=t.Record({fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),C=t.Record({to:e,fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),V=t.Record({burn:t.Opt(E),kind:t.Text,mint:t.Opt(S),approve:t.Opt(G),timestamp:o,transfer:t.Opt(C)}),q=t.Record({transactions:t.Vec(V)}),U=t.Func([A],[q],["query"]),M=t.Record({first_index:T,log_length:t.Nat,transactions:t.Vec(V),archived_transactions:t.Vec(t.Record({callback:U,start:T,length:t.Nat}))}),n=t.Nat,z=t.Record({url:t.Text,name:t.Text}),Q=t.Record({to:e,fee:t.Opt(n),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(r),created_at_time:t.Opt(o),amount:n}),H=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),W=t.Variant({Ok:s,Err:H}),Z=t.Record({account:e,spender:e}),$=t.Record({allowance:t.Nat,expires_at:t.Opt(o)}),X=t.Record({fee:t.Opt(t.Nat),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),j=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:t.Nat}),AllowanceChanged:t.Record({current_allowance:t.Nat}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,Expired:t.Record({ledger_time:o}),InsufficientFunds:t.Record({balance:t.Nat})}),Y=t.Variant({Ok:s,Err:j}),J=t.Record({to:e,fee:t.Opt(n),spender_subaccount:t.Opt(r),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:n}),K=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,InsufficientAllowance:t.Record({allowance:n}),BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),I=t.Variant({Ok:s,Err:K});return t.Service({archives:t.Func([],[t.Vec(N)],["query"]),get_blocks:t.Func([u],[P],["query"]),get_data_certificate:t.Func([],[B],["query"]),get_transactions:t.Func([A],[M],["query"]),icrc1_balance_of:t.Func([e],[n],["query"]),icrc1_decimals:t.Func([],[t.Nat8],["query"]),icrc1_fee:t.Func([],[n],["query"]),icrc1_metadata:t.Func([],[t.Vec(t.Tuple(t.Text,c))],["query"]),icrc1_minting_account:t.Func([],[t.Opt(e)],["query"]),icrc1_name:t.Func([],[t.Text],["query"]),icrc1_supported_standards:t.Func([],[t.Vec(z)],["query"]),icrc1_symbol:t.Func([],[t.Text],["query"]),icrc1_total_supply:t.Func([],[n],["query"]),icrc1_transfer:t.Func([Q],[W],[]),icrc2_allowance:t.Func([Z],[$],["query"]),icrc2_approve:t.Func([X],[Y],[]),icrc2_transfer_from:t.Func([J],[I],[])})};var l=require("@dfinity/utils"),nt=({from_subaccount:t,fee:a,created_at_time:c,memo:r,...e})=>({...e,fee:(0,l.toNullable)(a),memo:(0,l.toNullable)(r),from_subaccount:(0,l.toNullable)(t),created_at_time:(0,l.toNullable)(c)}),st=({spender_subaccount:t,fee:a,created_at_time:c,memo:r,...e})=>({...e,fee:(0,l.toNullable)(a),memo:(0,l.toNullable)(r),spender_subaccount:(0,l.toNullable)(t),created_at_time:(0,l.toNullable)(c)}),it=({fee:t,created_at_time:a,memo:c,from_subaccount:r,expected_allowance:e,expires_at:i,...p})=>({...p,fee:(0,l.toNullable)(t),memo:(0,l.toNullable)(c),from_subaccount:(0,l.toNullable)(r),created_at_time:(0,l.toNullable)(a),expected_allowance:(0,l.toNullable)(e),expires_at:(0,l.toNullable)(i)});var v=class t extends R.Canister{constructor(){super(...arguments);this.metadata=c=>this.caller(c).icrc1_metadata();this.transactionFee=c=>this.caller(c).icrc1_fee();this.balance=c=>this.caller({certified:c.certified}).icrc1_balance_of({owner:c.owner,subaccount:(0,R.toNullable)(c.subaccount)});this.transfer=async c=>{let r=await this.caller({certified:!0}).icrc1_transfer(nt(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to transfer"});return r.Ok};this.totalTokensSupply=c=>this.caller(c).icrc1_total_supply();this.transferFrom=async c=>{let r=await this.caller({certified:!0}).icrc2_transfer_from(st(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to transfer from"});return r.Ok};this.approve=async c=>{let r=await this.caller({certified:!0}).icrc2_approve(it(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to entitle the spender to transfer the amount"});return r.Ok};this.allowance=async c=>{let{certified:r,...e}=c;return this.caller({certified:r}).icrc2_allowance({...e})}}static create(c){let{service:r,certifiedService:e,canisterId:i}=(0,R.createServices)({options:c,idlFactory:ot,certifiedIdlFactory:at});return new t(i,r,e)}};var pt=(i=>(i.SYMBOL="icrc1:symbol",i.NAME="icrc1:name",i.DECIMALS="icrc1:decimals",i.FEE="icrc1:fee",i.LOGO="icrc1:logo",i))(pt||{});var tt=require("@dfinity/principal"),m=require("@dfinity/utils"),gt=64,Tt=({owner:t,subaccount:a})=>{if((0,m.isNullish)(a))return t.toText();let r=(e=>e.replace(/^0+/,""))((0,m.uint8ArrayToHexString)(Uint8Array.from(a)));return r.length===0?t.toText():`${t.toText()}-${lt({owner:t,subaccount:a})}.${r}`},lt=({owner:t,subaccount:a})=>{let c=(0,m.bigEndianCrc32)(Uint8Array.from([...t.toUint8Array(),...a]));return(0,m.encodeBase32)(c)},xt=t=>{let[a,c]=t.split(".");if(!(0,m.notEmptyString)(a))throw new Error("Invalid account. No string provided.");if((0,m.isNullish)(c))return{owner:tt.Principal.fromText(t)};let[r,...e]=a.split("-").reverse(),i=e.reverse().join("-"),p={owner:tt.Principal.fromText(i),subaccount:(0,m.hexStringToUint8Array)(c.padStart(gt,"0"))};if(lt(p)!==r)throw new Error("Invalid account. Invalid checksum.");return p};var k=require("@dfinity/utils"),Rt=t=>{let a=/^([a-zA-Z]+):([A-Za-z0-9:\-.]+).*?(?:[?&](?:amount|value)=(\d+(?:\.\d+)?))?$/,c=t.match(a);if((0,k.isNullish)(c))return;let[r,e,i,p]=c;return{token:e,identifier:i,...(0,k.nonNullish)(p)&&!isNaN(parseFloat(p))&&{amount:parseFloat(p)}}};0&&(module.exports={IcrcIndexCanister,IcrcLedgerCanister,IcrcMetadataResponseEntries,IcrcTransferError,IndexError,decodeIcrcAccount,decodePayment,encodeIcrcAccount});
1
+ "use strict";var L=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var _t=(t,a)=>{for(var c in a)L(t,c,{get:a[c],enumerable:!0})},ft=(t,a,c,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of dt(a))!ut.call(t,e)&&e!==c&&L(t,e,{get:()=>a[e],enumerable:!(r=mt(a,e))||r.enumerable});return t};var Nt=t=>ft(L({},"__esModule",{value:!0}),t);var yt={};_t(yt,{IcrcIndexCanister:()=>F,IcrcLedgerCanister:()=>v,IcrcMetadataResponseEntries:()=>pt,IcrcTransferError:()=>x,IndexError:()=>b,decodeIcrcAccount:()=>xt,decodePayment:()=>Rt,encodeIcrcAccount:()=>Tt});module.exports=Nt(yt);var b=class extends Error{};var x=class extends Error{constructor({msg:a,errorType:c}){super(a),this.errorType=c}};var h=require("@dfinity/utils");var et=({IDL:t})=>{let a=t.Record({ledger_id:t.Principal}),c=t.Nat,r=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),e=t.Record({max_results:t.Nat,start:t.Opt(c),account:r}),i=t.Record({from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),p=t.Record({to:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat}),_=t.Record({fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(t.Nat64),spender:r}),f=t.Record({to:r,fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),y=t.Record({burn:t.Opt(i),kind:t.Text,mint:t.Opt(p),approve:t.Opt(_),timestamp:t.Nat64,transfer:t.Opt(f)}),s=t.Record({id:c,transaction:y}),N=t.Record({transactions:t.Vec(s),oldest_tx_id:t.Opt(c)}),u=t.Record({message:t.Text}),O=t.Variant({Ok:N,Err:u}),d=t.Vec(t.Nat8),g=t.Record({owner:t.Principal,start:t.Opt(d)});return t.Service({get_account_transactions:t.Func([e],[O],[]),ledger_id:t.Func([],[t.Principal],[]),list_subaccounts:t.Func([g],[t.Vec(d)],[])})};var rt=({IDL:t})=>{let a=t.Record({ledger_id:t.Principal}),c=t.Nat,r=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),e=t.Record({max_results:t.Nat,start:t.Opt(c),account:r}),i=t.Record({from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),p=t.Record({to:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat}),_=t.Record({fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(t.Nat64),spender:r}),f=t.Record({to:r,fee:t.Opt(t.Nat),from:r,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(t.Nat64),amount:t.Nat,spender:t.Opt(r)}),y=t.Record({burn:t.Opt(i),kind:t.Text,mint:t.Opt(p),approve:t.Opt(_),timestamp:t.Nat64,transfer:t.Opt(f)}),s=t.Record({id:c,transaction:y}),N=t.Record({transactions:t.Vec(s),oldest_tx_id:t.Opt(c)}),u=t.Record({message:t.Text}),O=t.Variant({Ok:N,Err:u}),d=t.Vec(t.Nat8),g=t.Record({owner:t.Principal,start:t.Opt(d)});return t.Service({get_account_transactions:t.Func([e],[O],[]),ledger_id:t.Func([],[t.Principal],["query"]),list_subaccounts:t.Func([g],[t.Vec(d)],["query"])})};var D=require("@dfinity/utils"),Ot=({owner:t,subaccount:a})=>({owner:t,subaccount:(0,D.toNullable)(a)}),ct=({account:t,max_results:a,start:c})=>({account:Ot(t),max_results:a,start:(0,D.toNullable)(c)});var F=class t extends h.Canister{constructor(){super(...arguments);this.getTransactions=async c=>{let r=await this.caller({certified:!0}).get_account_transactions(ct(c));if("Err"in r)throw new b(r.Err.message);return r.Ok}}static create(c){let{service:r,certifiedService:e,canisterId:i}=(0,h.createServices)({options:c,idlFactory:rt,certifiedIdlFactory:et});return new t(i,r,e)}};var R=require("@dfinity/utils");var at=({IDL:t})=>{let a=t.Rec(),c=t.Variant({Int:t.Int,Nat:t.Nat,Blob:t.Vec(t.Nat8),Text:t.Text}),r=t.Vec(t.Nat8),e=t.Record({owner:t.Principal,subaccount:t.Opt(r)}),i=t.Variant({SetTo:e,Unset:t.Null}),p=t.Record({icrc2:t.Bool}),_=t.Record({token_symbol:t.Opt(t.Text),transfer_fee:t.Opt(t.Nat),metadata:t.Opt(t.Vec(t.Tuple(t.Text,c))),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),change_fee_collector:t.Opt(i),max_memo_length:t.Opt(t.Nat16),token_name:t.Opt(t.Text),feature_flags:t.Opt(p)}),f=t.Record({decimals:t.Opt(t.Nat8),token_symbol:t.Text,transfer_fee:t.Nat,metadata:t.Vec(t.Tuple(t.Text,c)),minting_account:e,initial_balances:t.Vec(t.Tuple(e,t.Nat)),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),fee_collector_account:t.Opt(e),archive_options:t.Record({num_blocks_to_archive:t.Nat64,max_transactions_per_response:t.Opt(t.Nat64),trigger_threshold:t.Nat64,max_message_size_bytes:t.Opt(t.Nat64),cycles_for_archive_creation:t.Opt(t.Nat64),node_max_memory_size_bytes:t.Opt(t.Nat64),controller_id:t.Principal}),max_memo_length:t.Opt(t.Nat16),token_name:t.Text,feature_flags:t.Opt(p)}),y=t.Variant({Upgrade:t.Opt(_),Init:f}),s=t.Nat,N=t.Record({block_range_end:s,canister_id:t.Principal,block_range_start:s}),u=t.Record({start:s,length:t.Nat}),O=t.Vec(t.Tuple(t.Text,a));a.fill(t.Variant({Int:t.Int,Map:O,Nat:t.Nat,Nat64:t.Nat64,Blob:t.Vec(t.Nat8),Text:t.Text,Array:t.Vec(a)}));let d=a,g=t.Record({blocks:t.Vec(d)}),w=t.Func([u],[g],[]),P=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),first_index:s,blocks:t.Vec(d),chain_length:t.Nat64,archived_blocks:t.Vec(t.Record({callback:w,start:s,length:t.Nat}))}),B=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),hash_tree:t.Vec(t.Nat8)}),T=t.Nat,A=t.Record({start:T,length:t.Nat}),o=t.Nat64,E=t.Record({from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),S=t.Record({to:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat}),G=t.Record({fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),C=t.Record({to:e,fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),V=t.Record({burn:t.Opt(E),kind:t.Text,mint:t.Opt(S),approve:t.Opt(G),timestamp:o,transfer:t.Opt(C)}),q=t.Record({transactions:t.Vec(V)}),U=t.Func([A],[q],[]),M=t.Record({first_index:T,log_length:t.Nat,transactions:t.Vec(V),archived_transactions:t.Vec(t.Record({callback:U,start:T,length:t.Nat}))}),n=t.Nat,z=t.Record({url:t.Text,name:t.Text}),Q=t.Record({to:e,fee:t.Opt(n),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(r),created_at_time:t.Opt(o),amount:n}),H=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),W=t.Variant({Ok:s,Err:H}),Z=t.Record({account:e,spender:e}),$=t.Record({allowance:t.Nat,expires_at:t.Opt(o)}),X=t.Record({fee:t.Opt(t.Nat),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),j=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:t.Nat}),AllowanceChanged:t.Record({current_allowance:t.Nat}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,Expired:t.Record({ledger_time:o}),InsufficientFunds:t.Record({balance:t.Nat})}),Y=t.Variant({Ok:s,Err:j}),J=t.Record({to:e,fee:t.Opt(n),spender_subaccount:t.Opt(r),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:n}),K=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,InsufficientAllowance:t.Record({allowance:n}),BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),I=t.Variant({Ok:s,Err:K});return t.Service({archives:t.Func([],[t.Vec(N)],[]),get_blocks:t.Func([u],[P],[]),get_data_certificate:t.Func([],[B],[]),get_transactions:t.Func([A],[M],[]),icrc1_balance_of:t.Func([e],[n],[]),icrc1_decimals:t.Func([],[t.Nat8],[]),icrc1_fee:t.Func([],[n],[]),icrc1_metadata:t.Func([],[t.Vec(t.Tuple(t.Text,c))],[]),icrc1_minting_account:t.Func([],[t.Opt(e)],[]),icrc1_name:t.Func([],[t.Text],[]),icrc1_supported_standards:t.Func([],[t.Vec(z)],[]),icrc1_symbol:t.Func([],[t.Text],[]),icrc1_total_supply:t.Func([],[n],[]),icrc1_transfer:t.Func([Q],[W],[]),icrc2_allowance:t.Func([Z],[$],[]),icrc2_approve:t.Func([X],[Y],[]),icrc2_transfer_from:t.Func([J],[I],[])})};var ot=({IDL:t})=>{let a=t.Rec(),c=t.Variant({Int:t.Int,Nat:t.Nat,Blob:t.Vec(t.Nat8),Text:t.Text}),r=t.Vec(t.Nat8),e=t.Record({owner:t.Principal,subaccount:t.Opt(r)}),i=t.Variant({SetTo:e,Unset:t.Null}),p=t.Record({icrc2:t.Bool}),_=t.Record({token_symbol:t.Opt(t.Text),transfer_fee:t.Opt(t.Nat),metadata:t.Opt(t.Vec(t.Tuple(t.Text,c))),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),change_fee_collector:t.Opt(i),max_memo_length:t.Opt(t.Nat16),token_name:t.Opt(t.Text),feature_flags:t.Opt(p)}),f=t.Record({decimals:t.Opt(t.Nat8),token_symbol:t.Text,transfer_fee:t.Nat,metadata:t.Vec(t.Tuple(t.Text,c)),minting_account:e,initial_balances:t.Vec(t.Tuple(e,t.Nat)),maximum_number_of_accounts:t.Opt(t.Nat64),accounts_overflow_trim_quantity:t.Opt(t.Nat64),fee_collector_account:t.Opt(e),archive_options:t.Record({num_blocks_to_archive:t.Nat64,max_transactions_per_response:t.Opt(t.Nat64),trigger_threshold:t.Nat64,max_message_size_bytes:t.Opt(t.Nat64),cycles_for_archive_creation:t.Opt(t.Nat64),node_max_memory_size_bytes:t.Opt(t.Nat64),controller_id:t.Principal}),max_memo_length:t.Opt(t.Nat16),token_name:t.Text,feature_flags:t.Opt(p)}),y=t.Variant({Upgrade:t.Opt(_),Init:f}),s=t.Nat,N=t.Record({block_range_end:s,canister_id:t.Principal,block_range_start:s}),u=t.Record({start:s,length:t.Nat}),O=t.Vec(t.Tuple(t.Text,a));a.fill(t.Variant({Int:t.Int,Map:O,Nat:t.Nat,Nat64:t.Nat64,Blob:t.Vec(t.Nat8),Text:t.Text,Array:t.Vec(a)}));let d=a,g=t.Record({blocks:t.Vec(d)}),w=t.Func([u],[g],["query"]),P=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),first_index:s,blocks:t.Vec(d),chain_length:t.Nat64,archived_blocks:t.Vec(t.Record({callback:w,start:s,length:t.Nat}))}),B=t.Record({certificate:t.Opt(t.Vec(t.Nat8)),hash_tree:t.Vec(t.Nat8)}),T=t.Nat,A=t.Record({start:T,length:t.Nat}),o=t.Nat64,E=t.Record({from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),S=t.Record({to:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat}),G=t.Record({fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),C=t.Record({to:e,fee:t.Opt(t.Nat),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,spender:t.Opt(e)}),V=t.Record({burn:t.Opt(E),kind:t.Text,mint:t.Opt(S),approve:t.Opt(G),timestamp:o,transfer:t.Opt(C)}),q=t.Record({transactions:t.Vec(V)}),U=t.Func([A],[q],["query"]),M=t.Record({first_index:T,log_length:t.Nat,transactions:t.Vec(V),archived_transactions:t.Vec(t.Record({callback:U,start:T,length:t.Nat}))}),n=t.Nat,z=t.Record({url:t.Text,name:t.Text}),Q=t.Record({to:e,fee:t.Opt(n),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(r),created_at_time:t.Opt(o),amount:n}),H=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),W=t.Variant({Ok:s,Err:H}),Z=t.Record({account:e,spender:e}),$=t.Record({allowance:t.Nat,expires_at:t.Opt(o)}),X=t.Record({fee:t.Opt(t.Nat),memo:t.Opt(t.Vec(t.Nat8)),from_subaccount:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:t.Nat,expected_allowance:t.Opt(t.Nat),expires_at:t.Opt(o),spender:e}),j=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:t.Nat}),AllowanceChanged:t.Record({current_allowance:t.Nat}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,Expired:t.Record({ledger_time:o}),InsufficientFunds:t.Record({balance:t.Nat})}),Y=t.Variant({Ok:s,Err:j}),J=t.Record({to:e,fee:t.Opt(n),spender_subaccount:t.Opt(r),from:e,memo:t.Opt(t.Vec(t.Nat8)),created_at_time:t.Opt(o),amount:n}),K=t.Variant({GenericError:t.Record({message:t.Text,error_code:t.Nat}),TemporarilyUnavailable:t.Null,InsufficientAllowance:t.Record({allowance:n}),BadBurn:t.Record({min_burn_amount:n}),Duplicate:t.Record({duplicate_of:s}),BadFee:t.Record({expected_fee:n}),CreatedInFuture:t.Record({ledger_time:o}),TooOld:t.Null,InsufficientFunds:t.Record({balance:n})}),I=t.Variant({Ok:s,Err:K});return t.Service({archives:t.Func([],[t.Vec(N)],["query"]),get_blocks:t.Func([u],[P],["query"]),get_data_certificate:t.Func([],[B],["query"]),get_transactions:t.Func([A],[M],["query"]),icrc1_balance_of:t.Func([e],[n],["query"]),icrc1_decimals:t.Func([],[t.Nat8],["query"]),icrc1_fee:t.Func([],[n],["query"]),icrc1_metadata:t.Func([],[t.Vec(t.Tuple(t.Text,c))],["query"]),icrc1_minting_account:t.Func([],[t.Opt(e)],["query"]),icrc1_name:t.Func([],[t.Text],["query"]),icrc1_supported_standards:t.Func([],[t.Vec(z)],["query"]),icrc1_symbol:t.Func([],[t.Text],["query"]),icrc1_total_supply:t.Func([],[n],["query"]),icrc1_transfer:t.Func([Q],[W],[]),icrc2_allowance:t.Func([Z],[$],["query"]),icrc2_approve:t.Func([X],[Y],[]),icrc2_transfer_from:t.Func([J],[I],[])})};var l=require("@dfinity/utils"),nt=({from_subaccount:t,fee:a,created_at_time:c,memo:r,...e})=>({...e,fee:(0,l.toNullable)(a),memo:(0,l.toNullable)(r),from_subaccount:(0,l.toNullable)(t),created_at_time:(0,l.toNullable)(c)}),st=({spender_subaccount:t,fee:a,created_at_time:c,memo:r,...e})=>({...e,fee:(0,l.toNullable)(a),memo:(0,l.toNullable)(r),spender_subaccount:(0,l.toNullable)(t),created_at_time:(0,l.toNullable)(c)}),it=({fee:t,created_at_time:a,memo:c,from_subaccount:r,expected_allowance:e,expires_at:i,...p})=>({...p,fee:(0,l.toNullable)(t),memo:(0,l.toNullable)(c),from_subaccount:(0,l.toNullable)(r),created_at_time:(0,l.toNullable)(a),expected_allowance:(0,l.toNullable)(e),expires_at:(0,l.toNullable)(i)});var v=class t extends R.Canister{constructor(){super(...arguments);this.metadata=c=>this.caller(c).icrc1_metadata();this.transactionFee=c=>this.caller(c).icrc1_fee();this.balance=c=>this.caller({certified:c.certified}).icrc1_balance_of({owner:c.owner,subaccount:(0,R.toNullable)(c.subaccount)});this.transfer=async c=>{let r=await this.caller({certified:!0}).icrc1_transfer(nt(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to transfer"});return r.Ok};this.totalTokensSupply=c=>this.caller(c).icrc1_total_supply();this.transferFrom=async c=>{let r=await this.caller({certified:!0}).icrc2_transfer_from(st(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to transfer from"});return r.Ok};this.approve=async c=>{let r=await this.caller({certified:!0}).icrc2_approve(it(c));if("Err"in r)throw new x({errorType:r.Err,msg:"Failed to entitle the spender to transfer the amount"});return r.Ok};this.allowance=async c=>{let{certified:r,...e}=c;return this.caller({certified:r}).icrc2_allowance({...e})}}static create(c){let{service:r,certifiedService:e,canisterId:i}=(0,R.createServices)({options:c,idlFactory:ot,certifiedIdlFactory:at});return new t(i,r,e)}};var pt=(i=>(i.SYMBOL="icrc1:symbol",i.NAME="icrc1:name",i.DECIMALS="icrc1:decimals",i.FEE="icrc1:fee",i.LOGO="icrc1:logo",i))(pt||{});var tt=require("@dfinity/principal"),m=require("@dfinity/utils"),gt=64,Tt=({owner:t,subaccount:a})=>{if((0,m.isNullish)(a))return t.toText();let r=(e=>e.replace(/^0+/,""))((0,m.uint8ArrayToHexString)(Uint8Array.from(a)));return r.length===0?t.toText():`${t.toText()}-${lt({owner:t,subaccount:a})}.${r}`},lt=({owner:t,subaccount:a})=>{let c=(0,m.bigEndianCrc32)(Uint8Array.from([...t.toUint8Array(),...a]));return(0,m.encodeBase32)(c)},xt=t=>{let[a,c]=t.split(".");if(!(0,m.notEmptyString)(a))throw new Error("Invalid account. No string provided.");if((0,m.isNullish)(c))return{owner:tt.Principal.fromText(t)};let[r,...e]=a.split("-").reverse(),i=e.reverse().join("-"),p={owner:tt.Principal.fromText(i),subaccount:(0,m.hexStringToUint8Array)(c.padStart(gt,"0"))};if(lt(p)!==r)throw new Error("Invalid account. Invalid checksum.");return p};var k=require("@dfinity/utils"),Rt=t=>{let a=/^([a-zA-Z]+):([A-Za-z0-9:\-.]+).*?(?:[?&](?:amount|value)=(\d+(?:\.\d+)?))?$/,c=t.match(a);if((0,k.isNullish)(c))return;let[r,e,i,p]=c;return{token:e,identifier:i,...(0,k.nonNullish)(p)&&!isNaN(parseFloat(p))&&{amount:parseFloat(p)}}};0&&(module.exports={IcrcIndexCanister,IcrcLedgerCanister,IcrcMetadataResponseEntries,IcrcTransferError,IndexError,decodeIcrcAccount,decodePayment,encodeIcrcAccount});
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,2 +1,2 @@
1
- import{Canister as I,createServices as L,toNullable as D}from"@dfinity/utils";var J=({IDL:e})=>{let s=e.Rec(),r=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),a=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(a)}),l=e.Variant({SetTo:t,Unset:e.Null}),p=e.Record({icrc2:e.Bool}),O=e.Record({token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(e.Nat),metadata:e.Opt(e.Vec(e.Tuple(e.Text,r))),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),change_fee_collector:e.Opt(l),max_memo_length:e.Opt(e.Nat16),token_name:e.Opt(e.Text),feature_flags:e.Opt(p)}),g=e.Record({decimals:e.Opt(e.Nat8),token_symbol:e.Text,transfer_fee:e.Nat,metadata:e.Vec(e.Tuple(e.Text,r)),minting_account:t,initial_balances:e.Vec(e.Tuple(t,e.Nat)),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),fee_collector_account:e.Opt(t),archive_options:e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,max_message_size_bytes:e.Opt(e.Nat64),cycles_for_archive_creation:e.Opt(e.Nat64),node_max_memory_size_bytes:e.Opt(e.Nat64),controller_id:e.Principal}),max_memo_length:e.Opt(e.Nat16),token_name:e.Text,feature_flags:e.Opt(p)}),$=e.Variant({Upgrade:e.Opt(O),Init:g}),n=e.Nat,T=e.Record({block_range_end:n,canister_id:e.Principal,block_range_start:n}),d=e.Record({start:n,length:e.Nat}),x=e.Vec(e.Tuple(e.Text,s));s.fill(e.Variant({Int:e.Int,Map:x,Nat:e.Nat,Nat64:e.Nat64,Blob:e.Vec(e.Nat8),Text:e.Text,Array:e.Vec(s)}));let u=s,R=e.Record({blocks:e.Vec(u)}),b=e.Func([d],[R],[]),V=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),first_index:n,blocks:e.Vec(u),chain_length:e.Nat64,archived_blocks:e.Vec(e.Record({callback:b,start:n,length:e.Nat}))}),y=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),hash_tree:e.Vec(e.Nat8)}),_=e.Nat,f=e.Record({start:_,length:e.Nat}),c=e.Nat64,F=e.Record({from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,spender:e.Opt(t)}),h=e.Record({to:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat}),A=e.Record({fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(c),spender:t}),k=e.Record({to:t,fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,spender:e.Opt(t)}),N=e.Record({burn:e.Opt(F),kind:e.Text,mint:e.Opt(h),approve:e.Opt(A),timestamp:c,transfer:e.Opt(k)}),v=e.Record({transactions:e.Vec(N)}),w=e.Func([f],[v],[]),B=e.Record({first_index:_,log_length:e.Nat,transactions:e.Vec(N),archived_transactions:e.Vec(e.Record({callback:w,start:_,length:e.Nat}))}),o=e.Nat,P=e.Record({url:e.Text,name:e.Text}),E=e.Record({to:t,fee:e.Opt(o),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(a),created_at_time:e.Opt(c),amount:o}),q=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),C=e.Variant({Ok:n,Err:q}),S=e.Record({account:t,spender:t}),U=e.Record({allowance:e.Nat,expires_at:e.Opt(c)}),G=e.Record({fee:e.Opt(e.Nat),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(c),spender:t}),M=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:e.Nat}),AllowanceChanged:e.Record({current_allowance:e.Nat}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,Expired:e.Record({ledger_time:c}),InsufficientFunds:e.Record({balance:e.Nat})}),z=e.Variant({Ok:n,Err:M}),Q=e.Record({to:t,fee:e.Opt(o),spender_subaccount:e.Opt(a),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:o}),j=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:o}),BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),H=e.Variant({Ok:n,Err:j});return e.Service({archives:e.Func([],[e.Vec(T)],[]),get_blocks:e.Func([d],[V],[]),get_data_certificate:e.Func([],[y],[]),get_transactions:e.Func([f],[B],[]),icrc1_balance_of:e.Func([t],[o],[]),icrc1_decimals:e.Func([],[e.Nat8],[]),icrc1_fee:e.Func([],[o],[]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,r))],[]),icrc1_minting_account:e.Func([],[e.Opt(t)],[]),icrc1_name:e.Func([],[e.Text],[]),icrc1_supported_standards:e.Func([],[e.Vec(P)],[]),icrc1_symbol:e.Func([],[e.Text],[]),icrc1_total_supply:e.Func([],[o],[]),icrc1_transfer:e.Func([E],[C],[]),icrc2_allowance:e.Func([S],[U],[]),icrc2_approve:e.Func([G],[z],[]),icrc2_transfer_from:e.Func([Q],[H],[])})};var K=({IDL:e})=>{let s=e.Rec(),r=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),a=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(a)}),l=e.Variant({SetTo:t,Unset:e.Null}),p=e.Record({icrc2:e.Bool}),O=e.Record({token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(e.Nat),metadata:e.Opt(e.Vec(e.Tuple(e.Text,r))),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),change_fee_collector:e.Opt(l),max_memo_length:e.Opt(e.Nat16),token_name:e.Opt(e.Text),feature_flags:e.Opt(p)}),g=e.Record({decimals:e.Opt(e.Nat8),token_symbol:e.Text,transfer_fee:e.Nat,metadata:e.Vec(e.Tuple(e.Text,r)),minting_account:t,initial_balances:e.Vec(e.Tuple(t,e.Nat)),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),fee_collector_account:e.Opt(t),archive_options:e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,max_message_size_bytes:e.Opt(e.Nat64),cycles_for_archive_creation:e.Opt(e.Nat64),node_max_memory_size_bytes:e.Opt(e.Nat64),controller_id:e.Principal}),max_memo_length:e.Opt(e.Nat16),token_name:e.Text,feature_flags:e.Opt(p)}),$=e.Variant({Upgrade:e.Opt(O),Init:g}),n=e.Nat,T=e.Record({block_range_end:n,canister_id:e.Principal,block_range_start:n}),d=e.Record({start:n,length:e.Nat}),x=e.Vec(e.Tuple(e.Text,s));s.fill(e.Variant({Int:e.Int,Map:x,Nat:e.Nat,Nat64:e.Nat64,Blob:e.Vec(e.Nat8),Text:e.Text,Array:e.Vec(s)}));let u=s,R=e.Record({blocks:e.Vec(u)}),b=e.Func([d],[R],["query"]),V=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),first_index:n,blocks:e.Vec(u),chain_length:e.Nat64,archived_blocks:e.Vec(e.Record({callback:b,start:n,length:e.Nat}))}),y=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),hash_tree:e.Vec(e.Nat8)}),_=e.Nat,f=e.Record({start:_,length:e.Nat}),c=e.Nat64,F=e.Record({from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,spender:e.Opt(t)}),h=e.Record({to:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat}),A=e.Record({fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(c),spender:t}),k=e.Record({to:t,fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,spender:e.Opt(t)}),N=e.Record({burn:e.Opt(F),kind:e.Text,mint:e.Opt(h),approve:e.Opt(A),timestamp:c,transfer:e.Opt(k)}),v=e.Record({transactions:e.Vec(N)}),w=e.Func([f],[v],["query"]),B=e.Record({first_index:_,log_length:e.Nat,transactions:e.Vec(N),archived_transactions:e.Vec(e.Record({callback:w,start:_,length:e.Nat}))}),o=e.Nat,P=e.Record({url:e.Text,name:e.Text}),E=e.Record({to:t,fee:e.Opt(o),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(a),created_at_time:e.Opt(c),amount:o}),q=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),C=e.Variant({Ok:n,Err:q}),S=e.Record({account:t,spender:t}),U=e.Record({allowance:e.Nat,expires_at:e.Opt(c)}),G=e.Record({fee:e.Opt(e.Nat),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(c),spender:t}),M=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:e.Nat}),AllowanceChanged:e.Record({current_allowance:e.Nat}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,Expired:e.Record({ledger_time:c}),InsufficientFunds:e.Record({balance:e.Nat})}),z=e.Variant({Ok:n,Err:M}),Q=e.Record({to:t,fee:e.Opt(o),spender_subaccount:e.Opt(a),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(c),amount:o}),j=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:o}),BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:c}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),H=e.Variant({Ok:n,Err:j});return e.Service({archives:e.Func([],[e.Vec(T)],["query"]),get_blocks:e.Func([d],[V],["query"]),get_data_certificate:e.Func([],[y],["query"]),get_transactions:e.Func([f],[B],["query"]),icrc1_balance_of:e.Func([t],[o],["query"]),icrc1_decimals:e.Func([],[e.Nat8],["query"]),icrc1_fee:e.Func([],[o],["query"]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,r))],["query"]),icrc1_minting_account:e.Func([],[e.Opt(t)],["query"]),icrc1_name:e.Func([],[e.Text],["query"]),icrc1_supported_standards:e.Func([],[e.Vec(P)],["query"]),icrc1_symbol:e.Func([],[e.Text],["query"]),icrc1_total_supply:e.Func([],[o],["query"]),icrc1_transfer:e.Func([E],[C],[]),icrc2_allowance:e.Func([S],[U],["query"]),icrc2_approve:e.Func([G],[z],[]),icrc2_transfer_from:e.Func([Q],[H],[])})};import{toNullable as i}from"@dfinity/utils";var W=({from_subaccount:e,fee:s,created_at_time:r,memo:a,...t})=>({...t,fee:i(s),memo:i(a),from_subaccount:i(e),created_at_time:i(r)}),X=({spender_subaccount:e,fee:s,created_at_time:r,memo:a,...t})=>({...t,fee:i(s),memo:i(a),spender_subaccount:i(e),created_at_time:i(r)}),Y=({fee:e,created_at_time:s,memo:r,from_subaccount:a,expected_allowance:t,expires_at:l,...p})=>({...p,fee:i(e),memo:i(r),from_subaccount:i(a),created_at_time:i(s),expected_allowance:i(t),expires_at:i(l)});var m=class extends Error{constructor({msg:r,errorType:a}){super(r);this.errorType=a}};var Z=class e extends I{constructor(){super(...arguments);this.metadata=r=>this.caller(r).icrc1_metadata();this.transactionFee=r=>this.caller(r).icrc1_fee();this.balance=r=>this.caller({certified:r.certified}).icrc1_balance_of({owner:r.owner,subaccount:D(r.subaccount)});this.transfer=async r=>{let a=await this.caller({certified:!0}).icrc1_transfer(W(r));if("Err"in a)throw new m({errorType:a.Err,msg:"Failed to transfer"});return a.Ok};this.totalTokensSupply=r=>this.caller(r).icrc1_total_supply();this.transferFrom=async r=>{let a=await this.caller({certified:!0}).icrc2_transfer_from(X(r));if("Err"in a)throw new m({errorType:a.Err,msg:"Failed to transfer from"});return a.Ok};this.approve=async r=>{let a=await this.caller({certified:!0}).icrc2_approve(Y(r));if("Err"in a)throw new m({errorType:a.Err,msg:"Failed to entitle the spender to transfer the amount"});return a.Ok};this.allowance=async r=>{let{certified:a,...t}=r;return this.caller({certified:a}).icrc2_allowance({...t})}}static create(r){let{service:a,certifiedService:t,canisterId:l}=L({options:r,idlFactory:K,certifiedIdlFactory:J});return new e(l,a,t)}};export{m as a,Z as b};
2
- //# sourceMappingURL=chunk-SEWDUW4T.js.map
1
+ import{Canister as I,createServices as L,toNullable as D}from"@dfinity/utils";var J=({IDL:e})=>{let s=e.Rec(),r=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),c=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(c)}),l=e.Variant({SetTo:t,Unset:e.Null}),p=e.Record({icrc2:e.Bool}),O=e.Record({token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(e.Nat),metadata:e.Opt(e.Vec(e.Tuple(e.Text,r))),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),change_fee_collector:e.Opt(l),max_memo_length:e.Opt(e.Nat16),token_name:e.Opt(e.Text),feature_flags:e.Opt(p)}),g=e.Record({decimals:e.Opt(e.Nat8),token_symbol:e.Text,transfer_fee:e.Nat,metadata:e.Vec(e.Tuple(e.Text,r)),minting_account:t,initial_balances:e.Vec(e.Tuple(t,e.Nat)),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),fee_collector_account:e.Opt(t),archive_options:e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,max_message_size_bytes:e.Opt(e.Nat64),cycles_for_archive_creation:e.Opt(e.Nat64),node_max_memory_size_bytes:e.Opt(e.Nat64),controller_id:e.Principal}),max_memo_length:e.Opt(e.Nat16),token_name:e.Text,feature_flags:e.Opt(p)}),$=e.Variant({Upgrade:e.Opt(O),Init:g}),n=e.Nat,T=e.Record({block_range_end:n,canister_id:e.Principal,block_range_start:n}),d=e.Record({start:n,length:e.Nat}),x=e.Vec(e.Tuple(e.Text,s));s.fill(e.Variant({Int:e.Int,Map:x,Nat:e.Nat,Nat64:e.Nat64,Blob:e.Vec(e.Nat8),Text:e.Text,Array:e.Vec(s)}));let u=s,R=e.Record({blocks:e.Vec(u)}),b=e.Func([d],[R],[]),V=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),first_index:n,blocks:e.Vec(u),chain_length:e.Nat64,archived_blocks:e.Vec(e.Record({callback:b,start:n,length:e.Nat}))}),y=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),hash_tree:e.Vec(e.Nat8)}),_=e.Nat,f=e.Record({start:_,length:e.Nat}),a=e.Nat64,F=e.Record({from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,spender:e.Opt(t)}),h=e.Record({to:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat}),A=e.Record({fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(a),spender:t}),k=e.Record({to:t,fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,spender:e.Opt(t)}),N=e.Record({burn:e.Opt(F),kind:e.Text,mint:e.Opt(h),approve:e.Opt(A),timestamp:a,transfer:e.Opt(k)}),v=e.Record({transactions:e.Vec(N)}),w=e.Func([f],[v],[]),B=e.Record({first_index:_,log_length:e.Nat,transactions:e.Vec(N),archived_transactions:e.Vec(e.Record({callback:w,start:_,length:e.Nat}))}),o=e.Nat,P=e.Record({url:e.Text,name:e.Text}),E=e.Record({to:t,fee:e.Opt(o),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(c),created_at_time:e.Opt(a),amount:o}),q=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),C=e.Variant({Ok:n,Err:q}),S=e.Record({account:t,spender:t}),U=e.Record({allowance:e.Nat,expires_at:e.Opt(a)}),G=e.Record({fee:e.Opt(e.Nat),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(a),spender:t}),M=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:e.Nat}),AllowanceChanged:e.Record({current_allowance:e.Nat}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,Expired:e.Record({ledger_time:a}),InsufficientFunds:e.Record({balance:e.Nat})}),z=e.Variant({Ok:n,Err:M}),Q=e.Record({to:t,fee:e.Opt(o),spender_subaccount:e.Opt(c),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:o}),j=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:o}),BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),H=e.Variant({Ok:n,Err:j});return e.Service({archives:e.Func([],[e.Vec(T)],[]),get_blocks:e.Func([d],[V],[]),get_data_certificate:e.Func([],[y],[]),get_transactions:e.Func([f],[B],[]),icrc1_balance_of:e.Func([t],[o],[]),icrc1_decimals:e.Func([],[e.Nat8],[]),icrc1_fee:e.Func([],[o],[]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,r))],[]),icrc1_minting_account:e.Func([],[e.Opt(t)],[]),icrc1_name:e.Func([],[e.Text],[]),icrc1_supported_standards:e.Func([],[e.Vec(P)],[]),icrc1_symbol:e.Func([],[e.Text],[]),icrc1_total_supply:e.Func([],[o],[]),icrc1_transfer:e.Func([E],[C],[]),icrc2_allowance:e.Func([S],[U],[]),icrc2_approve:e.Func([G],[z],[]),icrc2_transfer_from:e.Func([Q],[H],[])})};var K=({IDL:e})=>{let s=e.Rec(),r=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),c=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(c)}),l=e.Variant({SetTo:t,Unset:e.Null}),p=e.Record({icrc2:e.Bool}),O=e.Record({token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(e.Nat),metadata:e.Opt(e.Vec(e.Tuple(e.Text,r))),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),change_fee_collector:e.Opt(l),max_memo_length:e.Opt(e.Nat16),token_name:e.Opt(e.Text),feature_flags:e.Opt(p)}),g=e.Record({decimals:e.Opt(e.Nat8),token_symbol:e.Text,transfer_fee:e.Nat,metadata:e.Vec(e.Tuple(e.Text,r)),minting_account:t,initial_balances:e.Vec(e.Tuple(t,e.Nat)),maximum_number_of_accounts:e.Opt(e.Nat64),accounts_overflow_trim_quantity:e.Opt(e.Nat64),fee_collector_account:e.Opt(t),archive_options:e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,max_message_size_bytes:e.Opt(e.Nat64),cycles_for_archive_creation:e.Opt(e.Nat64),node_max_memory_size_bytes:e.Opt(e.Nat64),controller_id:e.Principal}),max_memo_length:e.Opt(e.Nat16),token_name:e.Text,feature_flags:e.Opt(p)}),$=e.Variant({Upgrade:e.Opt(O),Init:g}),n=e.Nat,T=e.Record({block_range_end:n,canister_id:e.Principal,block_range_start:n}),d=e.Record({start:n,length:e.Nat}),x=e.Vec(e.Tuple(e.Text,s));s.fill(e.Variant({Int:e.Int,Map:x,Nat:e.Nat,Nat64:e.Nat64,Blob:e.Vec(e.Nat8),Text:e.Text,Array:e.Vec(s)}));let u=s,R=e.Record({blocks:e.Vec(u)}),b=e.Func([d],[R],["query"]),V=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),first_index:n,blocks:e.Vec(u),chain_length:e.Nat64,archived_blocks:e.Vec(e.Record({callback:b,start:n,length:e.Nat}))}),y=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),hash_tree:e.Vec(e.Nat8)}),_=e.Nat,f=e.Record({start:_,length:e.Nat}),a=e.Nat64,F=e.Record({from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,spender:e.Opt(t)}),h=e.Record({to:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat}),A=e.Record({fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(a),spender:t}),k=e.Record({to:t,fee:e.Opt(e.Nat),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,spender:e.Opt(t)}),N=e.Record({burn:e.Opt(F),kind:e.Text,mint:e.Opt(h),approve:e.Opt(A),timestamp:a,transfer:e.Opt(k)}),v=e.Record({transactions:e.Vec(N)}),w=e.Func([f],[v],["query"]),B=e.Record({first_index:_,log_length:e.Nat,transactions:e.Vec(N),archived_transactions:e.Vec(e.Record({callback:w,start:_,length:e.Nat}))}),o=e.Nat,P=e.Record({url:e.Text,name:e.Text}),E=e.Record({to:t,fee:e.Opt(o),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(c),created_at_time:e.Opt(a),amount:o}),q=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),C=e.Variant({Ok:n,Err:q}),S=e.Record({account:t,spender:t}),U=e.Record({allowance:e.Nat,expires_at:e.Opt(a)}),G=e.Record({fee:e.Opt(e.Nat),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:e.Nat,expected_allowance:e.Opt(e.Nat),expires_at:e.Opt(a),spender:t}),M=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:e.Nat}),AllowanceChanged:e.Record({current_allowance:e.Nat}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,Expired:e.Record({ledger_time:a}),InsufficientFunds:e.Record({balance:e.Nat})}),z=e.Variant({Ok:n,Err:M}),Q=e.Record({to:t,fee:e.Opt(o),spender_subaccount:e.Opt(c),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(a),amount:o}),j=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:o}),BadBurn:e.Record({min_burn_amount:o}),Duplicate:e.Record({duplicate_of:n}),BadFee:e.Record({expected_fee:o}),CreatedInFuture:e.Record({ledger_time:a}),TooOld:e.Null,InsufficientFunds:e.Record({balance:o})}),H=e.Variant({Ok:n,Err:j});return e.Service({archives:e.Func([],[e.Vec(T)],["query"]),get_blocks:e.Func([d],[V],["query"]),get_data_certificate:e.Func([],[y],["query"]),get_transactions:e.Func([f],[B],["query"]),icrc1_balance_of:e.Func([t],[o],["query"]),icrc1_decimals:e.Func([],[e.Nat8],["query"]),icrc1_fee:e.Func([],[o],["query"]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,r))],["query"]),icrc1_minting_account:e.Func([],[e.Opt(t)],["query"]),icrc1_name:e.Func([],[e.Text],["query"]),icrc1_supported_standards:e.Func([],[e.Vec(P)],["query"]),icrc1_symbol:e.Func([],[e.Text],["query"]),icrc1_total_supply:e.Func([],[o],["query"]),icrc1_transfer:e.Func([E],[C],[]),icrc2_allowance:e.Func([S],[U],["query"]),icrc2_approve:e.Func([G],[z],[]),icrc2_transfer_from:e.Func([Q],[H],[])})};import{toNullable as i}from"@dfinity/utils";var W=({from_subaccount:e,fee:s,created_at_time:r,memo:c,...t})=>({...t,fee:i(s),memo:i(c),from_subaccount:i(e),created_at_time:i(r)}),X=({spender_subaccount:e,fee:s,created_at_time:r,memo:c,...t})=>({...t,fee:i(s),memo:i(c),spender_subaccount:i(e),created_at_time:i(r)}),Y=({fee:e,created_at_time:s,memo:r,from_subaccount:c,expected_allowance:t,expires_at:l,...p})=>({...p,fee:i(e),memo:i(r),from_subaccount:i(c),created_at_time:i(s),expected_allowance:i(t),expires_at:i(l)});var m=class extends Error{constructor({msg:s,errorType:r}){super(s),this.errorType=r}};var Z=class e extends I{constructor(){super(...arguments);this.metadata=r=>this.caller(r).icrc1_metadata();this.transactionFee=r=>this.caller(r).icrc1_fee();this.balance=r=>this.caller({certified:r.certified}).icrc1_balance_of({owner:r.owner,subaccount:D(r.subaccount)});this.transfer=async r=>{let c=await this.caller({certified:!0}).icrc1_transfer(W(r));if("Err"in c)throw new m({errorType:c.Err,msg:"Failed to transfer"});return c.Ok};this.totalTokensSupply=r=>this.caller(r).icrc1_total_supply();this.transferFrom=async r=>{let c=await this.caller({certified:!0}).icrc2_transfer_from(X(r));if("Err"in c)throw new m({errorType:c.Err,msg:"Failed to transfer from"});return c.Ok};this.approve=async r=>{let c=await this.caller({certified:!0}).icrc2_approve(Y(r));if("Err"in c)throw new m({errorType:c.Err,msg:"Failed to entitle the spender to transfer the amount"});return c.Ok};this.allowance=async r=>{let{certified:c,...t}=r;return this.caller({certified:c}).icrc2_allowance({...t})}}static create(r){let{service:c,certifiedService:t,canisterId:l}=L({options:r,idlFactory:K,certifiedIdlFactory:J});return new e(l,c,t)}};export{m as a,Z as b};
2
+ //# sourceMappingURL=chunk-UACBN2PF.js.map
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as S,b as m}from"./chunk-MJQNXPUY.js";import{a as b,b as p}from"./chunk-SEWDUW4T.js";var d=(t=>(t.SYMBOL="icrc1:symbol",t.NAME="icrc1:name",t.DECIMALS="icrc1:decimals",t.FEE="icrc1:fee",t.LOGO="icrc1:logo",t))(d||{});import{Principal as a}from"@dfinity/principal";import{bigEndianCrc32 as f,encodeBase32 as x,hexStringToUint8Array as l,isNullish as s,notEmptyString as T,uint8ArrayToHexString as I}from"@dfinity/utils";var g=64,C=({owner:r,subaccount:c})=>{if(s(c))return r.toText();let n=(i=>i.replace(/^0+/,""))(I(Uint8Array.from(c)));return n.length===0?r.toText():`${r.toText()}-${u({owner:r,subaccount:c})}.${n}`},u=({owner:r,subaccount:c})=>{let e=f(Uint8Array.from([...r.toUint8Array(),...c]));return x(e)},E=r=>{let[c,e]=r.split(".");if(!T(c))throw new Error("Invalid account. No string provided.");if(s(e))return{owner:a.fromText(r)};let[n,...i]=c.split("-").reverse(),t=i.reverse().join("-"),o={owner:a.fromText(t),subaccount:l(e.padStart(g,"0"))};if(u(o)!==n)throw new Error("Invalid account. Invalid checksum.");return o};import{isNullish as A,nonNullish as y}from"@dfinity/utils";var U=r=>{let c=/^([a-zA-Z]+):([A-Za-z0-9:\-.]+).*?(?:[?&](?:amount|value)=(\d+(?:\.\d+)?))?$/,e=r.match(c);if(A(e))return;let[n,i,t,o]=e;return{token:i,identifier:t,...y(o)&&!isNaN(parseFloat(o))&&{amount:parseFloat(o)}}};export{m as IcrcIndexCanister,p as IcrcLedgerCanister,d as IcrcMetadataResponseEntries,b as IcrcTransferError,S as IndexError,E as decodeIcrcAccount,U as decodePayment,C as encodeIcrcAccount};
1
+ import{a as S,b as m}from"./chunk-MJQNXPUY.js";import{a as b,b as p}from"./chunk-UACBN2PF.js";var d=(t=>(t.SYMBOL="icrc1:symbol",t.NAME="icrc1:name",t.DECIMALS="icrc1:decimals",t.FEE="icrc1:fee",t.LOGO="icrc1:logo",t))(d||{});import{Principal as a}from"@dfinity/principal";import{bigEndianCrc32 as f,encodeBase32 as x,hexStringToUint8Array as l,isNullish as s,notEmptyString as T,uint8ArrayToHexString as I}from"@dfinity/utils";var g=64,C=({owner:r,subaccount:c})=>{if(s(c))return r.toText();let n=(i=>i.replace(/^0+/,""))(I(Uint8Array.from(c)));return n.length===0?r.toText():`${r.toText()}-${u({owner:r,subaccount:c})}.${n}`},u=({owner:r,subaccount:c})=>{let e=f(Uint8Array.from([...r.toUint8Array(),...c]));return x(e)},E=r=>{let[c,e]=r.split(".");if(!T(c))throw new Error("Invalid account. No string provided.");if(s(e))return{owner:a.fromText(r)};let[n,...i]=c.split("-").reverse(),t=i.reverse().join("-"),o={owner:a.fromText(t),subaccount:l(e.padStart(g,"0"))};if(u(o)!==n)throw new Error("Invalid account. Invalid checksum.");return o};import{isNullish as A,nonNullish as y}from"@dfinity/utils";var U=r=>{let c=/^([a-zA-Z]+):([A-Za-z0-9:\-.]+).*?(?:[?&](?:amount|value)=(\d+(?:\.\d+)?))?$/,e=r.match(c);if(A(e))return;let[n,i,t,o]=e;return{token:i,identifier:t,...y(o)&&!isNaN(parseFloat(o))&&{amount:parseFloat(o)}}};export{m as IcrcIndexCanister,p as IcrcLedgerCanister,d as IcrcMetadataResponseEntries,b as IcrcTransferError,S as IndexError,E as decodeIcrcAccount,U as decodePayment,C as encodeIcrcAccount};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{b as a}from"./chunk-SEWDUW4T.js";export{a as IcrcLedgerCanister};
1
+ import{b as a}from"./chunk-UACBN2PF.js";export{a as IcrcLedgerCanister};
2
2
  //# sourceMappingURL=ledger.canister.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/ledger-icrc",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "A library for interfacing with ICRC ledgers on the Internet Computer.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/cjs/index.cjs.js",
@@ -40,6 +40,6 @@
40
40
  "@dfinity/agent": "^0.20.2",
41
41
  "@dfinity/candid": "^0.20.2",
42
42
  "@dfinity/principal": "^0.20.2",
43
- "@dfinity/utils": "^2.1.0"
43
+ "@dfinity/utils": "^2.1.1"
44
44
  }
45
45
  }