@dfinity/ledger-icp
Version:
A library for interfacing with the ICP ledger on the Internet Computer.
12 lines (9 loc) • 31.6 kB
JavaScript
"use strict";var Je=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var At=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)Je(e,r,{get:t[r],enumerable:!0})},Ft=(e,t,r,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ot(t))!At.call(e,o)&&o!==r&&Je(e,o,{get:()=>t[o],enumerable:!(c=Nt(t,o))||c.enumerable});return e};var Vt=e=>Ft(Je({},"__esModule",{value:!0}),e);var Ct={};wt(Ct,{AccountIdentifier:()=>B,AllowanceChangedError:()=>te,ApproveError:()=>N,BadFeeError:()=>M,ConsentMessageError:()=>P,ConsentMessageUnavailableError:()=>ae,CreatedInFutureError:()=>re,DuplicateError:()=>ee,ExpiredError:()=>ne,GenericError:()=>K,IcrcError:()=>U,IndexCanister:()=>ue,InsufficientFundsError:()=>G,InsufficientPaymentError:()=>oe,InvalidAccountIDError:()=>S,InvalidSenderError:()=>ct,LedgerCanister:()=>de,SubAccount:()=>j,TemporarilyUnavailableError:()=>L,TooOldError:()=>ce,TransferError:()=>w,TxCreatedInFutureError:()=>J,TxDuplicateError:()=>X,TxTooOldError:()=>W,UnsupportedCanisterCallError:()=>se,checkAccountId:()=>Tt,isIcpAccountIdentifier:()=>qt,mapIcrc1TransferError:()=>ot,mapIcrc21ConsentMessageError:()=>at,mapIcrc2ApproveError:()=>st,mapTransferError:()=>nt,toIcrc1TransferRawRequest:()=>et,toIcrc21ConsentMessageRawRequest:()=>rt,toIcrc2ApproveRawRequest:()=>tt,toTransferRawRequest:()=>Le});module.exports=Vt(Ct);var T=require("@dfinity/utils");function kt(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Xe(e,...t){if(!kt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ke(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function dt(e,t){Xe(e);let r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var Z=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),b=(e,t)=>e<<32-t|e>>>t;var Gt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Bt(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){return typeof e=="string"&&(e=Bt(e)),Xe(e),e}var Y=class{clone(){return this._cloneInto()}},Mt={}.toString;function pt(e){let t=c=>e().update(Ye(c)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function vt(e,t,r,c){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,c);let o=BigInt(32),n=BigInt(4294967295),s=Number(r>>o&n),u=Number(r&n),d=c?4:0,p=c?0:4;e.setUint32(t+d,s,c),e.setUint32(t+p,u,c)}var lt=(e,t,r)=>e&t^~e&r,ft=(e,t,r)=>e&t^e&r^t&r,I=class extends Y{constructor(t,r,c,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=c,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Z(this.buffer)}update(t){Ke(this);let{view:r,buffer:c,blockLen:o}=this;t=Ye(t);let n=t.length;for(let s=0;s<n;){let u=Math.min(o-this.pos,n-s);if(u===o){let d=Z(t);for(;o<=n-s;s+=o)this.process(d,s);continue}c.set(t.subarray(s,s+u),this.pos),this.pos+=u,s+=u,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),dt(t,this),this.finished=!0;let{buffer:r,view:c,blockLen:o,isLE:n}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(c,0),s=0);for(let a=s;a<o;a++)r[a]=0;vt(c,o-8,BigInt(this.length*8),n),this.process(c,0);let u=Z(t),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],n)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let c=t.slice(0,r);return this.destroy(),c}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:c,length:o,finished:n,destroyed:s,pos:u}=this;return t.length=o,t.pos=u,t.finished=n,t.destroyed=s,o%r&&t.buffer.set(c),t}};var Et=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]),V=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),k=new Uint32Array(64),Ze=class extends I{constructor(){super(64,32,8,!1),this.A=V[0]|0,this.B=V[1]|0,this.C=V[2]|0,this.D=V[3]|0,this.E=V[4]|0,this.F=V[5]|0,this.G=V[6]|0,this.H=V[7]|0}get(){let{A:t,B:r,C:c,D:o,E:n,F:s,G:u,H:d}=this;return[t,r,c,o,n,s,u,d]}set(t,r,c,o,n,s,u,d){this.A=t|0,this.B=r|0,this.C=c|0,this.D=o|0,this.E=n|0,this.F=s|0,this.G=u|0,this.H=d|0}process(t,r){for(let a=0;a<16;a++,r+=4)k[a]=t.getUint32(r,!1);for(let a=16;a<64;a++){let x=k[a-15],m=k[a-2],A=b(x,7)^b(x,18)^x>>>3,h=b(m,17)^b(m,19)^m>>>10;k[a]=h+k[a-7]+A+k[a-16]|0}let{A:c,B:o,C:n,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+lt(u,d,p)+Et[a]+k[a]|0,h=(b(c,2)^b(c,13)^b(c,22))+ft(c,o,n)|0;_=p,p=d,d=u,u=s+m|0,s=n,n=o,o=c,c=m+h|0}c=c+this.A|0,o=o+this.B|0,n=n+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(c,o,n,s,u,d,p,_)}roundClean(){k.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Ie=class extends Ze{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 De=pt(()=>new Ie);var B=class e{constructor(t){this.bytes=t}static fromHex(t){let r=Uint8Array.from(Buffer.from(t,"hex"));if(r.length!==32)throw new Error(`Invalid AccountIdentifier: expected 32 bytes, got ${r.length}.`);let c=(0,T.uint8ArrayToHexString)(r.slice(0,4)),o=r.slice(4),n=(0,T.uint8ArrayToHexString)((0,T.bigEndianCrc32)(o));if(c!==n)throw Error(`Checksum mismatch. Expected ${n}, but got ${c}.`);return new e(r)}static fromPrincipal({principal:t,subAccount:r=j.fromID(0)}){let c=(0,T.asciiStringToByteArray)(`
account-id`),o=De.create();o.update((0,T.arrayOfNumberToUint8Array)([...c,...t.toUint8Array(),...r.toUint8Array()]));let n=o.digest(),s=(0,T.bigEndianCrc32)(n),u=new Uint8Array([...s,...n]);return new e(u)}toHex(){return(0,T.uint8ArrayToHexString)(this.bytes)}toUint8Array(){return this.bytes}toNumbers(){return Array.from(this.bytes)}toAccountIdentifierHash(){return{hash:this.toUint8Array()}}},j=class e{constructor(t){this.bytes=t}static fromBytes(t){if(t.length!==32)throw new Error("Subaccount length must be 32-bytes");return new e(t)}static fromPrincipal(t){let r=new Uint8Array(32).fill(0),c=t.toUint8Array();r[0]=c.length;for(let o=0;o<c.length;o++)r[1+o]=c[o];return new e(r)}static fromID(t){if(t<0)throw new Error("Number cannot be negative");if(t>Number.MAX_SAFE_INTEGER)throw new Error("Number is too large to fit in 32 bytes.");let r=new DataView(new ArrayBuffer(32));if(typeof r.setBigUint64=="function")r.setBigUint64(24,BigInt(t));else{let o=BigInt(1)<<BigInt(32);r.setUint32(24,Number(BigInt(t)>>BigInt(32))),r.setUint32(28,Number(BigInt(t)%o))}let c=new Uint8Array(r.buffer);return new e(c)}toUint8Array(){return this.bytes}};var f=require("@dfinity/utils");var Dt=BigInt(1095062083),Lt=BigInt(1347768404),D=BigInt(1e4),er=BigInt(1e8);var _t=e=>({e8s:e}),Le=({to:e,amount:t,memo:r,fee:c,fromSubAccount:o,createdAt:n})=>({to:e.toUint8Array(),fee:_t(c??D),amount:_t(t),memo:r??BigInt(0),created_at_time:n!==void 0?[{timestamp_nanos:n}]:[],from_subaccount:o===void 0?[]:[(0,f.arrayOfNumberToUint8Array)(o)]}),et=({fromSubAccount:e,to:t,amount:r,fee:c,icrc1Memo:o,createdAt:n})=>({to:t,fee:(0,f.toNullable)(c??D),amount:r,memo:(0,f.toNullable)(o),created_at_time:(0,f.toNullable)(n),from_subaccount:(0,f.toNullable)(e)}),tt=({fee:e,createdAt:t,icrc1Memo:r,fromSubAccount:c,expected_allowance:o,expires_at:n,amount:s,...u})=>({...u,fee:(0,f.toNullable)(e??D),memo:(0,f.toNullable)(r),from_subaccount:(0,f.toNullable)(c),created_at_time:(0,f.toNullable)(t),amount:s,expected_allowance:(0,f.toNullable)(o),expires_at:(0,f.toNullable)(n)}),rt=({userPreferences:{metadata:{utcOffsetMinutes:e,language:t},deriveSpec:r},...c})=>({...c,user_preferences:{metadata:{language:t,utc_offset_minutes:(0,f.toNullable)(e)},device_spec:(0,f.isNullish)(r)?(0,f.toNullable)():(0,f.toNullable)("GenericDisplay"in r?{GenericDisplay:null}:{LineDisplay:{characters_per_line:r.LineDisplay.charactersPerLine,lines_per_page:r.LineDisplay.linesPerPage}})}});var U=class extends Error{},w=class extends U{},N=class extends U{},P=class extends U{},ct=class extends w{},S=class extends Error{},G=class extends w{constructor(r){super();this.balance=r}},W=class extends w{constructor(r){super();this.allowed_window_secs=r}},J=class extends w{},X=class extends w{constructor(r){super();this.duplicateOf=r}},M=class extends U{constructor(r){super();this.expectedFee=r}},K=class extends N{constructor(r,c){super();this.message=r;this.error_code=c}},L=class extends N{},ee=class extends N{constructor(r){super();this.duplicateOf=r}},te=class extends N{constructor(r){super();this.currentAllowance=r}},re=class extends N{},ce=class extends N{},ne=class extends N{constructor(r){super();this.ledgerTime=r}},oe=class extends P{},se=class extends P{},ae=class extends P{},nt=e=>"TxDuplicate"in e?new X(e.TxDuplicate.duplicate_of):"InsufficientFunds"in e?new G(e.InsufficientFunds.balance.e8s):"TxCreatedInFuture"in e?new J:"TxTooOld"in e?new W(Number(e.TxTooOld.allowed_window_nanos)):"BadFee"in e?new M(e.BadFee.expected_fee.e8s):new w(`Unknown error type ${JSON.stringify(e)}`),ot=e=>"Duplicate"in e?new X(e.Duplicate.duplicate_of):"InsufficientFunds"in e?new G(e.InsufficientFunds.balance):"CreatedInFuture"in e?new J:"TooOld"in e?new W:"BadFee"in e?new M(e.BadFee.expected_fee):new w(`Unknown error type ${JSON.stringify(e)}`),st=e=>"GenericError"in e?new K(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 M(e.BadFee.expected_fee):"AllowanceChanged"in e?new te(e.AllowanceChanged.current_allowance):"CreatedInFuture"in e?new re:"TooOld"in e?new ce:"Expired"in e?new ne(e.Expired.ledger_time):"InsufficientFunds"in e?new G(e.InsufficientFunds.balance):new N(`Unknown error type ${JSON.stringify(e)}`),at=e=>"GenericError"in e?new K(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 P(`Unknown error type ${JSON.stringify(e)}`);var H=require("@dfinity/utils");var mt=({IDL:e})=>{let t=e.Record({ledger_id:e.Principal}),r=e.Record({max_results:e.Nat64,start:e.Opt(e.Nat64),account_identifier:e.Text}),c=e.Record({e8s:e.Nat64}),o=e.Record({timestamp_nanos:e.Nat64}),n=e.Variant({Approve:e.Record({fee:c,from:e.Text,allowance:c,expected_allowance:e.Opt(c),expires_at:e.Opt(o),spender:e.Text}),Burn:e.Record({from:e.Text,amount:c,spender:e.Opt(e.Text)}),Mint:e.Record({to:e.Text,amount:c}),Transfer:e.Record({to:e.Text,fee:c,from:e.Text,amount:c,spender:e.Opt(e.Text)})}),s=e.Record({memo:e.Nat64,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:n,timestamp:e.Opt(o),created_at_time:e.Opt(o)}),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}),h=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text))}),v=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),status_code:e.Nat16}),E=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([r],[_],[]),get_account_transactions:e.Func([x],[_],[]),get_blocks:e.Func([m],[A],[]),http_request:e.Func([h],[v],[]),icrc1_balance_of:e.Func([a],[e.Nat64],[]),ledger_id:e.Func([],[e.Principal],[]),status:e.Func([],[E],[])})};var xt=({IDL:e})=>{let t=e.Record({ledger_id:e.Principal}),r=e.Record({max_results:e.Nat64,start:e.Opt(e.Nat64),account_identifier:e.Text}),c=e.Record({e8s:e.Nat64}),o=e.Record({timestamp_nanos:e.Nat64}),n=e.Variant({Approve:e.Record({fee:c,from:e.Text,allowance:c,expected_allowance:e.Opt(c),expires_at:e.Opt(o),spender:e.Text}),Burn:e.Record({from:e.Text,amount:c,spender:e.Opt(e.Text)}),Mint:e.Record({to:e.Text,amount:c}),Transfer:e.Record({to:e.Text,fee:c,from:e.Text,amount:c,spender:e.Opt(e.Text)})}),s=e.Record({memo:e.Nat64,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:n,timestamp:e.Opt(o),created_at_time:e.Opt(o)}),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}),h=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text))}),v=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),status_code:e.Nat16}),E=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([r],[_],["query"]),get_account_transactions:e.Func([x],[_],["query"]),get_blocks:e.Func([m],[A],["query"]),http_request:e.Func([h],[v],["query"]),icrc1_balance_of:e.Func([a],[e.Nat64],["query"]),ledger_id:e.Func([],[e.Principal],["query"]),status:e.Func([],[E],["query"])})};var it=require("@dfinity/principal"),gt=it.Principal.fromText("ryjl3-tyaaa-aaaaa-aaaba-cai"),Rt=it.Principal.fromText("qhbym-qaaaa-aaaaa-aaafq-cai");var ie=class extends Error{};var ht=e=>e instanceof B?e:B.fromHex(e),ut=e=>e instanceof B?e.toHex():e;var ue=class e extends H.Canister{static create({canisterId:t,...r}){let{service:c,certifiedService:o,canisterId:n}=(0,H.createServices)({options:{...r,canisterId:t??Rt},idlFactory:xt,certifiedIdlFactory:mt});return new e(n,c,o)}accountBalance=({certified:t,accountIdentifier:r})=>this.caller({certified:t}).get_account_identifier_balance(ut(r));getTransactions=async({certified:t,accountIdentifier:r,start:c,maxResults:o})=>{let n=await this.caller({certified:t}).get_account_identifier_transactions({account_identifier:ut(r),start:(0,H.toNullable)(c),max_results:o});if("Err"in n)throw new ie(n.Err.message);return n.Ok}};var pe=require("@dfinity/utils");var yt=({IDL:e})=>{let t=e.Vec(e.Nat8),r=e.Record({owner:e.Principal,subaccount:e.Opt(t)}),c=e.Record({icrc2:e.Bool}),o=e.Record({icrc1_minting_account:e.Opt(r),feature_flags:e.Opt(c)}),n=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(n),minting_account:s,transaction_window:e.Opt(u),max_message_size_bytes:e.Opt(e.Nat64),icrc1_minting_account:e.Opt(r),archive_options:e.Opt(d),initial_values:e.Vec(e.Tuple(s,n)),token_name:e.Opt(e.Text),feature_flags:e.Opt(c)}),_=e.Variant({Upgrade:e.Opt(o),Init:p}),a=e.Vec(e.Nat8),x=e.Record({account:a}),m=e.Record({account:s}),A=e.Record({canister_id:e.Principal}),h=e.Record({archives:e.Vec(A)}),v=e.Record({prev_spender_id:e.Opt(s),from_account_id:s,take:e.Opt(e.Nat64)}),E=e.Vec(e.Record({from_account_id:s,to_spender_id:s,allowance:n,expires_at:e.Opt(e.Nat64)})),i=e.Nat,le=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),g=e.Nat64,fe=e.Record({to:r,fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(t),created_at_time:e.Opt(g),amount:i}),R=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:R}),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:R,Err:_e}),$=e.Record({utc_offset_minutes:e.Opt(e.Int16),language:e.Text}),xe=e.Record({metadata:$,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}),Re=e.Variant({LineDisplayMessage:e.Record({pages:e.Vec(e.Record({lines:e.Vec(e.Text)}))}),GenericDisplayMessage:e.Text}),he=e.Record({metadata:$,consent_message:Re}),q=e.Record({description:e.Text}),ye=e.Variant({GenericError:e.Record({description:e.Text,error_code:e.Nat}),InsufficientPayment:q,UnsupportedCanisterCall:q,ConsentMessageUnavailable:q}),be=e.Variant({Ok:he,Err:ye}),Te=e.Record({account:r,spender:r}),Ne=e.Record({allowance:i,expires_at:e.Opt(g)}),Oe=e.Record({fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(t),created_at_time:e.Opt(g),amount:i,expected_allowance:e.Opt(i),expires_at:e.Opt(g),spender:r}),Ae=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:R}),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:R,Err:Ae}),Fe=e.Record({to:r,fee:e.Opt(i),spender_subaccount:e.Opt(t),from:r,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:R}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:g}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),ke=e.Variant({Ok:R,Err:Ve}),l=e.Nat64,F=e.Record({start:l,length:e.Nat64}),C=e.Nat64,y=e.Record({timestamp_nanos:e.Nat64}),Be=e.Variant({Approve:e.Record({fee:n,from:a,allowance_e8s:e.Int,allowance:n,expected_allowance:e.Opt(n),expires_at:e.Opt(y),spender:a}),Burn:e.Record({from:a,amount:n,spender:e.Opt(a)}),Mint:e.Record({to:a,amount:n}),Transfer:e.Record({to:a,fee:n,from:a,amount:n,spender:e.Opt(e.Vec(e.Nat8))})}),ve=e.Record({memo:C,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:e.Opt(Be),created_at_time:y}),Q=e.Record({transaction:ve,timestamp:y,parent_hash:e.Opt(e.Vec(e.Nat8))}),Ee=e.Record({blocks:e.Vec(Q)}),z=e.Variant({BadFirstBlockIndex:e.Record({requested_index:l,first_valid_index:l}),Other:e.Record({error_message:e.Text,error_code:e.Nat64})}),qe=e.Variant({Ok:Ee,Err:z}),Ce=e.Func([F],[qe],[]),Ue=e.Record({callback:Ce,start:l,length:e.Nat64}),Pe=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec(Q),chain_length:e.Nat64,first_block_index:l,archived_blocks:e.Vec(Ue)}),Se=e.Record({callback:e.Func([F],[e.Variant({Ok:e.Vec(e.Vec(e.Nat8)),Err:z})],[]),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:n,memo:C,from_subaccount:e.Opt(t),created_at_time:e.Opt(y),amount:n}),He=e.Record({certification:e.Opt(e.Vec(e.Nat8)),tip_index:l}),$e=e.Record({to:a,fee:n,memo:C,from_subaccount:e.Opt(t),created_at_time:e.Opt(y),amount:n}),Qe=e.Variant({TxTooOld:e.Record({allowed_window_nanos:e.Nat64}),BadFee:e.Record({expected_fee:n}),TxDuplicate:e.Record({duplicate_of:l}),TxCreatedInFuture:e.Null,InsufficientFunds:e.Record({balance:n})}),ze=e.Variant({Ok:l,Err:Qe}),je=e.Record({}),We=e.Record({transfer_fee:n});return e.Service({account_balance:e.Func([x],[n],[]),account_balance_dfx:e.Func([m],[n],[]),account_identifier:e.Func([r],[a],[]),archives:e.Func([],[h],[]),decimals:e.Func([],[e.Record({decimals:e.Nat32})],[]),get_allowances:e.Func([v],[E],[]),icrc10_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],[]),icrc1_balance_of:e.Func([r],[i],[]),icrc1_decimals:e.Func([],[e.Nat8],[]),icrc1_fee:e.Func([],[i],[]),icrc1_metadata:e.Func([],[e.Vec(e.Tuple(e.Text,le))],[]),icrc1_minting_account:e.Func([],[e.Opt(r)],[]),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],[Ne],[]),icrc2_approve:e.Func([Oe],[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([F],[Pe],[]),query_encoded_blocks:e.Func([F],[Ge],[]),send_dfx:e.Func([Me],[l],[]),symbol:e.Func([],[e.Record({symbol:e.Text})],[]),tip_of_chain:e.Func([],[He],[]),transfer:e.Func([$e],[ze],[]),transfer_fee:e.Func([je],[We],[])})};var bt=({IDL:e})=>{let t=e.Vec(e.Nat8),r=e.Record({owner:e.Principal,subaccount:e.Opt(t)}),c=e.Record({icrc2:e.Bool}),o=e.Record({icrc1_minting_account:e.Opt(r),feature_flags:e.Opt(c)}),n=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(n),minting_account:s,transaction_window:e.Opt(u),max_message_size_bytes:e.Opt(e.Nat64),icrc1_minting_account:e.Opt(r),archive_options:e.Opt(d),initial_values:e.Vec(e.Tuple(s,n)),token_name:e.Opt(e.Text),feature_flags:e.Opt(c)}),_=e.Variant({Upgrade:e.Opt(o),Init:p}),a=e.Vec(e.Nat8),x=e.Record({account:a}),m=e.Record({account:s}),A=e.Record({canister_id:e.Principal}),h=e.Record({archives:e.Vec(A)}),v=e.Record({prev_spender_id:e.Opt(s),from_account_id:s,take:e.Opt(e.Nat64)}),E=e.Vec(e.Record({from_account_id:s,to_spender_id:s,allowance:n,expires_at:e.Opt(e.Nat64)})),i=e.Nat,le=e.Variant({Int:e.Int,Nat:e.Nat,Blob:e.Vec(e.Nat8),Text:e.Text}),g=e.Nat64,fe=e.Record({to:r,fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(t),created_at_time:e.Opt(g),amount:i}),R=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:R}),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:R,Err:_e}),$=e.Record({utc_offset_minutes:e.Opt(e.Int16),language:e.Text}),xe=e.Record({metadata:$,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}),Re=e.Variant({LineDisplayMessage:e.Record({pages:e.Vec(e.Record({lines:e.Vec(e.Text)}))}),GenericDisplayMessage:e.Text}),he=e.Record({metadata:$,consent_message:Re}),q=e.Record({description:e.Text}),ye=e.Variant({GenericError:e.Record({description:e.Text,error_code:e.Nat}),InsufficientPayment:q,UnsupportedCanisterCall:q,ConsentMessageUnavailable:q}),be=e.Variant({Ok:he,Err:ye}),Te=e.Record({account:r,spender:r}),Ne=e.Record({allowance:i,expires_at:e.Opt(g)}),Oe=e.Record({fee:e.Opt(i),memo:e.Opt(e.Vec(e.Nat8)),from_subaccount:e.Opt(t),created_at_time:e.Opt(g),amount:i,expected_allowance:e.Opt(i),expires_at:e.Opt(g),spender:r}),Ae=e.Variant({GenericError:e.Record({message:e.Text,error_code:e.Nat}),TemporarilyUnavailable:e.Null,Duplicate:e.Record({duplicate_of:R}),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:R,Err:Ae}),Fe=e.Record({to:r,fee:e.Opt(i),spender_subaccount:e.Opt(t),from:r,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:R}),BadFee:e.Record({expected_fee:i}),CreatedInFuture:e.Record({ledger_time:g}),TooOld:e.Null,InsufficientFunds:e.Record({balance:i})}),ke=e.Variant({Ok:R,Err:Ve}),l=e.Nat64,F=e.Record({start:l,length:e.Nat64}),C=e.Nat64,y=e.Record({timestamp_nanos:e.Nat64}),Be=e.Variant({Approve:e.Record({fee:n,from:a,allowance_e8s:e.Int,allowance:n,expected_allowance:e.Opt(n),expires_at:e.Opt(y),spender:a}),Burn:e.Record({from:a,amount:n,spender:e.Opt(a)}),Mint:e.Record({to:a,amount:n}),Transfer:e.Record({to:a,fee:n,from:a,amount:n,spender:e.Opt(e.Vec(e.Nat8))})}),ve=e.Record({memo:C,icrc1_memo:e.Opt(e.Vec(e.Nat8)),operation:e.Opt(Be),created_at_time:y}),Q=e.Record({transaction:ve,timestamp:y,parent_hash:e.Opt(e.Vec(e.Nat8))}),Ee=e.Record({blocks:e.Vec(Q)}),z=e.Variant({BadFirstBlockIndex:e.Record({requested_index:l,first_valid_index:l}),Other:e.Record({error_message:e.Text,error_code:e.Nat64})}),qe=e.Variant({Ok:Ee,Err:z}),Ce=e.Func([F],[qe],["query"]),Ue=e.Record({callback:Ce,start:l,length:e.Nat64}),Pe=e.Record({certificate:e.Opt(e.Vec(e.Nat8)),blocks:e.Vec(Q),chain_length:e.Nat64,first_block_index:l,archived_blocks:e.Vec(Ue)}),Se=e.Record({callback:e.Func([F],[e.Variant({Ok:e.Vec(e.Vec(e.Nat8)),Err:z})],["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:n,memo:C,from_subaccount:e.Opt(t),created_at_time:e.Opt(y),amount:n}),He=e.Record({certification:e.Opt(e.Vec(e.Nat8)),tip_index:l}),$e=e.Record({to:a,fee:n,memo:C,from_subaccount:e.Opt(t),created_at_time:e.Opt(y),amount:n}),Qe=e.Variant({TxTooOld:e.Record({allowed_window_nanos:e.Nat64}),BadFee:e.Record({expected_fee:n}),TxDuplicate:e.Record({duplicate_of:l}),TxCreatedInFuture:e.Null,InsufficientFunds:e.Record({balance:n})}),ze=e.Variant({Ok:l,Err:Qe}),je=e.Record({}),We=e.Record({transfer_fee:n});return e.Service({account_balance:e.Func([x],[n],["query"]),account_balance_dfx:e.Func([m],[n],["query"]),account_identifier:e.Func([r],[a],["query"]),archives:e.Func([],[h],["query"]),decimals:e.Func([],[e.Record({decimals:e.Nat32})],["query"]),get_allowances:e.Func([v],[E],["query"]),icrc10_supported_standards:e.Func([],[e.Vec(e.Record({url:e.Text,name:e.Text}))],["query"]),icrc1_balance_of:e.Func([r],[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,le))],["query"]),icrc1_minting_account:e.Func([],[e.Opt(r)],["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],[Ne],["query"]),icrc2_approve:e.Func([Oe],[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([F],[Pe],["query"]),query_encoded_blocks:e.Func([F],[Ge],["query"]),send_dfx:e.Func([Me],[l],[]),symbol:e.Func([],[e.Record({symbol:e.Text})],["query"]),tip_of_chain:e.Func([],[He],["query"]),transfer:e.Func([$e],[ze],[]),transfer_fee:e.Func([je],[We],["query"])})};var de=class e extends pe.Canister{static create(t={}){let r=t.canisterId??gt,{service:c,certifiedService:o}=(0,pe.createServices)({options:{...t,canisterId:r},idlFactory:bt,certifiedIdlFactory:yt});return new e(r,c,o)}accountBalance=async({accountIdentifier:t,certified:r=!0})=>{let c=ht(t);return(await(r?this.certifiedService:this.service).account_balance({account:c.toUint8Array()})).e8s};metadata=t=>{let{icrc1_metadata:r}=this.caller(t);return r()};transactionFee=async(t={certified:!1})=>{let{transfer_fee:r}=this.caller(t),{transfer_fee:{e8s:c}}=await r({});return c};transfer=async t=>{let r=Le(t),c=await this.certifiedService.transfer(r);if("Err"in c)throw nt(c.Err);return c.Ok};icrc1Transfer=async t=>{let r=et(t),c=await this.certifiedService.icrc1_transfer(r);if("Err"in c)throw ot(c.Err);return c.Ok};icrc2Approve=async t=>{let{icrc2_approve:r}=this.caller({certified:!0}),c=await r(tt(t));if("Err"in c)throw st(c.Err);return c.Ok};icrc21ConsentMessage=async t=>{let{icrc21_canister_call_consent_message:r}=this.caller({certified:!0}),c=await r(rt(t));if("Err"in c)throw at(c.Err);return c.Ok}};var O=require("@dfinity/utils");var Tt=e=>{if(e.length!=64)throw new S(`Invalid account identifier ${e}. The account identifier must be 64 chars in length.`);let t=(0,O.hexStringToUint8Array)(e),r=t.slice(0,4),c=(0,O.bigEndianCrc32)(t.slice(4));if(!(0,O.uint8ArraysEqual)({a:c,b:r}))throw new S(`Account identifier ${e} has an invalid checksum. Are you sure the account identifier is correct?
Expected checksum: ${(0,O.uint8ArrayToHexString)(c)}
Found checksum: ${(0,O.uint8ArrayToHexString)(r)}`)},qt=e=>{if((0,O.isNullish)(e))return!1;try{return Tt(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,checkAccountId,isIcpAccountIdentifier,mapIcrc1TransferError,mapIcrc21ConsentMessageError,mapIcrc2ApproveError,mapTransferError,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