UNPKG

@dfinity/ledger-icp

Version:

A library for interfacing with the ICP ledger on the Internet Computer.

13 lines (10 loc) 31.3 kB
"use strict";var We=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Nt=Object.prototype.hasOwnProperty;var Ot=(e,r)=>{for(var t in r)We(e,t,{get:r[t],enumerable:!0})},wt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let c of At(r))!Nt.call(e,c)&&c!==t&&We(e,c,{get:()=>r[c],enumerable:!(n=Tt(r,c))||n.enumerable});return e};var Ft=e=>wt(We({},"__esModule",{value:!0}),e);var Pt={};Ot(Pt,{AccountIdentifier:()=>V,AllowanceChangedError:()=>te,ApproveError:()=>T,BadFeeError:()=>G,ConsentMessageError:()=>C,ConsentMessageUnavailableError:()=>ae,CreatedInFutureError:()=>re,DuplicateError:()=>ee,ExpiredError:()=>ce,GenericError:()=>X,IcrcError:()=>U,IndexCanister:()=>ue,InsufficientFundsError:()=>S,InsufficientPaymentError:()=>oe,InvalidAccountIDError:()=>P,InvalidSenderError:()=>tt,LedgerCanister:()=>de,SubAccount:()=>z,TemporarilyUnavailableError:()=>L,TooOldError:()=>ne,TransferError:()=>N,TxCreatedInFutureError:()=>W,TxDuplicateError:()=>J,TxTooOldError:()=>j,UnsupportedCanisterCallError:()=>se,accountIdentifierFromBytes:()=>qt,accountIdentifierToBytes:()=>Et,checkAccountId:()=>bt,isIcpAccountIdentifier:()=>Ct,mapIcrc1TransferError:()=>nt,mapIcrc21ConsentMessageError:()=>ot,mapIcrc2ApproveError:()=>ct,mapTransferError:()=>rt,principalToAccountIdentifier:()=>Ut,toIcrc1TransferRawRequest:()=>De,toIcrc21ConsentMessageRawRequest:()=>et,toIcrc2ApproveRawRequest:()=>Le,toTransferRawRequest:()=>Ie});module.exports=Ft(Pt);var k=require("@dfinity/utils");function Vt(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Je(e,...r){if(!Vt(e))throw new Error("Uint8Array expected");if(r.length>0&&!r.includes(e.length))throw new Error(`Uint8Array expected of length ${r}, not of length=${e.length}`)}function Xe(e,r=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(r&&e.finished)throw new Error("Hash#digest() has already been called")}function ut(e,r){Je(e);let t=r.outputLen;if(e.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Y=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),b=(e,r)=>e<<32-r|e>>>r;var Ht=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function kt(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ke(e){return typeof e=="string"&&(e=kt(e)),Je(e),e}var K=class{clone(){return this._cloneInto()}},$t={}.toString;function dt(e){let r=n=>e().update(Ke(n)).digest(),t=e();return r.outputLen=t.outputLen,r.blockLen=t.blockLen,r.create=()=>e(),r}function Bt(e,r,t,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(r,t,n);let c=BigInt(32),o=BigInt(4294967295),s=Number(t>>c&o),u=Number(t&o),d=n?4:0,p=n?0:4;e.setUint32(r+d,s,n),e.setUint32(r+p,u,n)}var pt=(e,r,t)=>e&r^~e&t,lt=(e,r,t)=>e&r^e&t^r&t,Z=class extends K{constructor(r,t,n,c){super(),this.blockLen=r,this.outputLen=t,this.padOffset=n,this.isLE=c,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(r),this.view=Y(this.buffer)}update(r){Xe(this);let{view:t,buffer:n,blockLen:c}=this;r=Ke(r);let o=r.length;for(let s=0;s<o;){let u=Math.min(c-this.pos,o-s);if(u===c){let d=Y(r);for(;c<=o-s;s+=c)this.process(d,s);continue}n.set(r.subarray(s,s+u),this.pos),this.pos+=u,s+=u,this.pos===c&&(this.process(t,0),this.pos=0)}return this.length+=r.length,this.roundClean(),this}digestInto(r){Xe(this),ut(r,this),this.finished=!0;let{buffer:t,view:n,blockLen:c,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>c-s&&(this.process(n,0),s=0);for(let a=s;a<c;a++)t[a]=0;Bt(n,c-8,BigInt(this.length*8),o),this.process(n,0);let u=Y(r),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let p=d/4,_=this.get();if(p>_.length)throw new Error("_sha2: outputLen bigger than state");for(let a=0;a<p;a++)u.setUint32(4*a,_[a],o)}digest(){let{buffer:r,outputLen:t}=this;this.digestInto(r);let n=r.slice(0,t);return this.destroy(),n}_cloneInto(r){r||(r=new this.constructor),r.set(...this.get());let{blockLen:t,buffer:n,length:c,finished:o,destroyed:s,pos:u}=this;return r.length=c,r.pos=u,r.finished=o,r.destroyed=s,c%t&&r.buffer.set(n),r}};var vt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),w=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),F=new Uint32Array(64),Ye=class extends Z{constructor(){super(64,32,8,!1),this.A=w[0]|0,this.B=w[1]|0,this.C=w[2]|0,this.D=w[3]|0,this.E=w[4]|0,this.F=w[5]|0,this.G=w[6]|0,this.H=w[7]|0}get(){let{A:r,B:t,C:n,D:c,E:o,F:s,G:u,H:d}=this;return[r,t,n,c,o,s,u,d]}set(r,t,n,c,o,s,u,d){this.A=r|0,this.B=t|0,this.C=n|0,this.D=c|0,this.E=o|0,this.F=s|0,this.G=u|0,this.H=d|0}process(r,t){for(let a=0;a<16;a++,t+=4)F[a]=r.getUint32(t,!1);for(let a=16;a<64;a++){let x=F[a-15],m=F[a-2],A=b(x,7)^b(x,18)^x>>>3,R=b(m,17)^b(m,19)^m>>>10;F[a]=R+F[a-7]+A+F[a-16]|0}let{A:n,B:c,C:o,D:s,E:u,F:d,G:p,H:_}=this;for(let a=0;a<64;a++){let x=b(u,6)^b(u,11)^b(u,25),m=_+x+pt(u,d,p)+vt[a]+F[a]|0,R=(b(n,2)^b(n,13)^b(n,22))+lt(n,c,o)|0;_=p,p=d,d=u,u=s+m|0,s=o,o=c,c=n,n=m+R|0}n=n+this.A|0,c=c+this.B|0,o=o+this.C|0,s=s+this.D|0,u=u+this.E|0,d=d+this.F|0,p=p+this.G|0,_=_+this.H|0,this.set(n,c,o,s,u,d,p,_)}roundClean(){F.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Ze=class extends Ye{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};var I=dt(()=>new Ze);var V=class e{constructor(r){this.bytes=r}static fromHex(r){return new e(Uint8Array.from(Buffer.from(r,"hex")))}static fromPrincipal({principal:r,subAccount:t=z.fromID(0)}){let n=(0,k.asciiStringToByteArray)(` account-id`),c=I.create();c.update((0,k.arrayOfNumberToUint8Array)([...n,...r.toUint8Array(),...t.toUint8Array()]));let o=c.digest(),s=(0,k.bigEndianCrc32)(o),u=new Uint8Array([...s,...o]);return new e(u)}toHex(){return(0,k.uint8ArrayToHexString)(this.bytes)}toUint8Array(){return this.bytes}toNumbers(){return Array.from(this.bytes)}toAccountIdentifierHash(){return{hash:this.toUint8Array()}}},z=class e{constructor(r){this.bytes=r}static fromBytes(r){return r.length!=32?Error("Subaccount length must be 32-bytes"):new e(r)}static fromPrincipal(r){let t=new Uint8Array(32).fill(0),n=r.toUint8Array();t[0]=n.length;for(let c=0;c<n.length;c++)t[1+c]=n[c];return new e(t)}static fromID(r){if(r<0)throw new Error("Number cannot be negative");if(r>Number.MAX_SAFE_INTEGER)throw new Error("Number is too large to fit in 32 bytes.");let t=new DataView(new ArrayBuffer(32));if(typeof t.setBigUint64=="function")t.setBigUint64(24,BigInt(r));else{let c=BigInt(1)<<BigInt(32);t.setUint32(24,Number(BigInt(r)>>BigInt(32))),t.setUint32(28,Number(BigInt(r)%c))}let n=new Uint8Array(t.buffer);return new e(n)}toUint8Array(){return this.bytes}};var l=require("@dfinity/utils");var It=BigInt(1095062083),Dt=BigInt(1347768404),D=BigInt(1e4),Lt=BigInt(1e8);var ft=e=>({e8s:e}),Ie=({to:e,amount:r,memo:t,fee:n,fromSubAccount:c,createdAt:o})=>({to:e.toUint8Array(),fee:ft(n??D),amount:ft(r),memo:t??BigInt(0),created_at_time:o!==void 0?[{timestamp_nanos:o}]:[],from_subaccount:c===void 0?[]:[(0,l.arrayOfNumberToUint8Array)(c)]}),De=({fromSubAccount:e,to:r,amount:t,fee:n,icrc1Memo:c,createdAt:o})=>({to:r,fee:(0,l.toNullable)(n??D),amount:t,memo:(0,l.toNullable)(c),created_at_time:(0,l.toNullable)(o),from_subaccount:(0,l.toNullable)(e)}),Le=({fee:e,createdAt:r,icrc1Memo:t,fromSubAccount:n,expected_allowance:c,expires_at:o,amount:s,...u})=>({...u,fee:(0,l.toNullable)(e??D),memo:(0,l.toNullable)(t),from_subaccount:(0,l.toNullable)(n),created_at_time:(0,l.toNullable)(r),amount:s,expected_allowance:(0,l.toNullable)(c),expires_at:(0,l.toNullable)(o)}),et=({userPreferences:{metadata:{utcOffsetMinutes:e,language:r},deriveSpec:t},...n})=>({...n,user_preferences:{metadata:{language:r,utc_offset_minutes:(0,l.toNullable)(e)},device_spec:(0,l.isNullish)(t)?(0,l.toNullable)():(0,l.toNullable)("GenericDisplay"in t?{GenericDisplay:null}:{LineDisplay:{characters_per_line:t.LineDisplay.charactersPerLine,lines_per_page:t.LineDisplay.linesPerPage}})}});var U=class extends Error{},N=class extends U{},T=class extends U{},C=class extends U{},tt=class extends N{},P=class extends Error{},S=class extends N{constructor(t){super();this.balance=t}},j=class extends N{constructor(t){super();this.allowed_window_secs=t}},W=class extends N{},J=class extends N{constructor(t){super();this.duplicateOf=t}},G=class extends U{constructor(t){super();this.expectedFee=t}},X=class extends T{constructor(t,n){super();this.message=t;this.error_code=n}},L=class extends T{},ee=class extends T{constructor(t){super();this.duplicateOf=t}},te=class extends T{constructor(t){super();this.currentAllowance=t}},re=class extends T{},ne=class extends T{},ce=class extends T{constructor(t){super();this.ledgerTime=t}},oe=class extends C{},se=class extends C{},ae=class extends C{},rt=e=>"TxDuplicate"in e?new J(e.TxDuplicate.duplicate_of):"InsufficientFunds"in e?new S(e.InsufficientFunds.balance.e8s):"TxCreatedInFuture"in e?new W:"TxTooOld"in e?new j(Number(e.TxTooOld.allowed_window_nanos)):"BadFee"in e?new G(e.BadFee.expected_fee.e8s):new N(`Unknown error type ${JSON.stringify(e)}`),nt=e=>"Duplicate"in e?new J(e.Duplicate.duplicate_of):"InsufficientFunds"in e?new S(e.InsufficientFunds.balance):"CreatedInFuture"in e?new W:"TooOld"in e?new j:"BadFee"in e?new G(e.BadFee.expected_fee):new N(`Unknown error type ${JSON.stringify(e)}`),ct=e=>"GenericError"in e?new X(e.GenericError.message,e.GenericError.error_code):"TemporarilyUnavailable"in e?new L:"Duplicate"in e?new ee(e.Duplicate.duplicate_of):"BadFee"in e?new G(e.BadFee.expected_fee):"AllowanceChanged"in e?new te(e.AllowanceChanged.current_allowance):"CreatedInFuture"in e?new re:"TooOld"in e?new ne:"Expired"in e?new ce(e.Expired.ledger_time):"InsufficientFunds"in e?new S(e.InsufficientFunds.balance):new T(`Unknown error type ${JSON.stringify(e)}`),ot=e=>"GenericError"in e?new X(e.GenericError.description,e.GenericError.error_code):"InsufficientPayment"in e?new oe(e.InsufficientPayment.description):"UnsupportedCanisterCall"in e?new se(e.UnsupportedCanisterCall.description):"ConsentMessageUnavailable"in e?new ae(e.ConsentMessageUnavailable.description):new C(`Unknown error type ${JSON.stringify(e)}`);var M=require("@dfinity/utils");var _t=({IDL:e})=>{let r=e.Record({ledger_id:e.Principal}),t=e.Record({max_results:e.Nat64,start:e.Opt(e.Nat64),account_identifier:e.Text}),n=e.Record({e8s:e.Nat64}),c=e.Record({timestamp_nanos:e.Nat64}),o=e.Variant({Approve:e.Record({fee:n,from:e.Text,allowance:n,expected_allowance:e.Opt(n),expires_at:e.Opt(c),spender:e.Text}),Burn:e.Record({from:e.Text,amount:n,spender:e.Opt(e.Text)}),Mint:e.Record({to:e.Text,amount:n}),Transfer:e.Record({to:e.Text,fee:n,from:e.Text,amount:n,spender:e.Opt(e.Text)})}),s=e.Record({memo:e.Nat64,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:o,timestamp:e.Opt(c),created_at_time:e.Opt(c)}),u=e.Record({id:e.Nat64,transaction:s}),d=e.Record({balance:e.Nat64,transactions:e.Vec(u),oldest_tx_id:e.Opt(e.Nat64)}),p=e.Record({message:e.Text}),_=e.Variant({Ok:d,Err:p}),a=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),x=e.Record({max_results:e.Nat,start:e.Opt(e.Nat),account:a}),m=e.Record({start:e.Nat,length:e.Nat}),A=e.Record({blocks:e.Vec(e.Vec(e.Nat8)),chain_length:e.Nat64}),R=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text))}),i=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),status_code:e.Nat16}),v=e.Record({num_blocks_synced:e.Nat64});return e.Service({get_account_identifier_balance:e.Func([e.Text],[e.Nat64],[]),get_account_identifier_transactions:e.Func([t],[_],[]),get_account_transactions:e.Func([x],[_],[]),get_blocks:e.Func([m],[A],[]),http_request:e.Func([R],[i],[]),icrc1_balance_of:e.Func([a],[e.Nat64],[]),ledger_id:e.Func([],[e.Principal],[]),status:e.Func([],[v],[])})};var mt=({IDL:e})=>{let r=e.Record({ledger_id:e.Principal}),t=e.Record({max_results:e.Nat64,start:e.Opt(e.Nat64),account_identifier:e.Text}),n=e.Record({e8s:e.Nat64}),c=e.Record({timestamp_nanos:e.Nat64}),o=e.Variant({Approve:e.Record({fee:n,from:e.Text,allowance:n,expected_allowance:e.Opt(n),expires_at:e.Opt(c),spender:e.Text}),Burn:e.Record({from:e.Text,amount:n,spender:e.Opt(e.Text)}),Mint:e.Record({to:e.Text,amount:n}),Transfer:e.Record({to:e.Text,fee:n,from:e.Text,amount:n,spender:e.Opt(e.Text)})}),s=e.Record({memo:e.Nat64,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:o,timestamp:e.Opt(c),created_at_time:e.Opt(c)}),u=e.Record({id:e.Nat64,transaction:s}),d=e.Record({balance:e.Nat64,transactions:e.Vec(u),oldest_tx_id:e.Opt(e.Nat64)}),p=e.Record({message:e.Text}),_=e.Variant({Ok:d,Err:p}),a=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),x=e.Record({max_results:e.Nat,start:e.Opt(e.Nat),account:a}),m=e.Record({start:e.Nat,length:e.Nat}),A=e.Record({blocks:e.Vec(e.Vec(e.Nat8)),chain_length:e.Nat64}),R=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text))}),i=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),status_code:e.Nat16}),v=e.Record({num_blocks_synced:e.Nat64});return e.Service({get_account_identifier_balance:e.Func([e.Text],[e.Nat64],["query"]),get_account_identifier_transactions:e.Func([t],[_],["query"]),get_account_transactions:e.Func([x],[_],["query"]),get_blocks:e.Func([m],[A],["query"]),http_request:e.Func([R],[i],["query"]),icrc1_balance_of:e.Func([a],[e.Nat64],["query"]),ledger_id:e.Func([],[e.Principal],["query"]),status:e.Func([],[v],["query"])})};var st=require("@dfinity/principal"),xt=st.Principal.fromText("ryjl3-tyaaa-aaaaa-aaaba-cai"),gt=st.Principal.fromText("qhbym-qaaaa-aaaaa-aaafq-cai");var ie=class extends Error{};var yt=e=>e instanceof V?e:V.fromHex(e),at=e=>e instanceof V?e.toHex():e;var ue=class e extends M.Canister{constructor(){super(...arguments);this.accountBalance=({certified:t,accountIdentifier:n})=>this.caller({certified:t}).get_account_identifier_balance(at(n));this.getTransactions=async({certified:t,accountIdentifier:n,start:c,maxResults:o})=>{let s=await this.caller({certified:t}).get_account_identifier_transactions({account_identifier:at(n),start:(0,M.toNullable)(c),max_results:o});if("Err"in s)throw new ie(s.Err.message);return s.Ok}}static create({canisterId:t,...n}){let{service:c,certifiedService:o,canisterId:s}=(0,M.createServices)({options:{...n,canisterId:t??gt},idlFactory:mt,certifiedIdlFactory:_t});return new e(s,c,o)}};var pe=require("@dfinity/utils");var Rt=({IDL:e})=>{let r=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(r)}),n=e.Record({icrc2:e.Bool}),c=e.Record({icrc1_minting_account:e.Opt(t),feature_flags:e.Opt(n)}),o=e.Record({e8s:e.Nat64}),s=e.Text,u=e.Record({secs:e.Nat64,nanos:e.Nat32}),d=e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,more_controller_ids:e.Opt(e.Vec(e.Principal)),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}),p=e.Record({send_whitelist:e.Vec(e.Principal),token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(o),minting_account:s,transaction_window:e.Opt(u),max_message_size_bytes:e.Opt(e.Nat64),icrc1_minting_account:e.Opt(t),archive_options:e.Opt(d),initial_values:e.Vec(e.Tuple(s,o)),token_name:e.Opt(e.Text),feature_flags:e.Opt(n)}),_=e.Variant({Upgrade:e.Opt(c),Init:p}),a=e.Vec(e.Nat8),x=e.Record({account:a}),m=e.Record({account:s}),A=e.Record({canister_id:e.Principal}),R=e.Record({archives:e.Vec(A)}),i=e.Nat,v=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),g=e.Nat64,fe=e.Record({to:t,fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(r),created_at_time:e.Opt(g),amount:i}),y=e.Nat,_e=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:i}),Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:e.Nat64}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),me=e.Variant({Ok:y,Err:_e}),H=e.Record({utc_offset_minutes:e.Opt(e.Int16),language:e.Text}),xe=e.Record({metadata:H,device_spec:e.Opt(e.Variant({GenericDisplay:e.Null,LineDisplay:e.Record({characters_per_line:e.Nat16,lines_per_page:e.Nat16})}))}),ge=e.Record({arg:e.Vec(e.Nat8),method:e.Text,user_preferences:xe}),ye=e.Variant({LineDisplayMessage:e.Record({pages:e.Vec(e.Record({lines:e.Vec(e.Text)}))}),GenericDisplayMessage:e.Text}),Re=e.Record({metadata:H,consent_message:ye}),E=e.Record({description:e.Text}),he=e.Variant({GenericError:e.Record({description:e.Text,error_code:e.Nat}),InsufficientPayment:E,UnsupportedCanisterCall:E,ConsentMessageUnavailable:E}),be=e.Variant({Ok:Re,Err:he}),Te=e.Record({account:t,spender:t}),Ae=e.Record({allowance:i,expires_at:e.Opt(g)}),Ne=e.Record({fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(r),created_at_time:e.Opt(g),amount:i,expected_allowance:e.Opt(i),expires_at:e.Opt(g),spender:t}),Oe=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),AllowanceChanged:e.Record({current_allowance:i}),CreatedInFuture:e.Record({ledger_time:e.Nat64}),TooOld:e.Null,Expired:e.Record({ledger_time:e.Nat64}),InsufficientFunds:e.Record({balance:i})}),we=e.Variant({Ok:y,Err:Oe}),Fe=e.Record({to:t,fee:e.Opt(i),spender_subaccount:e.Opt(r),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(g),amount:i}),Ve=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:i}),BadBurn:e.Record({min_burn_amount:i}),Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:g}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),ke=e.Variant({Ok:y,Err:Ve}),f=e.Nat64,O=e.Record({start:f,length:e.Nat64}),q=e.Nat64,h=e.Record({timestamp_nanos:e.Nat64}),Be=e.Variant({Approve:e.Record({fee:o,from:a,allowance_e8s:e.Int,allowance:o,expected_allowance:e.Opt(o),expires_at:e.Opt(h),spender:a}),Burn:e.Record({from:a,amount:o,spender:e.Opt(a)}),Mint:e.Record({to:a,amount:o}),Transfer:e.Record({to:a,fee:o,from:a,amount:o,spender:e.Opt(e.Vec(e.Nat8))})}),ve=e.Record({memo:q,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:e.Opt(Be),created_at_time:h}),$=e.Record({transaction:ve,timestamp:h,parent_hash:e.Opt(e.Vec(e.Nat8))}),Ee=e.Record({blocks:e.Vec($)}),Q=e.Variant({BadFirstBlockIndex:e.Record({requested_index:f,first_valid_index:f}),Other:e.Record({error_message:e.Text,error_code:e.Nat64})}),qe=e.Variant({Ok:Ee,Err:Q}),Ue=e.Func([O],[qe],[]),Ce=e.Record({callback:Ue,start:f,length:e.Nat64}),Pe=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec($),chain_length:e.Nat64,first_block_index:f,archived_blocks:e.Vec(Ce)}),Se=e.Record({callback:e.Func([O],[e.Variant({Ok:e.Vec(e.Vec(e.Nat8)),Err:Q})],[]),start:e.Nat64,length:e.Nat64}),Ge=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec(e.Vec(e.Nat8)),chain_length:e.Nat64,first_block_index:e.Nat64,archived_blocks:e.Vec(Se)}),Me=e.Record({to:s,fee:o,memo:q,from_subaccount:e.Opt(r),created_at_time:e.Opt(h),amount:o}),He=e.Record({to:a,fee:o,memo:q,from_subaccount:e.Opt(r),created_at_time:e.Opt(h),amount:o}),$e=e.Variant({TxTooOld:e.Record({allowed_window_nanos:e.Nat64}),BadFee:e.Record({expected_fee:o}),TxDuplicate:e.Record({duplicate_of:f}),TxCreatedInFuture:e.Null,InsufficientFunds:e.Record({balance:o})}),Qe=e.Variant({Ok:f,Err:$e}),ze=e.Record({}),je=e.Record({transfer_fee:o});return e.Service({account_balance:e.Func([x],[o],[]),account_balance_dfx:e.Func([m],[o],[]),account_identifier:e.Func([t],[a],[]),archives:e.Func([],[R],[]),decimals:e.Func([],[e.Record({decimals:e.Nat32})],[]),icrc10_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],[]),icrc1_balance_of:e.Func([t],[i],[]),icrc1_decimals:e.Func([],[e.Nat8],[]),icrc1_fee:e.Func([],[i],[]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,v))],[]),icrc1_minting_account:e.Func([],[e.Opt(t)],[]),icrc1_name:e.Func([],[e.Text],[]),icrc1_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],[]),icrc1_symbol:e.Func([],[e.Text],[]),icrc1_total_supply:e.Func([],[i],[]),icrc1_transfer:e.Func([fe],[me],[]),icrc21_canister_call_consent_message:e.Func([ge],[be],[]),icrc2_allowance:e.Func([Te],[Ae],[]),icrc2_approve:e.Func([Ne],[we],[]),icrc2_transfer_from:e.Func([Fe],[ke],[]),is_ledger_ready:e.Func([],[e.Bool],[]),name:e.Func([],[e.Record({name:e.Text})],[]),query_blocks:e.Func([O],[Pe],[]),query_encoded_blocks:e.Func([O],[Ge],[]),send_dfx:e.Func([Me],[f],[]),symbol:e.Func([],[e.Record({symbol:e.Text})],[]),transfer:e.Func([He],[Qe],[]),transfer_fee:e.Func([ze],[je],[])})};var ht=({IDL:e})=>{let r=e.Vec(e.Nat8),t=e.Record({owner:e.Principal,subaccount:e.Opt(r)}),n=e.Record({icrc2:e.Bool}),c=e.Record({icrc1_minting_account:e.Opt(t),feature_flags:e.Opt(n)}),o=e.Record({e8s:e.Nat64}),s=e.Text,u=e.Record({secs:e.Nat64,nanos:e.Nat32}),d=e.Record({num_blocks_to_archive:e.Nat64,max_transactions_per_response:e.Opt(e.Nat64),trigger_threshold:e.Nat64,more_controller_ids:e.Opt(e.Vec(e.Principal)),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}),p=e.Record({send_whitelist:e.Vec(e.Principal),token_symbol:e.Opt(e.Text),transfer_fee:e.Opt(o),minting_account:s,transaction_window:e.Opt(u),max_message_size_bytes:e.Opt(e.Nat64),icrc1_minting_account:e.Opt(t),archive_options:e.Opt(d),initial_values:e.Vec(e.Tuple(s,o)),token_name:e.Opt(e.Text),feature_flags:e.Opt(n)}),_=e.Variant({Upgrade:e.Opt(c),Init:p}),a=e.Vec(e.Nat8),x=e.Record({account:a}),m=e.Record({account:s}),A=e.Record({canister_id:e.Principal}),R=e.Record({archives:e.Vec(A)}),i=e.Nat,v=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),g=e.Nat64,fe=e.Record({to:t,fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(r),created_at_time:e.Opt(g),amount:i}),y=e.Nat,_e=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,BadBurn:e.Record({min_burn_amount:i}),Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:e.Nat64}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),me=e.Variant({Ok:y,Err:_e}),H=e.Record({utc_offset_minutes:e.Opt(e.Int16),language:e.Text}),xe=e.Record({metadata:H,device_spec:e.Opt(e.Variant({GenericDisplay:e.Null,LineDisplay:e.Record({characters_per_line:e.Nat16,lines_per_page:e.Nat16})}))}),ge=e.Record({arg:e.Vec(e.Nat8),method:e.Text,user_preferences:xe}),ye=e.Variant({LineDisplayMessage:e.Record({pages:e.Vec(e.Record({lines:e.Vec(e.Text)}))}),GenericDisplayMessage:e.Text}),Re=e.Record({metadata:H,consent_message:ye}),E=e.Record({description:e.Text}),he=e.Variant({GenericError:e.Record({description:e.Text,error_code:e.Nat}),InsufficientPayment:E,UnsupportedCanisterCall:E,ConsentMessageUnavailable:E}),be=e.Variant({Ok:Re,Err:he}),Te=e.Record({account:t,spender:t}),Ae=e.Record({allowance:i,expires_at:e.Opt(g)}),Ne=e.Record({fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(r),created_at_time:e.Opt(g),amount:i,expected_allowance:e.Opt(i),expires_at:e.Opt(g),spender:t}),Oe=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),AllowanceChanged:e.Record({current_allowance:i}),CreatedInFuture:e.Record({ledger_time:e.Nat64}),TooOld:e.Null,Expired:e.Record({ledger_time:e.Nat64}),InsufficientFunds:e.Record({balance:i})}),we=e.Variant({Ok:y,Err:Oe}),Fe=e.Record({to:t,fee:e.Opt(i),spender_subaccount:e.Opt(r),from:t,memo:e.Opt(e.Vec(e.Nat8)),created_at_time:e.Opt(g),amount:i}),Ve=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,InsufficientAllowance:e.Record({allowance:i}),BadBurn:e.Record({min_burn_amount:i}),Duplicate:e.Record({duplicate_of:y}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:g}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),ke=e.Variant({Ok:y,Err:Ve}),f=e.Nat64,O=e.Record({start:f,length:e.Nat64}),q=e.Nat64,h=e.Record({timestamp_nanos:e.Nat64}),Be=e.Variant({Approve:e.Record({fee:o,from:a,allowance_e8s:e.Int,allowance:o,expected_allowance:e.Opt(o),expires_at:e.Opt(h),spender:a}),Burn:e.Record({from:a,amount:o,spender:e.Opt(a)}),Mint:e.Record({to:a,amount:o}),Transfer:e.Record({to:a,fee:o,from:a,amount:o,spender:e.Opt(e.Vec(e.Nat8))})}),ve=e.Record({memo:q,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:e.Opt(Be),created_at_time:h}),$=e.Record({transaction:ve,timestamp:h,parent_hash:e.Opt(e.Vec(e.Nat8))}),Ee=e.Record({blocks:e.Vec($)}),Q=e.Variant({BadFirstBlockIndex:e.Record({requested_index:f,first_valid_index:f}),Other:e.Record({error_message:e.Text,error_code:e.Nat64})}),qe=e.Variant({Ok:Ee,Err:Q}),Ue=e.Func([O],[qe],["query"]),Ce=e.Record({callback:Ue,start:f,length:e.Nat64}),Pe=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec($),chain_length:e.Nat64,first_block_index:f,archived_blocks:e.Vec(Ce)}),Se=e.Record({callback:e.Func([O],[e.Variant({Ok:e.Vec(e.Vec(e.Nat8)),Err:Q})],["query"]),start:e.Nat64,length:e.Nat64}),Ge=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec(e.Vec(e.Nat8)),chain_length:e.Nat64,first_block_index:e.Nat64,archived_blocks:e.Vec(Se)}),Me=e.Record({to:s,fee:o,memo:q,from_subaccount:e.Opt(r),created_at_time:e.Opt(h),amount:o}),He=e.Record({to:a,fee:o,memo:q,from_subaccount:e.Opt(r),created_at_time:e.Opt(h),amount:o}),$e=e.Variant({TxTooOld:e.Record({allowed_window_nanos:e.Nat64}),BadFee:e.Record({expected_fee:o}),TxDuplicate:e.Record({duplicate_of:f}),TxCreatedInFuture:e.Null,InsufficientFunds:e.Record({balance:o})}),Qe=e.Variant({Ok:f,Err:$e}),ze=e.Record({}),je=e.Record({transfer_fee:o});return e.Service({account_balance:e.Func([x],[o],["query"]),account_balance_dfx:e.Func([m],[o],["query"]),account_identifier:e.Func([t],[a],["query"]),archives:e.Func([],[R],["query"]),decimals:e.Func([],[e.Record({decimals:e.Nat32})],["query"]),icrc10_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],["query"]),icrc1_balance_of:e.Func([t],[i],["query"]),icrc1_decimals:e.Func([],[e.Nat8],["query"]),icrc1_fee:e.Func([],[i],["query"]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,v))],["query"]),icrc1_minting_account:e.Func([],[e.Opt(t)],["query"]),icrc1_name:e.Func([],[e.Text],["query"]),icrc1_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],["query"]),icrc1_symbol:e.Func([],[e.Text],["query"]),icrc1_total_supply:e.Func([],[i],["query"]),icrc1_transfer:e.Func([fe],[me],[]),icrc21_canister_call_consent_message:e.Func([ge],[be],[]),icrc2_allowance:e.Func([Te],[Ae],["query"]),icrc2_approve:e.Func([Ne],[we],[]),icrc2_transfer_from:e.Func([Fe],[ke],[]),is_ledger_ready:e.Func([],[e.Bool],["query"]),name:e.Func([],[e.Record({name:e.Text})],["query"]),query_blocks:e.Func([O],[Pe],["query"]),query_encoded_blocks:e.Func([O],[Ge],["query"]),send_dfx:e.Func([Me],[f],[]),symbol:e.Func([],[e.Record({symbol:e.Text})],["query"]),transfer:e.Func([He],[Qe],[]),transfer_fee:e.Func([ze],[je],["query"])})};var de=class e extends pe.Canister{constructor(){super(...arguments);this.accountBalance=async({accountIdentifier:t,certified:n=!0})=>{let c=yt(t);return(await(n?this.certifiedService:this.service).account_balance({account:c.toUint8Array()})).e8s};this.metadata=t=>{let{icrc1_metadata:n}=this.caller(t);return n()};this.transactionFee=async(t={certified:!1})=>{let{transfer_fee:n}=this.caller(t),{transfer_fee:{e8s:c}}=await n({});return c};this.transfer=async t=>{let n=Ie(t),c=await this.certifiedService.transfer(n);if("Err"in c)throw rt(c.Err);return c.Ok};this.icrc1Transfer=async t=>{let n=De(t),c=await this.certifiedService.icrc1_transfer(n);if("Err"in c)throw nt(c.Err);return c.Ok};this.icrc2Approve=async t=>{let{icrc2_approve:n}=this.caller({certified:!0}),c=await n(Le(t));if("Err"in c)throw ct(c.Err);return c.Ok};this.icrc21ConsentMessage=async t=>{let{icrc21_canister_call_consent_message:n}=this.caller({certified:!0}),c=await n(et(t));if("Err"in c)throw ot(c.Err);return c.Ok}}static create(t={}){let n=t.canisterId??xt,{service:c,certifiedService:o}=(0,pe.createServices)({options:{...t,canisterId:n},idlFactory:ht,certifiedIdlFactory:Rt});return new e(n,c,o)}};var B=require("@dfinity/utils");var it=require("buffer"),Et=e=>Uint8Array.from(it.Buffer.from(e,"hex")).subarray(4),qt=e=>it.Buffer.from(e).toString("hex"),Ut=(e,r)=>{let t=(0,B.asciiStringToByteArray)(` account-id`),n=I.create();n.update((0,B.arrayOfNumberToUint8Array)([...t,...e.toUint8Array(),...r??Array(32).fill(0)]));let c=n.digest(),o=(0,B.bigEndianCrc32)(c),s=new Uint8Array([...o,...c]);return(0,B.uint8ArrayToHexString)(s)};var le=require("@dfinity/utils");var bt=e=>{if(e.length!=64)throw new P(`Invalid account identifier ${e}. The account identifier must be 64 chars in length.`);let r=Buffer.from(e,"hex"),t=r.slice(0,4),n=Buffer.from((0,le.bigEndianCrc32)(r.slice(4)));if(!n.equals(t))throw new P(`Account identifier ${e} has an invalid checksum. Are you sure the account identifier is correct? Expected checksum: ${n.toString("hex")} Found checksum: ${t.toString("hex")}`)},Ct=e=>{if((0,le.isNullish)(e))return!1;try{return bt(e),!0}catch{}return!1};0&&(module.exports={AccountIdentifier,AllowanceChangedError,ApproveError,BadFeeError,ConsentMessageError,ConsentMessageUnavailableError,CreatedInFutureError,DuplicateError,ExpiredError,GenericError,IcrcError,IndexCanister,InsufficientFundsError,InsufficientPaymentError,InvalidAccountIDError,InvalidSenderError,LedgerCanister,SubAccount,TemporarilyUnavailableError,TooOldError,TransferError,TxCreatedInFutureError,TxDuplicateError,TxTooOldError,UnsupportedCanisterCallError,accountIdentifierFromBytes,accountIdentifierToBytes,checkAccountId,isIcpAccountIdentifier,mapIcrc1TransferError,mapIcrc21ConsentMessageError,mapIcrc2ApproveError,mapTransferError,principalToAccountIdentifier,toIcrc1TransferRawRequest,toIcrc21ConsentMessageRawRequest,toIcrc2ApproveRawRequest,toTransferRawRequest}); /*! Bundled license information: @noble/hashes/esm/utils.js: (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) */ //# sourceMappingURL=index.cjs.js.map