@monerium/sdk-react-provider 0.0.4 → 0.0.6
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 +435 -0
- package/README.md +55 -0
- package/dist/index.js +1 -0
- package/{index.mjs → dist/index.mjs} +160 -156
- package/dist/package.json +20 -0
- package/package.json +13 -8
- package/index.js +0 -1
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{lib → dist/lib}/context.d.ts +0 -0
- /package/{lib → dist/lib}/provider.d.ts +0 -0
|
@@ -6,11 +6,11 @@ var y = (o, e, t) => (te(o, e, "read from private field"), t ? t.call(o) : e.get
|
|
|
6
6
|
if (e.has(o))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
e instanceof WeakSet ? e.add(o) : e.set(o, t);
|
|
9
|
-
},
|
|
10
|
-
var
|
|
9
|
+
}, I = (o, e, t, n) => (te(o, e, "write to private field"), n ? n.call(o, t) : e.set(o, t), t);
|
|
10
|
+
var P = (o, e, t) => (te(o, e, "access private method"), t);
|
|
11
11
|
import { jsx as ve } from "react/jsx-runtime";
|
|
12
12
|
import { createContext as ge, useState as z, useEffect as re, useCallback as Y, useContext as we } from "react";
|
|
13
|
-
const
|
|
13
|
+
const de = ge(null), Z = (o) => {
|
|
14
14
|
var e;
|
|
15
15
|
return o && ((e = Object.entries(o)) == null ? void 0 : e.length) > 0 ? Object.entries(o).map(
|
|
16
16
|
([t, n]) => `${encodeURIComponent(t)}=${encodeURIComponent(n)}`
|
|
@@ -57,9 +57,9 @@ const fe = ge(null), Z = (o) => {
|
|
|
57
57
|
wss: "wss://api.monerium.dev"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
},
|
|
61
|
-
var
|
|
62
|
-
function
|
|
60
|
+
}, N = "monerium.sdk.code_verifier", oe = "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
63
|
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
64
64
|
}
|
|
65
65
|
function _e(o) {
|
|
@@ -89,7 +89,7 @@ function _e(o) {
|
|
|
89
89
|
});
|
|
90
90
|
}), t;
|
|
91
91
|
}
|
|
92
|
-
var
|
|
92
|
+
var he = { exports: {} };
|
|
93
93
|
function be(o) {
|
|
94
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
95
|
}
|
|
@@ -99,19 +99,19 @@ const Be = {}, ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
|
|
|
99
99
|
default: Be
|
|
100
100
|
}, Symbol.toStringTag, { value: "Module" })), Ce = /* @__PURE__ */ _e(ke);
|
|
101
101
|
var ae;
|
|
102
|
-
function
|
|
102
|
+
function le() {
|
|
103
103
|
return ae || (ae = 1, function(o, e) {
|
|
104
104
|
(function(t, n) {
|
|
105
105
|
o.exports = n();
|
|
106
|
-
})(
|
|
106
|
+
})(j, function() {
|
|
107
107
|
var t = t || function(n, i) {
|
|
108
108
|
var c;
|
|
109
|
-
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
|
|
109
|
+
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 j < "u" && j.crypto && (c = j.crypto), !c && typeof be == "function")
|
|
110
110
|
try {
|
|
111
111
|
c = Ce;
|
|
112
112
|
} catch {
|
|
113
113
|
}
|
|
114
|
-
var
|
|
114
|
+
var f = function() {
|
|
115
115
|
if (c) {
|
|
116
116
|
if (typeof c.getRandomValues == "function")
|
|
117
117
|
try {
|
|
@@ -132,7 +132,7 @@ function he() {
|
|
|
132
132
|
var u;
|
|
133
133
|
return r.prototype = s, u = new r(), r.prototype = null, u;
|
|
134
134
|
};
|
|
135
|
-
}(),
|
|
135
|
+
}(), l = {}, w = l.lib = {}, m = w.Base = function() {
|
|
136
136
|
return {
|
|
137
137
|
/**
|
|
138
138
|
* Creates a new object that inherits from this object.
|
|
@@ -247,7 +247,7 @@ function he() {
|
|
|
247
247
|
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
248
248
|
*/
|
|
249
249
|
toString: function(r) {
|
|
250
|
-
return (r ||
|
|
250
|
+
return (r || h).stringify(this);
|
|
251
251
|
},
|
|
252
252
|
/**
|
|
253
253
|
* Concatenates a word array to this word array.
|
|
@@ -261,15 +261,15 @@ function he() {
|
|
|
261
261
|
* wordArray1.concat(wordArray2);
|
|
262
262
|
*/
|
|
263
263
|
concat: function(r) {
|
|
264
|
-
var s = this.words, u = r.words,
|
|
265
|
-
if (this.clamp(),
|
|
264
|
+
var s = this.words, u = r.words, d = this.sigBytes, _ = r.sigBytes;
|
|
265
|
+
if (this.clamp(), d % 4)
|
|
266
266
|
for (var b = 0; b < _; b++) {
|
|
267
267
|
var S = u[b >>> 2] >>> 24 - b % 4 * 8 & 255;
|
|
268
|
-
s[
|
|
268
|
+
s[d + b >>> 2] |= S << 24 - (d + b) % 4 * 8;
|
|
269
269
|
}
|
|
270
270
|
else
|
|
271
271
|
for (var x = 0; x < _; x += 4)
|
|
272
|
-
s[
|
|
272
|
+
s[d + x >>> 2] = u[x >>> 2];
|
|
273
273
|
return this.sigBytes += _, this;
|
|
274
274
|
},
|
|
275
275
|
/**
|
|
@@ -311,10 +311,10 @@ function he() {
|
|
|
311
311
|
*/
|
|
312
312
|
random: function(r) {
|
|
313
313
|
for (var s = [], u = 0; u < r; u += 4)
|
|
314
|
-
s.push(
|
|
314
|
+
s.push(f());
|
|
315
315
|
return new g.init(s, r);
|
|
316
316
|
}
|
|
317
|
-
}), B =
|
|
317
|
+
}), B = l.enc = {}, h = B.Hex = {
|
|
318
318
|
/**
|
|
319
319
|
* Converts a word array to a hex string.
|
|
320
320
|
*
|
|
@@ -329,11 +329,11 @@ function he() {
|
|
|
329
329
|
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
330
330
|
*/
|
|
331
331
|
stringify: function(r) {
|
|
332
|
-
for (var s = r.words, u = r.sigBytes,
|
|
332
|
+
for (var s = r.words, u = r.sigBytes, d = [], _ = 0; _ < u; _++) {
|
|
333
333
|
var b = s[_ >>> 2] >>> 24 - _ % 4 * 8 & 255;
|
|
334
|
-
|
|
334
|
+
d.push((b >>> 4).toString(16)), d.push((b & 15).toString(16));
|
|
335
335
|
}
|
|
336
|
-
return
|
|
336
|
+
return d.join("");
|
|
337
337
|
},
|
|
338
338
|
/**
|
|
339
339
|
* Converts a hex string to a word array.
|
|
@@ -349,8 +349,8 @@ function he() {
|
|
|
349
349
|
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
350
350
|
*/
|
|
351
351
|
parse: function(r) {
|
|
352
|
-
for (var s = r.length, u = [],
|
|
353
|
-
u[
|
|
352
|
+
for (var s = r.length, u = [], d = 0; d < s; d += 2)
|
|
353
|
+
u[d >>> 3] |= parseInt(r.substr(d, 2), 16) << 24 - d % 8 * 4;
|
|
354
354
|
return new g.init(u, s / 2);
|
|
355
355
|
}
|
|
356
356
|
}, v = B.Latin1 = {
|
|
@@ -368,11 +368,11 @@ function he() {
|
|
|
368
368
|
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
369
369
|
*/
|
|
370
370
|
stringify: function(r) {
|
|
371
|
-
for (var s = r.words, u = r.sigBytes,
|
|
371
|
+
for (var s = r.words, u = r.sigBytes, d = [], _ = 0; _ < u; _++) {
|
|
372
372
|
var b = s[_ >>> 2] >>> 24 - _ % 4 * 8 & 255;
|
|
373
|
-
|
|
373
|
+
d.push(String.fromCharCode(b));
|
|
374
374
|
}
|
|
375
|
-
return
|
|
375
|
+
return d.join("");
|
|
376
376
|
},
|
|
377
377
|
/**
|
|
378
378
|
* Converts a Latin1 string to a word array.
|
|
@@ -388,8 +388,8 @@ function he() {
|
|
|
388
388
|
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
389
389
|
*/
|
|
390
390
|
parse: function(r) {
|
|
391
|
-
for (var s = r.length, u = [],
|
|
392
|
-
u[
|
|
391
|
+
for (var s = r.length, u = [], d = 0; d < s; d++)
|
|
392
|
+
u[d >>> 2] |= (r.charCodeAt(d) & 255) << 24 - d % 4 * 8;
|
|
393
393
|
return new g.init(u, s);
|
|
394
394
|
}
|
|
395
395
|
}, a = B.Utf8 = {
|
|
@@ -468,13 +468,13 @@ function he() {
|
|
|
468
468
|
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
469
469
|
*/
|
|
470
470
|
_process: function(r) {
|
|
471
|
-
var s, u = this._data,
|
|
471
|
+
var s, u = this._data, d = u.words, _ = u.sigBytes, b = this.blockSize, S = b * 4, x = _ / S;
|
|
472
472
|
r ? x = n.ceil(x) : x = n.max((x | 0) - this._minBufferSize, 0);
|
|
473
473
|
var D = x * b, U = n.min(D * 4, _);
|
|
474
474
|
if (D) {
|
|
475
475
|
for (var F = 0; F < D; F += b)
|
|
476
|
-
this._doProcessBlock(
|
|
477
|
-
s =
|
|
476
|
+
this._doProcessBlock(d, F);
|
|
477
|
+
s = d.splice(0, D), u.sigBytes -= U;
|
|
478
478
|
}
|
|
479
479
|
return new g.init(s, U);
|
|
480
480
|
},
|
|
@@ -592,8 +592,8 @@ function he() {
|
|
|
592
592
|
};
|
|
593
593
|
}
|
|
594
594
|
});
|
|
595
|
-
var C =
|
|
596
|
-
return
|
|
595
|
+
var C = l.algo = {};
|
|
596
|
+
return l;
|
|
597
597
|
}(Math);
|
|
598
598
|
return t;
|
|
599
599
|
});
|
|
@@ -601,11 +601,11 @@ function he() {
|
|
|
601
601
|
}
|
|
602
602
|
(function(o, e) {
|
|
603
603
|
(function(t, n) {
|
|
604
|
-
o.exports = n(
|
|
605
|
-
})(
|
|
604
|
+
o.exports = n(le());
|
|
605
|
+
})(j, function(t) {
|
|
606
606
|
return function() {
|
|
607
|
-
var n = t, i = n.lib, c = i.WordArray,
|
|
608
|
-
|
|
607
|
+
var n = t, i = n.lib, c = i.WordArray, f = n.enc;
|
|
608
|
+
f.Base64url = {
|
|
609
609
|
/**
|
|
610
610
|
* Converts a word array to a Base64url string.
|
|
611
611
|
*
|
|
@@ -621,18 +621,18 @@ function he() {
|
|
|
621
621
|
*
|
|
622
622
|
* var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
|
|
623
623
|
*/
|
|
624
|
-
stringify: function(
|
|
624
|
+
stringify: function(l, w) {
|
|
625
625
|
w === void 0 && (w = !0);
|
|
626
|
-
var m =
|
|
627
|
-
|
|
628
|
-
for (var
|
|
626
|
+
var m = l.words, g = l.sigBytes, B = w ? this._safe_map : this._map;
|
|
627
|
+
l.clamp();
|
|
628
|
+
for (var h = [], v = 0; v < g; v += 3)
|
|
629
629
|
for (var a = m[v >>> 2] >>> 24 - v % 4 * 8 & 255, p = m[v + 1 >>> 2] >>> 24 - (v + 1) % 4 * 8 & 255, C = m[v + 2 >>> 2] >>> 24 - (v + 2) % 4 * 8 & 255, r = a << 16 | p << 8 | C, s = 0; s < 4 && v + s * 0.75 < g; s++)
|
|
630
|
-
|
|
630
|
+
h.push(B.charAt(r >>> 6 * (3 - s) & 63));
|
|
631
631
|
var u = B.charAt(64);
|
|
632
632
|
if (u)
|
|
633
|
-
for (;
|
|
634
|
-
|
|
635
|
-
return
|
|
633
|
+
for (; h.length % 4; )
|
|
634
|
+
h.push(u);
|
|
635
|
+
return h.join("");
|
|
636
636
|
},
|
|
637
637
|
/**
|
|
638
638
|
* Converts a Base64url string to a word array.
|
|
@@ -649,46 +649,46 @@ function he() {
|
|
|
649
649
|
*
|
|
650
650
|
* var wordArray = CryptoJS.enc.Base64url.parse(base64String);
|
|
651
651
|
*/
|
|
652
|
-
parse: function(
|
|
652
|
+
parse: function(l, w) {
|
|
653
653
|
w === void 0 && (w = !0);
|
|
654
|
-
var m =
|
|
654
|
+
var m = l.length, g = w ? this._safe_map : this._map, B = this._reverseMap;
|
|
655
655
|
if (!B) {
|
|
656
656
|
B = this._reverseMap = [];
|
|
657
|
-
for (var
|
|
658
|
-
B[g.charCodeAt(
|
|
657
|
+
for (var h = 0; h < g.length; h++)
|
|
658
|
+
B[g.charCodeAt(h)] = h;
|
|
659
659
|
}
|
|
660
660
|
var v = g.charAt(64);
|
|
661
661
|
if (v) {
|
|
662
|
-
var a =
|
|
662
|
+
var a = l.indexOf(v);
|
|
663
663
|
a !== -1 && (m = a);
|
|
664
664
|
}
|
|
665
|
-
return k(
|
|
665
|
+
return k(l, m, B);
|
|
666
666
|
},
|
|
667
667
|
_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
668
668
|
_safe_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
669
669
|
};
|
|
670
|
-
function k(
|
|
671
|
-
for (var g = [], B = 0,
|
|
672
|
-
if (
|
|
673
|
-
var v = m[
|
|
670
|
+
function k(l, w, m) {
|
|
671
|
+
for (var g = [], B = 0, h = 0; h < w; h++)
|
|
672
|
+
if (h % 4) {
|
|
673
|
+
var v = m[l.charCodeAt(h - 1)] << h % 4 * 2, a = m[l.charCodeAt(h)] >>> 6 - h % 4 * 2, p = v | a;
|
|
674
674
|
g[B >>> 2] |= p << 24 - B % 4 * 8, B++;
|
|
675
675
|
}
|
|
676
676
|
return c.create(g, B);
|
|
677
677
|
}
|
|
678
678
|
}(), t.enc.Base64url;
|
|
679
679
|
});
|
|
680
|
-
})(
|
|
681
|
-
var Se =
|
|
682
|
-
const xe = /* @__PURE__ */
|
|
680
|
+
})(he);
|
|
681
|
+
var Se = he.exports;
|
|
682
|
+
const xe = /* @__PURE__ */ fe(Se);
|
|
683
683
|
var pe = { exports: {} };
|
|
684
684
|
(function(o, e) {
|
|
685
685
|
(function(t, n) {
|
|
686
|
-
o.exports = n(
|
|
687
|
-
})(
|
|
686
|
+
o.exports = n(le());
|
|
687
|
+
})(j, function(t) {
|
|
688
688
|
return function(n) {
|
|
689
|
-
var i = t, c = i.lib,
|
|
689
|
+
var i = t, c = i.lib, f = c.WordArray, k = c.Hasher, l = i.algo, w = [], m = [];
|
|
690
690
|
(function() {
|
|
691
|
-
function
|
|
691
|
+
function h(C) {
|
|
692
692
|
for (var r = n.sqrt(C), s = 2; s <= r; s++)
|
|
693
693
|
if (!(C % s))
|
|
694
694
|
return !1;
|
|
@@ -698,32 +698,32 @@ var pe = { exports: {} };
|
|
|
698
698
|
return (C - (C | 0)) * 4294967296 | 0;
|
|
699
699
|
}
|
|
700
700
|
for (var a = 2, p = 0; p < 64; )
|
|
701
|
-
|
|
701
|
+
h(a) && (p < 8 && (w[p] = v(n.pow(a, 1 / 2))), m[p] = v(n.pow(a, 1 / 3)), p++), a++;
|
|
702
702
|
})();
|
|
703
|
-
var g = [], B =
|
|
703
|
+
var g = [], B = l.SHA256 = k.extend({
|
|
704
704
|
_doReset: function() {
|
|
705
|
-
this._hash = new
|
|
705
|
+
this._hash = new f.init(w.slice(0));
|
|
706
706
|
},
|
|
707
|
-
_doProcessBlock: function(
|
|
708
|
-
for (var a = this._hash.words, p = a[0], C = a[1], r = a[2], s = a[3], u = a[4],
|
|
707
|
+
_doProcessBlock: function(h, v) {
|
|
708
|
+
for (var a = this._hash.words, p = a[0], C = a[1], r = a[2], s = a[3], u = a[4], d = a[5], _ = a[6], b = a[7], S = 0; S < 64; S++) {
|
|
709
709
|
if (S < 16)
|
|
710
|
-
g[S] =
|
|
710
|
+
g[S] = h[v + S] | 0;
|
|
711
711
|
else {
|
|
712
712
|
var x = g[S - 15], D = (x << 25 | x >>> 7) ^ (x << 14 | x >>> 18) ^ x >>> 3, U = g[S - 2], F = (U << 15 | U >>> 17) ^ (U << 13 | U >>> 19) ^ U >>> 10;
|
|
713
713
|
g[S] = D + g[S - 7] + F + g[S - 16];
|
|
714
714
|
}
|
|
715
|
-
var ee = u &
|
|
716
|
-
b = _, _ =
|
|
715
|
+
var ee = u & d ^ ~u & _, A = p & C ^ p & r ^ C & r, R = (p << 30 | p >>> 2) ^ (p << 19 | p >>> 13) ^ (p << 10 | p >>> 22), M = (u << 26 | u >>> 6) ^ (u << 21 | u >>> 11) ^ (u << 7 | u >>> 25), q = b + M + ee + m[S] + g[S], V = R + A;
|
|
716
|
+
b = _, _ = d, d = u, u = s + q | 0, s = r, r = C, C = p, p = q + V | 0;
|
|
717
717
|
}
|
|
718
|
-
a[0] = a[0] + p | 0, a[1] = a[1] + C | 0, a[2] = a[2] + r | 0, a[3] = a[3] + s | 0, a[4] = a[4] + u | 0, a[5] = a[5] +
|
|
718
|
+
a[0] = a[0] + p | 0, a[1] = a[1] + C | 0, a[2] = a[2] + r | 0, a[3] = a[3] + s | 0, a[4] = a[4] + u | 0, a[5] = a[5] + d | 0, a[6] = a[6] + _ | 0, a[7] = a[7] + b | 0;
|
|
719
719
|
},
|
|
720
720
|
_doFinalize: function() {
|
|
721
|
-
var
|
|
722
|
-
return v[p >>> 5] |= 128 << 24 - p % 32, v[(p + 64 >>> 9 << 4) + 14] = n.floor(a / 4294967296), v[(p + 64 >>> 9 << 4) + 15] = a,
|
|
721
|
+
var h = this._data, v = h.words, a = this._nDataBytes * 8, p = h.sigBytes * 8;
|
|
722
|
+
return v[p >>> 5] |= 128 << 24 - p % 32, v[(p + 64 >>> 9 << 4) + 14] = n.floor(a / 4294967296), v[(p + 64 >>> 9 << 4) + 15] = a, h.sigBytes = v.length * 4, this._process(), this._hash;
|
|
723
723
|
},
|
|
724
724
|
clone: function() {
|
|
725
|
-
var
|
|
726
|
-
return
|
|
725
|
+
var h = k.clone.call(this);
|
|
726
|
+
return h._hash = this._hash.clone(), h;
|
|
727
727
|
}
|
|
728
728
|
});
|
|
729
729
|
i.SHA256 = k._createHelper(B), i.HmacSHA256 = k._createHmacHelper(B);
|
|
@@ -731,22 +731,22 @@ var pe = { exports: {} };
|
|
|
731
731
|
});
|
|
732
732
|
})(pe);
|
|
733
733
|
var Ae = pe.exports;
|
|
734
|
-
const Ee = /* @__PURE__ */
|
|
734
|
+
const Ee = /* @__PURE__ */ fe(Ae), Ie = (o, e) => {
|
|
735
735
|
const {
|
|
736
736
|
client_id: t,
|
|
737
737
|
redirect_uri: n,
|
|
738
738
|
scope: i,
|
|
739
739
|
state: c,
|
|
740
|
-
chainId:
|
|
740
|
+
chainId: f,
|
|
741
741
|
chain: k,
|
|
742
|
-
network:
|
|
742
|
+
network: l,
|
|
743
743
|
address: w,
|
|
744
744
|
signature: m
|
|
745
745
|
} = o, g = w ? {
|
|
746
746
|
address: w,
|
|
747
747
|
...m !== void 0 ? { signature: m } : {},
|
|
748
|
-
...
|
|
749
|
-
...
|
|
748
|
+
...f !== void 0 || k !== void 0 ? { chain: f ? ye(f) : k } : {},
|
|
749
|
+
...f !== void 0 || l !== void 0 ? { network: f ? me(f) : l } : {}
|
|
750
750
|
} : {};
|
|
751
751
|
return Z({
|
|
752
752
|
client_id: t,
|
|
@@ -758,16 +758,16 @@ const Ee = /* @__PURE__ */ de(Ae), Pe = (o, e) => {
|
|
|
758
758
|
response_type: "code",
|
|
759
759
|
...g
|
|
760
760
|
});
|
|
761
|
-
},
|
|
761
|
+
}, Pe = () => {
|
|
762
762
|
let o = "";
|
|
763
763
|
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", t = e.length;
|
|
764
764
|
let n = 0;
|
|
765
765
|
for (; n < 128; )
|
|
766
766
|
o += e.charAt(Math.floor(Math.random() * t)), n += 1;
|
|
767
767
|
return o;
|
|
768
|
-
},
|
|
769
|
-
const t =
|
|
770
|
-
return sessionStorage.setItem(
|
|
768
|
+
}, Oe = (o) => xe.stringify(Ee(o)), ce = (o, e) => {
|
|
769
|
+
const t = Pe(), n = Oe(t);
|
|
770
|
+
return sessionStorage.setItem(N, t || ""), `${o}/auth?${Ie(e, n)}`;
|
|
771
771
|
}, Re = () => {
|
|
772
772
|
const o = window.location.href, [e, t] = o.split("?");
|
|
773
773
|
t && window.history.replaceState(null, "", e);
|
|
@@ -778,17 +778,17 @@ const Ee = /* @__PURE__ */ de(Ae), Pe = (o, e) => {
|
|
|
778
778
|
body: t
|
|
779
779
|
});
|
|
780
780
|
let c;
|
|
781
|
-
const
|
|
781
|
+
const f = await i.text();
|
|
782
782
|
try {
|
|
783
|
-
c = JSON.parse(
|
|
783
|
+
c = JSON.parse(f);
|
|
784
784
|
} catch {
|
|
785
|
-
throw
|
|
785
|
+
throw f;
|
|
786
786
|
}
|
|
787
787
|
if (!i.ok)
|
|
788
788
|
throw c;
|
|
789
789
|
return c;
|
|
790
790
|
}, ie = typeof window > "u";
|
|
791
|
-
var T, G, W, L, $, E,
|
|
791
|
+
var T, G, W, L, $, E, O, J, K, Q;
|
|
792
792
|
class Ue {
|
|
793
793
|
constructor(e) {
|
|
794
794
|
// -- Helper Methods
|
|
@@ -802,23 +802,23 @@ class Ue {
|
|
|
802
802
|
H(this, J, void 0);
|
|
803
803
|
H(this, K, void 0);
|
|
804
804
|
H(this, Q, void 0);
|
|
805
|
-
if (
|
|
806
|
-
const c = sessionStorage.getItem(
|
|
805
|
+
if (I(this, L, /* @__PURE__ */ new Map()), this.isAuthorized = !!this.bearerProfile, I(this, J, async (t, n, i) => {
|
|
806
|
+
const c = sessionStorage.getItem(N) || "";
|
|
807
807
|
if (!c)
|
|
808
808
|
throw new Error("Code verifier not found");
|
|
809
|
-
return this.codeVerifier = c, sessionStorage.removeItem(
|
|
809
|
+
return this.codeVerifier = c, sessionStorage.removeItem(N), await this.getBearerToken({
|
|
810
810
|
code: i,
|
|
811
811
|
redirect_uri: n,
|
|
812
812
|
client_id: t,
|
|
813
813
|
code_verifier: c
|
|
814
814
|
});
|
|
815
|
-
}),
|
|
815
|
+
}), I(this, K, async ({
|
|
816
816
|
clientId: t,
|
|
817
817
|
clientSecret: n
|
|
818
818
|
}) => await this.getBearerToken({
|
|
819
819
|
client_id: t,
|
|
820
820
|
client_secret: n
|
|
821
|
-
})),
|
|
821
|
+
})), I(this, Q, async (t, n) => await this.getBearerToken({
|
|
822
822
|
refresh_token: n,
|
|
823
823
|
client_id: t
|
|
824
824
|
})), this.subscribeToOrderNotifications = () => {
|
|
@@ -826,32 +826,35 @@ class Ue {
|
|
|
826
826
|
const t = `${y(this, T).wss}/profiles/${(i = this.bearerProfile) == null ? void 0 : i.profile}/orders?access_token=${(c = this.bearerProfile) == null ? void 0 : c.access_token}`, n = new WebSocket(t);
|
|
827
827
|
return n.addEventListener("open", () => {
|
|
828
828
|
console.info(`Socket connected: ${t}`);
|
|
829
|
-
}), n.addEventListener("error", (
|
|
830
|
-
throw console.error(
|
|
831
|
-
}), n.addEventListener("message", (
|
|
832
|
-
var
|
|
833
|
-
const k = JSON.parse(
|
|
834
|
-
(
|
|
829
|
+
}), n.addEventListener("error", (f) => {
|
|
830
|
+
throw console.error(f), new Error(`Socket error: ${t}`);
|
|
831
|
+
}), n.addEventListener("message", (f) => {
|
|
832
|
+
var l;
|
|
833
|
+
const k = JSON.parse(f.data);
|
|
834
|
+
(l = y(this, L).get(k.meta.state)) == null || l(
|
|
835
835
|
k
|
|
836
836
|
);
|
|
837
837
|
}), n.addEventListener("close", () => {
|
|
838
838
|
console.info(`Socket connection closed: ${t}`);
|
|
839
839
|
}), n;
|
|
840
|
-
}, this.auth = async (t) => await this.getBearerToken(t), this.getAuthFlowURI = (t) =>
|
|
841
|
-
|
|
840
|
+
}, this.auth = async (t) => await this.getBearerToken(t), this.getAuthFlowURI = (t) => {
|
|
841
|
+
const n = ce(y(this, T).api, t);
|
|
842
|
+
return this.codeVerifier = sessionStorage.getItem(N), n;
|
|
843
|
+
}, this.pkceRequest = (t) => this.getAuthFlowURI(t), this.getEnvironment = () => y(this, T), !e) {
|
|
844
|
+
I(this, T, ne.environments.sandbox);
|
|
842
845
|
return;
|
|
843
846
|
}
|
|
844
847
|
if (typeof e == "string")
|
|
845
|
-
|
|
846
|
-
else if (
|
|
848
|
+
I(this, T, ne.environments[e]);
|
|
849
|
+
else if (I(this, T, ne.environments[e.environment || "sandbox"]), ie) {
|
|
847
850
|
const { clientId: t, clientSecret: n } = e;
|
|
848
|
-
|
|
851
|
+
I(this, $, {
|
|
849
852
|
clientId: t,
|
|
850
853
|
clientSecret: n
|
|
851
854
|
});
|
|
852
855
|
} else {
|
|
853
856
|
const { clientId: t, redirectUrl: n } = e;
|
|
854
|
-
|
|
857
|
+
I(this, $, {
|
|
855
858
|
clientId: t,
|
|
856
859
|
redirectUrl: n
|
|
857
860
|
});
|
|
@@ -865,8 +868,8 @@ class Ue {
|
|
|
865
868
|
* {@link https://monerium.dev/api-docs#operation/auth}
|
|
866
869
|
*/
|
|
867
870
|
async authorize(e) {
|
|
868
|
-
var c,
|
|
869
|
-
const t = (e == null ? void 0 : e.clientId) || ((c = y(this, $)) == null ? void 0 : c.clientId), n = (e == null ? void 0 : e.redirectUrl) || ((
|
|
871
|
+
var c, f;
|
|
872
|
+
const t = (e == null ? void 0 : e.clientId) || ((c = y(this, $)) == null ? void 0 : c.clientId), n = (e == null ? void 0 : e.redirectUrl) || ((f = y(this, $)) == null ? void 0 : f.redirectUrl);
|
|
870
873
|
if (!t)
|
|
871
874
|
throw new Error("Missing ClientId");
|
|
872
875
|
if (!n)
|
|
@@ -874,15 +877,16 @@ class Ue {
|
|
|
874
877
|
const i = ce(y(this, T).api, {
|
|
875
878
|
client_id: t,
|
|
876
879
|
redirect_uri: n,
|
|
877
|
-
|
|
880
|
+
address: e == null ? void 0 : e.address,
|
|
881
|
+
signature: e == null ? void 0 : e.signature,
|
|
882
|
+
chainId: e == null ? void 0 : e.chainId
|
|
878
883
|
});
|
|
879
884
|
window.location.replace(i);
|
|
880
885
|
}
|
|
881
|
-
// TODO: TEST auto link & manual link + address
|
|
882
886
|
async connect(e) {
|
|
883
|
-
var k,
|
|
887
|
+
var k, l, w;
|
|
884
888
|
const t = (e == null ? void 0 : e.clientId) || ((k = y(this, $)) == null ? void 0 : k.clientId);
|
|
885
|
-
if ((e == null ? void 0 : e.clientSecret) || ((
|
|
889
|
+
if ((e == null ? void 0 : e.clientSecret) || ((l = y(this, $)) == null ? void 0 : l.clientSecret)) {
|
|
886
890
|
if (!ie)
|
|
887
891
|
throw new Error("Only use client credentials on server side");
|
|
888
892
|
return await y(this, K).call(this, y(this, $)), !!this.bearerProfile;
|
|
@@ -892,8 +896,8 @@ class Ue {
|
|
|
892
896
|
throw new Error("Missing ClientId");
|
|
893
897
|
if (ie)
|
|
894
898
|
throw new Error("This only works on client side");
|
|
895
|
-
const c = new URLSearchParams(window.location.search).get("code") || void 0,
|
|
896
|
-
return c ? await y(this, J).call(this, t, i, c) :
|
|
899
|
+
const c = new URLSearchParams(window.location.search).get("code") || void 0, f = sessionStorage.getItem(oe) || void 0;
|
|
900
|
+
return c ? await y(this, J).call(this, t, i, c) : f && await y(this, Q).call(this, t, f), !!this.bearerProfile;
|
|
897
901
|
}
|
|
898
902
|
/**
|
|
899
903
|
* {@link https://monerium.dev/api-docs#operation/auth-token}
|
|
@@ -908,14 +912,14 @@ class Ue {
|
|
|
908
912
|
t = { ...e, grant_type: "client_credentials" };
|
|
909
913
|
else
|
|
910
914
|
throw new Error("Authentication method could not be detected.");
|
|
911
|
-
return await
|
|
915
|
+
return await P(this, E, O).call(this, "post", "auth/token", t, !0).then((n) => {
|
|
912
916
|
var i;
|
|
913
|
-
this.bearerProfile = n, this.isAuthorized = !!n,
|
|
917
|
+
this.bearerProfile = n, this.isAuthorized = !!n, I(this, G, `Bearer ${n == null ? void 0 : n.access_token}`), window.sessionStorage.setItem(
|
|
914
918
|
oe,
|
|
915
919
|
((i = this.bearerProfile) == null ? void 0 : i.refresh_token) || ""
|
|
916
920
|
);
|
|
917
921
|
}).catch((n) => {
|
|
918
|
-
throw sessionStorage.removeItem(
|
|
922
|
+
throw sessionStorage.removeItem(N), sessionStorage.removeItem(oe), new Error(n == null ? void 0 : n.message);
|
|
919
923
|
}), ue(e) && Re(), this.bearerProfile;
|
|
920
924
|
}
|
|
921
925
|
// -- Read Methods
|
|
@@ -923,7 +927,7 @@ class Ue {
|
|
|
923
927
|
* {@link https://monerium.dev/api-docs#operation/auth-context}
|
|
924
928
|
*/
|
|
925
929
|
getAuthContext() {
|
|
926
|
-
return
|
|
930
|
+
return P(this, E, O).call(this, "get", "auth/context");
|
|
927
931
|
}
|
|
928
932
|
/**
|
|
929
933
|
* {@link https://monerium.dev/api-docs#operation/profile}
|
|
@@ -931,47 +935,47 @@ class Ue {
|
|
|
931
935
|
|
|
932
936
|
*/
|
|
933
937
|
getProfile(e) {
|
|
934
|
-
return
|
|
938
|
+
return P(this, E, O).call(this, "get", `profiles/${e}`);
|
|
935
939
|
}
|
|
936
940
|
/**
|
|
937
941
|
* {@link https://monerium.dev/api-docs#operation/profile-balances}
|
|
938
942
|
* @param {string=} profileId - the id of the profile to fetch balances.
|
|
939
943
|
*/
|
|
940
944
|
getBalances(e) {
|
|
941
|
-
return e ?
|
|
945
|
+
return e ? P(this, E, O).call(this, "get", `profiles/${e}/balances`) : P(this, E, O).call(this, "get", "balances");
|
|
942
946
|
}
|
|
943
947
|
/**
|
|
944
948
|
* {@link https://monerium.dev/api-docs#operation/orders}
|
|
945
949
|
*/
|
|
946
950
|
getOrders(e) {
|
|
947
951
|
const t = Z(e);
|
|
948
|
-
return
|
|
952
|
+
return P(this, E, O).call(this, "get", `orders?${t}`);
|
|
949
953
|
}
|
|
950
954
|
/**
|
|
951
955
|
* {@link https://monerium.dev/api-docs#operation/order}
|
|
952
956
|
*/
|
|
953
957
|
getOrder(e) {
|
|
954
|
-
return
|
|
958
|
+
return P(this, E, O).call(this, "get", `orders/${e}`);
|
|
955
959
|
}
|
|
956
960
|
/**
|
|
957
961
|
* {@link https://monerium.dev/api-docs#operation/tokens}
|
|
958
962
|
*/
|
|
959
963
|
getTokens() {
|
|
960
|
-
return
|
|
964
|
+
return P(this, E, O).call(this, "get", "tokens");
|
|
961
965
|
}
|
|
962
966
|
// -- Write Methods
|
|
963
967
|
/**
|
|
964
968
|
* {@link https://monerium.dev/api-docs#operation/profile-addresses}
|
|
965
969
|
*/
|
|
966
970
|
linkAddress(e, t) {
|
|
967
|
-
return
|
|
971
|
+
return P(this, E, O).call(this, "post", `profiles/${e}/addresses`, JSON.stringify(t));
|
|
968
972
|
}
|
|
969
973
|
/**
|
|
970
974
|
* {@link https://monerium.dev/api-docs#operation/post-orders}
|
|
971
975
|
*/
|
|
972
976
|
placeOrder(e, t) {
|
|
973
977
|
const n = { ...e, kind: "redeem", currency: "eur" };
|
|
974
|
-
return t ?
|
|
978
|
+
return t ? P(this, E, O).call(this, "post", `profiles/${t}/orders`, JSON.stringify(n)) : P(this, E, O).call(this, "post", "orders", JSON.stringify(n));
|
|
975
979
|
}
|
|
976
980
|
/**
|
|
977
981
|
* {@link https://monerium.dev/api-docs#operation/supporting-document}
|
|
@@ -980,16 +984,16 @@ class Ue {
|
|
|
980
984
|
const t = Z(
|
|
981
985
|
e
|
|
982
986
|
);
|
|
983
|
-
return
|
|
987
|
+
return P(this, E, O).call(this, "post", "files/supporting-document", t, !0);
|
|
984
988
|
}
|
|
985
989
|
// -- Notifications
|
|
986
990
|
async connectOrderSocket() {
|
|
987
991
|
var e;
|
|
988
|
-
(e = this.bearerProfile) != null && e.access_token && y(this, L).size > 0 &&
|
|
992
|
+
(e = this.bearerProfile) != null && e.access_token && y(this, L).size > 0 && I(this, W, this.subscribeToOrderNotifications());
|
|
989
993
|
}
|
|
990
994
|
async disconnect() {
|
|
991
995
|
var e;
|
|
992
|
-
sessionStorage.removeItem(
|
|
996
|
+
sessionStorage.removeItem(N), y(this, L).clear(), (e = y(this, W)) == null || e.close();
|
|
993
997
|
}
|
|
994
998
|
/**
|
|
995
999
|
* Subscribe to MoneriumEvent to receive notifications using the Monerium API (WebSocket)
|
|
@@ -1007,10 +1011,10 @@ class Ue {
|
|
|
1007
1011
|
*/
|
|
1008
1012
|
unsubscribeOrders(e) {
|
|
1009
1013
|
var t;
|
|
1010
|
-
y(this, L).delete(e), y(this, L).size === 0 && ((t = y(this, W)) == null || t.close(),
|
|
1014
|
+
y(this, L).delete(e), y(this, L).size === 0 && ((t = y(this, W)) == null || t.close(), I(this, W, void 0));
|
|
1011
1015
|
}
|
|
1012
1016
|
}
|
|
1013
|
-
T = new WeakMap(), G = new WeakMap(), W = new WeakMap(), L = new WeakMap(), $ = new WeakMap(), E = new WeakSet(),
|
|
1017
|
+
T = new WeakMap(), G = new WeakMap(), W = new WeakMap(), L = new WeakMap(), $ = new WeakMap(), E = new WeakSet(), O = async function(e, t, n, i) {
|
|
1014
1018
|
return $e(
|
|
1015
1019
|
`${y(this, T).api}/${t}`,
|
|
1016
1020
|
e,
|
|
@@ -1027,7 +1031,7 @@ const De = ({
|
|
|
1027
1031
|
redirectUrl: t = "http://localhost:5173",
|
|
1028
1032
|
environment: n = "sandbox"
|
|
1029
1033
|
}) => {
|
|
1030
|
-
const [i, c] = z(), [
|
|
1034
|
+
const [i, c] = z(), [f, k] = z(!1), [l, w] = z(null), [m, g] = z(null), [B, h] = z(!1), [v, a] = z(!1), [p, C] = z(!1), [r, s] = z(!1), [u, d] = z(null), [_, b] = z([]), [S, x] = z([]);
|
|
1031
1035
|
re(() => {
|
|
1032
1036
|
const A = new Ue({
|
|
1033
1037
|
environment: n,
|
|
@@ -1041,38 +1045,38 @@ const De = ({
|
|
|
1041
1045
|
i && i.disconnect();
|
|
1042
1046
|
}), [i]), re(() => {
|
|
1043
1047
|
(async () => {
|
|
1044
|
-
if (i &&
|
|
1048
|
+
if (i && f)
|
|
1045
1049
|
try {
|
|
1046
|
-
|
|
1047
|
-
const R = await i.getAuthContext(), M = await i.getProfile(R.defaultProfile), q = await i.getBalances(),
|
|
1048
|
-
w(M), g(q), b(
|
|
1050
|
+
h(!0);
|
|
1051
|
+
const R = await i.getAuthContext(), M = await i.getProfile(R.defaultProfile), q = await i.getBalances(), V = await i.getOrders(), X = await i.getTokens();
|
|
1052
|
+
w(M), g(q), b(V), x(X);
|
|
1049
1053
|
} catch (R) {
|
|
1050
|
-
console.error("Error fetching data:", R),
|
|
1054
|
+
console.error("Error fetching data:", R), d(R);
|
|
1051
1055
|
} finally {
|
|
1052
|
-
|
|
1056
|
+
h(!1);
|
|
1053
1057
|
}
|
|
1054
1058
|
})();
|
|
1055
|
-
}, [i,
|
|
1059
|
+
}, [i, f]);
|
|
1056
1060
|
const D = Y(async () => {
|
|
1057
1061
|
try {
|
|
1058
1062
|
i && await i.authorize();
|
|
1059
1063
|
} catch (A) {
|
|
1060
|
-
console.error("Error during authorization:", A),
|
|
1064
|
+
console.error("Error during authorization:", A), d(A);
|
|
1061
1065
|
}
|
|
1062
1066
|
}, [i]), U = Y(async () => {
|
|
1063
|
-
if (i &&
|
|
1067
|
+
if (i && f)
|
|
1064
1068
|
try {
|
|
1065
1069
|
s(!0);
|
|
1066
1070
|
const A = await i.getBalances();
|
|
1067
1071
|
g(A);
|
|
1068
1072
|
} catch (A) {
|
|
1069
|
-
console.error("Error getting balances:", A),
|
|
1073
|
+
console.error("Error getting balances:", A), d(A);
|
|
1070
1074
|
} finally {
|
|
1071
1075
|
s(!1);
|
|
1072
1076
|
}
|
|
1073
|
-
}, [i,
|
|
1077
|
+
}, [i, f]), F = Y(
|
|
1074
1078
|
async (A, R) => {
|
|
1075
|
-
if (i &&
|
|
1079
|
+
if (i && f)
|
|
1076
1080
|
try {
|
|
1077
1081
|
a(!0);
|
|
1078
1082
|
let M;
|
|
@@ -1082,35 +1086,35 @@ const De = ({
|
|
|
1082
1086
|
const q = {
|
|
1083
1087
|
...A,
|
|
1084
1088
|
documentId: M
|
|
1085
|
-
},
|
|
1086
|
-
b((X) => [...X,
|
|
1089
|
+
}, V = await i.placeOrder(q);
|
|
1090
|
+
b((X) => [...X, V]);
|
|
1087
1091
|
} catch (M) {
|
|
1088
|
-
console.error("Error placing order:", M),
|
|
1092
|
+
console.error("Error placing order:", M), d(M);
|
|
1089
1093
|
} finally {
|
|
1090
1094
|
a(!1);
|
|
1091
1095
|
}
|
|
1092
1096
|
},
|
|
1093
|
-
[i,
|
|
1097
|
+
[i, f]
|
|
1094
1098
|
), ee = Y(
|
|
1095
1099
|
async (A) => {
|
|
1096
|
-
if (i &&
|
|
1100
|
+
if (i && f && l)
|
|
1097
1101
|
try {
|
|
1098
|
-
return C(!0), await i.linkAddress(
|
|
1102
|
+
return C(!0), await i.linkAddress(l.id, A);
|
|
1099
1103
|
} catch (R) {
|
|
1100
|
-
console.error("Error linking address:", R),
|
|
1104
|
+
console.error("Error linking address:", R), d(R);
|
|
1101
1105
|
} finally {
|
|
1102
1106
|
C(!1);
|
|
1103
1107
|
}
|
|
1104
1108
|
},
|
|
1105
|
-
[i,
|
|
1109
|
+
[i, f, l]
|
|
1106
1110
|
);
|
|
1107
1111
|
return /* @__PURE__ */ ve(
|
|
1108
|
-
|
|
1112
|
+
de.Provider,
|
|
1109
1113
|
{
|
|
1110
1114
|
value: {
|
|
1111
1115
|
authorize: D,
|
|
1112
|
-
isAuthorized:
|
|
1113
|
-
profile:
|
|
1116
|
+
isAuthorized: f,
|
|
1117
|
+
profile: l,
|
|
1114
1118
|
balances: m,
|
|
1115
1119
|
loading: B,
|
|
1116
1120
|
loadingPlaceOrder: v,
|
|
@@ -1128,13 +1132,13 @@ const De = ({
|
|
|
1128
1132
|
);
|
|
1129
1133
|
};
|
|
1130
1134
|
function Fe() {
|
|
1131
|
-
const o = we(
|
|
1135
|
+
const o = we(de);
|
|
1132
1136
|
if (o === null)
|
|
1133
1137
|
throw new Error("useMonerium must be used within a MoneriumProvider");
|
|
1134
1138
|
return o;
|
|
1135
1139
|
}
|
|
1136
1140
|
export {
|
|
1137
|
-
|
|
1141
|
+
de as MoneriumContext,
|
|
1138
1142
|
De as MoneriumProvider,
|
|
1139
1143
|
Fe as useMonerium
|
|
1140
1144
|
};
|