@fastnear/api 0.1.0 → 0.4.0

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.
Files changed (44) hide show
  1. package/dist/cjs/cryptoUtils.js +89 -0
  2. package/dist/cjs/cryptoUtils.js.map +7 -0
  3. package/dist/cjs/index.esm.js +1219 -0
  4. package/dist/cjs/index.esm.js.map +7 -0
  5. package/dist/cjs/index.js +1274 -0
  6. package/dist/cjs/index.js.map +7 -0
  7. package/dist/cjs/near.js +1219 -0
  8. package/dist/cjs/near.js.map +7 -0
  9. package/dist/cjs/transaction.js +360 -0
  10. package/dist/cjs/transaction.js.map +7 -0
  11. package/dist/cjs/utils.js +105 -0
  12. package/dist/cjs/utils.js.map +7 -0
  13. package/dist/esm/chunk-2SCAGR3F.js +68 -0
  14. package/dist/esm/chunk-2SCAGR3F.js.map +7 -0
  15. package/dist/esm/chunk-OR3WITSY.js +842 -0
  16. package/dist/esm/chunk-OR3WITSY.js.map +7 -0
  17. package/dist/esm/chunk-S5Q2EM2B.js +48 -0
  18. package/dist/esm/chunk-S5Q2EM2B.js.map +7 -0
  19. package/{src/transaction.js → dist/esm/chunk-YKPILPMX.js} +113 -99
  20. package/dist/esm/chunk-YKPILPMX.js.map +7 -0
  21. package/dist/esm/cryptoUtils.js +21 -0
  22. package/dist/esm/cryptoUtils.js.map +7 -0
  23. package/dist/esm/index.esm.js +13 -0
  24. package/dist/esm/index.esm.js.map +7 -0
  25. package/dist/esm/index.js +63 -0
  26. package/dist/esm/index.js.map +7 -0
  27. package/dist/esm/near.js +15 -0
  28. package/dist/esm/near.js.map +7 -0
  29. package/dist/esm/transaction.js +16 -0
  30. package/dist/esm/transaction.js.map +7 -0
  31. package/dist/esm/utils.js +24 -0
  32. package/dist/esm/utils.js.map +7 -0
  33. package/dist/umd/index.js +4227 -0
  34. package/dist/umd/index.js.map +7 -0
  35. package/package.json +35 -25
  36. package/README.md +0 -76
  37. package/dist/fastnear.cjs +0 -35
  38. package/dist/fastnear.ejs +0 -24
  39. package/dist/fastnear.js +0 -35
  40. package/src/crypto.js +0 -37
  41. package/src/index.esm.js +0 -3
  42. package/src/index.js +0 -8
  43. package/src/near.js +0 -566
  44. package/src/utils.js +0 -48
