@monerium/sdk 2.15.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 +45 -81
- package/dist/index.d.ts +406 -169
- package/dist/index.js +24 -20
- package/dist/index.mjs +4 -4
- package/package.json +3 -4
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
|
|
|
@@ -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;
|
|
@@ -94,6 +87,10 @@ type PKCERequest = {
|
|
|
94
87
|
signature?: string;
|
|
95
88
|
/** The network of the wallet to automatically link */
|
|
96
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;
|
|
97
94
|
};
|
|
98
95
|
declare enum Method {
|
|
99
96
|
password = "password",
|
|
@@ -109,24 +106,17 @@ declare enum Permission {
|
|
|
109
106
|
read = "read",
|
|
110
107
|
write = "write"
|
|
111
108
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
auth: {
|
|
124
|
-
method: Method;
|
|
125
|
-
subject: string;
|
|
126
|
-
verified: boolean;
|
|
127
|
-
};
|
|
128
|
-
defaultProfile: string;
|
|
129
|
-
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"
|
|
130
120
|
}
|
|
131
121
|
declare enum KYCState {
|
|
132
122
|
absent = "absent",
|
|
@@ -153,29 +143,102 @@ declare enum PaymentStandard {
|
|
|
153
143
|
scan = "scan",
|
|
154
144
|
chain = "chain"
|
|
155
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
|
+
}
|
|
156
155
|
interface Identifier {
|
|
157
156
|
standard: PaymentStandard;
|
|
158
157
|
bic?: string;
|
|
159
158
|
}
|
|
160
|
-
interface
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
state?: AccountState;
|
|
159
|
+
interface ProfilePermissions {
|
|
160
|
+
id: string;
|
|
161
|
+
kind: ProfileType;
|
|
162
|
+
name: string;
|
|
163
|
+
perms: Permission[];
|
|
164
|
+
}
|
|
165
|
+
interface ProfilesResponse {
|
|
166
|
+
profiles: ProfilePermissions[];
|
|
169
167
|
}
|
|
170
168
|
interface Profile {
|
|
171
169
|
id: string;
|
|
172
170
|
name: string;
|
|
173
|
-
email: string;
|
|
174
|
-
kyc: KYC;
|
|
175
171
|
kind: ProfileType;
|
|
176
|
-
|
|
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
|
+
}
|
|
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[];
|
|
177
240
|
}
|
|
178
|
-
interface
|
|
241
|
+
interface CurrencyBalance {
|
|
179
242
|
currency: Currency;
|
|
180
243
|
amount: string;
|
|
181
244
|
}
|
|
@@ -183,8 +246,7 @@ interface Balances {
|
|
|
183
246
|
id: string;
|
|
184
247
|
address: string;
|
|
185
248
|
chain: Chain;
|
|
186
|
-
|
|
187
|
-
balances: Balance[];
|
|
249
|
+
balances: CurrencyBalance[];
|
|
188
250
|
}
|
|
189
251
|
declare enum OrderKind {
|
|
190
252
|
redeem = "redeem",
|
|
@@ -201,18 +263,18 @@ interface Fee {
|
|
|
201
263
|
currency: Currency;
|
|
202
264
|
amount: string;
|
|
203
265
|
}
|
|
204
|
-
interface
|
|
266
|
+
interface IBANIdentifier extends Identifier {
|
|
205
267
|
standard: PaymentStandard.iban;
|
|
206
268
|
iban: string;
|
|
207
269
|
}
|
|
208
|
-
interface
|
|
270
|
+
interface CrossChainIdentifier extends Identifier {
|
|
209
271
|
standard: PaymentStandard.chain;
|
|
210
272
|
/** The receivers address */
|
|
211
273
|
address: string;
|
|
212
274
|
/** The receivers network */
|
|
213
275
|
chain: Chain | ChainId;
|
|
214
276
|
}
|
|
215
|
-
interface
|
|
277
|
+
interface SCANIdentifier extends Identifier {
|
|
216
278
|
standard: PaymentStandard.scan;
|
|
217
279
|
sortCode: string;
|
|
218
280
|
accountNumber: string;
|
|
@@ -227,7 +289,7 @@ interface Corporation {
|
|
|
227
289
|
country: string;
|
|
228
290
|
}
|
|
229
291
|
interface Counterpart {
|
|
230
|
-
identifier:
|
|
292
|
+
identifier: IBANIdentifier | SCANIdentifier | CrossChainIdentifier;
|
|
231
293
|
details: Individual | Corporation;
|
|
232
294
|
}
|
|
233
295
|
interface OrderMetadata {
|
|
@@ -254,6 +316,7 @@ interface Order {
|
|
|
254
316
|
accountId: string;
|
|
255
317
|
address: string;
|
|
256
318
|
kind: OrderKind;
|
|
319
|
+
chain: Chain;
|
|
257
320
|
amount: string;
|
|
258
321
|
currency: Currency;
|
|
259
322
|
totalFee: string;
|
|
@@ -264,6 +327,9 @@ interface Order {
|
|
|
264
327
|
supportingDocumentId: string;
|
|
265
328
|
meta: OrderMetadata;
|
|
266
329
|
}
|
|
330
|
+
interface OrdersResponse {
|
|
331
|
+
orders: Order[];
|
|
332
|
+
}
|
|
267
333
|
/**
|
|
268
334
|
* Information about the EURe token on different networks.
|
|
269
335
|
*/
|
|
@@ -272,7 +338,6 @@ interface Token {
|
|
|
272
338
|
ticker: Ticker;
|
|
273
339
|
symbol: TokenSymbol;
|
|
274
340
|
chain: Chain;
|
|
275
|
-
network: Network;
|
|
276
341
|
/** The address of the EURe contract on this network */
|
|
277
342
|
address: string;
|
|
278
343
|
/** How many decimals this token supports */
|
|
@@ -309,59 +374,87 @@ interface SupportingDoc {
|
|
|
309
374
|
hash: string;
|
|
310
375
|
meta: SupportingDocMetadata;
|
|
311
376
|
}
|
|
312
|
-
interface CurrencyAccounts {
|
|
313
|
-
/** The accounts network */
|
|
314
|
-
chain: Chain | ChainId;
|
|
315
|
-
currency: Currency;
|
|
316
|
-
}
|
|
317
377
|
interface LinkAddress {
|
|
378
|
+
/** Profile ID that owns the address. */
|
|
379
|
+
profile?: string;
|
|
380
|
+
/** The public key of the blockchain account. */
|
|
318
381
|
address: string;
|
|
319
|
-
|
|
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
|
+
*/
|
|
320
393
|
signature: string;
|
|
321
|
-
|
|
322
|
-
chain?: Chain | ChainId;
|
|
394
|
+
chain: Chain | ChainId;
|
|
323
395
|
}
|
|
324
396
|
interface LinkedAddress {
|
|
325
|
-
id: string;
|
|
326
397
|
profile: string;
|
|
327
398
|
address: string;
|
|
328
|
-
|
|
399
|
+
state: string;
|
|
329
400
|
meta: {
|
|
330
401
|
linkedBy: string;
|
|
331
402
|
linkedAt: string;
|
|
332
403
|
};
|
|
333
404
|
}
|
|
334
|
-
interface
|
|
335
|
-
|
|
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;
|
|
336
420
|
profile: string;
|
|
337
|
-
accountId: string;
|
|
338
421
|
address: string;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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;
|
|
349
436
|
}
|
|
350
|
-
type MoneriumEvent = OrderState;
|
|
351
|
-
type MoneriumEventListener = (notification: OrderNotification) => void;
|
|
352
437
|
type ClassOptions = {
|
|
353
438
|
environment?: ENV;
|
|
439
|
+
debug?: boolean;
|
|
354
440
|
} & BearerTokenCredentials;
|
|
355
441
|
interface AuthFlowOptions {
|
|
442
|
+
/** the auth flow client ID for your application */
|
|
356
443
|
clientId?: string;
|
|
444
|
+
/** the redirect URI defined by your application */
|
|
357
445
|
redirectUri?: string;
|
|
358
|
-
/**
|
|
359
|
-
redirectUrl?: string;
|
|
446
|
+
/** the address your customer should link in auth flow */
|
|
360
447
|
address?: string;
|
|
448
|
+
/** the signature of the address */
|
|
361
449
|
signature?: string;
|
|
450
|
+
/** the chain of the address */
|
|
362
451
|
chain?: Chain | ChainId;
|
|
452
|
+
/** the state oauth parameter */
|
|
363
453
|
state?: string;
|
|
364
|
-
|
|
454
|
+
/** skip account creation in auth flow */
|
|
455
|
+
skipCreateAccount?: boolean;
|
|
456
|
+
/** skip KYC in auth flow */
|
|
457
|
+
skipKyc?: boolean;
|
|
365
458
|
}
|
|
366
459
|
interface ClientCredentials {
|
|
367
460
|
clientId: string;
|
|
@@ -371,26 +464,40 @@ interface AuthorizationCodeCredentials {
|
|
|
371
464
|
clientId: string;
|
|
372
465
|
redirectUri: string;
|
|
373
466
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
type BearerTokenCredentials = ClientCredentials | AuthorizationCodeCredentials | DeprecatedAuthorizationCodeCredentials;
|
|
467
|
+
type BearerTokenCredentials = ClientCredentials | AuthorizationCodeCredentials;
|
|
468
|
+
type ResponseStatus = {
|
|
469
|
+
status: number;
|
|
470
|
+
statusText: string;
|
|
471
|
+
};
|
|
381
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
|
+
*/
|
|
382
492
|
declare class MoneriumClient {
|
|
383
493
|
#private;
|
|
384
|
-
/**
|
|
385
|
-
* The PKCE code verifier
|
|
386
|
-
* @deprecated, use localStorage, will be removed in v3
|
|
387
|
-
* @hidden
|
|
388
|
-
* */
|
|
389
|
-
codeVerifier?: string;
|
|
390
494
|
/**
|
|
391
495
|
* The bearer profile will be available after authentication, it includes the `access_token` and `refresh_token`
|
|
392
496
|
* */
|
|
393
497
|
bearerProfile?: BearerProfile;
|
|
498
|
+
/**
|
|
499
|
+
* The client is authorized if the bearer profile is available
|
|
500
|
+
*/
|
|
394
501
|
isAuthorized: boolean;
|
|
395
502
|
/**
|
|
396
503
|
* The state parameter is used to maintain state between the request and the callback.
|
|
@@ -398,126 +505,185 @@ declare class MoneriumClient {
|
|
|
398
505
|
state: string | undefined;
|
|
399
506
|
/**
|
|
400
507
|
* @defaultValue `sandbox`
|
|
401
|
-
* @example
|
|
402
|
-
* new MoneriumClient() // defaults to `sandbox`
|
|
403
|
-
*
|
|
404
|
-
* new MoneriumClient('production')
|
|
405
|
-
*
|
|
406
|
-
* new MoneriumClient({
|
|
407
|
-
* environment: 'sandbox',
|
|
408
|
-
* clientId: 'your-client-id',
|
|
409
|
-
* redirectUri: 'your-redirect-url'
|
|
410
|
-
* })
|
|
411
508
|
* */
|
|
412
509
|
constructor(envOrOptions?: ENV | ClassOptions);
|
|
413
510
|
/**
|
|
414
511
|
* Construct the url to the authorization code flow and redirects,
|
|
415
512
|
* Code Verifier needed for the code challenge is stored in local storage
|
|
416
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
|
|
417
518
|
* @returns string
|
|
418
|
-
*
|
|
419
|
-
* @category Auth
|
|
519
|
+
*
|
|
420
520
|
*/
|
|
421
|
-
authorize(
|
|
521
|
+
authorize(params?: AuthFlowOptions): Promise<void>;
|
|
422
522
|
/**
|
|
423
|
-
*
|
|
523
|
+
* Will use the authorization code flow code to get access token
|
|
524
|
+
*
|
|
525
|
+
* @group Authentication
|
|
526
|
+
*
|
|
424
527
|
* @param {AuthorizationCodeCredentials | ClientCredentials} client - the client credentials
|
|
528
|
+
*
|
|
425
529
|
* @returns boolean to indicate if access has been granted
|
|
426
|
-
*
|
|
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
|
+
* ```
|
|
427
543
|
*/
|
|
428
|
-
getAccess(
|
|
544
|
+
getAccess(refreshToken?: string): Promise<boolean>;
|
|
429
545
|
/**
|
|
430
|
-
*
|
|
431
|
-
* @
|
|
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}
|
|
432
549
|
*/
|
|
433
|
-
|
|
550
|
+
getProfile(profile: string): Promise<Profile>;
|
|
434
551
|
/**
|
|
435
|
-
*
|
|
436
|
-
* @
|
|
437
|
-
* @category Profiles
|
|
552
|
+
* @group Profiles
|
|
553
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/profiles/operation/profiles | API Documentation}
|
|
438
554
|
*/
|
|
439
|
-
|
|
555
|
+
getProfiles(params?: ProfilesQueryParams): Promise<ProfilesResponse>;
|
|
440
556
|
/**
|
|
441
|
-
*
|
|
442
|
-
*
|
|
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
|
+
* ```
|
|
443
569
|
*/
|
|
444
|
-
|
|
570
|
+
getAddress(address: string): Promise<Address>;
|
|
445
571
|
/**
|
|
446
|
-
*
|
|
447
|
-
* @param {
|
|
448
|
-
* @
|
|
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}
|
|
449
588
|
*/
|
|
450
|
-
|
|
589
|
+
getIban(iban: string): Promise<IBAN>;
|
|
451
590
|
/**
|
|
452
|
-
*
|
|
453
|
-
* @
|
|
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}
|
|
454
594
|
*/
|
|
455
|
-
|
|
595
|
+
getIbans(queryParameters?: IbansQueryParams): Promise<IBANsResponse>;
|
|
456
596
|
/**
|
|
457
|
-
*
|
|
458
|
-
* @
|
|
597
|
+
* @group Orders
|
|
598
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders | API Documentation}
|
|
599
|
+
*/
|
|
600
|
+
getOrders(filter?: OrderFilter): Promise<OrdersResponse>;
|
|
601
|
+
/**
|
|
602
|
+
* @group Orders
|
|
603
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/order | API Documentation}
|
|
459
604
|
*/
|
|
460
605
|
getOrder(orderId: string): Promise<Order>;
|
|
461
606
|
/**
|
|
462
|
-
*
|
|
463
|
-
* @
|
|
607
|
+
* @group Tokens
|
|
608
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/tokens | API Documentation}
|
|
464
609
|
*/
|
|
465
610
|
getTokens(): Promise<Token[]>;
|
|
466
611
|
/**
|
|
467
|
-
*
|
|
468
|
-
* @
|
|
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}
|
|
469
615
|
*/
|
|
470
|
-
linkAddress(
|
|
616
|
+
linkAddress(payload: LinkAddress): Promise<LinkedAddress>;
|
|
471
617
|
/**
|
|
472
|
-
* {@link https://monerium.dev/api-docs#operation/post-orders}
|
|
473
|
-
*
|
|
618
|
+
* @see {@link https://monerium.dev/api-docs-v2#tag/orders/operation/post-orders | API Documentation}
|
|
619
|
+
*
|
|
620
|
+
* @group Orders
|
|
474
621
|
*/
|
|
475
622
|
placeOrder(order: NewOrder): Promise<Order>;
|
|
476
623
|
/**
|
|
477
|
-
*
|
|
478
|
-
* @
|
|
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}
|
|
479
644
|
*/
|
|
480
645
|
uploadSupportingDocument(document: File): Promise<SupportingDoc>;
|
|
481
646
|
/**
|
|
482
647
|
* Connects to the order notifications socket
|
|
483
|
-
*
|
|
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
|
+
|
|
484
653
|
*/
|
|
485
|
-
|
|
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;
|
|
486
660
|
/**
|
|
487
|
-
*
|
|
488
|
-
*
|
|
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}
|
|
489
666
|
*/
|
|
490
|
-
|
|
667
|
+
unsubscribeOrderNotifications(params?: OrderNotificationQueryParams): void;
|
|
491
668
|
/**
|
|
492
|
-
* Cleanups the
|
|
493
|
-
*
|
|
669
|
+
* Cleanups the localstorage and websocket connections
|
|
670
|
+
*
|
|
671
|
+
* @group Authentication
|
|
494
672
|
*/
|
|
495
673
|
disconnect(): Promise<void>;
|
|
496
674
|
/**
|
|
497
675
|
* Revokes access
|
|
498
|
-
*
|
|
676
|
+
*
|
|
677
|
+
* @group Authentication
|
|
499
678
|
*/
|
|
500
679
|
revokeAccess(): Promise<void>;
|
|
501
680
|
/**
|
|
502
|
-
*
|
|
503
|
-
* We are setting a subscription map because we need the user to have a token to start the WebSocket connection
|
|
504
|
-
* {@link https://monerium.dev/api-docs#operation/profile-orders-notifications}
|
|
505
|
-
* @param event The event to subscribe to
|
|
506
|
-
* @param handler The handler to be called when the event is triggered
|
|
507
|
-
* @category Orders
|
|
508
|
-
*/
|
|
509
|
-
subscribeOrders(event: MoneriumEvent, handler: MoneriumEventListener): void;
|
|
510
|
-
/**
|
|
511
|
-
* Unsubscribe from MoneriumEvent and close the socket if there are no more subscriptions
|
|
512
|
-
* @param event The event to unsubscribe from
|
|
513
|
-
* @category Orders
|
|
514
|
-
*/
|
|
515
|
-
unsubscribeOrders(event: MoneriumEvent): void;
|
|
516
|
-
/**
|
|
681
|
+
*
|
|
517
682
|
* @hidden
|
|
518
683
|
*/
|
|
519
684
|
getEnvironment: () => Environment;
|
|
520
685
|
/**
|
|
686
|
+
*
|
|
521
687
|
* @hidden
|
|
522
688
|
*/
|
|
523
689
|
getAuthFlowURI: (args: PKCERequestArgs) => string;
|
|
@@ -533,25 +699,96 @@ declare const _default: {
|
|
|
533
699
|
*/
|
|
534
700
|
STORAGE_CODE_VERIFIER: string;
|
|
535
701
|
/**
|
|
536
|
-
* 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.
|
|
537
707
|
*/
|
|
538
|
-
|
|
708
|
+
STORAGE_ACCESS_EXPIRY: string;
|
|
539
709
|
};
|
|
540
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
|
+
*/
|
|
541
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;
|
|
542
725
|
/**
|
|
543
726
|
* The message to be signed when placing an order.
|
|
544
727
|
* @param amount The amount to be sent
|
|
545
728
|
* @param currency The currency to be sent
|
|
546
729
|
* @param receiver The receiver of the funds
|
|
547
730
|
* @param chain The chainId of the network if it's a cross-chain transaction
|
|
548
|
-
* @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`
|
|
549
744
|
*/
|
|
550
745
|
declare const placeOrderMessage: (amount: string | number, currency: Currency, receiver: string, chain?: ChainId | Chain) => string;
|
|
551
746
|
/**
|
|
552
|
-
*
|
|
553
|
-
* @
|
|
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
|
+
* ```
|
|
554
761
|
*/
|
|
555
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
|
+
*/
|
|
556
793
|
|
|
557
|
-
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 l={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 E=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(E||{}),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||{}),v=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(v||{}),N=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(N||{}),q=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(q||{}),B=(t=>(t.redeem="redeem",t.issue="issue",t))(B||{}),U=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))(U||{});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())},h=n=>typeof n=="number"?R(n):n,z=(n,e,t,r)=>{let i=`${e?.toUpperCase()||"EUR"}`;return r?`Send ${i} ${n} to ${t} on ${h(r)} 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("&"):"",R=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?.chain){let{chain:e,...t}=n;return {...t,chain:h(e)}}return n};var M=(n,e)=>{let{client_id:t,redirect_uri:r,scope:i,state:s,address:o,signature:d,chain:k}=n,S=o?{address:o,...d!==void 0?{signature:d}:{},...k!==void 0?{chain:h(k)}:{}}:{};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})},F=()=>{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=>$__default.default.stringify(D__default.default(n)),x=(n,e)=>{let t=F(),r=L(t);return localStorage.setItem(c.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${M(e,r)}`},y=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},w=n=>n.code!=null,I=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:g,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=l.environments.sandbox;return}if(typeof e=="string")this.#t=l.environments[e];else if(this.#t=l.environments[e.environment||"sandbox"],a){let{clientId:t,clientSecret:r}=e;this.#r={clientId:t,clientSecret:r};}else {let{clientId:t,redirectUri:r}=e,{redirectUrl:i}=e;this.#r={clientId:t,redirectUri:r||i};}}async authorize(e){let t=e?.clientId||this.#r?.clientId,r=e?.redirectUri||e?.redirectUrl||this.#r?.redirectUri;if(!t)throw new Error("Missing ClientId");if(!r)throw new Error("Missing RedirectUri");let i=x(this.#t.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chain:e?.chain,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?.redirectUri||e?.redirectUrl||this.#r?.redirectUri;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(w(e))t={...e,grant_type:"authorization_code"};else if(I(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(g),localStorage.removeItem(m),y()),new Error(r?.message)}),w(e)&&y(),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(g)||"";if(!s)throw new Error("Code verifier not found");return this.codeVerifier=s,this.state=i,localStorage.removeItem(g),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(g),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(g),t}};var le=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 =
|
|
15
|
+
exports.AccountState = M;
|
|
16
16
|
exports.Currency = E;
|
|
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.
|
|
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 l={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 E=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(E||{}),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||{}),v=(r=>(r.approved="approved",r.rejected="rejected",r.unknown="unknown",r))(v||{}),N=(r=>(r.requested="requested",r.approved="approved",r.pending="pending",r))(N||{}),q=(r=>(r.iban="iban",r.scan="scan",r.chain="chain",r))(q||{}),B=(t=>(t.redeem="redeem",t.issue="issue",t))(B||{}),U=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))(U||{});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())},h=n=>typeof n=="number"?R(n):n,z=(n,e,t,r)=>{let i=`${e?.toUpperCase()||"EUR"}`;return r?`Send ${i} ${n} to ${t} on ${h(r)} 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("&"):"",R=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?.chain){let{chain:e,...t}=n;return {...t,chain:h(e)}}return n};var M=(n,e)=>{let{client_id:t,redirect_uri:r,scope:i,state:s,address:o,signature:d,chain:k}=n,S=o?{address:o,...d!==void 0?{signature:d}:{},...k!==void 0?{chain:h(k)}:{}}:{};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})},F=()=>{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=>$.stringify(D(n)),x=(n,e)=>{let t=F(),r=L(t);return localStorage.setItem(c.STORAGE_CODE_VERIFIER,t||""),`${n}/auth?${M(e,r)}`},y=()=>{let n=window.location.href;if(!n||!n?.includes("?"))return;let[e,t]=n.split("?");t&&window.history.replaceState(null,"",e);},w=n=>n.code!=null,I=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:g,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=l.environments.sandbox;return}if(typeof e=="string")this.#t=l.environments[e];else if(this.#t=l.environments[e.environment||"sandbox"],a){let{clientId:t,clientSecret:r}=e;this.#r={clientId:t,clientSecret:r};}else {let{clientId:t,redirectUri:r}=e,{redirectUrl:i}=e;this.#r={clientId:t,redirectUri:r||i};}}async authorize(e){let t=e?.clientId||this.#r?.clientId,r=e?.redirectUri||e?.redirectUrl||this.#r?.redirectUri;if(!t)throw new Error("Missing ClientId");if(!r)throw new Error("Missing RedirectUri");let i=x(this.#t.api,{client_id:t,redirect_uri:r,address:e?.address,signature:e?.signature,chain:e?.chain,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?.redirectUri||e?.redirectUrl||this.#r?.redirectUri;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(w(e))t={...e,grant_type:"authorization_code"};else if(I(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(g),localStorage.removeItem(m),y()),new Error(r?.message)}),w(e)&&y(),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(g)||"";if(!s)throw new Error("Code verifier not found");return this.codeVerifier=s,this.state=i,localStorage.removeItem(g),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(g),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(g),t}};var le=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,10 +39,9 @@
|
|
|
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",
|