@monerium/sdk
Advanced tools
Comparing version 2.11.0 to 2.12.0
# Changelog | ||
## [2.12.0](https://github.com/monerium/js-sdk/compare/sdk-v2.11.1...sdk-v2.12.0) (2024-03-12) | ||
### Bug Fixes | ||
* upload document ([0f6d49d](https://github.com/monerium/js-sdk/commit/0f6d49d821afa72c4a61e94e7a3a1377357dc727)) | ||
## [2.11.1](https://github.com/monerium/js-sdk/compare/sdk-v2.11.0...sdk-v2.11.1) (2024-03-12) | ||
### Bug Fixes | ||
* upload document ([0f6d49d](https://github.com/monerium/js-sdk/commit/0f6d49d821afa72c4a61e94e7a3a1377357dc727)) | ||
## [2.11.0](https://github.com/monerium/js-sdk/compare/sdk-v2.10.0...sdk-v2.11.0) (2024-02-05) | ||
@@ -4,0 +17,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";var X=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var y=(e,t,r)=>(X(e,t,"read from private field"),r?r.call(e):t.get(e)),R=(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)=>(X(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var k=(e,t,r)=>(X(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ce=(e=>(e.eur="eur",e))(ce||{}),ue=(e=>(e.corporate="corporate",e.personal="personal",e))(ue||{}),he=(e=>(e.read="read",e.write="write",e))(he||{}),de=(e=>(e.absent="absent",e.submitted="submitted",e.pending="pending",e.confirmed="confirmed",e))(de||{}),fe=(e=>(e.approved="approved",e.rejected="rejected",e.unknown="unknown",e))(fe||{}),le=(e=>(e.requested="requested",e.approved="approved",e.pending="pending",e))(le||{}),pe=(e=>(e.iban="iban",e.scan="scan",e.chain="chain",e))(pe||{}),ve=(e=>(e.redeem="redeem",e.issue="issue",e))(ve||{}),ge=(e=>(e.placed="placed",e.pending="pending",e.processed="processed",e.rejected="rejected",e))(ge||{});const te=e=>{if(e.toString()==="Invalid Date")throw e;const t=n=>n<10?"0"+n:n,r=n=>{if(n===0)return"Z";const c=n>0?"-":"+";return n=Math.abs(n),c+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())},xe=(e,t,r,n)=>{const c=`${(n==null?void 0:n.toUpperCase())||"EUR"}`;return r?`Send ${c} ${e} to ${t} on ${K(r)} at ${te(new Date)}`:`Send ${c} ${e} to ${t} at ${te(new Date)}`},Z=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("&"):""},K=e=>{switch(e){case 1:case 11155111:return"ethereum";case 100:case 10200:return"gnosis";case 137:case 80001:return"polygon";default:throw new Error(`Chain not supported: ${e}`)}},re=e=>{switch(e){case 1:case 100:case 137:return"mainnet";case 11155111:return"sepolia";case 10200:return"chiado";case 80001:return"mumbai";default:throw new Error(`Network not supported: ${e}`)}},Q=e=>{if(e!=null&&e.chainId){const{chainId:t,...r}=e;return{...r,chain:K(t),network:re(t)}}return e},Y={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"}}},Ae="I hereby declare that I am the address owner.",M="monerium.sdk.code_verifier",D="monerium.sdk.refresh_token",Ee={LINK_MESSAGE:Ae,STORAGE_CODE_VERIFIER:M,STORAGE_REFRESH_TOKEN:D};var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function we(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ie(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 c=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,c.get?c:{enumerable:!0,get:function(){return e[n]}})}),r}var ye={exports:{}};function $e(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 ee={exports:{}};const Re={},Pe=Object.freeze(Object.defineProperty({__proto__:null,default:Re},Symbol.toStringTag,{value:"Module"})),Oe=Ie(Pe);var oe;function me(){return oe||(oe=1,function(e,t){(function(r,n){e.exports=n()})(q,function(){var r=r||function(n,c){var u;if(typeof window<"u"&&window.crypto&&(u=window.crypto),typeof self<"u"&&self.crypto&&(u=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(u=globalThis.crypto),!u&&typeof window<"u"&&window.msCrypto&&(u=window.msCrypto),!u&&typeof q<"u"&&q.crypto&&(u=q.crypto),!u&&typeof $e=="function")try{u=Oe}catch{}var l=function(){if(u){if(typeof u.getRandomValues=="function")try{return u.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof u.randomBytes=="function")try{return u.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},C=Object.create||function(){function o(){}return function(s){var a;return o.prototype=s,a=new o,o.prototype=null,a}}(),v={},m=v.lib={},w=m.Base=function(){return{extend:function(o){var s=C(this);return o&&s.mixIn(o),(!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 o=this.extend();return o.init.apply(o,arguments),o},init:function(){},mixIn:function(o){for(var s in o)o.hasOwnProperty(s)&&(this[s]=o[s]);o.hasOwnProperty("toString")&&(this.toString=o.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),g=m.WordArray=w.extend({init:function(o,s){o=this.words=o||[],s!=c?this.sigBytes=s:this.sigBytes=o.length*4},toString:function(o){return(o||d).stringify(this)},concat:function(o){var s=this.words,a=o.words,h=this.sigBytes,_=o.sigBytes;if(this.clamp(),h%4)for(var S=0;S<_;S++){var B=a[S>>>2]>>>24-S%4*8&255;s[h+S>>>2]|=B<<24-(h+S)%4*8}else for(var x=0;x<_;x+=4)s[h+x>>>2]=a[x>>>2];return this.sigBytes+=_,this},clamp:function(){var o=this.words,s=this.sigBytes;o[s>>>2]&=4294967295<<32-s%4*8,o.length=n.ceil(s/4)},clone:function(){var o=w.clone.call(this);return o.words=this.words.slice(0),o},random:function(o){for(var s=[],a=0;a<o;a+=4)s.push(l());return new g.init(s,o)}}),b=v.enc={},d=b.Hex={stringify:function(o){for(var s=o.words,a=o.sigBytes,h=[],_=0;_<a;_++){var S=s[_>>>2]>>>24-_%4*8&255;h.push((S>>>4).toString(16)),h.push((S&15).toString(16))}return h.join("")},parse:function(o){for(var s=o.length,a=[],h=0;h<s;h+=2)a[h>>>3]|=parseInt(o.substr(h,2),16)<<24-h%8*4;return new g.init(a,s/2)}},p=b.Latin1={stringify:function(o){for(var s=o.words,a=o.sigBytes,h=[],_=0;_<a;_++){var S=s[_>>>2]>>>24-_%4*8&255;h.push(String.fromCharCode(S))}return h.join("")},parse:function(o){for(var s=o.length,a=[],h=0;h<s;h++)a[h>>>2]|=(o.charCodeAt(h)&255)<<24-h%4*8;return new g.init(a,s)}},i=b.Utf8={stringify:function(o){try{return decodeURIComponent(escape(p.stringify(o)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(o){return p.parse(unescape(encodeURIComponent(o)))}},f=m.BufferedBlockAlgorithm=w.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(o){typeof o=="string"&&(o=i.parse(o)),this._data.concat(o),this._nDataBytes+=o.sigBytes},_process:function(o){var s,a=this._data,h=a.words,_=a.sigBytes,S=this.blockSize,B=S*4,x=_/B;o?x=n.ceil(x):x=n.max((x|0)-this._minBufferSize,0);var N=x*S,z=n.min(N*4,_);if(N){for(var W=0;W<N;W+=S)this._doProcessBlock(h,W);s=h.splice(0,N),a.sigBytes-=z}return new g.init(s,z)},clone:function(){var o=w.clone.call(this);return o._data=this._data.clone(),o},_minBufferSize:0});m.Hasher=f.extend({cfg:w.extend(),init:function(o){this.cfg=this.cfg.extend(o),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(o){return this._append(o),this._process(),this},finalize:function(o){o&&this._append(o);var s=this._doFinalize();return s},blockSize:16,_createHelper:function(o){return function(s,a){return new o.init(a).finalize(s)}},_createHmacHelper:function(o){return function(s,a){return new A.HMAC.init(o,a).finalize(s)}}});var A=v.algo={};return v}(Math);return r})}(ee)),ee.exports}(function(e,t){(function(r,n){e.exports=n(me())})(q,function(r){return function(){var n=r,c=n.lib,u=c.WordArray,l=n.enc;l.Base64url={stringify:function(v,m){m===void 0&&(m=!0);var w=v.words,g=v.sigBytes,b=m?this._safe_map:this._map;v.clamp();for(var d=[],p=0;p<g;p+=3)for(var i=w[p>>>2]>>>24-p%4*8&255,f=w[p+1>>>2]>>>24-(p+1)%4*8&255,A=w[p+2>>>2]>>>24-(p+2)%4*8&255,o=i<<16|f<<8|A,s=0;s<4&&p+s*.75<g;s++)d.push(b.charAt(o>>>6*(3-s)&63));var a=b.charAt(64);if(a)for(;d.length%4;)d.push(a);return d.join("")},parse:function(v,m){m===void 0&&(m=!0);var w=v.length,g=m?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 p=g.charAt(64);if(p){var i=v.indexOf(p);i!==-1&&(w=i)}return C(v,w,b)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function C(v,m,w){for(var g=[],b=0,d=0;d<m;d++)if(d%4){var p=w[v.charCodeAt(d-1)]<<d%4*2,i=w[v.charCodeAt(d)]>>>6-d%4*2,f=p|i;g[b>>>2]|=f<<24-b%4*8,b++}return u.create(g,b)}}(),r.enc.Base64url})})(ye);var Ue=ye.exports;const ze=we(Ue);var _e={exports:{}};(function(e,t){(function(r,n){e.exports=n(me())})(q,function(r){return function(n){var c=r,u=c.lib,l=u.WordArray,C=u.Hasher,v=c.algo,m=[],w=[];(function(){function d(A){for(var o=n.sqrt(A),s=2;s<=o;s++)if(!(A%s))return!1;return!0}function p(A){return(A-(A|0))*4294967296|0}for(var i=2,f=0;f<64;)d(i)&&(f<8&&(m[f]=p(n.pow(i,1/2))),w[f]=p(n.pow(i,1/3)),f++),i++})();var g=[],b=v.SHA256=C.extend({_doReset:function(){this._hash=new l.init(m.slice(0))},_doProcessBlock:function(d,p){for(var i=this._hash.words,f=i[0],A=i[1],o=i[2],s=i[3],a=i[4],h=i[5],_=i[6],S=i[7],B=0;B<64;B++){if(B<16)g[B]=d[p+B]|0;else{var x=g[B-15],N=(x<<25|x>>>7)^(x<<14|x>>>18)^x>>>3,z=g[B-2],W=(z<<15|z>>>17)^(z<<13|z>>>19)^z>>>10;g[B]=N+g[B-7]+W+g[B-16]}var be=a&h^~a&_,Se=f&A^f&o^A&o,Ce=(f<<30|f>>>2)^(f<<19|f>>>13)^(f<<10|f>>>22),ke=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),ne=S+ke+be+w[B]+g[B],Be=Ce+Se;S=_,_=h,h=a,a=s+ne|0,s=o,o=A,A=f,f=ne+Be|0}i[0]=i[0]+f|0,i[1]=i[1]+A|0,i[2]=i[2]+o|0,i[3]=i[3]+s|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,p=d.words,i=this._nDataBytes*8,f=d.sigBytes*8;return p[f>>>5]|=128<<24-f%32,p[(f+64>>>9<<4)+14]=n.floor(i/4294967296),p[(f+64>>>9<<4)+15]=i,d.sigBytes=p.length*4,this._process(),this._hash},clone:function(){var d=C.clone.call(this);return d._hash=this._hash.clone(),d}});c.SHA256=C._createHelper(b),c.HmacSHA256=C._createHmacHelper(b)}(Math),r.SHA256})})(_e);var He=_e.exports;const Te=we(He),Me=(e,t)=>{const{client_id:r,redirect_uri:n,scope:c,state:u,chainId:l,chain:C,network:v,address:m,signature:w}=e,g=m?{address:m,...w!==void 0?{signature:w}:{},...l!==void 0||C!==void 0?{chain:l?K(l):C}:{},...l!==void 0||v!==void 0?{network:l?re(l):v}:{}}:{};return Z({client_id:r,redirect_uri:n,...c!==void 0?{scope:c}:{},...u!==void 0?{state:u}:{},code_challenge:t,code_challenge_method:"S256",response_type:"code",...g})},Le=()=>{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},Ne=e=>ze.stringify(Te(e)),se=(e,t)=>{const r=Le(),n=Ne(r);return localStorage.setItem(M,r||""),`${e}/auth?${Me(t,n)}`},ie=()=>{const e=window.location.href;if(!e||!(e!=null&&e.includes("?")))return;const[t,r]=e.split("?");r&&window.history.replaceState(null,"",t)},ae=e=>e.code!=null,je=e=>e.refresh_token!=null,qe=e=>e.client_secret!=null,Fe=async(e,t,r,n)=>{const c=await fetch(`${e}`,{method:t,headers:n,body:r});let u;const l=await c.text();try{u=JSON.parse(l)}catch{throw l}if(!c.ok)throw u;return u},T=typeof window>"u";var P,F,L,U,O,H,j,E,$,V,G,J;class We{constructor(t){R(this,H);R(this,E);R(this,P,void 0);R(this,F,void 0);R(this,L,void 0);R(this,U,void 0);R(this,O,void 0);R(this,V,void 0);R(this,G,void 0);R(this,J,void 0);if(I(this,U,new Map),this.isAuthorized=!!this.bearerProfile,I(this,V,async(r,n,c,u)=>{const l=localStorage.getItem(M)||"";if(!l)throw new Error("Code verifier not found");return this.codeVerifier=l,this.state=u,localStorage.removeItem(M),await k(this,H,j).call(this,{code:c,redirect_uri:n,client_id:r,code_verifier:l})}),I(this,G,async({clientId:r,clientSecret:n})=>await k(this,H,j).call(this,{client_id:r,client_secret:n})),I(this,J,async(r,n)=>await k(this,H,j).call(this,{refresh_token:n,client_id:r})),this.subscribeToOrderNotifications=()=>{var c,u;const r=`${y(this,P).wss}/profiles/${(c=this.bearerProfile)==null?void 0:c.profile}/orders?access_token=${(u=this.bearerProfile)==null?void 0:u.access_token}`,n=new WebSocket(r);return n.addEventListener("open",()=>{console.info(`Socket connected: ${r}`)}),n.addEventListener("error",l=>{throw console.error(l),new Error(`Socket error: ${r}`)}),n.addEventListener("message",l=>{var v;const C=JSON.parse(l.data);(v=y(this,U).get(C.meta.state))==null||v(C)}),n.addEventListener("close",()=>{console.info(`Socket connection closed: ${r}`)}),n},this.auth=async r=>await k(this,H,j).call(this,r),this.connect=async r=>await k(this,H,j).call(this,r),this.getAuthFlowURI=r=>{const n=se(y(this,P).api,r);return this.codeVerifier=localStorage.getItem(M),n},this.pkceRequest=r=>this.getAuthFlowURI(r),this.getEnvironment=()=>y(this,P),!t){I(this,P,Y.environments.sandbox);return}if(typeof t=="string")I(this,P,Y.environments[t]);else if(I(this,P,Y.environments[t.environment||"sandbox"]),T){const{clientId:r,clientSecret:n}=t;I(this,O,{clientId:r,clientSecret:n})}else{const{clientId:r,redirectUrl:n}=t;I(this,O,{clientId:r,redirectUrl:n})}}async authorize(t){var u,l;const r=(t==null?void 0:t.clientId)||((u=y(this,O))==null?void 0:u.clientId),n=(t==null?void 0:t.redirectUrl)||((l=y(this,O))==null?void 0:l.redirectUrl);if(!r)throw new Error("Missing ClientId");if(!n)throw new Error("Missing RedirectUrl");const c=se(y(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,state:t==null?void 0:t.state});window.location.replace(c)}async getAccess(t){var v,m,w;const r=(t==null?void 0:t.clientId)||((v=y(this,O))==null?void 0:v.clientId);if((t==null?void 0:t.clientSecret)||((m=y(this,O))==null?void 0:m.clientSecret)){if(!T)throw new Error("Only use client credentials on server side");return await y(this,G).call(this,y(this,O)),!!this.bearerProfile}const c=(t==null?void 0:t.redirectUrl)||((w=y(this,O))==null?void 0:w.redirectUrl);if(!r)throw new Error("Missing ClientId");if(T)throw new Error("This only works client side");const u=new URLSearchParams(window.location.search).get("code")||void 0,l=new URLSearchParams(window.location.search).get("state")||void 0,C=localStorage.getItem(D)||void 0;return C?await y(this,J).call(this,r,C):u&&await y(this,V).call(this,r,c,u,l),!!this.bearerProfile}getAuthContext(){return k(this,E,$).call(this,"get","auth/context")}getProfile(t){return k(this,E,$).call(this,"get",`profiles/${t}`)}getBalances(t){return t?k(this,E,$).call(this,"get",`profiles/${t}/balances`):k(this,E,$).call(this,"get","balances")}getOrders(t){const r=Z(t);return k(this,E,$).call(this,"get",`orders?${r}`)}getOrder(t){return k(this,E,$).call(this,"get",`orders/${t}`)}getTokens(){return k(this,E,$).call(this,"get","tokens")}linkAddress(t,r){return r=Q(r),r.accounts=r.accounts.map(n=>Q(n)),k(this,E,$).call(this,"post",`profiles/${t}/addresses`,JSON.stringify(r))}placeOrder(t,r){const n={kind:"redeem",currency:"eur",...Q(t),counterpart:{...t.counterpart,identifier:Q(t.counterpart.identifier)}};return r?k(this,E,$).call(this,"post",`profiles/${r}/orders`,JSON.stringify(n)):k(this,E,$).call(this,"post","orders",JSON.stringify(n))}uploadSupportingDocument(t){const r=Z(t);return k(this,E,$).call(this,"post","files/supporting-document",r,!0)}async connectOrderSocket(){var t;(t=this.bearerProfile)!=null&&t.access_token&&y(this,U).size>0&&I(this,L,this.subscribeToOrderNotifications())}async disconnect(){var t;T||localStorage.removeItem(M),y(this,U).clear(),(t=y(this,L))==null||t.close(),I(this,F,void 0),this.bearerProfile=void 0}async revokeAccess(){T||localStorage.removeItem(D),this.disconnect()}subscribeOrders(t,r){y(this,U).set(t,r)}unsubscribeOrders(t){var r;y(this,U).delete(t),y(this,U).size===0&&((r=y(this,L))==null||r.close(),I(this,L,void 0))}}P=new WeakMap,F=new WeakMap,L=new WeakMap,U=new WeakMap,O=new WeakMap,H=new WeakSet,j=async function(t){let r;if(ae(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 k(this,E,$).call(this,"post","auth/token",r,!0).then(n=>{var c;this.bearerProfile=n,this.isAuthorized=!!n,I(this,F,`Bearer ${n==null?void 0:n.access_token}`),T||window.localStorage.setItem(D,((c=this.bearerProfile)==null?void 0:c.refresh_token)||"")}).catch(n=>{throw T||(localStorage.removeItem(M),localStorage.removeItem(D),ie()),new Error(n==null?void 0:n.message)}),ae(t)&&ie(),this.bearerProfile},E=new WeakSet,$=async function(t,r,n,c){return Fe(`${y(this,P).api}/${r}`,t,c?Z(n):n,{Authorization:y(this,F)||"","Content-Type":`application/${c?"x-www-form-urlencoded":"json"}`})},V=new WeakMap,G=new WeakMap,J=new WeakMap;exports.AccountState=le;exports.Currency=ce;exports.KYCOutcome=fe;exports.KYCState=de;exports.MoneriumClient=We;exports.OrderKind=ve;exports.OrderState=ge;exports.PaymentStandard=pe;exports.Permission=he;exports.ProfileType=ue;exports.constants=Ee;exports.getChain=K;exports.getNetwork=re;exports.placeOrderMessage=xe;exports.rfc3339=te; | ||
"use strict";var K=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var g=(e,t,r)=>(K(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)},E=(e,t,r,n)=>(K(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var k=(e,t,r)=>(K(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ue=(e=>(e.eur="eur",e))(ue||{}),he=(e=>(e.corporate="corporate",e.personal="personal",e))(he||{}),fe=(e=>(e.read="read",e.write="write",e))(fe||{}),de=(e=>(e.absent="absent",e.submitted="submitted",e.pending="pending",e.confirmed="confirmed",e))(de||{}),le=(e=>(e.approved="approved",e.rejected="rejected",e.unknown="unknown",e))(le||{}),pe=(e=>(e.requested="requested",e.approved="approved",e.pending="pending",e))(pe||{}),ve=(e=>(e.iban="iban",e.scan="scan",e.chain="chain",e))(ve||{}),ge=(e=>(e.redeem="redeem",e.issue="issue",e))(ge||{}),we=(e=>(e.placed="placed",e.pending="pending",e.processed="processed",e.rejected="rejected",e))(we||{});const ee=e=>{if(e.toString()==="Invalid Date")throw e;const t=n=>n<10?"0"+n:n,r=n=>{if(n===0)return"Z";const c=n>0?"-":"+";return n=Math.abs(n),c+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())},Ae=(e,t,r,n)=>{const c=`${(n==null?void 0:n.toUpperCase())||"EUR"}`;return r?`Send ${c} ${e} to ${t} on ${Z(r)} at ${ee(new Date)}`:`Send ${c} ${e} to ${t} at ${ee(new Date)}`},te=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("&"):""},Z=e=>{switch(e){case 1:case 11155111:return"ethereum";case 100:case 10200:return"gnosis";case 137:case 80001:return"polygon";default:throw new Error(`Chain not supported: ${e}`)}},re=e=>{switch(e){case 1:case 100:case 137:return"mainnet";case 11155111:return"sepolia";case 10200:return"chiado";case 80001:return"mumbai";default:throw new Error(`Network not supported: ${e}`)}},Q=e=>{if(e!=null&&e.chainId){const{chainId:t,...r}=e;return{...r,chain:Z(t),network:re(t)}}return e},X={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"}}},Ee="I hereby declare that I am the address owner.",M="monerium.sdk.code_verifier",W="monerium.sdk.refresh_token",Ie={LINK_MESSAGE:Ee,STORAGE_CODE_VERIFIER:M,STORAGE_REFRESH_TOKEN:W};var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ye(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function $e(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 c=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,c.get?c:{enumerable:!0,get:function(){return e[n]}})}),r}var me={exports:{}};function Re(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 Y={exports:{}};const Oe={},Pe=Object.freeze(Object.defineProperty({__proto__:null,default:Oe},Symbol.toStringTag,{value:"Module"})),ze=$e(Pe);var oe;function _e(){return oe||(oe=1,function(e,t){(function(r,n){e.exports=n()})(q,function(){var r=r||function(n,c){var u;if(typeof window<"u"&&window.crypto&&(u=window.crypto),typeof self<"u"&&self.crypto&&(u=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(u=globalThis.crypto),!u&&typeof window<"u"&&window.msCrypto&&(u=window.msCrypto),!u&&typeof q<"u"&&q.crypto&&(u=q.crypto),!u&&typeof Re=="function")try{u=ze}catch{}var l=function(){if(u){if(typeof u.getRandomValues=="function")try{return u.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof u.randomBytes=="function")try{return u.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},C=Object.create||function(){function o(){}return function(s){var a;return o.prototype=s,a=new o,o.prototype=null,a}}(),v={},m=v.lib={},y=m.Base=function(){return{extend:function(o){var s=C(this);return o&&s.mixIn(o),(!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 o=this.extend();return o.init.apply(o,arguments),o},init:function(){},mixIn:function(o){for(var s in o)o.hasOwnProperty(s)&&(this[s]=o[s]);o.hasOwnProperty("toString")&&(this.toString=o.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),w=m.WordArray=y.extend({init:function(o,s){o=this.words=o||[],s!=c?this.sigBytes=s:this.sigBytes=o.length*4},toString:function(o){return(o||f).stringify(this)},concat:function(o){var s=this.words,a=o.words,h=this.sigBytes,_=o.sigBytes;if(this.clamp(),h%4)for(var S=0;S<_;S++){var B=a[S>>>2]>>>24-S%4*8&255;s[h+S>>>2]|=B<<24-(h+S)%4*8}else for(var x=0;x<_;x+=4)s[h+x>>>2]=a[x>>>2];return this.sigBytes+=_,this},clamp:function(){var o=this.words,s=this.sigBytes;o[s>>>2]&=4294967295<<32-s%4*8,o.length=n.ceil(s/4)},clone:function(){var o=y.clone.call(this);return o.words=this.words.slice(0),o},random:function(o){for(var s=[],a=0;a<o;a+=4)s.push(l());return new w.init(s,o)}}),b=v.enc={},f=b.Hex={stringify:function(o){for(var s=o.words,a=o.sigBytes,h=[],_=0;_<a;_++){var S=s[_>>>2]>>>24-_%4*8&255;h.push((S>>>4).toString(16)),h.push((S&15).toString(16))}return h.join("")},parse:function(o){for(var s=o.length,a=[],h=0;h<s;h+=2)a[h>>>3]|=parseInt(o.substr(h,2),16)<<24-h%8*4;return new w.init(a,s/2)}},p=b.Latin1={stringify:function(o){for(var s=o.words,a=o.sigBytes,h=[],_=0;_<a;_++){var S=s[_>>>2]>>>24-_%4*8&255;h.push(String.fromCharCode(S))}return h.join("")},parse:function(o){for(var s=o.length,a=[],h=0;h<s;h++)a[h>>>2]|=(o.charCodeAt(h)&255)<<24-h%4*8;return new w.init(a,s)}},i=b.Utf8={stringify:function(o){try{return decodeURIComponent(escape(p.stringify(o)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(o){return p.parse(unescape(encodeURIComponent(o)))}},d=m.BufferedBlockAlgorithm=y.extend({reset:function(){this._data=new w.init,this._nDataBytes=0},_append:function(o){typeof o=="string"&&(o=i.parse(o)),this._data.concat(o),this._nDataBytes+=o.sigBytes},_process:function(o){var s,a=this._data,h=a.words,_=a.sigBytes,S=this.blockSize,B=S*4,x=_/B;o?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 D=0;D<j;D+=S)this._doProcessBlock(h,D);s=h.splice(0,j),a.sigBytes-=U}return new w.init(s,U)},clone:function(){var o=y.clone.call(this);return o._data=this._data.clone(),o},_minBufferSize:0});m.Hasher=d.extend({cfg:y.extend(),init:function(o){this.cfg=this.cfg.extend(o),this.reset()},reset:function(){d.reset.call(this),this._doReset()},update:function(o){return this._append(o),this._process(),this},finalize:function(o){o&&this._append(o);var s=this._doFinalize();return s},blockSize:16,_createHelper:function(o){return function(s,a){return new o.init(a).finalize(s)}},_createHmacHelper:function(o){return function(s,a){return new A.HMAC.init(o,a).finalize(s)}}});var A=v.algo={};return v}(Math);return r})}(Y)),Y.exports}(function(e,t){(function(r,n){e.exports=n(_e())})(q,function(r){return function(){var n=r,c=n.lib,u=c.WordArray,l=n.enc;l.Base64url={stringify:function(v,m){m===void 0&&(m=!0);var y=v.words,w=v.sigBytes,b=m?this._safe_map:this._map;v.clamp();for(var f=[],p=0;p<w;p+=3)for(var i=y[p>>>2]>>>24-p%4*8&255,d=y[p+1>>>2]>>>24-(p+1)%4*8&255,A=y[p+2>>>2]>>>24-(p+2)%4*8&255,o=i<<16|d<<8|A,s=0;s<4&&p+s*.75<w;s++)f.push(b.charAt(o>>>6*(3-s)&63));var a=b.charAt(64);if(a)for(;f.length%4;)f.push(a);return f.join("")},parse:function(v,m){m===void 0&&(m=!0);var y=v.length,w=m?this._safe_map:this._map,b=this._reverseMap;if(!b){b=this._reverseMap=[];for(var f=0;f<w.length;f++)b[w.charCodeAt(f)]=f}var p=w.charAt(64);if(p){var i=v.indexOf(p);i!==-1&&(y=i)}return C(v,y,b)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function C(v,m,y){for(var w=[],b=0,f=0;f<m;f++)if(f%4){var p=y[v.charCodeAt(f-1)]<<f%4*2,i=y[v.charCodeAt(f)]>>>6-f%4*2,d=p|i;w[b>>>2]|=d<<24-b%4*8,b++}return u.create(w,b)}}(),r.enc.Base64url})})(me);var Ue=me.exports;const He=ye(Ue);var be={exports:{}};(function(e,t){(function(r,n){e.exports=n(_e())})(q,function(r){return function(n){var c=r,u=c.lib,l=u.WordArray,C=u.Hasher,v=c.algo,m=[],y=[];(function(){function f(A){for(var o=n.sqrt(A),s=2;s<=o;s++)if(!(A%s))return!1;return!0}function p(A){return(A-(A|0))*4294967296|0}for(var i=2,d=0;d<64;)f(i)&&(d<8&&(m[d]=p(n.pow(i,1/2))),y[d]=p(n.pow(i,1/3)),d++),i++})();var w=[],b=v.SHA256=C.extend({_doReset:function(){this._hash=new l.init(m.slice(0))},_doProcessBlock:function(f,p){for(var i=this._hash.words,d=i[0],A=i[1],o=i[2],s=i[3],a=i[4],h=i[5],_=i[6],S=i[7],B=0;B<64;B++){if(B<16)w[B]=f[p+B]|0;else{var x=w[B-15],j=(x<<25|x>>>7)^(x<<14|x>>>18)^x>>>3,U=w[B-2],D=(U<<15|U>>>17)^(U<<13|U>>>19)^U>>>10;w[B]=j+w[B-7]+D+w[B-16]}var Se=a&h^~a&_,Ce=d&A^d&o^A&o,ke=(d<<30|d>>>2)^(d<<19|d>>>13)^(d<<10|d>>>22),Be=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),ne=S+Be+Se+y[B]+w[B],xe=ke+Ce;S=_,_=h,h=a,a=s+ne|0,s=o,o=A,A=d,d=ne+xe|0}i[0]=i[0]+d|0,i[1]=i[1]+A|0,i[2]=i[2]+o|0,i[3]=i[3]+s|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 f=this._data,p=f.words,i=this._nDataBytes*8,d=f.sigBytes*8;return p[d>>>5]|=128<<24-d%32,p[(d+64>>>9<<4)+14]=n.floor(i/4294967296),p[(d+64>>>9<<4)+15]=i,f.sigBytes=p.length*4,this._process(),this._hash},clone:function(){var f=C.clone.call(this);return f._hash=this._hash.clone(),f}});c.SHA256=C._createHelper(b),c.HmacSHA256=C._createHmacHelper(b)}(Math),r.SHA256})})(be);var Te=be.exports;const Me=ye(Te),Le=(e,t)=>{const{client_id:r,redirect_uri:n,scope:c,state:u,chainId:l,chain:C,network:v,address:m,signature:y}=e,w=m?{address:m,...y!==void 0?{signature:y}:{},...l!==void 0||C!==void 0?{chain:l?Z(l):C}:{},...l!==void 0||v!==void 0?{network:l?re(l):v}:{}}:{};return te({client_id:r,redirect_uri:n,...c!==void 0?{scope:c}:{},...u!==void 0?{state:u}:{},code_challenge:t,code_challenge_method:"S256",response_type:"code",...w})},Ne=()=>{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},je=e=>He.stringify(Me(e)),se=(e,t)=>{const r=Ne(),n=je(r);return localStorage.setItem(M,r||""),`${e}/auth?${Le(t,n)}`},ie=()=>{const e=window.location.href;if(!e||!(e!=null&&e.includes("?")))return;const[t,r]=e.split("?");r&&window.history.replaceState(null,"",t)},ae=e=>e.code!=null,Fe=e=>e.refresh_token!=null,qe=e=>e.client_secret!=null,ce=async(e,t,r,n)=>{const c=await fetch(`${e}`,{method:t,headers:n,body:r});let u;const l=await c.text();try{u=JSON.parse(l)}catch{throw l}if(!c.ok)throw u;return u},T=typeof window>"u";var R,L,N,z,P,H,F,I,$,V,G,J;class De{constructor(t){O(this,H);O(this,I);O(this,R,void 0);O(this,L,void 0);O(this,N,void 0);O(this,z,void 0);O(this,P,void 0);O(this,V,void 0);O(this,G,void 0);O(this,J,void 0);if(E(this,z,new Map),this.isAuthorized=!!this.bearerProfile,E(this,V,async(r,n,c,u)=>{const l=localStorage.getItem(M)||"";if(!l)throw new Error("Code verifier not found");return this.codeVerifier=l,this.state=u,localStorage.removeItem(M),await k(this,H,F).call(this,{code:c,redirect_uri:n,client_id:r,code_verifier:l})}),E(this,G,async({clientId:r,clientSecret:n})=>await k(this,H,F).call(this,{client_id:r,client_secret:n})),E(this,J,async(r,n)=>await k(this,H,F).call(this,{refresh_token:n,client_id:r})),this.subscribeToOrderNotifications=()=>{var c,u;const r=`${g(this,R).wss}/profiles/${(c=this.bearerProfile)==null?void 0:c.profile}/orders?access_token=${(u=this.bearerProfile)==null?void 0:u.access_token}`,n=new WebSocket(r);return n.addEventListener("open",()=>{console.info(`Socket connected: ${r}`)}),n.addEventListener("error",l=>{throw console.error(l),new Error(`Socket error: ${r}`)}),n.addEventListener("message",l=>{var v;const C=JSON.parse(l.data);(v=g(this,z).get(C.meta.state))==null||v(C)}),n.addEventListener("close",()=>{console.info(`Socket connection closed: ${r}`)}),n},this.auth=async r=>await k(this,H,F).call(this,r),this.connect=async r=>await k(this,H,F).call(this,r),this.getAuthFlowURI=r=>{const n=se(g(this,R).api,r);return this.codeVerifier=localStorage.getItem(M),n},this.pkceRequest=r=>this.getAuthFlowURI(r),this.getEnvironment=()=>g(this,R),!t){E(this,R,X.environments.sandbox);return}if(typeof t=="string")E(this,R,X.environments[t]);else if(E(this,R,X.environments[t.environment||"sandbox"]),T){const{clientId:r,clientSecret:n}=t;E(this,P,{clientId:r,clientSecret:n})}else{const{clientId:r,redirectUrl:n}=t;E(this,P,{clientId:r,redirectUrl:n})}}async authorize(t){var u,l;const r=(t==null?void 0:t.clientId)||((u=g(this,P))==null?void 0:u.clientId),n=(t==null?void 0:t.redirectUrl)||((l=g(this,P))==null?void 0:l.redirectUrl);if(!r)throw new Error("Missing ClientId");if(!n)throw new Error("Missing RedirectUrl");const c=se(g(this,R).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,state:t==null?void 0:t.state});window.location.replace(c)}async getAccess(t){var v,m,y;const r=(t==null?void 0:t.clientId)||((v=g(this,P))==null?void 0:v.clientId);if((t==null?void 0:t.clientSecret)||((m=g(this,P))==null?void 0:m.clientSecret)){if(!T)throw new Error("Only use client credentials on server side");return await g(this,G).call(this,g(this,P)),!!this.bearerProfile}const c=(t==null?void 0:t.redirectUrl)||((y=g(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 u=new URLSearchParams(window.location.search).get("code")||void 0,l=new URLSearchParams(window.location.search).get("state")||void 0,C=localStorage.getItem(W)||void 0;return C?await g(this,J).call(this,r,C):u&&await g(this,V).call(this,r,c,u,l),!!this.bearerProfile}getAuthContext(){return k(this,I,$).call(this,"get","auth/context")}getProfile(t){return k(this,I,$).call(this,"get",`profiles/${t}`)}getBalances(t){return t?k(this,I,$).call(this,"get",`profiles/${t}/balances`):k(this,I,$).call(this,"get","balances")}getOrders(t){const r=te(t);return k(this,I,$).call(this,"get",`orders?${r}`)}getOrder(t){return k(this,I,$).call(this,"get",`orders/${t}`)}getTokens(){return k(this,I,$).call(this,"get","tokens")}linkAddress(t,r){return r=Q(r),r.accounts=r.accounts.map(n=>Q(n)),k(this,I,$).call(this,"post",`profiles/${t}/addresses`,JSON.stringify(r))}placeOrder(t,r){const n={kind:"redeem",currency:"eur",...Q(t),counterpart:{...t.counterpart,identifier:Q(t.counterpart.identifier)}};return r?k(this,I,$).call(this,"post",`profiles/${r}/orders`,JSON.stringify(n)):k(this,I,$).call(this,"post","orders",JSON.stringify(n))}uploadSupportingDocument(t){const r=new FormData;return r.append("file",t),ce(`${g(this,R).api}/files`,"post",r,{Authorization:g(this,L)||""})}async connectOrderSocket(){var t;(t=this.bearerProfile)!=null&&t.access_token&&g(this,z).size>0&&E(this,N,this.subscribeToOrderNotifications())}async disconnect(){var t;T||localStorage.removeItem(M),g(this,z).clear(),(t=g(this,N))==null||t.close(),E(this,L,void 0),this.bearerProfile=void 0}async revokeAccess(){T||localStorage.removeItem(W),this.disconnect()}subscribeOrders(t,r){g(this,z).set(t,r)}unsubscribeOrders(t){var r;g(this,z).delete(t),g(this,z).size===0&&((r=g(this,N))==null||r.close(),E(this,N,void 0))}}R=new WeakMap,L=new WeakMap,N=new WeakMap,z=new WeakMap,P=new WeakMap,H=new WeakSet,F=async function(t){let r;if(ae(t))r={...t,grant_type:"authorization_code"};else if(Fe(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 k(this,I,$).call(this,"post","auth/token",r,!0).then(n=>{var c;this.bearerProfile=n,this.isAuthorized=!!n,E(this,L,`Bearer ${n==null?void 0:n.access_token}`),T||window.localStorage.setItem(W,((c=this.bearerProfile)==null?void 0:c.refresh_token)||"")}).catch(n=>{throw T||(localStorage.removeItem(M),localStorage.removeItem(W),ie()),new Error(n==null?void 0:n.message)}),ae(t)&&ie(),this.bearerProfile},I=new WeakSet,$=async function(t,r,n,c){return ce(`${g(this,R).api}/${r}`,t,c?te(n):n,{Authorization:g(this,L)||"","Content-Type":`application/${c?"x-www-form-urlencoded":"json"}`})},V=new WeakMap,G=new WeakMap,J=new WeakMap;exports.AccountState=pe;exports.Currency=ue;exports.KYCOutcome=le;exports.KYCState=de;exports.MoneriumClient=De;exports.OrderKind=ge;exports.OrderState=we;exports.PaymentStandard=ve;exports.Permission=fe;exports.ProfileType=he;exports.constants=Ie;exports.getChain=Z;exports.getNetwork=re;exports.placeOrderMessage=Ae;exports.rfc3339=ee; |
{ | ||
"name": "@monerium/sdk", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "Everything you need to interact with the Monerium API - an electronic money issuer.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
{ | ||
"name": "@monerium/sdk", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "Everything you need to interact with the Monerium API - an electronic money issuer.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
128782