@metamask/browser-playground 0.7.0 → 0.7.1
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.
- package/CHANGELOG.md +10 -1
- package/build/asset-manifest.json +9 -3
- package/build/index.html +1 -1
- package/build/static/js/127.6f28ac63.chunk.js +3 -0
- package/build/static/js/127.6f28ac63.chunk.js.LICENSE.txt +1 -0
- package/build/static/js/127.6f28ac63.chunk.js.map +1 -0
- package/build/static/js/288.51cc5192.chunk.js +3 -0
- package/build/static/js/288.51cc5192.chunk.js.LICENSE.txt +3 -0
- package/build/static/js/288.51cc5192.chunk.js.map +1 -0
- package/build/static/js/921.58d10f34.chunk.js +2 -0
- package/build/static/js/921.58d10f34.chunk.js.map +1 -0
- package/build/static/js/main.2f01c3f9.js +3 -0
- package/build/static/js/{main.6fb69fc4.js.LICENSE.txt → main.2f01c3f9.js.LICENSE.txt} +0 -6
- package/build/static/js/main.2f01c3f9.js.map +1 -0
- package/package.json +3 -3
- package/build/static/js/main.6fb69fc4.js +0 -3
- package/build/static/js/main.6fb69fc4.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump workspace dependencies:
|
|
15
|
+
- @metamask/connect-evm@1.1.0
|
|
16
|
+
- @metamask/connect-multichain@0.13.0
|
|
17
|
+
|
|
10
18
|
## [0.7.0]
|
|
11
19
|
|
|
12
20
|
### Changed
|
|
@@ -188,7 +196,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
188
196
|
|
|
189
197
|
- Initial release
|
|
190
198
|
|
|
191
|
-
[Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.7.
|
|
199
|
+
[Unreleased]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.7.1...HEAD
|
|
200
|
+
[0.7.1]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.7.0...@metamask/browser-playground@0.7.1
|
|
192
201
|
[0.7.0]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.6.6...@metamask/browser-playground@0.7.0
|
|
193
202
|
[0.6.6]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.6.5...@metamask/browser-playground@0.6.6
|
|
194
203
|
[0.6.5]: https://github.com/MetaMask/connect-monorepo/compare/@metamask/browser-playground@0.6.4...@metamask/browser-playground@0.6.5
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "./static/css/main.cdee3abe.css",
|
|
4
|
-
"main.js": "./static/js/main.
|
|
4
|
+
"main.js": "./static/js/main.2f01c3f9.js",
|
|
5
|
+
"static/js/921.58d10f34.chunk.js": "./static/js/921.58d10f34.chunk.js",
|
|
6
|
+
"static/js/288.51cc5192.chunk.js": "./static/js/288.51cc5192.chunk.js",
|
|
7
|
+
"static/js/127.6f28ac63.chunk.js": "./static/js/127.6f28ac63.chunk.js",
|
|
5
8
|
"static/js/435.8081f498.chunk.js": "./static/js/435.8081f498.chunk.js",
|
|
6
9
|
"static/js/817.bf92ca72.chunk.js": "./static/js/817.bf92ca72.chunk.js",
|
|
7
10
|
"static/js/578.67e35af4.chunk.js": "./static/js/578.67e35af4.chunk.js",
|
|
@@ -9,7 +12,10 @@
|
|
|
9
12
|
"static/js/29.8d088763.chunk.js": "./static/js/29.8d088763.chunk.js",
|
|
10
13
|
"index.html": "./index.html",
|
|
11
14
|
"main.cdee3abe.css.map": "./static/css/main.cdee3abe.css.map",
|
|
12
|
-
"main.
|
|
15
|
+
"main.2f01c3f9.js.map": "./static/js/main.2f01c3f9.js.map",
|
|
16
|
+
"921.58d10f34.chunk.js.map": "./static/js/921.58d10f34.chunk.js.map",
|
|
17
|
+
"288.51cc5192.chunk.js.map": "./static/js/288.51cc5192.chunk.js.map",
|
|
18
|
+
"127.6f28ac63.chunk.js.map": "./static/js/127.6f28ac63.chunk.js.map",
|
|
13
19
|
"435.8081f498.chunk.js.map": "./static/js/435.8081f498.chunk.js.map",
|
|
14
20
|
"817.bf92ca72.chunk.js.map": "./static/js/817.bf92ca72.chunk.js.map",
|
|
15
21
|
"578.67e35af4.chunk.js.map": "./static/js/578.67e35af4.chunk.js.map",
|
|
@@ -18,6 +24,6 @@
|
|
|
18
24
|
},
|
|
19
25
|
"entrypoints": [
|
|
20
26
|
"static/css/main.cdee3abe.css",
|
|
21
|
-
"static/js/main.
|
|
27
|
+
"static/js/main.2f01c3f9.js"
|
|
22
28
|
]
|
|
23
29
|
}
|
package/build/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./alt-fox.svg"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><title>Multichain Test Dapp</title><meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' wss://mm-sdk-relay.api.cx.metamask.io https://mm-sdk-analytics.api.cx.metamask.io https://*.infura.io; frame-src https://fwd.metamask.io; font-src 'self';"/><script defer="defer" src="./static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./alt-fox.svg"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><title>Multichain Test Dapp</title><meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' wss://mm-sdk-relay.api.cx.metamask.io https://mm-sdk-analytics.api.cx.metamask.io https://*.infura.io; frame-src https://fwd.metamask.io; font-src 'self';"/><script defer="defer" src="./static/js/main.2f01c3f9.js"></script><link href="./static/css/main.cdee3abe.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! For license information please see 127.6f28ac63.chunk.js.LICENSE.txt */
|
|
2
|
+
"use strict";(self.webpackChunk_metamask_browser_playground=self.webpackChunk_metamask_browser_playground||[]).push([[127],{7127:(e,t,n)=>{n.r(t),n.d(t,{DappClient:()=>te});var r=n(9740),o=n(1979),i=n(5921);function s(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function a(e){if(!s(e))throw new Error("Uint8Array expected");for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(n.length>0&&!n.includes(e.length))throw new Error("Uint8Array expected of length "+n+", got length="+e.length)}function c(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"===typeof e):t.every(e=>Number.isSafeInteger(e))))}function d(e){if("function"!==typeof e)throw new Error("function expected");return!0}function h(e,t){if("string"!==typeof t)throw new Error("".concat(e,": string expected"));return!0}function l(e){if(!Number.isSafeInteger(e))throw new Error("invalid integer: ".concat(e))}function f(e){if(!Array.isArray(e))throw new Error("array expected")}function u(e,t){if(!c(!0,t))throw new Error("".concat(e,": array of strings expected"))}function w(e,t){if(!c(!1,t))throw new Error("".concat(e,": array of numbers expected"))}function p(){const e=e=>e,t=(e,t)=>n=>e(t(n));for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return{encode:r.map(e=>e.encode).reduceRight(t,e),decode:r.map(e=>e.decode).reduce(t,e)}}function E(e){const t="string"===typeof e?e.split(""):e,n=t.length;u("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(f(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error('alphabet.encode: digit index outside alphabet "'.concat(r,'". Allowed: ').concat(e));return t[r]})),decode:t=>(f(t),t.map(t=>{h("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error('Unknown letter: "'.concat(t,'". Allowed: ').concat(e));return n}))}}function g(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return h("join",e),{encode:t=>(u("join.decode",t),t.join(e)),decode:t=>(h("join.decode",t),t.split(e))}}function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"=";return l(e),h("padding",t),{encode(n){for(u("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){u("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8===0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}function m(e){return d(e),{encode:e=>e,decode:t=>e(t)}}function x(e,t,n){if(t<2)throw new Error("convertRadix: invalid from=".concat(t,", base cannot be less than 2"));if(n<2)throw new Error("convertRadix: invalid to=".concat(n,", base cannot be less than 2"));if(f(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if(l(e),e<0||e>=t)throw new Error("invalid integer: ".concat(e));return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,d=c+s;if(!Number.isSafeInteger(d)||c/t!==e||d-s!==c)throw new Error("convertRadix: carry overflow");const h=d/n;e=d%n;const l=Math.floor(h);if(i[o]=l,!Number.isSafeInteger(l)||l*n+e!==d)throw new Error("convertRadix: carry overflow");a&&(l?a=!1:r=o)}if(o.push(e),a)break}for(let a=0;a<e.length-1&&0===e[a];a++)o.push(0);return o.reverse()}const A=(e,t)=>0===t?e:A(t,e%t),S=(e,t)=>e+(t-A(e,t)),b=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function v(e,t,n,r){if(f(e),t<=0||t>32)throw new Error("convertRadix2: wrong from=".concat(t));if(n<=0||n>32)throw new Error("convertRadix2: wrong to=".concat(n));if(S(t,n)>32)throw new Error("convertRadix2: carry overflow from=".concat(t," to=").concat(n," carryBits=").concat(S(t,n)));let o=0,i=0;const s=b[t],a=b[n]-1,c=[];for(const d of e){if(l(d),d>=s)throw new Error("convertRadix2: invalid data word=".concat(d," from=").concat(t));if(o=o<<t|d,i+t>32)throw new Error("convertRadix2: carry overflow pos=".concat(i," from=").concat(t));for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=b[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error("Non-zero padding: ".concat(o));return r&&i>0&&c.push(o>>>0),c}function C(e){l(e);return{encode:t=>{if(!s(t))throw new Error("radix.encode input should be Uint8Array");return x(Array.from(t),256,e)},decode:t=>(w("radix.decode",t),Uint8Array.from(x(t,e,256)))}}function T(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(l(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(S(8,e)>32||S(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!s(n))throw new Error("radix2.encode input should be Uint8Array");return v(Array.from(n),8,e,!t)},decode:n=>(w("radix2.decode",n),Uint8Array.from(v(n,e,8,t)))}}function _(e){return d(e),function(){try{for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.apply(null,n)}catch(o){}}}const I=p(T(4),E("0123456789ABCDEF"),g("")),N=p(T(5),E("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),y(5),g("")),k=(p(T(5),E("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),g("")),p(T(5),E("0123456789ABCDEFGHIJKLMNOPQRSTUV"),y(5),g("")),p(T(5),E("0123456789ABCDEFGHIJKLMNOPQRSTUV"),g("")),p(T(5),E("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),g(""),m(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),(()=>"function"===typeof Uint8Array.from([]).toBase64&&"function"===typeof Uint8Array.fromBase64)()),O=(e,t)=>{h("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})},D=k?{encode:e=>(a(e),e.toBase64()),decode:e=>O(e,!1)}:p(T(6),E("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),y(6),g("")),U=(p(T(6),E("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),g("")),k?{encode:e=>(a(e),e.toBase64({alphabet:"base64url"})),decode:e=>O(e,!0)}:p(T(6),E("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),y(6),g(""))),R=(p(T(6),E("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),g("")),e=>p(C(58),E(e),g(""))),P=R("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),B=(R("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),R("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),[0,2,3,5,6,7,9,10,11]),M={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=P.encode(r).padStart(B[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),o=B.indexOf(r.length),i=P.decode(r);for(let e=0;e<i.length-o;e++)if(0!==i[e])throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(i.slice(i.length-o)))}return Uint8Array.from(t)}},L=p(E("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),g("")),F=[996825010,642813549,513874426,1027748829,705979059];function H(e){const t=e>>25;let n=(33554431&e)<<5;for(let r=0;r<F.length;r++)1===(t>>r&1)&&(n^=F[r]);return n}function K(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;const r=e.length;let o=1;for(let i=0;i<r;i++){const t=e.charCodeAt(i);if(t<33||t>126)throw new Error("Invalid prefix (".concat(e,")"));o=H(o)^t>>5}o=H(o);for(let i=0;i<r;i++)o=H(o)^31&e.charCodeAt(i);for(let i of t)o=H(o)^i;for(let i=0;i<6;i++)o=H(o);return o^=n,L.encode(v([o%b[30]],30,5,!1))}function V(e){const t="bech32"===e?1:734539939,n=T(5),r=n.decode,o=n.encode,i=_(r);function a(e,n){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:90;h("bech32.encode prefix",e),s(n)&&(n=Array.from(n)),w("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError("Invalid prefix length ".concat(o));const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError("Length ".concat(i," exceeds limit ").concat(r));const a=e.toLowerCase(),c=K(a,n,t);return"".concat(a,"1").concat(L.encode(n)).concat(c)}function c(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:90;h("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError("invalid string length: ".concat(r," (").concat(e,"). Expected (8..").concat(n,")"));const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=L.decode(a).slice(0,-6),d=K(s,c,t);if(!a.endsWith(d))throw new Error("Invalid checksum in ".concat(e,': expected "').concat(d,'"'));return{prefix:s,words:c}}return{encode:a,decode:c,encodeFromBytes:function(e,t){return a(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=c(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:_(c),fromWords:r,fromWordsUnsafe:i,toWords:o}}V("bech32"),V("bech32m");const q={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)};(()=>"function"===typeof Uint8Array.from([]).toHex&&"function"===typeof Uint8Array.fromHex)()||p(T(4),E("0123456789abcdef"),g(""),m(e=>{if("string"!==typeof e||e.length%2!==0)throw new TypeError("hex.decode: expected string, got ".concat(typeof e," with length ").concat(e.length));return e.toLowerCase()}));function Q(e,t){return function(e){var t;return Boolean("string"===typeof(null===e||void 0===e||null===(t=e.prototype)||void 0===t||null===(t=t.constructor)||void 0===t?void 0:t.name))}(e)?new e({message:t}):e({message:t})}class z extends Error{constructor(e){super(e.message),this.code="ERR_ASSERTION"}}function W(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Assertion failed.";if(!e){if(t instanceof Error)throw t;throw Q(arguments.length>2&&void 0!==arguments[2]?arguments[2]:z,t)}}!function(){const e=[]}();function X(e){return e instanceof Uint8Array}function G(e){W(X(e),"Value must be a Uint8Array.")}function j(e){return G(e),D.encode(e)}function J(e){return W("string"===typeof e,"Value must be a string."),D.decode(e)}var Z=n(3563),Y=class{constructor(e){(0,o.A)(this,"context",void 0),this.context=e}async execute(e,t){await this.context.transport.connect(),await this.context.transport.subscribe(t.channel);const n=await this._waitForHandshakeOffer(t.expiresAt),r=this._createFinalSession(e,n);this.context.session=r,await this._finalizeConnection(r,t)}_waitForHandshakeOffer(e){return new Promise((t,n)=>{if(e<Date.now())return n(new i.SessionError(i.ErrorCode.REQUEST_EXPIRED,"Session request expired before wallet could connect"));const r=e+ee-Date.now(),o=setTimeout(()=>{this.context.off("handshake_offer_received",s),n(new i.SessionError(i.ErrorCode.REQUEST_EXPIRED,"Did not receive handshake offer from wallet in time."))},r),s=e=>{clearTimeout(o),t(e)};this.context.once("handshake_offer_received",s)})}_createFinalSession(e,t){const n=J(t.publicKeyB64);return this.context.keymanager.validatePeerKey(n),(0,r.A)((0,r.A)({},e),{},{channel:"session:".concat(t.channelId),theirPublicKey:n})}async _finalizeConnection(e,t){if(!this.context.session)throw new i.SessionError(i.ErrorCode.SESSION_INVALID_STATE);await this.context.sessionstore.set(this.context.session),await this.context.transport.subscribe(e.channel),await this.context.transport.clear(t.channel),this.context.state=i.ClientState.CONNECTED,this.context.emit("connected")}},$=class{constructor(e){(0,o.A)(this,"context",void 0),(0,o.A)(this,"otpAttempts",3),(0,o.A)(this,"timeoutId",null),this.context=e}async execute(e,t){await this.context.transport.connect(),await this.context.transport.subscribe(t.channel);const n=await this._waitForHandshakeOffer(t.expiresAt);await this._handleOtpInput(n);const r=this._createFinalSession(e,n);this.context.session=r,await this._acknowledgeHandshake(r),await this._finalizeConnection(t.channel)}_waitForHandshakeOffer(e){return new Promise((t,n)=>{const r=e-Date.now();if(r<=0)return n(new i.SessionError(i.ErrorCode.REQUEST_EXPIRED,"Session request expired before wallet could connect."));this.timeoutId=setTimeout(()=>{this.context.off("handshake_offer_received",o),n(new i.SessionError(i.ErrorCode.REQUEST_EXPIRED,"Did not receive handshake offer from wallet in time."))},r);const o=e=>{this.timeoutId&&clearTimeout(this.timeoutId),this.timeoutId=null,t(e)};this.context.once("handshake_offer_received",o)})}_handleOtpInput(e){return new Promise((t,n)=>{if(!e.deadline||!e.otp)return n(new i.SessionError(i.ErrorCode.UNKNOWN,"Handshake offer is missing OTP details for untrusted connection."));if(Date.now()>e.deadline)return n(new i.SessionError(i.ErrorCode.OTP_ENTRY_TIMEOUT,"The OTP has already expired."));const r=e.otp;let o=0;this.context.emit("otp_required",{submit:async e=>{if((0,i.timingSafeEqual)(e,r))t();else{if(o++,!(o>=this.otpAttempts))throw new i.SessionError(i.ErrorCode.OTP_INCORRECT,"Incorrect OTP. ".concat(this.otpAttempts-o," attempts remaining."));n(new i.SessionError(i.ErrorCode.OTP_MAX_ATTEMPTS_REACHED,"Maximum OTP attempts reached."))}},cancel:()=>n(new Error("User cancelled OTP entry.")),deadline:e.deadline})})}_createFinalSession(e,t){const n=J(t.publicKeyB64);return this.context.keymanager.validatePeerKey(n),(0,r.A)((0,r.A)({},e),{},{channel:"session:".concat(t.channelId),theirPublicKey:n})}async _acknowledgeHandshake(e){await this.context.transport.subscribe(e.channel),await this.context.sendMessage(e.channel,{type:"handshake-ack"})}async _finalizeConnection(e){if(!this.context.session)throw new i.SessionError(i.ErrorCode.SESSION_INVALID_STATE);await this.context.sessionstore.set(this.context.session),await this.context.transport.clear(e),this.context.state=i.ClientState.CONNECTED,this.context.emit("connected")}},ee=6e4,te=class extends i.BaseClient{on(e,t){return super.on(e,t)}constructor(e){super(e.transport,e.keymanager,e.sessionstore)}async connect(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==i.ClientState.DISCONNECTED)throw new i.SessionError(i.ErrorCode.SESSION_INVALID_STATE,"Cannot connect when state is ".concat(this.state));const{mode:t="untrusted",initialPayload:n}=e;if(!(0,i.isValidConnectionMode)(t))throw new i.SessionError(i.ErrorCode.SESSION_INVALID_STATE,'Invalid connection mode: "'.concat(String(t),'"'));this.state=i.ClientState.CONNECTING;const{pendingSession:r,request:o}=this._createPendingSessionAndRequest(t,n);this.session=r,this.emit("session_request",o);const s=this,a={transport:this.transport,sessionstore:this.sessionstore,keymanager:this.keymanager,get session(){return s.session},set session(e){s.session=e},get state(){return s.state},set state(e){s.state=e},emit:this.emit.bind(this),once:this.once.bind(this),off:this.off.bind(this),sendMessage:this.sendMessage.bind(this)},c="trusted"===t?new Y(a):new $(a);try{await c.execute(r,o)}catch(d){throw this.emit("error",d),await this.disconnect(),d}}async sendRequest(e){if(this.state!==i.ClientState.CONNECTED||!this.session)throw new i.SessionError(i.ErrorCode.SESSION_INVALID_STATE,"Cannot send request: not connected.");await this.sendMessage(this.session.channel,{type:"message",payload:e})}handleMessage(e){this.state===i.ClientState.CONNECTING&&"handshake-offer"===e.type?this.emit("handshake_offer_received",e.payload):this.state===i.ClientState.CONNECTED&&"message"===e.type&&this.emit("message",e.payload)}_createPendingSessionAndRequest(e,t){const n=(0,Z.A)(),r=this.keymanager.generateKeyPair(),o=t?{type:"message",payload:t}:void 0;return{pendingSession:{id:n,channel:"",keyPair:r,theirPublicKey:new Uint8Array(0),expiresAt:Date.now()+i.DEFAULT_SESSION_TTL},request:{id:n,mode:e,channel:"handshake:".concat(n),publicKeyB64:j(r.publicKey),expiresAt:Date.now()+6e4,initialMessage:o}}}}}}]);
|
|
3
|
+
//# sourceMappingURL=127.6f28ac63.chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static/js/127.6f28ac63.chunk.js","mappings":";+MAYA,SAASA,EAAQC,GACf,OAAOA,aAAaC,YAAeC,YAAYC,OAAOH,IAA6B,eAAvBA,EAAEI,YAAYC,IAC5E,CAEA,SAASC,EAAOC,GACd,IAAKR,EAAQQ,GAAI,MAAM,IAAIC,MAAM,uBAAuB,QAAAC,EAAAC,UAAAC,OADZC,EAAiB,IAAAC,MAAAJ,EAAA,EAAAA,EAAA,KAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAjBF,EAAiBE,EAAA,GAAAJ,UAAAI,GAE7D,GAAIF,EAAQD,OAAS,IAAMC,EAAQG,SAASR,EAAEI,QAC5C,MAAM,IAAIH,MAAM,iCAAmCI,EAAU,gBAAkBL,EAAEI,OACrF,CAEA,SAASK,EAAUC,EAAmBC,GACpC,QAAKL,MAAMM,QAAQD,KACA,IAAfA,EAAIP,SACJM,EACKC,EAAIE,MAAOC,GAAyB,kBAATA,GAE3BH,EAAIE,MAAOC,GAASC,OAAOC,cAAcF,KAEpD,CAIA,SAASG,EAAIC,GACX,GAAqB,oBAAVA,EAAsB,MAAM,IAAIjB,MAAM,qBACjD,OAAO,CACT,CAEA,SAASkB,EAAKC,EAAeF,GAC3B,GAAqB,kBAAVA,EAAoB,MAAM,IAAIjB,MAAM,GAADoB,O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GAE/BuM,UAAWQ,KAAKC,MAAQ4E,EAAAA,qBAWD5F,QART,CACd9J,KACAyO,OACAvE,QAAS,aAAFzK,OAAeO,GACtB4L,aAActC,EAAckG,EAAQG,WACpCtF,UAAWQ,KAAKC,MArHI,IAsHpB8E,eAAgBpH,GAGpB,E","sources":["../../../node_modules/@scure/base/index.ts","../../../node_modules/@metamask/mobile-wallet-protocol-dapp-client/node_modules/@metamask/utils/src/assert.ts","../../../node_modules/@metamask/mobile-wallet-protocol-dapp-client/node_modules/@metamask/utils/src/bytes.ts","../../../node_modules/@metamask/mobile-wallet-protocol-dapp-client/dist/index.mjs"],"sourcesContent":["/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\nexport interface Coder<F, T> {\n encode(from: F): T;\n decode(to: T): F;\n}\n\nexport interface BytesCoder extends Coder<Uint8Array, string> {\n encode: (data: Uint8Array) => string;\n decode: (str: string) => Uint8Array;\n}\n\nfunction isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n/** Asserts something is Uint8Array. */\nfunction abytes(b: Uint8Array | undefined, ...lengths: number[]): void {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n\nfunction isArrayOf(isString: boolean, arr: any[]) {\n if (!Array.isArray(arr)) return false;\n if (arr.length === 0) return true;\n if (isString) {\n return arr.every((item) => typeof item === 'string');\n } else {\n return arr.every((item) => Number.isSafeInteger(item));\n }\n}\n\n// no abytes: seems to have 10% slowdown. Why?!\n\nfunction afn(input: Function): input is Function {\n if (typeof input !== 'function') throw new Error('function expected');\n return true;\n}\n\nfunction astr(label: string, input: unknown): input is string {\n if (typeof input !== 'string') throw new Error(`${label}: string expected`);\n return true;\n}\n\nfunction anumber(n: number): void {\n if (!Number.isSafeInteger(n)) throw new Error(`invalid integer: ${n}`);\n}\n\nfunction aArr(input: any[]) {\n if (!Array.isArray(input)) throw new Error('array expected');\n}\nfunction astrArr(label: string, input: string[]) {\n if (!isArrayOf(true, input)) throw new Error(`${label}: array of strings expected`);\n}\nfunction anumArr(label: string, input: number[]) {\n if (!isArrayOf(false, input)) throw new Error(`${label}: array of numbers expected`);\n}\n\n// TODO: some recusive type inference so it would check correct order of input/output inside rest?\n// like <string, number>, <number, bytes>, <bytes, float>\ntype Chain = [Coder<any, any>, ...Coder<any, any>[]];\n// Extract info from Coder type\ntype Input<F> = F extends Coder<infer T, any> ? T : never;\ntype Output<F> = F extends Coder<any, infer T> ? T : never;\n// Generic function for arrays\ntype First<T> = T extends [infer U, ...any[]] ? U : never;\ntype Last<T> = T extends [...any[], infer U] ? U : never;\ntype Tail<T> = T extends [any, ...infer U] ? U : never;\n\ntype AsChain<C extends Chain, Rest = Tail<C>> = {\n // C[K] = Coder<Input<C[K]>, Input<Rest[k]>>\n [K in keyof C]: Coder<Input<C[K]>, Input<K extends keyof Rest ? Rest[K] : any>>;\n};\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction chain<T extends Chain & AsChain<T>>(...args: T): Coder<Input<First<T>>, Output<Last<T>>> {\n const id = (a: any) => a;\n // Wrap call in closure so JIT can inline calls\n const wrap = (a: any, b: any) => (c: any) => a(b(c));\n // Construct chain of args[-1].encode(args[-2].encode([...]))\n const encode = args.map((x) => x.encode).reduceRight(wrap, id);\n // Construct chain of args[0].decode(args[1].decode(...))\n const decode = args.map((x) => x.decode).reduce(wrap, id);\n return { encode, decode };\n}\n\n/**\n * Encodes integer radix representation to array of strings using alphabet and back.\n * Could also be array of strings.\n * @__NO_SIDE_EFFECTS__\n */\nfunction alphabet(letters: string | string[]): Coder<number[], string[]> {\n // mapping 1 to \"b\"\n const lettersA = typeof letters === 'string' ? letters.split('') : letters;\n const len = lettersA.length;\n astrArr('alphabet', lettersA);\n\n // mapping \"b\" to 1\n const indexes = new Map(lettersA.map((l, i) => [l, i]));\n return {\n encode: (digits: number[]) => {\n aArr(digits);\n return digits.map((i) => {\n if (!Number.isSafeInteger(i) || i < 0 || i >= len)\n throw new Error(\n `alphabet.encode: digit index outside alphabet \"${i}\". Allowed: ${letters}`\n );\n return lettersA[i]!;\n });\n },\n decode: (input: string[]): number[] => {\n aArr(input);\n return input.map((letter) => {\n astr('alphabet.decode', letter);\n const i = indexes.get(letter);\n if (i === undefined) throw new Error(`Unknown letter: \"${letter}\". Allowed: ${letters}`);\n return i;\n });\n },\n };\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction join(separator = ''): Coder<string[], string> {\n astr('join', separator);\n return {\n encode: (from) => {\n astrArr('join.decode', from);\n return from.join(separator);\n },\n decode: (to) => {\n astr('join.decode', to);\n return to.split(separator);\n },\n };\n}\n\n/**\n * Pad strings array so it has integer number of bits\n * @__NO_SIDE_EFFECTS__\n */\nfunction padding(bits: number, chr = '='): Coder<string[], string[]> {\n anumber(bits);\n astr('padding', chr);\n return {\n encode(data: string[]): string[] {\n astrArr('padding.encode', data);\n while ((data.length * bits) % 8) data.push(chr);\n return data;\n },\n decode(input: string[]): string[] {\n astrArr('padding.decode', input);\n let end = input.length;\n if ((end * bits) % 8)\n throw new Error('padding: invalid, string should have whole number of bytes');\n for (; end > 0 && input[end - 1] === chr; end--) {\n const last = end - 1;\n const byte = last * bits;\n if (byte % 8 === 0) throw new Error('padding: invalid, string has too much padding');\n }\n return input.slice(0, end);\n },\n };\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction normalize<T>(fn: (val: T) => T): Coder<T, T> {\n afn(fn);\n return { encode: (from: T) => from, decode: (to: T) => fn(to) };\n}\n\n/**\n * Slow: O(n^2) time complexity\n */\nfunction convertRadix(data: number[], from: number, to: number): number[] {\n // base 1 is impossible\n if (from < 2) throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);\n if (to < 2) throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);\n aArr(data);\n if (!data.length) return [];\n let pos = 0;\n const res = [];\n const digits = Array.from(data, (d) => {\n anumber(d);\n if (d < 0 || d >= from) throw new Error(`invalid integer: ${d}`);\n return d;\n });\n const dlen = digits.length;\n while (true) {\n let carry = 0;\n let done = true;\n for (let i = pos; i < dlen; i++) {\n const digit = digits[i]!;\n const fromCarry = from * carry;\n const digitBase = fromCarry + digit;\n if (\n !Number.isSafeInteger(digitBase) ||\n fromCarry / from !== carry ||\n digitBase - digit !== fromCarry\n ) {\n throw new Error('convertRadix: carry overflow');\n }\n const div = digitBase / to;\n carry = digitBase % to;\n const rounded = Math.floor(div);\n digits[i] = rounded;\n if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)\n throw new Error('convertRadix: carry overflow');\n if (!done) continue;\n else if (!rounded) pos = i;\n else done = false;\n }\n res.push(carry);\n if (done) break;\n }\n for (let i = 0; i < data.length - 1 && data[i] === 0; i++) res.push(0);\n return res.reverse();\n}\n\nconst gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));\nconst radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from: number, to: number) =>\n from + (to - gcd(from, to));\nconst powers: number[] = /* @__PURE__ */ (() => {\n let res = [];\n for (let i = 0; i < 40; i++) res.push(2 ** i);\n return res;\n})();\n/**\n * Implemented with numbers, because BigInt is 5x slower\n */\nfunction convertRadix2(data: number[], from: number, to: number, padding: boolean): number[] {\n aArr(data);\n if (from <= 0 || from > 32) throw new Error(`convertRadix2: wrong from=${from}`);\n if (to <= 0 || to > 32) throw new Error(`convertRadix2: wrong to=${to}`);\n if (radix2carry(from, to) > 32) {\n throw new Error(\n `convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`\n );\n }\n let carry = 0;\n let pos = 0; // bitwise position in current element\n const max = powers[from]!;\n const mask = powers[to]! - 1;\n const res: number[] = [];\n for (const n of data) {\n anumber(n);\n if (n >= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);\n carry = (carry << from) | n;\n if (pos + from > 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);\n pos += from;\n for (; pos >= to; pos -= to) res.push(((carry >> (pos - to)) & mask) >>> 0);\n const pow = powers[pos];\n if (pow === undefined) throw new Error('invalid carry');\n carry &= pow - 1; // clean carry, otherwise it will cause overflow\n }\n carry = (carry << (to - pos)) & mask;\n if (!padding && pos >= from) throw new Error('Excess padding');\n if (!padding && carry > 0) throw new Error(`Non-zero padding: ${carry}`);\n if (padding && pos > 0) res.push(carry >>> 0);\n return res;\n}\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix(num: number): Coder<Uint8Array, number[]> {\n anumber(num);\n const _256 = 2 ** 8;\n return {\n encode: (bytes: Uint8Array) => {\n if (!isBytes(bytes)) throw new Error('radix.encode input should be Uint8Array');\n return convertRadix(Array.from(bytes), _256, num);\n },\n decode: (digits: number[]) => {\n anumArr('radix.decode', digits);\n return Uint8Array.from(convertRadix(digits, num, _256));\n },\n };\n}\n\n/**\n * If both bases are power of same number (like `2**8 <-> 2**64`),\n * there is a linear algorithm. For now we have implementation for power-of-two bases only.\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix2(bits: number, revPadding = false): Coder<Uint8Array, number[]> {\n anumber(bits);\n if (bits <= 0 || bits > 32) throw new Error('radix2: bits should be in (0..32]');\n if (radix2carry(8, bits) > 32 || radix2carry(bits, 8) > 32)\n throw new Error('radix2: carry overflow');\n return {\n encode: (bytes: Uint8Array) => {\n if (!isBytes(bytes)) throw new Error('radix2.encode input should be Uint8Array');\n return convertRadix2(Array.from(bytes), 8, bits, !revPadding);\n },\n decode: (digits: number[]) => {\n anumArr('radix2.decode', digits);\n return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));\n },\n };\n}\n\ntype ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;\nfunction unsafeWrapper<T extends (...args: any) => any>(fn: T) {\n afn(fn);\n return function (...args: ArgumentTypes<T>): ReturnType<T> | void {\n try {\n return fn.apply(null, args);\n } catch (e) {}\n };\n}\n\nfunction checksum(\n len: number,\n fn: (data: Uint8Array) => Uint8Array\n): Coder<Uint8Array, Uint8Array> {\n anumber(len);\n afn(fn);\n return {\n encode(data: Uint8Array) {\n if (!isBytes(data)) throw new Error('checksum.encode: input should be Uint8Array');\n const sum = fn(data).slice(0, len);\n const res = new Uint8Array(data.length + len);\n res.set(data);\n res.set(sum, data.length);\n return res;\n },\n decode(data: Uint8Array) {\n if (!isBytes(data)) throw new Error('checksum.decode: input should be Uint8Array');\n const payload = data.slice(0, -len);\n const oldChecksum = data.slice(-len);\n const newChecksum = fn(payload).slice(0, len);\n for (let i = 0; i < len; i++)\n if (newChecksum[i] !== oldChecksum[i]) throw new Error('Invalid checksum');\n return payload;\n },\n };\n}\n\n// prettier-ignore\nexport const utils: { alphabet: typeof alphabet; chain: typeof chain; checksum: typeof checksum; convertRadix: typeof convertRadix; convertRadix2: typeof convertRadix2; radix: typeof radix; radix2: typeof radix2; join: typeof join; padding: typeof padding; } = {\n alphabet, chain, checksum, convertRadix, convertRadix2, radix, radix2, join, padding,\n};\n\n// RFC 4648 aka RFC 3548\n// ---------------------\n\n/**\n * base16 encoding from RFC 4648.\n * @example\n * ```js\n * base16.encode(Uint8Array.from([0x12, 0xab]));\n * // => '12AB'\n * ```\n */\nexport const base16: BytesCoder = chain(radix2(4), alphabet('0123456789ABCDEF'), join(''));\n\n/**\n * base32 encoding from RFC 4648. Has padding.\n * Use `base32nopad` for unpadded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'CKVQ===='\n * base32.decode('CKVQ====');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32: BytesCoder = chain(\n radix2(5),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'),\n padding(5),\n join('')\n);\n\n/**\n * base32 encoding from RFC 4648. No padding.\n * Use `base32` for padded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'CKVQ'\n * base32nopad.decode('CKVQ');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32nopad: BytesCoder = chain(\n radix2(5),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'),\n join('')\n);\n/**\n * base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.\n * Use `base32hexnopad` for unpadded version.\n * @example\n * ```js\n * base32hex.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ALG===='\n * base32hex.decode('2ALG====');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hex: BytesCoder = chain(\n radix2(5),\n alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'),\n padding(5),\n join('')\n);\n\n/**\n * base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.\n * Use `base32hex` for padded version.\n * @example\n * ```js\n * base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ALG'\n * base32hexnopad.decode('2ALG');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hexnopad: BytesCoder = chain(\n radix2(5),\n alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'),\n join('')\n);\n/**\n * base32 encoding from RFC 4648. Doug Crockford's version.\n * https://www.crockford.com/base32.html\n * @example\n * ```js\n * base32crockford.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ANG'\n * base32crockford.decode('2ANG');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32crockford: BytesCoder = chain(\n radix2(5),\n alphabet('0123456789ABCDEFGHJKMNPQRSTVWXYZ'),\n join(''),\n normalize((s: string) => s.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1'))\n);\n\n// Built-in base64 conversion https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64\n// prettier-ignore\nconst hasBase64Builtin: boolean = /* @__PURE__ */ (() =>\n typeof (Uint8Array as any).from([]).toBase64 === 'function' &&\n typeof (Uint8Array as any).fromBase64 === 'function')();\n\nconst decodeBase64Builtin = (s: string, isUrl: boolean) => {\n astr('base64', s);\n const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;\n const alphabet = isUrl ? 'base64url' : 'base64';\n if (s.length > 0 && !re.test(s)) throw new Error('invalid base64');\n return (Uint8Array as any).fromBase64(s, { alphabet, lastChunkHandling: 'strict' });\n};\n\n/**\n * base64 from RFC 4648. Padded.\n * Use `base64nopad` for unpadded version.\n * Also check out `base64url`, `base64urlnopad`.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs='\n * base64.decode('Eqs=');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64: BytesCoder = hasBase64Builtin ? {\n encode(b) { abytes(b); return (b as any).toBase64(); },\n decode(s) { return decodeBase64Builtin(s, false); },\n} : chain(\n radix2(6),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),\n padding(6),\n join('')\n);\n/**\n * base64 from RFC 4648. No padding.\n * Use `base64` for padded version.\n * @example\n * ```js\n * base64nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs'\n * base64nopad.decode('Eqs');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64nopad: BytesCoder = chain(\n radix2(6),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),\n join('')\n);\n\n/**\n * base64 from RFC 4648, using URL-safe alphabet. Padded.\n * Use `base64urlnopad` for unpadded version.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64url.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs='\n * base64url.decode('Eqs=');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64url: BytesCoder = hasBase64Builtin ? {\n encode(b) { abytes(b); return (b as any).toBase64({ alphabet: 'base64url' }); },\n decode(s) { return decodeBase64Builtin(s, true); },\n} : chain(\n radix2(6),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),\n padding(6),\n join('')\n);\n\n/**\n * base64 from RFC 4648, using URL-safe alphabet. No padding.\n * Use `base64url` for padded version.\n * @example\n * ```js\n * base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs'\n * base64urlnopad.decode('Eqs');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64urlnopad: BytesCoder = chain(\n radix2(6),\n alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),\n join('')\n);\n\n// base58 code\n// -----------\nconst genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc: string) =>\n chain(radix(58), alphabet(abc), join(''));\n\n/**\n * base58: base64 without ambigous characters +, /, 0, O, I, l.\n * Quadratic (O(n^2)) - so, can't be used on large inputs.\n * @example\n * ```js\n * base58.decode('01abcdef');\n * // => '3UhJW'\n * ```\n */\nexport const base58: BytesCoder = genBase58(\n '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\n);\n/**\n * base58: flickr version. Check out `base58`.\n */\nexport const base58flickr: BytesCoder = genBase58(\n '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'\n);\n/**\n * base58: XRP version. Check out `base58`.\n */\nexport const base58xrp: BytesCoder = genBase58(\n 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz'\n);\n\n// Data len (index) -> encoded block len\nconst XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11];\n\n/**\n * base58: XMR version. Check out `base58`.\n * Done in 8-byte blocks (which equals 11 chars in decoding). Last (non-full) block padded with '1' to size in XMR_BLOCK_LEN.\n * Block encoding significantly reduces quadratic complexity of base58.\n */\nexport const base58xmr: BytesCoder = {\n encode(data: Uint8Array) {\n let res = '';\n for (let i = 0; i < data.length; i += 8) {\n const block = data.subarray(i, i + 8);\n res += base58.encode(block).padStart(XMR_BLOCK_LEN[block.length]!, '1');\n }\n return res;\n },\n decode(str: string) {\n let res: number[] = [];\n for (let i = 0; i < str.length; i += 11) {\n const slice = str.slice(i, i + 11);\n const blockLen = XMR_BLOCK_LEN.indexOf(slice.length);\n const block = base58.decode(slice);\n for (let j = 0; j < block.length - blockLen; j++) {\n if (block[j] !== 0) throw new Error('base58xmr: wrong padding');\n }\n res = res.concat(Array.from(block.slice(block.length - blockLen)));\n }\n return Uint8Array.from(res);\n },\n};\n\n/**\n * Method, which creates base58check encoder.\n * Requires function, calculating sha256.\n */\nexport const createBase58check = (sha256: (data: Uint8Array) => Uint8Array): BytesCoder =>\n chain(\n checksum(4, (data) => sha256(sha256(data))),\n base58\n );\n\n/**\n * Use `createBase58check` instead.\n * @deprecated\n */\nexport const base58check: (sha256: (data: Uint8Array) => Uint8Array) => BytesCoder =\n createBase58check;\n\n// Bech32 code\n// -----------\nexport interface Bech32Decoded<Prefix extends string = string> {\n prefix: Prefix;\n words: number[];\n}\nexport interface Bech32DecodedWithArray<Prefix extends string = string> {\n prefix: Prefix;\n words: number[];\n bytes: Uint8Array;\n}\n\nconst BECH_ALPHABET: Coder<number[], string> = chain(\n alphabet('qpzry9x8gf2tvdw0s3jn54khce6mua7l'),\n join('')\n);\n\nconst POLYMOD_GENERATORS = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];\nfunction bech32Polymod(pre: number): number {\n const b = pre >> 25;\n let chk = (pre & 0x1ffffff) << 5;\n for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {\n if (((b >> i) & 1) === 1) chk ^= POLYMOD_GENERATORS[i]!;\n }\n return chk;\n}\n\nfunction bechChecksum(prefix: string, words: number[], encodingConst = 1): string {\n const len = prefix.length;\n let chk = 1;\n for (let i = 0; i < len; i++) {\n const c = prefix.charCodeAt(i);\n if (c < 33 || c > 126) throw new Error(`Invalid prefix (${prefix})`);\n chk = bech32Polymod(chk) ^ (c >> 5);\n }\n chk = bech32Polymod(chk);\n for (let i = 0; i < len; i++) chk = bech32Polymod(chk) ^ (prefix.charCodeAt(i) & 0x1f);\n for (let v of words) chk = bech32Polymod(chk) ^ v;\n for (let i = 0; i < 6; i++) chk = bech32Polymod(chk);\n chk ^= encodingConst;\n return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]!], 30, 5, false));\n}\n\nexport interface Bech32 {\n encode<Prefix extends string>(\n prefix: Prefix,\n words: number[] | Uint8Array,\n limit?: number | false\n ): `${Lowercase<Prefix>}1${string}`;\n decode<Prefix extends string>(\n str: `${Prefix}1${string}`,\n limit?: number | false\n ): Bech32Decoded<Prefix>;\n encodeFromBytes(prefix: string, bytes: Uint8Array): string;\n decodeToBytes(str: string): Bech32DecodedWithArray;\n decodeUnsafe(str: string, limit?: number | false): void | Bech32Decoded<string>;\n fromWords(to: number[]): Uint8Array;\n fromWordsUnsafe(to: number[]): void | Uint8Array;\n toWords(from: Uint8Array): number[];\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction genBech32(encoding: 'bech32' | 'bech32m'): Bech32 {\n const ENCODING_CONST = encoding === 'bech32' ? 1 : 0x2bc830a3;\n const _words = radix2(5);\n const fromWords = _words.decode;\n const toWords = _words.encode;\n const fromWordsUnsafe = unsafeWrapper(fromWords);\n\n function encode<Prefix extends string>(\n prefix: Prefix,\n words: number[] | Uint8Array,\n limit: number | false = 90\n ): `${Lowercase<Prefix>}1${string}` {\n astr('bech32.encode prefix', prefix);\n if (isBytes(words)) words = Array.from(words);\n anumArr('bech32.encode', words);\n const plen = prefix.length;\n if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);\n const actualLength = plen + 7 + words.length;\n if (limit !== false && actualLength > limit)\n throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);\n const lowered = prefix.toLowerCase();\n const sum = bechChecksum(lowered, words, ENCODING_CONST);\n return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}` as `${Lowercase<Prefix>}1${string}`;\n }\n\n function decode<Prefix extends string>(\n str: `${Prefix}1${string}`,\n limit?: number | false\n ): Bech32Decoded<Prefix>;\n function decode(str: string, limit?: number | false): Bech32Decoded;\n function decode(str: string, limit: number | false = 90): Bech32Decoded {\n astr('bech32.decode input', str);\n const slen = str.length;\n if (slen < 8 || (limit !== false && slen > limit))\n throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);\n // don't allow mixed case\n const lowered = str.toLowerCase();\n if (str !== lowered && str !== str.toUpperCase())\n throw new Error(`String must be lowercase or uppercase`);\n const sepIndex = lowered.lastIndexOf('1');\n if (sepIndex === 0 || sepIndex === -1)\n throw new Error(`Letter \"1\" must be present between prefix and data only`);\n const prefix = lowered.slice(0, sepIndex);\n const data = lowered.slice(sepIndex + 1);\n if (data.length < 6) throw new Error('Data must be at least 6 characters long');\n const words = BECH_ALPHABET.decode(data).slice(0, -6);\n const sum = bechChecksum(prefix, words, ENCODING_CONST);\n if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str}: expected \"${sum}\"`);\n return { prefix, words };\n }\n\n const decodeUnsafe = unsafeWrapper(decode);\n\n function decodeToBytes(str: string): Bech32DecodedWithArray {\n const { prefix, words } = decode(str, false);\n return { prefix, words, bytes: fromWords(words) };\n }\n\n function encodeFromBytes(prefix: string, bytes: Uint8Array) {\n return encode(prefix, toWords(bytes));\n }\n\n return {\n encode,\n decode,\n encodeFromBytes,\n decodeToBytes,\n decodeUnsafe,\n fromWords,\n fromWordsUnsafe,\n toWords,\n };\n}\n\n/**\n * bech32 from BIP 173. Operates on words.\n * For high-level, check out scure-btc-signer:\n * https://github.com/paulmillr/scure-btc-signer.\n */\nexport const bech32: Bech32 = genBech32('bech32');\n\n/**\n * bech32m from BIP 350. Operates on words.\n * It was to mitigate `bech32` weaknesses.\n * For high-level, check out scure-btc-signer:\n * https://github.com/paulmillr/scure-btc-signer.\n */\nexport const bech32m: Bech32 = genBech32('bech32m');\n\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * UTF-8-to-byte decoder. Uses built-in TextDecoder / TextEncoder.\n * @example\n * ```js\n * const b = utf8.decode(\"hey\"); // => new Uint8Array([ 104, 101, 121 ])\n * const str = utf8.encode(b); // \"hey\"\n * ```\n */\nexport const utf8: BytesCoder = {\n encode: (data) => new TextDecoder().decode(data),\n decode: (str) => new TextEncoder().encode(str),\n};\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\n// prettier-ignore\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =>\n typeof (Uint8Array as any).from([]).toHex === 'function' &&\n typeof (Uint8Array as any).fromHex === 'function')();\n// prettier-ignore\nconst hexBuiltin: BytesCoder = {\n encode(data) { abytes(data); return (data as any).toHex(); },\n decode(s) { astr('hex', s); return (Uint8Array as any).fromHex(s); },\n};\n/**\n * hex string decoder. Uses built-in function, when available.\n * @example\n * ```js\n * const b = hex.decode(\"0102ff\"); // => new Uint8Array([ 1, 2, 255 ])\n * const str = hex.encode(b); // \"0102ff\"\n * ```\n */\nexport const hex: BytesCoder = hasHexBuiltin\n ? hexBuiltin\n : chain(\n radix2(4),\n alphabet('0123456789abcdef'),\n join(''),\n normalize((s: string) => {\n if (typeof s !== 'string' || s.length % 2 !== 0)\n throw new TypeError(\n `hex.decode: expected string, got ${typeof s} with length ${s.length}`\n );\n return s.toLowerCase();\n })\n );\n\nexport type SomeCoders = {\n utf8: BytesCoder;\n hex: BytesCoder;\n base16: BytesCoder;\n base32: BytesCoder;\n base64: BytesCoder;\n base64url: BytesCoder;\n base58: BytesCoder;\n base58xmr: BytesCoder;\n};\n// prettier-ignore\nconst CODERS: SomeCoders = {\n utf8, hex, base16, base32, base64, base64url, base58, base58xmr\n};\ntype CoderType = keyof SomeCoders;\nconst coderTypeError =\n 'Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr';\n\n/** @deprecated */\nexport const bytesToString = (type: CoderType, bytes: Uint8Array): string => {\n if (typeof type !== 'string' || !CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);\n if (!isBytes(bytes)) throw new TypeError('bytesToString() expects Uint8Array');\n return CODERS[type].encode(bytes);\n};\n\n/** @deprecated */\nexport const str: (type: CoderType, bytes: Uint8Array) => string = bytesToString; // as in python, but for bytes only\n\n/** @deprecated */\nexport const stringToBytes = (type: CoderType, str: string): Uint8Array => {\n if (!CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);\n if (typeof str !== 'string') throw new TypeError('stringToBytes() expects string');\n return CODERS[type].decode(str);\n};\n/** @deprecated */\nexport const bytes: (type: CoderType, str: string) => Uint8Array = stringToBytes;\n","import type { Struct } from '@metamask/superstruct';\nimport { assert as assertSuperstruct } from '@metamask/superstruct';\n\nimport { getErrorMessage } from './errors';\n\nexport type AssertionErrorConstructor =\n | (new (args: { message: string }) => Error)\n | ((args: { message: string }) => Error);\n\n/**\n * Check if a value is a constructor, i.e., a function that can be called with\n * the `new` keyword.\n *\n * @param fn - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nfunction isConstructable(\n fn: AssertionErrorConstructor,\n): fn is new (args: { message: string }) => Error {\n /* istanbul ignore next */\n return Boolean(typeof fn?.prototype?.constructor?.name === 'string');\n}\n\n/**\n * Attempts to obtain the message from a possible error object. If it is\n * possible to do so, any trailing period will be removed from the message;\n * otherwise an empty string is returned.\n *\n * @param error - The error object to get the message from.\n * @returns The message without any trailing period if `error` is an object\n * with a `message` property; the string version of `error` without any trailing\n * period if it is not `undefined` or `null`; otherwise an empty string.\n */\nfunction getErrorMessageWithoutTrailingPeriod(error: unknown): string {\n // We'll add our own period.\n return getErrorMessage(error).replace(/\\.$/u, '');\n}\n\n/**\n * Initialise an {@link AssertionErrorConstructor} error.\n *\n * @param ErrorWrapper - The error class to use.\n * @param message - The error message.\n * @returns The error object.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction getError(ErrorWrapper: AssertionErrorConstructor, message: string) {\n if (isConstructable(ErrorWrapper)) {\n return new ErrorWrapper({\n message,\n });\n }\n return ErrorWrapper({\n message,\n });\n}\n\n/**\n * The default error class that is thrown if an assertion fails.\n */\nexport class AssertionError extends Error {\n readonly code = 'ERR_ASSERTION';\n\n constructor(options: { message: string }) {\n super(options.message);\n }\n}\n\n/**\n * Same as Node.js assert.\n * If the value is falsy, throws an error, does nothing otherwise.\n *\n * @throws {@link AssertionError} If value is falsy.\n * @param value - The test that should be truthy to pass.\n * @param message - Message to be passed to {@link AssertionError} or an\n * {@link Error} instance to throw.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}. If a custom error class is provided for\n * the `message` argument, this argument is ignored.\n */\nexport function assert(\n value: any,\n message: string | Error = 'Assertion failed.',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value {\n if (!value) {\n if (message instanceof Error) {\n throw message;\n }\n\n throw getError(ErrorWrapper, message);\n }\n}\n\n/**\n * Assert a value against a Superstruct struct.\n *\n * @param value - The value to validate.\n * @param struct - The struct to validate against.\n * @param errorPrefix - A prefix to add to the error message. Defaults to\n * \"Assertion failed\".\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the value is not valid.\n */\nexport function assertStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n errorPrefix = 'Assertion failed',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value is Type {\n try {\n assertSuperstruct(value, struct);\n } catch (error) {\n throw getError(\n ErrorWrapper,\n `${errorPrefix}: ${getErrorMessageWithoutTrailingPeriod(error)}.`,\n );\n }\n}\n\n/**\n * Use in the default case of a switch that you want to be fully exhaustive.\n * Using this function forces the compiler to enforce exhaustivity during\n * compile-time.\n *\n * @example\n * ```\n * const number = 1;\n * switch (number) {\n * case 0:\n * ...\n * case 1:\n * ...\n * default:\n * assertExhaustive(snapPrefix);\n * }\n * ```\n * @param _object - The object on which the switch is being operated.\n */\nexport function assertExhaustive(_object: never): never {\n throw new Error(\n 'Invalid branch reached. Should be detected during compilation.',\n );\n}\n","import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n","// src/client.ts\nimport {\n BaseClient,\n ClientState as ClientState3,\n DEFAULT_SESSION_TTL,\n ErrorCode as ErrorCode3,\n isValidConnectionMode,\n SessionError as SessionError3\n} from \"@metamask/mobile-wallet-protocol-core\";\nimport { bytesToBase64 } from \"@metamask/utils\";\nimport { v4 as uuid } from \"uuid\";\n\n// src/handlers/trusted-connection-handler.ts\nimport { ClientState, ErrorCode, SessionError } from \"@metamask/mobile-wallet-protocol-core\";\nimport { base64ToBytes } from \"@metamask/utils\";\nvar TrustedConnectionHandler = class {\n context;\n constructor(context) {\n this.context = context;\n }\n /**\n * Executes the complete trusted connection flow.\n * This method is fully self-contained and handles the connection process.\n */\n async execute(session, request) {\n await this.context.transport.connect();\n await this.context.transport.subscribe(request.channel);\n const offer = await this._waitForHandshakeOffer(request.expiresAt);\n const finalSession = this._createFinalSession(session, offer);\n this.context.session = finalSession;\n await this._finalizeConnection(finalSession, request);\n }\n /**\n * Waits for a `handshake-offer` message from the wallet.\n *\n * This method uses a dual-timeout strategy. The total wait time is the sum of the\n * `SessionRequest` TTL (the time the user has to scan the QR code) and the\n * `HANDSHAKE_TIMEOUT` (a grace period for the dApp to resume from suspension\n * and process the historical message from the relay).\n *\n * @param requestExpiry - The timestamp when the session request expires.\n * @returns A promise that resolves with the `HandshakeOfferPayload`.\n * @throws {SessionError} If the offer is not received before the combined timeout expires.\n */\n _waitForHandshakeOffer(requestExpiry) {\n return new Promise((resolve, reject) => {\n if (requestExpiry < Date.now()) {\n return reject(new SessionError(ErrorCode.REQUEST_EXPIRED, \"Session request expired before wallet could connect\"));\n }\n const timeoutDuration = requestExpiry + HANDSHAKE_TIMEOUT - Date.now();\n const timeoutId = setTimeout(() => {\n this.context.off(\"handshake_offer_received\", onOfferReceived);\n reject(new SessionError(ErrorCode.REQUEST_EXPIRED, \"Did not receive handshake offer from wallet in time.\"));\n }, timeoutDuration);\n const onOfferReceived = (payload) => {\n clearTimeout(timeoutId);\n resolve(payload);\n };\n this.context.once(\"handshake_offer_received\", onOfferReceived);\n });\n }\n /**\n * Creates the final session object with details from the wallet's offer.\n *\n * @param session - The pending session object (with temporary values)\n * @param offer - The handshake offer payload from the wallet\n * @returns The complete session object ready for use\n */\n _createFinalSession(session, offer) {\n const theirPublicKey = base64ToBytes(offer.publicKeyB64);\n this.context.keymanager.validatePeerKey(theirPublicKey);\n return {\n ...session,\n channel: `session:${offer.channelId}`,\n theirPublicKey\n };\n }\n /**\n * Completes the connection by persisting the session, cleaning up the\n * temporary handshake channel, and transitioning to the `CONNECTED` state.\n *\n * @param session - The finalized session object\n * @param request - The session request object\n */\n async _finalizeConnection(session, request) {\n if (!this.context.session) throw new SessionError(ErrorCode.SESSION_INVALID_STATE);\n await this.context.sessionstore.set(this.context.session);\n await this.context.transport.subscribe(session.channel);\n await this.context.transport.clear(request.channel);\n this.context.state = ClientState.CONNECTED;\n this.context.emit(\"connected\");\n }\n};\n\n// src/handlers/untrusted-connection-handler.ts\nimport { ClientState as ClientState2, ErrorCode as ErrorCode2, SessionError as SessionError2, timingSafeEqual } from \"@metamask/mobile-wallet-protocol-core\";\nimport { base64ToBytes as base64ToBytes2 } from \"@metamask/utils\";\nvar UntrustedConnectionHandler = class {\n context;\n otpAttempts = 3;\n timeoutId = null;\n constructor(context) {\n this.context = context;\n }\n /**\n * Executes the complete untrusted connection flow.\n * This method is fully self-contained and handles the entire OTP-based connection process.\n */\n async execute(session, request) {\n await this.context.transport.connect();\n await this.context.transport.subscribe(request.channel);\n const offer = await this._waitForHandshakeOffer(request.expiresAt);\n await this._handleOtpInput(offer);\n const finalSession = this._createFinalSession(session, offer);\n this.context.session = finalSession;\n await this._acknowledgeHandshake(finalSession);\n await this._finalizeConnection(request.channel);\n }\n /**\n * Waits for a `handshake-offer` message from the wallet on the handshake channel.\n *\n * @param requestExpiry - The timestamp when the session request expires\n * @returns A promise that resolves with the `HandshakeOfferPayload`\n * @throws {SessionError} If the offer is not received before the request expires\n */\n _waitForHandshakeOffer(requestExpiry) {\n return new Promise((resolve, reject) => {\n const timeoutDuration = requestExpiry - Date.now();\n if (timeoutDuration <= 0) {\n return reject(new SessionError2(ErrorCode2.REQUEST_EXPIRED, \"Session request expired before wallet could connect.\"));\n }\n this.timeoutId = setTimeout(() => {\n this.context.off(\"handshake_offer_received\", onOfferReceived);\n reject(new SessionError2(ErrorCode2.REQUEST_EXPIRED, \"Did not receive handshake offer from wallet in time.\"));\n }, timeoutDuration);\n const onOfferReceived = (payload) => {\n if (this.timeoutId) clearTimeout(this.timeoutId);\n this.timeoutId = null;\n resolve(payload);\n };\n this.context.once(\"handshake_offer_received\", onOfferReceived);\n });\n }\n /**\n * Manages the OTP verification step by emitting the `otp_required` event and\n * waiting for the user to submit the correct OTP.\n *\n * @param offer - The handshake offer from the wallet containing the OTP\n * @throws {SessionError} If the OTP is incorrect after max attempts, the OTP expires,\n * or the user cancels\n */\n _handleOtpInput(offer) {\n return new Promise((resolve, reject) => {\n if (!offer.deadline || !offer.otp) {\n return reject(new SessionError2(ErrorCode2.UNKNOWN, \"Handshake offer is missing OTP details for untrusted connection.\"));\n }\n if (Date.now() > offer.deadline) {\n return reject(new SessionError2(ErrorCode2.OTP_ENTRY_TIMEOUT, \"The OTP has already expired.\"));\n }\n const expectedOtp = offer.otp;\n let attempts = 0;\n const submit = async (otp) => {\n if (!timingSafeEqual(otp, expectedOtp)) {\n attempts++;\n if (attempts >= this.otpAttempts) {\n reject(new SessionError2(ErrorCode2.OTP_MAX_ATTEMPTS_REACHED, \"Maximum OTP attempts reached.\"));\n } else {\n throw new SessionError2(ErrorCode2.OTP_INCORRECT, `Incorrect OTP. ${this.otpAttempts - attempts} attempts remaining.`);\n }\n return;\n }\n resolve();\n };\n const cancel = () => reject(new Error(\"User cancelled OTP entry.\"));\n this.context.emit(\"otp_required\", { submit, cancel, deadline: offer.deadline });\n });\n }\n /**\n * Creates the final session object with details from the wallet's offer.\n *\n * @param session - The pending session object (with temporary values)\n * @param offer - The handshake offer payload from the wallet\n * @returns The complete session object ready for use\n */\n _createFinalSession(session, offer) {\n const theirPublicKey = base64ToBytes2(offer.publicKeyB64);\n this.context.keymanager.validatePeerKey(theirPublicKey);\n return {\n ...session,\n channel: `session:${offer.channelId}`,\n theirPublicKey\n };\n }\n /**\n * Subscribes to the secure session channel and sends handshake acknowledgment.\n *\n * @param session - The finalized session object\n */\n async _acknowledgeHandshake(session) {\n await this.context.transport.subscribe(session.channel);\n await this.context.sendMessage(session.channel, { type: \"handshake-ack\" });\n }\n /**\n * Completes the connection by persisting the session, cleaning up the\n * temporary handshake channel, and transitioning to the `CONNECTED` state.\n *\n * @param handshakeChannel - The temporary channel used for the initial handshake\n */\n async _finalizeConnection(handshakeChannel) {\n if (!this.context.session) throw new SessionError2(ErrorCode2.SESSION_INVALID_STATE);\n await this.context.sessionstore.set(this.context.session);\n await this.context.transport.clear(handshakeChannel);\n this.context.state = ClientState2.CONNECTED;\n this.context.emit(\"connected\");\n }\n};\n\n// src/client.ts\nvar SESSION_REQUEST_TTL = 60 * 1e3;\nvar HANDSHAKE_TIMEOUT = 60 * 1e3;\nvar DappClient = class extends BaseClient {\n // biome-ignore lint/suspicious/noExplicitAny: used for event emitter\n on(event, listener) {\n return super.on(event, listener);\n }\n constructor(options) {\n super(options.transport, options.keymanager, options.sessionstore);\n }\n /**\n * Initiates a new session with a wallet. The process differs based on the connection mode:\n *\n * **Trusted Mode** (same-device/trusted context):\n * 1. Emits a `session_request` event\n * 2. Waits for wallet handshake offer\n * 3. Automatically finalizes secure session\n *\n * **Untrusted Mode** (high-security):\n * 1. Emits a `session_request` event\n * 2. Waits for wallet handshake offer with OTP\n * 3. Emits `otp_required` event for user verification\n * 4. Finalizes secure, encrypted session after OTP validation\n *\n * @param options - Connection options including the desired mode\n * @returns A promise that resolves when the session is successfully established\n * @throws {SessionError} If the client is not in a `DISCONNECTED` state or if the\n * connection process fails\n */\n async connect(options = {}) {\n if (this.state !== ClientState3.DISCONNECTED) throw new SessionError3(ErrorCode3.SESSION_INVALID_STATE, `Cannot connect when state is ${this.state}`);\n const { mode = \"untrusted\", initialPayload } = options;\n if (!isValidConnectionMode(mode)) throw new SessionError3(ErrorCode3.SESSION_INVALID_STATE, `Invalid connection mode: \"${String(mode)}\"`);\n this.state = ClientState3.CONNECTING;\n const { pendingSession, request } = this._createPendingSessionAndRequest(mode, initialPayload);\n this.session = pendingSession;\n this.emit(\"session_request\", request);\n const self = this;\n const context = {\n transport: this.transport,\n sessionstore: this.sessionstore,\n keymanager: this.keymanager,\n get session() {\n return self.session;\n },\n set session(session) {\n self.session = session;\n },\n get state() {\n return self.state;\n },\n set state(state) {\n self.state = state;\n },\n emit: this.emit.bind(this),\n once: this.once.bind(this),\n off: this.off.bind(this),\n sendMessage: this.sendMessage.bind(this)\n };\n const handler = mode === \"trusted\" ? new TrustedConnectionHandler(context) : new UntrustedConnectionHandler(context);\n try {\n await handler.execute(pendingSession, request);\n } catch (error) {\n this.emit(\"error\", error);\n await this.disconnect();\n throw error;\n }\n }\n /**\n * Sends a request payload to the connected wallet.\n *\n * @param payload - The request payload to send to the wallet\n * @throws {SessionError} If the client is not in a `CONNECTED` state\n */\n async sendRequest(payload) {\n if (this.state !== ClientState3.CONNECTED || !this.session) throw new SessionError3(ErrorCode3.SESSION_INVALID_STATE, \"Cannot send request: not connected.\");\n await this.sendMessage(this.session.channel, { type: \"message\", payload });\n }\n /**\n * Routes incoming messages based on the client's connection state.\n * During connection, it handles handshake messages. Once connected, it\n * handles standard application messages.\n *\n * @param message - The incoming message to handle\n */\n handleMessage(message) {\n if (this.state === ClientState3.CONNECTING && message.type === \"handshake-offer\") {\n this.emit(\"handshake_offer_received\", message.payload);\n } else if (this.state === ClientState3.CONNECTED && message.type === \"message\") {\n this.emit(\"message\", message.payload);\n }\n }\n /**\n * Creates a temporary session object and the corresponding `SessionRequest`\n * payload to be shared with the wallet.\n *\n * @param mode - The connection mode to use for this session\n * @returns An object containing the pending session and session request\n */\n _createPendingSessionAndRequest(mode, initialPayload) {\n const id = uuid();\n const keyPair = this.keymanager.generateKeyPair();\n const pendingSession = {\n id,\n channel: \"\",\n // To be determined by the wallet's handshake offer\n keyPair,\n theirPublicKey: new Uint8Array(0),\n // Placeholder, will be updated\n expiresAt: Date.now() + DEFAULT_SESSION_TTL\n };\n const message = initialPayload ? { type: \"message\", payload: initialPayload } : void 0;\n const request = {\n id,\n mode,\n channel: `handshake:${id}`,\n publicKeyB64: bytesToBase64(keyPair.publicKey),\n expiresAt: Date.now() + SESSION_REQUEST_TTL,\n initialMessage: message\n };\n return { pendingSession, request };\n }\n};\nexport {\n DappClient\n};\n"],"names":["isBytes","a","Uint8Array","ArrayBuffer","isView","constructor","name","abytes","b","Error","_len","arguments","length","lengths","Array","_key","includes","isArrayOf","isString","arr","isArray","every","item","Number","isSafeInteger","afn","input","astr","label","concat","anumber","n","aArr","astrArr","anumArr","chain","id","wrap","c","_len2","args","_key2","encode","map","x","reduceRight","decode","reduce","alphabet","letters","lettersA","split","len","indexes","Map","l","i","digits","letter","get","undefined","join","separator","from","to","padding","bits","chr","data","push","end","slice","normalize","fn","convertRadix","pos","res","d","dlen","carry","done","digit","fromCarry","digitBase","div","rounded","Math","floor","reverse","gcd","radix2carry","powers","convertRadix2","max","mask","pow","radix","num","bytes","radix2","revPadding","unsafeWrapper","_len3","_key3","apply","e","base16","base32","hasBase64Builtin","s","toUpperCase","replace","toBase64","fromBase64","decodeBase64Builtin","isUrl","re","test","lastChunkHandling","base64","base64url","genBase58","abc","base58","XMR_BLOCK_LEN","base58xmr","block","subarray","padStart","str","blockLen","indexOf","j","BECH_ALPHABET","POLYMOD_GENERATORS","bech32Polymod","pre","chk","bechChecksum","prefix","words","encodingConst","charCodeAt","v","genBech32","encoding","ENCODING_CONST","_words","fromWords","toWords","fromWordsUnsafe","limit","plen","TypeError","actualLength","lowered","toLowerCase","sum","slen","sepIndex","lastIndexOf","endsWith","encodeFromBytes","decodeToBytes","decodeUnsafe","utf8","TextDecoder","TextEncoder","toHex","fromHex","getError","ErrorWrapper","message","_fn$prototype","Boolean","prototype","isConstructable","AssertionError","options","super","code","assert","value","lookupTable","getPrecomputedHexValuesBuilder","assertIsBytes","bytesToBase64","base64ToBytes","TrustedConnectionHandler","context","_defineProperty","this","execute","session","request","transport","connect","subscribe","channel","offer","_waitForHandshakeOffer","expiresAt","finalSession","_createFinalSession","_finalizeConnection","requestExpiry","Promise","resolve","reject","Date","now","SessionError","ErrorCode","REQUEST_EXPIRED","timeoutDuration","HANDSHAKE_TIMEOUT","timeoutId","setTimeout","off","onOfferReceived","payload","clearTimeout","once","theirPublicKey","publicKeyB64","keymanager","validatePeerKey","_objectSpread","channelId","SESSION_INVALID_STATE","sessionstore","set","clear","state","ClientState","CONNECTED","emit","UntrustedConnectionHandler","_handleOtpInput","_acknowledgeHandshake","SessionError2","ErrorCode2","deadline","otp","UNKNOWN","OTP_ENTRY_TIMEOUT","expectedOtp","attempts","submit","async","timingSafeEqual","otpAttempts","OTP_INCORRECT","OTP_MAX_ATTEMPTS_REACHED","cancel","base64ToBytes2","sendMessage","type","handshakeChannel","ClientState2","DappClient","BaseClient","on","event","listener","ClientState3","DISCONNECTED","SessionError3","ErrorCode3","mode","initialPayload","isValidConnectionMode","String","CONNECTING","pendingSession","_createPendingSessionAndRequest","self","bind","handler","error","disconnect","sendRequest","handleMessage","uuid","keyPair","generateKeyPair","DEFAULT_SESSION_TTL","publicKey","initialMessage"],"sourceRoot":""}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! For license information please see 288.51cc5192.chunk.js.LICENSE.txt */
|
|
2
|
+
"use strict";(self.webpackChunk_metamask_browser_playground=self.webpackChunk_metamask_browser_playground||[]).push([[288],{1586:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(4710),e),o(n(5288),e),o(n(2115),e),o(n(7337),e)},2115:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.decodeHex=e.remove0x=void 0;var r=n(4314);e.remove0x=function(t){return t.startsWith("0x")||t.startsWith("0X")?t.slice(2):t};e.decodeHex=function(t){return(0,r.hexToBytes)((0,e.remove0x)(t))}},2338:(t,e,n)=>{n.r(e),n.d(e,{aeskw:()=>$,aeskwp:()=>et,cbc:()=>F,cfb:()=>D,ctr:()=>N,ecb:()=>j,gcm:()=>R,gcmsiv:()=>Y,siv:()=>Z,unsafe:()=>nt});var r=n(4314);const o=16,s=new Uint8Array(16),i=(0,r.u32)(s),c=(t,e,n,r)=>({s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^225<<24&-(1&(1&r))}),u=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255;class a{constructor(t,e){this.blockLen=o,this.outputLen=o,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,t=(0,r.toBytes)(t),(0,r.abytes)(t,16);const n=(0,r.createView)(t);let s=n.getUint32(0,!1),i=n.getUint32(4,!1),a=n.getUint32(8,!1),l=n.getUint32(12,!1);const h=[];for(let r=0;r<128;r++)h.push({s0:u(s),s1:u(i),s2:u(a),s3:u(l)}),({s0:s,s1:i,s2:a,s3:l}=c(s,i,a,l));const y=(f=e||1024)>65536?8:f>1024?4:2;var f;if(![1,2,4,8].includes(y))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=y;const p=128/y,d=this.windowSize=2**y,g=[];for(let r=0;r<p;r++)for(let t=0;t<d;t++){let e=0,n=0,o=0,s=0;for(let i=0;i<y;i++){if(!(t>>>y-i-1&1))continue;const{s0:c,s1:u,s2:a,s3:l}=h[y*r+i];e^=c,n^=u,o^=a,s^=l}g.push({s0:e,s1:n,s2:o,s3:s})}this.t=g}_updateBlock(t,e,n,r){t^=this.s0,e^=this.s1,n^=this.s2,r^=this.s3;const{W:o,t:s,windowSize:i}=this;let c=0,u=0,a=0,l=0;const h=(1<<o)-1;let y=0;for(const f of[t,e,n,r])for(let t=0;t<4;t++){const e=f>>>8*t&255;for(let t=8/o-1;t>=0;t--){const n=e>>>o*t&h,{s0:r,s1:f,s2:p,s3:d}=s[y*i+n];c^=r,u^=f,a^=p,l^=d,y+=1}}this.s0=c,this.s1=u,this.s2=a,this.s3=l}update(t){(0,r.aexists)(this),t=(0,r.toBytes)(t),(0,r.abytes)(t);const e=(0,r.u32)(t),n=Math.floor(t.length/o),c=t.length%o;for(let r=0;r<n;r++)this._updateBlock(e[4*r+0],e[4*r+1],e[4*r+2],e[4*r+3]);return c&&(s.set(t.subarray(n*o)),this._updateBlock(i[0],i[1],i[2],i[3]),(0,r.clean)(i)),this}destroy(){const{t:t}=this;for(const e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){(0,r.aexists)(this),(0,r.aoutput)(t,this),this.finished=!0;const{s0:e,s1:n,s2:o,s3:s}=this,i=(0,r.u32)(t);return i[0]=e,i[1]=n,i[2]=o,i[3]=s,t}digest(){const t=new Uint8Array(o);return this.digestInto(t),this.destroy(),t}}class l extends a{constructor(t,e){t=(0,r.toBytes)(t),(0,r.abytes)(t);const n=function(t){t.reverse();const e=1&t[15];let n=0;for(let r=0;r<t.length;r++){const e=t[r];t[r]=e>>>1|n,n=(1&e)<<7}return t[0]^=225&-e,t}((0,r.copyBytes)(t));super(n,e),(0,r.clean)(n)}update(t){t=(0,r.toBytes)(t),(0,r.aexists)(this);const e=(0,r.u32)(t),n=t.length%o,c=Math.floor(t.length/o);for(let r=0;r<c;r++)this._updateBlock(u(e[4*r+3]),u(e[4*r+2]),u(e[4*r+1]),u(e[4*r+0]));return n&&(s.set(t.subarray(c*o)),this._updateBlock(u(i[3]),u(i[2]),u(i[1]),u(i[0])),(0,r.clean)(i)),this}digestInto(t){(0,r.aexists)(this),(0,r.aoutput)(t,this),this.finished=!0;const{s0:e,s1:n,s2:o,s3:s}=this,i=(0,r.u32)(t);return i[0]=e,i[1]=n,i[2]=o,i[3]=s,t.reverse()}}function h(t){const e=(e,n)=>t(n,e.length).update((0,r.toBytes)(e)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(e,n)=>t(e,n),e}const y=h((t,e)=>new a(t,e)),f=h((t,e)=>new l(t,e)),p=16,d=new Uint8Array(p);function g(t){return t<<1^283&-(t>>7)}function b(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(1&e),t=g(t);return n}const w=(()=>{const t=new Uint8Array(256);for(let n=0,r=1;n<256;n++,r^=g(r))t[n]=r;const e=new Uint8Array(256);e[0]=99;for(let n=0;n<255;n++){let r=t[255-n];r|=r<<8,e[t[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return(0,r.clean)(t),e})(),E=w.map((t,e)=>w.indexOf(e)),m=t=>t<<24|t>>>8,v=t=>t<<8|t>>>24,_=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;function A(t,e){if(256!==t.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>e(t[r])),r=n.map(v),o=r.map(v),s=o.map(v),i=new Uint32Array(65536),c=new Uint32Array(65536),u=new Uint16Array(65536);for(let a=0;a<256;a++)for(let e=0;e<256;e++){const l=256*a+e;i[l]=n[a]^r[e],c[l]=o[a]^s[e],u[l]=t[a]<<8|t[e]}return{sbox:t,sbox2:u,T0:n,T1:r,T2:o,T3:s,T01:i,T23:c}}const x=A(w,t=>b(t,3)<<24|t<<16|t<<8|b(t,2)),C=A(E,t=>b(t,11)<<24|b(t,13)<<16|b(t,9)<<8|b(t,14)),B=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=g(n))t[e]=n;return t})();function K(t){(0,r.abytes)(t);const e=t.length;if(![16,24,32].includes(e))throw new Error("aes: invalid key size, should be 16, 24 or 32, got "+e);const{sbox2:n}=x,o=[];(0,r.isAligned32)(t)||o.push(t=(0,r.copyBytes)(t));const s=(0,r.u32)(t),i=s.length,c=t=>P(n,t,t,t,t),u=new Uint32Array(e+28);u.set(s);for(let r=i;r<u.length;r++){let t=u[r-1];r%i===0?t=c(m(t))^B[r/i-1]:i>6&&r%i===4&&(t=c(t)),u[r]=u[r-i]^t}return(0,r.clean)(...o),u}function U(t){const e=K(t),n=e.slice(),o=e.length,{sbox2:s}=x,{T0:i,T1:c,T2:u,T3:a}=C;for(let r=0;r<o;r+=4)for(let t=0;t<4;t++)n[r+t]=e[o-r-4+t];(0,r.clean)(e);for(let r=4;r<o-4;r++){const t=n[r],e=P(s,t,t,t,t);n[r]=i[255&e]^c[e>>>8&255]^u[e>>>16&255]^a[e>>>24]}return n}function S(t,e,n,r,o,s){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|s>>>24&255]}function P(t,e,n,r,o){return t[255&e|65280&n]|t[r>>>16&255|o>>>16&65280]<<16}function L(t,e,n,r,o){const{sbox2:s,T01:i,T23:c}=x;let u=0;e^=t[u++],n^=t[u++],r^=t[u++],o^=t[u++];const a=t.length/4-2;for(let l=0;l<a;l++){const s=t[u++]^S(i,c,e,n,r,o),a=t[u++]^S(i,c,n,r,o,e),l=t[u++]^S(i,c,r,o,e,n),h=t[u++]^S(i,c,o,e,n,r);e=s,n=a,r=l,o=h}return{s0:t[u++]^P(s,e,n,r,o),s1:t[u++]^P(s,n,r,o,e),s2:t[u++]^P(s,r,o,e,n),s3:t[u++]^P(s,o,e,n,r)}}function O(t,e,n,r,o){const{sbox2:s,T01:i,T23:c}=C;let u=0;e^=t[u++],n^=t[u++],r^=t[u++],o^=t[u++];const a=t.length/4-2;for(let l=0;l<a;l++){const s=t[u++]^S(i,c,e,o,r,n),a=t[u++]^S(i,c,n,e,o,r),l=t[u++]^S(i,c,r,n,e,o),h=t[u++]^S(i,c,o,r,n,e);e=s,n=a,r=l,o=h}return{s0:t[u++]^P(s,e,o,r,n),s1:t[u++]^P(s,n,e,o,r),s2:t[u++]^P(s,r,n,e,o),s3:t[u++]^P(s,o,r,n,e)}}function I(t,e,n,o){(0,r.abytes)(e,p),(0,r.abytes)(n);const s=n.length;o=(0,r.getOutput)(s,o),(0,r.complexOverlapBytes)(n,o);const i=e,c=(0,r.u32)(i);let{s0:u,s1:a,s2:l,s3:h}=L(t,c[0],c[1],c[2],c[3]);const y=(0,r.u32)(n),f=(0,r.u32)(o);for(let r=0;r+4<=y.length;r+=4){f[r+0]=y[r+0]^u,f[r+1]=y[r+1]^a,f[r+2]=y[r+2]^l,f[r+3]=y[r+3]^h;let e=1;for(let t=i.length-1;t>=0;t--)e=e+(255&i[t])|0,i[t]=255&e,e>>>=8;({s0:u,s1:a,s2:l,s3:h}=L(t,c[0],c[1],c[2],c[3]))}const d=p*Math.floor(y.length/4);if(d<s){const t=new Uint32Array([u,a,l,h]),e=(0,r.u8)(t);for(let r=d,i=0;r<s;r++,i++)o[r]=n[r]^e[i];(0,r.clean)(t)}return o}function k(t,e,n,o,s){(0,r.abytes)(n,p),(0,r.abytes)(o),s=(0,r.getOutput)(o.length,s);const i=n,c=(0,r.u32)(i),u=(0,r.createView)(i),a=(0,r.u32)(o),l=(0,r.u32)(s),h=e?0:12,y=o.length;let f=u.getUint32(h,e),{s0:d,s1:g,s2:b,s3:w}=L(t,c[0],c[1],c[2],c[3]);for(let r=0;r+4<=a.length;r+=4)l[r+0]=a[r+0]^d,l[r+1]=a[r+1]^g,l[r+2]=a[r+2]^b,l[r+3]=a[r+3]^w,f=f+1>>>0,u.setUint32(h,f,e),({s0:d,s1:g,s2:b,s3:w}=L(t,c[0],c[1],c[2],c[3]));const E=p*Math.floor(a.length/4);if(E<y){const t=new Uint32Array([d,g,b,w]),e=(0,r.u8)(t);for(let n=E,r=0;n<y;n++,r++)s[n]=o[n]^e[r];(0,r.clean)(t)}return s}const N=(0,r.wrapCipher)({blockSize:16,nonceLength:16},function(t,e){function n(n,o){if((0,r.abytes)(n),void 0!==o&&((0,r.abytes)(o),!(0,r.isAligned32)(o)))throw new Error("unaligned destination");const s=K(t),i=(0,r.copyBytes)(e),c=[s,i];(0,r.isAligned32)(n)||c.push(n=(0,r.copyBytes)(n));const u=I(s,i,n,o);return(0,r.clean)(...c),u}return{encrypt:(t,e)=>n(t,e),decrypt:(t,e)=>n(t,e)}});function T(t){if((0,r.abytes)(t),t.length%p!==0)throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size 16")}function H(t,e,n){(0,r.abytes)(t);let o=t.length;const s=o%p;if(!e&&0!==s)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");(0,r.isAligned32)(t)||(t=(0,r.copyBytes)(t));const i=(0,r.u32)(t);if(e){let t=p-s;t||(t=p),o+=t}n=(0,r.getOutput)(o,n),(0,r.complexOverlapBytes)(t,n);return{b:i,o:(0,r.u32)(n),out:n}}function M(t,e){if(!e)return t;const n=t.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=t[n-1];if(r<=0||r>16)throw new Error("aes/pcks5: wrong padding");const o=t.subarray(0,-r);for(let s=0;s<r;s++)if(t[n-s-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}function G(t){const e=new Uint8Array(16),n=(0,r.u32)(e);e.set(t);const o=p-t.length;for(let r=p-o;r<p;r++)e[r]=o;return n}const j=(0,r.wrapCipher)({blockSize:16},function(t){const e=!(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).disablePadding;return{encrypt(n,o){const{b:s,o:i,out:c}=H(n,e,o),u=K(t);let a=0;for(;a+4<=s.length;){const{s0:t,s1:e,s2:n,s3:r}=L(u,s[a+0],s[a+1],s[a+2],s[a+3]);i[a++]=t,i[a++]=e,i[a++]=n,i[a++]=r}if(e){const t=G(n.subarray(4*a)),{s0:e,s1:r,s2:o,s3:s}=L(u,t[0],t[1],t[2],t[3]);i[a++]=e,i[a++]=r,i[a++]=o,i[a++]=s}return(0,r.clean)(u),c},decrypt(n,o){T(n);const s=U(t);o=(0,r.getOutput)(n.length,o);const i=[s];(0,r.isAligned32)(n)||i.push(n=(0,r.copyBytes)(n)),(0,r.complexOverlapBytes)(n,o);const c=(0,r.u32)(n),u=(0,r.u32)(o);for(let t=0;t+4<=c.length;){const{s0:e,s1:n,s2:r,s3:o}=O(s,c[t+0],c[t+1],c[t+2],c[t+3]);u[t++]=e,u[t++]=n,u[t++]=r,u[t++]=o}return(0,r.clean)(...i),M(o,e)}}}),F=(0,r.wrapCipher)({blockSize:16,nonceLength:16},function(t,e){const n=!(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).disablePadding;return{encrypt(o,s){const i=K(t),{b:c,o:u,out:a}=H(o,n,s);let l=e;const h=[i];(0,r.isAligned32)(l)||h.push(l=(0,r.copyBytes)(l));const y=(0,r.u32)(l);let f=y[0],p=y[1],d=y[2],g=y[3],b=0;for(;b+4<=c.length;)f^=c[b+0],p^=c[b+1],d^=c[b+2],g^=c[b+3],({s0:f,s1:p,s2:d,s3:g}=L(i,f,p,d,g)),u[b++]=f,u[b++]=p,u[b++]=d,u[b++]=g;if(n){const t=G(o.subarray(4*b));f^=t[0],p^=t[1],d^=t[2],g^=t[3],({s0:f,s1:p,s2:d,s3:g}=L(i,f,p,d,g)),u[b++]=f,u[b++]=p,u[b++]=d,u[b++]=g}return(0,r.clean)(...h),a},decrypt(o,s){T(o);const i=U(t);let c=e;const u=[i];(0,r.isAligned32)(c)||u.push(c=(0,r.copyBytes)(c));const a=(0,r.u32)(c);s=(0,r.getOutput)(o.length,s),(0,r.isAligned32)(o)||u.push(o=(0,r.copyBytes)(o)),(0,r.complexOverlapBytes)(o,s);const l=(0,r.u32)(o),h=(0,r.u32)(s);let y=a[0],f=a[1],p=a[2],d=a[3];for(let t=0;t+4<=l.length;){const e=y,n=f,r=p,o=d;y=l[t+0],f=l[t+1],p=l[t+2],d=l[t+3];const{s0:s,s1:c,s2:u,s3:a}=O(i,y,f,p,d);h[t++]=s^e,h[t++]=c^n,h[t++]=u^r,h[t++]=a^o}return(0,r.clean)(...u),M(s,n)}}}),D=(0,r.wrapCipher)({blockSize:16,nonceLength:16},function(t,e){function n(n,o,s){(0,r.abytes)(n);const i=n.length;if(s=(0,r.getOutput)(i,s),(0,r.overlapBytes)(n,s))throw new Error("overlapping src and dst not supported.");const c=K(t);let u=e;const a=[c];(0,r.isAligned32)(u)||a.push(u=(0,r.copyBytes)(u)),(0,r.isAligned32)(n)||a.push(n=(0,r.copyBytes)(n));const l=(0,r.u32)(n),h=(0,r.u32)(s),y=o?h:l,f=(0,r.u32)(u);let d=f[0],g=f[1],b=f[2],w=f[3];for(let t=0;t+4<=l.length;){const{s0:e,s1:n,s2:r,s3:o}=L(c,d,g,b,w);h[t+0]=l[t+0]^e,h[t+1]=l[t+1]^n,h[t+2]=l[t+2]^r,h[t+3]=l[t+3]^o,d=y[t++],g=y[t++],b=y[t++],w=y[t++]}const E=p*Math.floor(l.length/4);if(E<i){({s0:d,s1:g,s2:b,s3:w}=L(c,d,g,b,w));const t=(0,r.u8)(new Uint32Array([d,g,b,w]));for(let e=E,r=0;e<i;e++,r++)s[e]=n[e]^t[r];(0,r.clean)(t)}return(0,r.clean)(...a),s}return{encrypt:(t,e)=>n(t,!0,e),decrypt:(t,e)=>n(t,!1,e)}});function z(t,e,n,o,s){const i=s?s.length:0,c=t.create(n,o.length+i);s&&c.update(s);const u=(0,r.u64Lengths)(8*o.length,8*i,e);c.update(o),c.update(u);const a=c.digest();return(0,r.clean)(u),a}const R=(0,r.wrapCipher)({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(t,e,n){if(e.length<8)throw new Error("aes/gcm: invalid nonce length");function o(t,e,r){const o=z(y,!1,t,r,n);for(let n=0;n<e.length;n++)o[n]^=e[n];return o}function s(){const n=K(t),o=d.slice(),s=d.slice();if(k(n,!1,s,s,o),12===e.length)s.set(e);else{const t=d.slice(),n=(0,r.createView)(t);(0,r.setBigUint64)(n,8,BigInt(8*e.length),!1);const i=y.create(o).update(e).update(t);i.digestInto(s),i.destroy()}return{xk:n,authKey:o,counter:s,tagMask:k(n,!1,s,d)}}return{encrypt(t){const{xk:e,authKey:n,counter:i,tagMask:c}=s(),u=new Uint8Array(t.length+16),a=[e,n,i,c];(0,r.isAligned32)(t)||a.push(t=(0,r.copyBytes)(t)),k(e,!1,i,t,u.subarray(0,t.length));const l=o(n,c,u.subarray(0,u.length-16));return a.push(l),u.set(l,t.length),(0,r.clean)(...a),u},decrypt(t){const{xk:e,authKey:n,counter:i,tagMask:c}=s(),u=[e,n,c,i];(0,r.isAligned32)(t)||u.push(t=(0,r.copyBytes)(t));const a=t.subarray(0,-16),l=t.subarray(-16),h=o(n,c,a);if(u.push(h),!(0,r.equalBytes)(h,l))throw new Error("aes/gcm: invalid ghash tag");const y=k(e,!1,i,a);return(0,r.clean)(...u),y}}}),V=(t,e,n)=>r=>{if(!Number.isSafeInteger(r)||e>r||r>n){throw new Error(t+": expected value in range "+("["+e+".."+n+"]")+", got "+r)}},Y=(0,r.wrapCipher)({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(t,e,n){const o=V("AAD",0,2**36),s=V("plaintext",0,2**36),i=V("nonce",12,12),c=V("ciphertext",16,2**36+16);function u(){const n=K(t),o=new Uint8Array(t.length),s=new Uint8Array(16),i=[n,o];let c=e;(0,r.isAligned32)(c)||i.push(c=(0,r.copyBytes)(c));const u=(0,r.u32)(c);let a=0,l=u[0],h=u[1],y=u[2],f=0;for(const t of[s,o].map(r.u32)){const e=(0,r.u32)(t);for(let t=0;t<e.length;t+=2){const{s0:r,s1:o}=L(n,a,l,h,y);e[t+0]=r,e[t+1]=o,a=++f}}const p={authKey:s,encKey:K(o)};return(0,r.clean)(...i),p}function a(t,o,s){const i=z(f,!0,o,s,n);for(let n=0;n<12;n++)i[n]^=e[n];i[15]&=127;const c=(0,r.u32)(i);let u=c[0],a=c[1],l=c[2],h=c[3];return({s0:u,s1:a,s2:l,s3:h}=L(t,u,a,l,h)),c[0]=u,c[1]=a,c[2]=l,c[3]=h,i}function l(t,e,n){let o=(0,r.copyBytes)(e);o[15]|=128;const s=k(t,!0,o,n);return(0,r.clean)(o),s}return(0,r.abytes)(t,16,24,32),i(e.length),void 0!==n&&o(n.length),{encrypt(t){s(t.length);const{encKey:e,authKey:n}=u(),o=a(e,n,t),i=[e,n,o];(0,r.isAligned32)(t)||i.push(t=(0,r.copyBytes)(t));const c=new Uint8Array(t.length+16);return c.set(o,t.length),c.set(l(e,o,t)),(0,r.clean)(...i),c},decrypt(t){c(t.length);const e=t.subarray(-16),{encKey:n,authKey:o}=u(),s=[n,o];(0,r.isAligned32)(t)||s.push(t=(0,r.copyBytes)(t));const i=l(n,e,t.subarray(0,-16)),h=a(n,o,i);if(s.push(h),!(0,r.equalBytes)(e,h))throw(0,r.clean)(...s),new Error("invalid polyval tag");return(0,r.clean)(...s),i}}}),Z=Y;function q(t){return t instanceof Uint32Array||ArrayBuffer.isView(t)&&"Uint32Array"===t.constructor.name}function W(t,e){if((0,r.abytes)(e,16),!q(t))throw new Error("_encryptBlock accepts result of expandKeyLE");const n=(0,r.u32)(e);let{s0:o,s1:s,s2:i,s3:c}=L(t,n[0],n[1],n[2],n[3]);return n[0]=o,n[1]=s,n[2]=i,n[3]=c,e}function X(t,e){if((0,r.abytes)(e,16),!q(t))throw new Error("_decryptBlock accepts result of expandKeyLE");const n=(0,r.u32)(e);let{s0:o,s1:s,s2:i,s3:c}=O(t,n[0],n[1],n[2],n[3]);return n[0]=o,n[1]=s,n[2]=i,n[3]=c,e}const J={encrypt(t,e){if(e.length>=2**32)throw new Error("plaintext should be less than 4gb");const n=K(t);if(16===e.length)W(n,e);else{const t=(0,r.u32)(e);let o=t[0],s=t[1];for(let e=0,r=1;e<6;e++)for(let i=2;i<t.length;i+=2,r++){const{s0:e,s1:c,s2:u,s3:a}=L(n,o,s,t[i],t[i+1]);o=e,s=c^_(r),t[i]=u,t[i+1]=a}t[0]=o,t[1]=s}n.fill(0)},decrypt(t,e){if(e.length-8>=2**32)throw new Error("ciphertext should be less than 4gb");const n=U(t),o=e.length/8-1;if(1===o)X(n,e);else{const t=(0,r.u32)(e);let s=t[0],i=t[1];for(let e=0,r=6*o;e<6;e++)for(let c=2*o;c>=1;c-=2,r--){i^=_(r);const{s0:e,s1:o,s2:u,s3:a}=O(n,s,i,t[c],t[c+1]);s=e,i=o,t[c]=u,t[c+1]=a}t[0]=s,t[1]=i}n.fill(0)}},Q=new Uint8Array(8).fill(166),$=(0,r.wrapCipher)({blockSize:8},t=>({encrypt(e){if(!e.length||e.length%8!==0)throw new Error("invalid plaintext length");if(8===e.length)throw new Error("8-byte keys not allowed in AESKW, use AESKWP instead");const n=(0,r.concatBytes)(Q,e);return J.encrypt(t,n),n},decrypt(e){if(e.length%8!==0||e.length<24)throw new Error("invalid ciphertext length");const n=(0,r.copyBytes)(e);if(J.decrypt(t,n),!(0,r.equalBytes)(n.subarray(0,8),Q))throw new Error("integrity check failed");return n.subarray(0,8).fill(0),n.subarray(8)}})),tt=2790873510,et=(0,r.wrapCipher)({blockSize:8},t=>({encrypt(e){if(!e.length)throw new Error("invalid plaintext length");const n=8*Math.ceil(e.length/8),o=new Uint8Array(8+n);o.set(e,8);const s=(0,r.u32)(o);return s[0]=tt,s[1]=_(e.length),J.encrypt(t,o),o},decrypt(e){if(e.length<16)throw new Error("invalid ciphertext length");const n=(0,r.copyBytes)(e),o=(0,r.u32)(n);J.decrypt(t,n);const s=_(o[1])>>>0,i=8*Math.ceil(s/8);if(o[0]!==tt||n.length-8!==i)throw new Error("integrity check failed");for(let t=s;t<i;t++)if(0!==n[8+t])throw new Error("integrity check failed");return n.subarray(0,8).fill(0),n.subarray(8,8+s)}})),nt={expandKeyLE:K,expandKeyDecLE:U,encrypt:L,decrypt:O,encryptBlock:W,decryptBlock:X,ctrCounter:I,ctr32:k}},2837:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PublicKey=e.PrivateKey=void 0;var r=n(7963);Object.defineProperty(e,"PrivateKey",{enumerable:!0,get:function(){return r.PrivateKey}});var o=n(8745);Object.defineProperty(e,"PublicKey",{enumerable:!0,get:function(){return o.PublicKey}})},3927:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.chacha20=e.xchacha20=void 0;var r=n(4115);e.xchacha20=function(t,e,n){return(0,r.xchacha20poly1305)(t,e,n)};e.chacha20=function(t,e,n){return(0,r.chacha20poly1305)(t,e,n)}},4101:(t,e,n)=>{n.r(e),n.d(e,{cbc:()=>f,ctr:()=>p,gcm:()=>d,getWebcryptoSubtle:()=>i,managedNonce:()=>c,randomBytes:()=>s,utils:()=>u});const r="object"===typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;var o=n(4314);function s(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;if(r&&"function"===typeof r.getRandomValues)return r.getRandomValues(new Uint8Array(t));if(r&&"function"===typeof r.randomBytes)return Uint8Array.from(r.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function i(){if(r&&"object"===typeof r.subtle&&null!=r.subtle)return r.subtle;throw new Error("crypto.subtle must be defined")}function c(t){const{nonceLength:e}=t;return(0,o.anumber)(e),function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),c=1;c<r;c++)i[c-1]=arguments[c];return{encrypt(r){const c=s(e);for(var u=arguments.length,a=new Array(u>1?u-1:0),l=1;l<u;l++)a[l-1]=arguments[l];const h=t(n,c,...i).encrypt(r,...a),y=(0,o.concatBytes)(c,h);return h.fill(0),y},decrypt(r){const o=r.subarray(0,e),s=r.subarray(e);for(var c=arguments.length,u=new Array(c>1?c-1:0),a=1;a<c;a++)u[a-1]=arguments[a];return t(n,o,...i).decrypt(s,...u)}}}}const u={async encrypt(t,e,n,r){const o=i(),s=await o.importKey("raw",t,e,!0,["encrypt"]),c=await o.encrypt(n,s,r);return new Uint8Array(c)},async decrypt(t,e,n,r){const o=i(),s=await o.importKey("raw",t,e,!0,["decrypt"]),c=await o.decrypt(n,s,r);return new Uint8Array(c)}},a="AES-CBC",l="AES-CTR",h="AES-GCM";function y(t){return(e,n,r)=>{(0,o.abytes)(e),(0,o.abytes)(n);const s={name:t,length:8*e.length},i=function(t,e,n){if(t===a)return{name:a,iv:e};if(t===l)return{name:l,counter:e,length:64};if(t===h)return n?{name:h,iv:e,additionalData:n}:{name:h,iv:e};throw new Error("unknown aes block mode")}(t,n,r);let c=!1;return{encrypt(t){if((0,o.abytes)(t),c)throw new Error("Cannot encrypt() twice with same key / nonce");return c=!0,u.encrypt(e,s,i,t)},decrypt:t=>((0,o.abytes)(t),u.decrypt(e,s,i,t))}}}const f=(()=>y(a))(),p=(()=>y(l))(),d=(()=>y(h))()},4115:(t,e,n)=>{n.r(e),n.d(e,{_poly1305_aead:()=>U,chacha12:()=>A,chacha20:()=>m,chacha20orig:()=>E,chacha20poly1305:()=>S,chacha8:()=>_,hchacha:()=>w,xchacha20:()=>v,xchacha20poly1305:()=>P});var r=n(4314);const o=t=>Uint8Array.from(t.split("").map(t=>t.charCodeAt(0))),s=o("expand 16-byte k"),i=o("expand 32-byte k"),c=(0,r.u32)(s),u=(0,r.u32)(i);function a(t,e){return t<<e|t>>>32-e}function l(t){return t.byteOffset%4===0}const h=2**32-1,y=new Uint32Array;function f(t,e){const{allowShortKeys:n,extendNonceFn:o,counterLength:s,counterRight:i,rounds:a}=(0,r.checkOpts)({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if("function"!==typeof t)throw new Error("core must be a function");return(0,r.anumber)(s),(0,r.anumber)(a),(0,r.abool)(i),(0,r.abool)(n),function(e,f,p,d){let g=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;(0,r.abytes)(e),(0,r.abytes)(f),(0,r.abytes)(p);const b=p.length;if(void 0===d&&(d=new Uint8Array(b)),(0,r.abytes)(d),(0,r.anumber)(g),g<0||g>=h)throw new Error("arx: counter overflow");if(d.length<b)throw new Error("arx: output (".concat(d.length,") is shorter than data (").concat(b,")"));const w=[];let E,m,v=e.length;if(32===v)w.push(E=(0,r.copyBytes)(e)),m=u;else{if(16!==v||!n)throw new Error("arx: invalid 32-byte key, got length=".concat(v));E=new Uint8Array(32),E.set(e),E.set(e,16),m=c,w.push(E)}l(f)||w.push(f=(0,r.copyBytes)(f));const _=(0,r.u32)(E);if(o){if(24!==f.length)throw new Error("arx: extended nonce must be 24 bytes");o(m,_,(0,r.u32)(f.subarray(0,16)),_),f=f.subarray(16)}const A=16-s;if(A!==f.length)throw new Error("arx: nonce must be ".concat(A," or 16 bytes"));if(12!==A){const t=new Uint8Array(12);t.set(f,i?0:12-f.length),f=t,w.push(f)}const x=(0,r.u32)(f);return function(t,e,n,o,s,i,c,u){const a=s.length,f=new Uint8Array(64),p=(0,r.u32)(f),d=l(s)&&l(i),g=d?(0,r.u32)(s):y,b=d?(0,r.u32)(i):y;for(let r=0;r<a;c++){if(t(e,n,o,p,c,u),c>=h)throw new Error("arx: counter overflow");const l=Math.min(64,a-r);if(d&&64===l){const t=r/4;if(r%4!==0)throw new Error("arx: invalid block position");for(let e,n=0;n<16;n++)e=t+n,b[e]=g[e]^p[n];r+=64;continue}for(let t,e=0;e<l;e++)t=r+e,i[t]=s[t]^f[e];r+=l}}(t,m,_,x,p,d,g,a),(0,r.clean)(...w),d}}const p=(t,e)=>255&t[e++]|(255&t[e++])<<8;class d{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=(0,r.toBytes)(t),(0,r.abytes)(t,32);const e=p(t,0),n=p(t,2),o=p(t,4),s=p(t,6),i=p(t,8),c=p(t,10),u=p(t,12),a=p(t,14);this.r[0]=8191&e,this.r[1]=8191&(e>>>13|n<<3),this.r[2]=7939&(n>>>10|o<<6),this.r[3]=8191&(o>>>7|s<<9),this.r[4]=255&(s>>>4|i<<12),this.r[5]=i>>>1&8190,this.r[6]=8191&(i>>>14|c<<2),this.r[7]=8065&(c>>>11|u<<5),this.r[8]=8191&(u>>>8|a<<8),this.r[9]=a>>>5&127;for(let r=0;r<8;r++)this.pad[r]=p(t,16+2*r)}process(t,e){const n=arguments.length>2&&void 0!==arguments[2]&&arguments[2]?0:2048,{h:r,r:o}=this,s=o[0],i=o[1],c=o[2],u=o[3],a=o[4],l=o[5],h=o[6],y=o[7],f=o[8],d=o[9],g=p(t,e+0),b=p(t,e+2),w=p(t,e+4),E=p(t,e+6),m=p(t,e+8),v=p(t,e+10),_=p(t,e+12),A=p(t,e+14);let x=r[0]+(8191&g),C=r[1]+(8191&(g>>>13|b<<3)),B=r[2]+(8191&(b>>>10|w<<6)),K=r[3]+(8191&(w>>>7|E<<9)),U=r[4]+(8191&(E>>>4|m<<12)),S=r[5]+(m>>>1&8191),P=r[6]+(8191&(m>>>14|v<<2)),L=r[7]+(8191&(v>>>11|_<<5)),O=r[8]+(8191&(_>>>8|A<<8)),I=r[9]+(A>>>5|n),k=0,N=k+x*s+C*(5*d)+B*(5*f)+K*(5*y)+U*(5*h);k=N>>>13,N&=8191,N+=S*(5*l)+P*(5*a)+L*(5*u)+O*(5*c)+I*(5*i),k+=N>>>13,N&=8191;let T=k+x*i+C*s+B*(5*d)+K*(5*f)+U*(5*y);k=T>>>13,T&=8191,T+=S*(5*h)+P*(5*l)+L*(5*a)+O*(5*u)+I*(5*c),k+=T>>>13,T&=8191;let H=k+x*c+C*i+B*s+K*(5*d)+U*(5*f);k=H>>>13,H&=8191,H+=S*(5*y)+P*(5*h)+L*(5*l)+O*(5*a)+I*(5*u),k+=H>>>13,H&=8191;let M=k+x*u+C*c+B*i+K*s+U*(5*d);k=M>>>13,M&=8191,M+=S*(5*f)+P*(5*y)+L*(5*h)+O*(5*l)+I*(5*a),k+=M>>>13,M&=8191;let G=k+x*a+C*u+B*c+K*i+U*s;k=G>>>13,G&=8191,G+=S*(5*d)+P*(5*f)+L*(5*y)+O*(5*h)+I*(5*l),k+=G>>>13,G&=8191;let j=k+x*l+C*a+B*u+K*c+U*i;k=j>>>13,j&=8191,j+=S*s+P*(5*d)+L*(5*f)+O*(5*y)+I*(5*h),k+=j>>>13,j&=8191;let F=k+x*h+C*l+B*a+K*u+U*c;k=F>>>13,F&=8191,F+=S*i+P*s+L*(5*d)+O*(5*f)+I*(5*y),k+=F>>>13,F&=8191;let D=k+x*y+C*h+B*l+K*a+U*u;k=D>>>13,D&=8191,D+=S*c+P*i+L*s+O*(5*d)+I*(5*f),k+=D>>>13,D&=8191;let z=k+x*f+C*y+B*h+K*l+U*a;k=z>>>13,z&=8191,z+=S*u+P*c+L*i+O*s+I*(5*d),k+=z>>>13,z&=8191;let R=k+x*d+C*f+B*y+K*h+U*l;k=R>>>13,R&=8191,R+=S*a+P*u+L*c+O*i+I*s,k+=R>>>13,R&=8191,k=(k<<2)+k|0,k=k+N|0,N=8191&k,k>>>=13,T+=k,r[0]=N,r[1]=T,r[2]=H,r[3]=M,r[4]=G,r[5]=j,r[6]=F,r[7]=D,r[8]=z,r[9]=R}finalize(){const{h:t,pad:e}=this,n=new Uint16Array(10);let o=t[1]>>>13;t[1]&=8191;for(let r=2;r<10;r++)t[r]+=o,o=t[r]>>>13,t[r]&=8191;t[0]+=5*o,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,n[0]=t[0]+5,o=n[0]>>>13,n[0]&=8191;for(let r=1;r<10;r++)n[r]=t[r]+o,o=n[r]>>>13,n[r]&=8191;n[9]-=8192;let s=(1^o)-1;for(let r=0;r<10;r++)n[r]&=s;s=~s;for(let r=0;r<10;r++)t[r]=t[r]&s|n[r];t[0]=65535&(t[0]|t[1]<<13),t[1]=65535&(t[1]>>>3|t[2]<<10),t[2]=65535&(t[2]>>>6|t[3]<<7),t[3]=65535&(t[3]>>>9|t[4]<<4),t[4]=65535&(t[4]>>>12|t[5]<<1|t[6]<<14),t[5]=65535&(t[6]>>>2|t[7]<<11),t[6]=65535&(t[7]>>>5|t[8]<<8),t[7]=65535&(t[8]>>>8|t[9]<<5);let i=t[0]+e[0];t[0]=65535&i;for(let r=1;r<8;r++)i=(t[r]+e[r]|0)+(i>>>16)|0,t[r]=65535&i;(0,r.clean)(n)}update(t){(0,r.aexists)(this),t=(0,r.toBytes)(t),(0,r.abytes)(t);const{buffer:e,blockLen:n}=this,o=t.length;for(let r=0;r<o;){const s=Math.min(n-this.pos,o-r);if(s!==n)e.set(t.subarray(r,r+s),this.pos),this.pos+=s,r+=s,this.pos===n&&(this.process(e,0,!1),this.pos=0);else for(;n<=o-r;r+=n)this.process(t,r)}return this}destroy(){(0,r.clean)(this.h,this.r,this.buffer,this.pad)}digestInto(t){(0,r.aexists)(this),(0,r.aoutput)(t,this),this.finished=!0;const{buffer:e,h:n}=this;let{pos:o}=this;if(o){for(e[o++]=1;o<16;o++)e[o]=0;this.process(e,0,!0)}this.finalize();let s=0;for(let r=0;r<8;r++)t[s++]=n[r]>>>0,t[s++]=n[r]>>>8;return t}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}}const g=function(t){const e=(e,n)=>t(n).update((0,r.toBytes)(e)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e}(t=>new d(t));function b(t,e,n,r,o){let s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:20,i=t[0],c=t[1],u=t[2],l=t[3],h=e[0],y=e[1],f=e[2],p=e[3],d=e[4],g=e[5],b=e[6],w=e[7],E=o,m=n[0],v=n[1],_=n[2],A=i,x=c,C=u,B=l,K=h,U=y,S=f,P=p,L=d,O=g,I=b,k=w,N=E,T=m,H=v,M=_;for(let j=0;j<s;j+=2)A=A+K|0,N=a(N^A,16),L=L+N|0,K=a(K^L,12),A=A+K|0,N=a(N^A,8),L=L+N|0,K=a(K^L,7),x=x+U|0,T=a(T^x,16),O=O+T|0,U=a(U^O,12),x=x+U|0,T=a(T^x,8),O=O+T|0,U=a(U^O,7),C=C+S|0,H=a(H^C,16),I=I+H|0,S=a(S^I,12),C=C+S|0,H=a(H^C,8),I=I+H|0,S=a(S^I,7),B=B+P|0,M=a(M^B,16),k=k+M|0,P=a(P^k,12),B=B+P|0,M=a(M^B,8),k=k+M|0,P=a(P^k,7),A=A+U|0,M=a(M^A,16),I=I+M|0,U=a(U^I,12),A=A+U|0,M=a(M^A,8),I=I+M|0,U=a(U^I,7),x=x+S|0,N=a(N^x,16),k=k+N|0,S=a(S^k,12),x=x+S|0,N=a(N^x,8),k=k+N|0,S=a(S^k,7),C=C+P|0,T=a(T^C,16),L=L+T|0,P=a(P^L,12),C=C+P|0,T=a(T^C,8),L=L+T|0,P=a(P^L,7),B=B+K|0,H=a(H^B,16),O=O+H|0,K=a(K^O,12),B=B+K|0,H=a(H^B,8),O=O+H|0,K=a(K^O,7);let G=0;r[G++]=i+A|0,r[G++]=c+x|0,r[G++]=u+C|0,r[G++]=l+B|0,r[G++]=h+K|0,r[G++]=y+U|0,r[G++]=f+S|0,r[G++]=p+P|0,r[G++]=d+L|0,r[G++]=g+O|0,r[G++]=b+I|0,r[G++]=w+k|0,r[G++]=E+N|0,r[G++]=m+T|0,r[G++]=v+H|0,r[G++]=_+M|0}function w(t,e,n,r){let o=t[0],s=t[1],i=t[2],c=t[3],u=e[0],l=e[1],h=e[2],y=e[3],f=e[4],p=e[5],d=e[6],g=e[7],b=n[0],w=n[1],E=n[2],m=n[3];for(let _=0;_<20;_+=2)o=o+u|0,b=a(b^o,16),f=f+b|0,u=a(u^f,12),o=o+u|0,b=a(b^o,8),f=f+b|0,u=a(u^f,7),s=s+l|0,w=a(w^s,16),p=p+w|0,l=a(l^p,12),s=s+l|0,w=a(w^s,8),p=p+w|0,l=a(l^p,7),i=i+h|0,E=a(E^i,16),d=d+E|0,h=a(h^d,12),i=i+h|0,E=a(E^i,8),d=d+E|0,h=a(h^d,7),c=c+y|0,m=a(m^c,16),g=g+m|0,y=a(y^g,12),c=c+y|0,m=a(m^c,8),g=g+m|0,y=a(y^g,7),o=o+l|0,m=a(m^o,16),d=d+m|0,l=a(l^d,12),o=o+l|0,m=a(m^o,8),d=d+m|0,l=a(l^d,7),s=s+h|0,b=a(b^s,16),g=g+b|0,h=a(h^g,12),s=s+h|0,b=a(b^s,8),g=g+b|0,h=a(h^g,7),i=i+y|0,w=a(w^i,16),f=f+w|0,y=a(y^f,12),i=i+y|0,w=a(w^i,8),f=f+w|0,y=a(y^f,7),c=c+u|0,E=a(E^c,16),p=p+E|0,u=a(u^p,12),c=c+u|0,E=a(E^c,8),p=p+E|0,u=a(u^p,7);let v=0;r[v++]=o,r[v++]=s,r[v++]=i,r[v++]=c,r[v++]=b,r[v++]=w,r[v++]=E,r[v++]=m}const E=f(b,{counterRight:!1,counterLength:8,allowShortKeys:!0}),m=f(b,{counterRight:!1,counterLength:4,allowShortKeys:!1}),v=f(b,{counterRight:!1,counterLength:8,extendNonceFn:w,allowShortKeys:!1}),_=f(b,{counterRight:!1,counterLength:4,rounds:8}),A=f(b,{counterRight:!1,counterLength:4,rounds:12}),x=new Uint8Array(16),C=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(x.subarray(n))},B=new Uint8Array(32);function K(t,e,n,o,s){const i=t(e,n,B),c=g.create(i);s&&C(c,s),C(c,o);const u=(0,r.u64Lengths)(o.length,s?s.length:0,!0);c.update(u);const a=c.digest();return(0,r.clean)(i,u),a}const U=t=>(e,n,o)=>{const s=16;return{encrypt(i,c){const u=i.length;(c=(0,r.getOutput)(u+s,c,!1)).set(i);const a=c.subarray(0,-16);t(e,n,a,a,1);const l=K(t,e,n,a,o);return c.set(l,u),(0,r.clean)(l),c},decrypt(i,c){c=(0,r.getOutput)(i.length-s,c,!1);const u=i.subarray(0,-16),a=i.subarray(-16),l=K(t,e,n,u,o);if(!(0,r.equalBytes)(a,l))throw new Error("invalid tag");return c.set(i.subarray(0,-16)),t(e,n,c,c,1),(0,r.clean)(l),c}}},S=(0,r.wrapCipher)({blockSize:64,nonceLength:12,tagLength:16},U(m)),P=(0,r.wrapCipher)({blockSize:64,nonceLength:24,tagLength:16},U(v))},4288:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.PublicKey=e.PrivateKey=e.ECIES_CONFIG=void 0,e.encrypt=function(t,e){return Buffer.from(function(t,e,n){var o=n.ellipticCurve,c=new s.PrivateKey(void 0,o),u=t instanceof Uint8Array?new s.PublicKey(t,o):s.PublicKey.fromHex(t,o),a=c.encapsulate(u,n.isHkdfKeyCompressed),l=c.publicKey.toBytes(n.isEphemeralKeyCompressed),h=(0,i.symEncrypt)(a,e);return(0,r.concatBytes)(l,h)}(t,e,o.ECIES_CONFIG))},e.decrypt=function(t,e){return Buffer.from(function(t,e,n){void 0===n&&(n=o.ECIES_CONFIG);var r=n.ellipticCurve,c=t instanceof Uint8Array?new s.PrivateKey(t,r):s.PrivateKey.fromHex(t,r),u=n.ephemeralKeySize,a=new s.PublicKey(e.subarray(0,u),r),l=e.subarray(u),h=a.decapsulate(c,n.isHkdfKeyCompressed);return(0,i.symDecrypt)(h,l)}(t,e))};var r=n(4314),o=n(9956),s=n(2837),i=n(1586);var c=n(9956);Object.defineProperty(e,"ECIES_CONFIG",{enumerable:!0,get:function(){return c.ECIES_CONFIG}});var u=n(2837);Object.defineProperty(e,"PrivateKey",{enumerable:!0,get:function(){return u.PrivateKey}}),Object.defineProperty(e,"PublicKey",{enumerable:!0,get:function(){return u.PublicKey}}),e.utils={aesEncrypt:i.aesEncrypt,aesDecrypt:i.aesDecrypt,symEncrypt:i.symEncrypt,symDecrypt:i.symDecrypt,decodeHex:i.decodeHex,getValidSecret:i.getValidSecret,remove0x:i.remove0x}},4314:(t,e,n)=>{function r(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function o(t){if("boolean"!==typeof t)throw new Error("boolean expected, not ".concat(t))}function s(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function i(t){if(!r(t))throw new Error("Uint8Array expected");for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];if(n.length>0&&!n.includes(t.length))throw new Error("Uint8Array expected of length "+n+", got length="+t.length)}function c(t){if("function"!==typeof t||"function"!==typeof t.create)throw new Error("Hash should be wrapped by utils.createHasher");s(t.outputLen),s(t.blockLen)}function u(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];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 a(t,e){i(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function l(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function h(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function y(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(let r=0;r<e.length;r++)e[r].fill(0)}function f(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}n.r(e),n.d(e,{Hash:()=>I,abool:()=>o,abytes:()=>i,aexists:()=>u,ahash:()=>c,anumber:()=>s,aoutput:()=>a,bytesToHex:()=>b,bytesToNumberBE:()=>_,bytesToUtf8:()=>B,checkOpts:()=>L,clean:()=>y,complexOverlapBytes:()=>S,concatBytes:()=>P,copyBytes:()=>G,createView:()=>f,equalBytes:()=>O,getOutput:()=>N,hexToBytes:()=>m,hexToNumber:()=>v,isAligned32:()=>M,isBytes:()=>r,isLE:()=>p,nextTick:()=>x,numberToBytesBE:()=>A,overlapBytes:()=>U,setBigUint64:()=>T,toBytes:()=>K,u32:()=>h,u64Lengths:()=>H,u8:()=>l,utf8ToBytes:()=>C,wrapCipher:()=>k});const p=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])(),d=(()=>"function"===typeof Uint8Array.from([]).toHex&&"function"===typeof Uint8Array.fromHex)(),g=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function b(t){if(i(t),d)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=g[t[n]];return e}const w={_0:48,_9:57,A:65,F:70,a:97,f:102};function E(t){return t>=w._0&&t<=w._9?t-w._0:t>=w.A&&t<=w.F?t-(w.A-10):t>=w.a&&t<=w.f?t-(w.a-10):void 0}function m(t){if("string"!==typeof t)throw new Error("hex string expected, got "+typeof t);if(d)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){const e=E(t.charCodeAt(s)),n=E(t.charCodeAt(s+1));if(void 0===e||void 0===n){const e=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+s)}r[o]=16*e+n}return r}function v(t){if("string"!==typeof t)throw new Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":"0x"+t)}function _(t){return v(b(t))}function A(t,e){return m(t.toString(16).padStart(2*e,"0"))}const x=async()=>{};function C(t){if("string"!==typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}function B(t){return(new TextDecoder).decode(t)}function K(t){if("string"===typeof t)t=C(t);else{if(!r(t))throw new Error("Uint8Array expected, got "+typeof t);t=G(t)}return t}function U(t,e){return t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function S(t,e){if(U(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function P(){let t=0;for(let n=0;n<arguments.length;n++){const e=n<0||arguments.length<=n?void 0:arguments[n];i(e),t+=e.length}const e=new Uint8Array(t);for(let n=0,r=0;n<arguments.length;n++){const t=n<0||arguments.length<=n?void 0:arguments[n];e.set(t,r),r+=t.length}return e}function L(t,e){if(null==e||"object"!==typeof e)throw new Error("options must be defined");return Object.assign(t,e)}function O(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return 0===n}class I{}const k=(t,e)=>{function n(n){if(i(n),!p)throw new Error("Non little-endian hardware is not yet supported");for(var r=arguments.length,o=new Array(r>1?r-1:0),s=1;s<r;s++)o[s-1]=arguments[s];if(void 0!==t.nonceLength){const e=o[0];if(!e)throw new Error("nonce / iv required");t.varSizeNonce?i(e):i(e,t.nonceLength)}const c=t.tagLength;c&&void 0!==o[1]&&i(o[1]);const u=e(n,...o),a=(t,e)=>{if(void 0!==e){if(2!==t)throw new Error("cipher output not supported");i(e)}};let l=!1;return{encrypt(t,e){if(l)throw new Error("cannot encrypt() twice with same key + nonce");return l=!0,i(t),a(u.encrypt.length,e),u.encrypt(t,e)},decrypt(t,e){if(i(t),c&&t.length<c)throw new Error("invalid ciphertext length: smaller than tagLength="+c);return a(u.decrypt.length,e),u.decrypt(t,e)}}}return Object.assign(n,t),n};function N(t,e){let n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(void 0===e)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(n&&!M(e))throw new Error("invalid output, must be aligned");return e}function T(t,e,n,r){if("function"===typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),u=r?4:0,a=r?0:4;t.setUint32(e+u,i,r),t.setUint32(e+a,c,r)}function H(t,e,n){o(n);const r=new Uint8Array(16),s=f(r);return T(s,0,BigInt(e),n),T(s,8,BigInt(t),n),r}function M(t){return t.byteOffset%4===0}function G(t){return Uint8Array.from(t)}},4710:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.hexToPublicKey=e.convertPublicKeyFormat=e.getSharedPoint=e.getPublicKey=e.isValidPrivateKey=e.getValidSecret=void 0;var r=n(4101),o=n(5471),s=n(8717),i=n(9956),c=n(8798),u=n(2115);e.getValidSecret=function(t){var n;do{n=(0,r.randomBytes)(c.SECRET_KEY_LENGTH)}while(!(0,e.isValidPrivateKey)(n,t));return n};e.isValidPrivateKey=function(t,e){return a(e,function(e){return e.utils.isValidSecretKey(t)},function(){return!0},function(){return!0})};e.getPublicKey=function(t,e){return a(e,function(e){return e.getPublicKey(t)},function(e){return e.getPublicKey(t)},function(e){return e.getPublicKey(t)})};e.getSharedPoint=function(t,e,n,r){return a(r,function(r){return r.getSharedSecret(t,e,n)},function(n){return n.getSharedSecret(t,e)},function(n){return h(n,t,e)})};e.convertPublicKeyFormat=function(t,e,n){return a(n,function(n){return n.getSharedSecret(Uint8Array.from(Array(31).fill(0).concat([1])),t,e)},function(){return t},function(){return t})};function a(t,e,n,r){var c=t||i.ECIES_CONFIG.ellipticCurve;if("secp256k1"===c)return e(s.secp256k1);if("x25519"===c)return n(o.x25519);if("ed25519"===c)return r(o.ed25519);throw new Error("Not implemented")}e.hexToPublicKey=function(t,e){var n=(0,u.decodeHex)(t);return a(e,function(){return l(n)},function(){return n},function(){return n})};var l=function(t){if(t.length===c.ETH_PUBLIC_KEY_SIZE){var e=new Uint8Array(1+t.length);return e.set([4]),e.set(t,1),e}return t},h=function(t,e,n){var r=t.utils.getExtendedPublicKey(e).scalar;return t.Point.fromBytes(n).multiply(r).toBytes()}},5288:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getSharedKey=e.deriveKey=void 0;var r=n(4314),o=n(9618),s=n(929);e.deriveKey=function(t,e,n){return(0,o.hkdf)(s.sha256,t,e,n,32)};e.getSharedKey=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0,e.deriveKey)(r.concatBytes.apply(void 0,t))}},7337:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.aesDecrypt=e.aesEncrypt=e.symDecrypt=e.symEncrypt=void 0;var r=n(8322),o=n(3927),s=n(4314),i=n(4101),c=n(9956),u=n(8798);e.symEncrypt=function(t,e,n){return a(l,c.ECIES_CONFIG.symmetricAlgorithm,c.ECIES_CONFIG.symmetricNonceLength,t,e,n)};function a(t,e,n,s,i,c){if("aes-256-gcm"===e)return t(r.aes256gcm,s,i,n,u.AEAD_TAG_LENGTH,c);if("xchacha20"===e)return t(o.xchacha20,s,i,u.XCHACHA20_NONCE_LENGTH,u.AEAD_TAG_LENGTH,c);if("aes-256-cbc"===e)return t(r.aes256cbc,s,i,16,0);throw new Error("Not implemented")}function l(t,e,n,r,o,c){var u=(0,i.randomBytes)(r),a=t(e,u,c).encrypt(n);if(0===o)return(0,s.concatBytes)(u,a);var l=a.length-o,h=a.subarray(0,l),y=a.subarray(l);return(0,s.concatBytes)(u,y,h)}function h(t,e,n,r,o,i){var c=n.subarray(0,r),u=t(e,Uint8Array.from(c),i),a=n.subarray(r);if(0===o)return u.decrypt(a);var l=a.subarray(0,o),h=a.subarray(o);return u.decrypt((0,s.concatBytes)(h,l))}e.symDecrypt=function(t,e,n){return a(h,c.ECIES_CONFIG.symmetricAlgorithm,c.ECIES_CONFIG.symmetricNonceLength,t,e,n)},e.aesEncrypt=e.symEncrypt,e.aesDecrypt=e.symDecrypt},7963:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PrivateKey=void 0;var r=n(4314),o=n(1586),s=n(8745),i=function(){function t(t,e){if(this.curve=e,void 0===t)this.data=(0,o.getValidSecret)(e);else{if(!(0,o.isValidPrivateKey)(t,e))throw new Error("Invalid private key");this.data=t}this.publicKey=new s.PublicKey((0,o.getPublicKey)(this.data,e),e)}return t.fromHex=function(e,n){return new t((0,o.decodeHex)(e),n)},Object.defineProperty(t.prototype,"secret",{get:function(){return Buffer.from(this.data)},enumerable:!1,configurable:!0}),t.prototype.toHex=function(){return(0,r.bytesToHex)(this.data)},t.prototype.encapsulate=function(t,e){void 0===e&&(e=!1);var n=this.publicKey.toBytes(e),r=this.multiply(t,e);return(0,o.getSharedKey)(n,r)},t.prototype.multiply=function(t,e){return void 0===e&&(e=!1),(0,o.getSharedPoint)(this.data,t.toBytes(!0),e,this.curve)},t.prototype.equals=function(t){return(0,r.equalBytes)(this.data,t.data)},t}();e.PrivateKey=i},8322:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.aes256cbc=e.aes256gcm=void 0;var r=n(2338);e.aes256gcm=function(t,e,n){return(0,r.gcm)(t,e,n)};e.aes256cbc=function(t,e,n){return(0,r.cbc)(t,e)}},8745:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PublicKey=void 0;var r=n(4314),o=n(1586),s=function(){function t(t,e){var n=(0,o.convertPublicKeyFormat)(t,!0,e),r=(0,o.convertPublicKeyFormat)(t,!1,e);this.data=n,this.dataUncompressed=n.length!==r.length?r:null}return t.fromHex=function(e,n){return new t((0,o.hexToPublicKey)(e,n),n)},Object.defineProperty(t.prototype,"_uncompressed",{get:function(){return null!==this.dataUncompressed?this.dataUncompressed:this.data},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uncompressed",{get:function(){return Buffer.from(this._uncompressed)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"compressed",{get:function(){return Buffer.from(this.data)},enumerable:!1,configurable:!0}),t.prototype.toBytes=function(t){return void 0===t&&(t=!0),t?this.data:this._uncompressed},t.prototype.toHex=function(t){return void 0===t&&(t=!0),(0,r.bytesToHex)(this.toBytes(t))},t.prototype.decapsulate=function(t,e){void 0===e&&(e=!1);var n=this.toBytes(e),r=t.multiply(this,e);return(0,o.getSharedKey)(n,r)},t.prototype.equals=function(t){return(0,r.equalBytes)(this.data,t.data)},t}();e.PublicKey=s},8798:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AEAD_TAG_LENGTH=e.XCHACHA20_NONCE_LENGTH=e.CURVE25519_PUBLIC_KEY_SIZE=e.ETH_PUBLIC_KEY_SIZE=e.UNCOMPRESSED_PUBLIC_KEY_SIZE=e.COMPRESSED_PUBLIC_KEY_SIZE=e.SECRET_KEY_LENGTH=void 0,e.SECRET_KEY_LENGTH=32,e.COMPRESSED_PUBLIC_KEY_SIZE=33,e.UNCOMPRESSED_PUBLIC_KEY_SIZE=65,e.ETH_PUBLIC_KEY_SIZE=64,e.CURVE25519_PUBLIC_KEY_SIZE=32,e.XCHACHA20_NONCE_LENGTH=24,e.AEAD_TAG_LENGTH=16},9618:(t,e,n)=>{n.r(e),n.d(e,{expand:()=>u,extract:()=>s,hkdf:()=>a});var r=n(4934),o=n(2766);function s(t,e,n){return(0,o.sd)(t),void 0===n&&(n=new Uint8Array(t.outputLen)),(0,r.w)(t,(0,o.ZJ)(n),(0,o.ZJ)(e))}const i=Uint8Array.from([0]),c=Uint8Array.of();function u(t,e,n){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:32;(0,o.sd)(t),(0,o.Fe)(s);const u=t.outputLen;if(s>255*u)throw new Error("Length should be <= 255*HashLen");const a=Math.ceil(s/u);void 0===n&&(n=c);const l=new Uint8Array(a*u),h=r.w.create(t,e),y=h._cloneInto(),f=new Uint8Array(h.outputLen);for(let r=0;r<a;r++)i[0]=r+1,y.update(0===r?c:f).update(n).update(i).digestInto(f),l.set(f,u*r),h._cloneInto(y);return h.destroy(),y.destroy(),(0,o.uH)(f,i),l.slice(0,s)}const a=(t,e,n,r,o)=>u(t,s(t,e,n),r,o)},9956:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ephemeralKeySize=e.symmetricNonceLength=e.symmetricAlgorithm=e.isHkdfKeyCompressed=e.isEphemeralKeyCompressed=e.ellipticCurve=e.ECIES_CONFIG=e.Config=void 0;var r=n(8798),o=function(){function t(){this.ellipticCurve="secp256k1",this.isEphemeralKeyCompressed=!1,this.isHkdfKeyCompressed=!1,this.symmetricAlgorithm="aes-256-gcm",this.symmetricNonceLength=16}return Object.defineProperty(t.prototype,"ephemeralKeySize",{get:function(){var t={secp256k1:this.isEphemeralKeyCompressed?r.COMPRESSED_PUBLIC_KEY_SIZE:r.UNCOMPRESSED_PUBLIC_KEY_SIZE,x25519:r.CURVE25519_PUBLIC_KEY_SIZE,ed25519:r.CURVE25519_PUBLIC_KEY_SIZE};if(this.ellipticCurve in t)return t[this.ellipticCurve];throw new Error("Not implemented")},enumerable:!1,configurable:!0}),t}();e.Config=o,e.ECIES_CONFIG=new o;e.ellipticCurve=function(){return e.ECIES_CONFIG.ellipticCurve};e.isEphemeralKeyCompressed=function(){return e.ECIES_CONFIG.isEphemeralKeyCompressed};e.isHkdfKeyCompressed=function(){return e.ECIES_CONFIG.isHkdfKeyCompressed};e.symmetricAlgorithm=function(){return e.ECIES_CONFIG.symmetricAlgorithm};e.symmetricNonceLength=function(){return e.ECIES_CONFIG.symmetricNonceLength};e.ephemeralKeySize=function(){return e.ECIES_CONFIG.ephemeralKeySize}}}]);
|
|
3
|
+
//# sourceMappingURL=288.51cc5192.chunk.js.map
|