package/package.json CHANGED
@@ -1,33 +1,43 @@
1
1
  {
2
2
  "name": "@fastnear/api",
3
- "version": "0.1.0",
4
- "description": "The only NEAR front-end package you need",
3
+ "version": "0.4.0",
4
+ "description": "Interact with NEAR Protocol blockchain including transaction signing, utilities, and more.",
5
5
  "type": "module",
6
- "main": "src/index.js",
7
- "module": "./dist/fastnear.ejs",
8
- "browser": "./dist/fastnear.js",
9
- "files": [
10
- "dist",
11
- "src"
6
+ "main": "./dist/cjs/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "browser": "./dist/umd/index.js",
9
+ "scripts": {
10
+ "build": "node esbuild.config.mjs",
11
+ "publish": "yarn npm publish",
12
+ "clean": "yarn rimraf dist node_modules",
13
+ "type-check": "tsc --noEmit"
14
+ },
15
+ "keywords": [
16
+ "near-protocol",
17
+ "blockchain",
18
+ "fastnear"
12
19
  ],
13
- "repository": "https://github.com/fastnear/fastnear-js.git",
14
20
  "author": "FastNEAR",
15
- "license": "MIT",
16
- "devDependencies": {
17
- "esbuild": "^0.24.0",
18
- "prettier": "^3.4.2"
19
- },
20
- "scripts": {
21
- "build": "node build.js",
22
- "dev": "esbuild src/index.js --bundle --outfile=dist/fastnear.js"
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "require": "./dist/cjs/index.js",
27
+ "import": "./dist/esm/index.js"
28
+ }
23
29
  },
24
30
  "dependencies": {
25
- "@fastnear/wallet-adapter": "^0.1.0",
26
- "@noble/curves": "^1.7.0",
27
- "@noble/hashes": "^1.6.1",
28
- "base58-js": "=2.0.0",
29
- "big.js": "^6.2.2",
30
- "borsh": "^2.0.0",
31
- "buffer": "^6.0.3"
31
+ "@fastnear/wallet-adapter": "0.4.0",
32
+ "@noble/curves": "*",
33
+ "@noble/hashes": "*",
34
+ "base58-js": "*",
35
+ "big": "*",
36
+ "borsh": "*"
37
+ },
38
+ "devDependencies": {
39
+ "glob": "*",
40
+ "rimraf": "*",
41
+ "typescript": "*"
32
42
  }
33
- }
43
+ }
package/README.md DELETED
@@ -1,76 +0,0 @@
1
- # FastNear JS
2
-
3
- FastNear is a JavaScript library that allows you to interact with the NEAR blockchain. It is designed to be fast, lightweight, and easy to use.
4
-
5
- ## Interface
6
-
7
- Global object `window.near` is available after including the library. It has the following methods:
8
-
9
- Context:
10
-
11
- `near.accountId` - getter
12
-
13
- `near.config({...})` - either getter or setter
14
-
15
- `near.authStatus -> SignedIn | SignedOut | SignedInWithLimitedAccessKey(AccessKey)` - getter
16
-
17
- Queries:
18
-
19
- `near.view({ contractId, methodName, args, argsBase64, blockId }): Promise<any>`
20
- - `blockId` is optional and can be either a block hash, a block height or finality (`final` or `optimistic`)
21
-
22
- `near.account({ accountId, blockId }): Promise<Account>`
23
-
24
- `near.block({ blockId }): Promise<Block>`
25
-
26
- `near.accessKey({ accountId, publicKey, blockId }): Promise<AccessKey>`
27
-
28
- `near.tx({ txId }): Promise<Tx>`
29
-
30
- `near.localTxHistory(): TxStatus[]` - returns the list of transactions that were locally issued by this application.
31
-
32
- Sending transactions:
33
-
34
- `near.sendTx({ receiverId, actions, ... }): Promise<LocalTransactionId>`
35
- - returns the local transaction ID that can be used to track the transaction status using `localTxHistory`
36
-
37
- Helper methods to construct action objects:
38
-
39
- `near.actions.functionCall({ methodName, gas, deposit, args, argsBase64 }): Action`
40
-
41
- // The ammount should be a string in yoctoNEAR
42
- `near.actions.transfer(amount: string): Action`
43
-
44
- `near.actions.transferFt({ receiverId, ftContract, amount, memo }): Action`
45
-
46
- `near.actions.stakeNEAR({ amount, publicKey }): Action`
47
-
48
- `near.actions.unstakeNEAR({ amount }): Action`
49
-
50
- `near.actions.addFullAccessKey({ publicKey }): Action`
51
-
52
- `near.actions.addLimitedAccessKey({ publicKey, allowance, accountId, methodNames }): Action`
53
-
54
- `near.actions.deleteKey({ publicKey }): Action`
55
-
56
- `near.actions.deleteAccount({ beneficiaryId }): Action`
57
-
58
- `near.actions.createAccount(): Action`
59
-
60
- `near.actions.deployContract({ code }): Action`
61
-
62
- Authenticating:
63
-
64
- `near.requestSignIn({ contractId }): Promise<void>`
65
-
66
- `near.signOut()`
67
-
68
- Events:
69
-
70
- `near.onAccount((accountId: AccountId) => {})`
71
- - called when the account changes
72
-
73
- `near.onTx((txStatus: TxStatus) => {})`
74
- - called when a transaction status changes locally or remotely. E.g. you sent a new transaction, or a transaction that you sent was confirmed.
75
-
76
- ```
package/dist/fastnear.cjs DELETED
@@ -1,35 +0,0 @@
1
- var Jn=Object.create;var Qt=Object.defineProperty;var Qn=Object.getOwnPropertyDescriptor;var ti=Object.getOwnPropertyNames;var ei=Object.getPrototypeOf,ri=Object.prototype.hasOwnProperty;var Ee=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ni=(e,t)=>{for(var r in t)Qt(e,r,{get:t[r],enumerable:!0})},Br=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ti(t))!ri.call(e,i)&&i!==r&&Qt(e,i,{get:()=>t[i],enumerable:!(n=Qn(t,i))||n.enumerable});return e};var ii=(e,t,r)=>(r=e!=null?Jn(ei(e)):{},Br(t||!e||!e.__esModule?Qt(r,"default",{value:e,enumerable:!0}):r,e)),oi=e=>Br(Qt({},"__esModule",{value:!0}),e);var Ir=Ee(te=>{"use strict";te.byteLength=ci;te.toByteArray=ui;te.fromByteArray=hi;var et=[],G=[],si=typeof Uint8Array<"u"?Uint8Array:Array,_e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(bt=0,Er=_e.length;bt<Er;++bt)et[bt]=_e[bt],G[_e.charCodeAt(bt)]=bt;var bt,Er;G[45]=62;G[95]=63;function _r(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ci(e){var t=_r(e),r=t[0],n=t[1];return(r+n)*3/4-n}function fi(e,t,r){return(t+r)*3/4-r}function ui(e){var t,r=_r(e),n=r[0],i=r[1],o=new si(fi(e,n,i)),s=0,c=i>0?n-4:n,f;for(f=0;f<c;f+=4)t=G[e.charCodeAt(f)]<<18|G[e.charCodeAt(f+1)]<<12|G[e.charCodeAt(f+2)]<<6|G[e.charCodeAt(f+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=G[e.charCodeAt(f)]<<2|G[e.charCodeAt(f+1)]>>4,o[s++]=t&255),i===1&&(t=G[e.charCodeAt(f)]<<10|G[e.charCodeAt(f+1)]<<4|G[e.charCodeAt(f+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function ai(e){return et[e>>18&63]+et[e>>12&63]+et[e>>6&63]+et[e&63]}function li(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ai(n));return i.join("")}function hi(e){for(var t,r=e.length,n=r%3,i=[],o=16383,s=0,c=r-n;s<c;s+=o)i.push(li(e,s,s+o>c?c:s+o));return n===1?(t=e[r-1],i.push(et[t>>2]+et[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(et[t>>10]+et[t>>4&63]+et[t<<2&63]+"=")),i.join("")}});var Ar=Ee(Ie=>{Ie.read=function(e,t,r,n,i){var o,s,c=i*8-n-1,f=(1<<c)-1,u=f>>1,a=-7,l=r?i-1:0,d=r?-1:1,x=e[t+l];for(l+=d,o=x&(1<<-a)-1,x>>=-a,a+=c;a>0;o=o*256+e[t+l],l+=d,a-=8);for(s=o&(1<<-a)-1,o>>=-a,a+=n;a>0;s=s*256+e[t+l],l+=d,a-=8);if(o===0)o=1-u;else{if(o===f)return s?NaN:(x?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(x?-1:1)*s*Math.pow(2,o-n)};Ie.write=function(e,t,r,n,i,o){var s,c,f,u=o*8-i-1,a=(1<<u)-1,l=a>>1,d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=n?0:o-1,b=n?1:-1,g=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=a):(s=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-s))<1&&(s--,f*=2),s+l>=1?t+=d/f:t+=d*Math.pow(2,1-l),t*f>=2&&(s++,f/=2),s+l>=a?(c=0,s=a):s+l>=1?(c=(t*f-1)*Math.pow(2,i),s=s+l):(c=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+x]=c&255,x+=b,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;e[r+x]=s&255,x+=b,s/=256,u-=8);e[r+x-b]|=g*128}});var qr=Ee(Mt=>{"use strict";var Ae=Ir(),Ot=Ar(),Sr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Mt.Buffer=h;Mt.SlowBuffer=wi;Mt.INSPECT_MAX_BYTES=50;var ee=2147483647;Mt.kMaxLength=ee;h.TYPED_ARRAY_SUPPORT=pi();!h.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function pi(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}});Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}});function it(e){if(e>ee)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,h.prototype),t}function h(e,t,r){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Fe(e)}return Tr(e,t,r)}h.poolSize=8192;function Tr(e,t,r){if(typeof e=="string")return xi(e,t);if(ArrayBuffer.isView(e))return yi(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(rt(e,ArrayBuffer)||e&&rt(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(rt(e,SharedArrayBuffer)||e&&rt(e.buffer,SharedArrayBuffer)))return Ue(e,t,r);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=e.valueOf&&e.valueOf();if(n!=null&&n!==e)return h.from(n,t,r);let i=gi(e);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return h.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}h.from=function(e,t,r){return Tr(e,t,r)};Object.setPrototypeOf(h.prototype,Uint8Array.prototype);Object.setPrototypeOf(h,Uint8Array);function Lr(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function di(e,t,r){return Lr(e),e<=0?it(e):t!==void 0?typeof r=="string"?it(e).fill(t,r):it(e).fill(t):it(e)}h.alloc=function(e,t,r){return di(e,t,r)};function Fe(e){return Lr(e),it(e<0?0:Te(e)|0)}h.allocUnsafe=function(e){return Fe(e)};h.allocUnsafeSlow=function(e){return Fe(e)};function xi(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!h.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let r=Cr(e,t)|0,n=it(r),i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}function Se(e){let t=e.length<0?0:Te(e.length)|0,r=it(t);for(let n=0;n<t;n+=1)r[n]=e[n]&255;return r}function yi(e){if(rt(e,Uint8Array)){let t=new Uint8Array(e);return Ue(t.buffer,t.byteOffset,t.byteLength)}return Se(e)}function Ue(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return t===void 0&&r===void 0?n=new Uint8Array(e):r===void 0?n=new Uint8Array(e,t):n=new Uint8Array(e,t,r),Object.setPrototypeOf(n,h.prototype),n}function gi(e){if(h.isBuffer(e)){let t=Te(e.length)|0,r=it(t);return r.length===0||e.copy(r,0,0,t),r}if(e.length!==void 0)return typeof e.length!="number"||Ce(e.length)?it(0):Se(e);if(e.type==="Buffer"&&Array.isArray(e.data))return Se(e.data)}function Te(e){if(e>=ee)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ee.toString(16)+" bytes");return e|0}function wi(e){return+e!=e&&(e=0),h.alloc(+e)}h.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==h.prototype};h.compare=function(t,r){if(rt(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),rt(r,Uint8Array)&&(r=h.from(r,r.offset,r.byteLength)),!h.isBuffer(t)||!h.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;let n=t.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(t[o]!==r[o]){n=t[o],i=r[o];break}return n<i?-1:i<n?1:0};h.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};h.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return h.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<t.length;++n)r+=t[n].length;let i=h.allocUnsafe(r),o=0;for(n=0;n<t.length;++n){let s=t[n];if(rt(s,Uint8Array))o+s.length>i.length?(h.isBuffer(s)||(s=h.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(h.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Cr(e,t){if(h.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||rt(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let r=e.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return ve(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Hr(e).length;default:if(i)return n?-1:ve(e).length;t=(""+t).toLowerCase(),i=!0}}h.byteLength=Cr;function bi(e,t,r){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Fi(this,t,r);case"utf8":case"utf-8":return Nr(this,t,r);case"ascii":return Ui(this,t,r);case"latin1":case"binary":return vi(this,t,r);case"base64":return Ai(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ti(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}h.prototype._isBuffer=!0;function mt(e,t,r){let n=e[t];e[t]=e[r],e[r]=n}h.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<t;r+=2)mt(this,r,r+1);return this};h.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<t;r+=4)mt(this,r,r+3),mt(this,r+1,r+2);return this};h.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<t;r+=8)mt(this,r,r+7),mt(this,r+1,r+6),mt(this,r+2,r+5),mt(this,r+3,r+4);return this};h.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?Nr(this,0,t):bi.apply(this,arguments)};h.prototype.toLocaleString=h.prototype.toString;h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:h.compare(this,t)===0};h.prototype.inspect=function(){let t="",r=Mt.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"};Sr&&(h.prototype[Sr]=h.prototype.inspect);h.prototype.compare=function(t,r,n,i,o){if(rt(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),!h.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>t.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===t)return 0;let s=o-i,c=n-r,f=Math.min(s,c),u=this.slice(i,o),a=t.slice(r,n);for(let l=0;l<f;++l)if(u[l]!==a[l]){s=u[l],c=a[l];break}return s<c?-1:c<s?1:0};function Rr(e,t,r,n,i){if(e.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Ce(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof t=="string"&&(t=h.from(t,n)),h.isBuffer(t))return t.length===0?-1:Ur(e,t,r,n,i);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):Ur(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Ur(e,t,r,n,i){let o=1,s=e.length,c=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||t.length<2)return-1;o=2,s/=2,c/=2,r/=2}function f(a,l){return o===1?a[l]:a.readUInt16BE(l*o)}let u;if(i){let a=-1;for(u=r;u<s;u++)if(f(e,u)===f(t,a===-1?0:u-a)){if(a===-1&&(a=u),u-a+1===c)return a*o}else a!==-1&&(u-=u-a),a=-1}else for(r+c>s&&(r=s-c),u=r;u>=0;u--){let a=!0;for(let l=0;l<c;l++)if(f(e,u+l)!==f(t,l)){a=!1;break}if(a)return u}return-1}h.prototype.includes=function(t,r,n){return this.indexOf(t,r,n)!==-1};h.prototype.indexOf=function(t,r,n){return Rr(this,t,r,n,!0)};h.prototype.lastIndexOf=function(t,r,n){return Rr(this,t,r,n,!1)};function mi(e,t,r,n){r=Number(r)||0;let i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=t.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(t.substr(s*2,2),16);if(Ce(c))return s;e[r+s]=c}return s}function Bi(e,t,r,n){return re(ve(t,e.length-r),e,r,n)}function Ei(e,t,r,n){return re(Ni(t),e,r,n)}function _i(e,t,r,n){return re(Hr(t),e,r,n)}function Ii(e,t,r,n){return re(Di(t,e.length-r),e,r,n)}h.prototype.write=function(t,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),t.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return mi(this,t,r,n);case"utf8":case"utf-8":return Bi(this,t,r,n);case"ascii":case"latin1":case"binary":return Ei(this,t,r,n);case"base64":return _i(this,t,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ii(this,t,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ai(e,t,r){return t===0&&r===e.length?Ae.fromByteArray(e):Ae.fromByteArray(e.slice(t,r))}function Nr(e,t,r){r=Math.min(e.length,r);let n=[],i=t;for(;i<r;){let o=e[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=r){let f,u,a,l;switch(c){case 1:o<128&&(s=o);break;case 2:f=e[i+1],(f&192)===128&&(l=(o&31)<<6|f&63,l>127&&(s=l));break;case 3:f=e[i+1],u=e[i+2],(f&192)===128&&(u&192)===128&&(l=(o&15)<<12|(f&63)<<6|u&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:f=e[i+1],u=e[i+2],a=e[i+3],(f&192)===128&&(u&192)===128&&(a&192)===128&&(l=(o&15)<<18|(f&63)<<12|(u&63)<<6|a&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return Si(n)}var vr=4096;function Si(e){let t=e.length;if(t<=vr)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=vr));return r}function Ui(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]&127);return n}function vi(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function Fi(e,t,r){let n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=t;o<r;++o)i+=Oi[e[o]];return i}function Ti(e,t,r){let n=e.slice(t,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}h.prototype.slice=function(t,r){let n=this.length;t=~~t,r=r===void 0?n:~~r,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<t&&(r=t);let i=this.subarray(t,r);return Object.setPrototypeOf(i,h.prototype),i};function M(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}h.prototype.readUintLE=h.prototype.readUIntLE=function(t,r,n){t=t>>>0,r=r>>>0,n||M(t,r,this.length);let i=this[t],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[t+s]*o;return i};h.prototype.readUintBE=h.prototype.readUIntBE=function(t,r,n){t=t>>>0,r=r>>>0,n||M(t,r,this.length);let i=this[t+--r],o=1;for(;r>0&&(o*=256);)i+=this[t+--r]*o;return i};h.prototype.readUint8=h.prototype.readUInt8=function(t,r){return t=t>>>0,r||M(t,1,this.length),this[t]};h.prototype.readUint16LE=h.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||M(t,2,this.length),this[t]|this[t+1]<<8};h.prototype.readUint16BE=h.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||M(t,2,this.length),this[t]<<8|this[t+1]};h.prototype.readUint32LE=h.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||M(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};h.prototype.readUint32BE=h.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||M(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};h.prototype.readBigUInt64LE=lt(function(t){t=t>>>0,kt(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Wt(t,this.length-8);let i=r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});h.prototype.readBigUInt64BE=lt(function(t){t=t>>>0,kt(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Wt(t,this.length-8);let i=r*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});h.prototype.readIntLE=function(t,r,n){t=t>>>0,r=r>>>0,n||M(t,r,this.length);let i=this[t],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[t+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};h.prototype.readIntBE=function(t,r,n){t=t>>>0,r=r>>>0,n||M(t,r,this.length);let i=r,o=1,s=this[t+--i];for(;i>0&&(o*=256);)s+=this[t+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};h.prototype.readInt8=function(t,r){return t=t>>>0,r||M(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};h.prototype.readInt16LE=function(t,r){t=t>>>0,r||M(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};h.prototype.readInt16BE=function(t,r){t=t>>>0,r||M(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};h.prototype.readInt32LE=function(t,r){return t=t>>>0,r||M(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};h.prototype.readInt32BE=function(t,r){return t=t>>>0,r||M(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};h.prototype.readBigInt64LE=lt(function(t){t=t>>>0,kt(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Wt(t,this.length-8);let i=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});h.prototype.readBigInt64BE=lt(function(t){t=t>>>0,kt(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Wt(t,this.length-8);let i=(r<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n)});h.prototype.readFloatLE=function(t,r){return t=t>>>0,r||M(t,4,this.length),Ot.read(this,t,!0,23,4)};h.prototype.readFloatBE=function(t,r){return t=t>>>0,r||M(t,4,this.length),Ot.read(this,t,!1,23,4)};h.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||M(t,8,this.length),Ot.read(this,t,!0,52,8)};h.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||M(t,8,this.length),Ot.read(this,t,!1,52,8)};function q(e,t,r,n,i,o){if(!h.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}h.prototype.writeUintLE=h.prototype.writeUIntLE=function(t,r,n,i){if(t=+t,r=r>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;q(this,t,r,n,c,0)}let o=1,s=0;for(this[r]=t&255;++s<n&&(o*=256);)this[r+s]=t/o&255;return r+n};h.prototype.writeUintBE=h.prototype.writeUIntBE=function(t,r,n,i){if(t=+t,r=r>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;q(this,t,r,n,c,0)}let o=n-1,s=1;for(this[r+o]=t&255;--o>=0&&(s*=256);)this[r+o]=t/s&255;return r+n};h.prototype.writeUint8=h.prototype.writeUInt8=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,1,255,0),this[r]=t&255,r+1};h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2};h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2};h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4};h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function Dr(e,t,r,n,i){Kr(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s,r}function Or(e,t,r,n,i){Kr(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o=o>>8,e[r+6]=o,o=o>>8,e[r+5]=o,o=o>>8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s=s>>8,e[r+2]=s,s=s>>8,e[r+1]=s,s=s>>8,e[r]=s,r+8}h.prototype.writeBigUInt64LE=lt(function(t,r=0){return Dr(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});h.prototype.writeBigUInt64BE=lt(function(t,r=0){return Or(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});h.prototype.writeIntLE=function(t,r,n,i){if(t=+t,r=r>>>0,!i){let f=Math.pow(2,8*n-1);q(this,t,r,n,f-1,-f)}let o=0,s=1,c=0;for(this[r]=t&255;++o<n&&(s*=256);)t<0&&c===0&&this[r+o-1]!==0&&(c=1),this[r+o]=(t/s>>0)-c&255;return r+n};h.prototype.writeIntBE=function(t,r,n,i){if(t=+t,r=r>>>0,!i){let f=Math.pow(2,8*n-1);q(this,t,r,n,f-1,-f)}let o=n-1,s=1,c=0;for(this[r+o]=t&255;--o>=0&&(s*=256);)t<0&&c===0&&this[r+o+1]!==0&&(c=1),this[r+o]=(t/s>>0)-c&255;return r+n};h.prototype.writeInt8=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1};h.prototype.writeInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2};h.prototype.writeInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2};h.prototype.writeInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4};h.prototype.writeInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||q(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};h.prototype.writeBigInt64LE=lt(function(t,r=0){return Dr(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});h.prototype.writeBigInt64BE=lt(function(t,r=0){return Or(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function kr(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Mr(e,t,r,n,i){return t=+t,r=r>>>0,i||kr(e,t,r,4,34028234663852886e22,-34028234663852886e22),Ot.write(e,t,r,n,23,4),r+4}h.prototype.writeFloatLE=function(t,r,n){return Mr(this,t,r,!0,n)};h.prototype.writeFloatBE=function(t,r,n){return Mr(this,t,r,!1,n)};function Pr(e,t,r,n,i){return t=+t,r=r>>>0,i||kr(e,t,r,8,17976931348623157e292,-17976931348623157e292),Ot.write(e,t,r,n,52,8),r+8}h.prototype.writeDoubleLE=function(t,r,n){return Pr(this,t,r,!0,n)};h.prototype.writeDoubleBE=function(t,r,n){return Pr(this,t,r,!1,n)};h.prototype.copy=function(t,r,n,i){if(!h.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r<i-n&&(i=t.length-r+n);let o=i-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),r),o};h.prototype.fill=function(t,r,n,i){if(typeof t=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!h.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(t.length===1){let s=t.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let o;if(typeof t=="number")for(o=r;o<n;++o)this[o]=t;else{let s=h.isBuffer(t)?t:h.from(t,i),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%c]}return this};var Dt={};function Le(e,t,r){Dt[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}Le("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Le("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError);Le("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Fr(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Fr(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);function Fr(e){let t="",r=e.length,n=e[0]==="-"?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function Li(e,t,r){kt(t,"offset"),(e[t]===void 0||e[t+r]===void 0)&&Wt(t,e.length-(r+1))}function Kr(e,t,r,n,i,o){if(e>r||e<t){let s=typeof t=="bigint"?"n":"",c;throw o>3?t===0||t===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:c=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:c=`>= ${t}${s} and <= ${r}${s}`,new Dt.ERR_OUT_OF_RANGE("value",c,e)}Li(n,i,o)}function kt(e,t){if(typeof e!="number")throw new Dt.ERR_INVALID_ARG_TYPE(t,"number",e)}function Wt(e,t,r){throw Math.floor(e)!==e?(kt(e,r),new Dt.ERR_OUT_OF_RANGE(r||"offset","an integer",e)):t<0?new Dt.ERR_BUFFER_OUT_OF_BOUNDS:new Dt.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}var Ci=/[^+/0-9A-Za-z-_]/g;function Ri(e){if(e=e.split("=")[0],e=e.trim().replace(Ci,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function ve(e,t){t=t||1/0;let r,n=e.length,i=null,o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function Ni(e){let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function Di(e,t){let r,n,i,o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Hr(e){return Ae.toByteArray(Ri(e))}function re(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function rt(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function Ce(e){return e!==e}var Oi=function(){let e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function lt(e){return typeof BigInt>"u"?ki:e}function ki(){throw new Error("BigInt not supported")}});var bs={};ni(bs,{near:()=>lr});module.exports=oi(bs);var jn=ii(qr(),1);var Mi=20,Pi=1,Bt=1e6,jr=1e6,Ki=-7,Hi=21,qi=!1,Zt="[big.js] ",Et=Zt+"Invalid ",ne=Et+"decimal places",ji=Et+"rounding mode",zr=Zt+"Division by zero",S={},nt=void 0,zi=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Vr(){function e(t){var r=this;if(!(r instanceof e))return t===nt?Vr():new e(t);if(t instanceof e)r.s=t.s,r.e=t.e,r.c=t.c.slice();else{if(typeof t!="string"){if(e.strict===!0&&typeof t!="bigint")throw TypeError(Et+"value");t=t===0&&1/t<0?"-0":String(t)}Vi(r,t)}r.constructor=e}return e.prototype=S,e.DP=Mi,e.RM=Pi,e.NE=Ki,e.PE=Hi,e.strict=qi,e.roundDown=0,e.roundHalfUp=1,e.roundHalfEven=2,e.roundUp=3,e}function Vi(e,t){var r,n,i;if(!zi.test(t))throw Error(Et+"number");for(e.s=t.charAt(0)=="-"?(t=t.slice(1),-1):1,(r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),i=t.length,n=0;n<i&&t.charAt(n)=="0";)++n;if(n==i)e.c=[e.e=0];else{for(;i>0&&t.charAt(--i)=="0";);for(e.e=r-n-1,e.c=[],r=0;n<=i;)e.c[r++]=+t.charAt(n++)}return e}function _t(e,t,r,n){var i=e.c;if(r===nt&&(r=e.constructor.RM),r!==0&&r!==1&&r!==2&&r!==3)throw Error(ji);if(t<1)n=r===3&&(n||!!i[0])||t===0&&(r===1&&i[0]>=5||r===2&&(i[0]>5||i[0]===5&&(n||i[1]!==nt))),i.length=1,n?(e.e=e.e-t+1,i[0]=1):i[0]=e.e=0;else if(t<i.length){if(n=r===1&&i[t]>=5||r===2&&(i[t]>5||i[t]===5&&(n||i[t+1]!==nt||i[t-1]&1))||r===3&&(n||!!i[0]),i.length=t,n){for(;++i[--t]>9;)if(i[t]=0,t===0){++e.e,i.unshift(1);break}}for(t=i.length;!i[--t];)i.pop()}return e}function It(e,t,r){var n=e.e,i=e.c.join(""),o=i.length;if(t)i=i.charAt(0)+(o>1?"."+i.slice(1):"")+(n<0?"e":"e+")+n;else if(n<0){for(;++n;)i="0"+i;i="0."+i}else if(n>0)if(++n>o)for(n-=o;n--;)i+="0";else n<o&&(i=i.slice(0,n)+"."+i.slice(n));else o>1&&(i=i.charAt(0)+"."+i.slice(1));return e.s<0&&r?"-"+i:i}S.abs=function(){var e=new this.constructor(this);return e.s=1,e};S.cmp=function(e){var t,r=this,n=r.c,i=(e=new r.constructor(e)).c,o=r.s,s=e.s,c=r.e,f=e.e;if(!n[0]||!i[0])return n[0]?o:i[0]?-s:0;if(o!=s)return o;if(t=o<0,c!=f)return c>f^t?1:-1;for(s=(c=n.length)<(f=i.length)?c:f,o=-1;++o<s;)if(n[o]!=i[o])return n[o]>i[o]^t?1:-1;return c==f?0:c>f^t?1:-1};S.div=function(e){var t=this,r=t.constructor,n=t.c,i=(e=new r(e)).c,o=t.s==e.s?1:-1,s=r.DP;if(s!==~~s||s<0||s>Bt)throw Error(ne);if(!i[0])throw Error(zr);if(!n[0])return e.s=o,e.c=[e.e=0],e;var c,f,u,a,l,d=i.slice(),x=c=i.length,b=n.length,g=n.slice(0,c),_=g.length,D=e,v=D.c=[],y=0,O=s+(D.e=t.e-e.e)+1;for(D.s=o,o=O<0?0:O,d.unshift(0);_++<c;)g.push(0);do{for(u=0;u<10;u++){if(c!=(_=g.length))a=c>_?1:-1;else for(l=-1,a=0;++l<c;)if(i[l]!=g[l]){a=i[l]>g[l]?1:-1;break}if(a<0){for(f=_==c?i:d;_;){if(g[--_]<f[_]){for(l=_;l&&!g[--l];)g[l]=9;--g[l],g[_]+=10}g[_]-=f[_]}for(;!g[0];)g.shift()}else break}v[y++]=a?u:++u,g[0]&&a?g[_]=n[x]||0:g=[n[x]]}while((x++<b||g[0]!==nt)&&o--);return!v[0]&&y!=1&&(v.shift(),D.e--,O--),y>O&&_t(D,O,r.RM,g[0]!==nt),D};S.eq=function(e){return this.cmp(e)===0};S.gt=function(e){return this.cmp(e)>0};S.gte=function(e){return this.cmp(e)>-1};S.lt=function(e){return this.cmp(e)<0};S.lte=function(e){return this.cmp(e)<1};S.minus=S.sub=function(e){var t,r,n,i,o=this,s=o.constructor,c=o.s,f=(e=new s(e)).s;if(c!=f)return e.s=-f,o.plus(e);var u=o.c.slice(),a=o.e,l=e.c,d=e.e;if(!u[0]||!l[0])return l[0]?e.s=-f:u[0]?e=new s(o):e.s=1,e;if(c=a-d){for((i=c<0)?(c=-c,n=u):(d=a,n=l),n.reverse(),f=c;f--;)n.push(0);n.reverse()}else for(r=((i=u.length<l.length)?u:l).length,c=f=0;f<r;f++)if(u[f]!=l[f]){i=u[f]<l[f];break}if(i&&(n=u,u=l,l=n,e.s=-e.s),(f=(r=l.length)-(t=u.length))>0)for(;f--;)u[t++]=0;for(f=t;r>c;){if(u[--r]<l[r]){for(t=r;t&&!u[--t];)u[t]=9;--u[t],u[r]+=10}u[r]-=l[r]}for(;u[--f]===0;)u.pop();for(;u[0]===0;)u.shift(),--d;return u[0]||(e.s=1,u=[d=0]),e.c=u,e.e=d,e};S.mod=function(e){var t,r=this,n=r.constructor,i=r.s,o=(e=new n(e)).s;if(!e.c[0])throw Error(zr);return r.s=e.s=1,t=e.cmp(r)==1,r.s=i,e.s=o,t?new n(r):(i=n.DP,o=n.RM,n.DP=n.RM=0,r=r.div(e),n.DP=i,n.RM=o,this.minus(r.times(e)))};S.neg=function(){var e=new this.constructor(this);return e.s=-e.s,e};S.plus=S.add=function(e){var t,r,n,i=this,o=i.constructor;if(e=new o(e),i.s!=e.s)return e.s=-e.s,i.minus(e);var s=i.e,c=i.c,f=e.e,u=e.c;if(!c[0]||!u[0])return u[0]||(c[0]?e=new o(i):e.s=i.s),e;if(c=c.slice(),t=s-f){for(t>0?(f=s,n=u):(t=-t,n=c),n.reverse();t--;)n.push(0);n.reverse()}for(c.length-u.length<0&&(n=u,u=c,c=n),t=u.length,r=0;t;c[t]%=10)r=(c[--t]=c[t]+u[t]+r)/10|0;for(r&&(c.unshift(r),++f),t=c.length;c[--t]===0;)c.pop();return e.c=c,e.e=f,e};S.pow=function(e){var t=this,r=new t.constructor("1"),n=r,i=e<0;if(e!==~~e||e<-jr||e>jr)throw Error(Et+"exponent");for(i&&(e=-e);e&1&&(n=n.times(t)),e>>=1,!!e;)t=t.times(t);return i?r.div(n):n};S.prec=function(e,t){if(e!==~~e||e<1||e>Bt)throw Error(Et+"precision");return _t(new this.constructor(this),e,t)};S.round=function(e,t){if(e===nt)e=0;else if(e!==~~e||e<-Bt||e>Bt)throw Error(ne);return _t(new this.constructor(this),e+this.e+1,t)};S.sqrt=function(){var e,t,r,n=this,i=n.constructor,o=n.s,s=n.e,c=new i("0.5");if(!n.c[0])return new i(n);if(o<0)throw Error(Zt+"No square root");o=Math.sqrt(+It(n,!0,!0)),o===0||o===1/0?(t=n.c.join(""),t.length+s&1||(t+="0"),o=Math.sqrt(t),s=((s+1)/2|0)-(s<0||s&1),e=new i((o==1/0?"5e":(o=o.toExponential()).slice(0,o.indexOf("e")+1))+s)):e=new i(o+""),s=e.e+(i.DP+=4);do r=e,e=c.times(r.plus(n.div(r)));while(r.c.slice(0,s).join("")!==e.c.slice(0,s).join(""));return _t(e,(i.DP-=4)+e.e+1,i.RM)};S.times=S.mul=function(e){var t,r=this,n=r.constructor,i=r.c,o=(e=new n(e)).c,s=i.length,c=o.length,f=r.e,u=e.e;if(e.s=r.s==e.s?1:-1,!i[0]||!o[0])return e.c=[e.e=0],e;for(e.e=f+u,s<c&&(t=i,i=o,o=t,u=s,s=c,c=u),t=new Array(u=s+c);u--;)t[u]=0;for(f=c;f--;){for(c=0,u=s+f;u>f;)c=t[u]+o[f]*i[u-f-1]+c,t[u--]=c%10,c=c/10|0;t[u]=c}for(c?++e.e:t.shift(),f=t.length;!t[--f];)t.pop();return e.c=t,e};S.toExponential=function(e,t){var r=this,n=r.c[0];if(e!==nt){if(e!==~~e||e<0||e>Bt)throw Error(ne);for(r=_t(new r.constructor(r),++e,t);r.c.length<e;)r.c.push(0)}return It(r,!0,!!n)};S.toFixed=function(e,t){var r=this,n=r.c[0];if(e!==nt){if(e!==~~e||e<0||e>Bt)throw Error(ne);for(r=_t(new r.constructor(r),e+r.e+1,t),e=e+r.e+1;r.c.length<e;)r.c.push(0)}return It(r,!1,!!n)};S[Symbol.for("nodejs.util.inspect.custom")]=S.toJSON=S.toString=function(){var e=this,t=e.constructor;return It(e,e.e<=t.NE||e.e>=t.PE,!!e.c[0])};S.toNumber=function(){var e=+It(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(e.toString()))throw Error(Zt+"Imprecise conversion");return e};S.toPrecision=function(e,t){var r=this,n=r.constructor,i=r.c[0];if(e!==nt){if(e!==~~e||e<1||e>Bt)throw Error(Et+"precision");for(r=_t(new n(r),e,t);r.c.length<e;)r.c.push(0)}return It(r,e<=r.e||r.e<=n.NE||r.e>=n.PE,!!i)};S.valueOf=function(){var e=this,t=e.constructor;if(t.strict===!0)throw Error(Zt+"valueOf disallowed");return It(e,e.e<=t.NE||e.e>=t.PE,!0)};var Gi=Vr(),W=Gi;var Gr=class Wr{#t=null;#r;#i;#n=new Map;#e={};#o;#s;static defaultWidgetUrl="https://wallet-adapter.fastnear.com";constructor({widgetUrl:t=Wr.defaultWidgetUrl,targetOrigin:r="*",onStateUpdate:n,callbackUrl:i=window.location.href}={}){this.#r=r,this.#i=t,this.#o=n,this.#s=i,window.addEventListener("message",this.#c.bind(this))}#u(t){this.#t&&this.#t.remove();let r=new URL(t,this.#i),n=document.createElement("iframe");return n.src=r.toString(),n.allow="usb",n.style.border="none",n.style.zIndex="10000",n.style.position="fixed",n.style.display="block",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",document.body.appendChild(n),this.#t=n,n}#c(t){if(this.#r!=="*"&&t.origin!==this.#r)return;let{id:r,type:n,action:i,payload:o}=t.data;if(n!=="wallet-adapter")return;if(i==="close"){this.#t?.remove(),this.#t=null;return}o?.state&&(this.#e={...this.#e,...o.state},this.#o?.(this.#e));let s=this.#n.get(r);s&&(this.#n.delete(r),this.#t?.remove(),this.#t=null,s(o))}async#f(t,r,n){return new Promise(i=>{let o=Math.random().toString(36).slice(2);this.#n.set(o,i);let s=this.#u(t);s.onload=()=>{s.contentWindow?.postMessage({type:"wallet-adapter",method:r,params:{id:o,...n,state:this.#e,callbackUrl:n.callbackUrl||this.#s}},this.#r)}})}getState(){return{...this.#e}}async signIn(t){return this.#f("/login.html","signIn",t)}async sendTransaction(t){return this.#f("/sign.html","sendTransaction",t)}destroy(){window.removeEventListener("message",this.#c),this.#t?.remove(),this.#t=null}};function Wi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Re(e,...t){if(!Wi(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ne(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 Zr(e,t){Re(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var At=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var oe=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function $r(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function De(e){return typeof e=="string"&&(e=$r(e)),Re(e),e}var ie=class{clone(){return this._cloneInto()}};function Yr(e){let t=n=>e().update(De(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Xr(e=32){if(At&&typeof At.getRandomValues=="function")return At.getRandomValues(new Uint8Array(e));if(At&&typeof At.randomBytes=="function")return At.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function Zi(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),f=n?4:0,u=n?0:4;e.setUint32(t+f,s,n),e.setUint32(t+u,c,n)}var se=class extends ie{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=oe(this.buffer)}update(t){Ne(this);let{view:r,buffer:n,blockLen:i}=this;t=De(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let f=oe(t);for(;i<=o-s;s+=i)this.process(f,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ne(this),Zr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)r[l]=0;Zi(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=oe(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=f/4,a=this.get();if(u>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,a[l],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%r&&t.buffer.set(n),t}};var ce=BigInt(4294967295),Oe=BigInt(32);function Jr(e,t=!1){return t?{h:Number(e&ce),l:Number(e>>Oe&ce)}:{h:Number(e>>Oe&ce)|0,l:Number(e&ce)|0}}function $i(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){let{h:o,l:s}=Jr(e[i],t);[r[i],n[i]]=[o,s]}return[r,n]}var Yi=(e,t)=>BigInt(e>>>0)<<Oe|BigInt(t>>>0),Xi=(e,t,r)=>e>>>r,Ji=(e,t,r)=>e<<32-r|t>>>r,Qi=(e,t,r)=>e>>>r|t<<32-r,to=(e,t,r)=>e<<32-r|t>>>r,eo=(e,t,r)=>e<<64-r|t>>>r-32,ro=(e,t,r)=>e>>>r-32|t<<64-r,no=(e,t)=>t,io=(e,t)=>e,oo=(e,t,r)=>e<<r|t>>>32-r,so=(e,t,r)=>t<<r|e>>>32-r,co=(e,t,r)=>t<<r-32|e>>>64-r,fo=(e,t,r)=>e<<r-32|t>>>64-r;function uo(e,t,r,n){let i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:i|0}}var ao=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),lo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ho=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),po=(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0,xo=(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0),yo=(e,t,r,n,i,o)=>t+r+n+i+o+(e/2**32|0)|0;var go={fromBig:Jr,split:$i,toBig:Yi,shrSH:Xi,shrSL:Ji,rotrSH:Qi,rotrSL:to,rotrBH:eo,rotrBL:ro,rotr32H:no,rotr32L:io,rotlSH:oo,rotlSL:so,rotlBH:co,rotlBL:fo,add:uo,add3L:ao,add3H:lo,add4L:ho,add4H:po,add5H:yo,add5L:xo},E=go;var[wo,bo]=E.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),ht=new Uint32Array(80),pt=new Uint32Array(80),ke=class extends se{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:f,Eh:u,El:a,Fh:l,Fl:d,Gh:x,Gl:b,Hh:g,Hl:_}=this;return[t,r,n,i,o,s,c,f,u,a,l,d,x,b,g,_]}set(t,r,n,i,o,s,c,f,u,a,l,d,x,b,g,_){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=f|0,this.Eh=u|0,this.El=a|0,this.Fh=l|0,this.Fl=d|0,this.Gh=x|0,this.Gl=b|0,this.Hh=g|0,this.Hl=_|0}process(t,r){for(let y=0;y<16;y++,r+=4)ht[y]=t.getUint32(r),pt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let O=ht[y-15]|0,J=pt[y-15]|0,ut=E.rotrSH(O,J,1)^E.rotrSH(O,J,8)^E.shrSH(O,J,7),Ct=E.rotrSL(O,J,1)^E.rotrSL(O,J,8)^E.shrSL(O,J,7),z=ht[y-2]|0,K=pt[y-2]|0,Rt=E.rotrSH(z,K,19)^E.rotrBH(z,K,61)^E.shrSH(z,K,6),gt=E.rotrSL(z,K,19)^E.rotrBL(z,K,61)^E.shrSL(z,K,6),Nt=E.add4L(Ct,gt,pt[y-7],pt[y-16]),Gt=E.add4H(Nt,ut,Rt,ht[y-7],ht[y-16]);ht[y]=Gt|0,pt[y]=Nt|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:f,Dh:u,Dl:a,Eh:l,El:d,Fh:x,Fl:b,Gh:g,Gl:_,Hh:D,Hl:v}=this;for(let y=0;y<80;y++){let O=E.rotrSH(l,d,14)^E.rotrSH(l,d,18)^E.rotrBH(l,d,41),J=E.rotrSL(l,d,14)^E.rotrSL(l,d,18)^E.rotrBL(l,d,41),ut=l&x^~l&g,Ct=d&b^~d&_,z=E.add5L(v,J,Ct,bo[y],pt[y]),K=E.add5H(z,D,O,ut,wo[y],ht[y]),Rt=z|0,gt=E.rotrSH(n,i,28)^E.rotrBH(n,i,34)^E.rotrBH(n,i,39),Nt=E.rotrSL(n,i,28)^E.rotrBL(n,i,34)^E.rotrBL(n,i,39),Gt=n&o^n&c^o&c,be=i&s^i&f^s&f;D=g|0,v=_|0,g=x|0,_=b|0,x=l|0,b=d|0,{h:l,l:d}=E.add(u|0,a|0,K|0,Rt|0),u=c|0,a=f|0,c=o|0,f=s|0,o=n|0,s=i|0;let me=E.add3L(Rt,Nt,be);n=E.add3H(me,K,gt,Gt),i=me|0}({h:n,l:i}=E.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=E.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:f}=E.add(this.Ch|0,this.Cl|0,c|0,f|0),{h:u,l:a}=E.add(this.Dh|0,this.Dl|0,u|0,a|0),{h:l,l:d}=E.add(this.Eh|0,this.El|0,l|0,d|0),{h:x,l:b}=E.add(this.Fh|0,this.Fl|0,x|0,b|0),{h:g,l:_}=E.add(this.Gh|0,this.Gl|0,g|0,_|0),{h:D,l:v}=E.add(this.Hh|0,this.Hl|0,D|0,v|0),this.set(n,i,o,s,c,f,u,a,l,d,x,b,g,_,D,v)}roundClean(){ht.fill(0),pt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Qr=Yr(()=>new ke);var Pe=BigInt(0),en=BigInt(1),mo=BigInt(2);function Ke(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function He(e){if(!Ke(e))throw new Error("Uint8Array expected")}function fe(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}var Bo=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ue(e){He(e);let t="";for(let r=0;r<e.length;r++)t+=Bo[e[r]];return t}function rn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Pe:BigInt("0x"+e)}var ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function tn(e){if(e>=ot._0&&e<=ot._9)return e-ot._0;if(e>=ot.A&&e<=ot.F)return e-(ot.A-10);if(e>=ot.a&&e<=ot.f)return e-(ot.a-10)}function nn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=tn(e.charCodeAt(o)),c=tn(e.charCodeAt(o+1));if(s===void 0||c===void 0){let f=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+o)}n[i]=s*16+c}return n}function on(e){return rn(ue(e))}function Pt(e){return He(e),rn(ue(Uint8Array.from(e).reverse()))}function qe(e,t){return nn(e.toString(16).padStart(t*2,"0"))}function $t(e,t){return qe(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=nn(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Ke(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(e+" of length "+r+" expected, got "+i);return n}function je(...e){let t=0;for(let n=0;n<e.length;n++){let i=e[n];He(i),t+=i.length}let r=new Uint8Array(t);for(let n=0,i=0;n<e.length;n++){let o=e[n];r.set(o,i),i+=o.length}return r}var Me=e=>typeof e=="bigint"&&Pe<=e;function Eo(e,t,r){return Me(e)&&Me(t)&&Me(r)&&t<=e&&e<r}function Kt(e,t,r,n){if(!Eo(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function sn(e){let t;for(t=0;e>Pe;e>>=en,t+=1);return t}var cn=e=>(mo<<BigInt(e-1))-en;var _o={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Ke(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Ht(e,t,r={}){let n=(i,o,s)=>{let c=_o[o];if(typeof c!="function")throw new Error("invalid validator function");let f=e[i];if(!(s&&f===void 0)&&!c(f,e))throw new Error("param "+String(i)+" is invalid. Expected "+o+", got "+f)};for(let[i,o]of Object.entries(t))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return e}function ze(e){let t=new WeakMap;return(r,...n)=>{let i=t.get(r);if(i!==void 0)return i;let o=e(r,...n);return t.set(r,o),o}}var k=BigInt(0),C=BigInt(1),St=BigInt(2),Ao=BigInt(3),Ve=BigInt(4),fn=BigInt(5),un=BigInt(8),So=BigInt(9),Uo=BigInt(16);function R(e,t){let r=e%t;return r>=k?r:t+r}function vo(e,t,r){if(t<k)throw new Error("invalid exponent, negatives unsupported");if(r<=k)throw new Error("invalid modulus");if(r===C)return k;let n=C;for(;t>k;)t&C&&(n=n*e%r),e=e*e%r,t>>=C;return n}function $(e,t,r){let n=e;for(;t-- >k;)n*=n,n%=r;return n}function an(e,t){if(e===k)throw new Error("invert: expected non-zero number");if(t<=k)throw new Error("invert: expected positive modulus, got "+t);let r=R(e,t),n=t,i=k,o=C,s=C,c=k;for(;r!==k;){let u=n/r,a=n%r,l=i-s*u,d=o-c*u;n=r,r=a,i=s,o=c,s=l,c=d}if(n!==C)throw new Error("invert: does not exist");return R(i,t)}function Fo(e){let t=(e-C)/St,r,n,i;for(r=e-C,n=0;r%St===k;r/=St,n++);for(i=St;i<e&&vo(i,t,e)!==e-C;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(e+C)/Ve;return function(f,u){let a=f.pow(u,s);if(!f.eql(f.sqr(a),u))throw new Error("Cannot find square root");return a}}let o=(r+C)/St;return function(c,f){if(c.pow(f,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,a=c.pow(c.mul(c.ONE,i),r),l=c.pow(f,o),d=c.pow(f,r);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let x=1;for(let g=c.sqr(d);x<u&&!c.eql(g,c.ONE);x++)g=c.sqr(g);let b=c.pow(a,C<<BigInt(u-x-1));a=c.sqr(b),l=c.mul(l,b),d=c.mul(d,a),u=x}return l}}function To(e){if(e%Ve===Ao){let t=(e+C)/Ve;return function(n,i){let o=n.pow(i,t);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(e%un===fn){let t=(e-fn)/un;return function(n,i){let o=n.mul(i,St),s=n.pow(o,t),c=n.mul(i,s),f=n.mul(n.mul(c,St),s),u=n.mul(c,n.sub(f,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return e%Uo,Fo(e)}var ln=(e,t)=>(R(e,t)&C)===C,Lo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Lo.reduce((n,i)=>(n[i]="function",n),t);return Ht(e,r)}function Co(e,t,r){if(r<k)throw new Error("invalid exponent, negatives unsupported");if(r===k)return e.ONE;if(r===C)return t;let n=e.ONE,i=t;for(;r>k;)r&C&&(n=e.mul(n,i)),i=e.sqr(i),r>>=C;return n}function Ro(e,t){let r=new Array(t.length),n=t.reduce((o,s,c)=>e.is0(s)?o:(r[c]=o,e.mul(o,s)),e.ONE),i=e.inv(n);return t.reduceRight((o,s,c)=>e.is0(s)?o:(r[c]=e.mul(o,r[c]),e.mul(o,s)),i),r}function Ge(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ae(e,t,r=!1,n={}){if(e<=k)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:i,nByteLength:o}=Ge(e,t);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,c=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:cn(i),ZERO:k,ONE:C,create:f=>R(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return k<=f&&f<e},is0:f=>f===k,isOdd:f=>(f&C)===C,neg:f=>R(-f,e),eql:(f,u)=>f===u,sqr:f=>R(f*f,e),add:(f,u)=>R(f+u,e),sub:(f,u)=>R(f-u,e),mul:(f,u)=>R(f*u,e),pow:(f,u)=>Co(c,f,u),div:(f,u)=>R(f*an(u,e),e),sqrN:f=>f*f,addN:(f,u)=>f+u,subN:(f,u)=>f-u,mulN:(f,u)=>f*u,inv:f=>an(f,e),sqrt:n.sqrt||(f=>(s||(s=To(e)),s(c,f))),invertBatch:f=>Ro(c,f),cmov:(f,u,a)=>a?u:f,toBytes:f=>r?$t(f,o):qe(f,o),fromBytes:f=>{if(f.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+f.length);return r?Pt(f):on(f)}});return Object.freeze(c)}var pn=BigInt(0),le=BigInt(1);function We(e,t){let r=t.negate();return e?r:t}function dn(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ze(e,t){dn(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function No(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Do(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var $e=new WeakMap,xn=new WeakMap;function Ye(e){return xn.get(e)||1}function yn(e,t){return{constTimeNegate:We,hasPrecomputes(r){return Ye(r)!==1},unsafeLadder(r,n,i=e.ZERO){let o=r;for(;n>pn;)n&le&&(i=i.add(o)),o=o.double(),n>>=le;return i},precomputeWindow(r,n){let{windows:i,windowSize:o}=Ze(n,t),s=[],c=r,f=c;for(let u=0;u<i;u++){f=c,s.push(f);for(let a=1;a<o;a++)f=f.add(c),s.push(f);c=f.double()}return s},wNAF(r,n,i){let{windows:o,windowSize:s}=Ze(r,t),c=e.ZERO,f=e.BASE,u=BigInt(2**r-1),a=2**r,l=BigInt(r);for(let d=0;d<o;d++){let x=d*s,b=Number(i&u);i>>=l,b>s&&(b-=a,i+=le);let g=x,_=x+Math.abs(b)-1,D=d%2!==0,v=b<0;b===0?f=f.add(We(D,n[g])):c=c.add(We(v,n[_]))}return{p:c,f}},wNAFUnsafe(r,n,i,o=e.ZERO){let{windows:s,windowSize:c}=Ze(r,t),f=BigInt(2**r-1),u=2**r,a=BigInt(r);for(let l=0;l<s;l++){let d=l*c;if(i===pn)break;let x=Number(i&f);if(i>>=a,x>c&&(x-=u,i+=le),x===0)continue;let b=n[d+Math.abs(x)-1];x<0&&(b=b.negate()),o=o.add(b)}return o},getPrecomputes(r,n,i){let o=$e.get(n);return o||(o=this.precomputeWindow(n,r),r!==1&&$e.set(n,i(o))),o},wNAFCached(r,n,i){let o=Ye(r);return this.wNAF(o,this.getPrecomputes(o,r,i),n)},wNAFCachedUnsafe(r,n,i,o){let s=Ye(r);return s===1?this.unsafeLadder(r,n,o):this.wNAFUnsafe(s,this.getPrecomputes(s,r,i),n,o)},setWindowSize(r,n){dn(n,t),xn.set(r,n),$e.delete(r)}}}function gn(e,t,r,n){if(No(r,e),Do(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,o=sn(BigInt(r.length)),s=o>12?o-3:o>4?o-2:o?2:1,c=(1<<s)-1,f=new Array(c+1).fill(i),u=Math.floor((t.BITS-1)/s)*s,a=i;for(let l=u;l>=0;l-=s){f.fill(i);for(let x=0;x<n.length;x++){let b=n[x],g=Number(b>>BigInt(l)&BigInt(c));f[g]=f[g].add(r[x])}let d=i;for(let x=f.length-1,b=i;x>0;x--)b=b.add(f[x]),d=d.add(b);if(a=a.add(d),l!==0)for(let x=0;x<s;x++)a=a.double()}return a}function wn(e){return hn(e.Fp),Ht(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ge(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Y=BigInt(0),j=BigInt(1),he=BigInt(2),Oo=BigInt(8),ko={zip215:!0};function Mo(e){let t=wn(e);return Ht(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function bn(e){let t=Mo(e),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:f}=t,u=he<<BigInt(c*8)-j,a=r.create,l=ae(t.n,t.nBitLength),d=t.uvRatio||((B,p)=>{try{return{isValid:!0,value:r.sqrt(B*r.inv(p))}}catch{return{isValid:!1,value:Y}}}),x=t.adjustScalarBytes||(B=>B),b=t.domain||((B,p,w)=>{if(fe("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return B});function g(B,p){Kt("coordinate "+B,p,Y,u)}function _(B){if(!(B instanceof y))throw new Error("ExtendedPoint expected")}let D=ze((B,p)=>{let{ex:w,ey:m,ez:I}=B,A=B.is0();p==null&&(p=A?Oo:r.inv(I));let U=a(w*p),T=a(m*p),F=a(I*p);if(A)return{x:Y,y:j};if(F!==j)throw new Error("invZ was invalid");return{x:U,y:T}}),v=ze(B=>{let{a:p,d:w}=t;if(B.is0())throw new Error("bad point: ZERO");let{ex:m,ey:I,ez:A,et:U}=B,T=a(m*m),F=a(I*I),L=a(A*A),P=a(L*L),H=a(T*p),Q=a(L*a(H+F)),tt=a(P+a(w*a(T*F)));if(Q!==tt)throw new Error("bad point: equation left != right (1)");let V=a(m*I),at=a(A*U);if(V!==at)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,w,m,I){this.ex=p,this.ey=w,this.ez=m,this.et=I,g("x",p),g("y",w),g("z",m),g("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x:w,y:m}=p||{};return g("x",w),g("y",m),new y(w,m,j,a(w*m))}static normalizeZ(p){let w=r.invertBatch(p.map(m=>m.ez));return p.map((m,I)=>m.toAffine(w[I])).map(y.fromAffine)}static msm(p,w){return gn(y,l,p,w)}_setWindowSize(p){ut.setWindowSize(this,p)}assertValidity(){v(this)}equals(p){_(p);let{ex:w,ey:m,ez:I}=this,{ex:A,ey:U,ez:T}=p,F=a(w*T),L=a(A*I),P=a(m*T),H=a(U*I);return F===L&&P===H}is0(){return this.equals(y.ZERO)}negate(){return new y(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:p}=t,{ex:w,ey:m,ez:I}=this,A=a(w*w),U=a(m*m),T=a(he*a(I*I)),F=a(p*A),L=w+m,P=a(a(L*L)-A-U),H=F+U,Q=H-T,tt=F-U,V=a(P*Q),at=a(H*tt),wt=a(P*tt),Jt=a(Q*H);return new y(V,at,Jt,wt)}add(p){_(p);let{a:w,d:m}=t,{ex:I,ey:A,ez:U,et:T}=this,{ex:F,ey:L,ez:P,et:H}=p;if(w===BigInt(-1)){let dr=a((A-I)*(L+F)),xr=a((A+I)*(L-F)),Be=a(xr-dr);if(Be===Y)return this.double();let yr=a(U*he*H),gr=a(T*he*P),wr=gr+yr,br=xr+dr,mr=gr-yr,Zn=a(wr*Be),$n=a(br*mr),Yn=a(wr*mr),Xn=a(Be*br);return new y(Zn,$n,Xn,Yn)}let Q=a(I*F),tt=a(A*L),V=a(T*m*H),at=a(U*P),wt=a((I+A)*(F+L)-Q-tt),Jt=at-V,hr=at+V,pr=a(tt-w*Q),zn=a(wt*Jt),Vn=a(hr*pr),Gn=a(wt*pr),Wn=a(Jt*hr);return new y(zn,Vn,Wn,Gn)}subtract(p){return this.add(p.negate())}wNAF(p){return ut.wNAFCached(this,p,y.normalizeZ)}multiply(p){let w=p;Kt("scalar",w,j,n);let{p:m,f:I}=this.wNAF(w);return y.normalizeZ([m,I])[0]}multiplyUnsafe(p,w=y.ZERO){let m=p;return Kt("scalar",m,Y,n),m===Y?J:this.is0()||m===j?this:ut.wNAFCachedUnsafe(this,m,y.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(f).is0()}isTorsionFree(){return ut.unsafeLadder(this,n).is0()}toAffine(p){return D(this,p)}clearCofactor(){let{h:p}=t;return p===j?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:m,a:I}=t,A=r.BYTES;p=Z("pointHex",p,A),fe("zip215",w);let U=p.slice(),T=p[A-1];U[A-1]=T&-129;let F=Pt(U),L=w?u:r.ORDER;Kt("pointHex.y",F,Y,L);let P=a(F*F),H=a(P-j),Q=a(m*P-I),{isValid:tt,value:V}=d(H,Q);if(!tt)throw new Error("Point.fromHex: invalid y coordinate");let at=(V&j)===j,wt=(T&128)!==0;if(!w&&V===Y&&wt)throw new Error("Point.fromHex: x=0 and x_0=1");return wt!==at&&(V=a(-V)),y.fromAffine({x:V,y:F})}static fromPrivateKey(p){return K(p).point}toRawBytes(){let{x:p,y:w}=this.toAffine(),m=$t(w,r.BYTES);return m[m.length-1]|=p&j?128:0,m}toHex(){return ue(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,j,a(t.Gx*t.Gy)),y.ZERO=new y(Y,j,j,Y);let{BASE:O,ZERO:J}=y,ut=yn(y,c*8);function Ct(B){return R(B,n)}function z(B){return Ct(Pt(B))}function K(B){let p=r.BYTES;B=Z("private key",B,p);let w=Z("hashed private key",o(B),2*p),m=x(w.slice(0,p)),I=w.slice(p,2*p),A=z(m),U=O.multiply(A),T=U.toRawBytes();return{head:m,prefix:I,scalar:A,point:U,pointBytes:T}}function Rt(B){return K(B).pointBytes}function gt(B=new Uint8Array,...p){let w=je(...p);return z(o(b(w,Z("context",B),!!i)))}function Nt(B,p,w={}){B=Z("message",B),i&&(B=i(B));let{prefix:m,scalar:I,pointBytes:A}=K(p),U=gt(w.context,m,B),T=O.multiply(U).toRawBytes(),F=gt(w.context,T,A,B),L=Ct(U+F*I);Kt("signature.s",L,Y,n);let P=je(T,$t(L,r.BYTES));return Z("result",P,r.BYTES*2)}let Gt=ko;function be(B,p,w,m=Gt){let{context:I,zip215:A}=m,U=r.BYTES;B=Z("signature",B,2*U),p=Z("message",p),w=Z("publicKey",w,U),A!==void 0&&fe("zip215",A),i&&(p=i(p));let T=Pt(B.slice(U,2*U)),F,L,P;try{F=y.fromHex(w,A),L=y.fromHex(B.slice(0,U),A),P=O.multiplyUnsafe(T)}catch{return!1}if(!A&&F.isSmallOrder())return!1;let H=gt(I,L.toRawBytes(),F.toRawBytes(),p);return L.add(F.multiplyUnsafe(H)).subtract(P).clearCofactor().equals(y.ZERO)}return O._setWindowSize(8),{CURVE:t,getPublicKey:Rt,sign:Nt,verify:be,ExtendedPoint:y,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>s(r.BYTES),precompute(B=8,p=y.BASE){return p._setWindowSize(B),p.multiply(BigInt(3)),p}}}}var Xe=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),mn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ec=BigInt(0),Po=BigInt(1),Bn=BigInt(2),rc=BigInt(3),Ko=BigInt(5),Ho=BigInt(8);function qo(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),o=Xe,c=e*e%o*e%o,f=$(c,Bn,o)*c%o,u=$(f,Po,o)*e%o,a=$(u,Ko,o)*u%o,l=$(a,t,o)*a%o,d=$(l,r,o)*l%o,x=$(d,n,o)*d%o,b=$(x,i,o)*x%o,g=$(b,i,o)*x%o,_=$(g,t,o)*a%o;return{pow_p_5_8:$(_,Bn,o)*e%o,b2:c}}function jo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function zo(e,t){let r=Xe,n=R(t*t*t,r),i=R(n*n*t,r),o=qo(e*i).pow_p_5_8,s=R(e*n*o,r),c=R(t*s*s,r),f=s,u=R(s*mn,r),a=c===e,l=c===R(-e,r),d=c===R(-e*mn,r);return a&&(s=f),(l||d)&&(s=u),ln(s,r)&&(s=R(-s,r)),{isValid:a||l,value:s}}var Vo=ae(Xe,void 0,!0),Go={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Vo,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Ho,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Qr,randomBytes:Xr,adjustScalarBytes:jo,uvRatio:zo},Je=bn(Go);function Wo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Qe(e,...t){if(!Wo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function tr(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 En(e,t){Qe(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var de=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),X=(e,t)=>e<<32-t|e>>>t;function Zo(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function er(e){return typeof e=="string"&&(e=Zo(e)),Qe(e),e}var pe=class{clone(){return this._cloneInto()}};function _n(e){let t=n=>e().update(er(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function $o(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),f=n?4:0,u=n?0:4;e.setUint32(t+f,s,n),e.setUint32(t+u,c,n)}var In=(e,t,r)=>e&t^~e&r,An=(e,t,r)=>e&t^e&r^t&r,xe=class extends pe{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=de(this.buffer)}update(t){tr(this);let{view:r,buffer:n,blockLen:i}=this;t=er(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let f=de(t);for(;i<=o-s;s+=i)this.process(f,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){tr(this),En(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)r[l]=0;$o(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=de(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=f/4,a=this.get();if(u>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,a[l],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%r&&t.buffer.set(n),t}};var Yo=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]),dt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),xt=new Uint32Array(64),rr=class extends xe{constructor(){super(64,32,8,!1),this.A=dt[0]|0,this.B=dt[1]|0,this.C=dt[2]|0,this.D=dt[3]|0,this.E=dt[4]|0,this.F=dt[5]|0,this.G=dt[6]|0,this.H=dt[7]|0}get(){let{A:t,B:r,C:n,D:i,E:o,F:s,G:c,H:f}=this;return[t,r,n,i,o,s,c,f]}set(t,r,n,i,o,s,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)xt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=xt[l-15],x=xt[l-2],b=X(d,7)^X(d,18)^d>>>3,g=X(x,17)^X(x,19)^x>>>10;xt[l]=g+xt[l-7]+b+xt[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:f,G:u,H:a}=this;for(let l=0;l<64;l++){let d=X(c,6)^X(c,11)^X(c,25),x=a+d+In(c,f,u)+Yo[l]+xt[l]|0,g=(X(n,2)^X(n,13)^X(n,22))+An(n,i,o)|0;a=u,u=f,f=c,c=s+x|0,s=o,o=i,i=n,n=x+g|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,a=a+this.H|0,this.set(n,i,o,s,c,f,u,a)}roundClean(){xt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ye=_n(()=>new rr);var Xo="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",yt=Xo;function Jo(e){if(!e||typeof e!="string")throw new Error(`Expected base58 string but got \u201C${e}\u201D`);if(e.match(/[IOl0]/gmu))throw new Error(`Invalid base58 character \u201C${e.match(/[IOl0]/gmu)}\u201D`);let t=e.match(/^1+/gmu),r=t?t[0].length:0,n=(e.length-r)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(r),...e.match(/.{1}/gmu).map(i=>yt.indexOf(i)).reduce((i,o)=>(i=i.map(s=>{let c=s*58+o;return o=c>>8,c}),i),new Uint8Array(n)).reverse().filter((i=>o=>i=i||o)(!1))])}var st=Jo;var Qo=()=>{let e=Array(256).fill(-1);for(let t=0;t<yt.length;++t)e[yt.charCodeAt(t)]=t;return e},Sn=Qo;var ts=Sn();function es(e){let t=[];for(let r of e){let n=r;for(let i=0;i<t.length;++i){let o=(ts[t[i]]<<8)+n;t[i]=yt.charCodeAt(o%58),n=o/58|0}for(;n;)t.push(yt.charCodeAt(n%58)),n=n/58|0}for(let r of e){if(r)break;t.push(49)}return t.reverse(),String.fromCharCode(...t)}var Ut=es;var nr="__fastnear_";function ir(e){return Buffer.from(e).toString("base64")}function or(e){return Buffer.from(e,"base64")}function ct(e,t){t==null?localStorage.removeItem(nr+e):localStorage.setItem(nr+e,JSON.stringify(t))}function vt(e){let t=localStorage.getItem(nr+e);try{return JSON.parse(t)}catch{return null}}function sr(e){return JSON.parse(JSON.stringify(e))}function cr(...e){try{return JSON.parse(e[0])}catch{return e.length>1?e[1]:value}}var Ft=e=>st(e.includes(":")?(()=>{let[t,r]=e.split(":");if(t!=="ed25519")throw new Error(`Unsupported curve: ${t}`);return r})():e),rs=e=>`ed25519:${Ut(e)}`;function fr(e){e=Ft(e).slice(0,32);let t=Je.getPublicKey(e);return rs(t)}function Un(e,t){t=Ft(t).slice(0,32);let r=Je.sign(st(e),t);return Ut(r)}var qt=["u8","u16","u32","u64","u128","i8","i16","i32","i64","i128","f32","f64"];var vn=function(){function e(){this.offset=0,this.buffer_size=256,this.buffer=new ArrayBuffer(this.buffer_size),this.view=new DataView(this.buffer)}return e.prototype.resize_if_necessary=function(t){if(this.buffer_size-this.offset<t){this.buffer_size=Math.max(this.buffer_size*2,this.buffer_size+t);var r=new ArrayBuffer(this.buffer_size);new Uint8Array(r).set(new Uint8Array(this.buffer)),this.buffer=r,this.view=new DataView(r)}},e.prototype.get_used_buffer=function(){return new Uint8Array(this.buffer).slice(0,this.offset)},e.prototype.store_value=function(t,r){var n=r.substring(1),i=parseInt(n)/8;this.resize_if_necessary(i);var o=r[0]==="f"?"setFloat".concat(n):r[0]==="i"?"setInt".concat(n):"setUint".concat(n);this.view[o](this.offset,t,!0),this.offset+=i},e.prototype.store_bytes=function(t){this.resize_if_necessary(t.length),new Uint8Array(this.buffer).set(new Uint8Array(t),this.offset),this.offset+=t.length},e}();var Fn=function(){function e(t){this.offset=0,this.buffer_size=t.length,this.buffer=new ArrayBuffer(t.length),new Uint8Array(this.buffer).set(t),this.view=new DataView(this.buffer)}return e.prototype.assert_enough_buffer=function(t){if(this.offset+t>this.buffer.byteLength)throw new Error("Error in schema, the buffer is smaller than expected")},e.prototype.consume_value=function(t){var r=t.substring(1),n=parseInt(r)/8;this.assert_enough_buffer(n);var i=t[0]==="f"?"getFloat".concat(r):t[0]==="i"?"getInt".concat(r):"getUint".concat(r),o=this.view[i](this.offset,!0);return this.offset+=n,o},e.prototype.consume_bytes=function(t){this.assert_enough_buffer(t);var r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r},e}();var is=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(n[o]=i[o])},e(t,r)};return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");e(t,r);function n(){this.constructor=t}t.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}();function Cn(e){return Array.isArray(e)||!!e&&typeof e=="object"&&"length"in e&&typeof e.length=="number"&&(e.length===0||e.length>0&&e.length-1 in e)}function Tt(e,t,r){if(typeof e!==t)throw new Error("Expected ".concat(t," not ").concat(typeof e,"(").concat(e,") at ").concat(r.join(".")))}function Rn(e,t){var r=["number","string","bigint","boolean"].includes(typeof e),n=typeof e=="object"&&e!==null&&"toString"in e;if(!r&&!n)throw new Error("Expected bigint, number, boolean or string not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}function ur(e,t,r){if(e!==t)throw new Error("Array length ".concat(e," does not match schema length ").concat(t," at ").concat(r.join(".")))}function Nn(e,t){if(typeof e!="object"||e===null)throw new Error("Expected object not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}var Tn=qt.concat(["bool","string"]),Ln=["option","enum","array","set","map","struct"],jt=function(e){is(t,e);function t(r,n){var i="Invalid schema: ".concat(JSON.stringify(r)," expected ").concat(n);return e.call(this,i)||this}return t}(Error);function ft(e){if(!(typeof e=="string"&&Tn.includes(e))){if(e&&typeof e=="object"){var t=Object.keys(e);if(t.length===1&&Ln.includes(t[0])){var r=t[0];if(r==="option")return ft(e[r]);if(r==="enum")return os(e[r]);if(r==="array")return ss(e[r]);if(r==="set")return ft(e[r]);if(r==="map")return cs(e[r]);if(r==="struct")return fs(e[r])}}throw new jt(e,Ln.join(", ")+" or "+Tn.join(", "))}}function os(e){if(!Array.isArray(e))throw new jt(e,"Array");for(var t=0,r=e;t<r.length;t++){var n=r[t];if(typeof n!="object"||!("struct"in n))throw new Error('Missing "struct" key in enum schema');if(typeof n.struct!="object"||Object.keys(n.struct).length!==1)throw new Error('The "struct" in each enum must have a single key');ft({struct:n.struct})}}function ss(e){if(typeof e!="object")throw new jt(e,"{ type, len? }");if(e.len&&typeof e.len!="number")throw new Error("Invalid schema: ".concat(e));if("type"in e)return ft(e.type);throw new jt(e,"{ type, len? }")}function cs(e){if(typeof e=="object"&&"key"in e&&"value"in e)ft(e.key),ft(e.value);else throw new jt(e,"{ key, value }")}function fs(e){if(typeof e!="object")throw new jt(e,"object");for(var t in e)ft(e[t])}var On=function(){function e(t){this.encoded=new vn,this.fieldPath=["value"],this.checkTypes=t}return e.prototype.encode=function(t,r){return this.encode_value(t,r),this.encoded.get_used_buffer()},e.prototype.encode_value=function(t,r){if(typeof r=="string"){if(qt.includes(r))return this.encode_integer(t,r);if(r==="string")return this.encode_string(t);if(r==="bool")return this.encode_boolean(t)}if(typeof r=="object"){if("option"in r)return this.encode_option(t,r);if("enum"in r)return this.encode_enum(t,r);if("array"in r)return this.encode_array(t,r);if("set"in r)return this.encode_set(t,r);if("map"in r)return this.encode_map(t,r);if("struct"in r)return this.encode_struct(t,r)}},e.prototype.encode_integer=function(t,r){var n=parseInt(r.substring(1));n<=32||r=="f64"?(this.checkTypes&&Tt(t,"number",this.fieldPath),this.encoded.store_value(t,r)):(this.checkTypes&&Rn(t,this.fieldPath),this.encode_bigint(BigInt(t),n))},e.prototype.encode_bigint=function(t,r){for(var n=r/8,i=new Uint8Array(n),o=0;o<n;o++)i[o]=Number(t&BigInt(255)),t=t>>BigInt(8);this.encoded.store_bytes(new Uint8Array(i))},e.prototype.encode_string=function(t){this.checkTypes&&Tt(t,"string",this.fieldPath);for(var r=t,n=[],i=0;i<r.length;i++){var o=r.charCodeAt(i);o<128?n.push(o):o<2048?n.push(192|o>>6,128|o&63):o<55296||o>=57344?n.push(224|o>>12,128|o>>6&63,128|o&63):(i++,o=65536+((o&1023)<<10|r.charCodeAt(i)&1023),n.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63))}this.encoded.store_value(n.length,"u32"),this.encoded.store_bytes(new Uint8Array(n))},e.prototype.encode_boolean=function(t){this.checkTypes&&Tt(t,"boolean",this.fieldPath),this.encoded.store_value(t?1:0,"u8")},e.prototype.encode_option=function(t,r){t==null?this.encoded.store_value(0,"u8"):(this.encoded.store_value(1,"u8"),this.encode_value(t,r.option))},e.prototype.encode_enum=function(t,r){this.checkTypes&&Nn(t,this.fieldPath);for(var n=Object.keys(t)[0],i=0;i<r.enum.length;i++){var o=r.enum[i];if(n===Object.keys(o.struct)[0])return this.encoded.store_value(i,"u8"),this.encode_struct(t,o)}throw new Error("Enum key (".concat(n,") not found in enum schema: ").concat(JSON.stringify(r)," at ").concat(this.fieldPath.join(".")))},e.prototype.encode_array=function(t,r){if(Cn(t))return this.encode_arraylike(t,r);if(t instanceof ArrayBuffer)return this.encode_buffer(t,r);throw new Error("Expected Array-like not ".concat(typeof t,"(").concat(t,") at ").concat(this.fieldPath.join(".")))},e.prototype.encode_arraylike=function(t,r){r.array.len?ur(t.length,r.array.len,this.fieldPath):this.encoded.store_value(t.length,"u32");for(var n=0;n<t.length;n++)this.encode_value(t[n],r.array.type)},e.prototype.encode_buffer=function(t,r){r.array.len?ur(t.byteLength,r.array.len,this.fieldPath):this.encoded.store_value(t.byteLength,"u32"),this.encoded.store_bytes(new Uint8Array(t))},e.prototype.encode_set=function(t,r){this.checkTypes&&Tt(t,"object",this.fieldPath);var n=t instanceof Set,i=n?Array.from(t.values()):Object.values(t);this.encoded.store_value(i.length,"u32");for(var o=0,s=i;o<s.length;o++){var c=s[o];this.encode_value(c,r.set)}},e.prototype.encode_map=function(t,r){this.checkTypes&&Tt(t,"object",this.fieldPath);var n=t instanceof Map,i=n?Array.from(t.keys()):Object.keys(t);this.encoded.store_value(i.length,"u32");for(var o=0,s=i;o<s.length;o++){var c=s[o];this.encode_value(c,r.map.key),this.encode_value(n?t.get(c):t[c],r.map.value)}},e.prototype.encode_struct=function(t,r){this.checkTypes&&Tt(t,"object",this.fieldPath);for(var n=0,i=Object.keys(r.struct);n<i.length;n++){var o=i[n];this.fieldPath.push(o),this.encode_value(t[o],r.struct[o]),this.fieldPath.pop()}},e}();var us=function(){function e(t){this.buffer=new Fn(t)}return e.prototype.decode=function(t){return this.decode_value(t)},e.prototype.decode_value=function(t){if(typeof t=="string"){if(qt.includes(t))return this.decode_integer(t);if(t==="string")return this.decode_string();if(t==="bool")return this.decode_boolean()}if(typeof t=="object"){if("option"in t)return this.decode_option(t);if("enum"in t)return this.decode_enum(t);if("array"in t)return this.decode_array(t);if("set"in t)return this.decode_set(t);if("map"in t)return this.decode_map(t);if("struct"in t)return this.decode_struct(t)}throw new Error("Unsupported type: ".concat(t))},e.prototype.decode_integer=function(t){var r=parseInt(t.substring(1));return r<=32||t=="f64"?this.buffer.consume_value(t):this.decode_bigint(r,t.startsWith("i"))},e.prototype.decode_bigint=function(t,r){r===void 0&&(r=!1);var n=t/8,i=new Uint8Array(this.buffer.consume_bytes(n)),o=i.reduceRight(function(s,c){return s+c.toString(16).padStart(2,"0")},"");return r&&i[n-1]?BigInt.asIntN(t,BigInt("0x".concat(o))):BigInt("0x".concat(o))},e.prototype.decode_string=function(){for(var t=this.decode_integer("u32"),r=new Uint8Array(this.buffer.consume_bytes(t)),n=[],i=0;i<t;++i){var o=r[i];if(o<128)n.push(o);else if(o<224)n.push((o&31)<<6|r[++i]&63);else if(o<240)n.push((o&15)<<12|(r[++i]&63)<<6|r[++i]&63);else{var s=(o&7)<<18|(r[++i]&63)<<12|(r[++i]&63)<<6|r[++i]&63;n.push(s)}}return String.fromCodePoint.apply(String,n)},e.prototype.decode_boolean=function(){return this.buffer.consume_value("u8")>0},e.prototype.decode_option=function(t){var r=this.buffer.consume_value("u8");if(r===1)return this.decode_value(t.option);if(r!==0)throw new Error("Invalid option ".concat(r));return null},e.prototype.decode_enum=function(t){var r,n=this.buffer.consume_value("u8");if(n>t.enum.length)throw new Error("Enum option ".concat(n," is not available"));var i=t.enum[n].struct,o=Object.keys(i)[0];return r={},r[o]=this.decode_value(i[o]),r},e.prototype.decode_array=function(t){for(var r=[],n=t.array.len?t.array.len:this.decode_integer("u32"),i=0;i<n;++i)r.push(this.decode_value(t.array.type));return r},e.prototype.decode_set=function(t){for(var r=this.decode_integer("u32"),n=new Set,i=0;i<r;++i)n.add(this.decode_value(t.set));return n},e.prototype.decode_map=function(t){for(var r=this.decode_integer("u32"),n=new Map,i=0;i<r;++i){var o=this.decode_value(t.map.key),s=this.decode_value(t.map.value);n.set(o,s)}return n},e.prototype.decode_struct=function(t){var r={};for(var n in t.struct)r[n]=this.decode_value(t.struct[n]);return r},e}();function ar(e,t,r){r===void 0&&(r=!0),r&&ft(e);var n=new On(r);return n.encode(t,e)}function kn(e){return{signerId:e.signerId,publicKey:{ed25519Key:{data:Ft(e.publicKey)}},nonce:BigInt(e.nonce),receiverId:e.receiverId,blockHash:st(e.blockHash),actions:e.actions.map(Kn)}}function Mn(e){let t=kn(e);return ar(Hn.Transaction,t)}function Pn(e,t){let r={transaction:kn(e),signature:{ed25519Signature:{data:st(t)}}};return ar(Hn.SignedTransaction,r)}function Kn(e){switch(e.type){case"CreateAccount":return{createAccount:{}};case"DeployContract":return{deployContract:{code:or(e.codeBase64)}};case"FunctionCall":return{functionCall:{methodName:e.methodName,args:e.argsBase64?or(e.argsBase64):Buffer.from(JSON.stringify(e.args)),gas:BigInt(e.gas),deposit:BigInt(e.deposit)}};case"Transfer":return{transfer:{deposit:BigInt(e.deposit)}};case"Stake":return{stake:{stake:BigInt(e.stake),publicKey:{ed25519Key:Ft(e.publicKey)}}};case"AddKey":return{addKey:{publicKey:Ft(e.publicKey),accessKey:{nonce:BigInt(e.accessKey.nonce),permission:e.accessKey.permission==="FullAccess"?{fullAccess:{}}:{functionCall:{allowance:e.accessKey.allowance?BigInt(e.accessKey.allowance):null,receiverId:e.accessKey.receiverId,methodNames:e.accessKey.methodNames}}}}};case"DeleteKey":return{deleteKey:{publicKey:Ft(e.publicKey)}};case"DeleteAccount":return{deleteAccount:{beneficiaryId:e.beneficiaryId}};case"SignedDelegate":return{signedDelegate:{delegateAction:Kn(e.delegateAction),signature:{ed25519Signature:st(e.signature)}}};default:throw new Error("Not implemented action: "+e.type)}}var Hn=new class{Ed25519Signature={struct:{data:{array:{type:"u8",len:64}}}};Secp256k1Signature={struct:{data:{array:{type:"u8",len:65}}}};Signature={enum:[{struct:{ed25519Signature:this.Ed25519Signature}},{struct:{secp256k1Signature:this.Secp256k1Signature}}]};Ed25519Data={struct:{data:{array:{type:"u8",len:32}}}};Secp256k1Data={struct:{data:{array:{type:"u8",len:64}}}};PublicKey={enum:[{struct:{ed25519Key:this.Ed25519Data}},{struct:{secp256k1Key:this.Secp256k1Data}}]};FunctionCallPermission={struct:{allowance:{option:"u128"},receiverId:"string",methodNames:{array:{type:"string"}}}};FullAccessPermission={struct:{}};AccessKeyPermission={enum:[{struct:{functionCall:this.FunctionCallPermission}},{struct:{fullAccess:this.FullAccessPermission}}]};AccessKey={struct:{nonce:"u64",permission:this.AccessKeyPermission}};CreateAccount={struct:{}};DeployContract={struct:{code:{array:{type:"u8"}}}};FunctionCall={struct:{methodName:"string",args:{array:{type:"u8"}},gas:"u64",deposit:"u128"}};Transfer={struct:{deposit:"u128"}};Stake={struct:{stake:"u128",publicKey:this.PublicKey}};AddKey={struct:{publicKey:this.PublicKey,accessKey:this.AccessKey}};DeleteKey={struct:{publicKey:this.PublicKey}};DeleteAccount={struct:{beneficiaryId:"string"}};ClassicAction={enum:[{struct:{createAccount:this.CreateAccount}},{struct:{deployContract:this.DeployContract}},{struct:{functionCall:this.FunctionCall}},{struct:{transfer:this.Transfer}},{struct:{stake:this.Stake}},{struct:{addKey:this.AddKey}},{struct:{deleteKey:this.DeleteKey}},{struct:{deleteAccount:this.DeleteAccount}}]};DelegateAction={struct:{senderId:"string",receiverId:"string",actions:{array:{type:this.ClassicAction}},nonce:"u64",maxBlockHeight:"u64",publicKey:this.PublicKey}};SignedDelegate={struct:{delegateAction:this.DelegateAction,signature:this.Signature}};Action={enum:[{struct:{createAccount:this.CreateAccount}},{struct:{deployContract:this.DeployContract}},{struct:{functionCall:this.FunctionCall}},{struct:{transfer:this.Transfer}},{struct:{stake:this.Stake}},{struct:{addKey:this.AddKey}},{struct:{deleteKey:this.DeleteKey}},{struct:{deleteAccount:this.DeleteAccount}},{struct:{signedDelegate:this.SignedDelegate}}]};Transaction={struct:{signerId:"string",publicKey:this.PublicKey,nonce:"u64",receiverId:"string",blockHash:{array:{type:"u8",len:32}},actions:{array:{type:this.Action}}}};SignedTransaction={struct:{transaction:this.Transaction,signature:this.Signature}}};W.DP=27;var as=1e3*60*60*6,ls="mainnet",hs={testnet:{networkId:"testnet",nodeUrl:"https://rpc.testnet.fastnear.com/"},mainnet:{networkId:"mainnet",nodeUrl:"https://rpc.mainnet.fastnear.com/"}},zt={...hs[ls]},N;{let e=vt("privateKey");N={accountId:vt("accountId"),accessKeyContractId:vt("accessKeyContractId"),lastWalletId:vt("lastWalletId"),privateKey:e,publicKey:e?fr(e):null}}var Vt={},we={account:new Set,tx:new Set};function Xt(e){let t=N;N={...N,...e},ct("accountId",N.accountId),ct("privateKey",N.privateKey),ct("lastWalletId",N.lastWalletId),ct("accessKeyContractId",N.accessKeyContractId),e.hasOwnProperty("privateKey")&&e.privateKey!==t.privateKey&&(N.publicKey=e.privateKey?fr(e.privateKey):null,ct("nonce",null)),e.accountId!==t.accountId&&gs(e.accountId)}function Yt(e){let t=e.txId;Vt[t]={...Vt[t]??{},...e},ws(Vt[t])}function ps(e){console.log("Adapter state update:",e),Xt({privateKey:e.privateKey,accountId:e.accountId,lastWalletId:e.lastWalletId})}var ds=new Gr({onStateUpdate:ps});function xs(e){try{return JSON.parse(Buffer.from(e).toString())}catch{try{return Buffer.from(e)}catch{return e}}}function ge(e,t){return t==="final"||t==="optimistic"?{...e,finality:t}:t?{...e,block_id:t}:{...e,finality:"optimistic"}}async function Lt(e,t){let n=await(await fetch(zt.nodeUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:`fastnear-${Date.now()}`,method:e,params:t})})).json();if(n.error)throw new Error(JSON.stringify(n.error));return n.result}function ys(e,t,r){Lt("send_tx",{signed_tx_base64:e,wait_until:t??"INCLUDED"}).then(n=>{Yt({txId:r,status:"Included"}),Lt("tx",{tx_hash:Vt[r].txHash,sender_account_id:Vt[r].tx.signerId,wait_until:"EXECUTED_OPTIMISTIC"}).then(i=>{Yt({txId:r,status:"Executed",result:i})}).catch(i=>{Yt({txId:r,status:"ErrorAfterIncluded",error:cr(i.message)})})}).catch(n=>{Yt({txId:r,status:"Error",error:cr(n.message)})})}function gs(e){we.account.forEach(t=>{try{t(e)}catch(r){console.error(r)}})}function ws(e){we.tx.forEach(t=>{try{t(sr(e))}catch(r){console.error(r)}})}function qn(e,...t){if(Array.isArray(e)&&(e=e.reduce((r,n,i)=>r+(t[i-1]||"")+n)),typeof e=="string"){let r=e.match(/([0-9.,_]+)\s*([a-zA-Z]+)?/);if(r){let n=r[1].replace(/[_,]/g,""),i=r[2];if(i)switch(i.toLowerCase()){case"near":return W(n).mul(W(10).pow(24)).toFixed(0);case"tgas":return W(n).mul(W(10).pow(12)).toFixed(0);case"ggas":return W(n).mul(W(10).pow(9)).toFixed(0);case"gas":return W(n).toFixed(0);default:throw new Error(`Unknown unit: ${unit}`)}else return W(n).toFixed(0)}}return W(e).toFixed(0)}var lr={get accountId(){return N.accountId},get publicKey(){return N.publicKey},config(e){if(e){if(e.networkId&&zt.networkId!==e.networkId)throw new Error("TODO: Network ID change should handle scope");zt={...zt,...e}}return zt},get authStatus(){if(!N.accountId)return"SignedOut";let e=N.publicKey,t=N.accessKeyContractId;return e?{type:"SignedInWithLimitedAccessKey",accessKey:e,contractId:t}:"SignedIn"},async view({contractId:e,methodName:t,args:r,argsBase64:n,blockId:i}){let o=n||(r?ir(JSON.stringify(r)):""),s=await Lt("query",ge({request_type:"call_function",account_id:e,method_name:t,args_base64:o},i));return xs(s.result)},async account({accountId:e,blockId:t}){return Lt("query",ge({request_type:"view_account",account_id:e},t))},async block({blockId:e}){return Lt("block",ge({},e))},async accessKey({accountId:e,publicKey:t,blockId:r}){return Lt("query",ge({request_type:"view_access_key",account_id:e,public_key:t},r))},async tx({txHash:e,accountId:t}){return Lt("tx",[e,t])},localTxHistory(){return[...Vt]},async sendTx({receiverId:e,actions:t,waitUntil:r}){if(!N.accountId)throw new Error("Not signed in");if(e!==N.accessKeyContractId)throw new Error("Need to use walletAdapter. Not implemented yet");let n=N.accountId,i=N.publicKey,o=N.privateKey,s={},c=vt("nonce");c||(s.nonce=this.accessKey({accountId:n,publicKey:i}).then(v=>(ct("nonce",v.nonce),v.nonce)));let f=vt("block");if((!f||parseFloat(f.header.timestamp_nanosec)/1e6+as<Date.now())&&(s.block=this.block({blockId:"final"}).then(v=>(v={header:{prev_hash:v.header.prev_hash,timestamp_nanosec:v.header.timestamp_nanosec}},ct("block",v),v))),Object.keys(s).length>0){let v=await Promise.all(Object.values(s));for(let y=0;y<v.length;y++)Object.keys(s)[y]==="nonce"?c=v[y]:Object.keys(s)[y]==="block"&&(f=v[y])}let u=c+1;ct("nonce",u);let a=f.header.prev_hash,l=`tx-${Date.now()}-${Math.random()}`,d={signerId:n,publicKey:i,nonce:u,receiverId:e,blockHash:a,actions:t};console.log("Transaction:",d);let x=Mn(d),b=Ut(ye(x)),g=Un(b,o),_=Pn(d,g),D=ir(_);return Yt({status:"Pending",txId:l,tx:sr(d),signature:g,signedTxBase64:D,txHash:b}),ys(D,r,l),l},async requestSignIn({contractId:e}){Xt({accessKeyContractId:e,accountId:null,privateKey:null});let t=await ds.signIn({networkId:zt.networkId,contractId:e});if(console.log("Sign in result:",t),t.error)throw new Error(`Wallet error: ${t.error}`);t.url?(console.log("Redirecting to wallet:",t.url),window.location.href=t.url):t.accountId&&Xt({accountId:t.accountId})},signOut(){Xt({accountId:null,privateKey:null,contractId:null})},onAccount(e){we.account.add(e)},onTx(e){we.tx.add(e)},actions:{functionCall:({methodName:e,gas:t,deposit:r,args:n,argsBase64:i})=>({type:"FunctionCall",methodName:e,args:n,argsBase64:i,gas:t,deposit:r}),transfer:e=>({type:"Transfer",deposit:e}),stakeNEAR:({amount:e,publicKey:t})=>({type:"Stake",stake:e,publicKey:t}),addFullAccessKey:({publicKey:e})=>({type:"AddKey",publicKey:e,accessKey:{permission:"FullAccess"}}),addLimitedAccessKey:({publicKey:e,allowance:t,accountId:r,methodNames:n})=>({type:"AddKey",publicKey:e,accessKey:{permission:"FunctionCall",allowance:t,receiverId:r,methodNames:n}}),deleteKey:({publicKey:e})=>({type:"DeleteKey",publicKey:e}),deleteAccount:({beneficiaryId:e})=>({type:"DeleteAccount",beneficiaryId:e}),createAccount:()=>({type:"CreateAccount"}),deployContract:({codeBase64:e})=>({type:"DeployContract",codeBase64:e})}};try{let e=new URL(window.location.href),t=e.searchParams.get("account_id"),r=e.searchParams.get("public_key"),n=e.searchParams.get("error_code");n&&console.error(new Error(`Wallet error: ${n}`)),t&&r&&(r===N.publicKey?Xt({accountId:t}):console.error(new Error("Public key mismatch from wallet redirect"),r,N.publicKey)),e.searchParams.delete("account_id"),e.searchParams.delete("public_key"),e.searchParams.delete("error_code"),e.searchParams.delete("all_keys"),window.history.replaceState({},"",e.toString())}catch(e){console.error("Error handling wallet redirect:",e)}window.Buffer=jn.Buffer;window.near=lr;window.$$=qn;
2
- /*! Bundled license information:
3
-
4
- ieee754/index.js:
5
- (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
6
-
7
- buffer/index.js:
8
- (*!
9
- * The buffer module from node.js, for the browser.
10
- *
11
- * @author Feross Aboukhadijeh <https://feross.org>
12
- * @license MIT
13
- *)
14
-
15
- @noble/hashes/esm/utils.js:
16
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
17
-
18
- @noble/curves/esm/abstract/utils.js:
19
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
20
-
21
- @noble/curves/esm/abstract/modular.js:
22
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
23
-
24
- @noble/curves/esm/abstract/curve.js:
25
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26
-
27
- @noble/curves/esm/abstract/edwards.js:
28
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
29
-
30
- @noble/curves/esm/ed25519.js:
31
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
32
-
33
- @noble/hashes/esm/utils.js:
34
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
35
- */
package/dist/fastnear.ejs DELETED
@@ -1,24 +0,0 @@
1
- var Jn=20,$n=1,lt=1e6,ze=1e6,Qn=-7,tr=21,er=!1,Dt="[big.js] ",ht=Dt+"Invalid ",Ht=ht+"decimal places",nr=ht+"rounding mode",Ve=Dt+"Division by zero",A={},J=void 0,rr=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Ze(){function t(e){var n=this;if(!(n instanceof t))return e===J?Ze():new t(e);if(e instanceof t)n.s=e.s,n.e=e.e,n.c=e.c.slice();else{if(typeof e!="string"){if(t.strict===!0&&typeof e!="bigint")throw TypeError(ht+"value");e=e===0&&1/e<0?"-0":String(e)}or(n,e)}n.constructor=t}return t.prototype=A,t.DP=Jn,t.RM=$n,t.NE=Qn,t.PE=tr,t.strict=er,t.roundDown=0,t.roundHalfUp=1,t.roundHalfEven=2,t.roundUp=3,t}function or(t,e){var n,r,o;if(!rr.test(e))throw Error(ht+"number");for(t.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1,(n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),o=e.length,r=0;r<o&&e.charAt(r)=="0";)++r;if(r==o)t.c=[t.e=0];else{for(;o>0&&e.charAt(--o)=="0";);for(t.e=n-r-1,t.c=[],n=0;r<=o;)t.c[n++]=+e.charAt(r++)}return t}function dt(t,e,n,r){var o=t.c;if(n===J&&(n=t.constructor.RM),n!==0&&n!==1&&n!==2&&n!==3)throw Error(nr);if(e<1)r=n===3&&(r||!!o[0])||e===0&&(n===1&&o[0]>=5||n===2&&(o[0]>5||o[0]===5&&(r||o[1]!==J))),o.length=1,r?(t.e=t.e-e+1,o[0]=1):o[0]=t.e=0;else if(e<o.length){if(r=n===1&&o[e]>=5||n===2&&(o[e]>5||o[e]===5&&(r||o[e+1]!==J||o[e-1]&1))||n===3&&(r||!!o[0]),o.length=e,r){for(;++o[--e]>9;)if(o[e]=0,e===0){++t.e,o.unshift(1);break}}for(e=o.length;!o[--e];)o.pop()}return t}function pt(t,e,n){var r=t.e,o=t.c.join(""),s=o.length;if(e)o=o.charAt(0)+(s>1?"."+o.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)o="0"+o;o="0."+o}else if(r>0)if(++r>s)for(r-=s;r--;)o+="0";else r<s&&(o=o.slice(0,r)+"."+o.slice(r));else s>1&&(o=o.charAt(0)+"."+o.slice(1));return t.s<0&&n?"-"+o:o}A.abs=function(){var t=new this.constructor(this);return t.s=1,t};A.cmp=function(t){var e,n=this,r=n.c,o=(t=new n.constructor(t)).c,s=n.s,c=t.s,i=n.e,a=t.e;if(!r[0]||!o[0])return r[0]?s:o[0]?-c:0;if(s!=c)return s;if(e=s<0,i!=a)return i>a^e?1:-1;for(c=(i=r.length)<(a=o.length)?i:a,s=-1;++s<c;)if(r[s]!=o[s])return r[s]>o[s]^e?1:-1;return i==a?0:i>a^e?1:-1};A.div=function(t){var e=this,n=e.constructor,r=e.c,o=(t=new n(t)).c,s=e.s==t.s?1:-1,c=n.DP;if(c!==~~c||c<0||c>lt)throw Error(Ht);if(!o[0])throw Error(Ve);if(!r[0])return t.s=s,t.c=[t.e=0],t;var i,a,f,u,l,d=o.slice(),g=i=o.length,w=r.length,x=r.slice(0,i),E=x.length,N=t,S=N.c=[],p=0,k=c+(N.e=e.e-t.e)+1;for(N.s=s,s=k<0?0:k,d.unshift(0);E++<i;)x.push(0);do{for(f=0;f<10;f++){if(i!=(E=x.length))u=i>E?1:-1;else for(l=-1,u=0;++l<i;)if(o[l]!=x[l]){u=o[l]>x[l]?1:-1;break}if(u<0){for(a=E==i?o:d;E;){if(x[--E]<a[E]){for(l=E;l&&!x[--l];)x[l]=9;--x[l],x[E]+=10}x[E]-=a[E]}for(;!x[0];)x.shift()}else break}S[p++]=u?f:++f,x[0]&&u?x[E]=r[g]||0:x=[r[g]]}while((g++<w||x[0]!==J)&&s--);return!S[0]&&p!=1&&(S.shift(),N.e--,k--),p>k&&dt(N,k,n.RM,x[0]!==J),N};A.eq=function(t){return this.cmp(t)===0};A.gt=function(t){return this.cmp(t)>0};A.gte=function(t){return this.cmp(t)>-1};A.lt=function(t){return this.cmp(t)<0};A.lte=function(t){return this.cmp(t)<1};A.minus=A.sub=function(t){var e,n,r,o,s=this,c=s.constructor,i=s.s,a=(t=new c(t)).s;if(i!=a)return t.s=-a,s.plus(t);var f=s.c.slice(),u=s.e,l=t.c,d=t.e;if(!f[0]||!l[0])return l[0]?t.s=-a:f[0]?t=new c(s):t.s=1,t;if(i=u-d){for((o=i<0)?(i=-i,r=f):(d=u,r=l),r.reverse(),a=i;a--;)r.push(0);r.reverse()}else for(n=((o=f.length<l.length)?f:l).length,i=a=0;a<n;a++)if(f[a]!=l[a]){o=f[a]<l[a];break}if(o&&(r=f,f=l,l=r,t.s=-t.s),(a=(n=l.length)-(e=f.length))>0)for(;a--;)f[e++]=0;for(a=e;n>i;){if(f[--n]<l[n]){for(e=n;e&&!f[--e];)f[e]=9;--f[e],f[n]+=10}f[n]-=l[n]}for(;f[--a]===0;)f.pop();for(;f[0]===0;)f.shift(),--d;return f[0]||(t.s=1,f=[d=0]),t.c=f,t.e=d,t};A.mod=function(t){var e,n=this,r=n.constructor,o=n.s,s=(t=new r(t)).s;if(!t.c[0])throw Error(Ve);return n.s=t.s=1,e=t.cmp(n)==1,n.s=o,t.s=s,e?new r(n):(o=r.DP,s=r.RM,r.DP=r.RM=0,n=n.div(t),r.DP=o,r.RM=s,this.minus(n.times(t)))};A.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t};A.plus=A.add=function(t){var e,n,r,o=this,s=o.constructor;if(t=new s(t),o.s!=t.s)return t.s=-t.s,o.minus(t);var c=o.e,i=o.c,a=t.e,f=t.c;if(!i[0]||!f[0])return f[0]||(i[0]?t=new s(o):t.s=o.s),t;if(i=i.slice(),e=c-a){for(e>0?(a=c,r=f):(e=-e,r=i),r.reverse();e--;)r.push(0);r.reverse()}for(i.length-f.length<0&&(r=f,f=i,i=r),e=f.length,n=0;e;i[e]%=10)n=(i[--e]=i[e]+f[e]+n)/10|0;for(n&&(i.unshift(n),++a),e=i.length;i[--e]===0;)i.pop();return t.c=i,t.e=a,t};A.pow=function(t){var e=this,n=new e.constructor("1"),r=n,o=t<0;if(t!==~~t||t<-ze||t>ze)throw Error(ht+"exponent");for(o&&(t=-t);t&1&&(r=r.times(e)),t>>=1,!!t;)e=e.times(e);return o?n.div(r):r};A.prec=function(t,e){if(t!==~~t||t<1||t>lt)throw Error(ht+"precision");return dt(new this.constructor(this),t,e)};A.round=function(t,e){if(t===J)t=0;else if(t!==~~t||t<-lt||t>lt)throw Error(Ht);return dt(new this.constructor(this),t+this.e+1,e)};A.sqrt=function(){var t,e,n,r=this,o=r.constructor,s=r.s,c=r.e,i=new o("0.5");if(!r.c[0])return new o(r);if(s<0)throw Error(Dt+"No square root");s=Math.sqrt(+pt(r,!0,!0)),s===0||s===1/0?(e=r.c.join(""),e.length+c&1||(e+="0"),s=Math.sqrt(e),c=((c+1)/2|0)-(c<0||c&1),t=new o((s==1/0?"5e":(s=s.toExponential()).slice(0,s.indexOf("e")+1))+c)):t=new o(s+""),c=t.e+(o.DP+=4);do n=t,t=i.times(n.plus(r.div(n)));while(n.c.slice(0,c).join("")!==t.c.slice(0,c).join(""));return dt(t,(o.DP-=4)+t.e+1,o.RM)};A.times=A.mul=function(t){var e,n=this,r=n.constructor,o=n.c,s=(t=new r(t)).c,c=o.length,i=s.length,a=n.e,f=t.e;if(t.s=n.s==t.s?1:-1,!o[0]||!s[0])return t.c=[t.e=0],t;for(t.e=a+f,c<i&&(e=o,o=s,s=e,f=c,c=i,i=f),e=new Array(f=c+i);f--;)e[f]=0;for(a=i;a--;){for(i=0,f=c+a;f>a;)i=e[f]+s[a]*o[f-a-1]+i,e[f--]=i%10,i=i/10|0;e[f]=i}for(i?++t.e:e.shift(),a=e.length;!e[--a];)e.pop();return t.c=e,t};A.toExponential=function(t,e){var n=this,r=n.c[0];if(t!==J){if(t!==~~t||t<0||t>lt)throw Error(Ht);for(n=dt(new n.constructor(n),++t,e);n.c.length<t;)n.c.push(0)}return pt(n,!0,!!r)};A.toFixed=function(t,e){var n=this,r=n.c[0];if(t!==J){if(t!==~~t||t<0||t>lt)throw Error(Ht);for(n=dt(new n.constructor(n),t+n.e+1,e),t=t+n.e+1;n.c.length<t;)n.c.push(0)}return pt(n,!1,!!r)};A[Symbol.for("nodejs.util.inspect.custom")]=A.toJSON=A.toString=function(){var t=this,e=t.constructor;return pt(t,t.e<=e.NE||t.e>=e.PE,!!t.c[0])};A.toNumber=function(){var t=+pt(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(t.toString()))throw Error(Dt+"Imprecise conversion");return t};A.toPrecision=function(t,e){var n=this,r=n.constructor,o=n.c[0];if(t!==J){if(t!==~~t||t<1||t>lt)throw Error(ht+"precision");for(n=dt(new r(n),t,e);n.c.length<t;)n.c.push(0)}return pt(n,t<=n.e||n.e<=r.NE||n.e>=r.PE,!!o)};A.valueOf=function(){var t=this,e=t.constructor;if(e.strict===!0)throw Error(Dt+"valueOf disallowed");return pt(t,t.e<=e.NE||t.e>=e.PE,!0)};var sr=Ze(),j=sr;var We=class Ge{#t=null;#n;#o;#r=new Map;#e={};#s;#i;static defaultWidgetUrl="https://wallet-adapter.fastnear.com";constructor({widgetUrl:e=Ge.defaultWidgetUrl,targetOrigin:n="*",onStateUpdate:r,callbackUrl:o=window.location.href}={}){this.#n=n,this.#o=e,this.#s=r,this.#i=o,window.addEventListener("message",this.#c.bind(this))}#f(e){this.#t&&this.#t.remove();let n=new URL(e,this.#o),r=document.createElement("iframe");return r.src=n.toString(),r.allow="usb",r.style.border="none",r.style.zIndex="10000",r.style.position="fixed",r.style.display="block",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",document.body.appendChild(r),this.#t=r,r}#c(e){if(this.#n!=="*"&&e.origin!==this.#n)return;let{id:n,type:r,action:o,payload:s}=e.data;if(r!=="wallet-adapter")return;if(o==="close"){this.#t?.remove(),this.#t=null;return}s?.state&&(this.#e={...this.#e,...s.state},this.#s?.(this.#e));let c=this.#r.get(n);c&&(this.#r.delete(n),this.#t?.remove(),this.#t=null,c(s))}async#a(e,n,r){return new Promise(o=>{let s=Math.random().toString(36).slice(2);this.#r.set(s,o);let c=this.#f(e);c.onload=()=>{c.contentWindow?.postMessage({type:"wallet-adapter",method:n,params:{id:s,...r,state:this.#e,callbackUrl:r.callbackUrl||this.#i}},this.#n)}})}getState(){return{...this.#e}}async signIn(e){return this.#a("/login.html","signIn",e)}async sendTransaction(e){return this.#a("/sign.html","sendTransaction",e)}destroy(){window.removeEventListener("message",this.#c),this.#t?.remove(),this.#t=null}};function ir(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function re(t,...e){if(!ir(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function oe(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ye(t,e){re(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}var gt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Pt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function Xe(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function se(t){return typeof t=="string"&&(t=Xe(t)),re(t),t}var Mt=class{clone(){return this._cloneInto()}};function Je(t){let e=r=>t().update(se(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function $e(t=32){if(gt&&typeof gt.getRandomValues=="function")return gt.getRandomValues(new Uint8Array(t));if(gt&&typeof gt.randomBytes=="function")return gt.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function cr(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),s=BigInt(4294967295),c=Number(n>>o&s),i=Number(n&s),a=r?4:0,f=r?0:4;t.setUint32(e+a,c,r),t.setUint32(e+f,i,r)}var Ft=class extends Mt{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Pt(this.buffer)}update(e){oe(this);let{view:n,buffer:r,blockLen:o}=this;e=se(e);let s=e.length;for(let c=0;c<s;){let i=Math.min(o-this.pos,s-c);if(i===o){let a=Pt(e);for(;o<=s-c;c+=o)this.process(a,c);continue}r.set(e.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){oe(this),Ye(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:s}=this,{pos:c}=this;n[c++]=128,this.buffer.subarray(c).fill(0),this.padOffset>o-c&&(this.process(r,0),c=0);for(let l=c;l<o;l++)n[l]=0;cr(r,o-8,BigInt(this.length*8),s),this.process(r,0);let i=Pt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)i.setUint32(4*l,u[l],s)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:s,destroyed:c,pos:i}=this;return e.length=o,e.pos=i,e.finished=s,e.destroyed=c,o%n&&e.buffer.set(r),e}};var qt=BigInt(4294967295),ie=BigInt(32);function Qe(t,e=!1){return e?{h:Number(t&qt),l:Number(t>>ie&qt)}:{h:Number(t>>ie&qt)|0,l:Number(t&qt)|0}}function ar(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let o=0;o<t.length;o++){let{h:s,l:c}=Qe(t[o],e);[n[o],r[o]]=[s,c]}return[n,r]}var fr=(t,e)=>BigInt(t>>>0)<<ie|BigInt(e>>>0),ur=(t,e,n)=>t>>>n,lr=(t,e,n)=>t<<32-n|e>>>n,hr=(t,e,n)=>t>>>n|e<<32-n,dr=(t,e,n)=>t<<32-n|e>>>n,pr=(t,e,n)=>t<<64-n|e>>>n-32,gr=(t,e,n)=>t>>>n-32|e<<64-n,xr=(t,e)=>e,yr=(t,e)=>t,br=(t,e,n)=>t<<n|e>>>32-n,wr=(t,e,n)=>e<<n|t>>>32-n,mr=(t,e,n)=>e<<n-32|t>>>64-n,_r=(t,e,n)=>t<<n-32|e>>>64-n;function Er(t,e,n,r){let o=(e>>>0)+(r>>>0);return{h:t+n+(o/2**32|0)|0,l:o|0}}var Br=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),vr=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Ar=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Ir=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,Sr=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Lr=(t,e,n,r,o,s)=>e+n+r+o+s+(t/2**32|0)|0;var Tr={fromBig:Qe,split:ar,toBig:fr,shrSH:ur,shrSL:lr,rotrSH:hr,rotrSL:dr,rotrBH:pr,rotrBL:gr,rotr32H:xr,rotr32L:yr,rotlSH:br,rotlSL:wr,rotlBH:mr,rotlBL:_r,add:Er,add3L:Br,add3H:vr,add4L:Ar,add4H:Ir,add5H:Lr,add5L:Sr},_=Tr;var[Ur,Or]=_.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),ot=new Uint32Array(80),st=new Uint32Array(80),ce=class extends Ft{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:n,Bh:r,Bl:o,Ch:s,Cl:c,Dh:i,Dl:a,Eh:f,El:u,Fh:l,Fl:d,Gh:g,Gl:w,Hh:x,Hl:E}=this;return[e,n,r,o,s,c,i,a,f,u,l,d,g,w,x,E]}set(e,n,r,o,s,c,i,a,f,u,l,d,g,w,x,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=s|0,this.Cl=c|0,this.Dh=i|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=g|0,this.Gl=w|0,this.Hh=x|0,this.Hl=E|0}process(e,n){for(let p=0;p<16;p++,n+=4)ot[p]=e.getUint32(n),st[p]=e.getUint32(n+=4);for(let p=16;p<80;p++){let k=ot[p-15]|0,G=st[p-15]|0,nt=_.rotrSH(k,G,1)^_.rotrSH(k,G,8)^_.shrSH(k,G,7),Et=_.rotrSL(k,G,1)^_.rotrSL(k,G,8)^_.shrSL(k,G,7),F=ot[p-2]|0,H=st[p-2]|0,Bt=_.rotrSH(F,H,19)^_.rotrBH(F,H,61)^_.shrSH(F,H,6),ft=_.rotrSL(F,H,19)^_.rotrBL(F,H,61)^_.shrSL(F,H,6),vt=_.add4L(Et,ft,st[p-7],st[p-16]),Ct=_.add4H(vt,nt,Bt,ot[p-7],ot[p-16]);ot[p]=Ct|0,st[p]=vt|0}let{Ah:r,Al:o,Bh:s,Bl:c,Ch:i,Cl:a,Dh:f,Dl:u,Eh:l,El:d,Fh:g,Fl:w,Gh:x,Gl:E,Hh:N,Hl:S}=this;for(let p=0;p<80;p++){let k=_.rotrSH(l,d,14)^_.rotrSH(l,d,18)^_.rotrBH(l,d,41),G=_.rotrSL(l,d,14)^_.rotrSL(l,d,18)^_.rotrBL(l,d,41),nt=l&g^~l&x,Et=d&w^~d&E,F=_.add5L(S,G,Et,Or[p],st[p]),H=_.add5H(F,N,k,nt,Ur[p],ot[p]),Bt=F|0,ft=_.rotrSH(r,o,28)^_.rotrBH(r,o,34)^_.rotrBH(r,o,39),vt=_.rotrSL(r,o,28)^_.rotrBL(r,o,34)^_.rotrBL(r,o,39),Ct=r&s^r&i^s&i,te=o&c^o&a^c&a;N=x|0,S=E|0,x=g|0,E=w|0,g=l|0,w=d|0,{h:l,l:d}=_.add(f|0,u|0,H|0,Bt|0),f=i|0,u=a|0,i=s|0,a=c|0,s=r|0,c=o|0;let ee=_.add3L(Bt,vt,te);r=_.add3H(ee,H,ft,Ct),o=ee|0}({h:r,l:o}=_.add(this.Ah|0,this.Al|0,r|0,o|0)),{h:s,l:c}=_.add(this.Bh|0,this.Bl|0,s|0,c|0),{h:i,l:a}=_.add(this.Ch|0,this.Cl|0,i|0,a|0),{h:f,l:u}=_.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=_.add(this.Eh|0,this.El|0,l|0,d|0),{h:g,l:w}=_.add(this.Fh|0,this.Fl|0,g|0,w|0),{h:x,l:E}=_.add(this.Gh|0,this.Gl|0,x|0,E|0),{h:N,l:S}=_.add(this.Hh|0,this.Hl|0,N|0,S|0),this.set(r,o,s,c,i,a,f,u,l,d,g,w,x,E,N,S)}roundClean(){ot.fill(0),st.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var tn=Je(()=>new ce);var fe=BigInt(0),nn=BigInt(1),Cr=BigInt(2);function ue(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function le(t){if(!ue(t))throw new Error("Uint8Array expected")}function jt(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}var Dr=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function zt(t){le(t);let e="";for(let n=0;n<t.length;n++)e+=Dr[t[n]];return e}function rn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?fe:BigInt("0x"+t)}var $={_0:48,_9:57,A:65,F:70,a:97,f:102};function en(t){if(t>=$._0&&t<=$._9)return t-$._0;if(t>=$.A&&t<=$.F)return t-($.A-10);if(t>=$.a&&t<=$.f)return t-($.a-10)}function on(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){let c=en(t.charCodeAt(s)),i=en(t.charCodeAt(s+1));if(c===void 0||i===void 0){let a=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}r[o]=c*16+i}return r}function sn(t){return rn(zt(t))}function At(t){return le(t),rn(zt(Uint8Array.from(t).reverse()))}function he(t,e){return on(t.toString(16).padStart(e*2,"0"))}function Nt(t,e){return he(t,e).reverse()}function z(t,e,n){let r;if(typeof e=="string")try{r=on(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(ue(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=r.length;if(typeof n=="number"&&o!==n)throw new Error(t+" of length "+n+" expected, got "+o);return r}function de(...t){let e=0;for(let r=0;r<t.length;r++){let o=t[r];le(o),e+=o.length}let n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){let s=t[r];n.set(s,o),o+=s.length}return n}var ae=t=>typeof t=="bigint"&&fe<=t;function Nr(t,e,n){return ae(t)&&ae(e)&&ae(n)&&e<=t&&t<n}function It(t,e,n,r){if(!Nr(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function cn(t){let e;for(e=0;t>fe;t>>=nn,e+=1);return e}var an=t=>(Cr<<BigInt(t-1))-nn;var kr={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||ue(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function St(t,e,n={}){let r=(o,s,c)=>{let i=kr[s];if(typeof i!="function")throw new Error("invalid validator function");let a=t[o];if(!(c&&a===void 0)&&!i(a,t))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(e))r(o,s,!1);for(let[o,s]of Object.entries(n))r(o,s,!0);return t}function pe(t){let e=new WeakMap;return(n,...r)=>{let o=e.get(n);if(o!==void 0)return o;let s=t(n,...r);return e.set(n,s),s}}var K=BigInt(0),O=BigInt(1),xt=BigInt(2),Rr=BigInt(3),ge=BigInt(4),fn=BigInt(5),un=BigInt(8),Hr=BigInt(9),Mr=BigInt(16);function C(t,e){let n=t%e;return n>=K?n:e+n}function Pr(t,e,n){if(e<K)throw new Error("invalid exponent, negatives unsupported");if(n<=K)throw new Error("invalid modulus");if(n===O)return K;let r=O;for(;e>K;)e&O&&(r=r*t%n),t=t*t%n,e>>=O;return r}function V(t,e,n){let r=t;for(;e-- >K;)r*=r,r%=n;return r}function ln(t,e){if(t===K)throw new Error("invert: expected non-zero number");if(e<=K)throw new Error("invert: expected positive modulus, got "+e);let n=C(t,e),r=e,o=K,s=O,c=O,i=K;for(;n!==K;){let f=r/n,u=r%n,l=o-c*f,d=s-i*f;r=n,n=u,o=c,s=i,c=l,i=d}if(r!==O)throw new Error("invert: does not exist");return C(o,e)}function Fr(t){let e=(t-O)/xt,n,r,o;for(n=t-O,r=0;n%xt===K;n/=xt,r++);for(o=xt;o<t&&Pr(o,e,t)!==t-O;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){let c=(t+O)/ge;return function(a,f){let u=a.pow(f,c);if(!a.eql(a.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(n+O)/xt;return function(i,a){if(i.pow(a,e)===i.neg(i.ONE))throw new Error("Cannot find square root");let f=r,u=i.pow(i.mul(i.ONE,o),n),l=i.pow(a,s),d=i.pow(a,n);for(;!i.eql(d,i.ONE);){if(i.eql(d,i.ZERO))return i.ZERO;let g=1;for(let x=i.sqr(d);g<f&&!i.eql(x,i.ONE);g++)x=i.sqr(x);let w=i.pow(u,O<<BigInt(f-g-1));u=i.sqr(w),l=i.mul(l,w),d=i.mul(d,u),f=g}return l}}function qr(t){if(t%ge===Rr){let e=(t+O)/ge;return function(r,o){let s=r.pow(o,e);if(!r.eql(r.sqr(s),o))throw new Error("Cannot find square root");return s}}if(t%un===fn){let e=(t-fn)/un;return function(r,o){let s=r.mul(o,xt),c=r.pow(s,e),i=r.mul(o,c),a=r.mul(r.mul(i,xt),c),f=r.mul(i,r.sub(a,r.ONE));if(!r.eql(r.sqr(f),o))throw new Error("Cannot find square root");return f}}return t%Mr,Fr(t)}var hn=(t,e)=>(C(t,e)&O)===O,jr=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function dn(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=jr.reduce((r,o)=>(r[o]="function",r),e);return St(t,n)}function zr(t,e,n){if(n<K)throw new Error("invalid exponent, negatives unsupported");if(n===K)return t.ONE;if(n===O)return e;let r=t.ONE,o=e;for(;n>K;)n&O&&(r=t.mul(r,o)),o=t.sqr(o),n>>=O;return r}function Vr(t,e){let n=new Array(e.length),r=e.reduce((s,c,i)=>t.is0(c)?s:(n[i]=s,t.mul(s,c)),t.ONE),o=t.inv(r);return e.reduceRight((s,c,i)=>t.is0(c)?s:(n[i]=t.mul(s,n[i]),t.mul(s,c)),o),n}function xe(t,e){let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Vt(t,e,n=!1,r={}){if(t<=K)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:o,nByteLength:s}=xe(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,i=Object.freeze({ORDER:t,BITS:o,BYTES:s,MASK:an(o),ZERO:K,ONE:O,create:a=>C(a,t),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return K<=a&&a<t},is0:a=>a===K,isOdd:a=>(a&O)===O,neg:a=>C(-a,t),eql:(a,f)=>a===f,sqr:a=>C(a*a,t),add:(a,f)=>C(a+f,t),sub:(a,f)=>C(a-f,t),mul:(a,f)=>C(a*f,t),pow:(a,f)=>zr(i,a,f),div:(a,f)=>C(a*ln(f,t),t),sqrN:a=>a*a,addN:(a,f)=>a+f,subN:(a,f)=>a-f,mulN:(a,f)=>a*f,inv:a=>ln(a,t),sqrt:r.sqrt||(a=>(c||(c=qr(t)),c(i,a))),invertBatch:a=>Vr(i,a),cmov:(a,f,u)=>u?f:a,toBytes:a=>n?Nt(a,s):he(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return n?At(a):sn(a)}});return Object.freeze(i)}var pn=BigInt(0),Zt=BigInt(1);function ye(t,e){let n=e.negate();return t?n:e}function gn(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function be(t,e){gn(t,e);let n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function Zr(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function Wr(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}var we=new WeakMap,xn=new WeakMap;function me(t){return xn.get(t)||1}function yn(t,e){return{constTimeNegate:ye,hasPrecomputes(n){return me(n)!==1},unsafeLadder(n,r,o=t.ZERO){let s=n;for(;r>pn;)r&Zt&&(o=o.add(s)),s=s.double(),r>>=Zt;return o},precomputeWindow(n,r){let{windows:o,windowSize:s}=be(r,e),c=[],i=n,a=i;for(let f=0;f<o;f++){a=i,c.push(a);for(let u=1;u<s;u++)a=a.add(i),c.push(a);i=a.double()}return c},wNAF(n,r,o){let{windows:s,windowSize:c}=be(n,e),i=t.ZERO,a=t.BASE,f=BigInt(2**n-1),u=2**n,l=BigInt(n);for(let d=0;d<s;d++){let g=d*c,w=Number(o&f);o>>=l,w>c&&(w-=u,o+=Zt);let x=g,E=g+Math.abs(w)-1,N=d%2!==0,S=w<0;w===0?a=a.add(ye(N,r[x])):i=i.add(ye(S,r[E]))}return{p:i,f:a}},wNAFUnsafe(n,r,o,s=t.ZERO){let{windows:c,windowSize:i}=be(n,e),a=BigInt(2**n-1),f=2**n,u=BigInt(n);for(let l=0;l<c;l++){let d=l*i;if(o===pn)break;let g=Number(o&a);if(o>>=u,g>i&&(g-=f,o+=Zt),g===0)continue;let w=r[d+Math.abs(g)-1];g<0&&(w=w.negate()),s=s.add(w)}return s},getPrecomputes(n,r,o){let s=we.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&we.set(r,o(s))),s},wNAFCached(n,r,o){let s=me(n);return this.wNAF(s,this.getPrecomputes(s,n,o),r)},wNAFCachedUnsafe(n,r,o,s){let c=me(n);return c===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(c,this.getPrecomputes(c,n,o),r,s)},setWindowSize(n,r){gn(r,e),xn.set(n,r),we.delete(n)}}}function bn(t,e,n,r){if(Zr(n,t),Wr(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,s=cn(BigInt(n.length)),c=s>12?s-3:s>4?s-2:s?2:1,i=(1<<c)-1,a=new Array(i+1).fill(o),f=Math.floor((e.BITS-1)/c)*c,u=o;for(let l=f;l>=0;l-=c){a.fill(o);for(let g=0;g<r.length;g++){let w=r[g],x=Number(w>>BigInt(l)&BigInt(i));a[x]=a[x].add(n[g])}let d=o;for(let g=a.length-1,w=o;g>0;g--)w=w.add(a[g]),d=d.add(w);if(u=u.add(d),l!==0)for(let g=0;g<c;g++)u=u.double()}return u}function wn(t){return dn(t.Fp),St(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...xe(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var Z=BigInt(0),P=BigInt(1),Wt=BigInt(2),Gr=BigInt(8),Yr={zip215:!0};function Xr(t){let e=wn(t);return St(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function mn(t){let e=Xr(t),{Fp:n,n:r,prehash:o,hash:s,randomBytes:c,nByteLength:i,h:a}=e,f=Wt<<BigInt(i*8)-P,u=n.create,l=Vt(e.n,e.nBitLength),d=e.uvRatio||((m,h)=>{try{return{isValid:!0,value:n.sqrt(m*n.inv(h))}}catch{return{isValid:!1,value:Z}}}),g=e.adjustScalarBytes||(m=>m),w=e.domain||((m,h,y)=>{if(jt("phflag",y),h.length||y)throw new Error("Contexts/pre-hash are not supported");return m});function x(m,h){It("coordinate "+m,h,Z,f)}function E(m){if(!(m instanceof p))throw new Error("ExtendedPoint expected")}let N=pe((m,h)=>{let{ex:y,ey:b,ez:B}=m,v=m.is0();h==null&&(h=v?Gr:n.inv(B));let I=u(y*h),T=u(b*h),L=u(B*h);if(v)return{x:Z,y:P};if(L!==P)throw new Error("invZ was invalid");return{x:I,y:T}}),S=pe(m=>{let{a:h,d:y}=e;if(m.is0())throw new Error("bad point: ZERO");let{ex:b,ey:B,ez:v,et:I}=m,T=u(b*b),L=u(B*B),U=u(v*v),R=u(U*U),M=u(T*h),Y=u(U*u(M+L)),X=u(R+u(y*u(T*L)));if(Y!==X)throw new Error("bad point: equation left != right (1)");let q=u(b*B),rt=u(v*I);if(q!==rt)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(h,y,b,B){this.ex=h,this.ey=y,this.ez=b,this.et=B,x("x",h),x("y",y),x("z",b),x("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:y,y:b}=h||{};return x("x",y),x("y",b),new p(y,b,P,u(y*b))}static normalizeZ(h){let y=n.invertBatch(h.map(b=>b.ez));return h.map((b,B)=>b.toAffine(y[B])).map(p.fromAffine)}static msm(h,y){return bn(p,l,h,y)}_setWindowSize(h){nt.setWindowSize(this,h)}assertValidity(){S(this)}equals(h){E(h);let{ex:y,ey:b,ez:B}=this,{ex:v,ey:I,ez:T}=h,L=u(y*T),U=u(v*B),R=u(b*T),M=u(I*B);return L===U&&R===M}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:h}=e,{ex:y,ey:b,ez:B}=this,v=u(y*y),I=u(b*b),T=u(Wt*u(B*B)),L=u(h*v),U=y+b,R=u(u(U*U)-v-I),M=L+I,Y=M-T,X=L-I,q=u(R*Y),rt=u(M*X),ut=u(R*X),Rt=u(Y*M);return new p(q,rt,Rt,ut)}add(h){E(h);let{a:y,d:b}=e,{ex:B,ey:v,ez:I,et:T}=this,{ex:L,ey:U,ez:R,et:M}=h;if(y===BigInt(-1)){let Re=u((v-B)*(U+L)),He=u((v+B)*(U-L)),ne=u(He-Re);if(ne===Z)return this.double();let Me=u(I*Wt*M),Pe=u(T*Wt*R),Fe=Pe+Me,qe=He+Re,je=Pe-Me,Wn=u(Fe*ne),Gn=u(qe*je),Yn=u(Fe*je),Xn=u(ne*qe);return new p(Wn,Gn,Xn,Yn)}let Y=u(B*L),X=u(v*U),q=u(T*b*M),rt=u(I*R),ut=u((B+v)*(L+U)-Y-X),Rt=rt-q,ke=rt+q,Ke=u(X-y*Y),jn=u(ut*Rt),zn=u(ke*Ke),Vn=u(ut*Ke),Zn=u(Rt*ke);return new p(jn,zn,Zn,Vn)}subtract(h){return this.add(h.negate())}wNAF(h){return nt.wNAFCached(this,h,p.normalizeZ)}multiply(h){let y=h;It("scalar",y,P,r);let{p:b,f:B}=this.wNAF(y);return p.normalizeZ([b,B])[0]}multiplyUnsafe(h,y=p.ZERO){let b=h;return It("scalar",b,Z,r),b===Z?G:this.is0()||b===P?this:nt.wNAFCachedUnsafe(this,b,p.normalizeZ,y)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return nt.unsafeLadder(this,r).is0()}toAffine(h){return N(this,h)}clearCofactor(){let{h}=e;return h===P?this:this.multiplyUnsafe(h)}static fromHex(h,y=!1){let{d:b,a:B}=e,v=n.BYTES;h=z("pointHex",h,v),jt("zip215",y);let I=h.slice(),T=h[v-1];I[v-1]=T&-129;let L=At(I),U=y?f:n.ORDER;It("pointHex.y",L,Z,U);let R=u(L*L),M=u(R-P),Y=u(b*R-B),{isValid:X,value:q}=d(M,Y);if(!X)throw new Error("Point.fromHex: invalid y coordinate");let rt=(q&P)===P,ut=(T&128)!==0;if(!y&&q===Z&&ut)throw new Error("Point.fromHex: x=0 and x_0=1");return ut!==rt&&(q=u(-q)),p.fromAffine({x:q,y:L})}static fromPrivateKey(h){return H(h).point}toRawBytes(){let{x:h,y}=this.toAffine(),b=Nt(y,n.BYTES);return b[b.length-1]|=h&P?128:0,b}toHex(){return zt(this.toRawBytes())}}p.BASE=new p(e.Gx,e.Gy,P,u(e.Gx*e.Gy)),p.ZERO=new p(Z,P,P,Z);let{BASE:k,ZERO:G}=p,nt=yn(p,i*8);function Et(m){return C(m,r)}function F(m){return Et(At(m))}function H(m){let h=n.BYTES;m=z("private key",m,h);let y=z("hashed private key",s(m),2*h),b=g(y.slice(0,h)),B=y.slice(h,2*h),v=F(b),I=k.multiply(v),T=I.toRawBytes();return{head:b,prefix:B,scalar:v,point:I,pointBytes:T}}function Bt(m){return H(m).pointBytes}function ft(m=new Uint8Array,...h){let y=de(...h);return F(s(w(y,z("context",m),!!o)))}function vt(m,h,y={}){m=z("message",m),o&&(m=o(m));let{prefix:b,scalar:B,pointBytes:v}=H(h),I=ft(y.context,b,m),T=k.multiply(I).toRawBytes(),L=ft(y.context,T,v,m),U=Et(I+L*B);It("signature.s",U,Z,r);let R=de(T,Nt(U,n.BYTES));return z("result",R,n.BYTES*2)}let Ct=Yr;function te(m,h,y,b=Ct){let{context:B,zip215:v}=b,I=n.BYTES;m=z("signature",m,2*I),h=z("message",h),y=z("publicKey",y,I),v!==void 0&&jt("zip215",v),o&&(h=o(h));let T=At(m.slice(I,2*I)),L,U,R;try{L=p.fromHex(y,v),U=p.fromHex(m.slice(0,I),v),R=k.multiplyUnsafe(T)}catch{return!1}if(!v&&L.isSmallOrder())return!1;let M=ft(B,U.toRawBytes(),L.toRawBytes(),h);return U.add(L.multiplyUnsafe(M)).subtract(R).clearCofactor().equals(p.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:Bt,sign:vt,verify:te,ExtendedPoint:p,utils:{getExtendedPublicKey:H,randomPrivateKey:()=>c(n.BYTES),precompute(m=8,h=p.BASE){return h._setWindowSize(m),h.multiply(BigInt(3)),h}}}}var _e=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),_n=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),us=BigInt(0),Jr=BigInt(1),En=BigInt(2),ls=BigInt(3),$r=BigInt(5),Qr=BigInt(8);function to(t){let e=BigInt(10),n=BigInt(20),r=BigInt(40),o=BigInt(80),s=_e,i=t*t%s*t%s,a=V(i,En,s)*i%s,f=V(a,Jr,s)*t%s,u=V(f,$r,s)*f%s,l=V(u,e,s)*u%s,d=V(l,n,s)*l%s,g=V(d,r,s)*d%s,w=V(g,o,s)*g%s,x=V(w,o,s)*g%s,E=V(x,e,s)*u%s;return{pow_p_5_8:V(E,En,s)*t%s,b2:i}}function eo(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function no(t,e){let n=_e,r=C(e*e*e,n),o=C(r*r*e,n),s=to(t*o).pow_p_5_8,c=C(t*r*s,n),i=C(e*c*c,n),a=c,f=C(c*_n,n),u=i===t,l=i===C(-t,n),d=i===C(-t*_n,n);return u&&(c=a),(l||d)&&(c=f),hn(c,n)&&(c=C(-c,n)),{isValid:u||l,value:c}}var ro=Vt(_e,void 0,!0),oo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ro,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Qr,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:tn,randomBytes:$e,adjustScalarBytes:eo,uvRatio:no},Ee=mn(oo);function so(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Be(t,...e){if(!so(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function ve(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Bn(t,e){Be(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}var Yt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),W=(t,e)=>t<<32-e|t>>>e;function io(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Ae(t){return typeof t=="string"&&(t=io(t)),Be(t),t}var Gt=class{clone(){return this._cloneInto()}};function vn(t){let e=r=>t().update(Ae(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function co(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),s=BigInt(4294967295),c=Number(n>>o&s),i=Number(n&s),a=r?4:0,f=r?0:4;t.setUint32(e+a,c,r),t.setUint32(e+f,i,r)}var An=(t,e,n)=>t&e^~t&n,In=(t,e,n)=>t&e^t&n^e&n,Xt=class extends Gt{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Yt(this.buffer)}update(e){ve(this);let{view:n,buffer:r,blockLen:o}=this;e=Ae(e);let s=e.length;for(let c=0;c<s;){let i=Math.min(o-this.pos,s-c);if(i===o){let a=Yt(e);for(;o<=s-c;c+=o)this.process(a,c);continue}r.set(e.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ve(this),Bn(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:s}=this,{pos:c}=this;n[c++]=128,this.buffer.subarray(c).fill(0),this.padOffset>o-c&&(this.process(r,0),c=0);for(let l=c;l<o;l++)n[l]=0;co(r,o-8,BigInt(this.length*8),s),this.process(r,0);let i=Yt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)i.setUint32(4*l,u[l],s)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:s,destroyed:c,pos:i}=this;return e.length=o,e.pos=i,e.finished=s,e.destroyed=c,o%n&&e.buffer.set(r),e}};var ao=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]),it=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ct=new Uint32Array(64),Ie=class extends Xt{constructor(){super(64,32,8,!1),this.A=it[0]|0,this.B=it[1]|0,this.C=it[2]|0,this.D=it[3]|0,this.E=it[4]|0,this.F=it[5]|0,this.G=it[6]|0,this.H=it[7]|0}get(){let{A:e,B:n,C:r,D:o,E:s,F:c,G:i,H:a}=this;return[e,n,r,o,s,c,i,a]}set(e,n,r,o,s,c,i,a){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=c|0,this.G=i|0,this.H=a|0}process(e,n){for(let l=0;l<16;l++,n+=4)ct[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){let d=ct[l-15],g=ct[l-2],w=W(d,7)^W(d,18)^d>>>3,x=W(g,17)^W(g,19)^g>>>10;ct[l]=x+ct[l-7]+w+ct[l-16]|0}let{A:r,B:o,C:s,D:c,E:i,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let d=W(i,6)^W(i,11)^W(i,25),g=u+d+An(i,a,f)+ao[l]+ct[l]|0,x=(W(r,2)^W(r,13)^W(r,22))+In(r,o,s)|0;u=f,f=a,a=i,i=c+g|0,c=s,s=o,o=r,r=g+x|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,c=c+this.D|0,i=i+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(r,o,s,c,i,a,f,u)}roundClean(){ct.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Jt=vn(()=>new Ie);var fo="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",at=fo;function uo(t){if(!t||typeof t!="string")throw new Error(`Expected base58 string but got \u201C${t}\u201D`);if(t.match(/[IOl0]/gmu))throw new Error(`Invalid base58 character \u201C${t.match(/[IOl0]/gmu)}\u201D`);let e=t.match(/^1+/gmu),n=e?e[0].length:0,r=(t.length-n)*(Math.log(58)/Math.log(256))+1>>>0;return new Uint8Array([...new Uint8Array(n),...t.match(/.{1}/gmu).map(o=>at.indexOf(o)).reduce((o,s)=>(o=o.map(c=>{let i=c*58+s;return s=i>>8,i}),o),new Uint8Array(r)).reverse().filter((o=>s=>o=o||s)(!1))])}var Q=uo;var lo=()=>{let t=Array(256).fill(-1);for(let e=0;e<at.length;++e)t[at.charCodeAt(e)]=e;return t},Sn=lo;var ho=Sn();function po(t){let e=[];for(let n of t){let r=n;for(let o=0;o<e.length;++o){let s=(ho[e[o]]<<8)+r;e[o]=at.charCodeAt(s%58),r=s/58|0}for(;r;)e.push(at.charCodeAt(r%58)),r=r/58|0}for(let n of t){if(n)break;e.push(49)}return e.reverse(),String.fromCharCode(...e)}var yt=po;var Se="__fastnear_";function Le(t){return Buffer.from(t).toString("base64")}function Te(t){return Buffer.from(t,"base64")}function tt(t,e){e==null?localStorage.removeItem(Se+t):localStorage.setItem(Se+t,JSON.stringify(e))}function bt(t){let e=localStorage.getItem(Se+t);try{return JSON.parse(e)}catch{return null}}function Ue(t){return JSON.parse(JSON.stringify(t))}function Oe(...t){try{return JSON.parse(t[0])}catch{return t.length>1?t[1]:value}}var wt=t=>Q(t.includes(":")?(()=>{let[e,n]=t.split(":");if(e!=="ed25519")throw new Error(`Unsupported curve: ${e}`);return n})():t),go=t=>`ed25519:${yt(t)}`;function Ce(t){t=wt(t).slice(0,32);let e=Ee.getPublicKey(t);return go(e)}function Ln(t,e){e=wt(e).slice(0,32);let n=Ee.sign(Q(t),e);return yt(n)}var Lt=["u8","u16","u32","u64","u128","i8","i16","i32","i64","i128","f32","f64"];var Tn=function(){function t(){this.offset=0,this.buffer_size=256,this.buffer=new ArrayBuffer(this.buffer_size),this.view=new DataView(this.buffer)}return t.prototype.resize_if_necessary=function(e){if(this.buffer_size-this.offset<e){this.buffer_size=Math.max(this.buffer_size*2,this.buffer_size+e);var n=new ArrayBuffer(this.buffer_size);new Uint8Array(n).set(new Uint8Array(this.buffer)),this.buffer=n,this.view=new DataView(n)}},t.prototype.get_used_buffer=function(){return new Uint8Array(this.buffer).slice(0,this.offset)},t.prototype.store_value=function(e,n){var r=n.substring(1),o=parseInt(r)/8;this.resize_if_necessary(o);var s=n[0]==="f"?"setFloat".concat(r):n[0]==="i"?"setInt".concat(r):"setUint".concat(r);this.view[s](this.offset,e,!0),this.offset+=o},t.prototype.store_bytes=function(e){this.resize_if_necessary(e.length),new Uint8Array(this.buffer).set(new Uint8Array(e),this.offset),this.offset+=e.length},t}();var Un=function(){function t(e){this.offset=0,this.buffer_size=e.length,this.buffer=new ArrayBuffer(e.length),new Uint8Array(this.buffer).set(e),this.view=new DataView(this.buffer)}return t.prototype.assert_enough_buffer=function(e){if(this.offset+e>this.buffer.byteLength)throw new Error("Error in schema, the buffer is smaller than expected")},t.prototype.consume_value=function(e){var n=e.substring(1),r=parseInt(n)/8;this.assert_enough_buffer(r);var o=e[0]==="f"?"getFloat".concat(n):e[0]==="i"?"getInt".concat(n):"getUint".concat(n),s=this.view[o](this.offset,!0);return this.offset+=r,s},t.prototype.consume_bytes=function(e){this.assert_enough_buffer(e);var n=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,n},t}();var yo=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(r[s]=o[s])},t(e,n)};return function(e,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}();function Dn(t){return Array.isArray(t)||!!t&&typeof t=="object"&&"length"in t&&typeof t.length=="number"&&(t.length===0||t.length>0&&t.length-1 in t)}function mt(t,e,n){if(typeof t!==e)throw new Error("Expected ".concat(e," not ").concat(typeof t,"(").concat(t,") at ").concat(n.join(".")))}function Nn(t,e){var n=["number","string","bigint","boolean"].includes(typeof t),r=typeof t=="object"&&t!==null&&"toString"in t;if(!n&&!r)throw new Error("Expected bigint, number, boolean or string not ".concat(typeof t,"(").concat(t,") at ").concat(e.join(".")))}function De(t,e,n){if(t!==e)throw new Error("Array length ".concat(t," does not match schema length ").concat(e," at ").concat(n.join(".")))}function kn(t,e){if(typeof t!="object"||t===null)throw new Error("Expected object not ".concat(typeof t,"(").concat(t,") at ").concat(e.join(".")))}var On=Lt.concat(["bool","string"]),Cn=["option","enum","array","set","map","struct"],Tt=function(t){yo(e,t);function e(n,r){var o="Invalid schema: ".concat(JSON.stringify(n)," expected ").concat(r);return t.call(this,o)||this}return e}(Error);function et(t){if(!(typeof t=="string"&&On.includes(t))){if(t&&typeof t=="object"){var e=Object.keys(t);if(e.length===1&&Cn.includes(e[0])){var n=e[0];if(n==="option")return et(t[n]);if(n==="enum")return bo(t[n]);if(n==="array")return wo(t[n]);if(n==="set")return et(t[n]);if(n==="map")return mo(t[n]);if(n==="struct")return _o(t[n])}}throw new Tt(t,Cn.join(", ")+" or "+On.join(", "))}}function bo(t){if(!Array.isArray(t))throw new Tt(t,"Array");for(var e=0,n=t;e<n.length;e++){var r=n[e];if(typeof r!="object"||!("struct"in r))throw new Error('Missing "struct" key in enum schema');if(typeof r.struct!="object"||Object.keys(r.struct).length!==1)throw new Error('The "struct" in each enum must have a single key');et({struct:r.struct})}}function wo(t){if(typeof t!="object")throw new Tt(t,"{ type, len? }");if(t.len&&typeof t.len!="number")throw new Error("Invalid schema: ".concat(t));if("type"in t)return et(t.type);throw new Tt(t,"{ type, len? }")}function mo(t){if(typeof t=="object"&&"key"in t&&"value"in t)et(t.key),et(t.value);else throw new Tt(t,"{ key, value }")}function _o(t){if(typeof t!="object")throw new Tt(t,"object");for(var e in t)et(t[e])}var Rn=function(){function t(e){this.encoded=new Tn,this.fieldPath=["value"],this.checkTypes=e}return t.prototype.encode=function(e,n){return this.encode_value(e,n),this.encoded.get_used_buffer()},t.prototype.encode_value=function(e,n){if(typeof n=="string"){if(Lt.includes(n))return this.encode_integer(e,n);if(n==="string")return this.encode_string(e);if(n==="bool")return this.encode_boolean(e)}if(typeof n=="object"){if("option"in n)return this.encode_option(e,n);if("enum"in n)return this.encode_enum(e,n);if("array"in n)return this.encode_array(e,n);if("set"in n)return this.encode_set(e,n);if("map"in n)return this.encode_map(e,n);if("struct"in n)return this.encode_struct(e,n)}},t.prototype.encode_integer=function(e,n){var r=parseInt(n.substring(1));r<=32||n=="f64"?(this.checkTypes&&mt(e,"number",this.fieldPath),this.encoded.store_value(e,n)):(this.checkTypes&&Nn(e,this.fieldPath),this.encode_bigint(BigInt(e),r))},t.prototype.encode_bigint=function(e,n){for(var r=n/8,o=new Uint8Array(r),s=0;s<r;s++)o[s]=Number(e&BigInt(255)),e=e>>BigInt(8);this.encoded.store_bytes(new Uint8Array(o))},t.prototype.encode_string=function(e){this.checkTypes&&mt(e,"string",this.fieldPath);for(var n=e,r=[],o=0;o<n.length;o++){var s=n.charCodeAt(o);s<128?r.push(s):s<2048?r.push(192|s>>6,128|s&63):s<55296||s>=57344?r.push(224|s>>12,128|s>>6&63,128|s&63):(o++,s=65536+((s&1023)<<10|n.charCodeAt(o)&1023),r.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|s&63))}this.encoded.store_value(r.length,"u32"),this.encoded.store_bytes(new Uint8Array(r))},t.prototype.encode_boolean=function(e){this.checkTypes&&mt(e,"boolean",this.fieldPath),this.encoded.store_value(e?1:0,"u8")},t.prototype.encode_option=function(e,n){e==null?this.encoded.store_value(0,"u8"):(this.encoded.store_value(1,"u8"),this.encode_value(e,n.option))},t.prototype.encode_enum=function(e,n){this.checkTypes&&kn(e,this.fieldPath);for(var r=Object.keys(e)[0],o=0;o<n.enum.length;o++){var s=n.enum[o];if(r===Object.keys(s.struct)[0])return this.encoded.store_value(o,"u8"),this.encode_struct(e,s)}throw new Error("Enum key (".concat(r,") not found in enum schema: ").concat(JSON.stringify(n)," at ").concat(this.fieldPath.join(".")))},t.prototype.encode_array=function(e,n){if(Dn(e))return this.encode_arraylike(e,n);if(e instanceof ArrayBuffer)return this.encode_buffer(e,n);throw new Error("Expected Array-like not ".concat(typeof e,"(").concat(e,") at ").concat(this.fieldPath.join(".")))},t.prototype.encode_arraylike=function(e,n){n.array.len?De(e.length,n.array.len,this.fieldPath):this.encoded.store_value(e.length,"u32");for(var r=0;r<e.length;r++)this.encode_value(e[r],n.array.type)},t.prototype.encode_buffer=function(e,n){n.array.len?De(e.byteLength,n.array.len,this.fieldPath):this.encoded.store_value(e.byteLength,"u32"),this.encoded.store_bytes(new Uint8Array(e))},t.prototype.encode_set=function(e,n){this.checkTypes&&mt(e,"object",this.fieldPath);var r=e instanceof Set,o=r?Array.from(e.values()):Object.values(e);this.encoded.store_value(o.length,"u32");for(var s=0,c=o;s<c.length;s++){var i=c[s];this.encode_value(i,n.set)}},t.prototype.encode_map=function(e,n){this.checkTypes&&mt(e,"object",this.fieldPath);var r=e instanceof Map,o=r?Array.from(e.keys()):Object.keys(e);this.encoded.store_value(o.length,"u32");for(var s=0,c=o;s<c.length;s++){var i=c[s];this.encode_value(i,n.map.key),this.encode_value(r?e.get(i):e[i],n.map.value)}},t.prototype.encode_struct=function(e,n){this.checkTypes&&mt(e,"object",this.fieldPath);for(var r=0,o=Object.keys(n.struct);r<o.length;r++){var s=o[r];this.fieldPath.push(s),this.encode_value(e[s],n.struct[s]),this.fieldPath.pop()}},t}();var Eo=function(){function t(e){this.buffer=new Un(e)}return t.prototype.decode=function(e){return this.decode_value(e)},t.prototype.decode_value=function(e){if(typeof e=="string"){if(Lt.includes(e))return this.decode_integer(e);if(e==="string")return this.decode_string();if(e==="bool")return this.decode_boolean()}if(typeof e=="object"){if("option"in e)return this.decode_option(e);if("enum"in e)return this.decode_enum(e);if("array"in e)return this.decode_array(e);if("set"in e)return this.decode_set(e);if("map"in e)return this.decode_map(e);if("struct"in e)return this.decode_struct(e)}throw new Error("Unsupported type: ".concat(e))},t.prototype.decode_integer=function(e){var n=parseInt(e.substring(1));return n<=32||e=="f64"?this.buffer.consume_value(e):this.decode_bigint(n,e.startsWith("i"))},t.prototype.decode_bigint=function(e,n){n===void 0&&(n=!1);var r=e/8,o=new Uint8Array(this.buffer.consume_bytes(r)),s=o.reduceRight(function(c,i){return c+i.toString(16).padStart(2,"0")},"");return n&&o[r-1]?BigInt.asIntN(e,BigInt("0x".concat(s))):BigInt("0x".concat(s))},t.prototype.decode_string=function(){for(var e=this.decode_integer("u32"),n=new Uint8Array(this.buffer.consume_bytes(e)),r=[],o=0;o<e;++o){var s=n[o];if(s<128)r.push(s);else if(s<224)r.push((s&31)<<6|n[++o]&63);else if(s<240)r.push((s&15)<<12|(n[++o]&63)<<6|n[++o]&63);else{var c=(s&7)<<18|(n[++o]&63)<<12|(n[++o]&63)<<6|n[++o]&63;r.push(c)}}return String.fromCodePoint.apply(String,r)},t.prototype.decode_boolean=function(){return this.buffer.consume_value("u8")>0},t.prototype.decode_option=function(e){var n=this.buffer.consume_value("u8");if(n===1)return this.decode_value(e.option);if(n!==0)throw new Error("Invalid option ".concat(n));return null},t.prototype.decode_enum=function(e){var n,r=this.buffer.consume_value("u8");if(r>e.enum.length)throw new Error("Enum option ".concat(r," is not available"));var o=e.enum[r].struct,s=Object.keys(o)[0];return n={},n[s]=this.decode_value(o[s]),n},t.prototype.decode_array=function(e){for(var n=[],r=e.array.len?e.array.len:this.decode_integer("u32"),o=0;o<r;++o)n.push(this.decode_value(e.array.type));return n},t.prototype.decode_set=function(e){for(var n=this.decode_integer("u32"),r=new Set,o=0;o<n;++o)r.add(this.decode_value(e.set));return r},t.prototype.decode_map=function(e){for(var n=this.decode_integer("u32"),r=new Map,o=0;o<n;++o){var s=this.decode_value(e.map.key),c=this.decode_value(e.map.value);r.set(s,c)}return r},t.prototype.decode_struct=function(e){var n={};for(var r in e.struct)n[r]=this.decode_value(e.struct[r]);return n},t}();function Ne(t,e,n){n===void 0&&(n=!0),n&&et(t);var r=new Rn(n);return r.encode(e,t)}function Hn(t){return{signerId:t.signerId,publicKey:{ed25519Key:{data:wt(t.publicKey)}},nonce:BigInt(t.nonce),receiverId:t.receiverId,blockHash:Q(t.blockHash),actions:t.actions.map(Fn)}}function Mn(t){let e=Hn(t);return Ne(qn.Transaction,e)}function Pn(t,e){let n={transaction:Hn(t),signature:{ed25519Signature:{data:Q(e)}}};return Ne(qn.SignedTransaction,n)}function Fn(t){switch(t.type){case"CreateAccount":return{createAccount:{}};case"DeployContract":return{deployContract:{code:Te(t.codeBase64)}};case"FunctionCall":return{functionCall:{methodName:t.methodName,args:t.argsBase64?Te(t.argsBase64):Buffer.from(JSON.stringify(t.args)),gas:BigInt(t.gas),deposit:BigInt(t.deposit)}};case"Transfer":return{transfer:{deposit:BigInt(t.deposit)}};case"Stake":return{stake:{stake:BigInt(t.stake),publicKey:{ed25519Key:wt(t.publicKey)}}};case"AddKey":return{addKey:{publicKey:wt(t.publicKey),accessKey:{nonce:BigInt(t.accessKey.nonce),permission:t.accessKey.permission==="FullAccess"?{fullAccess:{}}:{functionCall:{allowance:t.accessKey.allowance?BigInt(t.accessKey.allowance):null,receiverId:t.accessKey.receiverId,methodNames:t.accessKey.methodNames}}}}};case"DeleteKey":return{deleteKey:{publicKey:wt(t.publicKey)}};case"DeleteAccount":return{deleteAccount:{beneficiaryId:t.beneficiaryId}};case"SignedDelegate":return{signedDelegate:{delegateAction:Fn(t.delegateAction),signature:{ed25519Signature:Q(t.signature)}}};default:throw new Error("Not implemented action: "+t.type)}}var qn=new class{Ed25519Signature={struct:{data:{array:{type:"u8",len:64}}}};Secp256k1Signature={struct:{data:{array:{type:"u8",len:65}}}};Signature={enum:[{struct:{ed25519Signature:this.Ed25519Signature}},{struct:{secp256k1Signature:this.Secp256k1Signature}}]};Ed25519Data={struct:{data:{array:{type:"u8",len:32}}}};Secp256k1Data={struct:{data:{array:{type:"u8",len:64}}}};PublicKey={enum:[{struct:{ed25519Key:this.Ed25519Data}},{struct:{secp256k1Key:this.Secp256k1Data}}]};FunctionCallPermission={struct:{allowance:{option:"u128"},receiverId:"string",methodNames:{array:{type:"string"}}}};FullAccessPermission={struct:{}};AccessKeyPermission={enum:[{struct:{functionCall:this.FunctionCallPermission}},{struct:{fullAccess:this.FullAccessPermission}}]};AccessKey={struct:{nonce:"u64",permission:this.AccessKeyPermission}};CreateAccount={struct:{}};DeployContract={struct:{code:{array:{type:"u8"}}}};FunctionCall={struct:{methodName:"string",args:{array:{type:"u8"}},gas:"u64",deposit:"u128"}};Transfer={struct:{deposit:"u128"}};Stake={struct:{stake:"u128",publicKey:this.PublicKey}};AddKey={struct:{publicKey:this.PublicKey,accessKey:this.AccessKey}};DeleteKey={struct:{publicKey:this.PublicKey}};DeleteAccount={struct:{beneficiaryId:"string"}};ClassicAction={enum:[{struct:{createAccount:this.CreateAccount}},{struct:{deployContract:this.DeployContract}},{struct:{functionCall:this.FunctionCall}},{struct:{transfer:this.Transfer}},{struct:{stake:this.Stake}},{struct:{addKey:this.AddKey}},{struct:{deleteKey:this.DeleteKey}},{struct:{deleteAccount:this.DeleteAccount}}]};DelegateAction={struct:{senderId:"string",receiverId:"string",actions:{array:{type:this.ClassicAction}},nonce:"u64",maxBlockHeight:"u64",publicKey:this.PublicKey}};SignedDelegate={struct:{delegateAction:this.DelegateAction,signature:this.Signature}};Action={enum:[{struct:{createAccount:this.CreateAccount}},{struct:{deployContract:this.DeployContract}},{struct:{functionCall:this.FunctionCall}},{struct:{transfer:this.Transfer}},{struct:{stake:this.Stake}},{struct:{addKey:this.AddKey}},{struct:{deleteKey:this.DeleteKey}},{struct:{deleteAccount:this.DeleteAccount}},{struct:{signedDelegate:this.SignedDelegate}}]};Transaction={struct:{signerId:"string",publicKey:this.PublicKey,nonce:"u64",receiverId:"string",blockHash:{array:{type:"u8",len:32}},actions:{array:{type:this.Action}}}};SignedTransaction={struct:{transaction:this.Transaction,signature:this.Signature}}};j.DP=27;var Bo=1e3*60*60*6,vo="mainnet",Ao={testnet:{networkId:"testnet",nodeUrl:"https://rpc.testnet.fastnear.com/"},mainnet:{networkId:"mainnet",nodeUrl:"https://rpc.mainnet.fastnear.com/"}},Ut={...Ao[vo]},D;{let t=bt("privateKey");D={accountId:bt("accountId"),accessKeyContractId:bt("accessKeyContractId"),lastWalletId:bt("lastWalletId"),privateKey:t,publicKey:t?Ce(t):null}}var Ot={},Qt={account:new Set,tx:new Set};function Kt(t){let e=D;D={...D,...t},tt("accountId",D.accountId),tt("privateKey",D.privateKey),tt("lastWalletId",D.lastWalletId),tt("accessKeyContractId",D.accessKeyContractId),t.hasOwnProperty("privateKey")&&t.privateKey!==e.privateKey&&(D.publicKey=t.privateKey?Ce(t.privateKey):null,tt("nonce",null)),t.accountId!==e.accountId&&Uo(t.accountId)}function kt(t){let e=t.txId;Ot[e]={...Ot[e]??{},...t},Oo(Ot[e])}function Io(t){console.log("Adapter state update:",t),Kt({privateKey:t.privateKey,accountId:t.accountId,lastWalletId:t.lastWalletId})}var So=new We({onStateUpdate:Io});function Lo(t){try{return JSON.parse(Buffer.from(t).toString())}catch{try{return Buffer.from(t)}catch{return t}}}function $t(t,e){return e==="final"||e==="optimistic"?{...t,finality:e}:e?{...t,block_id:e}:{...t,finality:"optimistic"}}async function _t(t,e){let r=await(await fetch(Ut.nodeUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:`fastnear-${Date.now()}`,method:t,params:e})})).json();if(r.error)throw new Error(JSON.stringify(r.error));return r.result}function To(t,e,n){_t("send_tx",{signed_tx_base64:t,wait_until:e??"INCLUDED"}).then(r=>{kt({txId:n,status:"Included"}),_t("tx",{tx_hash:Ot[n].txHash,sender_account_id:Ot[n].tx.signerId,wait_until:"EXECUTED_OPTIMISTIC"}).then(o=>{kt({txId:n,status:"Executed",result:o})}).catch(o=>{kt({txId:n,status:"ErrorAfterIncluded",error:Oe(o.message)})})}).catch(r=>{kt({txId:n,status:"Error",error:Oe(r.message)})})}function Uo(t){Qt.account.forEach(e=>{try{e(t)}catch(n){console.error(n)}})}function Oo(t){Qt.tx.forEach(e=>{try{e(Ue(t))}catch(n){console.error(n)}})}function Co(t,...e){if(Array.isArray(t)&&(t=t.reduce((n,r,o)=>n+(e[o-1]||"")+r)),typeof t=="string"){let n=t.match(/([0-9.,_]+)\s*([a-zA-Z]+)?/);if(n){let r=n[1].replace(/[_,]/g,""),o=n[2];if(o)switch(o.toLowerCase()){case"near":return j(r).mul(j(10).pow(24)).toFixed(0);case"tgas":return j(r).mul(j(10).pow(12)).toFixed(0);case"ggas":return j(r).mul(j(10).pow(9)).toFixed(0);case"gas":return j(r).toFixed(0);default:throw new Error(`Unknown unit: ${unit}`)}else return j(r).toFixed(0)}}return j(t).toFixed(0)}var Do={get accountId(){return D.accountId},get publicKey(){return D.publicKey},config(t){if(t){if(t.networkId&&Ut.networkId!==t.networkId)throw new Error("TODO: Network ID change should handle scope");Ut={...Ut,...t}}return Ut},get authStatus(){if(!D.accountId)return"SignedOut";let t=D.publicKey,e=D.accessKeyContractId;return t?{type:"SignedInWithLimitedAccessKey",accessKey:t,contractId:e}:"SignedIn"},async view({contractId:t,methodName:e,args:n,argsBase64:r,blockId:o}){let s=r||(n?Le(JSON.stringify(n)):""),c=await _t("query",$t({request_type:"call_function",account_id:t,method_name:e,args_base64:s},o));return Lo(c.result)},async account({accountId:t,blockId:e}){return _t("query",$t({request_type:"view_account",account_id:t},e))},async block({blockId:t}){return _t("block",$t({},t))},async accessKey({accountId:t,publicKey:e,blockId:n}){return _t("query",$t({request_type:"view_access_key",account_id:t,public_key:e},n))},async tx({txHash:t,accountId:e}){return _t("tx",[t,e])},localTxHistory(){return[...Ot]},async sendTx({receiverId:t,actions:e,waitUntil:n}){if(!D.accountId)throw new Error("Not signed in");if(t!==D.accessKeyContractId)throw new Error("Need to use walletAdapter. Not implemented yet");let r=D.accountId,o=D.publicKey,s=D.privateKey,c={},i=bt("nonce");i||(c.nonce=this.accessKey({accountId:r,publicKey:o}).then(S=>(tt("nonce",S.nonce),S.nonce)));let a=bt("block");if((!a||parseFloat(a.header.timestamp_nanosec)/1e6+Bo<Date.now())&&(c.block=this.block({blockId:"final"}).then(S=>(S={header:{prev_hash:S.header.prev_hash,timestamp_nanosec:S.header.timestamp_nanosec}},tt("block",S),S))),Object.keys(c).length>0){let S=await Promise.all(Object.values(c));for(let p=0;p<S.length;p++)Object.keys(c)[p]==="nonce"?i=S[p]:Object.keys(c)[p]==="block"&&(a=S[p])}let f=i+1;tt("nonce",f);let u=a.header.prev_hash,l=`tx-${Date.now()}-${Math.random()}`,d={signerId:r,publicKey:o,nonce:f,receiverId:t,blockHash:u,actions:e};console.log("Transaction:",d);let g=Mn(d),w=yt(Jt(g)),x=Ln(w,s),E=Pn(d,x),N=Le(E);return kt({status:"Pending",txId:l,tx:Ue(d),signature:x,signedTxBase64:N,txHash:w}),To(N,n,l),l},async requestSignIn({contractId:t}){Kt({accessKeyContractId:t,accountId:null,privateKey:null});let e=await So.signIn({networkId:Ut.networkId,contractId:t});if(console.log("Sign in result:",e),e.error)throw new Error(`Wallet error: ${e.error}`);e.url?(console.log("Redirecting to wallet:",e.url),window.location.href=e.url):e.accountId&&Kt({accountId:e.accountId})},signOut(){Kt({accountId:null,privateKey:null,contractId:null})},onAccount(t){Qt.account.add(t)},onTx(t){Qt.tx.add(t)},actions:{functionCall:({methodName:t,gas:e,deposit:n,args:r,argsBase64:o})=>({type:"FunctionCall",methodName:t,args:r,argsBase64:o,gas:e,deposit:n}),transfer:t=>({type:"Transfer",deposit:t}),stakeNEAR:({amount:t,publicKey:e})=>({type:"Stake",stake:t,publicKey:e}),addFullAccessKey:({publicKey:t})=>({type:"AddKey",publicKey:t,accessKey:{permission:"FullAccess"}}),addLimitedAccessKey:({publicKey:t,allowance:e,accountId:n,methodNames:r})=>({type:"AddKey",publicKey:t,accessKey:{permission:"FunctionCall",allowance:e,receiverId:n,methodNames:r}}),deleteKey:({publicKey:t})=>({type:"DeleteKey",publicKey:t}),deleteAccount:({beneficiaryId:t})=>({type:"DeleteAccount",beneficiaryId:t}),createAccount:()=>({type:"CreateAccount"}),deployContract:({codeBase64:t})=>({type:"DeployContract",codeBase64:t})}};try{let t=new URL(window.location.href),e=t.searchParams.get("account_id"),n=t.searchParams.get("public_key"),r=t.searchParams.get("error_code");r&&console.error(new Error(`Wallet error: ${r}`)),e&&n&&(n===D.publicKey?Kt({accountId:e}):console.error(new Error("Public key mismatch from wallet redirect"),n,D.publicKey)),t.searchParams.delete("account_id"),t.searchParams.delete("public_key"),t.searchParams.delete("error_code"),t.searchParams.delete("all_keys"),window.history.replaceState({},"",t.toString())}catch(t){console.error("Error handling wallet redirect:",t)}export{Co as $$,Do as near};
2
- /*! Bundled license information:
3
-
4
- @noble/hashes/esm/utils.js:
5
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6
-
7
- @noble/curves/esm/abstract/utils.js:
8
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
9
-
10
- @noble/curves/esm/abstract/modular.js:
11
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
12
-
13
- @noble/curves/esm/abstract/curve.js:
14
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
15
-
16
- @noble/curves/esm/abstract/edwards.js:
17
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
-
19
- @noble/curves/esm/ed25519.js:
20
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
21
-
22
- @noble/hashes/esm/utils.js:
23
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
24
- */