@monerium/sdk-react-provider 0.0.1 → 0.0.3
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/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1138 -0
- package/dist/lib/context.d.ts +20 -0
- package/dist/lib/provider.d.ts +8 -0
- package/dist/package.json +12 -0
- package/package.json +5 -5
- package/project.json +1 -1
- package/tsconfig.lib.json +1 -1
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Z=(o,e,r)=>{if(!e.has(o))throw TypeError("Cannot "+r)};var _=(o,e,r)=>(Z(o,e,"read from private field"),r?r.call(o):e.get(o)),H=(o,e,r)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,r)},O=(o,e,r,t)=>(Z(o,e,"write to private field"),t?t.call(o,r):e.set(o,r),r);var I=(o,e,r)=>(Z(o,e,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=require("react/jsx-runtime"),B=require("react"),oe=B.createContext(null),Y=o=>{var e;return o&&((e=Object.entries(o))==null?void 0:e.length)>0?Object.entries(o).map(([r,t])=>`${encodeURIComponent(r)}=${encodeURIComponent(t)}`).join("&"):""},he=o=>{switch(o){case 1:case 5:return"ethereum";case 100:case 10200:return"gnosis";case 137:case 80001:return"polygon";default:throw new Error(`Chain not supported: ${o}`)}},pe=o=>{switch(o){case 1:case 100:case 137:return"mainnet";case 5:return"goerli";case 10200:return"chiado";case 80001:return"mumbai";default:throw new Error(`Network not supported: ${o}`)}},ee={environments:{production:{api:"https://api.monerium.app",web:"https://monerium.app",wss:"wss://api.monerium.app"},sandbox:{api:"https://api.monerium.dev",web:"https://sandbox.monerium.dev",wss:"wss://api.monerium.dev"}}},G="monerium.sdk.code_verifier",te="monerium.sdk.refresh_token";var N=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ce(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}function ve(o){if(o.__esModule)return o;var e=o.default;if(typeof e=="function"){var r=function t(){if(this instanceof t){var u=[null];u.push.apply(u,arguments);var i=Function.bind.apply(e,u);return new i}return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(o).forEach(function(t){var u=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(r,t,u.get?u:{enumerable:!0,get:function(){return o[t]}})}),r}var ue={exports:{}};function ge(o){throw new Error('Could not dynamically require "'+o+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var re={exports:{}};const we={},ye=Object.freeze(Object.defineProperty({__proto__:null,default:we},Symbol.toStringTag,{value:"Module"})),me=ve(ye);var se;function le(){return se||(se=1,function(o,e){(function(r,t){o.exports=t()})(N,function(){var r=r||function(t,u){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof N<"u"&&N.crypto&&(i=N.crypto),!i&&typeof ge=="function")try{i=me}catch{}var v=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},b=Object.create||function(){function n(){}return function(s){var a;return n.prototype=s,a=new n,n.prototype=null,a}}(),p={},w=p.lib={},y=w.Base=function(){return{extend:function(n){var s=b(this);return n&&s.mixIn(n),(!s.hasOwnProperty("init")||this.init===s.init)&&(s.init=function(){s.$super.init.apply(this,arguments)}),s.init.prototype=s,s.$super=this,s},create:function(){var n=this.extend();return n.init.apply(n,arguments),n},init:function(){},mixIn:function(n){for(var s in n)n.hasOwnProperty(s)&&(this[s]=n[s]);n.hasOwnProperty("toString")&&(this.toString=n.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),g=w.WordArray=y.extend({init:function(n,s){n=this.words=n||[],s!=u?this.sigBytes=s:this.sigBytes=n.length*4},toString:function(n){return(n||f).stringify(this)},concat:function(n){var s=this.words,a=n.words,l=this.sigBytes,m=n.sigBytes;if(this.clamp(),l%4)for(var k=0;k<m;k++){var C=a[k>>>2]>>>24-k%4*8&255;s[l+k>>>2]|=C<<24-(l+k)%4*8}else for(var x=0;x<m;x+=4)s[l+x>>>2]=a[x>>>2];return this.sigBytes+=m,this},clamp:function(){var n=this.words,s=this.sigBytes;n[s>>>2]&=4294967295<<32-s%4*8,n.length=t.ceil(s/4)},clone:function(){var n=y.clone.call(this);return n.words=this.words.slice(0),n},random:function(n){for(var s=[],a=0;a<n;a+=4)s.push(v());return new g.init(s,n)}}),S=p.enc={},f=S.Hex={stringify:function(n){for(var s=n.words,a=n.sigBytes,l=[],m=0;m<a;m++){var k=s[m>>>2]>>>24-m%4*8&255;l.push((k>>>4).toString(16)),l.push((k&15).toString(16))}return l.join("")},parse:function(n){for(var s=n.length,a=[],l=0;l<s;l+=2)a[l>>>3]|=parseInt(n.substr(l,2),16)<<24-l%8*4;return new g.init(a,s/2)}},h=S.Latin1={stringify:function(n){for(var s=n.words,a=n.sigBytes,l=[],m=0;m<a;m++){var k=s[m>>>2]>>>24-m%4*8&255;l.push(String.fromCharCode(k))}return l.join("")},parse:function(n){for(var s=n.length,a=[],l=0;l<s;l++)a[l>>>2]|=(n.charCodeAt(l)&255)<<24-l%4*8;return new g.init(a,s)}},c=S.Utf8={stringify:function(n){try{return decodeURIComponent(escape(h.stringify(n)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(n){return h.parse(unescape(encodeURIComponent(n)))}},d=w.BufferedBlockAlgorithm=y.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(n){typeof n=="string"&&(n=c.parse(n)),this._data.concat(n),this._nDataBytes+=n.sigBytes},_process:function(n){var s,a=this._data,l=a.words,m=a.sigBytes,k=this.blockSize,C=k*4,x=m/C;n?x=t.ceil(x):x=t.max((x|0)-this._minBufferSize,0);var D=x*k,U=t.min(D*4,m);if(D){for(var q=0;q<D;q+=k)this._doProcessBlock(l,q);s=l.splice(0,D),a.sigBytes-=U}return new g.init(s,U)},clone:function(){var n=y.clone.call(this);return n._data=this._data.clone(),n},_minBufferSize:0});w.Hasher=d.extend({cfg:y.extend(),init:function(n){this.cfg=this.cfg.extend(n),this.reset()},reset:function(){d.reset.call(this),this._doReset()},update:function(n){return this._append(n),this._process(),this},finalize:function(n){n&&this._append(n);var s=this._doFinalize();return s},blockSize:16,_createHelper:function(n){return function(s,a){return new n.init(a).finalize(s)}},_createHmacHelper:function(n){return function(s,a){return new A.HMAC.init(n,a).finalize(s)}}});var A=p.algo={};return p}(Math);return r})}(re)),re.exports}(function(o,e){(function(r,t){o.exports=t(le())})(N,function(r){return function(){var t=r,u=t.lib,i=u.WordArray,v=t.enc;v.Base64url={stringify:function(p,w){w===void 0&&(w=!0);var y=p.words,g=p.sigBytes,S=w?this._safe_map:this._map;p.clamp();for(var f=[],h=0;h<g;h+=3)for(var c=y[h>>>2]>>>24-h%4*8&255,d=y[h+1>>>2]>>>24-(h+1)%4*8&255,A=y[h+2>>>2]>>>24-(h+2)%4*8&255,n=c<<16|d<<8|A,s=0;s<4&&h+s*.75<g;s++)f.push(S.charAt(n>>>6*(3-s)&63));var a=S.charAt(64);if(a)for(;f.length%4;)f.push(a);return f.join("")},parse:function(p,w){w===void 0&&(w=!0);var y=p.length,g=w?this._safe_map:this._map,S=this._reverseMap;if(!S){S=this._reverseMap=[];for(var f=0;f<g.length;f++)S[g.charCodeAt(f)]=f}var h=g.charAt(64);if(h){var c=p.indexOf(h);c!==-1&&(y=c)}return b(p,y,S)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function b(p,w,y){for(var g=[],S=0,f=0;f<w;f++)if(f%4){var h=y[p.charCodeAt(f-1)]<<f%4*2,c=y[p.charCodeAt(f)]>>>6-f%4*2,d=h|c;g[S>>>2]|=d<<24-S%4*8,S++}return i.create(g,S)}}(),r.enc.Base64url})})(ue);var _e=ue.exports;const be=ce(_e);var fe={exports:{}};(function(o,e){(function(r,t){o.exports=t(le())})(N,function(r){return function(t){var u=r,i=u.lib,v=i.WordArray,b=i.Hasher,p=u.algo,w=[],y=[];(function(){function f(A){for(var n=t.sqrt(A),s=2;s<=n;s++)if(!(A%s))return!1;return!0}function h(A){return(A-(A|0))*4294967296|0}for(var c=2,d=0;d<64;)f(c)&&(d<8&&(w[d]=h(t.pow(c,1/2))),y[d]=h(t.pow(c,1/3)),d++),c++})();var g=[],S=p.SHA256=b.extend({_doReset:function(){this._hash=new v.init(w.slice(0))},_doProcessBlock:function(f,h){for(var c=this._hash.words,d=c[0],A=c[1],n=c[2],s=c[3],a=c[4],l=c[5],m=c[6],k=c[7],C=0;C<64;C++){if(C<16)g[C]=f[h+C]|0;else{var x=g[C-15],D=(x<<25|x>>>7)^(x<<14|x>>>18)^x>>>3,U=g[C-2],q=(U<<15|U>>>17)^(U<<13|U>>>19)^U>>>10;g[C]=D+g[C-7]+q+g[C-16]}var E=a&l^~a&m,z=d&A^d&n^A&n,L=(d<<30|d>>>2)^(d<<19|d>>>13)^(d<<10|d>>>22),V=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),W=k+V+E+y[C]+g[C],j=L+z;k=m,m=l,l=a,a=s+W|0,s=n,n=A,A=d,d=W+j|0}c[0]=c[0]+d|0,c[1]=c[1]+A|0,c[2]=c[2]+n|0,c[3]=c[3]+s|0,c[4]=c[4]+a|0,c[5]=c[5]+l|0,c[6]=c[6]+m|0,c[7]=c[7]+k|0},_doFinalize:function(){var f=this._data,h=f.words,c=this._nDataBytes*8,d=f.sigBytes*8;return h[d>>>5]|=128<<24-d%32,h[(d+64>>>9<<4)+14]=t.floor(c/4294967296),h[(d+64>>>9<<4)+15]=c,f.sigBytes=h.length*4,this._process(),this._hash},clone:function(){var f=b.clone.call(this);return f._hash=this._hash.clone(),f}});u.SHA256=b._createHelper(S),u.HmacSHA256=b._createHmacHelper(S)}(Math),r.SHA256})})(fe);var Se=fe.exports;const ke=ce(Se),Be=(o,e)=>{const{client_id:r,redirect_uri:t,scope:u,state:i,chainId:v,chain:b,network:p,address:w,signature:y}=o,g=w?{address:w,...y!==void 0?{signature:y}:{},...v!==void 0||b!==void 0?{chain:v?he(v):b}:{},...v!==void 0||p!==void 0?{network:v?pe(v):p}:{}}:{};return Y({client_id:r,redirect_uri:t,...u!==void 0?{scope:u}:{},...i!==void 0?{state:i}:{},code_challenge:e,code_challenge_method:"S256",response_type:"code",...g})},Ce=()=>{let o="";const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=e.length;let t=0;for(;t<128;)o+=e.charAt(Math.floor(Math.random()*r)),t+=1;return o},xe=o=>be.stringify(ke(o)),ie=(o,e)=>{const r=Ce(),t=xe(r);return sessionStorage.setItem(G,r||""),`${o}/auth?${Be(e,t)}`},Ee=()=>{const o=window.location.href,[e,r]=o.split("?");r&&window.history.replaceState(null,"",e)},ae=o=>o.code!=null,Ae=o=>o.refresh_token!=null,Pe=o=>o.client_secret!=null,Oe=async(o,e,r,t)=>{const u=await fetch(`${o}`,{method:e,headers:t,body:r});let i;const v=await u.text();try{i=JSON.parse(v)}catch{throw v}if(!u.ok)throw i;return i},ne=typeof window>"u";var T,J,F,M,$,P,R,K,Q,X;class Ie{constructor(e){H(this,P);H(this,T,void 0);H(this,J,void 0);H(this,F,void 0);H(this,M,void 0);H(this,$,void 0);H(this,K,void 0);H(this,Q,void 0);H(this,X,void 0);if(O(this,M,new Map),this.isAuthorized=!!this.bearerProfile,O(this,K,async(r,t,u)=>{const i=sessionStorage.getItem(G)||"";if(!i)throw new Error("Code verifier not found");return this.codeVerifier=i,sessionStorage.removeItem(G),await this.getBearerToken({code:u,redirect_uri:t,client_id:r,code_verifier:i})}),O(this,Q,async({clientId:r,clientSecret:t})=>await this.getBearerToken({client_id:r,client_secret:t})),O(this,X,async(r,t)=>await this.getBearerToken({refresh_token:t,client_id:r})),this.subscribeToOrderNotifications=()=>{var u,i;const r=`${_(this,T).wss}/profiles/${(u=this.bearerProfile)==null?void 0:u.profile}/orders?access_token=${(i=this.bearerProfile)==null?void 0:i.access_token}`,t=new WebSocket(r);return t.addEventListener("open",()=>{console.info(`Socket connected: ${r}`)}),t.addEventListener("error",v=>{throw console.error(v),new Error(`Socket error: ${r}`)}),t.addEventListener("message",v=>{var p;const b=JSON.parse(v.data);(p=_(this,M).get(b.meta.state))==null||p(b)}),t.addEventListener("close",()=>{console.info(`Socket connection closed: ${r}`)}),t},this.auth=async r=>await this.getBearerToken(r),this.getAuthFlowURI=r=>ie(_(this,T).api,r),this.pkceRequest=r=>this.getAuthFlowURI(r),this.getEnvironment=()=>_(this,T),!e){O(this,T,ee.environments.sandbox);return}if(typeof e=="string")O(this,T,ee.environments[e]);else if(O(this,T,ee.environments[e.env||"sandbox"]),ne){const{clientId:r,clientSecret:t}=e;O(this,$,{clientId:r,clientSecret:t})}else{const{clientId:r,redirectUrl:t}=e;O(this,$,{clientId:r,redirectUrl:t})}}async authorize(e){var i,v;const r=(e==null?void 0:e.clientId)||((i=_(this,$))==null?void 0:i.clientId),t=(e==null?void 0:e.redirectUrl)||((v=_(this,$))==null?void 0:v.redirectUrl);if(!r)throw new Error("Missing ClientId");if(!t)throw new Error("Missing RedirectUrl");const u=ie(_(this,T).api,{client_id:r,redirect_uri:t,...e==null?void 0:e.wallet});window.location.replace(u)}async connect(e){var b,p,w;const r=(e==null?void 0:e.clientId)||((b=_(this,$))==null?void 0:b.clientId);if((e==null?void 0:e.clientSecret)||((p=_(this,$))==null?void 0:p.clientSecret)){if(!ne)throw new Error("Only use client credentials on server side");return await _(this,Q).call(this,_(this,$)),!!this.bearerProfile}const u=(e==null?void 0:e.redirectUrl)||((w=_(this,$))==null?void 0:w.redirectUrl);if(!r)throw new Error("Missing ClientId");if(ne)throw new Error("This only works on client side");const i=new URLSearchParams(window.location.search).get("code")||void 0,v=sessionStorage.getItem(te)||void 0;return i?await _(this,K).call(this,r,u,i):v&&await _(this,X).call(this,r,v),!!this.bearerProfile}async getBearerToken(e){let r;if(ae(e))r={...e,grant_type:"authorization_code"};else if(Ae(e))r={...e,grant_type:"refresh_token"};else if(Pe(e))r={...e,grant_type:"client_credentials"};else throw new Error("Authentication method could not be detected.");return await I(this,P,R).call(this,"post","auth/token",r,!0).then(t=>{var u;this.bearerProfile=t,this.isAuthorized=!!t,O(this,J,`Bearer ${t==null?void 0:t.access_token}`),window.sessionStorage.setItem(te,((u=this.bearerProfile)==null?void 0:u.refresh_token)||"")}).catch(t=>{throw sessionStorage.removeItem(G),sessionStorage.removeItem(te),new Error(t==null?void 0:t.message)}),ae(e)&&Ee(),this.bearerProfile}getAuthContext(){return I(this,P,R).call(this,"get","auth/context")}getProfile(e){return I(this,P,R).call(this,"get",`profiles/${e}`)}getBalances(e){return e?I(this,P,R).call(this,"get",`profiles/${e}/balances`):I(this,P,R).call(this,"get","balances")}getOrders(e){const r=Y(e);return I(this,P,R).call(this,"get",`orders?${r}`)}getOrder(e){return I(this,P,R).call(this,"get",`orders/${e}`)}getTokens(){return I(this,P,R).call(this,"get","tokens")}linkAddress(e,r){return I(this,P,R).call(this,"post",`profiles/${e}/addresses`,JSON.stringify(r))}placeOrder(e,r){const t={...e,kind:"redeem",currency:"eur"};return r?I(this,P,R).call(this,"post",`profiles/${r}/orders`,JSON.stringify(t)):I(this,P,R).call(this,"post","orders",JSON.stringify(t))}uploadSupportingDocument(e){const r=Y(e);return I(this,P,R).call(this,"post","files/supporting-document",r,!0)}async connectOrderSocket(){var e;(e=this.bearerProfile)!=null&&e.access_token&&_(this,M).size>0&&O(this,F,this.subscribeToOrderNotifications())}async disconnect(){var e;sessionStorage.removeItem(G),_(this,M).clear(),(e=_(this,F))==null||e.close()}subscribeOrders(e,r){_(this,M).set(e,r)}unsubscribeOrders(e){var r;_(this,M).delete(e),_(this,M).size===0&&((r=_(this,F))==null||r.close(),O(this,F,void 0))}}T=new WeakMap,J=new WeakMap,F=new WeakMap,M=new WeakMap,$=new WeakMap,P=new WeakSet,R=async function(e,r,t,u){return Oe(`${_(this,T).api}/${r}`,e,u?Y(t):t,{Authorization:_(this,J)||"","Content-Type":`application/${u?"x-www-form-urlencoded":"json"}`})},K=new WeakMap,Q=new WeakMap,X=new WeakMap;const Re=({children:o,clientId:e="f99e629b-6dca-11ee-8aa6-5273f65ed05b",redirectUrl:r="http://localhost:5173"})=>{const[t,u]=B.useState(),[i,v]=B.useState(!1),[b,p]=B.useState(null),[w,y]=B.useState(null),[g,S]=B.useState(!1),[f,h]=B.useState(!1),[c,d]=B.useState(!1),[A,n]=B.useState(!1),[s,a]=B.useState(null),[l,m]=B.useState([]),[k,C]=B.useState([]);B.useEffect(()=>{const E=new Ie({clientId:e,redirectUrl:r});u(E)},[]),B.useEffect(()=>((async()=>{t&&v(await t.connect())})(),()=>{t&&t.disconnect()}),[t]),B.useEffect(()=>{(async()=>{if(t&&i)try{S(!0);const z=await t.getAuthContext(),L=await t.getProfile(z.defaultProfile),V=await t.getBalances(),W=await t.getOrders(),j=await t.getTokens();p(L),y(V),m(W),C(j)}catch(z){console.error("Error fetching data:",z),a(z)}finally{S(!1)}})()},[t,i]);const x=B.useCallback(async()=>{try{t&&await t.authorize()}catch(E){console.error("Error during authorization:",E),a(E)}},[t]),D=B.useCallback(async()=>{if(t&&i)try{n(!0);const E=await t.getBalances();y(E)}catch(E){console.error("Error getting balances:",E),a(E)}finally{n(!1)}},[t,i]),U=B.useCallback(async(E,z)=>{if(t&&i)try{h(!0);let L;parseInt(E.amount)>15e3&&z&&(L=(await t.uploadSupportingDocument(z)).id);const V={...E,documentId:L},W=await t.placeOrder(V);m(j=>[...j,W])}catch(L){console.error("Error placing order:",L),a(L)}finally{h(!1)}},[t,i]),q=B.useCallback(async E=>{if(t&&i&&b)try{return d(!0),await t.linkAddress(b.id,E)}catch(z){console.error("Error linking address:",z),a(z)}finally{d(!1)}},[t,i,b]);return de.jsx(oe.Provider,{value:{authorize:x,isAuthorized:i,profile:b,balances:w,loading:g,loadingPlaceOrder:f,loadingLinkAddress:c,loadingBalances:A,getBalances:D,linkAddress:q,placeOrder:U,orders:l,tokens:k,error:s},children:o})};function ze(){const o=B.useContext(oe);if(o===null)throw new Error("useMonerium must be used within a MoneriumProvider");return o}exports.MoneriumContext=oe;exports.MoneriumProvider=Re;exports.useMonerium=ze;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1138 @@
|
|
|
1
|
+
var ee = (o, e, r) => {
|
|
2
|
+
if (!e.has(o))
|
|
3
|
+
throw TypeError("Cannot " + r);
|
|
4
|
+
};
|
|
5
|
+
var _ = (o, e, r) => (ee(o, e, "read from private field"), r ? r.call(o) : e.get(o)), H = (o, e, r) => {
|
|
6
|
+
if (e.has(o))
|
|
7
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
+
e instanceof WeakSet ? e.add(o) : e.set(o, r);
|
|
9
|
+
}, P = (o, e, r, t) => (ee(o, e, "write to private field"), t ? t.call(o, r) : e.set(o, r), r);
|
|
10
|
+
var O = (o, e, r) => (ee(o, e, "access private method"), r);
|
|
11
|
+
import { jsx as pe } from "react/jsx-runtime";
|
|
12
|
+
import { createContext as ve, useState as z, useEffect as te, useCallback as Y, useContext as ge } from "react";
|
|
13
|
+
const ue = ve(null), Z = (o) => {
|
|
14
|
+
var e;
|
|
15
|
+
return o && ((e = Object.entries(o)) == null ? void 0 : e.length) > 0 ? Object.entries(o).map(
|
|
16
|
+
([r, t]) => `${encodeURIComponent(r)}=${encodeURIComponent(t)}`
|
|
17
|
+
).join("&") : "";
|
|
18
|
+
}, we = (o) => {
|
|
19
|
+
switch (o) {
|
|
20
|
+
case 1:
|
|
21
|
+
case 5:
|
|
22
|
+
return "ethereum";
|
|
23
|
+
case 100:
|
|
24
|
+
case 10200:
|
|
25
|
+
return "gnosis";
|
|
26
|
+
case 137:
|
|
27
|
+
case 80001:
|
|
28
|
+
return "polygon";
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Chain not supported: ${o}`);
|
|
31
|
+
}
|
|
32
|
+
}, ye = (o) => {
|
|
33
|
+
switch (o) {
|
|
34
|
+
case 1:
|
|
35
|
+
case 100:
|
|
36
|
+
case 137:
|
|
37
|
+
return "mainnet";
|
|
38
|
+
case 5:
|
|
39
|
+
return "goerli";
|
|
40
|
+
case 10200:
|
|
41
|
+
return "chiado";
|
|
42
|
+
case 80001:
|
|
43
|
+
return "mumbai";
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Network not supported: ${o}`);
|
|
46
|
+
}
|
|
47
|
+
}, re = {
|
|
48
|
+
environments: {
|
|
49
|
+
production: {
|
|
50
|
+
api: "https://api.monerium.app",
|
|
51
|
+
web: "https://monerium.app",
|
|
52
|
+
wss: "wss://api.monerium.app"
|
|
53
|
+
},
|
|
54
|
+
sandbox: {
|
|
55
|
+
api: "https://api.monerium.dev",
|
|
56
|
+
web: "https://sandbox.monerium.dev",
|
|
57
|
+
wss: "wss://api.monerium.dev"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, G = "monerium.sdk.code_verifier", ne = "monerium.sdk.refresh_token";
|
|
61
|
+
var j = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
62
|
+
function fe(o) {
|
|
63
|
+
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
64
|
+
}
|
|
65
|
+
function me(o) {
|
|
66
|
+
if (o.__esModule)
|
|
67
|
+
return o;
|
|
68
|
+
var e = o.default;
|
|
69
|
+
if (typeof e == "function") {
|
|
70
|
+
var r = function t() {
|
|
71
|
+
if (this instanceof t) {
|
|
72
|
+
var u = [null];
|
|
73
|
+
u.push.apply(u, arguments);
|
|
74
|
+
var i = Function.bind.apply(e, u);
|
|
75
|
+
return new i();
|
|
76
|
+
}
|
|
77
|
+
return e.apply(this, arguments);
|
|
78
|
+
};
|
|
79
|
+
r.prototype = e.prototype;
|
|
80
|
+
} else
|
|
81
|
+
r = {};
|
|
82
|
+
return Object.defineProperty(r, "__esModule", { value: !0 }), Object.keys(o).forEach(function(t) {
|
|
83
|
+
var u = Object.getOwnPropertyDescriptor(o, t);
|
|
84
|
+
Object.defineProperty(r, t, u.get ? u : {
|
|
85
|
+
enumerable: !0,
|
|
86
|
+
get: function() {
|
|
87
|
+
return o[t];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}), r;
|
|
91
|
+
}
|
|
92
|
+
var de = { exports: {} };
|
|
93
|
+
function _e(o) {
|
|
94
|
+
throw new Error('Could not dynamically require "' + o + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
95
|
+
}
|
|
96
|
+
var oe = { exports: {} };
|
|
97
|
+
const be = {}, Be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
98
|
+
__proto__: null,
|
|
99
|
+
default: be
|
|
100
|
+
}, Symbol.toStringTag, { value: "Module" })), ke = /* @__PURE__ */ me(Be);
|
|
101
|
+
var ie;
|
|
102
|
+
function le() {
|
|
103
|
+
return ie || (ie = 1, function(o, e) {
|
|
104
|
+
(function(r, t) {
|
|
105
|
+
o.exports = t();
|
|
106
|
+
})(j, function() {
|
|
107
|
+
var r = r || function(t, u) {
|
|
108
|
+
var i;
|
|
109
|
+
if (typeof window < "u" && window.crypto && (i = window.crypto), typeof self < "u" && self.crypto && (i = self.crypto), typeof globalThis < "u" && globalThis.crypto && (i = globalThis.crypto), !i && typeof window < "u" && window.msCrypto && (i = window.msCrypto), !i && typeof j < "u" && j.crypto && (i = j.crypto), !i && typeof _e == "function")
|
|
110
|
+
try {
|
|
111
|
+
i = ke;
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
var v = function() {
|
|
115
|
+
if (i) {
|
|
116
|
+
if (typeof i.getRandomValues == "function")
|
|
117
|
+
try {
|
|
118
|
+
return i.getRandomValues(new Uint32Array(1))[0];
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
if (typeof i.randomBytes == "function")
|
|
122
|
+
try {
|
|
123
|
+
return i.randomBytes(4).readInt32LE();
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw new Error("Native crypto module could not be used to get secure random number.");
|
|
128
|
+
}, b = Object.create || function() {
|
|
129
|
+
function n() {
|
|
130
|
+
}
|
|
131
|
+
return function(s) {
|
|
132
|
+
var a;
|
|
133
|
+
return n.prototype = s, a = new n(), n.prototype = null, a;
|
|
134
|
+
};
|
|
135
|
+
}(), p = {}, w = p.lib = {}, y = w.Base = function() {
|
|
136
|
+
return {
|
|
137
|
+
/**
|
|
138
|
+
* Creates a new object that inherits from this object.
|
|
139
|
+
*
|
|
140
|
+
* @param {Object} overrides Properties to copy into the new object.
|
|
141
|
+
*
|
|
142
|
+
* @return {Object} The new object.
|
|
143
|
+
*
|
|
144
|
+
* @static
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
*
|
|
148
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
149
|
+
* field: 'value',
|
|
150
|
+
*
|
|
151
|
+
* method: function () {
|
|
152
|
+
* }
|
|
153
|
+
* });
|
|
154
|
+
*/
|
|
155
|
+
extend: function(n) {
|
|
156
|
+
var s = b(this);
|
|
157
|
+
return n && s.mixIn(n), (!s.hasOwnProperty("init") || this.init === s.init) && (s.init = function() {
|
|
158
|
+
s.$super.init.apply(this, arguments);
|
|
159
|
+
}), s.init.prototype = s, s.$super = this, s;
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* Extends this object and runs the init method.
|
|
163
|
+
* Arguments to create() will be passed to init().
|
|
164
|
+
*
|
|
165
|
+
* @return {Object} The new object.
|
|
166
|
+
*
|
|
167
|
+
* @static
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
*
|
|
171
|
+
* var instance = MyType.create();
|
|
172
|
+
*/
|
|
173
|
+
create: function() {
|
|
174
|
+
var n = this.extend();
|
|
175
|
+
return n.init.apply(n, arguments), n;
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* Initializes a newly created object.
|
|
179
|
+
* Override this method to add some logic when your objects are created.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
*
|
|
183
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
184
|
+
* init: function () {
|
|
185
|
+
* // ...
|
|
186
|
+
* }
|
|
187
|
+
* });
|
|
188
|
+
*/
|
|
189
|
+
init: function() {
|
|
190
|
+
},
|
|
191
|
+
/**
|
|
192
|
+
* Copies properties into this object.
|
|
193
|
+
*
|
|
194
|
+
* @param {Object} properties The properties to mix in.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
*
|
|
198
|
+
* MyType.mixIn({
|
|
199
|
+
* field: 'value'
|
|
200
|
+
* });
|
|
201
|
+
*/
|
|
202
|
+
mixIn: function(n) {
|
|
203
|
+
for (var s in n)
|
|
204
|
+
n.hasOwnProperty(s) && (this[s] = n[s]);
|
|
205
|
+
n.hasOwnProperty("toString") && (this.toString = n.toString);
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* Creates a copy of this object.
|
|
209
|
+
*
|
|
210
|
+
* @return {Object} The clone.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
*
|
|
214
|
+
* var clone = instance.clone();
|
|
215
|
+
*/
|
|
216
|
+
clone: function() {
|
|
217
|
+
return this.init.prototype.extend(this);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}(), g = w.WordArray = y.extend({
|
|
221
|
+
/**
|
|
222
|
+
* Initializes a newly created word array.
|
|
223
|
+
*
|
|
224
|
+
* @param {Array} words (Optional) An array of 32-bit words.
|
|
225
|
+
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
*
|
|
229
|
+
* var wordArray = CryptoJS.lib.WordArray.create();
|
|
230
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
|
231
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
|
232
|
+
*/
|
|
233
|
+
init: function(n, s) {
|
|
234
|
+
n = this.words = n || [], s != u ? this.sigBytes = s : this.sigBytes = n.length * 4;
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* Converts this word array to a string.
|
|
238
|
+
*
|
|
239
|
+
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
|
240
|
+
*
|
|
241
|
+
* @return {string} The stringified word array.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
*
|
|
245
|
+
* var string = wordArray + '';
|
|
246
|
+
* var string = wordArray.toString();
|
|
247
|
+
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
248
|
+
*/
|
|
249
|
+
toString: function(n) {
|
|
250
|
+
return (n || d).stringify(this);
|
|
251
|
+
},
|
|
252
|
+
/**
|
|
253
|
+
* Concatenates a word array to this word array.
|
|
254
|
+
*
|
|
255
|
+
* @param {WordArray} wordArray The word array to append.
|
|
256
|
+
*
|
|
257
|
+
* @return {WordArray} This word array.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
*
|
|
261
|
+
* wordArray1.concat(wordArray2);
|
|
262
|
+
*/
|
|
263
|
+
concat: function(n) {
|
|
264
|
+
var s = this.words, a = n.words, f = this.sigBytes, m = n.sigBytes;
|
|
265
|
+
if (this.clamp(), f % 4)
|
|
266
|
+
for (var k = 0; k < m; k++) {
|
|
267
|
+
var C = a[k >>> 2] >>> 24 - k % 4 * 8 & 255;
|
|
268
|
+
s[f + k >>> 2] |= C << 24 - (f + k) % 4 * 8;
|
|
269
|
+
}
|
|
270
|
+
else
|
|
271
|
+
for (var S = 0; S < m; S += 4)
|
|
272
|
+
s[f + S >>> 2] = a[S >>> 2];
|
|
273
|
+
return this.sigBytes += m, this;
|
|
274
|
+
},
|
|
275
|
+
/**
|
|
276
|
+
* Removes insignificant bits.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
*
|
|
280
|
+
* wordArray.clamp();
|
|
281
|
+
*/
|
|
282
|
+
clamp: function() {
|
|
283
|
+
var n = this.words, s = this.sigBytes;
|
|
284
|
+
n[s >>> 2] &= 4294967295 << 32 - s % 4 * 8, n.length = t.ceil(s / 4);
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Creates a copy of this word array.
|
|
288
|
+
*
|
|
289
|
+
* @return {WordArray} The clone.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
*
|
|
293
|
+
* var clone = wordArray.clone();
|
|
294
|
+
*/
|
|
295
|
+
clone: function() {
|
|
296
|
+
var n = y.clone.call(this);
|
|
297
|
+
return n.words = this.words.slice(0), n;
|
|
298
|
+
},
|
|
299
|
+
/**
|
|
300
|
+
* Creates a word array filled with random bytes.
|
|
301
|
+
*
|
|
302
|
+
* @param {number} nBytes The number of random bytes to generate.
|
|
303
|
+
*
|
|
304
|
+
* @return {WordArray} The random word array.
|
|
305
|
+
*
|
|
306
|
+
* @static
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
*
|
|
310
|
+
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
|
311
|
+
*/
|
|
312
|
+
random: function(n) {
|
|
313
|
+
for (var s = [], a = 0; a < n; a += 4)
|
|
314
|
+
s.push(v());
|
|
315
|
+
return new g.init(s, n);
|
|
316
|
+
}
|
|
317
|
+
}), B = p.enc = {}, d = B.Hex = {
|
|
318
|
+
/**
|
|
319
|
+
* Converts a word array to a hex string.
|
|
320
|
+
*
|
|
321
|
+
* @param {WordArray} wordArray The word array.
|
|
322
|
+
*
|
|
323
|
+
* @return {string} The hex string.
|
|
324
|
+
*
|
|
325
|
+
* @static
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
*
|
|
329
|
+
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
330
|
+
*/
|
|
331
|
+
stringify: function(n) {
|
|
332
|
+
for (var s = n.words, a = n.sigBytes, f = [], m = 0; m < a; m++) {
|
|
333
|
+
var k = s[m >>> 2] >>> 24 - m % 4 * 8 & 255;
|
|
334
|
+
f.push((k >>> 4).toString(16)), f.push((k & 15).toString(16));
|
|
335
|
+
}
|
|
336
|
+
return f.join("");
|
|
337
|
+
},
|
|
338
|
+
/**
|
|
339
|
+
* Converts a hex string to a word array.
|
|
340
|
+
*
|
|
341
|
+
* @param {string} hexStr The hex string.
|
|
342
|
+
*
|
|
343
|
+
* @return {WordArray} The word array.
|
|
344
|
+
*
|
|
345
|
+
* @static
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
*
|
|
349
|
+
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
350
|
+
*/
|
|
351
|
+
parse: function(n) {
|
|
352
|
+
for (var s = n.length, a = [], f = 0; f < s; f += 2)
|
|
353
|
+
a[f >>> 3] |= parseInt(n.substr(f, 2), 16) << 24 - f % 8 * 4;
|
|
354
|
+
return new g.init(a, s / 2);
|
|
355
|
+
}
|
|
356
|
+
}, h = B.Latin1 = {
|
|
357
|
+
/**
|
|
358
|
+
* Converts a word array to a Latin1 string.
|
|
359
|
+
*
|
|
360
|
+
* @param {WordArray} wordArray The word array.
|
|
361
|
+
*
|
|
362
|
+
* @return {string} The Latin1 string.
|
|
363
|
+
*
|
|
364
|
+
* @static
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
*
|
|
368
|
+
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
369
|
+
*/
|
|
370
|
+
stringify: function(n) {
|
|
371
|
+
for (var s = n.words, a = n.sigBytes, f = [], m = 0; m < a; m++) {
|
|
372
|
+
var k = s[m >>> 2] >>> 24 - m % 4 * 8 & 255;
|
|
373
|
+
f.push(String.fromCharCode(k));
|
|
374
|
+
}
|
|
375
|
+
return f.join("");
|
|
376
|
+
},
|
|
377
|
+
/**
|
|
378
|
+
* Converts a Latin1 string to a word array.
|
|
379
|
+
*
|
|
380
|
+
* @param {string} latin1Str The Latin1 string.
|
|
381
|
+
*
|
|
382
|
+
* @return {WordArray} The word array.
|
|
383
|
+
*
|
|
384
|
+
* @static
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
*
|
|
388
|
+
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
389
|
+
*/
|
|
390
|
+
parse: function(n) {
|
|
391
|
+
for (var s = n.length, a = [], f = 0; f < s; f++)
|
|
392
|
+
a[f >>> 2] |= (n.charCodeAt(f) & 255) << 24 - f % 4 * 8;
|
|
393
|
+
return new g.init(a, s);
|
|
394
|
+
}
|
|
395
|
+
}, c = B.Utf8 = {
|
|
396
|
+
/**
|
|
397
|
+
* Converts a word array to a UTF-8 string.
|
|
398
|
+
*
|
|
399
|
+
* @param {WordArray} wordArray The word array.
|
|
400
|
+
*
|
|
401
|
+
* @return {string} The UTF-8 string.
|
|
402
|
+
*
|
|
403
|
+
* @static
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
*
|
|
407
|
+
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
408
|
+
*/
|
|
409
|
+
stringify: function(n) {
|
|
410
|
+
try {
|
|
411
|
+
return decodeURIComponent(escape(h.stringify(n)));
|
|
412
|
+
} catch {
|
|
413
|
+
throw new Error("Malformed UTF-8 data");
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
/**
|
|
417
|
+
* Converts a UTF-8 string to a word array.
|
|
418
|
+
*
|
|
419
|
+
* @param {string} utf8Str The UTF-8 string.
|
|
420
|
+
*
|
|
421
|
+
* @return {WordArray} The word array.
|
|
422
|
+
*
|
|
423
|
+
* @static
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
*
|
|
427
|
+
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
|
428
|
+
*/
|
|
429
|
+
parse: function(n) {
|
|
430
|
+
return h.parse(unescape(encodeURIComponent(n)));
|
|
431
|
+
}
|
|
432
|
+
}, l = w.BufferedBlockAlgorithm = y.extend({
|
|
433
|
+
/**
|
|
434
|
+
* Resets this block algorithm's data buffer to its initial state.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
*
|
|
438
|
+
* bufferedBlockAlgorithm.reset();
|
|
439
|
+
*/
|
|
440
|
+
reset: function() {
|
|
441
|
+
this._data = new g.init(), this._nDataBytes = 0;
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
444
|
+
* Adds new data to this block algorithm's buffer.
|
|
445
|
+
*
|
|
446
|
+
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
*
|
|
450
|
+
* bufferedBlockAlgorithm._append('data');
|
|
451
|
+
* bufferedBlockAlgorithm._append(wordArray);
|
|
452
|
+
*/
|
|
453
|
+
_append: function(n) {
|
|
454
|
+
typeof n == "string" && (n = c.parse(n)), this._data.concat(n), this._nDataBytes += n.sigBytes;
|
|
455
|
+
},
|
|
456
|
+
/**
|
|
457
|
+
* Processes available data blocks.
|
|
458
|
+
*
|
|
459
|
+
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
|
460
|
+
*
|
|
461
|
+
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
|
462
|
+
*
|
|
463
|
+
* @return {WordArray} The processed data.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* var processedData = bufferedBlockAlgorithm._process();
|
|
468
|
+
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
469
|
+
*/
|
|
470
|
+
_process: function(n) {
|
|
471
|
+
var s, a = this._data, f = a.words, m = a.sigBytes, k = this.blockSize, C = k * 4, S = m / C;
|
|
472
|
+
n ? S = t.ceil(S) : S = t.max((S | 0) - this._minBufferSize, 0);
|
|
473
|
+
var D = S * k, U = t.min(D * 4, m);
|
|
474
|
+
if (D) {
|
|
475
|
+
for (var F = 0; F < D; F += k)
|
|
476
|
+
this._doProcessBlock(f, F);
|
|
477
|
+
s = f.splice(0, D), a.sigBytes -= U;
|
|
478
|
+
}
|
|
479
|
+
return new g.init(s, U);
|
|
480
|
+
},
|
|
481
|
+
/**
|
|
482
|
+
* Creates a copy of this object.
|
|
483
|
+
*
|
|
484
|
+
* @return {Object} The clone.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
*
|
|
488
|
+
* var clone = bufferedBlockAlgorithm.clone();
|
|
489
|
+
*/
|
|
490
|
+
clone: function() {
|
|
491
|
+
var n = y.clone.call(this);
|
|
492
|
+
return n._data = this._data.clone(), n;
|
|
493
|
+
},
|
|
494
|
+
_minBufferSize: 0
|
|
495
|
+
});
|
|
496
|
+
w.Hasher = l.extend({
|
|
497
|
+
/**
|
|
498
|
+
* Configuration options.
|
|
499
|
+
*/
|
|
500
|
+
cfg: y.extend(),
|
|
501
|
+
/**
|
|
502
|
+
* Initializes a newly created hasher.
|
|
503
|
+
*
|
|
504
|
+
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
*
|
|
508
|
+
* var hasher = CryptoJS.algo.SHA256.create();
|
|
509
|
+
*/
|
|
510
|
+
init: function(n) {
|
|
511
|
+
this.cfg = this.cfg.extend(n), this.reset();
|
|
512
|
+
},
|
|
513
|
+
/**
|
|
514
|
+
* Resets this hasher to its initial state.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* hasher.reset();
|
|
519
|
+
*/
|
|
520
|
+
reset: function() {
|
|
521
|
+
l.reset.call(this), this._doReset();
|
|
522
|
+
},
|
|
523
|
+
/**
|
|
524
|
+
* Updates this hasher with a message.
|
|
525
|
+
*
|
|
526
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
|
527
|
+
*
|
|
528
|
+
* @return {Hasher} This hasher.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
*
|
|
532
|
+
* hasher.update('message');
|
|
533
|
+
* hasher.update(wordArray);
|
|
534
|
+
*/
|
|
535
|
+
update: function(n) {
|
|
536
|
+
return this._append(n), this._process(), this;
|
|
537
|
+
},
|
|
538
|
+
/**
|
|
539
|
+
* Finalizes the hash computation.
|
|
540
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
541
|
+
*
|
|
542
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
|
543
|
+
*
|
|
544
|
+
* @return {WordArray} The hash.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
*
|
|
548
|
+
* var hash = hasher.finalize();
|
|
549
|
+
* var hash = hasher.finalize('message');
|
|
550
|
+
* var hash = hasher.finalize(wordArray);
|
|
551
|
+
*/
|
|
552
|
+
finalize: function(n) {
|
|
553
|
+
n && this._append(n);
|
|
554
|
+
var s = this._doFinalize();
|
|
555
|
+
return s;
|
|
556
|
+
},
|
|
557
|
+
blockSize: 16,
|
|
558
|
+
/**
|
|
559
|
+
* Creates a shortcut function to a hasher's object interface.
|
|
560
|
+
*
|
|
561
|
+
* @param {Hasher} hasher The hasher to create a helper for.
|
|
562
|
+
*
|
|
563
|
+
* @return {Function} The shortcut function.
|
|
564
|
+
*
|
|
565
|
+
* @static
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
*
|
|
569
|
+
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
|
570
|
+
*/
|
|
571
|
+
_createHelper: function(n) {
|
|
572
|
+
return function(s, a) {
|
|
573
|
+
return new n.init(a).finalize(s);
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
/**
|
|
577
|
+
* Creates a shortcut function to the HMAC's object interface.
|
|
578
|
+
*
|
|
579
|
+
* @param {Hasher} hasher The hasher to use in this HMAC helper.
|
|
580
|
+
*
|
|
581
|
+
* @return {Function} The shortcut function.
|
|
582
|
+
*
|
|
583
|
+
* @static
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
*
|
|
587
|
+
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
|
588
|
+
*/
|
|
589
|
+
_createHmacHelper: function(n) {
|
|
590
|
+
return function(s, a) {
|
|
591
|
+
return new A.HMAC.init(n, a).finalize(s);
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
var A = p.algo = {};
|
|
596
|
+
return p;
|
|
597
|
+
}(Math);
|
|
598
|
+
return r;
|
|
599
|
+
});
|
|
600
|
+
}(oe)), oe.exports;
|
|
601
|
+
}
|
|
602
|
+
(function(o, e) {
|
|
603
|
+
(function(r, t) {
|
|
604
|
+
o.exports = t(le());
|
|
605
|
+
})(j, function(r) {
|
|
606
|
+
return function() {
|
|
607
|
+
var t = r, u = t.lib, i = u.WordArray, v = t.enc;
|
|
608
|
+
v.Base64url = {
|
|
609
|
+
/**
|
|
610
|
+
* Converts a word array to a Base64url string.
|
|
611
|
+
*
|
|
612
|
+
* @param {WordArray} wordArray The word array.
|
|
613
|
+
*
|
|
614
|
+
* @param {boolean} urlSafe Whether to use url safe
|
|
615
|
+
*
|
|
616
|
+
* @return {string} The Base64url string.
|
|
617
|
+
*
|
|
618
|
+
* @static
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
*
|
|
622
|
+
* var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
|
|
623
|
+
*/
|
|
624
|
+
stringify: function(p, w) {
|
|
625
|
+
w === void 0 && (w = !0);
|
|
626
|
+
var y = p.words, g = p.sigBytes, B = w ? this._safe_map : this._map;
|
|
627
|
+
p.clamp();
|
|
628
|
+
for (var d = [], h = 0; h < g; h += 3)
|
|
629
|
+
for (var c = y[h >>> 2] >>> 24 - h % 4 * 8 & 255, l = y[h + 1 >>> 2] >>> 24 - (h + 1) % 4 * 8 & 255, A = y[h + 2 >>> 2] >>> 24 - (h + 2) % 4 * 8 & 255, n = c << 16 | l << 8 | A, s = 0; s < 4 && h + s * 0.75 < g; s++)
|
|
630
|
+
d.push(B.charAt(n >>> 6 * (3 - s) & 63));
|
|
631
|
+
var a = B.charAt(64);
|
|
632
|
+
if (a)
|
|
633
|
+
for (; d.length % 4; )
|
|
634
|
+
d.push(a);
|
|
635
|
+
return d.join("");
|
|
636
|
+
},
|
|
637
|
+
/**
|
|
638
|
+
* Converts a Base64url string to a word array.
|
|
639
|
+
*
|
|
640
|
+
* @param {string} base64Str The Base64url string.
|
|
641
|
+
*
|
|
642
|
+
* @param {boolean} urlSafe Whether to use url safe
|
|
643
|
+
*
|
|
644
|
+
* @return {WordArray} The word array.
|
|
645
|
+
*
|
|
646
|
+
* @static
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
*
|
|
650
|
+
* var wordArray = CryptoJS.enc.Base64url.parse(base64String);
|
|
651
|
+
*/
|
|
652
|
+
parse: function(p, w) {
|
|
653
|
+
w === void 0 && (w = !0);
|
|
654
|
+
var y = p.length, g = w ? this._safe_map : this._map, B = this._reverseMap;
|
|
655
|
+
if (!B) {
|
|
656
|
+
B = this._reverseMap = [];
|
|
657
|
+
for (var d = 0; d < g.length; d++)
|
|
658
|
+
B[g.charCodeAt(d)] = d;
|
|
659
|
+
}
|
|
660
|
+
var h = g.charAt(64);
|
|
661
|
+
if (h) {
|
|
662
|
+
var c = p.indexOf(h);
|
|
663
|
+
c !== -1 && (y = c);
|
|
664
|
+
}
|
|
665
|
+
return b(p, y, B);
|
|
666
|
+
},
|
|
667
|
+
_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
668
|
+
_safe_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
669
|
+
};
|
|
670
|
+
function b(p, w, y) {
|
|
671
|
+
for (var g = [], B = 0, d = 0; d < w; d++)
|
|
672
|
+
if (d % 4) {
|
|
673
|
+
var h = y[p.charCodeAt(d - 1)] << d % 4 * 2, c = y[p.charCodeAt(d)] >>> 6 - d % 4 * 2, l = h | c;
|
|
674
|
+
g[B >>> 2] |= l << 24 - B % 4 * 8, B++;
|
|
675
|
+
}
|
|
676
|
+
return i.create(g, B);
|
|
677
|
+
}
|
|
678
|
+
}(), r.enc.Base64url;
|
|
679
|
+
});
|
|
680
|
+
})(de);
|
|
681
|
+
var Ce = de.exports;
|
|
682
|
+
const Se = /* @__PURE__ */ fe(Ce);
|
|
683
|
+
var he = { exports: {} };
|
|
684
|
+
(function(o, e) {
|
|
685
|
+
(function(r, t) {
|
|
686
|
+
o.exports = t(le());
|
|
687
|
+
})(j, function(r) {
|
|
688
|
+
return function(t) {
|
|
689
|
+
var u = r, i = u.lib, v = i.WordArray, b = i.Hasher, p = u.algo, w = [], y = [];
|
|
690
|
+
(function() {
|
|
691
|
+
function d(A) {
|
|
692
|
+
for (var n = t.sqrt(A), s = 2; s <= n; s++)
|
|
693
|
+
if (!(A % s))
|
|
694
|
+
return !1;
|
|
695
|
+
return !0;
|
|
696
|
+
}
|
|
697
|
+
function h(A) {
|
|
698
|
+
return (A - (A | 0)) * 4294967296 | 0;
|
|
699
|
+
}
|
|
700
|
+
for (var c = 2, l = 0; l < 64; )
|
|
701
|
+
d(c) && (l < 8 && (w[l] = h(t.pow(c, 1 / 2))), y[l] = h(t.pow(c, 1 / 3)), l++), c++;
|
|
702
|
+
})();
|
|
703
|
+
var g = [], B = p.SHA256 = b.extend({
|
|
704
|
+
_doReset: function() {
|
|
705
|
+
this._hash = new v.init(w.slice(0));
|
|
706
|
+
},
|
|
707
|
+
_doProcessBlock: function(d, h) {
|
|
708
|
+
for (var c = this._hash.words, l = c[0], A = c[1], n = c[2], s = c[3], a = c[4], f = c[5], m = c[6], k = c[7], C = 0; C < 64; C++) {
|
|
709
|
+
if (C < 16)
|
|
710
|
+
g[C] = d[h + C] | 0;
|
|
711
|
+
else {
|
|
712
|
+
var S = g[C - 15], D = (S << 25 | S >>> 7) ^ (S << 14 | S >>> 18) ^ S >>> 3, U = g[C - 2], F = (U << 15 | U >>> 17) ^ (U << 13 | U >>> 19) ^ U >>> 10;
|
|
713
|
+
g[C] = D + g[C - 7] + F + g[C - 16];
|
|
714
|
+
}
|
|
715
|
+
var x = a & f ^ ~a & m, R = l & A ^ l & n ^ A & n, M = (l << 30 | l >>> 2) ^ (l << 19 | l >>> 13) ^ (l << 10 | l >>> 22), V = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), q = k + V + x + y[C] + g[C], N = M + R;
|
|
716
|
+
k = m, m = f, f = a, a = s + q | 0, s = n, n = A, A = l, l = q + N | 0;
|
|
717
|
+
}
|
|
718
|
+
c[0] = c[0] + l | 0, c[1] = c[1] + A | 0, c[2] = c[2] + n | 0, c[3] = c[3] + s | 0, c[4] = c[4] + a | 0, c[5] = c[5] + f | 0, c[6] = c[6] + m | 0, c[7] = c[7] + k | 0;
|
|
719
|
+
},
|
|
720
|
+
_doFinalize: function() {
|
|
721
|
+
var d = this._data, h = d.words, c = this._nDataBytes * 8, l = d.sigBytes * 8;
|
|
722
|
+
return h[l >>> 5] |= 128 << 24 - l % 32, h[(l + 64 >>> 9 << 4) + 14] = t.floor(c / 4294967296), h[(l + 64 >>> 9 << 4) + 15] = c, d.sigBytes = h.length * 4, this._process(), this._hash;
|
|
723
|
+
},
|
|
724
|
+
clone: function() {
|
|
725
|
+
var d = b.clone.call(this);
|
|
726
|
+
return d._hash = this._hash.clone(), d;
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
u.SHA256 = b._createHelper(B), u.HmacSHA256 = b._createHmacHelper(B);
|
|
730
|
+
}(Math), r.SHA256;
|
|
731
|
+
});
|
|
732
|
+
})(he);
|
|
733
|
+
var xe = he.exports;
|
|
734
|
+
const Ae = /* @__PURE__ */ fe(xe), Ee = (o, e) => {
|
|
735
|
+
const {
|
|
736
|
+
client_id: r,
|
|
737
|
+
redirect_uri: t,
|
|
738
|
+
scope: u,
|
|
739
|
+
state: i,
|
|
740
|
+
chainId: v,
|
|
741
|
+
chain: b,
|
|
742
|
+
network: p,
|
|
743
|
+
address: w,
|
|
744
|
+
signature: y
|
|
745
|
+
} = o, g = w ? {
|
|
746
|
+
address: w,
|
|
747
|
+
...y !== void 0 ? { signature: y } : {},
|
|
748
|
+
...v !== void 0 || b !== void 0 ? { chain: v ? we(v) : b } : {},
|
|
749
|
+
...v !== void 0 || p !== void 0 ? { network: v ? ye(v) : p } : {}
|
|
750
|
+
} : {};
|
|
751
|
+
return Z({
|
|
752
|
+
client_id: r,
|
|
753
|
+
redirect_uri: t,
|
|
754
|
+
...u !== void 0 ? { scope: u } : {},
|
|
755
|
+
...i !== void 0 ? { state: i } : {},
|
|
756
|
+
code_challenge: e,
|
|
757
|
+
code_challenge_method: "S256",
|
|
758
|
+
response_type: "code",
|
|
759
|
+
...g
|
|
760
|
+
});
|
|
761
|
+
}, Pe = () => {
|
|
762
|
+
let o = "";
|
|
763
|
+
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", r = e.length;
|
|
764
|
+
let t = 0;
|
|
765
|
+
for (; t < 128; )
|
|
766
|
+
o += e.charAt(Math.floor(Math.random() * r)), t += 1;
|
|
767
|
+
return o;
|
|
768
|
+
}, Oe = (o) => Se.stringify(Ae(o)), ae = (o, e) => {
|
|
769
|
+
const r = Pe(), t = Oe(r);
|
|
770
|
+
return sessionStorage.setItem(G, r || ""), `${o}/auth?${Ee(e, t)}`;
|
|
771
|
+
}, Ie = () => {
|
|
772
|
+
const o = window.location.href, [e, r] = o.split("?");
|
|
773
|
+
r && window.history.replaceState(null, "", e);
|
|
774
|
+
}, ce = (o) => o.code != null, Re = (o) => o.refresh_token != null, ze = (o) => o.client_secret != null, Te = async (o, e, r, t) => {
|
|
775
|
+
const u = await fetch(`${o}`, {
|
|
776
|
+
method: e,
|
|
777
|
+
headers: t,
|
|
778
|
+
body: r
|
|
779
|
+
});
|
|
780
|
+
let i;
|
|
781
|
+
const v = await u.text();
|
|
782
|
+
try {
|
|
783
|
+
i = JSON.parse(v);
|
|
784
|
+
} catch {
|
|
785
|
+
throw v;
|
|
786
|
+
}
|
|
787
|
+
if (!u.ok)
|
|
788
|
+
throw i;
|
|
789
|
+
return i;
|
|
790
|
+
}, se = typeof window > "u";
|
|
791
|
+
var T, J, W, L, $, E, I, K, Q, X;
|
|
792
|
+
class $e {
|
|
793
|
+
constructor(e) {
|
|
794
|
+
// -- Helper Methods
|
|
795
|
+
H(this, E);
|
|
796
|
+
H(this, T, void 0);
|
|
797
|
+
H(this, J, void 0);
|
|
798
|
+
/** The socket will be available after subscribing to an event */
|
|
799
|
+
H(this, W, void 0);
|
|
800
|
+
H(this, L, void 0);
|
|
801
|
+
H(this, $, void 0);
|
|
802
|
+
H(this, K, void 0);
|
|
803
|
+
H(this, Q, void 0);
|
|
804
|
+
H(this, X, void 0);
|
|
805
|
+
if (P(this, L, /* @__PURE__ */ new Map()), this.isAuthorized = !!this.bearerProfile, P(this, K, async (r, t, u) => {
|
|
806
|
+
const i = sessionStorage.getItem(G) || "";
|
|
807
|
+
if (!i)
|
|
808
|
+
throw new Error("Code verifier not found");
|
|
809
|
+
return this.codeVerifier = i, sessionStorage.removeItem(G), await this.getBearerToken({
|
|
810
|
+
code: u,
|
|
811
|
+
redirect_uri: t,
|
|
812
|
+
client_id: r,
|
|
813
|
+
code_verifier: i
|
|
814
|
+
});
|
|
815
|
+
}), P(this, Q, async ({
|
|
816
|
+
clientId: r,
|
|
817
|
+
clientSecret: t
|
|
818
|
+
}) => await this.getBearerToken({
|
|
819
|
+
client_id: r,
|
|
820
|
+
client_secret: t
|
|
821
|
+
})), P(this, X, async (r, t) => await this.getBearerToken({
|
|
822
|
+
refresh_token: t,
|
|
823
|
+
client_id: r
|
|
824
|
+
})), this.subscribeToOrderNotifications = () => {
|
|
825
|
+
var u, i;
|
|
826
|
+
const r = `${_(this, T).wss}/profiles/${(u = this.bearerProfile) == null ? void 0 : u.profile}/orders?access_token=${(i = this.bearerProfile) == null ? void 0 : i.access_token}`, t = new WebSocket(r);
|
|
827
|
+
return t.addEventListener("open", () => {
|
|
828
|
+
console.info(`Socket connected: ${r}`);
|
|
829
|
+
}), t.addEventListener("error", (v) => {
|
|
830
|
+
throw console.error(v), new Error(`Socket error: ${r}`);
|
|
831
|
+
}), t.addEventListener("message", (v) => {
|
|
832
|
+
var p;
|
|
833
|
+
const b = JSON.parse(v.data);
|
|
834
|
+
(p = _(this, L).get(b.meta.state)) == null || p(
|
|
835
|
+
b
|
|
836
|
+
);
|
|
837
|
+
}), t.addEventListener("close", () => {
|
|
838
|
+
console.info(`Socket connection closed: ${r}`);
|
|
839
|
+
}), t;
|
|
840
|
+
}, this.auth = async (r) => await this.getBearerToken(r), this.getAuthFlowURI = (r) => ae(_(this, T).api, r), this.pkceRequest = (r) => this.getAuthFlowURI(r), this.getEnvironment = () => _(this, T), !e) {
|
|
841
|
+
P(this, T, re.environments.sandbox);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (typeof e == "string")
|
|
845
|
+
P(this, T, re.environments[e]);
|
|
846
|
+
else if (P(this, T, re.environments[e.env || "sandbox"]), se) {
|
|
847
|
+
const { clientId: r, clientSecret: t } = e;
|
|
848
|
+
P(this, $, {
|
|
849
|
+
clientId: r,
|
|
850
|
+
clientSecret: t
|
|
851
|
+
});
|
|
852
|
+
} else {
|
|
853
|
+
const { clientId: r, redirectUrl: t } = e;
|
|
854
|
+
P(this, $, {
|
|
855
|
+
clientId: r,
|
|
856
|
+
redirectUrl: t
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Construct the url to the authorization code flow,
|
|
862
|
+
* Code Verifier needed for the code challenge is stored in session storage
|
|
863
|
+
* For automatic wallet link, add the following properties: `address`, `signature` & `chainId`
|
|
864
|
+
* @returns string
|
|
865
|
+
* {@link https://monerium.dev/api-docs#operation/auth}
|
|
866
|
+
*/
|
|
867
|
+
async authorize(e) {
|
|
868
|
+
var i, v;
|
|
869
|
+
const r = (e == null ? void 0 : e.clientId) || ((i = _(this, $)) == null ? void 0 : i.clientId), t = (e == null ? void 0 : e.redirectUrl) || ((v = _(this, $)) == null ? void 0 : v.redirectUrl);
|
|
870
|
+
if (!r)
|
|
871
|
+
throw new Error("Missing ClientId");
|
|
872
|
+
if (!t)
|
|
873
|
+
throw new Error("Missing RedirectUrl");
|
|
874
|
+
const u = ae(_(this, T).api, {
|
|
875
|
+
client_id: r,
|
|
876
|
+
redirect_uri: t,
|
|
877
|
+
...e == null ? void 0 : e.wallet
|
|
878
|
+
});
|
|
879
|
+
window.location.replace(u);
|
|
880
|
+
}
|
|
881
|
+
// TODO: TEST auto link & manual link + address
|
|
882
|
+
async connect(e) {
|
|
883
|
+
var b, p, w;
|
|
884
|
+
const r = (e == null ? void 0 : e.clientId) || ((b = _(this, $)) == null ? void 0 : b.clientId);
|
|
885
|
+
if ((e == null ? void 0 : e.clientSecret) || ((p = _(this, $)) == null ? void 0 : p.clientSecret)) {
|
|
886
|
+
if (!se)
|
|
887
|
+
throw new Error("Only use client credentials on server side");
|
|
888
|
+
return await _(this, Q).call(this, _(this, $)), !!this.bearerProfile;
|
|
889
|
+
}
|
|
890
|
+
const u = (e == null ? void 0 : e.redirectUrl) || ((w = _(this, $)) == null ? void 0 : w.redirectUrl);
|
|
891
|
+
if (!r)
|
|
892
|
+
throw new Error("Missing ClientId");
|
|
893
|
+
if (se)
|
|
894
|
+
throw new Error("This only works on client side");
|
|
895
|
+
const i = new URLSearchParams(window.location.search).get("code") || void 0, v = sessionStorage.getItem(ne) || void 0;
|
|
896
|
+
return i ? await _(this, K).call(this, r, u, i) : v && await _(this, X).call(this, r, v), !!this.bearerProfile;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* {@link https://monerium.dev/api-docs#operation/auth-token}
|
|
900
|
+
*/
|
|
901
|
+
async getBearerToken(e) {
|
|
902
|
+
let r;
|
|
903
|
+
if (ce(e))
|
|
904
|
+
r = { ...e, grant_type: "authorization_code" };
|
|
905
|
+
else if (Re(e))
|
|
906
|
+
r = { ...e, grant_type: "refresh_token" };
|
|
907
|
+
else if (ze(e))
|
|
908
|
+
r = { ...e, grant_type: "client_credentials" };
|
|
909
|
+
else
|
|
910
|
+
throw new Error("Authentication method could not be detected.");
|
|
911
|
+
return await O(this, E, I).call(this, "post", "auth/token", r, !0).then((t) => {
|
|
912
|
+
var u;
|
|
913
|
+
this.bearerProfile = t, this.isAuthorized = !!t, P(this, J, `Bearer ${t == null ? void 0 : t.access_token}`), window.sessionStorage.setItem(
|
|
914
|
+
ne,
|
|
915
|
+
((u = this.bearerProfile) == null ? void 0 : u.refresh_token) || ""
|
|
916
|
+
);
|
|
917
|
+
}).catch((t) => {
|
|
918
|
+
throw sessionStorage.removeItem(G), sessionStorage.removeItem(ne), new Error(t == null ? void 0 : t.message);
|
|
919
|
+
}), ce(e) && Ie(), this.bearerProfile;
|
|
920
|
+
}
|
|
921
|
+
// -- Read Methods
|
|
922
|
+
/**
|
|
923
|
+
* {@link https://monerium.dev/api-docs#operation/auth-context}
|
|
924
|
+
*/
|
|
925
|
+
getAuthContext() {
|
|
926
|
+
return O(this, E, I).call(this, "get", "auth/context");
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* {@link https://monerium.dev/api-docs#operation/profile}
|
|
930
|
+
* @param {string} profileId - the id of the profile to fetch.
|
|
931
|
+
|
|
932
|
+
*/
|
|
933
|
+
getProfile(e) {
|
|
934
|
+
return O(this, E, I).call(this, "get", `profiles/${e}`);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* {@link https://monerium.dev/api-docs#operation/profile-balances}
|
|
938
|
+
* @param {string=} profileId - the id of the profile to fetch balances.
|
|
939
|
+
*/
|
|
940
|
+
getBalances(e) {
|
|
941
|
+
return e ? O(this, E, I).call(this, "get", `profiles/${e}/balances`) : O(this, E, I).call(this, "get", "balances");
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* {@link https://monerium.dev/api-docs#operation/orders}
|
|
945
|
+
*/
|
|
946
|
+
getOrders(e) {
|
|
947
|
+
const r = Z(e);
|
|
948
|
+
return O(this, E, I).call(this, "get", `orders?${r}`);
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* {@link https://monerium.dev/api-docs#operation/order}
|
|
952
|
+
*/
|
|
953
|
+
getOrder(e) {
|
|
954
|
+
return O(this, E, I).call(this, "get", `orders/${e}`);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* {@link https://monerium.dev/api-docs#operation/tokens}
|
|
958
|
+
*/
|
|
959
|
+
getTokens() {
|
|
960
|
+
return O(this, E, I).call(this, "get", "tokens");
|
|
961
|
+
}
|
|
962
|
+
// -- Write Methods
|
|
963
|
+
/**
|
|
964
|
+
* {@link https://monerium.dev/api-docs#operation/profile-addresses}
|
|
965
|
+
*/
|
|
966
|
+
linkAddress(e, r) {
|
|
967
|
+
return O(this, E, I).call(this, "post", `profiles/${e}/addresses`, JSON.stringify(r));
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* {@link https://monerium.dev/api-docs#operation/post-orders}
|
|
971
|
+
*/
|
|
972
|
+
placeOrder(e, r) {
|
|
973
|
+
const t = { ...e, kind: "redeem", currency: "eur" };
|
|
974
|
+
return r ? O(this, E, I).call(this, "post", `profiles/${r}/orders`, JSON.stringify(t)) : O(this, E, I).call(this, "post", "orders", JSON.stringify(t));
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* {@link https://monerium.dev/api-docs#operation/supporting-document}
|
|
978
|
+
*/
|
|
979
|
+
uploadSupportingDocument(e) {
|
|
980
|
+
const r = Z(
|
|
981
|
+
e
|
|
982
|
+
);
|
|
983
|
+
return O(this, E, I).call(this, "post", "files/supporting-document", r, !0);
|
|
984
|
+
}
|
|
985
|
+
// -- Notifications
|
|
986
|
+
async connectOrderSocket() {
|
|
987
|
+
var e;
|
|
988
|
+
(e = this.bearerProfile) != null && e.access_token && _(this, L).size > 0 && P(this, W, this.subscribeToOrderNotifications());
|
|
989
|
+
}
|
|
990
|
+
async disconnect() {
|
|
991
|
+
var e;
|
|
992
|
+
sessionStorage.removeItem(G), _(this, L).clear(), (e = _(this, W)) == null || e.close();
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Subscribe to MoneriumEvent to receive notifications using the Monerium API (WebSocket)
|
|
996
|
+
* We are setting a subscription map because we need the user to have a token to start the WebSocket connection
|
|
997
|
+
* {@link https://monerium.dev/api-docs#operation/profile-orders-notifications}
|
|
998
|
+
* @param event The event to subscribe to
|
|
999
|
+
* @param handler The handler to be called when the event is triggered
|
|
1000
|
+
*/
|
|
1001
|
+
subscribeOrders(e, r) {
|
|
1002
|
+
_(this, L).set(e, r);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Unsubscribe from MoneriumEvent and close the socket if there are no more subscriptions
|
|
1006
|
+
* @param event The event to unsubscribe from
|
|
1007
|
+
*/
|
|
1008
|
+
unsubscribeOrders(e) {
|
|
1009
|
+
var r;
|
|
1010
|
+
_(this, L).delete(e), _(this, L).size === 0 && ((r = _(this, W)) == null || r.close(), P(this, W, void 0));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
T = new WeakMap(), J = new WeakMap(), W = new WeakMap(), L = new WeakMap(), $ = new WeakMap(), E = new WeakSet(), I = async function(e, r, t, u) {
|
|
1014
|
+
return Te(
|
|
1015
|
+
`${_(this, T).api}/${r}`,
|
|
1016
|
+
e,
|
|
1017
|
+
u ? Z(t) : t,
|
|
1018
|
+
{
|
|
1019
|
+
Authorization: _(this, J) || "",
|
|
1020
|
+
"Content-Type": `application/${u ? "x-www-form-urlencoded" : "json"}`
|
|
1021
|
+
}
|
|
1022
|
+
);
|
|
1023
|
+
}, K = new WeakMap(), Q = new WeakMap(), X = new WeakMap();
|
|
1024
|
+
const Me = ({
|
|
1025
|
+
children: o,
|
|
1026
|
+
clientId: e = "f99e629b-6dca-11ee-8aa6-5273f65ed05b",
|
|
1027
|
+
redirectUrl: r = "http://localhost:5173"
|
|
1028
|
+
}) => {
|
|
1029
|
+
const [t, u] = z(), [i, v] = z(!1), [b, p] = z(null), [w, y] = z(null), [g, B] = z(!1), [d, h] = z(!1), [c, l] = z(!1), [A, n] = z(!1), [s, a] = z(null), [f, m] = z([]), [k, C] = z([]);
|
|
1030
|
+
te(() => {
|
|
1031
|
+
const x = new $e({
|
|
1032
|
+
clientId: e,
|
|
1033
|
+
redirectUrl: r
|
|
1034
|
+
});
|
|
1035
|
+
u(x);
|
|
1036
|
+
}, []), te(() => ((async () => {
|
|
1037
|
+
t && v(await t.connect());
|
|
1038
|
+
})(), () => {
|
|
1039
|
+
t && t.disconnect();
|
|
1040
|
+
}), [t]), te(() => {
|
|
1041
|
+
(async () => {
|
|
1042
|
+
if (t && i)
|
|
1043
|
+
try {
|
|
1044
|
+
B(!0);
|
|
1045
|
+
const R = await t.getAuthContext(), M = await t.getProfile(R.defaultProfile), V = await t.getBalances(), q = await t.getOrders(), N = await t.getTokens();
|
|
1046
|
+
p(M), y(V), m(q), C(N);
|
|
1047
|
+
} catch (R) {
|
|
1048
|
+
console.error("Error fetching data:", R), a(R);
|
|
1049
|
+
} finally {
|
|
1050
|
+
B(!1);
|
|
1051
|
+
}
|
|
1052
|
+
})();
|
|
1053
|
+
}, [t, i]);
|
|
1054
|
+
const S = Y(async () => {
|
|
1055
|
+
try {
|
|
1056
|
+
t && await t.authorize();
|
|
1057
|
+
} catch (x) {
|
|
1058
|
+
console.error("Error during authorization:", x), a(x);
|
|
1059
|
+
}
|
|
1060
|
+
}, [t]), D = Y(async () => {
|
|
1061
|
+
if (t && i)
|
|
1062
|
+
try {
|
|
1063
|
+
n(!0);
|
|
1064
|
+
const x = await t.getBalances();
|
|
1065
|
+
y(x);
|
|
1066
|
+
} catch (x) {
|
|
1067
|
+
console.error("Error getting balances:", x), a(x);
|
|
1068
|
+
} finally {
|
|
1069
|
+
n(!1);
|
|
1070
|
+
}
|
|
1071
|
+
}, [t, i]), U = Y(
|
|
1072
|
+
async (x, R) => {
|
|
1073
|
+
if (t && i)
|
|
1074
|
+
try {
|
|
1075
|
+
h(!0);
|
|
1076
|
+
let M;
|
|
1077
|
+
parseInt(x.amount) > 15e3 && R && (M = (await t.uploadSupportingDocument(
|
|
1078
|
+
R
|
|
1079
|
+
)).id);
|
|
1080
|
+
const V = {
|
|
1081
|
+
...x,
|
|
1082
|
+
documentId: M
|
|
1083
|
+
}, q = await t.placeOrder(V);
|
|
1084
|
+
m((N) => [...N, q]);
|
|
1085
|
+
} catch (M) {
|
|
1086
|
+
console.error("Error placing order:", M), a(M);
|
|
1087
|
+
} finally {
|
|
1088
|
+
h(!1);
|
|
1089
|
+
}
|
|
1090
|
+
},
|
|
1091
|
+
[t, i]
|
|
1092
|
+
), F = Y(
|
|
1093
|
+
async (x) => {
|
|
1094
|
+
if (t && i && b)
|
|
1095
|
+
try {
|
|
1096
|
+
return l(!0), await t.linkAddress(b.id, x);
|
|
1097
|
+
} catch (R) {
|
|
1098
|
+
console.error("Error linking address:", R), a(R);
|
|
1099
|
+
} finally {
|
|
1100
|
+
l(!1);
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
[t, i, b]
|
|
1104
|
+
);
|
|
1105
|
+
return /* @__PURE__ */ pe(
|
|
1106
|
+
ue.Provider,
|
|
1107
|
+
{
|
|
1108
|
+
value: {
|
|
1109
|
+
authorize: S,
|
|
1110
|
+
isAuthorized: i,
|
|
1111
|
+
profile: b,
|
|
1112
|
+
balances: w,
|
|
1113
|
+
loading: g,
|
|
1114
|
+
loadingPlaceOrder: d,
|
|
1115
|
+
loadingLinkAddress: c,
|
|
1116
|
+
loadingBalances: A,
|
|
1117
|
+
getBalances: D,
|
|
1118
|
+
linkAddress: F,
|
|
1119
|
+
placeOrder: U,
|
|
1120
|
+
orders: f,
|
|
1121
|
+
tokens: k,
|
|
1122
|
+
error: s
|
|
1123
|
+
},
|
|
1124
|
+
children: o
|
|
1125
|
+
}
|
|
1126
|
+
);
|
|
1127
|
+
};
|
|
1128
|
+
function De() {
|
|
1129
|
+
const o = ge(ue);
|
|
1130
|
+
if (o === null)
|
|
1131
|
+
throw new Error("useMonerium must be used within a MoneriumProvider");
|
|
1132
|
+
return o;
|
|
1133
|
+
}
|
|
1134
|
+
export {
|
|
1135
|
+
ue as MoneriumContext,
|
|
1136
|
+
Me as MoneriumProvider,
|
|
1137
|
+
De as useMonerium
|
|
1138
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Profile, Balances, LinkAddress, Order, NewOrder, Token } from '@monerium/sdk';
|
|
3
|
+
interface MoneriumContextValue {
|
|
4
|
+
authorize: () => Promise<void>;
|
|
5
|
+
isAuthorized: boolean;
|
|
6
|
+
profile: Profile | null;
|
|
7
|
+
balances: Balances[] | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
loadingPlaceOrder: boolean;
|
|
10
|
+
loadingLinkAddress: boolean;
|
|
11
|
+
loadingBalances: boolean;
|
|
12
|
+
getBalances: () => Promise<void>;
|
|
13
|
+
linkAddress: (addressDetails: LinkAddress) => Promise<unknown>;
|
|
14
|
+
placeOrder: (orderDetails: NewOrder, supportingDocument?: File) => Promise<void>;
|
|
15
|
+
orders: Order[];
|
|
16
|
+
tokens: Token[];
|
|
17
|
+
error: unknown;
|
|
18
|
+
}
|
|
19
|
+
export declare const MoneriumContext: import("react").Context<MoneriumContextValue | null>;
|
|
20
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monerium/sdk-react-provider",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "./index.js",
|
|
5
|
-
"types": "./index.d.ts",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"import": "./index.mjs",
|
|
9
|
-
"require": "./index.js"
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.js"
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
}
|
package/project.json
CHANGED