UNPKG

@dfinity/ledger-icrc

Version:

A library for interfacing with ICRC ledgers on the Internet Computer.

3 lines (2 loc) 2.5 kB
import{a as f}from"./chunk-QSOCC3T6.js";import"./chunk-6GLYJI63.js";import{a as u}from"./chunk-A77UW7FO.js";import{b as M}from"./chunk-42OX77TJ.js";import{a as N,b as h,c as S,d as C,e as L,f as O,g as B,h as F,i as P,j as U,k as _,l as x}from"./chunk-RQUD6I43.js";var s=(e=>(e.SYMBOL="icrc1:symbol",e.NAME="icrc1:name",e.DECIMALS="icrc1:decimals",e.FEE="icrc1:fee",e.LOGO="icrc1:logo",e))(s||{});import{Principal as p}from"@dfinity/principal";import{bigEndianCrc32 as T,encodeBase32 as l,hexStringToUint8Array as I,isNullish as m,nonNullish as a,notEmptyString as g,uint8ArrayToHexString as y}from"@dfinity/utils";var k=64,$=({owner:t,subaccount:n})=>{if(m(n))return t.toText();let r=(c=>c.replace(/^0+/,""))(y(Uint8Array.from(n)));return r.length===0?t.toText():`${t.toText()}-${d({owner:t,subaccount:n})}.${r}`},d=({owner:t,subaccount:n})=>{let o=T(Uint8Array.from([...t.toUint8Array(),...n]));return l(o)},G=t=>{let[n,o]=t.split(".");if(!g(n))throw new Error("Invalid account. No string provided.");if(m(o))return{owner:p.fromText(t)};let[r,...c]=n.split("-").reverse(),e=c.reverse().join("-"),i={owner:p.fromText(e),subaccount:I(o.padStart(k,"0"))};if(d(i)!==r)throw new Error("Invalid account. Invalid checksum.");return i},v=t=>{let n=t.reduce((r,[c,e])=>{switch(c){case"icrc1:symbol":r={...r,..."Text"in e&&{symbol:e.Text}};break;case"icrc1:name":r={...r,..."Text"in e&&{name:e.Text}};break;case"icrc1:fee":r={...r,..."Nat"in e&&{fee:e.Nat}};break;case"icrc1:decimals":r={...r,..."Nat"in e&&{decimals:Number(e.Nat)}};break;case"icrc1:logo":r={...r,..."Text"in e&&{icon:e.Text}}}return r},{});if((r=>a(r.symbol)&&a(r.name)&&a(r.fee)&&a(r.decimals))(n))return n};import{isNullish as A,nonNullish as b}from"@dfinity/utils";var X=t=>{let n=/^([a-zA-Z]+):([A-Za-z0-9:\-.]+).*?(?:[?&](?:amount|value)=(\d+(?:\.\d+)?))?$/,o=t.match(n);if(A(o))return;let[r,c,e,i]=o;return{token:c,identifier:e,...b(i)&&!isNaN(parseFloat(i))&&{amount:parseFloat(i)}}};export{B as ConsentMessageError,U as ConsentMessageUnavailableError,O as GenericError,u as IcrcIndexCanister,f as IcrcIndexNgCanister,x as IcrcLedgerCanister,s as IcrcMetadataResponseEntries,L as IcrcTransferError,M as IndexError,F as InsufficientPaymentError,P as UnsupportedCanisterCallError,G as decodeIcrcAccount,X as decodePayment,$ as encodeIcrcAccount,_ as mapIcrc21ConsentMessageError,v as mapTokenMetadata,S as toApproveArgs,C as toIcrc21ConsentMessageArgs,N as toTransferArg,h as toTransferFromArgs}; //# sourceMappingURL=index.js.map