@monerium/sdk 2.7.3 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.8.0](https://github.com/monerium/js-sdk/compare/sdk-v2.7.3...sdk-v2.8.0) (2023-11-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * add cross-chain typings ([f3b6583](https://github.com/monerium/js-sdk/commit/f3b6583a268e3aeaf31f143ce5fddbb30cb2f32e))
9
+
3
10
  ## [2.7.3](https://github.com/monerium/public-monorepo/compare/sdk-v2.7.3...sdk-v2.7.3) (2023-11-17)
4
11
 
5
12
 
package/README.md CHANGED
@@ -404,8 +404,8 @@ Common questions developers have regarding the SDK.
404
404
 
405
405
  [Support](https://monerium.app/help)
406
406
  [Telegram](https://t.me/+lGtM1gY9zWthNGE8)
407
- [Github Issues](https://github.com/monerium/sdk/issues)
407
+ [Github Issues](https://github.com/monerium/js-sdk/issues)
408
408
 
409
409
  ## Release Notes
410
410
 
411
- https://github.com/monerium/sdk/releases
411
+ https://github.com/monerium/js-sdk/releases
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var w=(e,t,r)=>(Z(e,t,"read from private field"),r?r.call(e):t.get(e)),O=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},I=(e,t,r,n)=>(Z(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var B=(e,t,r)=>(Z(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var se=(e=>(e.eur="eur",e))(se||{}),oe=(e=>(e.corporate="corporate",e.personal="personal",e))(oe||{}),ie=(e=>(e.read="read",e.write="write",e))(ie||{}),ae=(e=>(e.absent="absent",e.submitted="submitted",e.pending="pending",e.confirmed="confirmed",e))(ae||{}),ce=(e=>(e.approved="approved",e.rejected="rejected",e.unknown="unknown",e))(ce||{}),ue=(e=>(e.requested="requested",e.approved="approved",e.pending="pending",e))(ue||{}),de=(e=>(e.iban="iban",e.scan="scan",e))(de||{}),he=(e=>(e.redeem="redeem",e.issue="issue",e))(he||{}),fe=(e=>(e.placed="placed",e.pending="pending",e.processed="processed",e.rejected="rejected",e))(fe||{});const le=e=>{if(e.toString()==="Invalid Date")throw e;const t=n=>n<10?"0"+n:n,r=n=>{if(n===0)return"Z";const u=n>0?"-":"+";return n=Math.abs(n),u+t(Math.floor(n/60))+":"+t(n%60)};return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+r(e.getTimezoneOffset())},ke=(e,t)=>`Send EUR ${e} to ${t} at ${le(new Date)}`,Q=e=>{var t;return e&&((t=Object.entries(e))==null?void 0:t.length)>0?Object.entries(e).map(([r,n])=>`${encodeURIComponent(r)}=${encodeURIComponent(n)}`).join("&"):""},pe=e=>{switch(e){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: ${e}`)}},ve=e=>{switch(e){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: ${e}`)}},K={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"}}},xe="I hereby declare that I am the address owner.",M="monerium.sdk.code_verifier",W="monerium.sdk.refresh_token",Ae={LINK_MESSAGE:xe,STORAGE_CODE_VERIFIER:M,STORAGE_REFRESH_TOKEN:W};var N=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ge(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ee(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var u=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,u.get?u:{enumerable:!0,get:function(){return e[n]}})}),r}var we={exports:{}};function Ie(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var X={exports:{}};const Re={},Oe=Object.freeze(Object.defineProperty({__proto__:null,default:Re},Symbol.toStringTag,{value:"Module"})),Pe=Ee(Oe);var ee;function ye(){return ee||(ee=1,function(e,t){(function(r,n){e.exports=n()})(N,function(){var r=r||function(n,u){var c;if(typeof window<"u"&&window.crypto&&(c=window.crypto),typeof self<"u"&&self.crypto&&(c=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(c=globalThis.crypto),!c&&typeof window<"u"&&window.msCrypto&&(c=window.msCrypto),!c&&typeof N<"u"&&N.crypto&&(c=N.crypto),!c&&typeof Ie=="function")try{c=Pe}catch{}var v=function(){if(c){if(typeof c.getRandomValues=="function")try{return c.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof c.randomBytes=="function")try{return c.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},C=Object.create||function(){function s(){}return function(o){var a;return s.prototype=o,a=new s,s.prototype=null,a}}(),p={},y=p.lib={},m=y.Base=function(){return{extend:function(s){var o=C(this);return s&&o.mixIn(s),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments)}),o.init.prototype=o,o.$super=this,o},create:function(){var s=this.extend();return s.init.apply(s,arguments),s},init:function(){},mixIn:function(s){for(var o in s)s.hasOwnProperty(o)&&(this[o]=s[o]);s.hasOwnProperty("toString")&&(this.toString=s.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),g=y.WordArray=m.extend({init:function(s,o){s=this.words=s||[],o!=u?this.sigBytes=o:this.sigBytes=s.length*4},toString:function(s){return(s||h).stringify(this)},concat:function(s){var o=this.words,a=s.words,d=this.sigBytes,_=s.sigBytes;if(this.clamp(),d%4)for(var S=0;S<_;S++){var k=a[S>>>2]>>>24-S%4*8&255;o[d+S>>>2]|=k<<24-(d+S)%4*8}else for(var x=0;x<_;x+=4)o[d+x>>>2]=a[x>>>2];return this.sigBytes+=_,this},clamp:function(){var s=this.words,o=this.sigBytes;s[o>>>2]&=4294967295<<32-o%4*8,s.length=n.ceil(o/4)},clone:function(){var s=m.clone.call(this);return s.words=this.words.slice(0),s},random:function(s){for(var o=[],a=0;a<s;a+=4)o.push(v());return new g.init(o,s)}}),b=p.enc={},h=b.Hex={stringify:function(s){for(var o=s.words,a=s.sigBytes,d=[],_=0;_<a;_++){var S=o[_>>>2]>>>24-_%4*8&255;d.push((S>>>4).toString(16)),d.push((S&15).toString(16))}return d.join("")},parse:function(s){for(var o=s.length,a=[],d=0;d<o;d+=2)a[d>>>3]|=parseInt(s.substr(d,2),16)<<24-d%8*4;return new g.init(a,o/2)}},l=b.Latin1={stringify:function(s){for(var o=s.words,a=s.sigBytes,d=[],_=0;_<a;_++){var S=o[_>>>2]>>>24-_%4*8&255;d.push(String.fromCharCode(S))}return d.join("")},parse:function(s){for(var o=s.length,a=[],d=0;d<o;d++)a[d>>>2]|=(s.charCodeAt(d)&255)<<24-d%4*8;return new g.init(a,o)}},i=b.Utf8={stringify:function(s){try{return decodeURIComponent(escape(l.stringify(s)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(s){return l.parse(unescape(encodeURIComponent(s)))}},f=y.BufferedBlockAlgorithm=m.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(s){typeof s=="string"&&(s=i.parse(s)),this._data.concat(s),this._nDataBytes+=s.sigBytes},_process:function(s){var o,a=this._data,d=a.words,_=a.sigBytes,S=this.blockSize,k=S*4,x=_/k;s?x=n.ceil(x):x=n.max((x|0)-this._minBufferSize,0);var j=x*S,U=n.min(j*4,_);if(j){for(var F=0;F<j;F+=S)this._doProcessBlock(d,F);o=d.splice(0,j),a.sigBytes-=U}return new g.init(o,U)},clone:function(){var s=m.clone.call(this);return s._data=this._data.clone(),s},_minBufferSize:0});y.Hasher=f.extend({cfg:m.extend(),init:function(s){this.cfg=this.cfg.extend(s),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(s){return this._append(s),this._process(),this},finalize:function(s){s&&this._append(s);var o=this._doFinalize();return o},blockSize:16,_createHelper:function(s){return function(o,a){return new s.init(a).finalize(o)}},_createHmacHelper:function(s){return function(o,a){return new A.HMAC.init(s,a).finalize(o)}}});var A=p.algo={};return p}(Math);return r})}(X)),X.exports}(function(e,t){(function(r,n){e.exports=n(ye())})(N,function(r){return function(){var n=r,u=n.lib,c=u.WordArray,v=n.enc;v.Base64url={stringify:function(p,y){y===void 0&&(y=!0);var m=p.words,g=p.sigBytes,b=y?this._safe_map:this._map;p.clamp();for(var h=[],l=0;l<g;l+=3)for(var i=m[l>>>2]>>>24-l%4*8&255,f=m[l+1>>>2]>>>24-(l+1)%4*8&255,A=m[l+2>>>2]>>>24-(l+2)%4*8&255,s=i<<16|f<<8|A,o=0;o<4&&l+o*.75<g;o++)h.push(b.charAt(s>>>6*(3-o)&63));var a=b.charAt(64);if(a)for(;h.length%4;)h.push(a);return h.join("")},parse:function(p,y){y===void 0&&(y=!0);var m=p.length,g=y?this._safe_map:this._map,b=this._reverseMap;if(!b){b=this._reverseMap=[];for(var h=0;h<g.length;h++)b[g.charCodeAt(h)]=h}var l=g.charAt(64);if(l){var i=p.indexOf(l);i!==-1&&(m=i)}return C(p,m,b)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function C(p,y,m){for(var g=[],b=0,h=0;h<y;h++)if(h%4){var l=m[p.charCodeAt(h-1)]<<h%4*2,i=m[p.charCodeAt(h)]>>>6-h%4*2,f=l|i;g[b>>>2]|=f<<24-b%4*8,b++}return c.create(g,b)}}(),r.enc.Base64url})})(we);var $e=we.exports;const ze=ge($e);var me={exports:{}};(function(e,t){(function(r,n){e.exports=n(ye())})(N,function(r){return function(n){var u=r,c=u.lib,v=c.WordArray,C=c.Hasher,p=u.algo,y=[],m=[];(function(){function h(A){for(var s=n.sqrt(A),o=2;o<=s;o++)if(!(A%o))return!1;return!0}function l(A){return(A-(A|0))*4294967296|0}for(var i=2,f=0;f<64;)h(i)&&(f<8&&(y[f]=l(n.pow(i,1/2))),m[f]=l(n.pow(i,1/3)),f++),i++})();var g=[],b=p.SHA256=C.extend({_doReset:function(){this._hash=new v.init(y.slice(0))},_doProcessBlock:function(h,l){for(var i=this._hash.words,f=i[0],A=i[1],s=i[2],o=i[3],a=i[4],d=i[5],_=i[6],S=i[7],k=0;k<64;k++){if(k<16)g[k]=h[l+k]|0;else{var x=g[k-15],j=(x<<25|x>>>7)^(x<<14|x>>>18)^x>>>3,U=g[k-2],F=(U<<15|U>>>17)^(U<<13|U>>>19)^U>>>10;g[k]=j+g[k-7]+F+g[k-16]}var _e=a&d^~a&_,be=f&A^f&s^A&s,Se=(f<<30|f>>>2)^(f<<19|f>>>13)^(f<<10|f>>>22),Ce=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),Y=S+Ce+_e+m[k]+g[k],Be=Se+be;S=_,_=d,d=a,a=o+Y|0,o=s,s=A,A=f,f=Y+Be|0}i[0]=i[0]+f|0,i[1]=i[1]+A|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+d|0,i[6]=i[6]+_|0,i[7]=i[7]+S|0},_doFinalize:function(){var h=this._data,l=h.words,i=this._nDataBytes*8,f=h.sigBytes*8;return l[f>>>5]|=128<<24-f%32,l[(f+64>>>9<<4)+14]=n.floor(i/4294967296),l[(f+64>>>9<<4)+15]=i,h.sigBytes=l.length*4,this._process(),this._hash},clone:function(){var h=C.clone.call(this);return h._hash=this._hash.clone(),h}});u.SHA256=C._createHelper(b),u.HmacSHA256=C._createHmacHelper(b)}(Math),r.SHA256})})(me);var Ue=me.exports;const He=ge(Ue),Te=(e,t)=>{const{client_id:r,redirect_uri:n,scope:u,state:c,chainId:v,chain:C,network:p,address:y,signature:m}=e,g=y?{address:y,...m!==void 0?{signature:m}:{},...v!==void 0||C!==void 0?{chain:v?pe(v):C}:{},...v!==void 0||p!==void 0?{network:v?ve(v):p}:{}}:{};return Q({client_id:r,redirect_uri:n,...u!==void 0?{scope:u}:{},...c!==void 0?{state:c}:{},code_challenge:t,code_challenge_method:"S256",response_type:"code",...g})},Me=()=>{let e="";const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=t.length;let n=0;for(;n<128;)e+=t.charAt(Math.floor(Math.random()*r)),n+=1;return e},Le=e=>ze.stringify(He(e)),te=(e,t)=>{const r=Me(),n=Le(r);return sessionStorage.setItem(M,r||""),`${e}/auth?${Te(t,n)}`},re=()=>{const e=window.location.href;if(!e||!(e!=null&&e.includes("?")))return;const[t,r]=e.split("?");r&&window.history.replaceState(null,"",t)},ne=e=>e.code!=null,je=e=>e.refresh_token!=null,qe=e=>e.client_secret!=null,Ne=async(e,t,r,n)=>{const u=await fetch(`${e}`,{method:t,headers:n,body:r});let c;const v=await u.text();try{c=JSON.parse(v)}catch{throw v}if(!u.ok)throw c;return c},T=typeof window>"u";var P,D,L,z,$,H,q,E,R,V,G,J;class Fe{constructor(t){O(this,H);O(this,E);O(this,P,void 0);O(this,D,void 0);O(this,L,void 0);O(this,z,void 0);O(this,$,void 0);O(this,V,void 0);O(this,G,void 0);O(this,J,void 0);if(I(this,z,new Map),this.isAuthorized=!!this.bearerProfile,I(this,V,async(r,n,u)=>{const c=sessionStorage.getItem(M)||"";if(!c)throw new Error("Code verifier not found");return this.codeVerifier=c,sessionStorage.removeItem(M),await B(this,H,q).call(this,{code:u,redirect_uri:n,client_id:r,code_verifier:c})}),I(this,G,async({clientId:r,clientSecret:n})=>await B(this,H,q).call(this,{client_id:r,client_secret:n})),I(this,J,async(r,n)=>await B(this,H,q).call(this,{refresh_token:n,client_id:r})),this.subscribeToOrderNotifications=()=>{var u,c;const r=`${w(this,P).wss}/profiles/${(u=this.bearerProfile)==null?void 0:u.profile}/orders?access_token=${(c=this.bearerProfile)==null?void 0:c.access_token}`,n=new WebSocket(r);return n.addEventListener("open",()=>{console.info(`Socket connected: ${r}`)}),n.addEventListener("error",v=>{throw console.error(v),new Error(`Socket error: ${r}`)}),n.addEventListener("message",v=>{var p;const C=JSON.parse(v.data);(p=w(this,z).get(C.meta.state))==null||p(C)}),n.addEventListener("close",()=>{console.info(`Socket connection closed: ${r}`)}),n},this.auth=async r=>await B(this,H,q).call(this,r),this.connect=async r=>await B(this,H,q).call(this,r),this.getAuthFlowURI=r=>{const n=te(w(this,P).api,r);return this.codeVerifier=sessionStorage.getItem(M),n},this.pkceRequest=r=>this.getAuthFlowURI(r),this.getEnvironment=()=>w(this,P),!t){I(this,P,K.environments.sandbox);return}if(typeof t=="string")I(this,P,K.environments[t]);else if(I(this,P,K.environments[t.environment||"sandbox"]),T){const{clientId:r,clientSecret:n}=t;I(this,$,{clientId:r,clientSecret:n})}else{const{clientId:r,redirectUrl:n}=t;I(this,$,{clientId:r,redirectUrl:n})}}async authorize(t){var c,v;const r=(t==null?void 0:t.clientId)||((c=w(this,$))==null?void 0:c.clientId),n=(t==null?void 0:t.redirectUrl)||((v=w(this,$))==null?void 0:v.redirectUrl);if(!r)throw new Error("Missing ClientId");if(!n)throw new Error("Missing RedirectUrl");const u=te(w(this,P).api,{client_id:r,redirect_uri:n,address:t==null?void 0:t.address,signature:t==null?void 0:t.signature,chainId:t==null?void 0:t.chainId});window.location.replace(u)}async getAccess(t){var C,p,y;const r=(t==null?void 0:t.clientId)||((C=w(this,$))==null?void 0:C.clientId);if((t==null?void 0:t.clientSecret)||((p=w(this,$))==null?void 0:p.clientSecret)){if(!T)throw new Error("Only use client credentials on server side");return await w(this,G).call(this,w(this,$)),!!this.bearerProfile}const u=(t==null?void 0:t.redirectUrl)||((y=w(this,$))==null?void 0:y.redirectUrl);if(!r)throw new Error("Missing ClientId");if(T)throw new Error("This only works client side");const c=new URLSearchParams(window.location.search).get("code")||void 0,v=sessionStorage.getItem(W)||void 0;return v?await w(this,J).call(this,r,v):c&&await w(this,V).call(this,r,u,c),!!this.bearerProfile}getAuthContext(){return B(this,E,R).call(this,"get","auth/context")}getProfile(t){return B(this,E,R).call(this,"get",`profiles/${t}`)}getBalances(t){return t?B(this,E,R).call(this,"get",`profiles/${t}/balances`):B(this,E,R).call(this,"get","balances")}getOrders(t){const r=Q(t);return B(this,E,R).call(this,"get",`orders?${r}`)}getOrder(t){return B(this,E,R).call(this,"get",`orders/${t}`)}getTokens(){return B(this,E,R).call(this,"get","tokens")}linkAddress(t,r){return B(this,E,R).call(this,"post",`profiles/${t}/addresses`,JSON.stringify(r))}placeOrder(t,r){const n={...t,kind:"redeem",currency:"eur"};return r?B(this,E,R).call(this,"post",`profiles/${r}/orders`,JSON.stringify(n)):B(this,E,R).call(this,"post","orders",JSON.stringify(n))}uploadSupportingDocument(t){const r=Q(t);return B(this,E,R).call(this,"post","files/supporting-document",r,!0)}async connectOrderSocket(){var t;(t=this.bearerProfile)!=null&&t.access_token&&w(this,z).size>0&&I(this,L,this.subscribeToOrderNotifications())}async disconnect(){var t;T||sessionStorage.removeItem(M),w(this,z).clear(),(t=w(this,L))==null||t.close()}async revokeAccess(){T||sessionStorage.removeItem(W),this.disconnect()}subscribeOrders(t,r){w(this,z).set(t,r)}unsubscribeOrders(t){var r;w(this,z).delete(t),w(this,z).size===0&&((r=w(this,L))==null||r.close(),I(this,L,void 0))}}P=new WeakMap,D=new WeakMap,L=new WeakMap,z=new WeakMap,$=new WeakMap,H=new WeakSet,q=async function(t){let r;if(ne(t))r={...t,grant_type:"authorization_code"};else if(je(t))r={...t,grant_type:"refresh_token"};else if(qe(t))r={...t,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await B(this,E,R).call(this,"post","auth/token",r,!0).then(n=>{var u;this.bearerProfile=n,this.isAuthorized=!!n,I(this,D,`Bearer ${n==null?void 0:n.access_token}`),T||window.sessionStorage.setItem(W,((u=this.bearerProfile)==null?void 0:u.refresh_token)||"")}).catch(n=>{throw T||(sessionStorage.removeItem(M),sessionStorage.removeItem(W),re()),new Error(n==null?void 0:n.message)}),ne(t)&&re(),this.bearerProfile},E=new WeakSet,R=async function(t,r,n,u){return Ne(`${w(this,P).api}/${r}`,t,u?Q(n):n,{Authorization:w(this,D)||"","Content-Type":`application/${u?"x-www-form-urlencoded":"json"}`})},V=new WeakMap,G=new WeakMap,J=new WeakMap;exports.AccountState=ue;exports.Currency=se;exports.KYCOutcome=ce;exports.KYCState=ae;exports.MoneriumClient=Fe;exports.OrderKind=he;exports.OrderState=fe;exports.PaymentStandard=de;exports.Permission=ie;exports.ProfileType=oe;exports.constants=Ae;exports.getChain=pe;exports.getNetwork=ve;exports.placeOrderMessage=ke;exports.rfc3339=le;
1
+ "use strict";var Z=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var w=(e,t,r)=>(Z(e,t,"read from private field"),r?r.call(e):t.get(e)),$=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},I=(e,t,r,n)=>(Z(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var B=(e,t,r)=>(Z(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ie=(e=>(e.eur="eur",e))(ie||{}),ae=(e=>(e.corporate="corporate",e.personal="personal",e))(ae||{}),ce=(e=>(e.read="read",e.write="write",e))(ce||{}),ue=(e=>(e.absent="absent",e.submitted="submitted",e.pending="pending",e.confirmed="confirmed",e))(ue||{}),he=(e=>(e.approved="approved",e.rejected="rejected",e.unknown="unknown",e))(he||{}),de=(e=>(e.requested="requested",e.approved="approved",e.pending="pending",e))(de||{}),fe=(e=>(e.iban="iban",e.scan="scan",e.chain="chain",e))(fe||{}),le=(e=>(e.redeem="redeem",e.issue="issue",e))(le||{}),pe=(e=>(e.placed="placed",e.pending="pending",e.processed="processed",e.rejected="rejected",e))(pe||{});const Y=e=>{if(e.toString()==="Invalid Date")throw e;const t=n=>n<10?"0"+n:n,r=n=>{if(n===0)return"Z";const u=n>0?"-":"+";return n=Math.abs(n),u+t(Math.floor(n/60))+":"+t(n%60)};return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+r(e.getTimezoneOffset())},ke=(e,t,r)=>r?`Send EUR ${e} to ${t} on ${ee(r)} at ${Y(new Date)}`:`Send EUR ${e} to ${t} at ${Y(new Date)}`,Q=e=>{var t;return e&&((t=Object.entries(e))==null?void 0:t.length)>0?Object.entries(e).map(([r,n])=>`${encodeURIComponent(r)}=${encodeURIComponent(n)}`).join("&"):""},ee=e=>{switch(e){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: ${e}`)}},ve=e=>{switch(e){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: ${e}`)}},K={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"}}},xe="I hereby declare that I am the address owner.",M="monerium.sdk.code_verifier",W="monerium.sdk.refresh_token",Ae={LINK_MESSAGE:xe,STORAGE_CODE_VERIFIER:M,STORAGE_REFRESH_TOKEN:W};var N=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ge(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ee(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var u=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,u.get?u:{enumerable:!0,get:function(){return e[n]}})}),r}var we={exports:{}};function Ie(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var X={exports:{}};const Re={},$e=Object.freeze(Object.defineProperty({__proto__:null,default:Re},Symbol.toStringTag,{value:"Module"})),Oe=Ee($e);var re;function ye(){return re||(re=1,function(e,t){(function(r,n){e.exports=n()})(N,function(){var r=r||function(n,u){var c;if(typeof window<"u"&&window.crypto&&(c=window.crypto),typeof self<"u"&&self.crypto&&(c=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(c=globalThis.crypto),!c&&typeof window<"u"&&window.msCrypto&&(c=window.msCrypto),!c&&typeof N<"u"&&N.crypto&&(c=N.crypto),!c&&typeof Ie=="function")try{c=Oe}catch{}var v=function(){if(c){if(typeof c.getRandomValues=="function")try{return c.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof c.randomBytes=="function")try{return c.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},C=Object.create||function(){function s(){}return function(o){var a;return s.prototype=o,a=new s,s.prototype=null,a}}(),p={},y=p.lib={},m=y.Base=function(){return{extend:function(s){var o=C(this);return s&&o.mixIn(s),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments)}),o.init.prototype=o,o.$super=this,o},create:function(){var s=this.extend();return s.init.apply(s,arguments),s},init:function(){},mixIn:function(s){for(var o in s)s.hasOwnProperty(o)&&(this[o]=s[o]);s.hasOwnProperty("toString")&&(this.toString=s.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),g=y.WordArray=m.extend({init:function(s,o){s=this.words=s||[],o!=u?this.sigBytes=o:this.sigBytes=s.length*4},toString:function(s){return(s||d).stringify(this)},concat:function(s){var o=this.words,a=s.words,h=this.sigBytes,_=s.sigBytes;if(this.clamp(),h%4)for(var S=0;S<_;S++){var k=a[S>>>2]>>>24-S%4*8&255;o[h+S>>>2]|=k<<24-(h+S)%4*8}else for(var x=0;x<_;x+=4)o[h+x>>>2]=a[x>>>2];return this.sigBytes+=_,this},clamp:function(){var s=this.words,o=this.sigBytes;s[o>>>2]&=4294967295<<32-o%4*8,s.length=n.ceil(o/4)},clone:function(){var s=m.clone.call(this);return s.words=this.words.slice(0),s},random:function(s){for(var o=[],a=0;a<s;a+=4)o.push(v());return new g.init(o,s)}}),b=p.enc={},d=b.Hex={stringify:function(s){for(var o=s.words,a=s.sigBytes,h=[],_=0;_<a;_++){var S=o[_>>>2]>>>24-_%4*8&255;h.push((S>>>4).toString(16)),h.push((S&15).toString(16))}return h.join("")},parse:function(s){for(var o=s.length,a=[],h=0;h<o;h+=2)a[h>>>3]|=parseInt(s.substr(h,2),16)<<24-h%8*4;return new g.init(a,o/2)}},l=b.Latin1={stringify:function(s){for(var o=s.words,a=s.sigBytes,h=[],_=0;_<a;_++){var S=o[_>>>2]>>>24-_%4*8&255;h.push(String.fromCharCode(S))}return h.join("")},parse:function(s){for(var o=s.length,a=[],h=0;h<o;h++)a[h>>>2]|=(s.charCodeAt(h)&255)<<24-h%4*8;return new g.init(a,o)}},i=b.Utf8={stringify:function(s){try{return decodeURIComponent(escape(l.stringify(s)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(s){return l.parse(unescape(encodeURIComponent(s)))}},f=y.BufferedBlockAlgorithm=m.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(s){typeof s=="string"&&(s=i.parse(s)),this._data.concat(s),this._nDataBytes+=s.sigBytes},_process:function(s){var o,a=this._data,h=a.words,_=a.sigBytes,S=this.blockSize,k=S*4,x=_/k;s?x=n.ceil(x):x=n.max((x|0)-this._minBufferSize,0);var j=x*S,U=n.min(j*4,_);if(j){for(var F=0;F<j;F+=S)this._doProcessBlock(h,F);o=h.splice(0,j),a.sigBytes-=U}return new g.init(o,U)},clone:function(){var s=m.clone.call(this);return s._data=this._data.clone(),s},_minBufferSize:0});y.Hasher=f.extend({cfg:m.extend(),init:function(s){this.cfg=this.cfg.extend(s),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(s){return this._append(s),this._process(),this},finalize:function(s){s&&this._append(s);var o=this._doFinalize();return o},blockSize:16,_createHelper:function(s){return function(o,a){return new s.init(a).finalize(o)}},_createHmacHelper:function(s){return function(o,a){return new A.HMAC.init(s,a).finalize(o)}}});var A=p.algo={};return p}(Math);return r})}(X)),X.exports}(function(e,t){(function(r,n){e.exports=n(ye())})(N,function(r){return function(){var n=r,u=n.lib,c=u.WordArray,v=n.enc;v.Base64url={stringify:function(p,y){y===void 0&&(y=!0);var m=p.words,g=p.sigBytes,b=y?this._safe_map:this._map;p.clamp();for(var d=[],l=0;l<g;l+=3)for(var i=m[l>>>2]>>>24-l%4*8&255,f=m[l+1>>>2]>>>24-(l+1)%4*8&255,A=m[l+2>>>2]>>>24-(l+2)%4*8&255,s=i<<16|f<<8|A,o=0;o<4&&l+o*.75<g;o++)d.push(b.charAt(s>>>6*(3-o)&63));var a=b.charAt(64);if(a)for(;d.length%4;)d.push(a);return d.join("")},parse:function(p,y){y===void 0&&(y=!0);var m=p.length,g=y?this._safe_map:this._map,b=this._reverseMap;if(!b){b=this._reverseMap=[];for(var d=0;d<g.length;d++)b[g.charCodeAt(d)]=d}var l=g.charAt(64);if(l){var i=p.indexOf(l);i!==-1&&(m=i)}return C(p,m,b)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function C(p,y,m){for(var g=[],b=0,d=0;d<y;d++)if(d%4){var l=m[p.charCodeAt(d-1)]<<d%4*2,i=m[p.charCodeAt(d)]>>>6-d%4*2,f=l|i;g[b>>>2]|=f<<24-b%4*8,b++}return c.create(g,b)}}(),r.enc.Base64url})})(we);var Pe=we.exports;const ze=ge(Pe);var me={exports:{}};(function(e,t){(function(r,n){e.exports=n(ye())})(N,function(r){return function(n){var u=r,c=u.lib,v=c.WordArray,C=c.Hasher,p=u.algo,y=[],m=[];(function(){function d(A){for(var s=n.sqrt(A),o=2;o<=s;o++)if(!(A%o))return!1;return!0}function l(A){return(A-(A|0))*4294967296|0}for(var i=2,f=0;f<64;)d(i)&&(f<8&&(y[f]=l(n.pow(i,1/2))),m[f]=l(n.pow(i,1/3)),f++),i++})();var g=[],b=p.SHA256=C.extend({_doReset:function(){this._hash=new v.init(y.slice(0))},_doProcessBlock:function(d,l){for(var i=this._hash.words,f=i[0],A=i[1],s=i[2],o=i[3],a=i[4],h=i[5],_=i[6],S=i[7],k=0;k<64;k++){if(k<16)g[k]=d[l+k]|0;else{var x=g[k-15],j=(x<<25|x>>>7)^(x<<14|x>>>18)^x>>>3,U=g[k-2],F=(U<<15|U>>>17)^(U<<13|U>>>19)^U>>>10;g[k]=j+g[k-7]+F+g[k-16]}var _e=a&h^~a&_,be=f&A^f&s^A&s,Se=(f<<30|f>>>2)^(f<<19|f>>>13)^(f<<10|f>>>22),Ce=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),te=S+Ce+_e+m[k]+g[k],Be=Se+be;S=_,_=h,h=a,a=o+te|0,o=s,s=A,A=f,f=te+Be|0}i[0]=i[0]+f|0,i[1]=i[1]+A|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+h|0,i[6]=i[6]+_|0,i[7]=i[7]+S|0},_doFinalize:function(){var d=this._data,l=d.words,i=this._nDataBytes*8,f=d.sigBytes*8;return l[f>>>5]|=128<<24-f%32,l[(f+64>>>9<<4)+14]=n.floor(i/4294967296),l[(f+64>>>9<<4)+15]=i,d.sigBytes=l.length*4,this._process(),this._hash},clone:function(){var d=C.clone.call(this);return d._hash=this._hash.clone(),d}});u.SHA256=C._createHelper(b),u.HmacSHA256=C._createHmacHelper(b)}(Math),r.SHA256})})(me);var Ue=me.exports;const He=ge(Ue),Te=(e,t)=>{const{client_id:r,redirect_uri:n,scope:u,state:c,chainId:v,chain:C,network:p,address:y,signature:m}=e,g=y?{address:y,...m!==void 0?{signature:m}:{},...v!==void 0||C!==void 0?{chain:v?ee(v):C}:{},...v!==void 0||p!==void 0?{network:v?ve(v):p}:{}}:{};return Q({client_id:r,redirect_uri:n,...u!==void 0?{scope:u}:{},...c!==void 0?{state:c}:{},code_challenge:t,code_challenge_method:"S256",response_type:"code",...g})},Me=()=>{let e="";const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=t.length;let n=0;for(;n<128;)e+=t.charAt(Math.floor(Math.random()*r)),n+=1;return e},Le=e=>ze.stringify(He(e)),ne=(e,t)=>{const r=Me(),n=Le(r);return sessionStorage.setItem(M,r||""),`${e}/auth?${Te(t,n)}`},se=()=>{const e=window.location.href;if(!e||!(e!=null&&e.includes("?")))return;const[t,r]=e.split("?");r&&window.history.replaceState(null,"",t)},oe=e=>e.code!=null,je=e=>e.refresh_token!=null,qe=e=>e.client_secret!=null,Ne=async(e,t,r,n)=>{const u=await fetch(`${e}`,{method:t,headers:n,body:r});let c;const v=await u.text();try{c=JSON.parse(v)}catch{throw v}if(!u.ok)throw c;return c},T=typeof window>"u";var O,D,L,z,P,H,q,E,R,V,G,J;class Fe{constructor(t){$(this,H);$(this,E);$(this,O,void 0);$(this,D,void 0);$(this,L,void 0);$(this,z,void 0);$(this,P,void 0);$(this,V,void 0);$(this,G,void 0);$(this,J,void 0);if(I(this,z,new Map),this.isAuthorized=!!this.bearerProfile,I(this,V,async(r,n,u)=>{const c=sessionStorage.getItem(M)||"";if(!c)throw new Error("Code verifier not found");return this.codeVerifier=c,sessionStorage.removeItem(M),await B(this,H,q).call(this,{code:u,redirect_uri:n,client_id:r,code_verifier:c})}),I(this,G,async({clientId:r,clientSecret:n})=>await B(this,H,q).call(this,{client_id:r,client_secret:n})),I(this,J,async(r,n)=>await B(this,H,q).call(this,{refresh_token:n,client_id:r})),this.subscribeToOrderNotifications=()=>{var u,c;const r=`${w(this,O).wss}/profiles/${(u=this.bearerProfile)==null?void 0:u.profile}/orders?access_token=${(c=this.bearerProfile)==null?void 0:c.access_token}`,n=new WebSocket(r);return n.addEventListener("open",()=>{console.info(`Socket connected: ${r}`)}),n.addEventListener("error",v=>{throw console.error(v),new Error(`Socket error: ${r}`)}),n.addEventListener("message",v=>{var p;const C=JSON.parse(v.data);(p=w(this,z).get(C.meta.state))==null||p(C)}),n.addEventListener("close",()=>{console.info(`Socket connection closed: ${r}`)}),n},this.auth=async r=>await B(this,H,q).call(this,r),this.connect=async r=>await B(this,H,q).call(this,r),this.getAuthFlowURI=r=>{const n=ne(w(this,O).api,r);return this.codeVerifier=sessionStorage.getItem(M),n},this.pkceRequest=r=>this.getAuthFlowURI(r),this.getEnvironment=()=>w(this,O),!t){I(this,O,K.environments.sandbox);return}if(typeof t=="string")I(this,O,K.environments[t]);else if(I(this,O,K.environments[t.environment||"sandbox"]),T){const{clientId:r,clientSecret:n}=t;I(this,P,{clientId:r,clientSecret:n})}else{const{clientId:r,redirectUrl:n}=t;I(this,P,{clientId:r,redirectUrl:n})}}async authorize(t){var c,v;const r=(t==null?void 0:t.clientId)||((c=w(this,P))==null?void 0:c.clientId),n=(t==null?void 0:t.redirectUrl)||((v=w(this,P))==null?void 0:v.redirectUrl);if(!r)throw new Error("Missing ClientId");if(!n)throw new Error("Missing RedirectUrl");const u=ne(w(this,O).api,{client_id:r,redirect_uri:n,address:t==null?void 0:t.address,signature:t==null?void 0:t.signature,chainId:t==null?void 0:t.chainId});window.location.replace(u)}async getAccess(t){var C,p,y;const r=(t==null?void 0:t.clientId)||((C=w(this,P))==null?void 0:C.clientId);if((t==null?void 0:t.clientSecret)||((p=w(this,P))==null?void 0:p.clientSecret)){if(!T)throw new Error("Only use client credentials on server side");return await w(this,G).call(this,w(this,P)),!!this.bearerProfile}const u=(t==null?void 0:t.redirectUrl)||((y=w(this,P))==null?void 0:y.redirectUrl);if(!r)throw new Error("Missing ClientId");if(T)throw new Error("This only works client side");const c=new URLSearchParams(window.location.search).get("code")||void 0,v=sessionStorage.getItem(W)||void 0;return v?await w(this,J).call(this,r,v):c&&await w(this,V).call(this,r,u,c),!!this.bearerProfile}getAuthContext(){return B(this,E,R).call(this,"get","auth/context")}getProfile(t){return B(this,E,R).call(this,"get",`profiles/${t}`)}getBalances(t){return t?B(this,E,R).call(this,"get",`profiles/${t}/balances`):B(this,E,R).call(this,"get","balances")}getOrders(t){const r=Q(t);return B(this,E,R).call(this,"get",`orders?${r}`)}getOrder(t){return B(this,E,R).call(this,"get",`orders/${t}`)}getTokens(){return B(this,E,R).call(this,"get","tokens")}linkAddress(t,r){return B(this,E,R).call(this,"post",`profiles/${t}/addresses`,JSON.stringify(r))}placeOrder(t,r){const n={...t,kind:"redeem",currency:"eur"};return r?B(this,E,R).call(this,"post",`profiles/${r}/orders`,JSON.stringify(n)):B(this,E,R).call(this,"post","orders",JSON.stringify(n))}uploadSupportingDocument(t){const r=Q(t);return B(this,E,R).call(this,"post","files/supporting-document",r,!0)}async connectOrderSocket(){var t;(t=this.bearerProfile)!=null&&t.access_token&&w(this,z).size>0&&I(this,L,this.subscribeToOrderNotifications())}async disconnect(){var t;T||sessionStorage.removeItem(M),w(this,z).clear(),(t=w(this,L))==null||t.close()}async revokeAccess(){T||sessionStorage.removeItem(W),this.disconnect()}subscribeOrders(t,r){w(this,z).set(t,r)}unsubscribeOrders(t){var r;w(this,z).delete(t),w(this,z).size===0&&((r=w(this,L))==null||r.close(),I(this,L,void 0))}}O=new WeakMap,D=new WeakMap,L=new WeakMap,z=new WeakMap,P=new WeakMap,H=new WeakSet,q=async function(t){let r;if(oe(t))r={...t,grant_type:"authorization_code"};else if(je(t))r={...t,grant_type:"refresh_token"};else if(qe(t))r={...t,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await B(this,E,R).call(this,"post","auth/token",r,!0).then(n=>{var u;this.bearerProfile=n,this.isAuthorized=!!n,I(this,D,`Bearer ${n==null?void 0:n.access_token}`),T||window.sessionStorage.setItem(W,((u=this.bearerProfile)==null?void 0:u.refresh_token)||"")}).catch(n=>{throw T||(sessionStorage.removeItem(M),sessionStorage.removeItem(W),se()),new Error(n==null?void 0:n.message)}),oe(t)&&se(),this.bearerProfile},E=new WeakSet,R=async function(t,r,n,u){return Ne(`${w(this,O).api}/${r}`,t,u?Q(n):n,{Authorization:w(this,D)||"","Content-Type":`application/${u?"x-www-form-urlencoded":"json"}`})},V=new WeakMap,G=new WeakMap,J=new WeakMap;exports.AccountState=de;exports.Currency=ie;exports.KYCOutcome=he;exports.KYCState=ue;exports.MoneriumClient=Fe;exports.OrderKind=le;exports.OrderState=pe;exports.PaymentStandard=fe;exports.Permission=ce;exports.ProfileType=ae;exports.constants=Ae;exports.getChain=ee;exports.getNetwork=ve;exports.placeOrderMessage=ke;exports.rfc3339=Y;
package/dist/index.mjs CHANGED
@@ -8,8 +8,8 @@ var w = (e, t, r) => (Z(e, t, "read from private field"), r ? r.call(e) : t.get(
8
8
  t instanceof WeakSet ? t.add(e) : t.set(e, r);
9
9
  }, I = (e, t, r, n) => (Z(e, t, "write to private field"), n ? n.call(e, r) : t.set(e, r), r);
10
10
  var k = (e, t, r) => (Z(e, t, "access private method"), r);
11
- var le = /* @__PURE__ */ ((e) => (e.eur = "eur", e))(le || {}), pe = /* @__PURE__ */ ((e) => (e.corporate = "corporate", e.personal = "personal", e))(pe || {}), ve = /* @__PURE__ */ ((e) => (e.read = "read", e.write = "write", e))(ve || {}), ge = /* @__PURE__ */ ((e) => (e.absent = "absent", e.submitted = "submitted", e.pending = "pending", e.confirmed = "confirmed", e))(ge || {}), we = /* @__PURE__ */ ((e) => (e.approved = "approved", e.rejected = "rejected", e.unknown = "unknown", e))(we || {}), ye = /* @__PURE__ */ ((e) => (e.requested = "requested", e.approved = "approved", e.pending = "pending", e))(ye || {}), me = /* @__PURE__ */ ((e) => (e.iban = "iban", e.scan = "scan", e))(me || {}), _e = /* @__PURE__ */ ((e) => (e.redeem = "redeem", e.issue = "issue", e))(_e || {}), be = /* @__PURE__ */ ((e) => (e.placed = "placed", e.pending = "pending", e.processed = "processed", e.rejected = "rejected", e))(be || {});
12
- const Se = (e) => {
11
+ var ve = /* @__PURE__ */ ((e) => (e.eur = "eur", e))(ve || {}), ge = /* @__PURE__ */ ((e) => (e.corporate = "corporate", e.personal = "personal", e))(ge || {}), we = /* @__PURE__ */ ((e) => (e.read = "read", e.write = "write", e))(we || {}), ye = /* @__PURE__ */ ((e) => (e.absent = "absent", e.submitted = "submitted", e.pending = "pending", e.confirmed = "confirmed", e))(ye || {}), me = /* @__PURE__ */ ((e) => (e.approved = "approved", e.rejected = "rejected", e.unknown = "unknown", e))(me || {}), _e = /* @__PURE__ */ ((e) => (e.requested = "requested", e.approved = "approved", e.pending = "pending", e))(_e || {}), be = /* @__PURE__ */ ((e) => (e.iban = "iban", e.scan = "scan", e.chain = "chain", e))(be || {}), Se = /* @__PURE__ */ ((e) => (e.redeem = "redeem", e.issue = "issue", e))(Se || {}), Be = /* @__PURE__ */ ((e) => (e.placed = "placed", e.pending = "pending", e.processed = "processed", e.rejected = "rejected", e))(Be || {});
12
+ const ee = (e) => {
13
13
  if (e.toString() === "Invalid Date")
14
14
  throw e;
15
15
  const t = (n) => n < 10 ? "0" + n : n, r = (n) => {
@@ -19,12 +19,14 @@ const Se = (e) => {
19
19
  return n = Math.abs(n), u + t(Math.floor(n / 60)) + ":" + t(n % 60);
20
20
  };
21
21
  return e.getFullYear() + "-" + t(e.getMonth() + 1) + "-" + t(e.getDate()) + "T" + t(e.getHours()) + ":" + t(e.getMinutes()) + ":" + t(e.getSeconds()) + r(e.getTimezoneOffset());
22
- }, Fe = (e, t) => `Send EUR ${e} to ${t} at ${Se(/* @__PURE__ */ new Date())}`, Q = (e) => {
22
+ }, Fe = (e, t, r) => r ? `Send EUR ${e} to ${t} on ${oe(
23
+ r
24
+ )} at ${ee(/* @__PURE__ */ new Date())}` : `Send EUR ${e} to ${t} at ${ee(/* @__PURE__ */ new Date())}`, Q = (e) => {
23
25
  var t;
24
26
  return e && ((t = Object.entries(e)) == null ? void 0 : t.length) > 0 ? Object.entries(e).map(
25
27
  ([r, n]) => `${encodeURIComponent(r)}=${encodeURIComponent(n)}`
26
28
  ).join("&") : "";
27
- }, Be = (e) => {
29
+ }, oe = (e) => {
28
30
  switch (e) {
29
31
  case 1:
30
32
  case 5:
@@ -72,7 +74,7 @@ const Se = (e) => {
72
74
  STORAGE_REFRESH_TOKEN: W
73
75
  };
74
76
  var F = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
75
- function se(e) {
77
+ function ie(e) {
76
78
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
77
79
  }
78
80
  function xe(e) {
@@ -96,7 +98,7 @@ function xe(e) {
96
98
  });
97
99
  }), r;
98
100
  }
99
- var oe = { exports: {} };
101
+ var ae = { exports: {} };
100
102
  function Ae(e) {
101
103
  throw new Error('Could not dynamically require "' + e + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
102
104
  }
@@ -105,9 +107,9 @@ const Ee = {}, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
105
107
  __proto__: null,
106
108
  default: Ee
107
109
  }, Symbol.toStringTag, { value: "Module" })), Re = /* @__PURE__ */ xe(Ie);
108
- var ee;
109
- function ie() {
110
- return ee || (ee = 1, function(e, t) {
110
+ var te;
111
+ function ce() {
112
+ return te || (te = 1, function(e, t) {
111
113
  (function(r, n) {
112
114
  e.exports = n();
113
115
  })(F, function() {
@@ -477,13 +479,13 @@ function ie() {
477
479
  _process: function(s) {
478
480
  var o, a = this._data, h = a.words, _ = a.sigBytes, S = this.blockSize, C = S * 4, x = _ / C;
479
481
  s ? x = n.ceil(x) : x = n.max((x | 0) - this._minBufferSize, 0);
480
- var q = x * S, P = n.min(q * 4, _);
482
+ var q = x * S, O = n.min(q * 4, _);
481
483
  if (q) {
482
484
  for (var N = 0; N < q; N += S)
483
485
  this._doProcessBlock(h, N);
484
- o = h.splice(0, q), a.sigBytes -= P;
486
+ o = h.splice(0, q), a.sigBytes -= O;
485
487
  }
486
- return new g.init(o, P);
488
+ return new g.init(o, O);
487
489
  },
488
490
  /**
489
491
  * Creates a copy of this object.
@@ -608,7 +610,7 @@ function ie() {
608
610
  }
609
611
  (function(e, t) {
610
612
  (function(r, n) {
611
- e.exports = n(ie());
613
+ e.exports = n(ce());
612
614
  })(F, function(r) {
613
615
  return function() {
614
616
  var n = r, u = n.lib, c = u.WordArray, v = n.enc;
@@ -684,13 +686,13 @@ function ie() {
684
686
  }
685
687
  }(), r.enc.Base64url;
686
688
  });
687
- })(oe);
688
- var $e = oe.exports;
689
- const ze = /* @__PURE__ */ se($e);
690
- var ae = { exports: {} };
689
+ })(ae);
690
+ var $e = ae.exports;
691
+ const ze = /* @__PURE__ */ ie($e);
692
+ var ue = { exports: {} };
691
693
  (function(e, t) {
692
694
  (function(r, n) {
693
- e.exports = n(ie());
695
+ e.exports = n(ce());
694
696
  })(F, function(r) {
695
697
  return function(n) {
696
698
  var u = r, c = u.lib, v = c.WordArray, B = c.Hasher, p = u.algo, y = [], m = [];
@@ -716,11 +718,11 @@ var ae = { exports: {} };
716
718
  if (C < 16)
717
719
  g[C] = d[l + C] | 0;
718
720
  else {
719
- var x = g[C - 15], q = (x << 25 | x >>> 7) ^ (x << 14 | x >>> 18) ^ x >>> 3, P = g[C - 2], N = (P << 15 | P >>> 17) ^ (P << 13 | P >>> 19) ^ P >>> 10;
721
+ var x = g[C - 15], q = (x << 25 | x >>> 7) ^ (x << 14 | x >>> 18) ^ x >>> 3, O = g[C - 2], N = (O << 15 | O >>> 17) ^ (O << 13 | O >>> 19) ^ O >>> 10;
720
722
  g[C] = q + g[C - 7] + N + g[C - 16];
721
723
  }
722
- var ce = a & h ^ ~a & _, ue = f & A ^ f & s ^ A & s, he = (f << 30 | f >>> 2) ^ (f << 19 | f >>> 13) ^ (f << 10 | f >>> 22), de = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), Y = S + de + ce + m[C] + g[C], fe = he + ue;
723
- S = _, _ = h, h = a, a = o + Y | 0, o = s, s = A, A = f, f = Y + fe | 0;
724
+ var he = a & h ^ ~a & _, de = f & A ^ f & s ^ A & s, fe = (f << 30 | f >>> 2) ^ (f << 19 | f >>> 13) ^ (f << 10 | f >>> 22), le = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), Y = S + le + he + m[C] + g[C], pe = fe + de;
725
+ S = _, _ = h, h = a, a = o + Y | 0, o = s, s = A, A = f, f = Y + pe | 0;
724
726
  }
725
727
  i[0] = i[0] + f | 0, i[1] = i[1] + A | 0, i[2] = i[2] + s | 0, i[3] = i[3] + o | 0, i[4] = i[4] + a | 0, i[5] = i[5] + h | 0, i[6] = i[6] + _ | 0, i[7] = i[7] + S | 0;
726
728
  },
@@ -736,9 +738,9 @@ var ae = { exports: {} };
736
738
  u.SHA256 = B._createHelper(b), u.HmacSHA256 = B._createHmacHelper(b);
737
739
  }(Math), r.SHA256;
738
740
  });
739
- })(ae);
740
- var Ue = ae.exports;
741
- const He = /* @__PURE__ */ se(Ue), Pe = (e, t) => {
741
+ })(ue);
742
+ var Ue = ue.exports;
743
+ const He = /* @__PURE__ */ ie(Ue), Oe = (e, t) => {
742
744
  const {
743
745
  client_id: r,
744
746
  redirect_uri: n,
@@ -752,7 +754,7 @@ const He = /* @__PURE__ */ se(Ue), Pe = (e, t) => {
752
754
  } = e, g = y ? {
753
755
  address: y,
754
756
  ...m !== void 0 ? { signature: m } : {},
755
- ...v !== void 0 || B !== void 0 ? { chain: v ? Be(v) : B } : {},
757
+ ...v !== void 0 || B !== void 0 ? { chain: v ? oe(v) : B } : {},
756
758
  ...v !== void 0 || p !== void 0 ? { network: v ? ke(v) : p } : {}
757
759
  } : {};
758
760
  return Q({
@@ -765,23 +767,23 @@ const He = /* @__PURE__ */ se(Ue), Pe = (e, t) => {
765
767
  response_type: "code",
766
768
  ...g
767
769
  });
768
- }, Oe = () => {
770
+ }, Pe = () => {
769
771
  let e = "";
770
772
  const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", r = t.length;
771
773
  let n = 0;
772
774
  for (; n < 128; )
773
775
  e += t.charAt(Math.floor(Math.random() * r)), n += 1;
774
776
  return e;
775
- }, Te = (e) => ze.stringify(He(e)), te = (e, t) => {
776
- const r = Oe(), n = Te(r);
777
- return sessionStorage.setItem(M, r || ""), `${e}/auth?${Pe(t, n)}`;
778
- }, re = () => {
777
+ }, Te = (e) => ze.stringify(He(e)), re = (e, t) => {
778
+ const r = Pe(), n = Te(r);
779
+ return sessionStorage.setItem(M, r || ""), `${e}/auth?${Oe(t, n)}`;
780
+ }, ne = () => {
779
781
  const e = window.location.href;
780
782
  if (!e || !(e != null && e.includes("?")))
781
783
  return;
782
784
  const [t, r] = e.split("?");
783
785
  r && window.history.replaceState(null, "", t);
784
- }, ne = (e) => e.code != null, Me = (e) => e.refresh_token != null, Le = (e) => e.client_secret != null, qe = async (e, t, r, n) => {
786
+ }, se = (e) => e.code != null, Me = (e) => e.refresh_token != null, Le = (e) => e.client_secret != null, qe = async (e, t, r, n) => {
785
787
  const u = await fetch(`${e}`, {
786
788
  method: t,
787
789
  headers: n,
@@ -798,13 +800,13 @@ const He = /* @__PURE__ */ se(Ue), Pe = (e, t) => {
798
800
  throw c;
799
801
  return c;
800
802
  }, T = typeof window > "u";
801
- var z, D, L, H, U, O, j, E, R, V, G, J;
803
+ var z, D, L, H, U, P, j, E, R, V, G, J;
802
804
  class We {
803
805
  constructor(t) {
804
806
  /**
805
807
  * {@link https://monerium.dev/api-docs#operation/auth-token}
806
808
  */
807
- $(this, O);
809
+ $(this, P);
808
810
  // -- Helper Methods
809
811
  $(this, E);
810
812
  $(this, z, void 0);
@@ -820,7 +822,7 @@ class We {
820
822
  const c = sessionStorage.getItem(M) || "";
821
823
  if (!c)
822
824
  throw new Error("Code verifier not found");
823
- return this.codeVerifier = c, sessionStorage.removeItem(M), await k(this, O, j).call(this, {
825
+ return this.codeVerifier = c, sessionStorage.removeItem(M), await k(this, P, j).call(this, {
824
826
  code: u,
825
827
  redirect_uri: n,
826
828
  client_id: r,
@@ -829,10 +831,10 @@ class We {
829
831
  }), I(this, G, async ({
830
832
  clientId: r,
831
833
  clientSecret: n
832
- }) => await k(this, O, j).call(this, {
834
+ }) => await k(this, P, j).call(this, {
833
835
  client_id: r,
834
836
  client_secret: n
835
- })), I(this, J, async (r, n) => await k(this, O, j).call(this, {
837
+ })), I(this, J, async (r, n) => await k(this, P, j).call(this, {
836
838
  refresh_token: n,
837
839
  client_id: r
838
840
  })), this.subscribeToOrderNotifications = () => {
@@ -851,8 +853,8 @@ class We {
851
853
  }), n.addEventListener("close", () => {
852
854
  console.info(`Socket connection closed: ${r}`);
853
855
  }), n;
854
- }, this.auth = async (r) => await k(this, O, j).call(this, r), this.connect = async (r) => await k(this, O, j).call(this, r), this.getAuthFlowURI = (r) => {
855
- const n = te(w(this, z).api, r);
856
+ }, this.auth = async (r) => await k(this, P, j).call(this, r), this.connect = async (r) => await k(this, P, j).call(this, r), this.getAuthFlowURI = (r) => {
857
+ const n = re(w(this, z).api, r);
856
858
  return this.codeVerifier = sessionStorage.getItem(M), n;
857
859
  }, this.pkceRequest = (r) => this.getAuthFlowURI(r), this.getEnvironment = () => w(this, z), !t) {
858
860
  I(this, z, X.environments.sandbox);
@@ -888,7 +890,7 @@ class We {
888
890
  throw new Error("Missing ClientId");
889
891
  if (!n)
890
892
  throw new Error("Missing RedirectUrl");
891
- const u = te(w(this, z).api, {
893
+ const u = re(w(this, z).api, {
892
894
  client_id: r,
893
895
  redirect_uri: n,
894
896
  address: t == null ? void 0 : t.address,
@@ -1019,9 +1021,9 @@ class We {
1019
1021
  w(this, H).delete(t), w(this, H).size === 0 && ((r = w(this, L)) == null || r.close(), I(this, L, void 0));
1020
1022
  }
1021
1023
  }
1022
- z = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), U = new WeakMap(), O = new WeakSet(), j = async function(t) {
1024
+ z = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), U = new WeakMap(), P = new WeakSet(), j = async function(t) {
1023
1025
  let r;
1024
- if (ne(t))
1026
+ if (se(t))
1025
1027
  r = { ...t, grant_type: "authorization_code" };
1026
1028
  else if (Me(t))
1027
1029
  r = { ...t, grant_type: "refresh_token" };
@@ -1036,8 +1038,8 @@ z = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), U =
1036
1038
  ((u = this.bearerProfile) == null ? void 0 : u.refresh_token) || ""
1037
1039
  );
1038
1040
  }).catch((n) => {
1039
- throw T || (sessionStorage.removeItem(M), sessionStorage.removeItem(W), re()), new Error(n == null ? void 0 : n.message);
1040
- }), ne(t) && re(), this.bearerProfile;
1041
+ throw T || (sessionStorage.removeItem(M), sessionStorage.removeItem(W), ne()), new Error(n == null ? void 0 : n.message);
1042
+ }), se(t) && ne(), this.bearerProfile;
1041
1043
  }, E = new WeakSet(), R = async function(t, r, n, u) {
1042
1044
  return qe(
1043
1045
  `${w(this, z).api}/${r}`,
@@ -1050,19 +1052,19 @@ z = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), U =
1050
1052
  );
1051
1053
  }, V = new WeakMap(), G = new WeakMap(), J = new WeakMap();
1052
1054
  export {
1053
- ye as AccountState,
1054
- le as Currency,
1055
- we as KYCOutcome,
1056
- ge as KYCState,
1055
+ _e as AccountState,
1056
+ ve as Currency,
1057
+ me as KYCOutcome,
1058
+ ye as KYCState,
1057
1059
  We as MoneriumClient,
1058
- _e as OrderKind,
1059
- be as OrderState,
1060
- me as PaymentStandard,
1061
- ve as Permission,
1062
- pe as ProfileType,
1060
+ Se as OrderKind,
1061
+ Be as OrderState,
1062
+ be as PaymentStandard,
1063
+ we as Permission,
1064
+ ge as ProfileType,
1063
1065
  Ne as constants,
1064
- Be as getChain,
1066
+ oe as getChain,
1065
1067
  ke as getNetwork,
1066
1068
  Fe as placeOrderMessage,
1067
- Se as rfc3339
1069
+ ee as rfc3339
1068
1070
  };
package/dist/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@monerium/sdk",
3
- "version": "2.7.3",
3
+ "version": "2.8.0",
4
4
  "description": "Everything you need to interact with the Monerium API - an electronic money issuer.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/monerium/sdk.git"
8
+ "url": "git+https://github.com/monerium/js-sdk.git"
9
9
  },
10
10
  "bugs": {
11
- "url": "https://github.com/monerium/sdk/issues"
11
+ "url": "https://github.com/monerium/js-sdk/issues"
12
12
  },
13
13
  "main": "./dist/index.js",
14
14
  "module": "./dist/index.mjs",
package/dist/types.d.ts CHANGED
@@ -151,7 +151,12 @@ export interface KYC {
151
151
  }
152
152
  export declare enum PaymentStandard {
153
153
  iban = "iban",
154
- scan = "scan"
154
+ scan = "scan",
155
+ chain = "chain"
156
+ }
157
+ export interface Identifier {
158
+ standard: PaymentStandard;
159
+ bic?: string;
155
160
  }
156
161
  export interface Account {
157
162
  address: string;
@@ -195,11 +200,17 @@ export interface Fee {
195
200
  currency: Currency;
196
201
  amount: string;
197
202
  }
198
- export interface IBAN {
203
+ export interface IBAN extends Identifier {
199
204
  standard: PaymentStandard.iban;
200
205
  iban: string;
201
206
  }
202
- export interface SCAN {
207
+ export interface CrossChain extends Identifier {
208
+ standard: PaymentStandard.chain;
209
+ address: string;
210
+ chain: string;
211
+ network: string;
212
+ }
213
+ export interface SCAN extends Identifier {
203
214
  standard: PaymentStandard.scan;
204
215
  sortCode: string;
205
216
  accountNumber: string;
@@ -214,7 +225,7 @@ export interface Corporation {
214
225
  country: string;
215
226
  }
216
227
  export interface Counterpart {
217
- identifier: IBAN | SCAN;
228
+ identifier: IBAN | SCAN | CrossChain;
218
229
  details: Individual | Corporation;
219
230
  }
220
231
  export interface OrderMetadata {
package/dist/utils.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const rfc3339: (d: Date) => string;
5
5
  *
6
6
  * @returns string
7
7
  */
8
- export declare const placeOrderMessage: (amount: string | number, iban: string) => string;
8
+ export declare const placeOrderMessage: (amount: string | number, receiver: string, chainId?: number) => string;
9
9
  /**
10
10
  * Replacement for URLSearchParams, Metamask snaps do not include node globals.
11
11
  * It will not handle all special characters the same way as URLSearchParams, but it will be good enough for our use case.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@monerium/sdk",
3
- "version": "2.7.3",
3
+ "version": "2.8.0",
4
4
  "description": "Everything you need to interact with the Monerium API - an electronic money issuer.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/monerium/sdk.git"
8
+ "url": "git+https://github.com/monerium/js-sdk.git"
9
9
  },
10
10
  "bugs": {
11
- "url": "https://github.com/monerium/sdk/issues"
11
+ "url": "https://github.com/monerium/js-sdk/issues"
12
12
  },
13
13
  "main": "./dist/index.js",
14
14
  "module": "./dist/index.mjs",