@monerium/sdk 2.14.0 → 3.0.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/README.md +46 -82
- package/dist/index.d.ts +415 -181
- package/dist/index.js +25 -21
- package/dist/index.mjs +4 -4
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -5,27 +5,27 @@
|
|
|
5
5
|
|
|
6
6
|
<a href="https://monerium.dev/">
|
|
7
7
|
<picture>
|
|
8
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/Developer_portal-2c6ca7">
|
|
9
|
-
<img src="https://img.shields.io/badge/Developer_portal-2c6ca7" alt="Static Badge">
|
|
8
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/Developer_portal-2c6ca7"></source>
|
|
9
|
+
<img src="https://img.shields.io/badge/Developer_portal-2c6ca7" alt="Static Badge"></img>
|
|
10
10
|
</picture>
|
|
11
11
|
</a>
|
|
12
12
|
<a href="https://monerium.dev/api-docs">
|
|
13
13
|
<picture>
|
|
14
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/API_documentation-2c6ca7">
|
|
15
|
-
<img src="https://img.shields.io/badge/API_documentation-2c6ca7" alt="Static Badge">
|
|
14
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/API_documentation-2c6ca7"></source>
|
|
15
|
+
<img src="https://img.shields.io/badge/API_documentation-2c6ca7" alt="Static Badge"></img>
|
|
16
16
|
</picture>
|
|
17
17
|
</a>
|
|
18
|
-
|
|
18
|
+
<br></br>
|
|
19
19
|
<a href="https://www.npmjs.com/package/@monerium/sdk">
|
|
20
20
|
<picture>
|
|
21
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40monerium%2Fsdk?colorA=2c6ca7&colorB=21262d">
|
|
22
|
-
<img src="https://img.shields.io/npm/v/%40monerium%2Fsdk?colorA=f6f8fa&colorB=f6f8fa" alt="Version">
|
|
21
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40monerium%2Fsdk?colorA=2c6ca7&colorB=21262d"></source>
|
|
22
|
+
<img src="https://img.shields.io/npm/v/%40monerium%2Fsdk?colorA=f6f8fa&colorB=f6f8fa" alt="Version"></img>
|
|
23
23
|
</picture>
|
|
24
24
|
</a>
|
|
25
|
-
<a href="https://github.com/monerium/js-monorepo/issues>
|
|
25
|
+
<a href="https://github.com/monerium/js-monorepo/issues">
|
|
26
26
|
<picture>
|
|
27
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/issues/monerium/js-monorepo?colorA=2c6ca7&colorB=21262d">
|
|
28
|
-
<img src="https://img.shields.io/github/issues/monerium/js-monorepo?colorA=2c6ca7&colorB=21262d" alt="Version">
|
|
27
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/issues/monerium/js-monorepo?colorA=2c6ca7&colorB=21262d"></source>
|
|
28
|
+
<img src="https://img.shields.io/github/issues/monerium/js-monorepo?colorA=2c6ca7&colorB=21262d" alt="Version"></img>
|
|
29
29
|
</picture>
|
|
30
30
|
</a>
|
|
31
31
|
|
|
@@ -38,8 +38,8 @@ With a single signature from your wallet, your EURe is burned and sent as Euros
|
|
|
38
38
|
|
|
39
39
|
## Documentation
|
|
40
40
|
|
|
41
|
-
- [Documentation](
|
|
42
|
-
- [Documentation - MoneriumClient](
|
|
41
|
+
- [Documentation](../../apps/developer/docs/packages/SDK/index.md)
|
|
42
|
+
- [Documentation - MoneriumClient](../../apps/developer/docs/packages/SDK/classes/MoneriumClient.md)
|
|
43
43
|
|
|
44
44
|
## Table of Contents
|
|
45
45
|
|
|
@@ -102,22 +102,16 @@ const monerium = new MoneriumClient({
|
|
|
102
102
|
|
|
103
103
|
await monerium.getAccess();
|
|
104
104
|
|
|
105
|
-
// Retrieve
|
|
106
|
-
await monerium.
|
|
105
|
+
// Retrieve profiles the client has access to.
|
|
106
|
+
await monerium.getProfiles();
|
|
107
107
|
|
|
108
108
|
// Access tokens are now available for use.
|
|
109
109
|
const { access_token, refresh_token } = monerium.bearerProfile as BearerProfile;
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
Interfaces:
|
|
113
|
-
|
|
114
|
-
- [MoneriumClient](./docs/generated/classes/MoneriumClient.md)
|
|
115
|
-
- [BearerProfile](./docs/generated/interfaces/BearerProfile.md)
|
|
116
|
-
|
|
117
112
|
API documentation:
|
|
118
113
|
|
|
119
114
|
- [/auth/token](https://monerium.dev/api-docs#operation/auth-token)
|
|
120
|
-
- [/auth/context](https://monerium.dev/api-docs#operation/auth-context)
|
|
121
115
|
|
|
122
116
|
#### Initialize and authenticate using Authorization Code Flow with PKCE
|
|
123
117
|
|
|
@@ -129,7 +123,7 @@ First, you have to navigate the user to the Monerium authentication flow. This c
|
|
|
129
123
|
import { MoneriumClient } from '@monerium/sdk';
|
|
130
124
|
|
|
131
125
|
export function App() {
|
|
132
|
-
const [
|
|
126
|
+
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
|
133
127
|
const [monerium, setMonerium] = useState<MoneriumClient>();
|
|
134
128
|
const [isAuthorized, setIsAuthorized] = useState<boolean>(false);
|
|
135
129
|
|
|
@@ -137,7 +131,7 @@ export function App() {
|
|
|
137
131
|
const sdk = new MoneriumClient({
|
|
138
132
|
environment: 'sandbox',
|
|
139
133
|
clientId: 'f99e629b-6dca-11ee-8aa6-5273f65ed05b',
|
|
140
|
-
|
|
134
|
+
redirectUri: 'http://localhost:4200',
|
|
141
135
|
});
|
|
142
136
|
setMonerium(sdk);
|
|
143
137
|
}, []);
|
|
@@ -162,7 +156,8 @@ export function App() {
|
|
|
162
156
|
const fetchData = async () => {
|
|
163
157
|
if (monerium && isAuthorized) {
|
|
164
158
|
try {
|
|
165
|
-
|
|
159
|
+
const { profiles } = await monerium.getProfiles();
|
|
160
|
+
setProfiles(profiles);
|
|
166
161
|
} catch (err) {
|
|
167
162
|
console.error('Error fetching data:', err);
|
|
168
163
|
}
|
|
@@ -175,49 +170,36 @@ export function App() {
|
|
|
175
170
|
<div>
|
|
176
171
|
{!isAuthorized && <button onClick={() => monerium?.authorize()}>Connect</button>}
|
|
177
172
|
|
|
178
|
-
<p>{
|
|
173
|
+
<p>{profiles[0]?.name}</p>
|
|
179
174
|
</div>
|
|
180
175
|
);
|
|
181
176
|
}
|
|
182
177
|
```
|
|
183
178
|
|
|
184
|
-
Interfaces:
|
|
185
|
-
|
|
186
|
-
- [AuthCodeRequest](./docs/generated/interfaces/AuthCodeRequest.md)
|
|
187
|
-
- [BearerProfile](./docs/generated/interfaces/BearerProfile.md)
|
|
188
|
-
|
|
189
179
|
API documentation:
|
|
190
180
|
|
|
191
181
|
- [/auth](https://monerium.dev/api-docs#operation/auth)
|
|
192
182
|
- [/auth/token](https://monerium.dev/api-docs#operation/auth-token)
|
|
193
|
-
- [/auth/context](https://monerium.dev/api-docs#operation/auth-context)
|
|
194
183
|
|
|
195
184
|
#### Get account information
|
|
196
185
|
|
|
197
186
|
```ts
|
|
198
|
-
// Get all profiles
|
|
199
|
-
const
|
|
187
|
+
// Get all profiles
|
|
188
|
+
const { profiles }: Profile[] = await monerium.getProfiles();
|
|
200
189
|
|
|
201
190
|
// Fetching all accounts for a specific profile
|
|
202
191
|
const { id: profileId, accounts }: Profile = await monerium.getProfile(
|
|
203
|
-
|
|
192
|
+
profiles[0].id
|
|
204
193
|
);
|
|
205
194
|
|
|
206
195
|
// Fetching all balances for a specific profile
|
|
207
|
-
const balances: Balances = await monerium.getBalances(
|
|
196
|
+
const balances: Balances = await monerium.getBalances();
|
|
208
197
|
```
|
|
209
198
|
|
|
210
|
-
Interfaces:
|
|
211
|
-
|
|
212
|
-
- [AuthContext](./docs/generated/interfaces/AuthContext.md)
|
|
213
|
-
- [Profile](./docs/generated/interfaces/Profile.md)
|
|
214
|
-
- [Balances](./docs/generated/interfaces/Balances.md)
|
|
215
|
-
|
|
216
199
|
API documentation:
|
|
217
200
|
|
|
218
|
-
- [/auth/context](https://monerium.dev/api-docs#operation/auth-context)
|
|
219
201
|
- [/profile](https://monerium.dev/api-docs#operation/profile)
|
|
220
|
-
- [/profile
|
|
202
|
+
- [/profile/{profileId{/balances](https://monerium.dev/api-docs#operation/profile-balances)
|
|
221
203
|
|
|
222
204
|
#### Get token information
|
|
223
205
|
|
|
@@ -227,10 +209,6 @@ Get the contract addresses of EURe tokens.
|
|
|
227
209
|
const tokens: Token[] = await monerium.getTokens();
|
|
228
210
|
```
|
|
229
211
|
|
|
230
|
-
Interfaces:
|
|
231
|
-
|
|
232
|
-
- [Token](./docs/generated/interfaces/Token.md)
|
|
233
|
-
|
|
234
212
|
API documentation:
|
|
235
213
|
|
|
236
214
|
- [/tokens](https://monerium.dev/api-docs#operation/tokens)
|
|
@@ -255,24 +233,18 @@ const signature = await walletClient.signMessage({
|
|
|
255
233
|
})
|
|
256
234
|
|
|
257
235
|
// Link a new address to Monerium and create accounts for ethereum and gnosis.
|
|
258
|
-
await monerium.linkAddress(
|
|
236
|
+
await monerium.linkAddress({
|
|
237
|
+
profile: 'your-profile-id',
|
|
259
238
|
address: '0xUserAddress72413Fa92980B889A1eCE84dD', // user wallet address
|
|
260
239
|
message: LINK_MESSAGE
|
|
261
240
|
signature,
|
|
262
|
-
|
|
263
|
-
{"currency":"eur","chain":"ethereum"},
|
|
264
|
-
{"currency":"eur","chain":"gnosis"}
|
|
265
|
-
],
|
|
241
|
+
chain: 'ethereum',
|
|
266
242
|
} as LinkAddress);
|
|
267
243
|
```
|
|
268
244
|
|
|
269
|
-
Interfaces:
|
|
270
|
-
|
|
271
|
-
- [LinkAddress](./docs/generated/interfaces/LinkAddress.md)
|
|
272
|
-
|
|
273
245
|
API documentation:
|
|
274
246
|
|
|
275
|
-
- [/profile
|
|
247
|
+
- [/profile/{profileId{/addresses](https://monerium.dev/api-docs#operation/profile-addresses)
|
|
276
248
|
|
|
277
249
|
#### Get and place orders
|
|
278
250
|
|
|
@@ -325,11 +297,6 @@ const order = await monerium.placeOrder({
|
|
|
325
297
|
});
|
|
326
298
|
```
|
|
327
299
|
|
|
328
|
-
Interfaces:
|
|
329
|
-
|
|
330
|
-
- [Order](./docs/generated/interfaces/Order.md)
|
|
331
|
-
- [PaymentStandard](./docs/generated/enumerations/PaymentStandard.md)
|
|
332
|
-
|
|
333
300
|
API documentation:
|
|
334
301
|
|
|
335
302
|
- [GET /orders](https://monerium.dev/api-docs#operation/orders)
|
|
@@ -345,10 +312,6 @@ const supportingDocumentId: SupportingDoc =
|
|
|
345
312
|
await uploadSupportingDocument(document);
|
|
346
313
|
```
|
|
347
314
|
|
|
348
|
-
Interfaces:
|
|
349
|
-
|
|
350
|
-
- [SupportingDoc](./docs/generated/interfaces/SupportingDoc.md)
|
|
351
|
-
|
|
352
315
|
API documentation:
|
|
353
316
|
|
|
354
317
|
- [/files](https://monerium.dev/api-docs#operation/supporting-document)
|
|
@@ -358,28 +321,29 @@ API documentation:
|
|
|
358
321
|
```ts
|
|
359
322
|
import { OrderState } from '@monerium/sdk';
|
|
360
323
|
const [orderState, setOrderState] = useState<OrderState>();
|
|
361
|
-
// Subscribe to order events
|
|
362
|
-
monerium.subscribeOrders(OrderState.pending, (notification) => {
|
|
363
|
-
setOrderState(notification.meta.state);
|
|
364
|
-
});
|
|
365
324
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
});
|
|
325
|
+
// Subscribe to all order events
|
|
326
|
+
monerium.subscribeOrderNotifications();
|
|
369
327
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
328
|
+
// Subscribe to specific order events
|
|
329
|
+
monerium.subscribeOrderNotifications({
|
|
330
|
+
filter: {
|
|
331
|
+
state: OrderState.pending,
|
|
332
|
+
profile: 'my-profile-id',
|
|
333
|
+
},
|
|
334
|
+
// optional callback functions
|
|
335
|
+
onMessage: (order) => console.log(order)
|
|
336
|
+
onError: (error) => console.error(error)
|
|
375
337
|
});
|
|
376
338
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}, 5000);
|
|
339
|
+
// Unsubscribe from specific order events
|
|
340
|
+
monerium.unsubscribeOrderNotifications({
|
|
341
|
+
state: OrderState.pending,
|
|
342
|
+
profile: 'my-profile-id'
|
|
382
343
|
});
|
|
344
|
+
// Unsubscribe from all order events
|
|
345
|
+
monerium.unsubscribeOrderNotifications();
|
|
346
|
+
|
|
383
347
|
```
|
|
384
348
|
|
|
385
349
|
## API Reference
|
package/dist/index.d.ts
CHANGED
|
@@ -10,15 +10,10 @@ type Config = {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
type ENV = 'sandbox' | 'production';
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
type Networks = EthereumTestnet | GnosisTestnet | PolygonTestnet | 'mainnet';
|
|
18
|
-
type NetworkSemiStrict<C extends Chain> = C extends 'ethereum' ? EthereumTestnet | 'mainnet' : C extends 'gnosis' ? GnosisTestnet | 'mainnet' : C extends 'polygon' ? PolygonTestnet | 'mainnet' : never;
|
|
19
|
-
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;
|
|
20
|
-
type Network<C extends Chain = Chain, E extends ENV = ENV> = C extends Chain ? E extends ENV ? NetworkStrict<C, E> & NetworkSemiStrict<C> : never : never;
|
|
21
|
-
type ChainId = number | 1 | 11155111 | 100 | 137 | 10200 | 80002;
|
|
13
|
+
type Chain = 'ethereum' | 'gnosis' | 'polygon' | 'arbitrum' | 'noble';
|
|
14
|
+
type EvmChainId = number | 1 | 11155111 | 100 | 137 | 10200 | 80002 | 42161 | 421614;
|
|
15
|
+
type ChainId = EvmChainId | CosmosChainId;
|
|
16
|
+
type CosmosChainId = 'noble-1' | 'grand-1' | 'florin-1';
|
|
22
17
|
declare enum Currency {
|
|
23
18
|
eur = "eur",
|
|
24
19
|
usd = "usd",
|
|
@@ -27,39 +22,37 @@ declare enum Currency {
|
|
|
27
22
|
}
|
|
28
23
|
type TokenSymbol = 'EURe' | 'GBPe' | 'USDe' | 'ISKe';
|
|
29
24
|
type Ticker = 'EUR' | 'GBP' | 'USD' | 'ISK';
|
|
30
|
-
type
|
|
31
|
-
type
|
|
25
|
+
type CurrencyCode = 'eur' | 'gbp' | 'usd' | 'isk';
|
|
26
|
+
type AuthArgs = Omit<AuthCodePayload, 'grant_type'> | Omit<RefreshTokenPayload, 'grant_type'> | Omit<ClientCredentialsPayload, 'grant_type'>;
|
|
27
|
+
type OpenArgs = Omit<AuthCodePayload, 'grant_type' | 'code' | 'code_verifier'> | Omit<RefreshTokenPayload, 'grant_type'> | Omit<ClientCredentialsPayload, 'grant_type'> | PKCERequestArgs;
|
|
32
28
|
/** One of the options for the {@link AuthArgs}.
|
|
33
29
|
*
|
|
34
30
|
* [Auth endpoint in API documentation:](https://monerium.dev/api-docs#operation/auth).
|
|
35
31
|
* */
|
|
36
|
-
interface
|
|
32
|
+
interface AuthCodePayload {
|
|
37
33
|
grant_type: 'authorization_code';
|
|
38
34
|
client_id: string;
|
|
39
35
|
code: string;
|
|
40
36
|
code_verifier: string;
|
|
41
37
|
redirect_uri: string;
|
|
42
|
-
scope?: string;
|
|
43
38
|
}
|
|
44
39
|
/** One of the options for the {@link AuthArgs}.
|
|
45
40
|
*
|
|
46
41
|
* [Auth endpoint in API documentation:](https://monerium.dev/api-docs#operation/auth).
|
|
47
42
|
* */
|
|
48
|
-
interface
|
|
43
|
+
interface RefreshTokenPayload {
|
|
49
44
|
grant_type: 'refresh_token';
|
|
50
45
|
client_id: string;
|
|
51
46
|
refresh_token: string;
|
|
52
|
-
scope?: string;
|
|
53
47
|
}
|
|
54
48
|
/** One of the options for the {@link AuthArgs}.
|
|
55
49
|
*
|
|
56
50
|
* [Auth endpoint in API documentation:](https://monerium.dev/api-docs#operation/auth).
|
|
57
51
|
* */
|
|
58
|
-
interface
|
|
52
|
+
interface ClientCredentialsPayload {
|
|
59
53
|
grant_type: 'client_credentials';
|
|
60
54
|
client_id: string;
|
|
61
55
|
client_secret: string;
|
|
62
|
-
scope?: string;
|
|
63
56
|
}
|
|
64
57
|
interface BearerProfile {
|
|
65
58
|
access_token: string;
|
|
@@ -92,11 +85,12 @@ type PKCERequest = {
|
|
|
92
85
|
address?: string;
|
|
93
86
|
/** the signature of the wallet to automatically link */
|
|
94
87
|
signature?: string;
|
|
95
|
-
/** @deprecated - Use 'chainId' or 'chain' */
|
|
96
|
-
network?: Network;
|
|
97
|
-
chain?: Chain;
|
|
98
88
|
/** The network of the wallet to automatically link */
|
|
99
|
-
|
|
89
|
+
chain?: Chain | ChainId;
|
|
90
|
+
/** You can skip the connect wallet and request IBAN steps in the Authorization Flow and use the Link Address and Request IBAN API endpoints after you have gotten the authorization */
|
|
91
|
+
skip_create_account?: boolean;
|
|
92
|
+
/** You can skip the KYC onboarding steps in the Authorization Flow and use the the details, additional data, and verifications API endpoints after you have gotten the authorization. */
|
|
93
|
+
skip_kyc?: boolean;
|
|
100
94
|
};
|
|
101
95
|
declare enum Method {
|
|
102
96
|
password = "password",
|
|
@@ -112,24 +106,17 @@ declare enum Permission {
|
|
|
112
106
|
read = "read",
|
|
113
107
|
write = "write"
|
|
114
108
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
auth: {
|
|
127
|
-
method: Method;
|
|
128
|
-
subject: string;
|
|
129
|
-
verified: boolean;
|
|
130
|
-
};
|
|
131
|
-
defaultProfile: string;
|
|
132
|
-
profiles: AuthProfile[];
|
|
109
|
+
declare enum ProfileState {
|
|
110
|
+
/** The profile has been created but no details have been submitted.*/
|
|
111
|
+
created = "created",
|
|
112
|
+
/** The details have been submitted and are being processed. */
|
|
113
|
+
pending = "pending",
|
|
114
|
+
/** The profile is active and all Monerium services are supported.*/
|
|
115
|
+
approved = "approved",
|
|
116
|
+
/**The applicant details did not meet the compliance requirements of Monerium. Details can be fixed and re-submitted for processing.*/
|
|
117
|
+
rejected = "rejected",
|
|
118
|
+
/**Monerium is unable to offer the applicant services because of compliance reasons. Details cannot be re-submitted.*/
|
|
119
|
+
blocked = "blocked"
|
|
133
120
|
}
|
|
134
121
|
declare enum KYCState {
|
|
135
122
|
absent = "absent",
|
|
@@ -156,29 +143,102 @@ declare enum PaymentStandard {
|
|
|
156
143
|
scan = "scan",
|
|
157
144
|
chain = "chain"
|
|
158
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* The type of ID document. Passports, National ID cards, and driving licenses are supported.
|
|
148
|
+
* The ID document must verify the person's name, birthday, and nationality
|
|
149
|
+
*/
|
|
150
|
+
declare enum IdDocumentKind {
|
|
151
|
+
passport = "passport",
|
|
152
|
+
nationalIdentityCard = "nationalIdentityCard",
|
|
153
|
+
drivingLicense = "drivingLicense"
|
|
154
|
+
}
|
|
159
155
|
interface Identifier {
|
|
160
156
|
standard: PaymentStandard;
|
|
161
157
|
bic?: string;
|
|
162
158
|
}
|
|
163
|
-
interface
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
state?: AccountState;
|
|
159
|
+
interface ProfilePermissions {
|
|
160
|
+
id: string;
|
|
161
|
+
kind: ProfileType;
|
|
162
|
+
name: string;
|
|
163
|
+
perms: Permission[];
|
|
164
|
+
}
|
|
165
|
+
interface ProfilesResponse {
|
|
166
|
+
profiles: ProfilePermissions[];
|
|
172
167
|
}
|
|
173
168
|
interface Profile {
|
|
174
169
|
id: string;
|
|
175
170
|
name: string;
|
|
176
|
-
email: string;
|
|
177
|
-
kyc: KYC;
|
|
178
171
|
kind: ProfileType;
|
|
179
|
-
|
|
172
|
+
state: ProfileState;
|
|
173
|
+
kyc: KYC;
|
|
174
|
+
}
|
|
175
|
+
interface ProfilesQueryParams {
|
|
176
|
+
/** profile state to filter by */
|
|
177
|
+
state?: ProfileState;
|
|
178
|
+
/** profile kind to filter by */
|
|
179
|
+
kind?: ProfileType;
|
|
180
180
|
}
|
|
181
|
-
interface
|
|
181
|
+
interface PersonalProfileDetails {
|
|
182
|
+
idDocument: {
|
|
183
|
+
number: string;
|
|
184
|
+
kind: IdDocumentKind;
|
|
185
|
+
};
|
|
186
|
+
firstName: string;
|
|
187
|
+
lastName: string;
|
|
188
|
+
address: string;
|
|
189
|
+
postalCode: string;
|
|
190
|
+
city: string;
|
|
191
|
+
country: string;
|
|
192
|
+
countryState?: string;
|
|
193
|
+
nationality: string;
|
|
194
|
+
birthday: string;
|
|
195
|
+
}
|
|
196
|
+
interface PersonalProfileDetailsRequest {
|
|
197
|
+
personal: PersonalProfileDetails;
|
|
198
|
+
}
|
|
199
|
+
type Representative = PersonalProfileDetails;
|
|
200
|
+
type Beneficiary = Omit<PersonalProfileDetails, 'idDocument'> & {
|
|
201
|
+
/** Ownership in % that is between 25% and 100%. */
|
|
202
|
+
ownershipPercentage: number;
|
|
203
|
+
};
|
|
204
|
+
type Director = Omit<PersonalProfileDetails, 'idDocument'>;
|
|
205
|
+
interface CorporateProfileDetails {
|
|
206
|
+
name: string;
|
|
207
|
+
registrationNumber: string;
|
|
208
|
+
address: string;
|
|
209
|
+
postalCode: string;
|
|
210
|
+
city: string;
|
|
211
|
+
country: string;
|
|
212
|
+
countryState: string;
|
|
213
|
+
/** List of individuals representing the company and authorized to act on it's behalf. */
|
|
214
|
+
representatives: Representative[];
|
|
215
|
+
/** List of beneficial owner that owns 25% or more in a corporation. */
|
|
216
|
+
finalBeneficiaries: Beneficiary[];
|
|
217
|
+
/** List of Individual who has powers to legally bind the company (power of procuration). */
|
|
218
|
+
directors: Director[];
|
|
219
|
+
}
|
|
220
|
+
interface CorporateProfileDetailsRequest {
|
|
221
|
+
corporate: CorporateProfileDetails;
|
|
222
|
+
}
|
|
223
|
+
type SubmitProfileDetailsPayload = PersonalProfileDetailsRequest | CorporateProfileDetailsRequest;
|
|
224
|
+
interface AddressesQueryParams {
|
|
225
|
+
/** Filter the list by profile */
|
|
226
|
+
profile?: string;
|
|
227
|
+
/** Filter the list by chain */
|
|
228
|
+
chain?: Chain | ChainId;
|
|
229
|
+
}
|
|
230
|
+
interface Address {
|
|
231
|
+
/** The id of the profile the address belongs to. */
|
|
232
|
+
profile: string;
|
|
233
|
+
/** The address */
|
|
234
|
+
address: string;
|
|
235
|
+
/** Which chains is the address linked on. */
|
|
236
|
+
chains: Chain[];
|
|
237
|
+
}
|
|
238
|
+
interface AddressesResponse {
|
|
239
|
+
addresses: Address[];
|
|
240
|
+
}
|
|
241
|
+
interface CurrencyBalance {
|
|
182
242
|
currency: Currency;
|
|
183
243
|
amount: string;
|
|
184
244
|
}
|
|
@@ -186,8 +246,7 @@ interface Balances {
|
|
|
186
246
|
id: string;
|
|
187
247
|
address: string;
|
|
188
248
|
chain: Chain;
|
|
189
|
-
|
|
190
|
-
balances: Balance[];
|
|
249
|
+
balances: CurrencyBalance[];
|
|
191
250
|
}
|
|
192
251
|
declare enum OrderKind {
|
|
193
252
|
redeem = "redeem",
|
|
@@ -204,19 +263,18 @@ interface Fee {
|
|
|
204
263
|
currency: Currency;
|
|
205
264
|
amount: string;
|
|
206
265
|
}
|
|
207
|
-
interface
|
|
266
|
+
interface IBANIdentifier extends Identifier {
|
|
208
267
|
standard: PaymentStandard.iban;
|
|
209
268
|
iban: string;
|
|
210
269
|
}
|
|
211
|
-
interface
|
|
270
|
+
interface CrossChainIdentifier extends Identifier {
|
|
212
271
|
standard: PaymentStandard.chain;
|
|
272
|
+
/** The receivers address */
|
|
213
273
|
address: string;
|
|
214
|
-
|
|
215
|
-
chain
|
|
216
|
-
/** @deprecated - Use 'chainId' or 'chain' */
|
|
217
|
-
network?: Network;
|
|
274
|
+
/** The receivers network */
|
|
275
|
+
chain: Chain | ChainId;
|
|
218
276
|
}
|
|
219
|
-
interface
|
|
277
|
+
interface SCANIdentifier extends Identifier {
|
|
220
278
|
standard: PaymentStandard.scan;
|
|
221
279
|
sortCode: string;
|
|
222
280
|
accountNumber: string;
|
|
@@ -231,7 +289,7 @@ interface Corporation {
|
|
|
231
289
|
country: string;
|
|
232
290
|
}
|
|
233
291
|
interface Counterpart {
|
|
234
|
-
identifier:
|
|
292
|
+
identifier: IBANIdentifier | SCANIdentifier | CrossChainIdentifier;
|
|
235
293
|
details: Individual | Corporation;
|
|
236
294
|
}
|
|
237
295
|
interface OrderMetadata {
|
|
@@ -258,6 +316,7 @@ interface Order {
|
|
|
258
316
|
accountId: string;
|
|
259
317
|
address: string;
|
|
260
318
|
kind: OrderKind;
|
|
319
|
+
chain: Chain;
|
|
261
320
|
amount: string;
|
|
262
321
|
currency: Currency;
|
|
263
322
|
totalFee: string;
|
|
@@ -268,6 +327,9 @@ interface Order {
|
|
|
268
327
|
supportingDocumentId: string;
|
|
269
328
|
meta: OrderMetadata;
|
|
270
329
|
}
|
|
330
|
+
interface OrdersResponse {
|
|
331
|
+
orders: Order[];
|
|
332
|
+
}
|
|
271
333
|
/**
|
|
272
334
|
* Information about the EURe token on different networks.
|
|
273
335
|
*/
|
|
@@ -276,7 +338,6 @@ interface Token {
|
|
|
276
338
|
ticker: Ticker;
|
|
277
339
|
symbol: TokenSymbol;
|
|
278
340
|
chain: Chain;
|
|
279
|
-
network: Network;
|
|
280
341
|
/** The address of the EURe contract on this network */
|
|
281
342
|
address: string;
|
|
282
343
|
/** How many decimals this token supports */
|
|
@@ -294,10 +355,8 @@ interface NewOrderCommon {
|
|
|
294
355
|
}
|
|
295
356
|
interface NewOrderByAddress extends NewOrderCommon {
|
|
296
357
|
address: string;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
network?: Network;
|
|
300
|
-
chainId?: ChainId;
|
|
358
|
+
/** The senders network */
|
|
359
|
+
chain: Chain | ChainId;
|
|
301
360
|
}
|
|
302
361
|
interface NewOrderByAccountId extends NewOrderCommon {
|
|
303
362
|
accountId: string;
|
|
@@ -315,62 +374,87 @@ interface SupportingDoc {
|
|
|
315
374
|
hash: string;
|
|
316
375
|
meta: SupportingDocMetadata;
|
|
317
376
|
}
|
|
318
|
-
interface CurrencyAccounts {
|
|
319
|
-
/** @deprecated - Use 'chainId' or 'chain' */
|
|
320
|
-
network?: Network;
|
|
321
|
-
chain?: Chain;
|
|
322
|
-
chainId?: ChainId;
|
|
323
|
-
currency: Currency;
|
|
324
|
-
}
|
|
325
377
|
interface LinkAddress {
|
|
378
|
+
/** Profile ID that owns the address. */
|
|
379
|
+
profile?: string;
|
|
380
|
+
/** The public key of the blockchain account. */
|
|
326
381
|
address: string;
|
|
327
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Fixed message to be signed with the private key corresponding to the given address.
|
|
384
|
+
*
|
|
385
|
+
* `I hereby declare that I am the address owner.`
|
|
386
|
+
*/
|
|
387
|
+
message?: string;
|
|
388
|
+
/**
|
|
389
|
+
* The signature hash of signing the `message` with the private key associated with the given address.
|
|
390
|
+
* For signing on-chain with ERC1271 contracts, use `0x`, visit the documentation for further details.
|
|
391
|
+
* https://monerium.dev/api-docs-v2#tag/addresses/operation/link-address
|
|
392
|
+
*/
|
|
328
393
|
signature: string;
|
|
329
|
-
|
|
330
|
-
/** @deprecated - Use 'chainId' or 'chain' */
|
|
331
|
-
network?: Network;
|
|
332
|
-
chain?: Chain;
|
|
333
|
-
chainId?: ChainId;
|
|
394
|
+
chain: Chain | ChainId;
|
|
334
395
|
}
|
|
335
396
|
interface LinkedAddress {
|
|
336
|
-
id: string;
|
|
337
397
|
profile: string;
|
|
338
398
|
address: string;
|
|
339
|
-
|
|
399
|
+
state: string;
|
|
340
400
|
meta: {
|
|
341
401
|
linkedBy: string;
|
|
342
402
|
linkedAt: string;
|
|
343
403
|
};
|
|
344
404
|
}
|
|
345
|
-
interface
|
|
346
|
-
|
|
405
|
+
interface RequestIbanPayload {
|
|
406
|
+
/** the address to request the IBAN. */
|
|
407
|
+
address: string;
|
|
408
|
+
/** the chain to request the IBAN. */
|
|
409
|
+
chain: Chain | ChainId;
|
|
410
|
+
/** payment email notifications sent to customers, `true` by default. */
|
|
411
|
+
emailNotifications: boolean;
|
|
412
|
+
}
|
|
413
|
+
interface IbansQueryParams {
|
|
414
|
+
profile?: string;
|
|
415
|
+
chain?: Chain | ChainId;
|
|
416
|
+
}
|
|
417
|
+
interface IBAN {
|
|
418
|
+
iban: string;
|
|
419
|
+
bic: string;
|
|
347
420
|
profile: string;
|
|
348
|
-
accountId: string;
|
|
349
421
|
address: string;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
422
|
+
chain: Chain;
|
|
423
|
+
}
|
|
424
|
+
interface IBANsResponse {
|
|
425
|
+
ibans: IBAN[];
|
|
426
|
+
}
|
|
427
|
+
interface MoveIbanPayload {
|
|
428
|
+
/** the address to move iban to */
|
|
429
|
+
address: string;
|
|
430
|
+
/** the chain to move iban to */
|
|
431
|
+
chain: Chain | ChainId;
|
|
432
|
+
}
|
|
433
|
+
interface OrderNotificationQueryParams {
|
|
434
|
+
state?: OrderState;
|
|
435
|
+
profile?: string;
|
|
360
436
|
}
|
|
361
|
-
type MoneriumEvent = OrderState;
|
|
362
|
-
type MoneriumEventListener = (notification: OrderNotification) => void;
|
|
363
437
|
type ClassOptions = {
|
|
364
438
|
environment?: ENV;
|
|
439
|
+
debug?: boolean;
|
|
365
440
|
} & BearerTokenCredentials;
|
|
366
441
|
interface AuthFlowOptions {
|
|
442
|
+
/** the auth flow client ID for your application */
|
|
367
443
|
clientId?: string;
|
|
368
|
-
|
|
444
|
+
/** the redirect URI defined by your application */
|
|
445
|
+
redirectUri?: string;
|
|
446
|
+
/** the address your customer should link in auth flow */
|
|
369
447
|
address?: string;
|
|
448
|
+
/** the signature of the address */
|
|
370
449
|
signature?: string;
|
|
371
|
-
|
|
450
|
+
/** the chain of the address */
|
|
451
|
+
chain?: Chain | ChainId;
|
|
452
|
+
/** the state oauth parameter */
|
|
372
453
|
state?: string;
|
|
373
|
-
|
|
454
|
+
/** skip account creation in auth flow */
|
|
455
|
+
skipCreateAccount?: boolean;
|
|
456
|
+
/** skip KYC in auth flow */
|
|
457
|
+
skipKyc?: boolean;
|
|
374
458
|
}
|
|
375
459
|
interface ClientCredentials {
|
|
376
460
|
clientId: string;
|
|
@@ -378,22 +462,42 @@ interface ClientCredentials {
|
|
|
378
462
|
}
|
|
379
463
|
interface AuthorizationCodeCredentials {
|
|
380
464
|
clientId: string;
|
|
381
|
-
|
|
465
|
+
redirectUri: string;
|
|
382
466
|
}
|
|
383
467
|
type BearerTokenCredentials = ClientCredentials | AuthorizationCodeCredentials;
|
|
468
|
+
type ResponseStatus = {
|
|
469
|
+
status: number;
|
|
470
|
+
statusText: string;
|
|
471
|
+
};
|
|
384
472
|
|
|
473
|
+
/**
|
|
474
|
+
* In the [Monerium UI](https://monerium.app/), create an application to get the `clientId` and register your `redirectUri`.
|
|
475
|
+
* ```ts
|
|
476
|
+
* import { MoneriumClient } from '@monerium/sdk';
|
|
477
|
+
*
|
|
478
|
+
* const monerium = new MoneriumClient() // defaults to `sandbox`
|
|
479
|
+
*
|
|
480
|
+
* // or
|
|
481
|
+
* new MoneriumClient('production')
|
|
482
|
+
*
|
|
483
|
+
* // or
|
|
484
|
+
* new MoneriumClient({
|
|
485
|
+
* environment: 'sandbox',
|
|
486
|
+
* clientId: 'your-client-id',
|
|
487
|
+
* redirectUri: 'http://your-redirect-url.com/monerium'
|
|
488
|
+
* });
|
|
489
|
+
*
|
|
490
|
+
*```
|
|
491
|
+
*/
|
|
385
492
|
declare class MoneriumClient {
|
|
386
493
|
#private;
|
|
387
|
-
/**
|
|
388
|
-
* The PKCE code verifier
|
|
389
|
-
* @deprecated, use localStorage, will be removed in v3
|
|
390
|
-
* @hidden
|
|
391
|
-
* */
|
|
392
|
-
codeVerifier?: string;
|
|
393
494
|
/**
|
|
394
495
|
* The bearer profile will be available after authentication, it includes the `access_token` and `refresh_token`
|
|
395
496
|
* */
|
|
396
497
|
bearerProfile?: BearerProfile;
|
|
498
|
+
/**
|
|
499
|
+
* The client is authorized if the bearer profile is available
|
|
500
|
+
*/
|
|
397
501
|
isAuthorized: boolean;
|
|
398
502
|
/**
|
|
399
503
|
* The state parameter is used to maintain state between the request and the callback.
|
|
@@ -401,126 +505,185 @@ declare class MoneriumClient {
|
|
|
401
505
|
state: string | undefined;
|
|
402
506
|
/**
|
|
403
507
|
* @defaultValue `sandbox`
|
|
404
|
-
* @example
|
|
405
|
-
* new MoneriumClient() // defaults to `sandbox`
|
|
406
|
-
*
|
|
407
|
-
* new MoneriumClient('production')
|
|
408
|
-
*
|
|
409
|
-
* new MoneriumClient({
|
|
410
|
-
* environment: 'sandbox',
|
|
411
|
-
* clientId: 'your-client-id',
|
|
412
|
-
* redirectUrl: 'your-redirect-url'
|
|
413
|
-
* })
|
|
414
508
|
* */
|
|
415
509
|
constructor(envOrOptions?: ENV | ClassOptions);
|
|
416
510
|
/**
|
|
417
511
|
* Construct the url to the authorization code flow and redirects,
|
|
418
512
|
* Code Verifier needed for the code challenge is stored in local storage
|
|
419
|
-
* For automatic wallet link, add the following properties: `address`, `signature` & `
|
|
513
|
+
* For automatic wallet link, add the following properties: `address`, `signature` & `chain`
|
|
514
|
+
*
|
|
515
|
+
* @group Authentication
|
|
516
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/auth/operation/auth | API Documentation}
|
|
517
|
+
* @param {AuthFlowOptions} [params] - the auth flow params
|
|
420
518
|
* @returns string
|
|
421
|
-
*
|
|
422
|
-
* @category Auth
|
|
519
|
+
*
|
|
423
520
|
*/
|
|
424
|
-
authorize(
|
|
521
|
+
authorize(params?: AuthFlowOptions): Promise<void>;
|
|
425
522
|
/**
|
|
426
|
-
*
|
|
523
|
+
* Will use the authorization code flow code to get access token
|
|
524
|
+
*
|
|
525
|
+
* @group Authentication
|
|
526
|
+
*
|
|
427
527
|
* @param {AuthorizationCodeCredentials | ClientCredentials} client - the client credentials
|
|
528
|
+
*
|
|
428
529
|
* @returns boolean to indicate if access has been granted
|
|
429
|
-
*
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* import { MoneriumClient } from '@monerium/sdk';
|
|
534
|
+
* // Initialize the client with credentials
|
|
535
|
+
* const monerium = new MoneriumClient({
|
|
536
|
+
* environment: 'sandbox',
|
|
537
|
+
* clientId: 'your_client_credentials_uuid', // replace with your client ID
|
|
538
|
+
* clientSecret: 'your_client_secret', // replace with your client secret
|
|
539
|
+
* });
|
|
540
|
+
*
|
|
541
|
+
* await monerium.getAccess();
|
|
542
|
+
* ```
|
|
430
543
|
*/
|
|
431
|
-
getAccess(
|
|
544
|
+
getAccess(refreshToken?: string): Promise<boolean>;
|
|
432
545
|
/**
|
|
433
|
-
*
|
|
434
|
-
* @
|
|
546
|
+
* @group Profiles
|
|
547
|
+
* @param {string} profile - the id of the profile to fetch.
|
|
548
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/profiles/operation/profile | API Documentation}
|
|
435
549
|
*/
|
|
436
|
-
|
|
550
|
+
getProfile(profile: string): Promise<Profile>;
|
|
437
551
|
/**
|
|
438
|
-
*
|
|
439
|
-
* @
|
|
440
|
-
* @category Profiles
|
|
552
|
+
* @group Profiles
|
|
553
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/profiles/operation/profiles | API Documentation}
|
|
441
554
|
*/
|
|
442
|
-
|
|
555
|
+
getProfiles(params?: ProfilesQueryParams): Promise<ProfilesResponse>;
|
|
443
556
|
/**
|
|
444
|
-
*
|
|
445
|
-
*
|
|
557
|
+
*
|
|
558
|
+
* Get details for a single address by using the address public key after the address has been successfully linked to Monerium.
|
|
559
|
+
*
|
|
560
|
+
* @group Addresses
|
|
561
|
+
* @param {string} address - The public key of the blockchain account.
|
|
562
|
+
*
|
|
563
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/addresses/operation/address | API Documentation}
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```ts
|
|
567
|
+
* monerium.getAddress('0x1234567890abcdef1234567890abcdef12345678')
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
getAddress(address: string): Promise<Address>;
|
|
571
|
+
/**
|
|
572
|
+
* @group Addresses
|
|
573
|
+
* @param {AddressesQueryParams} [params] - No required parameters.
|
|
574
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/addresses/operation/addresses | API Documentation}
|
|
575
|
+
*/
|
|
576
|
+
getAddresses(params?: AddressesQueryParams): Promise<AddressesResponse>;
|
|
577
|
+
/**
|
|
578
|
+
* @group Addresses
|
|
579
|
+
* @see {@link https://monerium.dev/api-docs/v2#tag/addresses/operation/balances| API Documentation}
|
|
580
|
+
*/
|
|
581
|
+
getBalances(address: string, chain: Chain | ChainId, currencies?: Currency | Currency[]): Promise<Balances>;
|
|
582
|
+
/**
|
|
583
|
+
* Fetch details about a single IBAN
|
|
584
|
+
*
|
|
585
|
+
* @group IBANs
|
|
586
|
+
* @param {string} iban - the IBAN to fetch.
|
|
587
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/ibans/operation/iban | API Documentation}
|
|
446
588
|
*/
|
|
447
|
-
|
|
589
|
+
getIban(iban: string): Promise<IBAN>;
|
|
448
590
|
/**
|
|
449
|
-
*
|
|
450
|
-
* @
|
|
451
|
-
* @
|
|
591
|
+
* Fetch all IBANs for the profile
|
|
592
|
+
* @group IBANs
|
|
593
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/ibans/operation/ibans | API Documentation}
|
|
452
594
|
*/
|
|
453
|
-
|
|
595
|
+
getIbans(queryParameters?: IbansQueryParams): Promise<IBANsResponse>;
|
|
454
596
|
/**
|
|
455
|
-
*
|
|
456
|
-
* @
|
|
597
|
+
* @group Orders
|
|
598
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders | API Documentation}
|
|
457
599
|
*/
|
|
458
|
-
getOrders(filter?: OrderFilter): Promise<
|
|
600
|
+
getOrders(filter?: OrderFilter): Promise<OrdersResponse>;
|
|
459
601
|
/**
|
|
460
|
-
*
|
|
461
|
-
* @
|
|
602
|
+
* @group Orders
|
|
603
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/order | API Documentation}
|
|
462
604
|
*/
|
|
463
605
|
getOrder(orderId: string): Promise<Order>;
|
|
464
606
|
/**
|
|
465
|
-
*
|
|
466
|
-
* @
|
|
607
|
+
* @group Tokens
|
|
608
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/tokens | API Documentation}
|
|
467
609
|
*/
|
|
468
610
|
getTokens(): Promise<Token[]>;
|
|
469
611
|
/**
|
|
470
|
-
*
|
|
471
|
-
* @
|
|
612
|
+
* Add a new address to the profile
|
|
613
|
+
* @group Addresses
|
|
614
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/addresses/operation/link-address | API Documentation}
|
|
472
615
|
*/
|
|
473
|
-
linkAddress(
|
|
616
|
+
linkAddress(payload: LinkAddress): Promise<LinkedAddress>;
|
|
474
617
|
/**
|
|
475
|
-
* {@link https://monerium.dev/api-docs#operation/post-orders}
|
|
476
|
-
*
|
|
618
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/post-orders | API Documentation}
|
|
619
|
+
*
|
|
620
|
+
* @group Orders
|
|
477
621
|
*/
|
|
478
622
|
placeOrder(order: NewOrder): Promise<Order>;
|
|
479
623
|
/**
|
|
480
|
-
*
|
|
481
|
-
* @
|
|
624
|
+
* @group IBANs
|
|
625
|
+
* @param {string} iban - the IBAN to move.
|
|
626
|
+
* @param {MoveIbanPayload} payload - the payload to move the IBAN.
|
|
627
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/ibans/operation/move-iban | API Documentation}
|
|
628
|
+
*/
|
|
629
|
+
moveIban(iban: string, { address, chain }: MoveIbanPayload): Promise<ResponseStatus>;
|
|
630
|
+
/**
|
|
631
|
+
* @group IBANs
|
|
632
|
+
* @param {RequestIbanPayload} payload
|
|
633
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/ibans/operation/request-iban | API Documentation}
|
|
634
|
+
*/
|
|
635
|
+
requestIban({ address, chain, emailNotifications, }: RequestIbanPayload): Promise<ResponseStatus>;
|
|
636
|
+
/**
|
|
637
|
+
* @group Profiles
|
|
638
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/profiles/operation/profile-details | API Documentation}
|
|
639
|
+
*/
|
|
640
|
+
submitProfileDetails(profile: string, body: SubmitProfileDetailsPayload): Promise<ResponseStatus>;
|
|
641
|
+
/**
|
|
642
|
+
* @group Orders
|
|
643
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/supporting-document | API Documentation}
|
|
482
644
|
*/
|
|
483
645
|
uploadSupportingDocument(document: File): Promise<SupportingDoc>;
|
|
484
646
|
/**
|
|
485
647
|
* Connects to the order notifications socket
|
|
486
|
-
*
|
|
648
|
+
*
|
|
649
|
+
* @group Orders
|
|
650
|
+
* @param {OrderNotificationQueryParams} [params]
|
|
651
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/orders-notifications | API Document - Websocket}
|
|
652
|
+
|
|
487
653
|
*/
|
|
488
|
-
|
|
654
|
+
subscribeOrderNotifications({ filter, onMessage, onError, }?: {
|
|
655
|
+
/** specify which type of orders to listen to */
|
|
656
|
+
filter?: OrderNotificationQueryParams;
|
|
657
|
+
onMessage?: (data: Order) => void;
|
|
658
|
+
onError?: (err: Event) => void;
|
|
659
|
+
}): WebSocket | undefined;
|
|
489
660
|
/**
|
|
490
|
-
*
|
|
491
|
-
*
|
|
661
|
+
* Closes the order notifications sockets
|
|
662
|
+
*
|
|
663
|
+
* @group Orders
|
|
664
|
+
* @param {OrderNotificationQueryParams} [params] - specify which socket to close or close all if not provided
|
|
665
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/orders-notifications | API Document - Websocket}
|
|
492
666
|
*/
|
|
493
|
-
|
|
667
|
+
unsubscribeOrderNotifications(params?: OrderNotificationQueryParams): void;
|
|
494
668
|
/**
|
|
495
|
-
* Cleanups the
|
|
496
|
-
*
|
|
669
|
+
* Cleanups the localstorage and websocket connections
|
|
670
|
+
*
|
|
671
|
+
* @group Authentication
|
|
497
672
|
*/
|
|
498
673
|
disconnect(): Promise<void>;
|
|
499
674
|
/**
|
|
500
675
|
* Revokes access
|
|
501
|
-
*
|
|
676
|
+
*
|
|
677
|
+
* @group Authentication
|
|
502
678
|
*/
|
|
503
679
|
revokeAccess(): Promise<void>;
|
|
504
680
|
/**
|
|
505
|
-
*
|
|
506
|
-
* We are setting a subscription map because we need the user to have a token to start the WebSocket connection
|
|
507
|
-
* {@link https://monerium.dev/api-docs#operation/profile-orders-notifications}
|
|
508
|
-
* @param event The event to subscribe to
|
|
509
|
-
* @param handler The handler to be called when the event is triggered
|
|
510
|
-
* @category Orders
|
|
511
|
-
*/
|
|
512
|
-
subscribeOrders(event: MoneriumEvent, handler: MoneriumEventListener): void;
|
|
513
|
-
/**
|
|
514
|
-
* Unsubscribe from MoneriumEvent and close the socket if there are no more subscriptions
|
|
515
|
-
* @param event The event to unsubscribe from
|
|
516
|
-
* @category Orders
|
|
517
|
-
*/
|
|
518
|
-
unsubscribeOrders(event: MoneriumEvent): void;
|
|
519
|
-
/**
|
|
681
|
+
*
|
|
520
682
|
* @hidden
|
|
521
683
|
*/
|
|
522
684
|
getEnvironment: () => Environment;
|
|
523
685
|
/**
|
|
686
|
+
*
|
|
524
687
|
* @hidden
|
|
525
688
|
*/
|
|
526
689
|
getAuthFlowURI: (args: PKCERequestArgs) => string;
|
|
@@ -536,25 +699,96 @@ declare const _default: {
|
|
|
536
699
|
*/
|
|
537
700
|
STORAGE_CODE_VERIFIER: string;
|
|
538
701
|
/**
|
|
539
|
-
* The key used to store the
|
|
702
|
+
* The key used to store the access token in the local storage.
|
|
703
|
+
*/
|
|
704
|
+
STORAGE_ACCESS_TOKEN: string;
|
|
705
|
+
/**
|
|
706
|
+
* The unix timestamp used to calculate the expiration time of the access token.
|
|
540
707
|
*/
|
|
541
|
-
|
|
708
|
+
STORAGE_ACCESS_EXPIRY: string;
|
|
542
709
|
};
|
|
543
710
|
|
|
711
|
+
/**
|
|
712
|
+
*
|
|
713
|
+
* @param d Date to be formatted
|
|
714
|
+
* @returns RFC3339 date format.
|
|
715
|
+
* @example 2023-04-30T12:00:00+01:00
|
|
716
|
+
* @example 2023-04-30T02:08:15Z
|
|
717
|
+
*/
|
|
544
718
|
declare const rfc3339: (d: Date) => string;
|
|
719
|
+
/**
|
|
720
|
+
* This will resolve the chainId number to the corresponding chain name.
|
|
721
|
+
* @param chain The chainId of the network
|
|
722
|
+
* @returns chain name, 'ethereum', 'polygon', 'gnosis', etc.
|
|
723
|
+
*/
|
|
724
|
+
declare const parseChain: (chain: Chain | ChainId | number | string) => Chain;
|
|
545
725
|
/**
|
|
546
726
|
* The message to be signed when placing an order.
|
|
547
727
|
* @param amount The amount to be sent
|
|
548
728
|
* @param currency The currency to be sent
|
|
549
729
|
* @param receiver The receiver of the funds
|
|
550
730
|
* @param chain The chainId of the network if it's a cross-chain transaction
|
|
551
|
-
* @returns
|
|
731
|
+
* @returns
|
|
732
|
+
* cross-chain:
|
|
733
|
+
* ```ts
|
|
734
|
+
* Send {CURRENCY} {AMOUNT} to {RECEIVER} on {CHAIN} at {DATE}`
|
|
735
|
+
* ```
|
|
736
|
+
*
|
|
737
|
+
* off-ramp:
|
|
738
|
+
* ```ts
|
|
739
|
+
* Send {CURRENCY} {AMOUNT} to {RECEIVER} at {DATE}
|
|
740
|
+
* ```
|
|
741
|
+
* @example `Send EUR 1 to 0x1234123412341234123412341234123412341234 on ethereum at 2023-04-30T12:00:00+01:00`
|
|
742
|
+
*
|
|
743
|
+
* @example `Send EUR 1 to IS1234123412341234 at 2023-04-30T12:00:00+01:00`
|
|
552
744
|
*/
|
|
553
745
|
declare const placeOrderMessage: (amount: string | number, currency: Currency, receiver: string, chain?: ChainId | Chain) => string;
|
|
554
746
|
/**
|
|
555
|
-
*
|
|
556
|
-
* @
|
|
747
|
+
* This will resolve the chainId number to the corresponding chain name.
|
|
748
|
+
* @param chainId The chainId of the network
|
|
749
|
+
* @returns chain name
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* getChain(1) // 'ethereum'
|
|
753
|
+
* getChain(11155111) // 'ethereum'
|
|
754
|
+
*
|
|
755
|
+
* getChain(100) // 'gnosis'
|
|
756
|
+
* getChain(10200) // 'gnosis'
|
|
757
|
+
*
|
|
758
|
+
* getChain(137) // 'polygon'
|
|
759
|
+
* getChain(80002) // 'polygon'
|
|
760
|
+
* ```
|
|
557
761
|
*/
|
|
558
762
|
declare const getChain: (chainId: number) => Chain;
|
|
763
|
+
declare const shortenIban: (iban?: string) => string | undefined;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* @packageDocumentation
|
|
767
|
+
* A library to interact with Monerium API.
|
|
768
|
+
*
|
|
769
|
+
*
|
|
770
|
+
* ## Installation
|
|
771
|
+
*
|
|
772
|
+
* ```bash
|
|
773
|
+
* pnpm add @monerium/sdk
|
|
774
|
+
* ```
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```tsx
|
|
778
|
+
* import { MoneriumClient } from '@monerium/sdk';
|
|
779
|
+
*
|
|
780
|
+
* const monerium = new MoneriumClient({
|
|
781
|
+
* clientId: '...',
|
|
782
|
+
* redirectUri: '...',
|
|
783
|
+
* environment: 'sandbox',
|
|
784
|
+
* })
|
|
785
|
+
*
|
|
786
|
+
* // Will redirect the user to Monerium's authentication code flow.
|
|
787
|
+
* await monerium.getAccess();
|
|
788
|
+
*
|
|
789
|
+
* // Retrieve profiles the client has access to.
|
|
790
|
+
* await monerium.getProfiles();
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
559
793
|
|
|
560
|
-
export {
|
|
794
|
+
export { AccountState, type Address, type AddressesQueryParams, type AddressesResponse, type AuthArgs, type AuthCodePayload, type AuthFlowOptions, type AuthorizationCodeCredentials, type Balances, type BearerProfile, type BearerTokenCredentials, type Beneficiary, type Chain, type ChainId, type ClassOptions, type ClientCredentials, type ClientCredentialsPayload, type Config, type CorporateProfileDetails, type CorporateProfileDetailsRequest, type Corporation, type CosmosChainId, type Counterpart, type CrossChainIdentifier, Currency, type CurrencyBalance, type CurrencyCode, type Director, type ENV, type Environment, type EvmChainId, type Fee, type IBAN, type IBANIdentifier, type IBANsResponse, type IbansQueryParams, IdDocumentKind, type Identifier, type Individual, type KYC, KYCOutcome, KYCState, type LinkAddress, type LinkedAddress, Method, MoneriumClient, type MoveIbanPayload, type NewOrder, type NewOrderByAccountId, type NewOrderByAddress, type NewOrderCommon, type OpenArgs, type Order, type OrderFilter, OrderKind, type OrderMetadata, type OrderNotificationQueryParams, OrderState, type OrdersResponse, type PKCERequest, type PKCERequestArgs, PaymentStandard, Permission, type PersonalProfileDetails, type PersonalProfileDetailsRequest, type Profile, type ProfilePermissions, ProfileState, ProfileType, type ProfilesQueryParams, type ProfilesResponse, type RefreshTokenPayload, type Representative, type RequestIbanPayload, type ResponseStatus, type SCANIdentifier, type SubmitProfileDetailsPayload, type SupportingDoc, type SupportingDocMetadata, type Ticker, type Token, type TokenSymbol, _default as constants, MoneriumClient as default, getChain, parseChain, placeOrderMessage, rfc3339, shortenIban };
|
package/dist/index.js
CHANGED
|
@@ -2,29 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var W = require('crypto-js/enc-base64url.js');
|
|
6
|
+
var H = require('crypto-js/sha256.js');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var W__default = /*#__PURE__*/_interopDefault(W);
|
|
11
|
+
var H__default = /*#__PURE__*/_interopDefault(H);
|
|
12
12
|
|
|
13
|
-
var h={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"}}};var c={LINK_MESSAGE:"I hereby declare that I am the address owner.",STORAGE_CODE_VERIFIER:"monerium.sdk.code_verifier",STORAGE_REFRESH_TOKEN:"monerium.sdk.refresh_token"};var I=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(I||{}),b=(i=>(i.password="password",i.resource="resource",i.jwt="jwt",i.apiKey="apiKey",i))(b||{}),P=(t=>(t.corporate="corporate",t.personal="personal",t))(P||{}),O=(t=>(t.read="read",t.write="write",t))(O||{}),T=(i=>(i.absent="absent",i.submitted="submitted",i.pending="pending",i.confirmed="confirmed",i))(T||{}),N=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(N||{}),v=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(v||{}),q=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(q||{}),B=(t=>(t.redeem="redeem",t.issue="issue",t))(B||{}),$=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))($||{});var C=n=>{if(n.toString()==="Invalid Date")throw n;let e=r=>r<10?"0"+r:r,t=r=>{if(r===0)return "Z";let i=r>0?"-":"+";return r=Math.abs(r),i+e(Math.floor(r/60))+":"+e(r%60)};return n.getFullYear()+"-"+e(n.getMonth()+1)+"-"+e(n.getDate())+"T"+e(n.getHours())+":"+e(n.getMinutes())+":"+e(n.getSeconds())+t(n.getTimezoneOffset())},U=(n,e,t,r)=>{let i=`${e?.toUpperCase()||"EUR"}`,s=r;return typeof r=="number"&&(s=g(r)),s?`Send ${i} ${n} to ${t} on ${s} at ${C(new Date)}`:`Send ${i} ${n} to ${t} at ${C(new Date)}`},u=n=>n&&Object.entries(n)?.length>0?Object.entries(n).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&"):"",g=n=>{switch(n){case 1:case 11155111:return "ethereum";case 100:case 10200:return "gnosis";case 137:case 80002:return "polygon";default:throw new Error(`Chain not supported: ${n}`)}};var p=n=>{if(n?.chainId){let{chainId:e,...t}=n;return {...t,chain:g(e)}}return n};var F=(n,e)=>{let{client_id:t,redirect_uri:r,scope:i,state:s,chainId:o,address:d,signature:k,chain:E}=n,S=d?{address:d,...k!==void 0?{signature:k}:{},...o!==void 0||E!==void 0?{chain:o?g(o):E}:{}}:{};return u({client_id:t,redirect_uri:r,...i!==void 0?{scope:i}:{},...s!==void 0?{state:s}:{},code_challenge:e,code_challenge_method:"S256",response_type:"code",...S})},D=()=>{let n="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=e.length,r=0;for(;r<128;)n+=e.charAt(Math.floor(Math.random()*t)),r+=1;return n},L=n=>M__default.default.stringify(z__default.default(n)),x=(n,e)=>{let t=D(),r=L(t);return localStorage.setItem(c.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${F(e,r)}`},w=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},y=n=>n.code!=null,R=n=>n.refresh_token!=null,_=n=>n.client_secret!=null;var A=async(n,e,t,r)=>{let i=await fetch(`${n}`,{method:e,headers:r,body:t}),s,o=await i.text();try{s=JSON.parse(o);}catch{throw o}if(!i.ok)throw s;return s};var {STORAGE_CODE_VERIFIER:l,STORAGE_REFRESH_TOKEN:m}=c,a=typeof window>"u",f=class{#t;#i;codeVerifier;bearerProfile;#s;#n=new Map;isAuthorized=!!this.bearerProfile;#r;state;constructor(e){if(!e){this.#t=h.environments.sandbox;return}if(typeof e=="string")this.#t=h.environments[e];else if(this.#t=h.environments[e.environment||"sandbox"],a){let{clientId:t,clientSecret:r}=e;this.#r={clientId:t,clientSecret:r};}else {let{clientId:t,redirectUrl:r}=e;this.#r={clientId:t,redirectUrl:r};}}async authorize(e){let t=e?.clientId||this.#r?.clientId,r=e?.redirectUrl||this.#r?.redirectUrl;if(!t)throw new Error("Missing ClientId");if(!r)throw new Error("Missing RedirectUrl");let i=x(this.#t.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chainId:e?.chainId,state:e?.state,scope:e?.scope});window.location.assign(i);}async getAccess(e){let t=e?.clientId||this.#r?.clientId;if(e?.clientSecret||this.#r?.clientSecret){if(!a)throw new Error("Only use client credentials on server side");return await this.#d(this.#r),!!this.bearerProfile}let i=e?.redirectUrl||this.#r?.redirectUrl;if(!t)throw new Error("Missing ClientId");if(a)throw new Error("This only works client side");let s=new URLSearchParams(window.location.search).get("code")||void 0,o=new URLSearchParams(window.location.search).get("state")||void 0,d=localStorage.getItem(m)||void 0;return d?await this.#c(t,d):s&&await this.#a(t,i,s,o),!!this.bearerProfile}async#o(e){let t;if(y(e))t={...e,grant_type:"authorization_code"};else if(R(e))t={...e,grant_type:"refresh_token"};else if(_(e))t={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#e("post","auth/token",t,!0).then(r=>{this.bearerProfile=r,this.isAuthorized=!!r,this.#i=`Bearer ${r?.access_token}`,a||window.localStorage.setItem(m,this.bearerProfile?.refresh_token||"");}).catch(r=>{throw a||(localStorage.removeItem(l),localStorage.removeItem(m),w()),new Error(r?.message)}),y(e)&&w(),this.bearerProfile}getAuthContext(){return this.#e("get","auth/context")}getProfile(e){return this.#e("get",`profiles/${e}`)}getProfiles(){return this.#e("get","profiles")}getBalances(e){return e?this.#e("get",`profiles/${e}/balances`):this.#e("get","balances")}getOrders(e){let t=u(e),r=t?`orders?${t}`:"orders";return this.#e("get",r)}getOrder(e){return this.#e("get",`orders/${e}`)}getTokens(){return this.#e("get","tokens")}linkAddress(e,t){return t=p(t),t.accounts=t.accounts.map(r=>p(r)),this.#e("post",`profiles/${e}/addresses`,JSON.stringify(t))}placeOrder(e){let t={kind:"redeem",...p(e),counterpart:{...e.counterpart,identifier:p(e.counterpart.identifier)}};return this.#e("post","orders",JSON.stringify(t))}uploadSupportingDocument(e){let t=new FormData;return t.append("file",e),A(`${this.#t.api}/files`,"post",t,{Authorization:this.#i||""})}async#e(e,t,r,i){return A(`${this.#t.api}/${t}`,e,i?u(r):r,{Authorization:this.#i||"","Content-Type":`application/${i?"x-www-form-urlencoded":"json"}`})}#a=async(e,t,r,i)=>{let s=localStorage.getItem(l)||"";if(!s)throw new Error("Code verifier not found");return this.codeVerifier=s,this.state=i,localStorage.removeItem(l),await this.#o({code:r,redirect_uri:t,client_id:e,code_verifier:s})};#d=async({clientId:e,clientSecret:t})=>await this.#o({client_id:e,client_secret:t});#c=async(e,t)=>await this.#o({refresh_token:t,client_id:e});async connectOrderSocket(){this.bearerProfile?.access_token&&this.#n.size>0&&(this.#s=this.subscribeToOrderNotifications());}subscribeToOrderNotifications=()=>{let e=`${this.#t.wss}/profiles/${this.bearerProfile?.profile}/orders?access_token=${this.bearerProfile?.access_token}`,t=new WebSocket(e);return t.addEventListener("open",()=>{console.info(`Socket connected: ${e}`);}),t.addEventListener("error",r=>{throw console.error(r),new Error(`Socket error: ${e}`)}),t.addEventListener("message",r=>{let i=JSON.parse(r.data);this.#n.get(i.meta.state)?.(i);}),t.addEventListener("close",()=>{console.info(`Socket connection closed: ${e}`);}),t};async disconnect(){a||localStorage.removeItem(l),this.#n.clear(),this.#s?.close(),this.#i=void 0,this.bearerProfile=void 0;}async revokeAccess(){a||localStorage.removeItem(m),this.disconnect();}subscribeOrders(e,t){this.#n.set(e,t);}unsubscribeOrders(e){this.#n.delete(e),this.#n.size===0&&(this.#s?.close(),this.#s=void 0);}getEnvironment=()=>this.#t;getAuthFlowURI=e=>{let t=x(this.#t.api,e);return this.codeVerifier=localStorage.getItem(l),t}};var he=f;
|
|
13
|
+
var P={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"}}};var f={LINK_MESSAGE:"I hereby declare that I am the address owner.",STORAGE_CODE_VERIFIER:"monerium.sdk.code_verifier",STORAGE_ACCESS_TOKEN:"monerium.sdk.access_token",STORAGE_ACCESS_EXPIRY:"monerium.sdk.access_expiry"};var E=(s=>(s.eur="eur",s.usd="usd",s.gbp="gbp",s.isk="isk",s))(E||{}),B=(s=>(s.password="password",s.resource="resource",s.jwt="jwt",s.apiKey="apiKey",s))(B||{}),D=(t=>(t.corporate="corporate",t.personal="personal",t))(D||{}),U=(t=>(t.read="read",t.write="write",t))(U||{}),z=(i=>(i.created="created",i.pending="pending",i.approved="approved",i.rejected="rejected",i.blocked="blocked",i))(z||{}),q=(s=>(s.absent="absent",s.submitted="submitted",s.pending="pending",s.confirmed="confirmed",s))(q||{}),j=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(j||{}),M=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(M||{}),F=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(F||{}),K=(r=>(r.passport="passport",r.nationalIdentityCard="nationalIdentityCard",r.drivingLicense="drivingLicense",r))(K||{}),L=(t=>(t.redeem="redeem",t.issue="issue",t))(L||{}),Q=(s=>(s.placed="placed",s.pending="pending",s.processed="processed",s.rejected="rejected",s))(Q||{});var x=n=>{if(n.toString()==="Invalid Date")throw n;let e=r=>r<10?"0"+r:r,t=r=>{if(r===0)return "Z";let s=r>0?"-":"+";return r=Math.abs(r),s+e(Math.floor(r/60))+":"+e(r%60)};return n.getFullYear()+"-"+e(n.getMonth()+1)+"-"+e(n.getDate())+"T"+e(n.getHours())+":"+e(n.getMinutes())+":"+e(n.getSeconds())+t(n.getTimezoneOffset())},V=n=>{switch(n){case"noble":case"noble-1":case"florin-1":case"grand-1":return !0;default:return !1}},G=n=>{switch(n){case"ethereum":case"polygon":case"gnosis":case"arbitrum":return !0;default:return !1}},c=n=>{if(typeof n=="number")return w(n);if(V(n))return "noble";if(G(n))return n;try{return w(parseInt(n))}catch{throw new Error(`Chain not supported: ${n}`)}},J=(n,e,t,r)=>{let s=`${e?.toUpperCase()||"EUR"}`;return r?`Send ${s} ${n} to ${t} on ${c(r)} at ${x(new Date)}`:s==="EUR"?`Send ${s} ${n} to ${O(t)} at ${x(new Date)}`:`Send ${s} ${n} to ${t} at ${x(new Date)}`},m=n=>n&&Object.entries(n)?.length>0?Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&"):"",w=n=>{switch(n){case 1:case 11155111:return "ethereum";case 100:case 10200:return "gnosis";case 137:case 80002:return "polygon";case 42161:case 421614:return "arbitrum";default:throw new Error(`Chain not supported: ${n}`)}},O=n=>{if(typeof n!="string"||!n?.length)return n;let e=n.replace(/\s/g,"");return n?.length>11?`${e.substring(0,4)}...${e.substring(e.length-4)}`:n};var C=n=>{if(n?.chain){let{chain:e,...t}=n;return {...t,chain:c(e)}}return n};var X=(n,e)=>{let{client_id:t,redirect_uri:r,scope:s,state:i,address:d,signature:o,chain:l,skip_create_account:a,skip_kyc:h}=n,T=d?{address:d,...o!==void 0?{signature:o}:{},...l!==void 0?{chain:c(l)}:{}}:{};return m({client_id:t,redirect_uri:r,...s!==void 0?{scope:s}:{},...i!==void 0?{state:i}:{},...a!==void 0?{skip_create_account:a}:{},...h!==void 0?{skip_kyc:h}:{},code_challenge:e,code_challenge_method:"S256",response_type:"code",...T})},Z=()=>{let n="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=e.length,r=0;for(;r<128;)n+=e.charAt(Math.floor(Math.random()*t)),r+=1;return n},Y=n=>W__default.default.stringify(H__default.default(n)),I=(n,e)=>{let t=Z(),r=Y(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${X(e,r)}`},k=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},R=n=>n.code!=null,v=n=>n.refresh_token!=null,N=n=>n.client_secret!=null;var _=async(n,e,t,r)=>{let s=await fetch(`${n}`,{method:e,headers:r,body:t}),i,d=await s.text();try{if(i=JSON.parse(d),Object.keys(i).length===0&&i.constructor===Object)switch(s.status){case 201:case 202:return {status:s.status,statusText:s.statusText}}}catch{throw d}if(!s.ok)throw i;return i};var y=n=>{if(!n)return "";let e=Object.entries(n).filter(([t,r])=>r!==""&&r!==void 0&&r!==null).map(([t,r])=>`${encodeURIComponent(t)}=${encodeURIComponent(r)}`).join("&");return e?"?"+e:""};var $=n=>n?e=>{console.log("%c [MONERIUM:DEBUG]:","color:orange;",e);}:()=>{};var S=n=>Object.entries(n).filter(([t,r])=>r!=null).map(([t,r])=>`${t}-${r}`).join("-");var {STORAGE_CODE_VERIFIER:A,STORAGE_ACCESS_TOKEN:p,STORAGE_ACCESS_EXPIRY:g}=f,u=typeof window>"u",b=class{#r;#i;bearerProfile;#n=new Map;isAuthorized=!!this.bearerProfile;#t=()=>{};#s;state;constructor(e){if(!e){this.#r=P.environments.sandbox;return}if(typeof e=="string")this.#r=P.environments[e];else if(this.#t=$(e.debug??!1),this.#r=P.environments[e.environment||"sandbox"],!u&&!e?.clientSecret){let{clientId:t,redirectUri:r}=e;this.#s={clientId:t,redirectUri:r};}else {this.#t("Client credentials detected"),console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");let{clientId:t,clientSecret:r}=e;this.#s={clientId:t,clientSecret:r};}}async authorize(e){let t=e?.clientId||this.#s?.clientId,r=e?.redirectUri||this.#s?.redirectUri;if(!t)throw new Error("Missing ClientId");let s=I(this.#r.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chain:e?.chain,state:e?.state,skip_create_account:e?.skipCreateAccount,skip_kyc:e?.skipKyc});this.#t(`Authorization URL: ${s}`),window.location.assign(s);}async getAccess(e){let t=this.#s?.clientId;if(this.#s?.clientSecret){if(u)return await this.#d(this.#s),!!this?.bearerProfile;console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");}let s=this.#s?.redirectUri;if(!t)throw new Error("Missing ClientId");if(u)throw new Error("This only works client side");let i=new URLSearchParams(window.location.search).get("code")||void 0,d=new URLSearchParams(window.location.search).get("state")||void 0,o=window.localStorage.getItem(p),l=window.localStorage.getItem(g);if(i)return this.#t("Using auth code from auth flow to authorize"),await this.#a(t,s,i,d),this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(e)return this.#t("Using refresh token to authorize"),await this.#c(t,e),this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(o&&l){let a=new Date;if(parseInt(l)<a.getTime())throw window.localStorage.removeItem(p),window.localStorage.removeItem(g),this.isAuthorized=!1,this.bearerProfile=void 0,new Error("Access token has expired");this.#t("Access token should still be valid, checking if it is authorized...");try{return this.#i=`Bearer ${o}`,this.isAuthorized=!0,await this.getTokens(),this.#t("Authorized"),!0}catch{throw this.#t("Access token is invalid."),window.localStorage.removeItem(p),window.localStorage.removeItem(g),this.isAuthorized=!1,this.bearerProfile=void 0,new Error("Access token is invalid.")}}return this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile}async#o(e){let t;if(R(e))t={...e,grant_type:"authorization_code"};else if(v(e))t={...e,grant_type:"refresh_token"};else if(N(e))t={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#e("post","auth/token",t,!0).then(r=>{if(this.bearerProfile=r,this.isAuthorized=!!r,this.#i=`Bearer ${r?.access_token}`,!u){let i=new Date().getTime()+r?.expires_in*1e3;window.localStorage.setItem(p,r?.access_token||""),window.localStorage.setItem(g,i?.toString());}}).catch(r=>{throw u||(localStorage.removeItem(A),localStorage.removeItem(p),localStorage.removeItem(g),k()),new Error(r?.message)}),R(e)&&k(),this.bearerProfile}getProfile(e){return this.#e("get",`profiles/${e}`)}getProfiles(e){return this.#e("get",`profiles${y(e)}`)}getAddress(e){return this.#e("get",`addresses/${e}`)}getAddresses(e){e=C(e);let t=e?m(e):void 0,r=t?`addresses?${t}`:"addresses";return this.#e("get",r)}getBalances(e,t,r){let s=Array.isArray(r)?r.map(i=>`currency=${i}`).join("&"):r?`currency=${r}`:"";return this.#e("get",`balances/${c(t)}/${e}${s?`?${s}`:""}`)}getIban(e){return this.#e("get",`ibans/${encodeURI(e)}`)}getIbans(e){let{profile:t,chain:r}=e||{},s=y({profile:t,chain:r?c(r):""});return this.#e("get",`ibans${s}`)}getOrders(e){return this.#e("get",`orders${y(e)}`)}getOrder(e){return this.#e("get",`orders/${e}`)}getTokens(){return this.#e("get","tokens")}linkAddress(e){return e=C(e),this.#e("post","addresses",JSON.stringify(e))}placeOrder(e){let t={kind:"redeem",...C(e),counterpart:{...e.counterpart,identifier:C(e.counterpart.identifier)}};return this.#e("post","orders",JSON.stringify(t))}moveIban(e,{address:t,chain:r}){return this.#e("patch",`ibans/${e}`,JSON.stringify({address:t,chain:c(r)}))}requestIban({address:e,chain:t,emailNotifications:r=!0}){return this.#e("post","ibans",JSON.stringify({address:e,chain:c(t),emailNotifications:r}))}submitProfileDetails(e,t){return this.#e("put",`profiles/${e}/details`,JSON.stringify(t))}uploadSupportingDocument(e){let t=new FormData;return t.append("file",e),_(`${this.#r.api}/files`,"post",t,{Authorization:this.#i||""})}async#e(e,t,r,s){let i={Authorization:this.#i||"",Accept:"application/vnd.monerium.api-v2+json","Content-Type":`application/${s?"x-www-form-urlencoded":"json"}`};return _(`${this.#r.api}/${t}`,e.toUpperCase(),s?m(r):r,i)}#a=async(e,t,r,s)=>{let i=localStorage.getItem(A)||"";if(!i)throw new Error("Code verifier not found");return this.#t("Use code verifier to authorize"),this.state=s,localStorage.removeItem(A),await this.#o({code:r,redirect_uri:t,client_id:e,code_verifier:i})};#d=async({clientId:e,clientSecret:t})=>await this.#o({client_id:e,client_secret:t});#c=async(e,t)=>await this.#o({refresh_token:t,client_id:e});subscribeOrderNotifications({filter:e,onMessage:t,onError:r}={}){if(!this.bearerProfile?.access_token)return;let{profile:s,state:i}=e||{},d=y({access_token:this.bearerProfile?.access_token,profile:s,state:i}),o,l=S({profile:s,state:i});if(this.#n?.has(l))o=this.#n.get(l);else {let a=`${this.#r.wss}/orders${d}`;o=new WebSocket(a),this.#n?.set(l,o);}return o.onopen=()=>{console.log("Connected to WebSocket server");},o.onmessage=a=>{let h=JSON.parse(a.data);t&&t(h);},o.onclose=()=>{console.log("WebSocket connection closed"),this.#n?.delete(d);},o.onerror=a=>{r&&r(a),console.error("WebSocket error:",a);},o}unsubscribeOrderNotifications(e){if(e){let t=S({profile:e?.profile,state:e?.state}),r=this.#n?.get(t);r&&(r.close(),this.#n?.delete(t));}else this.#n?.forEach(t=>{t?.close();}),this.#n?.clear(),this.#n=void 0;}async disconnect(){u||localStorage.removeItem(A),this.unsubscribeOrderNotifications(),this.#i=void 0,this.bearerProfile=void 0;}async revokeAccess(){u||(localStorage.removeItem(p),localStorage.removeItem(g)),this.disconnect();}getEnvironment=()=>this.#r;getAuthFlowURI=e=>I(this.#r.api,e)};var Ee=b;
|
|
14
14
|
|
|
15
|
-
exports.AccountState =
|
|
16
|
-
exports.Currency =
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
15
|
+
exports.AccountState = M;
|
|
16
|
+
exports.Currency = E;
|
|
17
|
+
exports.IdDocumentKind = K;
|
|
18
|
+
exports.KYCOutcome = j;
|
|
19
|
+
exports.KYCState = q;
|
|
20
|
+
exports.Method = B;
|
|
21
|
+
exports.MoneriumClient = b;
|
|
22
|
+
exports.OrderKind = L;
|
|
23
|
+
exports.OrderState = Q;
|
|
24
|
+
exports.PaymentStandard = F;
|
|
25
|
+
exports.Permission = U;
|
|
26
|
+
exports.ProfileState = z;
|
|
27
|
+
exports.ProfileType = D;
|
|
28
|
+
exports.constants = f;
|
|
29
|
+
exports.default = Ee;
|
|
30
|
+
exports.getChain = w;
|
|
31
|
+
exports.parseChain = c;
|
|
32
|
+
exports.placeOrderMessage = J;
|
|
33
|
+
exports.rfc3339 = x;
|
|
34
|
+
exports.shortenIban = O;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import W from 'crypto-js/enc-base64url.js';
|
|
2
|
+
import H from 'crypto-js/sha256.js';
|
|
3
3
|
|
|
4
|
-
var h={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"}}};var c={LINK_MESSAGE:"I hereby declare that I am the address owner.",STORAGE_CODE_VERIFIER:"monerium.sdk.code_verifier",STORAGE_REFRESH_TOKEN:"monerium.sdk.refresh_token"};var I=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(I||{}),b=(i=>(i.password="password",i.resource="resource",i.jwt="jwt",i.apiKey="apiKey",i))(b||{}),P=(t=>(t.corporate="corporate",t.personal="personal",t))(P||{}),O=(t=>(t.read="read",t.write="write",t))(O||{}),T=(i=>(i.absent="absent",i.submitted="submitted",i.pending="pending",i.confirmed="confirmed",i))(T||{}),N=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(N||{}),v=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(v||{}),q=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(q||{}),B=(t=>(t.redeem="redeem",t.issue="issue",t))(B||{}),$=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))($||{});var C=n=>{if(n.toString()==="Invalid Date")throw n;let e=r=>r<10?"0"+r:r,t=r=>{if(r===0)return "Z";let i=r>0?"-":"+";return r=Math.abs(r),i+e(Math.floor(r/60))+":"+e(r%60)};return n.getFullYear()+"-"+e(n.getMonth()+1)+"-"+e(n.getDate())+"T"+e(n.getHours())+":"+e(n.getMinutes())+":"+e(n.getSeconds())+t(n.getTimezoneOffset())},U=(n,e,t,r)=>{let i=`${e?.toUpperCase()||"EUR"}`,s=r;return typeof r=="number"&&(s=g(r)),s?`Send ${i} ${n} to ${t} on ${s} at ${C(new Date)}`:`Send ${i} ${n} to ${t} at ${C(new Date)}`},u=n=>n&&Object.entries(n)?.length>0?Object.entries(n).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&"):"",g=n=>{switch(n){case 1:case 11155111:return "ethereum";case 100:case 10200:return "gnosis";case 137:case 80002:return "polygon";default:throw new Error(`Chain not supported: ${n}`)}};var p=n=>{if(n?.chainId){let{chainId:e,...t}=n;return {...t,chain:g(e)}}return n};var F=(n,e)=>{let{client_id:t,redirect_uri:r,scope:i,state:s,chainId:o,address:d,signature:k,chain:E}=n,S=d?{address:d,...k!==void 0?{signature:k}:{},...o!==void 0||E!==void 0?{chain:o?g(o):E}:{}}:{};return u({client_id:t,redirect_uri:r,...i!==void 0?{scope:i}:{},...s!==void 0?{state:s}:{},code_challenge:e,code_challenge_method:"S256",response_type:"code",...S})},D=()=>{let n="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=e.length,r=0;for(;r<128;)n+=e.charAt(Math.floor(Math.random()*t)),r+=1;return n},L=n=>M.stringify(z(n)),x=(n,e)=>{let t=D(),r=L(t);return localStorage.setItem(c.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${F(e,r)}`},w=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},y=n=>n.code!=null,R=n=>n.refresh_token!=null,_=n=>n.client_secret!=null;var A=async(n,e,t,r)=>{let i=await fetch(`${n}`,{method:e,headers:r,body:t}),s,o=await i.text();try{s=JSON.parse(o);}catch{throw o}if(!i.ok)throw s;return s};var {STORAGE_CODE_VERIFIER:l,STORAGE_REFRESH_TOKEN:m}=c,a=typeof window>"u",f=class{#t;#i;codeVerifier;bearerProfile;#s;#n=new Map;isAuthorized=!!this.bearerProfile;#r;state;constructor(e){if(!e){this.#t=h.environments.sandbox;return}if(typeof e=="string")this.#t=h.environments[e];else if(this.#t=h.environments[e.environment||"sandbox"],a){let{clientId:t,clientSecret:r}=e;this.#r={clientId:t,clientSecret:r};}else {let{clientId:t,redirectUrl:r}=e;this.#r={clientId:t,redirectUrl:r};}}async authorize(e){let t=e?.clientId||this.#r?.clientId,r=e?.redirectUrl||this.#r?.redirectUrl;if(!t)throw new Error("Missing ClientId");if(!r)throw new Error("Missing RedirectUrl");let i=x(this.#t.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chainId:e?.chainId,state:e?.state,scope:e?.scope});window.location.assign(i);}async getAccess(e){let t=e?.clientId||this.#r?.clientId;if(e?.clientSecret||this.#r?.clientSecret){if(!a)throw new Error("Only use client credentials on server side");return await this.#d(this.#r),!!this.bearerProfile}let i=e?.redirectUrl||this.#r?.redirectUrl;if(!t)throw new Error("Missing ClientId");if(a)throw new Error("This only works client side");let s=new URLSearchParams(window.location.search).get("code")||void 0,o=new URLSearchParams(window.location.search).get("state")||void 0,d=localStorage.getItem(m)||void 0;return d?await this.#c(t,d):s&&await this.#a(t,i,s,o),!!this.bearerProfile}async#o(e){let t;if(y(e))t={...e,grant_type:"authorization_code"};else if(R(e))t={...e,grant_type:"refresh_token"};else if(_(e))t={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#e("post","auth/token",t,!0).then(r=>{this.bearerProfile=r,this.isAuthorized=!!r,this.#i=`Bearer ${r?.access_token}`,a||window.localStorage.setItem(m,this.bearerProfile?.refresh_token||"");}).catch(r=>{throw a||(localStorage.removeItem(l),localStorage.removeItem(m),w()),new Error(r?.message)}),y(e)&&w(),this.bearerProfile}getAuthContext(){return this.#e("get","auth/context")}getProfile(e){return this.#e("get",`profiles/${e}`)}getProfiles(){return this.#e("get","profiles")}getBalances(e){return e?this.#e("get",`profiles/${e}/balances`):this.#e("get","balances")}getOrders(e){let t=u(e),r=t?`orders?${t}`:"orders";return this.#e("get",r)}getOrder(e){return this.#e("get",`orders/${e}`)}getTokens(){return this.#e("get","tokens")}linkAddress(e,t){return t=p(t),t.accounts=t.accounts.map(r=>p(r)),this.#e("post",`profiles/${e}/addresses`,JSON.stringify(t))}placeOrder(e){let t={kind:"redeem",...p(e),counterpart:{...e.counterpart,identifier:p(e.counterpart.identifier)}};return this.#e("post","orders",JSON.stringify(t))}uploadSupportingDocument(e){let t=new FormData;return t.append("file",e),A(`${this.#t.api}/files`,"post",t,{Authorization:this.#i||""})}async#e(e,t,r,i){return A(`${this.#t.api}/${t}`,e,i?u(r):r,{Authorization:this.#i||"","Content-Type":`application/${i?"x-www-form-urlencoded":"json"}`})}#a=async(e,t,r,i)=>{let s=localStorage.getItem(l)||"";if(!s)throw new Error("Code verifier not found");return this.codeVerifier=s,this.state=i,localStorage.removeItem(l),await this.#o({code:r,redirect_uri:t,client_id:e,code_verifier:s})};#d=async({clientId:e,clientSecret:t})=>await this.#o({client_id:e,client_secret:t});#c=async(e,t)=>await this.#o({refresh_token:t,client_id:e});async connectOrderSocket(){this.bearerProfile?.access_token&&this.#n.size>0&&(this.#s=this.subscribeToOrderNotifications());}subscribeToOrderNotifications=()=>{let e=`${this.#t.wss}/profiles/${this.bearerProfile?.profile}/orders?access_token=${this.bearerProfile?.access_token}`,t=new WebSocket(e);return t.addEventListener("open",()=>{console.info(`Socket connected: ${e}`);}),t.addEventListener("error",r=>{throw console.error(r),new Error(`Socket error: ${e}`)}),t.addEventListener("message",r=>{let i=JSON.parse(r.data);this.#n.get(i.meta.state)?.(i);}),t.addEventListener("close",()=>{console.info(`Socket connection closed: ${e}`);}),t};async disconnect(){a||localStorage.removeItem(l),this.#n.clear(),this.#s?.close(),this.#i=void 0,this.bearerProfile=void 0;}async revokeAccess(){a||localStorage.removeItem(m),this.disconnect();}subscribeOrders(e,t){this.#n.set(e,t);}unsubscribeOrders(e){this.#n.delete(e),this.#n.size===0&&(this.#s?.close(),this.#s=void 0);}getEnvironment=()=>this.#t;getAuthFlowURI=e=>{let t=x(this.#t.api,e);return this.codeVerifier=localStorage.getItem(l),t}};var he=f;
|
|
4
|
+
var P={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"}}};var f={LINK_MESSAGE:"I hereby declare that I am the address owner.",STORAGE_CODE_VERIFIER:"monerium.sdk.code_verifier",STORAGE_ACCESS_TOKEN:"monerium.sdk.access_token",STORAGE_ACCESS_EXPIRY:"monerium.sdk.access_expiry"};var E=(s=>(s.eur="eur",s.usd="usd",s.gbp="gbp",s.isk="isk",s))(E||{}),B=(s=>(s.password="password",s.resource="resource",s.jwt="jwt",s.apiKey="apiKey",s))(B||{}),D=(t=>(t.corporate="corporate",t.personal="personal",t))(D||{}),U=(t=>(t.read="read",t.write="write",t))(U||{}),z=(i=>(i.created="created",i.pending="pending",i.approved="approved",i.rejected="rejected",i.blocked="blocked",i))(z||{}),q=(s=>(s.absent="absent",s.submitted="submitted",s.pending="pending",s.confirmed="confirmed",s))(q||{}),j=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(j||{}),M=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(M||{}),F=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(F||{}),K=(r=>(r.passport="passport",r.nationalIdentityCard="nationalIdentityCard",r.drivingLicense="drivingLicense",r))(K||{}),L=(t=>(t.redeem="redeem",t.issue="issue",t))(L||{}),Q=(s=>(s.placed="placed",s.pending="pending",s.processed="processed",s.rejected="rejected",s))(Q||{});var x=n=>{if(n.toString()==="Invalid Date")throw n;let e=r=>r<10?"0"+r:r,t=r=>{if(r===0)return "Z";let s=r>0?"-":"+";return r=Math.abs(r),s+e(Math.floor(r/60))+":"+e(r%60)};return n.getFullYear()+"-"+e(n.getMonth()+1)+"-"+e(n.getDate())+"T"+e(n.getHours())+":"+e(n.getMinutes())+":"+e(n.getSeconds())+t(n.getTimezoneOffset())},V=n=>{switch(n){case"noble":case"noble-1":case"florin-1":case"grand-1":return !0;default:return !1}},G=n=>{switch(n){case"ethereum":case"polygon":case"gnosis":case"arbitrum":return !0;default:return !1}},c=n=>{if(typeof n=="number")return w(n);if(V(n))return "noble";if(G(n))return n;try{return w(parseInt(n))}catch{throw new Error(`Chain not supported: ${n}`)}},J=(n,e,t,r)=>{let s=`${e?.toUpperCase()||"EUR"}`;return r?`Send ${s} ${n} to ${t} on ${c(r)} at ${x(new Date)}`:s==="EUR"?`Send ${s} ${n} to ${O(t)} at ${x(new Date)}`:`Send ${s} ${n} to ${t} at ${x(new Date)}`},m=n=>n&&Object.entries(n)?.length>0?Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&"):"",w=n=>{switch(n){case 1:case 11155111:return "ethereum";case 100:case 10200:return "gnosis";case 137:case 80002:return "polygon";case 42161:case 421614:return "arbitrum";default:throw new Error(`Chain not supported: ${n}`)}},O=n=>{if(typeof n!="string"||!n?.length)return n;let e=n.replace(/\s/g,"");return n?.length>11?`${e.substring(0,4)}...${e.substring(e.length-4)}`:n};var C=n=>{if(n?.chain){let{chain:e,...t}=n;return {...t,chain:c(e)}}return n};var X=(n,e)=>{let{client_id:t,redirect_uri:r,scope:s,state:i,address:d,signature:o,chain:l,skip_create_account:a,skip_kyc:h}=n,T=d?{address:d,...o!==void 0?{signature:o}:{},...l!==void 0?{chain:c(l)}:{}}:{};return m({client_id:t,redirect_uri:r,...s!==void 0?{scope:s}:{},...i!==void 0?{state:i}:{},...a!==void 0?{skip_create_account:a}:{},...h!==void 0?{skip_kyc:h}:{},code_challenge:e,code_challenge_method:"S256",response_type:"code",...T})},Z=()=>{let n="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=e.length,r=0;for(;r<128;)n+=e.charAt(Math.floor(Math.random()*t)),r+=1;return n},Y=n=>W.stringify(H(n)),I=(n,e)=>{let t=Z(),r=Y(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${X(e,r)}`},k=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},R=n=>n.code!=null,v=n=>n.refresh_token!=null,N=n=>n.client_secret!=null;var _=async(n,e,t,r)=>{let s=await fetch(`${n}`,{method:e,headers:r,body:t}),i,d=await s.text();try{if(i=JSON.parse(d),Object.keys(i).length===0&&i.constructor===Object)switch(s.status){case 201:case 202:return {status:s.status,statusText:s.statusText}}}catch{throw d}if(!s.ok)throw i;return i};var y=n=>{if(!n)return "";let e=Object.entries(n).filter(([t,r])=>r!==""&&r!==void 0&&r!==null).map(([t,r])=>`${encodeURIComponent(t)}=${encodeURIComponent(r)}`).join("&");return e?"?"+e:""};var $=n=>n?e=>{console.log("%c [MONERIUM:DEBUG]:","color:orange;",e);}:()=>{};var S=n=>Object.entries(n).filter(([t,r])=>r!=null).map(([t,r])=>`${t}-${r}`).join("-");var {STORAGE_CODE_VERIFIER:A,STORAGE_ACCESS_TOKEN:p,STORAGE_ACCESS_EXPIRY:g}=f,u=typeof window>"u",b=class{#r;#i;bearerProfile;#n=new Map;isAuthorized=!!this.bearerProfile;#t=()=>{};#s;state;constructor(e){if(!e){this.#r=P.environments.sandbox;return}if(typeof e=="string")this.#r=P.environments[e];else if(this.#t=$(e.debug??!1),this.#r=P.environments[e.environment||"sandbox"],!u&&!e?.clientSecret){let{clientId:t,redirectUri:r}=e;this.#s={clientId:t,redirectUri:r};}else {this.#t("Client credentials detected"),console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");let{clientId:t,clientSecret:r}=e;this.#s={clientId:t,clientSecret:r};}}async authorize(e){let t=e?.clientId||this.#s?.clientId,r=e?.redirectUri||this.#s?.redirectUri;if(!t)throw new Error("Missing ClientId");let s=I(this.#r.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chain:e?.chain,state:e?.state,skip_create_account:e?.skipCreateAccount,skip_kyc:e?.skipKyc});this.#t(`Authorization URL: ${s}`),window.location.assign(s);}async getAccess(e){let t=this.#s?.clientId;if(this.#s?.clientSecret){if(u)return await this.#d(this.#s),!!this?.bearerProfile;console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");}let s=this.#s?.redirectUri;if(!t)throw new Error("Missing ClientId");if(u)throw new Error("This only works client side");let i=new URLSearchParams(window.location.search).get("code")||void 0,d=new URLSearchParams(window.location.search).get("state")||void 0,o=window.localStorage.getItem(p),l=window.localStorage.getItem(g);if(i)return this.#t("Using auth code from auth flow to authorize"),await this.#a(t,s,i,d),this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(e)return this.#t("Using refresh token to authorize"),await this.#c(t,e),this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(o&&l){let a=new Date;if(parseInt(l)<a.getTime())throw window.localStorage.removeItem(p),window.localStorage.removeItem(g),this.isAuthorized=!1,this.bearerProfile=void 0,new Error("Access token has expired");this.#t("Access token should still be valid, checking if it is authorized...");try{return this.#i=`Bearer ${o}`,this.isAuthorized=!0,await this.getTokens(),this.#t("Authorized"),!0}catch{throw this.#t("Access token is invalid."),window.localStorage.removeItem(p),window.localStorage.removeItem(g),this.isAuthorized=!1,this.bearerProfile=void 0,new Error("Access token is invalid.")}}return this.#t(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile}async#o(e){let t;if(R(e))t={...e,grant_type:"authorization_code"};else if(v(e))t={...e,grant_type:"refresh_token"};else if(N(e))t={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#e("post","auth/token",t,!0).then(r=>{if(this.bearerProfile=r,this.isAuthorized=!!r,this.#i=`Bearer ${r?.access_token}`,!u){let i=new Date().getTime()+r?.expires_in*1e3;window.localStorage.setItem(p,r?.access_token||""),window.localStorage.setItem(g,i?.toString());}}).catch(r=>{throw u||(localStorage.removeItem(A),localStorage.removeItem(p),localStorage.removeItem(g),k()),new Error(r?.message)}),R(e)&&k(),this.bearerProfile}getProfile(e){return this.#e("get",`profiles/${e}`)}getProfiles(e){return this.#e("get",`profiles${y(e)}`)}getAddress(e){return this.#e("get",`addresses/${e}`)}getAddresses(e){e=C(e);let t=e?m(e):void 0,r=t?`addresses?${t}`:"addresses";return this.#e("get",r)}getBalances(e,t,r){let s=Array.isArray(r)?r.map(i=>`currency=${i}`).join("&"):r?`currency=${r}`:"";return this.#e("get",`balances/${c(t)}/${e}${s?`?${s}`:""}`)}getIban(e){return this.#e("get",`ibans/${encodeURI(e)}`)}getIbans(e){let{profile:t,chain:r}=e||{},s=y({profile:t,chain:r?c(r):""});return this.#e("get",`ibans${s}`)}getOrders(e){return this.#e("get",`orders${y(e)}`)}getOrder(e){return this.#e("get",`orders/${e}`)}getTokens(){return this.#e("get","tokens")}linkAddress(e){return e=C(e),this.#e("post","addresses",JSON.stringify(e))}placeOrder(e){let t={kind:"redeem",...C(e),counterpart:{...e.counterpart,identifier:C(e.counterpart.identifier)}};return this.#e("post","orders",JSON.stringify(t))}moveIban(e,{address:t,chain:r}){return this.#e("patch",`ibans/${e}`,JSON.stringify({address:t,chain:c(r)}))}requestIban({address:e,chain:t,emailNotifications:r=!0}){return this.#e("post","ibans",JSON.stringify({address:e,chain:c(t),emailNotifications:r}))}submitProfileDetails(e,t){return this.#e("put",`profiles/${e}/details`,JSON.stringify(t))}uploadSupportingDocument(e){let t=new FormData;return t.append("file",e),_(`${this.#r.api}/files`,"post",t,{Authorization:this.#i||""})}async#e(e,t,r,s){let i={Authorization:this.#i||"",Accept:"application/vnd.monerium.api-v2+json","Content-Type":`application/${s?"x-www-form-urlencoded":"json"}`};return _(`${this.#r.api}/${t}`,e.toUpperCase(),s?m(r):r,i)}#a=async(e,t,r,s)=>{let i=localStorage.getItem(A)||"";if(!i)throw new Error("Code verifier not found");return this.#t("Use code verifier to authorize"),this.state=s,localStorage.removeItem(A),await this.#o({code:r,redirect_uri:t,client_id:e,code_verifier:i})};#d=async({clientId:e,clientSecret:t})=>await this.#o({client_id:e,client_secret:t});#c=async(e,t)=>await this.#o({refresh_token:t,client_id:e});subscribeOrderNotifications({filter:e,onMessage:t,onError:r}={}){if(!this.bearerProfile?.access_token)return;let{profile:s,state:i}=e||{},d=y({access_token:this.bearerProfile?.access_token,profile:s,state:i}),o,l=S({profile:s,state:i});if(this.#n?.has(l))o=this.#n.get(l);else {let a=`${this.#r.wss}/orders${d}`;o=new WebSocket(a),this.#n?.set(l,o);}return o.onopen=()=>{console.log("Connected to WebSocket server");},o.onmessage=a=>{let h=JSON.parse(a.data);t&&t(h);},o.onclose=()=>{console.log("WebSocket connection closed"),this.#n?.delete(d);},o.onerror=a=>{r&&r(a),console.error("WebSocket error:",a);},o}unsubscribeOrderNotifications(e){if(e){let t=S({profile:e?.profile,state:e?.state}),r=this.#n?.get(t);r&&(r.close(),this.#n?.delete(t));}else this.#n?.forEach(t=>{t?.close();}),this.#n?.clear(),this.#n=void 0;}async disconnect(){u||localStorage.removeItem(A),this.unsubscribeOrderNotifications(),this.#i=void 0,this.bearerProfile=void 0;}async revokeAccess(){u||(localStorage.removeItem(p),localStorage.removeItem(g)),this.disconnect();}getEnvironment=()=>this.#r;getAuthFlowURI=e=>I(this.#r.api,e)};var Ee=b;
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { M as AccountState, E as Currency, K as IdDocumentKind, j as KYCOutcome, q as KYCState, B as Method, b as MoneriumClient, L as OrderKind, Q as OrderState, F as PaymentStandard, U as Permission, z as ProfileState, D as ProfileType, f as constants, Ee as default, w as getChain, c as parseChain, J as placeOrderMessage, x as rfc3339, O as shortenIban };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monerium/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Essential tools to interact with the Monerium API, an electronic money issuer.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,14 +39,13 @@
|
|
|
39
39
|
"node": ">= 16.15"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"dev": "tsup --watch
|
|
42
|
+
"dev": "tsup --watch",
|
|
43
43
|
"build": "tsup",
|
|
44
|
-
"
|
|
45
|
-
"docs:watch": "typedoc --watch",
|
|
44
|
+
"typedoc": "typedoc",
|
|
46
45
|
"type-map": "tsc --emitDeclarationOnly --declaration",
|
|
47
46
|
"lint": "eslint . --fix",
|
|
48
47
|
"pub:pre": "pnpm publish --no-git-checks --dry-run",
|
|
49
|
-
"test": "jest",
|
|
50
|
-
"test:watch": "jest --watch"
|
|
48
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
49
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
51
50
|
}
|
|
52
51
|
}
|