@monerium/sdk 2.6.4 → 2.7.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 +507 -49
- package/README.md +303 -66
- package/dist/client.d.ts +99 -0
- package/dist/config.d.ts +3 -0
- package/dist/constants.d.ts +9 -0
- package/dist/helpers/auth.helpers.d.ts +23 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/service.helpers.d.ts +1 -0
- package/dist/index.d.ts +4 -334
- package/dist/index.js +1 -0
- package/dist/index.mjs +542 -364
- package/dist/package.json +41 -0
- package/dist/types.d.ts +348 -0
- package/dist/utils.d.ts +27 -0
- package/package.json +16 -46
- package/dist/index.mjs.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,334 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
web: string;
|
|
6
|
-
};
|
|
7
|
-
export type Config = {
|
|
8
|
-
environments: {
|
|
9
|
-
production: Environment;
|
|
10
|
-
sandbox: Environment;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type ENV = "sandbox" | "production";
|
|
14
|
-
export type EthereumTestnet = "goerli";
|
|
15
|
-
export type GnosisTestnet = "chiado";
|
|
16
|
-
export type PolygonTestnet = "mumbai";
|
|
17
|
-
export type Chain = "ethereum" | "gnosis" | "polygon";
|
|
18
|
-
export type Networks = EthereumTestnet | GnosisTestnet | PolygonTestnet | "mainnet";
|
|
19
|
-
export type NetworkSemiStrict<C extends Chain> = C extends "ethereum" ? EthereumTestnet | "mainnet" : C extends "gnosis" ? GnosisTestnet | "mainnet" : C extends "polygon" ? PolygonTestnet | "mainnet" : never;
|
|
20
|
-
export type NetworkStrict<C extends Chain, E extends ENV> = E extends "production" ? "mainnet" : E extends "sandbox" ? C extends "ethereum" ? EthereumTestnet : C extends "gnosis" ? GnosisTestnet : C extends "polygon" ? PolygonTestnet : never : never;
|
|
21
|
-
export type Network<C extends Chain = Chain, E extends ENV = ENV> = C extends Chain ? E extends ENV ? NetworkStrict<C, E> & NetworkSemiStrict<C> : never : never;
|
|
22
|
-
export declare enum Currency {
|
|
23
|
-
eur = "eur"
|
|
24
|
-
}
|
|
25
|
-
export type AuthArgs = Omit<AuthCode, "grant_type"> | Omit<RefreshToken, "grant_type"> | Omit<ClientCredentials, "grant_type">;
|
|
26
|
-
export interface AuthCode {
|
|
27
|
-
grant_type: "authorization_code";
|
|
28
|
-
client_id: string;
|
|
29
|
-
code: string;
|
|
30
|
-
code_verifier: string;
|
|
31
|
-
redirect_uri: string;
|
|
32
|
-
scope?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface BearerProfile {
|
|
35
|
-
access_token: string;
|
|
36
|
-
token_type: string;
|
|
37
|
-
expires_in: number;
|
|
38
|
-
refresh_token: string;
|
|
39
|
-
profile: string;
|
|
40
|
-
userId: string;
|
|
41
|
-
}
|
|
42
|
-
export interface RefreshToken {
|
|
43
|
-
grant_type: "refresh_token";
|
|
44
|
-
client_id: string;
|
|
45
|
-
refresh_token: string;
|
|
46
|
-
scope?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface ClientCredentials {
|
|
49
|
-
grant_type: "client_credentials";
|
|
50
|
-
client_id: string;
|
|
51
|
-
client_secret: string;
|
|
52
|
-
scope?: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @returns A {@link PKCERequest} object with properties omitted that are automatically computed in by the SDK.
|
|
56
|
-
*/
|
|
57
|
-
export type PKCERequestArgs = Omit<PKCERequest, "code_challenge" | "code_challenge_method" | "response_type">;
|
|
58
|
-
export type PKCERequest = {
|
|
59
|
-
/** the authentication flow client id of the application */
|
|
60
|
-
client_id: string;
|
|
61
|
-
/** the code challenge automatically generated by the SDK */
|
|
62
|
-
code_challenge: string;
|
|
63
|
-
/** the code challenge method for the authentication flow , handled by the SDK */
|
|
64
|
-
code_challenge_method: "S256";
|
|
65
|
-
/** the response type of the authentication flow, handled by the SDK */
|
|
66
|
-
response_type: "code";
|
|
67
|
-
/** the state of the application */
|
|
68
|
-
state?: string;
|
|
69
|
-
/** the redirect uri of the application */
|
|
70
|
-
redirect_uri?: string;
|
|
71
|
-
/** the scope of the application */
|
|
72
|
-
scope?: string;
|
|
73
|
-
/** the address of the wallet to automatically link */
|
|
74
|
-
address?: string;
|
|
75
|
-
/** the signature of the wallet to automatically link */
|
|
76
|
-
signature?: string;
|
|
77
|
-
/** the network of the wallet to automatically link */
|
|
78
|
-
network?: Network;
|
|
79
|
-
/** the chain of the wallet to automatically link */
|
|
80
|
-
chain?: Chain;
|
|
81
|
-
};
|
|
82
|
-
declare enum Method {
|
|
83
|
-
password = "password",
|
|
84
|
-
resource = "resource",
|
|
85
|
-
jwt = "jwt",
|
|
86
|
-
apiKey = "apiKey"
|
|
87
|
-
}
|
|
88
|
-
export declare enum ProfileType {
|
|
89
|
-
corporate = "corporate",
|
|
90
|
-
personal = "personal"
|
|
91
|
-
}
|
|
92
|
-
export declare enum Permission {
|
|
93
|
-
read = "read",
|
|
94
|
-
write = "write"
|
|
95
|
-
}
|
|
96
|
-
export interface AuthProfile {
|
|
97
|
-
id: string;
|
|
98
|
-
type: ProfileType;
|
|
99
|
-
name: string;
|
|
100
|
-
perms: Permission[];
|
|
101
|
-
}
|
|
102
|
-
export interface AuthContext {
|
|
103
|
-
userId: string;
|
|
104
|
-
email: string;
|
|
105
|
-
name: string;
|
|
106
|
-
roles: "admin"[];
|
|
107
|
-
auth: {
|
|
108
|
-
method: Method;
|
|
109
|
-
subject: string;
|
|
110
|
-
verified: boolean;
|
|
111
|
-
};
|
|
112
|
-
defaultProfile: string;
|
|
113
|
-
profiles: AuthProfile[];
|
|
114
|
-
}
|
|
115
|
-
export declare enum KYCState {
|
|
116
|
-
absent = "absent",
|
|
117
|
-
submitted = "submitted",
|
|
118
|
-
pending = "pending",
|
|
119
|
-
confirmed = "confirmed"
|
|
120
|
-
}
|
|
121
|
-
export declare enum KYCOutcome {
|
|
122
|
-
approved = "approved",
|
|
123
|
-
rejected = "rejected",
|
|
124
|
-
unknown = "unknown"
|
|
125
|
-
}
|
|
126
|
-
export declare enum AccountState {
|
|
127
|
-
requested = "requested",
|
|
128
|
-
approved = "approved",
|
|
129
|
-
pending = "pending"
|
|
130
|
-
}
|
|
131
|
-
export interface KYC {
|
|
132
|
-
state: KYCState;
|
|
133
|
-
outcome: KYCOutcome;
|
|
134
|
-
}
|
|
135
|
-
export declare enum PaymentStandard {
|
|
136
|
-
iban = "iban",
|
|
137
|
-
scan = "scan"
|
|
138
|
-
}
|
|
139
|
-
export interface Account {
|
|
140
|
-
address: string;
|
|
141
|
-
currency: Currency;
|
|
142
|
-
standard: PaymentStandard;
|
|
143
|
-
iban?: string;
|
|
144
|
-
network: Network;
|
|
145
|
-
chain: Chain;
|
|
146
|
-
id?: string;
|
|
147
|
-
state?: AccountState;
|
|
148
|
-
}
|
|
149
|
-
export interface Profile {
|
|
150
|
-
id: string;
|
|
151
|
-
name: string;
|
|
152
|
-
kyc: KYC;
|
|
153
|
-
accounts: Account[];
|
|
154
|
-
}
|
|
155
|
-
export interface Balance {
|
|
156
|
-
currency: Currency;
|
|
157
|
-
amount: string;
|
|
158
|
-
}
|
|
159
|
-
export interface Balances {
|
|
160
|
-
id: string;
|
|
161
|
-
address: string;
|
|
162
|
-
chain: Chain;
|
|
163
|
-
network: Network;
|
|
164
|
-
balances: Balance[];
|
|
165
|
-
}
|
|
166
|
-
export declare enum OrderKind {
|
|
167
|
-
redeem = "redeem",
|
|
168
|
-
issue = "issue"
|
|
169
|
-
}
|
|
170
|
-
export declare enum OrderState {
|
|
171
|
-
placed = "placed",
|
|
172
|
-
pending = "pending",
|
|
173
|
-
processed = "processed",
|
|
174
|
-
rejected = "rejected"
|
|
175
|
-
}
|
|
176
|
-
export interface Fee {
|
|
177
|
-
provider: "satchel";
|
|
178
|
-
currency: Currency;
|
|
179
|
-
amount: string;
|
|
180
|
-
}
|
|
181
|
-
export interface IBAN {
|
|
182
|
-
standard: PaymentStandard.iban;
|
|
183
|
-
iban: string;
|
|
184
|
-
}
|
|
185
|
-
export interface SCAN {
|
|
186
|
-
standard: PaymentStandard.scan;
|
|
187
|
-
sortCode: string;
|
|
188
|
-
accountNumber: string;
|
|
189
|
-
}
|
|
190
|
-
export interface Individual {
|
|
191
|
-
firstName: string;
|
|
192
|
-
lastName: string;
|
|
193
|
-
country?: string;
|
|
194
|
-
}
|
|
195
|
-
export interface Corporation {
|
|
196
|
-
companyName: string;
|
|
197
|
-
country: string;
|
|
198
|
-
}
|
|
199
|
-
export interface Counterpart {
|
|
200
|
-
identifier: IBAN | SCAN;
|
|
201
|
-
details: Individual | Corporation;
|
|
202
|
-
}
|
|
203
|
-
export interface OrderMetadata {
|
|
204
|
-
approvedAt: string;
|
|
205
|
-
processedAt: string;
|
|
206
|
-
rejectedAt: string;
|
|
207
|
-
state: OrderState;
|
|
208
|
-
placedBy: string;
|
|
209
|
-
placedAt: string;
|
|
210
|
-
receivedAmount: string;
|
|
211
|
-
sentAmount: string;
|
|
212
|
-
}
|
|
213
|
-
export interface OrderFilter {
|
|
214
|
-
address?: string;
|
|
215
|
-
txHash?: string;
|
|
216
|
-
profile?: string;
|
|
217
|
-
memo?: string;
|
|
218
|
-
accountId?: string;
|
|
219
|
-
state?: OrderState;
|
|
220
|
-
}
|
|
221
|
-
export interface Order {
|
|
222
|
-
id: string;
|
|
223
|
-
profile: string;
|
|
224
|
-
accountId: string;
|
|
225
|
-
address: string;
|
|
226
|
-
kind: OrderKind;
|
|
227
|
-
amount: string;
|
|
228
|
-
currency: Currency;
|
|
229
|
-
totalFee: string;
|
|
230
|
-
fees: Fee[];
|
|
231
|
-
counterpart: Counterpart;
|
|
232
|
-
memo: string;
|
|
233
|
-
rejectedReason: string;
|
|
234
|
-
supportingDocumentId: string;
|
|
235
|
-
meta: OrderMetadata;
|
|
236
|
-
}
|
|
237
|
-
export interface Token {
|
|
238
|
-
currency: Currency;
|
|
239
|
-
ticker: string;
|
|
240
|
-
symbol: string;
|
|
241
|
-
chain: Chain;
|
|
242
|
-
network: Network;
|
|
243
|
-
address: string;
|
|
244
|
-
decimals: number;
|
|
245
|
-
}
|
|
246
|
-
export type NewOrder = NewOrderByAddress | NewOrderByAccountId;
|
|
247
|
-
export interface NewOrderCommon {
|
|
248
|
-
amount: string;
|
|
249
|
-
signature: string;
|
|
250
|
-
counterpart: Counterpart;
|
|
251
|
-
message: string;
|
|
252
|
-
memo?: string;
|
|
253
|
-
supportingDocumentId?: string;
|
|
254
|
-
}
|
|
255
|
-
export interface NewOrderByAddress extends NewOrderCommon {
|
|
256
|
-
address: string;
|
|
257
|
-
chain: Chain;
|
|
258
|
-
network: Network;
|
|
259
|
-
}
|
|
260
|
-
export interface NewOrderByAccountId extends NewOrderCommon {
|
|
261
|
-
accountId: string;
|
|
262
|
-
}
|
|
263
|
-
export interface SupportingDocMetadata {
|
|
264
|
-
uploadedBy: string;
|
|
265
|
-
createdAt: string;
|
|
266
|
-
updatedAt: string;
|
|
267
|
-
}
|
|
268
|
-
export interface SupportingDoc {
|
|
269
|
-
id: string;
|
|
270
|
-
name: string;
|
|
271
|
-
type: string;
|
|
272
|
-
size: number;
|
|
273
|
-
hash: string;
|
|
274
|
-
meta: SupportingDocMetadata;
|
|
275
|
-
}
|
|
276
|
-
export interface CurrencyAccounts {
|
|
277
|
-
network: Network;
|
|
278
|
-
chain: Chain;
|
|
279
|
-
currency: Currency;
|
|
280
|
-
}
|
|
281
|
-
export interface LinkAddress {
|
|
282
|
-
address: string;
|
|
283
|
-
message: string;
|
|
284
|
-
signature: string;
|
|
285
|
-
accounts: CurrencyAccounts[];
|
|
286
|
-
network?: Network;
|
|
287
|
-
chain?: Chain;
|
|
288
|
-
}
|
|
289
|
-
export declare class MoneriumClient {
|
|
290
|
-
#private;
|
|
291
|
-
/** The PKCE code verifier */
|
|
292
|
-
codeVerifier?: string;
|
|
293
|
-
bearerProfile?: BearerProfile;
|
|
294
|
-
constructor(env?: "production" | "sandbox");
|
|
295
|
-
auth(args: AuthArgs): Promise<BearerProfile>;
|
|
296
|
-
/**
|
|
297
|
-
* Construct the url to the authorization code flow,
|
|
298
|
-
* the code verifier is needed afterwards to obtain an access token and is therefore stored in `this.codeVerifier`
|
|
299
|
-
* For automatic wallet link, add the following properties: `address`, `signature`, `chain` & `network`
|
|
300
|
-
* @returns string
|
|
301
|
-
*/
|
|
302
|
-
getAuthFlowURI(args: PKCERequestArgs): string;
|
|
303
|
-
/**
|
|
304
|
-
* @deprecated since v2.0.7, use {@link getAuthFlowURI} instead.
|
|
305
|
-
*/
|
|
306
|
-
pkceRequest: (args: PKCERequestArgs) => string;
|
|
307
|
-
getAuthContext(): Promise<AuthContext>;
|
|
308
|
-
/**
|
|
309
|
-
* @param {string} profileId - the id of the profile to fetch.
|
|
310
|
-
*/
|
|
311
|
-
getProfile(profileId: string): Promise<Profile>;
|
|
312
|
-
/**
|
|
313
|
-
* @param {string=} profileId - the id of the profile to fetch balances.
|
|
314
|
-
*/
|
|
315
|
-
getBalances(profileId?: string): Promise<Balances[]>;
|
|
316
|
-
getOrders(filter?: OrderFilter): Promise<Order[]>;
|
|
317
|
-
getOrder(orderId: string): Promise<Order>;
|
|
318
|
-
getTokens(): Promise<Token[]>;
|
|
319
|
-
linkAddress(profileId: string, body: LinkAddress): Promise<unknown>;
|
|
320
|
-
placeOrder(order: NewOrder, profileId?: string): Promise<Order>;
|
|
321
|
-
uploadSupportingDocument(document: File): Promise<SupportingDoc>;
|
|
322
|
-
}
|
|
323
|
-
export declare const constants: {
|
|
324
|
-
LINK_MESSAGE: string;
|
|
325
|
-
};
|
|
326
|
-
export declare const rfc3339: (d: Date) => string;
|
|
327
|
-
/**
|
|
328
|
-
* The message to be signed when placing an order.
|
|
329
|
-
*
|
|
330
|
-
* @returns string
|
|
331
|
-
*/
|
|
332
|
-
export declare const placeOrderMessage: (amount: string | number, iban: string) => string;
|
|
333
|
-
|
|
334
|
-
export {};
|
|
1
|
+
export { MoneriumClient } from './client';
|
|
2
|
+
export { default as constants } from './constants';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { placeOrderMessage, rfc3339 } from './utils';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var G=(e,r,t)=>{if(!r.has(e))throw TypeError("Cannot "+t)};var w=(e,r,t)=>(G(e,r,"read from private field"),t?t.call(e):r.get(e)),T=(e,r,t)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,t)},A=(e,r,t,n)=>(G(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t);var I=(e,r,t)=>(G(e,r,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var re=(e=>(e.eur="eur",e))(re||{}),te=(e=>(e.corporate="corporate",e.personal="personal",e))(te||{}),ne=(e=>(e.read="read",e.write="write",e))(ne||{}),oe=(e=>(e.absent="absent",e.submitted="submitted",e.pending="pending",e.confirmed="confirmed",e))(oe||{}),se=(e=>(e.approved="approved",e.rejected="rejected",e.unknown="unknown",e))(se||{}),ie=(e=>(e.requested="requested",e.approved="approved",e.pending="pending",e))(ie||{}),ae=(e=>(e.iban="iban",e.scan="scan",e))(ae||{}),ce=(e=>(e.redeem="redeem",e.issue="issue",e))(ce||{}),ue=(e=>(e.placed="placed",e.pending="pending",e.processed="processed",e.rejected="rejected",e))(ue||{});const de=e=>{if(e.toString()==="Invalid Date")throw e;const r=n=>n<10?"0"+n:n,t=n=>{if(n===0)return"Z";const u=n>0?"-":"+";return n=Math.abs(n),u+r(Math.floor(n/60))+":"+r(n%60)};return e.getFullYear()+"-"+r(e.getMonth()+1)+"-"+r(e.getDate())+"T"+r(e.getHours())+":"+r(e.getMinutes())+":"+r(e.getSeconds())+t(e.getTimezoneOffset())},_e=(e,r)=>`Send EUR ${e} to ${r} at ${de(new Date)}`,D=e=>{var r;return e&&((r=Object.entries(e))==null?void 0:r.length)>0?Object.entries(e).map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(n)}`).join("&"):""},be=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}`)}},Se=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}`)}},J={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"}}},Be="I hereby declare that I am the address owner.",U="monerium.sdk.code_verifier",V="monerium.sdk.refresh_token",ke={LINK_MESSAGE:Be,STORAGE_CODE_VERIFIER:U,STORAGE_REFRESH_TOKEN:V};var L=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ce(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function n(){if(this instanceof n){var u=[null];u.push.apply(u,arguments);var i=Function.bind.apply(r,u);return new i}return r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var u=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,u.get?u:{enumerable:!0,get:function(){return e[n]}})}),t}var fe={exports:{}};function xe(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 Q={exports:{}};const Ee={},Ae=Object.freeze(Object.defineProperty({__proto__:null,default:Ee},Symbol.toStringTag,{value:"Module"})),Ie=Ce(Ae);var X;function le(){return X||(X=1,function(e,r){(function(t,n){e.exports=n()})(L,function(){var t=t||function(n,u){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof L<"u"&&L.crypto&&(i=L.crypto),!i&&typeof xe=="function")try{i=Ie}catch{}var v=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},B=Object.create||function(){function o(){}return function(s){var c;return o.prototype=s,c=new o,o.prototype=null,c}}(),p={},y=p.lib={},m=y.Base=function(){return{extend:function(o){var s=B(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=y.WordArray=m.extend({init:function(o,s){o=this.words=o||[],s!=u?this.sigBytes=s:this.sigBytes=o.length*4},toString:function(o){return(o||h).stringify(this)},concat:function(o){var s=this.words,c=o.words,d=this.sigBytes,_=o.sigBytes;if(this.clamp(),d%4)for(var S=0;S<_;S++){var k=c[S>>>2]>>>24-S%4*8&255;s[d+S>>>2]|=k<<24-(d+S)%4*8}else for(var C=0;C<_;C+=4)s[d+C>>>2]=c[C>>>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=m.clone.call(this);return o.words=this.words.slice(0),o},random:function(o){for(var s=[],c=0;c<o;c+=4)s.push(v());return new g.init(s,o)}}),b=p.enc={},h=b.Hex={stringify:function(o){for(var s=o.words,c=o.sigBytes,d=[],_=0;_<c;_++){var S=s[_>>>2]>>>24-_%4*8&255;d.push((S>>>4).toString(16)),d.push((S&15).toString(16))}return d.join("")},parse:function(o){for(var s=o.length,c=[],d=0;d<s;d+=2)c[d>>>3]|=parseInt(o.substr(d,2),16)<<24-d%8*4;return new g.init(c,s/2)}},l=b.Latin1={stringify:function(o){for(var s=o.words,c=o.sigBytes,d=[],_=0;_<c;_++){var S=s[_>>>2]>>>24-_%4*8&255;d.push(String.fromCharCode(S))}return d.join("")},parse:function(o){for(var s=o.length,c=[],d=0;d<s;d++)c[d>>>2]|=(o.charCodeAt(d)&255)<<24-d%4*8;return new g.init(c,s)}},a=b.Utf8={stringify:function(o){try{return decodeURIComponent(escape(l.stringify(o)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(o){return l.parse(unescape(encodeURIComponent(o)))}},f=y.BufferedBlockAlgorithm=m.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(o){typeof o=="string"&&(o=a.parse(o)),this._data.concat(o),this._nDataBytes+=o.sigBytes},_process:function(o){var s,c=this._data,d=c.words,_=c.sigBytes,S=this.blockSize,k=S*4,C=_/k;o?C=n.ceil(C):C=n.max((C|0)-this._minBufferSize,0);var M=C*S,z=n.min(M*4,_);if(M){for(var j=0;j<M;j+=S)this._doProcessBlock(d,j);s=d.splice(0,M),c.sigBytes-=z}return new g.init(s,z)},clone:function(){var o=m.clone.call(this);return o._data=this._data.clone(),o},_minBufferSize:0});y.Hasher=f.extend({cfg:m.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,c){return new o.init(c).finalize(s)}},_createHmacHelper:function(o){return function(s,c){return new x.HMAC.init(o,c).finalize(s)}}});var x=p.algo={};return p}(Math);return t})}(Q)),Q.exports}(function(e,r){(function(t,n){e.exports=n(le())})(L,function(t){return function(){var n=t,u=n.lib,i=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 a=m[l>>>2]>>>24-l%4*8&255,f=m[l+1>>>2]>>>24-(l+1)%4*8&255,x=m[l+2>>>2]>>>24-(l+2)%4*8&255,o=a<<16|f<<8|x,s=0;s<4&&l+s*.75<g;s++)h.push(b.charAt(o>>>6*(3-s)&63));var c=b.charAt(64);if(c)for(;h.length%4;)h.push(c);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 a=p.indexOf(l);a!==-1&&(m=a)}return B(p,m,b)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"};function B(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,a=m[p.charCodeAt(h)]>>>6-h%4*2,f=l|a;g[b>>>2]|=f<<24-b%4*8,b++}return i.create(g,b)}}(),t.enc.Base64url})})(fe);var Re=fe.exports;const Oe=he(Re);var pe={exports:{}};(function(e,r){(function(t,n){e.exports=n(le())})(L,function(t){return function(n){var u=t,i=u.lib,v=i.WordArray,B=i.Hasher,p=u.algo,y=[],m=[];(function(){function h(x){for(var o=n.sqrt(x),s=2;s<=o;s++)if(!(x%s))return!1;return!0}function l(x){return(x-(x|0))*4294967296|0}for(var a=2,f=0;f<64;)h(a)&&(f<8&&(y[f]=l(n.pow(a,1/2))),m[f]=l(n.pow(a,1/3)),f++),a++})();var g=[],b=p.SHA256=B.extend({_doReset:function(){this._hash=new v.init(y.slice(0))},_doProcessBlock:function(h,l){for(var a=this._hash.words,f=a[0],x=a[1],o=a[2],s=a[3],c=a[4],d=a[5],_=a[6],S=a[7],k=0;k<64;k++){if(k<16)g[k]=h[l+k]|0;else{var C=g[k-15],M=(C<<25|C>>>7)^(C<<14|C>>>18)^C>>>3,z=g[k-2],j=(z<<15|z>>>17)^(z<<13|z>>>19)^z>>>10;g[k]=M+g[k-7]+j+g[k-16]}var ve=c&d^~c&_,ge=f&x^f&o^x&o,we=(f<<30|f>>>2)^(f<<19|f>>>13)^(f<<10|f>>>22),ye=(c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25),K=S+ye+ve+m[k]+g[k],me=we+ge;S=_,_=d,d=c,c=s+K|0,s=o,o=x,x=f,f=K+me|0}a[0]=a[0]+f|0,a[1]=a[1]+x|0,a[2]=a[2]+o|0,a[3]=a[3]+s|0,a[4]=a[4]+c|0,a[5]=a[5]+d|0,a[6]=a[6]+_|0,a[7]=a[7]+S|0},_doFinalize:function(){var h=this._data,l=h.words,a=this._nDataBytes*8,f=h.sigBytes*8;return l[f>>>5]|=128<<24-f%32,l[(f+64>>>9<<4)+14]=n.floor(a/4294967296),l[(f+64>>>9<<4)+15]=a,h.sigBytes=l.length*4,this._process(),this._hash},clone:function(){var h=B.clone.call(this);return h._hash=this._hash.clone(),h}});u.SHA256=B._createHelper(b),u.HmacSHA256=B._createHmacHelper(b)}(Math),t.SHA256})})(pe);var Pe=pe.exports;const Te=he(Pe),$e=(e,r)=>{const{client_id:t,redirect_uri:n,scope:u,state:i,chainId:v,chain:B,network:p,address:y,signature:m}=e,g=y?{address:y,...m!==void 0?{signature:m}:{},...v!==void 0||B!==void 0?{chain:v?be(v):B}:{},...v!==void 0||p!==void 0?{network:v?Se(v):p}:{}}:{};return D({client_id:t,redirect_uri:n,...u!==void 0?{scope:u}:{},...i!==void 0?{state:i}:{},code_challenge:r,code_challenge_method:"S256",response_type:"code",...g})},ze=()=>{let e="";const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=r.length;let n=0;for(;n<128;)e+=r.charAt(Math.floor(Math.random()*t)),n+=1;return e},Ue=e=>Oe.stringify(Te(e)),Y=(e,r)=>{const t=ze(),n=Ue(t);return sessionStorage.setItem(U,t||""),`${e}/auth?${$e(r,n)}`},He=()=>{const e=window.location.href,[r,t]=e.split("?");t&&window.history.replaceState(null,"",r)},ee=e=>e.code!=null,Me=e=>e.refresh_token!=null,Le=e=>e.client_secret!=null,je=async(e,r,t,n)=>{const u=await fetch(`${e}`,{method:r,headers:n,body:t});let i;const v=await u.text();try{i=JSON.parse(v)}catch{throw v}if(!u.ok)throw i;return i},Z=typeof window>"u";var O,q,H,$,P,E,R,F,N,W;class qe{constructor(r){T(this,E);T(this,O,void 0);T(this,q,void 0);T(this,H,void 0);T(this,$,void 0);T(this,P,void 0);T(this,F,void 0);T(this,N,void 0);T(this,W,void 0);if(A(this,$,new Map),this.isAuthorized=!!this.bearerProfile,A(this,F,async(t,n,u)=>{const i=sessionStorage.getItem(U)||"";if(!i)throw new Error("Code verifier not found");return this.codeVerifier=i,sessionStorage.removeItem(U),await this.getBearerToken({code:u,redirect_uri:n,client_id:t,code_verifier:i})}),A(this,N,async({clientId:t,clientSecret:n})=>await this.getBearerToken({client_id:t,client_secret:n})),A(this,W,async(t,n)=>await this.getBearerToken({refresh_token:n,client_id:t})),this.subscribeToOrderNotifications=()=>{var u,i;const t=`${w(this,O).wss}/profiles/${(u=this.bearerProfile)==null?void 0:u.profile}/orders?access_token=${(i=this.bearerProfile)==null?void 0:i.access_token}`,n=new WebSocket(t);return n.addEventListener("open",()=>{console.info(`Socket connected: ${t}`)}),n.addEventListener("error",v=>{throw console.error(v),new Error(`Socket error: ${t}`)}),n.addEventListener("message",v=>{var p;const B=JSON.parse(v.data);(p=w(this,$).get(B.meta.state))==null||p(B)}),n.addEventListener("close",()=>{console.info(`Socket connection closed: ${t}`)}),n},this.auth=async t=>await this.getBearerToken(t),this.getAuthFlowURI=t=>{const n=Y(w(this,O).api,t);return this.codeVerifier=sessionStorage.getItem(U),n},this.pkceRequest=t=>this.getAuthFlowURI(t),this.getEnvironment=()=>w(this,O),!r){A(this,O,J.environments.sandbox);return}if(typeof r=="string")A(this,O,J.environments[r]);else if(A(this,O,J.environments[r.environment||"sandbox"]),Z){const{clientId:t,clientSecret:n}=r;A(this,P,{clientId:t,clientSecret:n})}else{const{clientId:t,redirectUrl:n}=r;A(this,P,{clientId:t,redirectUrl:n})}}async authorize(r){var i,v;const t=(r==null?void 0:r.clientId)||((i=w(this,P))==null?void 0:i.clientId),n=(r==null?void 0:r.redirectUrl)||((v=w(this,P))==null?void 0:v.redirectUrl);if(!t)throw new Error("Missing ClientId");if(!n)throw new Error("Missing RedirectUrl");const u=Y(w(this,O).api,{client_id:t,redirect_uri:n,address:r==null?void 0:r.address,signature:r==null?void 0:r.signature,chainId:r==null?void 0:r.chainId});window.location.replace(u)}async connect(r){var B,p,y;const t=(r==null?void 0:r.clientId)||((B=w(this,P))==null?void 0:B.clientId);if((r==null?void 0:r.clientSecret)||((p=w(this,P))==null?void 0:p.clientSecret)){if(!Z)throw new Error("Only use client credentials on server side");return await w(this,N).call(this,w(this,P)),!!this.bearerProfile}const u=(r==null?void 0:r.redirectUrl)||((y=w(this,P))==null?void 0:y.redirectUrl);if(!t)throw new Error("Missing ClientId");if(Z)throw new Error("This only works on client side");const i=new URLSearchParams(window.location.search).get("code")||void 0,v=sessionStorage.getItem(V)||void 0;return i?await w(this,F).call(this,t,u,i):v&&await w(this,W).call(this,t,v),!!this.bearerProfile}async getBearerToken(r){let t;if(ee(r))t={...r,grant_type:"authorization_code"};else if(Me(r))t={...r,grant_type:"refresh_token"};else if(Le(r))t={...r,grant_type:"client_credentials"};else throw new Error("Authentication method could not be detected.");return await I(this,E,R).call(this,"post","auth/token",t,!0).then(n=>{var u;this.bearerProfile=n,this.isAuthorized=!!n,A(this,q,`Bearer ${n==null?void 0:n.access_token}`),window.sessionStorage.setItem(V,((u=this.bearerProfile)==null?void 0:u.refresh_token)||"")}).catch(n=>{throw sessionStorage.removeItem(U),sessionStorage.removeItem(V),new Error(n==null?void 0:n.message)}),ee(r)&&He(),this.bearerProfile}getAuthContext(){return I(this,E,R).call(this,"get","auth/context")}getProfile(r){return I(this,E,R).call(this,"get",`profiles/${r}`)}getBalances(r){return r?I(this,E,R).call(this,"get",`profiles/${r}/balances`):I(this,E,R).call(this,"get","balances")}getOrders(r){const t=D(r);return I(this,E,R).call(this,"get",`orders?${t}`)}getOrder(r){return I(this,E,R).call(this,"get",`orders/${r}`)}getTokens(){return I(this,E,R).call(this,"get","tokens")}linkAddress(r,t){return I(this,E,R).call(this,"post",`profiles/${r}/addresses`,JSON.stringify(t))}placeOrder(r,t){const n={...r,kind:"redeem",currency:"eur"};return t?I(this,E,R).call(this,"post",`profiles/${t}/orders`,JSON.stringify(n)):I(this,E,R).call(this,"post","orders",JSON.stringify(n))}uploadSupportingDocument(r){const t=D(r);return I(this,E,R).call(this,"post","files/supporting-document",t,!0)}async connectOrderSocket(){var r;(r=this.bearerProfile)!=null&&r.access_token&&w(this,$).size>0&&A(this,H,this.subscribeToOrderNotifications())}async disconnect(){var r;sessionStorage.removeItem(U),w(this,$).clear(),(r=w(this,H))==null||r.close()}subscribeOrders(r,t){w(this,$).set(r,t)}unsubscribeOrders(r){var t;w(this,$).delete(r),w(this,$).size===0&&((t=w(this,H))==null||t.close(),A(this,H,void 0))}}O=new WeakMap,q=new WeakMap,H=new WeakMap,$=new WeakMap,P=new WeakMap,E=new WeakSet,R=async function(r,t,n,u){return je(`${w(this,O).api}/${t}`,r,u?D(n):n,{Authorization:w(this,q)||"","Content-Type":`application/${u?"x-www-form-urlencoded":"json"}`})},F=new WeakMap,N=new WeakMap,W=new WeakMap;exports.AccountState=ie;exports.Currency=re;exports.KYCOutcome=se;exports.KYCState=oe;exports.MoneriumClient=qe;exports.OrderKind=ce;exports.OrderState=ue;exports.PaymentStandard=ae;exports.Permission=ne;exports.ProfileType=te;exports.constants=ke;exports.placeOrderMessage=_e;exports.rfc3339=de;
|