@monerium/sdk 3.4.8 → 3.4.10
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 +20 -20
- package/dist/index.d.ts +27 -27
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
| [Monerium.com](https://monerium.com/) | [Monerium.app](https://monerium.app/) | [Monerium
|
|
2
|
-
| ------------------------------------- | ------------------------------------- |
|
|
1
|
+
| [Monerium.com](https://monerium.com/) | [Monerium.app](https://monerium.app/) | [Monerium Dev Docs](https://docs.monerium.com/) |
|
|
2
|
+
| ------------------------------------- | ------------------------------------- | ----------------------------------------------- |
|
|
3
3
|
|
|
4
4
|
# Monerium SDK Documentation
|
|
5
5
|
|
|
6
|
-
<a href="https://monerium.
|
|
6
|
+
<a href="https://docs.monerium.com">
|
|
7
7
|
<picture>
|
|
8
8
|
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/Developer_portal-2c6ca7"></source>
|
|
9
9
|
<img src="https://img.shields.io/badge/Developer_portal-2c6ca7" alt="Static Badge"></img>
|
|
10
10
|
</picture>
|
|
11
11
|
</a>
|
|
12
|
-
<a href="https://monerium.
|
|
12
|
+
<a href="https://docs.monerium.com/api">
|
|
13
13
|
<picture>
|
|
14
14
|
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/API_documentation-2c6ca7"></source>
|
|
15
15
|
<img src="https://img.shields.io/badge/API_documentation-2c6ca7" alt="Static Badge"></img>
|
|
@@ -67,10 +67,10 @@ yarn add @monerium/sdk
|
|
|
67
67
|
|
|
68
68
|
### Environments - URLs
|
|
69
69
|
|
|
70
|
-
| Environment | Web
|
|
71
|
-
| ----------- |
|
|
72
|
-
| sandbox | https://monerium.
|
|
73
|
-
| production | https://monerium.app
|
|
70
|
+
| Environment | Web | API |
|
|
71
|
+
| ----------- | ---------------------------- | ------------------------ |
|
|
72
|
+
| sandbox | https://sandbox.monerium.app | https://api.monerium.dev |
|
|
73
|
+
| production | https://monerium.app | https://api.monerium.app |
|
|
74
74
|
|
|
75
75
|
### Environments - Networks
|
|
76
76
|
|
|
@@ -91,7 +91,7 @@ yarn add @monerium/sdk
|
|
|
91
91
|
|
|
92
92
|
## Usage Examples
|
|
93
93
|
|
|
94
|
-
We recommend starting in the [Developer Portal](https://monerium.
|
|
94
|
+
We recommend starting in the [Developer Portal](https://docs.monerium.com). There, you will learn more about `client_id`'s and ways of authenticating.
|
|
95
95
|
|
|
96
96
|
#### Initialize and authenticate using Client Credentials
|
|
97
97
|
|
|
@@ -120,7 +120,7 @@ await monerium.getAccess(refresh_token);
|
|
|
120
120
|
|
|
121
121
|
API documentation:
|
|
122
122
|
|
|
123
|
-
- [/auth/token](https://monerium.
|
|
123
|
+
- [/auth/token](https://docs.monerium.com/api#operation/auth-token)
|
|
124
124
|
|
|
125
125
|
#### Initialize and authenticate using Authorization Code Flow with PKCE
|
|
126
126
|
|
|
@@ -187,8 +187,8 @@ export function App() {
|
|
|
187
187
|
|
|
188
188
|
API documentation:
|
|
189
189
|
|
|
190
|
-
- [/auth](https://monerium.
|
|
191
|
-
- [/auth/token](https://monerium.
|
|
190
|
+
- [/auth](https://docs.monerium.com/api#operation/auth)
|
|
191
|
+
- [/auth/token](https://docs.monerium.com/api#operation/auth-token)
|
|
192
192
|
|
|
193
193
|
#### Get account information
|
|
194
194
|
|
|
@@ -207,8 +207,8 @@ const balances: Balances = await monerium.getBalances();
|
|
|
207
207
|
|
|
208
208
|
API documentation:
|
|
209
209
|
|
|
210
|
-
- [/profile](https://monerium.
|
|
211
|
-
- [/profile/{profileId{/balances](https://monerium.
|
|
210
|
+
- [/profile](https://docs.monerium.com/api#operation/profile)
|
|
211
|
+
- [/profile/{profileId{/balances](https://docs.monerium.com/api#operation/profile-balances)
|
|
212
212
|
|
|
213
213
|
#### Get token information
|
|
214
214
|
|
|
@@ -220,7 +220,7 @@ const tokens: Token[] = await monerium.getTokens();
|
|
|
220
220
|
|
|
221
221
|
API documentation:
|
|
222
222
|
|
|
223
|
-
- [/tokens](https://monerium.
|
|
223
|
+
- [/tokens](https://docs.monerium.com/api#operation/tokens)
|
|
224
224
|
|
|
225
225
|
#### Link a new address to Monerium
|
|
226
226
|
|
|
@@ -253,7 +253,7 @@ await monerium.linkAddress({
|
|
|
253
253
|
|
|
254
254
|
API documentation:
|
|
255
255
|
|
|
256
|
-
- [/profile/{profileId{/addresses](https://monerium.
|
|
256
|
+
- [/profile/{profileId{/addresses](https://docs.monerium.com/api#operation/profile-addresses)
|
|
257
257
|
|
|
258
258
|
#### Get and place orders
|
|
259
259
|
|
|
@@ -308,8 +308,8 @@ const order = await monerium.placeOrder({
|
|
|
308
308
|
|
|
309
309
|
API documentation:
|
|
310
310
|
|
|
311
|
-
- [GET /orders](https://monerium.
|
|
312
|
-
- [POST /orders](https://monerium.
|
|
311
|
+
- [GET /orders](https://docs.monerium.com/api#operation/orders)
|
|
312
|
+
- [POST /orders](https://docs.monerium.com/api#operation/post-orders)
|
|
313
313
|
|
|
314
314
|
#### Add supporting documents
|
|
315
315
|
|
|
@@ -323,7 +323,7 @@ const supportingDocumentId: SupportingDoc =
|
|
|
323
323
|
|
|
324
324
|
API documentation:
|
|
325
325
|
|
|
326
|
-
- [/files](https://monerium.
|
|
326
|
+
- [/files](https://docs.monerium.com/api#operation/supporting-document)
|
|
327
327
|
|
|
328
328
|
#### Subscribe to order events
|
|
329
329
|
|
|
@@ -357,7 +357,7 @@ monerium.unsubscribeOrderNotifications();
|
|
|
357
357
|
|
|
358
358
|
## API Reference
|
|
359
359
|
|
|
360
|
-
[API Documentation](https://monerium.
|
|
360
|
+
[API Documentation](https://docs.monerium.com//api)
|
|
361
361
|
|
|
362
362
|
## Contributing
|
|
363
363
|
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ type CurrencyCode = 'eur' | 'gbp' | 'usd' | 'isk';
|
|
|
29
29
|
type AuthArgs = Omit<AuthCodePayload, 'grant_type'> | Omit<RefreshTokenPayload, 'grant_type'> | Omit<ClientCredentialsPayload, 'grant_type'>;
|
|
30
30
|
/** One of the options for the {@link AuthArgs}.
|
|
31
31
|
*
|
|
32
|
-
* [Auth endpoint in API documentation:](https://monerium.
|
|
32
|
+
* [Auth endpoint in API documentation:](https://docs.monerium.com/api#operation/auth).
|
|
33
33
|
* */
|
|
34
34
|
interface AuthCodePayload {
|
|
35
35
|
grant_type: 'authorization_code';
|
|
@@ -40,7 +40,7 @@ interface AuthCodePayload {
|
|
|
40
40
|
}
|
|
41
41
|
/** One of the options for the {@link AuthArgs}.
|
|
42
42
|
*
|
|
43
|
-
* [Auth endpoint in API documentation:](https://monerium.
|
|
43
|
+
* [Auth endpoint in API documentation:](https://docs.monerium.com/api#operation/auth).
|
|
44
44
|
* */
|
|
45
45
|
interface RefreshTokenPayload {
|
|
46
46
|
grant_type: 'refresh_token';
|
|
@@ -49,7 +49,7 @@ interface RefreshTokenPayload {
|
|
|
49
49
|
}
|
|
50
50
|
/** One of the options for the {@link AuthArgs}.
|
|
51
51
|
*
|
|
52
|
-
* [Auth endpoint in API documentation:](https://monerium.
|
|
52
|
+
* [Auth endpoint in API documentation:](https://docs.monerium.com/api#operation/auth).
|
|
53
53
|
* */
|
|
54
54
|
interface ClientCredentialsPayload {
|
|
55
55
|
grant_type: 'client_credentials';
|
|
@@ -446,7 +446,7 @@ interface LinkAddress {
|
|
|
446
446
|
/**
|
|
447
447
|
* The signature hash of signing the `message` with the private key associated with the given address.
|
|
448
448
|
* For signing on-chain with ERC1271 contracts, use `0x`, visit the documentation for further details.
|
|
449
|
-
* https://monerium.
|
|
449
|
+
* https://docs.monerium.com/api#tag/addresses/operation/link-address
|
|
450
450
|
*/
|
|
451
451
|
signature: string;
|
|
452
452
|
chain: Chain | ChainId;
|
|
@@ -637,10 +637,10 @@ declare class MoneriumClient {
|
|
|
637
637
|
* Code Verifier needed for the code challenge is stored in local storage
|
|
638
638
|
* For automatic wallet link, add the following properties: `address`, `signature` & `chain`
|
|
639
639
|
*
|
|
640
|
-
* This authorization code is then used to request an access token via the token endpoint. (https://monerium.
|
|
640
|
+
* This authorization code is then used to request an access token via the token endpoint. (https://docs.monerium.com/api#operation/auth-token)
|
|
641
641
|
*
|
|
642
642
|
* @group Authentication
|
|
643
|
-
* @see {@link https://monerium.
|
|
643
|
+
* @see {@link https://docs.monerium.com/api#tag/auth/operation/auth | API Documentation}
|
|
644
644
|
* @param {AuthFlowOptions} [params] - the auth flow params
|
|
645
645
|
* @returns void
|
|
646
646
|
*
|
|
@@ -659,7 +659,7 @@ declare class MoneriumClient {
|
|
|
659
659
|
* https://monerium.com/siwe
|
|
660
660
|
*
|
|
661
661
|
* @group Authentication
|
|
662
|
-
* @see {@link https://monerium.
|
|
662
|
+
* @see {@link https://docs.monerium.com/api#tag/auth/operation/auth | API Documentation}
|
|
663
663
|
* @param {AuthFlowSIWEOptions} [params] - the auth flow SIWE params
|
|
664
664
|
* @returns void
|
|
665
665
|
*
|
|
@@ -697,18 +697,18 @@ declare class MoneriumClient {
|
|
|
697
697
|
getAccess(refreshToken?: string): Promise<boolean>;
|
|
698
698
|
/**
|
|
699
699
|
* @group Authentication
|
|
700
|
-
* @see {@link https://monerium.
|
|
700
|
+
* @see {@link https://docs.monerium.com/api#tag/auth/operation/auth-context | API Documentation}
|
|
701
701
|
*/
|
|
702
702
|
getAuthContext(): Promise<AuthContext>;
|
|
703
703
|
/**
|
|
704
704
|
* @group Profiles
|
|
705
705
|
* @param {string} profile - the id of the profile to fetch.
|
|
706
|
-
* @see {@link https://monerium.
|
|
706
|
+
* @see {@link https://docs.monerium.com/api#tag/profiles/operation/profile | API Documentation}
|
|
707
707
|
*/
|
|
708
708
|
getProfile(profile: string): Promise<Profile>;
|
|
709
709
|
/**
|
|
710
710
|
* @group Profiles
|
|
711
|
-
* @see {@link https://monerium.
|
|
711
|
+
* @see {@link https://docs.monerium.com/api#tag/profiles/operation/profiles | API Documentation}
|
|
712
712
|
*/
|
|
713
713
|
getProfiles(params?: ProfilesQueryParams): Promise<ProfilesResponse>;
|
|
714
714
|
/**
|
|
@@ -718,7 +718,7 @@ declare class MoneriumClient {
|
|
|
718
718
|
* @group Addresses
|
|
719
719
|
* @param {string} address - The public key of the blockchain account.
|
|
720
720
|
*
|
|
721
|
-
* @see {@link https://monerium.
|
|
721
|
+
* @see {@link https://docs.monerium.com/api#tag/addresses/operation/address | API Documentation}
|
|
722
722
|
*
|
|
723
723
|
* @example
|
|
724
724
|
* ```ts
|
|
@@ -729,12 +729,12 @@ declare class MoneriumClient {
|
|
|
729
729
|
/**
|
|
730
730
|
* @group Addresses
|
|
731
731
|
* @param {AddressesQueryParams} [params] - No required parameters.
|
|
732
|
-
* @see {@link https://monerium.
|
|
732
|
+
* @see {@link https://docs.monerium.com/api#tag/addresses/operation/addresses | API Documentation}
|
|
733
733
|
*/
|
|
734
734
|
getAddresses(params?: AddressesQueryParams): Promise<AddressesResponse>;
|
|
735
735
|
/**
|
|
736
736
|
* @group Addresses
|
|
737
|
-
* @see {@link https://monerium.
|
|
737
|
+
* @see {@link https://docs.monerium.com/api#tag/addresses/operation/balances| API Documentation}
|
|
738
738
|
*/
|
|
739
739
|
getBalances(address: string, chain: Chain | ChainId, currencies?: Currency | Currency[]): Promise<Balances>;
|
|
740
740
|
/**
|
|
@@ -742,28 +742,28 @@ declare class MoneriumClient {
|
|
|
742
742
|
*
|
|
743
743
|
* @group IBANs
|
|
744
744
|
* @param {string} iban - the IBAN to fetch.
|
|
745
|
-
* @see {@link https://monerium.
|
|
745
|
+
* @see {@link https://docs.monerium.com/api#tag/ibans/operation/iban | API Documentation}
|
|
746
746
|
*/
|
|
747
747
|
getIban(iban: string): Promise<IBAN>;
|
|
748
748
|
/**
|
|
749
749
|
* Fetch all IBANs for the profile
|
|
750
750
|
* @group IBANs
|
|
751
|
-
* @see {@link https://monerium.
|
|
751
|
+
* @see {@link https://docs.monerium.com/api#tag/ibans/operation/ibans | API Documentation}
|
|
752
752
|
*/
|
|
753
753
|
getIbans(queryParameters?: IbansQueryParams): Promise<IBANsResponse>;
|
|
754
754
|
/**
|
|
755
755
|
* @group Orders
|
|
756
|
-
* @see {@link https://monerium.
|
|
756
|
+
* @see {@link https://docs.monerium.com/api#tag/orders | API Documentation}
|
|
757
757
|
*/
|
|
758
758
|
getOrders(filter?: OrderFilter): Promise<OrdersResponse>;
|
|
759
759
|
/**
|
|
760
760
|
* @group Orders
|
|
761
|
-
* @see {@link https://monerium.
|
|
761
|
+
* @see {@link https://docs.monerium.com/api#tag/order | API Documentation}
|
|
762
762
|
*/
|
|
763
763
|
getOrder(orderId: string): Promise<Order>;
|
|
764
764
|
/**
|
|
765
765
|
* @group Tokens
|
|
766
|
-
* @see {@link https://monerium.
|
|
766
|
+
* @see {@link https://docs.monerium.com/api#tag/tokens | API Documentation}
|
|
767
767
|
*/
|
|
768
768
|
getTokens(): Promise<Token[]>;
|
|
769
769
|
/**
|
|
@@ -774,7 +774,7 @@ declare class MoneriumClient {
|
|
|
774
774
|
*
|
|
775
775
|
* @group Signatures
|
|
776
776
|
* @param {SignaturesQueryParams} [params] - Optional query parameters to filter signatures
|
|
777
|
-
* @see {@link https://monerium.
|
|
777
|
+
* @see {@link https://docs.monerium.com/api#tag/signatures/operation/get-signatures | API Documentation}
|
|
778
778
|
*
|
|
779
779
|
* @example
|
|
780
780
|
* ```ts
|
|
@@ -797,7 +797,7 @@ declare class MoneriumClient {
|
|
|
797
797
|
/**
|
|
798
798
|
* Add a new address to the profile
|
|
799
799
|
* @group Addresses
|
|
800
|
-
* @see {@link https://monerium.
|
|
800
|
+
* @see {@link https://docs.monerium.com/api#tag/addresses/operation/link-address | API Documentation}
|
|
801
801
|
*/
|
|
802
802
|
linkAddress(payload: LinkAddress): Promise<LinkedAddress>;
|
|
803
803
|
/**
|
|
@@ -810,7 +810,7 @@ declare class MoneriumClient {
|
|
|
810
810
|
* - `Order` - Full order object for regular orders
|
|
811
811
|
* - `ResponseStatus` - Status object with `{status: 202, statusText: "Accepted"}` for multi-sig orders
|
|
812
812
|
*
|
|
813
|
-
* @see {@link https://monerium.
|
|
813
|
+
* @see {@link https://docs.monerium.com/api#tag/orders/operation/post-orders | API Documentation}
|
|
814
814
|
*
|
|
815
815
|
* @group Orders
|
|
816
816
|
*/
|
|
@@ -819,23 +819,23 @@ declare class MoneriumClient {
|
|
|
819
819
|
* @group IBANs
|
|
820
820
|
* @param {string} iban - the IBAN to move.
|
|
821
821
|
* @param {MoveIbanPayload} payload - the payload to move the IBAN.
|
|
822
|
-
* @see {@link https://monerium.
|
|
822
|
+
* @see {@link https://docs.monerium.com/api#tag/ibans/operation/move-iban | API Documentation}
|
|
823
823
|
*/
|
|
824
824
|
moveIban(iban: string, { address, chain }: MoveIbanPayload): Promise<ResponseStatus>;
|
|
825
825
|
/**
|
|
826
826
|
* @group IBANs
|
|
827
827
|
* @param {RequestIbanPayload} payload
|
|
828
|
-
* @see {@link https://monerium.
|
|
828
|
+
* @see {@link https://docs.monerium.com/api#tag/ibans/operation/request-iban | API Documentation}
|
|
829
829
|
*/
|
|
830
830
|
requestIban({ address, chain, emailNotifications, }: RequestIbanPayload): Promise<ResponseStatus>;
|
|
831
831
|
/**
|
|
832
832
|
* @group Profiles
|
|
833
|
-
* @see {@link https://monerium.
|
|
833
|
+
* @see {@link https://docs.monerium.com/api#tag/profiles/operation/profile-details | API Documentation}
|
|
834
834
|
*/
|
|
835
835
|
submitProfileDetails(profile: string, body: SubmitProfileDetailsPayload): Promise<ResponseStatus>;
|
|
836
836
|
/**
|
|
837
837
|
* @group Orders
|
|
838
|
-
* @see {@link https://monerium.
|
|
838
|
+
* @see {@link https://docs.monerium.com/api#tag/orders/operation/supporting-document | API Documentation}
|
|
839
839
|
*/
|
|
840
840
|
uploadSupportingDocument(document: File): Promise<SupportingDoc>;
|
|
841
841
|
/**
|
|
@@ -843,7 +843,7 @@ declare class MoneriumClient {
|
|
|
843
843
|
*
|
|
844
844
|
* @group Orders
|
|
845
845
|
* @param {OrderNotificationQueryParams} [params]
|
|
846
|
-
* @see {@link https://monerium.
|
|
846
|
+
* @see {@link https://docs.monerium.com/api#tag/orders/operation/orders-notifications | API Document - Websocket}
|
|
847
847
|
|
|
848
848
|
*/
|
|
849
849
|
subscribeOrderNotifications({ filter, onMessage, onError, }?: {
|
|
@@ -857,7 +857,7 @@ declare class MoneriumClient {
|
|
|
857
857
|
*
|
|
858
858
|
* @group Orders
|
|
859
859
|
* @param {OrderNotificationQueryParams} [params] - specify which socket to close or close all if not provided
|
|
860
|
-
* @see {@link https://monerium.
|
|
860
|
+
* @see {@link https://docs.monerium.com/api#tag/orders/operation/orders-notifications | API Document - Websocket}
|
|
861
861
|
*/
|
|
862
862
|
unsubscribeOrderNotifications(params?: OrderNotificationQueryParams): void;
|
|
863
863
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var z=require('crypto-js/enc-base64url.js'),q=require('crypto-js/sha256.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var z__default=/*#__PURE__*/_interopDefault(z);var q__default=/*#__PURE__*/_interopDefault(q);var x={environments:{production:{name:"production",api:"https://api.monerium.app",web:"https://monerium.app",wss:"wss://api.monerium.app"},sandbox:{name:"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 A=()=>{let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=e.length,n=0;for(;n<128;)t+=e.charAt(Math.floor(Math.random()*r)),n+=1;return t},j=t=>z__default.default.stringify(q__default.default(t)),S=()=>{let t=A(),e=j(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),e},k=()=>{let t=window.location.href;if(!t||!t?.includes("?"))return;let[e,r]=t.split("?");r&&window.history.replaceState(null,"",e);},R=t=>t.code!=null,$=t=>t.refresh_token!=null,v=t=>t.client_secret!=null;var _=async(t,e,r,n)=>{let i=await fetch(`${t}`,{method:e,headers:n,body:r}),s,a=await i.text();try{if(s=JSON.parse(a),Object.keys(s).length===0&&s.constructor===Object)switch(i.status){case 201:case 202:return {status:i.status,statusText:i.statusText}}}catch{throw a}if(!i.ok)throw s;return s};var u=t=>{if(!t)return "";let e=Object.entries(t).filter(([r,n])=>n!==""&&n!==
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var z=require('crypto-js/enc-base64url.js'),q=require('crypto-js/sha256.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var z__default=/*#__PURE__*/_interopDefault(z);var q__default=/*#__PURE__*/_interopDefault(q);var x={environments:{production:{name:"production",api:"https://api.monerium.app",web:"https://monerium.app",wss:"wss://api.monerium.app"},sandbox:{name:"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 A=()=>{let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=e.length,n=0;for(;n<128;)t+=e.charAt(Math.floor(Math.random()*r)),n+=1;return t},j=t=>z__default.default.stringify(q__default.default(t)),S=()=>{let t=A(),e=j(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),e},k=()=>{let t=window.location.href;if(!t||!t?.includes("?"))return;let[e,r]=t.split("?");r&&window.history.replaceState(null,"",e);},R=t=>t.code!=null,$=t=>t.refresh_token!=null,v=t=>t.client_secret!=null;var _=async(t,e,r,n)=>{let i=await fetch(`${t}`,{method:e,headers:n,body:r}),s,a=await i.text();try{if(s=JSON.parse(a),Object.keys(s).length===0&&s.constructor===Object)switch(i.status){case 201:case 202:return {status:i.status,statusText:i.statusText}}}catch{throw a}if(!i.ok)throw s;return s};var u=t=>{if(!t)return "";let e=Object.entries(t).filter(([r,n])=>n!==""&&n!==void 0&&n!==null).map(([r,n])=>`${encodeURIComponent(r)}=${encodeURIComponent(n)}`).join("&");return e?"?"+e:""};var N=t=>t?e=>{console.log("%c [MONERIUM:DEBUG]:","color:orange;",e);}:()=>{};var E=t=>Object.entries(t).filter(([r,n])=>n!=null).map(([r,n])=>`${r}-${n}`).join("-");var B=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(B||{}),K=(s=>(s.password="password",s.resource="resource",s.jwt="jwt",s.apiKey="apiKey",s.bearer="bearer",s))(K||{}),M=(r=>(r.corporate="corporate",r.personal="personal",r))(M||{}),F=(r=>(r.read="read",r.write="write",r))(F||{}),L=(s=>(s.created="created",s.pending="pending",s.approved="approved",s.rejected="rejected",s.blocked="blocked",s))(L||{}),Q=(i=>(i.absent="absent",i.submitted="submitted",i.pending="pending",i.confirmed="confirmed",i))(Q||{}),W=(n=>(n.approved="approved",n.rejected="rejected",n.unknown="unknown",n))(W||{}),V=(s=>(s.requested="requested",s.approved="approved",s.pending="pending",s.rejected="rejected",s.closed="closed",s))(V||{}),G=(i=>(i.iban="iban",i.scan="scan",i.chain="chain",i.account="account",i))(G||{}),J=(n=>(n.passport="passport",n.nationalIdentityCard="nationalIdentityCard",n.drivingLicense="drivingLicense",n))(J||{}),H=(r=>(r.redeem="redeem",r.issue="issue",r))(H||{}),X=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))(X||{});var P=t=>{if(t.toString()==="Invalid Date")throw t;let e=n=>n<10?"0"+n:n,r=n=>{if(n===0)return "Z";let i=n>0?"-":"+";return n=Math.abs(n),i+e(Math.floor(n/60))+":"+e(n%60)};return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+"T"+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())+r(t.getTimezoneOffset())},Z=t=>{switch(t){case "noble":case "noble-1":case "grand":case "grand-1":return true;default:return false}},Y=t=>{switch(t){case "ethereum":case "sepolia":case "polygon":case "amoy":case "gnosis":case "chiado":case "arbitrum":case "arbitrumsepolia":case "linea":case "lineasepolia":case "scroll":case "scrollsepolia":case "camino":case "columbus":return true;default:return false}},b=t=>{if(typeof t=="number")return O(t);if(Z(t))return t.split("-")[0];if(Y(t))return t;try{return O(parseInt(t))}catch{throw new Error(`Chain not supported: ${t}`)}},g=(t,e)=>b(T(e,t)),ee=(t,e,r,n)=>{let i=`${e?.toUpperCase()||"EUR"}`;return n?`Send ${i} ${t} to ${r} on ${b(n)} at ${P(new Date)}`:i==="EUR"?`Send ${i} ${t} to ${D(r)} at ${P(new Date)}`:`Send ${i} ${t} to ${r} at ${P(new Date)}`},te=({domain:t,address:e,appName:r,redirectUri:n,chainId:i,issuedAt:s=new Date().toISOString(),expiryAt:a=new Date(Date.now()+1e3*60*5).toISOString(),privacyPolicyUrl:o,termsOfServiceUrl:l})=>`${t} wants you to sign in with your Ethereum account:
|
|
2
2
|
${e}
|
|
3
3
|
|
|
4
4
|
Allow ${r} to access my data on Monerium
|
|
@@ -12,4 +12,4 @@ Expiration Time: ${a}
|
|
|
12
12
|
Resources:
|
|
13
13
|
- https://monerium.com/siwe
|
|
14
14
|
- ${o}
|
|
15
|
-
- ${l}`,C=t=>t&&Object.entries(t)?.length>0?Object.entries(t).filter(([e,r])=>r!==
|
|
15
|
+
- ${l}`,C=t=>t&&Object.entries(t)?.length>0?Object.entries(t).filter(([e,r])=>r!==void 0).map(([e,r])=>`${encodeURIComponent(e)}=${encodeURIComponent(r)}`).join("&"):"",O=t=>{switch(t){case 1:return "ethereum";case 11155111:return "sepolia";case 100:return "gnosis";case 10200:return "chiado";case 137:return "polygon";case 80002:return "amoy";case 42161:return "arbitrum";case 421614:return "arbitrumsepolia";case 59144:return "linea";case 59141:return "lineasepolia";case 534352:return "scroll";case 534351:return "scrollsepolia";case 501:return "columbus";case 500:return "camino";default:throw new Error(`Chain not supported: ${t}`)}},D=t=>{if(typeof t!="string"||!t?.length)return t;let e=t.replace(/\s/g,"");return t?.length>11?`${e.substring(0,4)}...${e.substring(e.length-4)}`:t},re=t=>typeof t!="string"||!t?.length?t:t?.length>11?`${t.substring(0,7)}...${t.substring(t.length-5)}`:t;var T=(t,e)=>{if(e==="sandbox")switch(t){case "ethereum":return "sepolia";case "polygon":return "amoy";case "gnosis":return "chiado";case "arbitrum":return "arbitrumsepolia";case "linea":return "lineasepolia";case "scroll":return "scrollsepolia";case "camino":return "columbus";case "noble":return "noble";default:return t}return t},p=(t,e)=>{if(e?.chain){let{chain:r,...n}=e;return {...n,chain:b(T(r,t))}}return e};var {STORAGE_CODE_VERIFIER:w,STORAGE_ACCESS_TOKEN:h,STORAGE_ACCESS_EXPIRY:m}=f,d=typeof window>"u",I=class{#e;#s;bearerProfile;#i=new Map;isAuthorized=!!this.bearerProfile;#r=()=>{};#n;state;constructor(e){if(!e){this.#e=x.environments.sandbox;return}if(typeof e=="string")this.#e=x.environments[e];else if(this.#r=N(e.debug??false),this.#e=x.environments[e.environment||"sandbox"],!d&&!e?.clientSecret){let{clientId:r,redirectUri:n}=e;this.#n={clientId:r,redirectUri:n};}else if(d&&e?.clientSecret){this.#r("Client credentials detected");let{clientId:r,clientSecret:n}=e;this.#n={clientId:r,clientSecret:n};}}async authorize(e){let r=S(),n=e?.address?{address:e?.address,signature:e?.signature,chain:e?.chain?g(this.#e.name,e?.chain):void 0}:{},i=C({client_id:this.#n?.clientId,redirect_uri:this.#n?.redirectUri,code_challenge:r,code_challenge_method:"S256",response_type:"code",state:e?.state,skip_create_account:e?.skipCreateAccount,skip_kyc:e?.skipKyc,email:e?.email,...n}),s=`${this.#e.api}/auth?${i}`;this.#r(`Auth flow URL: ${s}`),window.location.assign(s);}async siwe(e){let r=S(),n=C({client_id:this.#n?.clientId,redirect_uri:this.#n?.redirectUri,message:e.message,signature:e.signature,code_challenge:r,code_challenge_method:"S256",authentication_method:"siwe",state:e?.state}),i=`${this.#e.api}/auth?${n}`;this.#r(`Auth flow SIWE URL: ${i}`),window.location.assign(i);}async getAccess(e){let r=this.#n?.clientId;if(this.#n?.clientSecret){if(d)return await this.#c(this.#n),!!this?.bearerProfile;console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");}let i=this.#n?.redirectUri;if(!r)throw new Error("Missing ClientId");if(d)throw new Error("This only works client side");let s=new URLSearchParams(window.location.search).get("error")||void 0,a=new URLSearchParams(window.location.search).get("error_description")||void 0;if(s||a)throw new Error(a);let o=new URLSearchParams(window.location.search).get("code")||void 0,l=new URLSearchParams(window.location.search).get("state")||void 0,c=window.localStorage.getItem(h),y=window.localStorage.getItem(m);if(o)return this.#r("Using auth code from auth flow to authorize"),await this.#a(r,i,o,l),this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(e)return this.#r("Using refresh token to authorize"),await this.#d(r,e),this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(c&&y){let U=new Date;if(parseInt(y)<U.getTime())throw window.localStorage.removeItem(h),window.localStorage.removeItem(m),this.isAuthorized=false,this.bearerProfile=void 0,new Error("Access token has expired");this.#r("Access token should still be valid, checking if it is authorized...");try{return this.#s=`Bearer ${c}`,this.isAuthorized=!0,await this.getTokens(),this.#r("Authorized"),!0}catch{throw this.#r("Access token is invalid."),window.localStorage.removeItem(h),window.localStorage.removeItem(m),this.isAuthorized=false,this.bearerProfile=void 0,new Error("Access token is invalid.")}}return this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile}async#o(e){let r;if(R(e))r={...e,grant_type:"authorization_code"};else if($(e))r={...e,grant_type:"refresh_token"};else if(v(e))r={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#t("post","auth/token",r,true).then(n=>{if(this.bearerProfile=n,this.isAuthorized=!!n,this.#s=`Bearer ${n?.access_token}`,!d){let s=new Date().getTime()+n?.expires_in*1e3;window.localStorage.setItem(h,n?.access_token||""),window.localStorage.setItem(m,s?.toString());}}).catch(n=>{throw d||(localStorage.removeItem(w),localStorage.removeItem(h),localStorage.removeItem(m),k()),new Error(n?.message)}),R(e)&&k(),this.bearerProfile}getAuthContext(){return this.#t("get","auth/context")}getProfile(e){return this.#t("get",`profiles/${e}`)}getProfiles(e){return this.#t("get",`profiles${u(e)}`)}getAddress(e){return this.#t("get",`addresses/${e}`)}getAddresses(e){e=p(this.#e.name,e);let r=e?C(e):void 0,n=r?`addresses?${r}`:"addresses";return this.#t("get",n)}getBalances(e,r,n){let i=Array.isArray(n)?n.map(a=>`currency=${a}`).join("&"):n?`currency=${n}`:"",s=g(this.#e.name,r);return this.#t("get",`balances/${s}/${e}${i?`?${i}`:""}`)}getIban(e){return this.#t("get",`ibans/${encodeURI(e)}`)}getIbans(e){let{profile:r,chain:n}=e||{},i=u({profile:r,chain:n?g(this.#e.name,n):""});return this.#t("get",`ibans${i}`)}getOrders(e){return this.#t("get",`orders${u(e)}`)}getOrder(e){return this.#t("get",`orders/${e}`)}getTokens(){return this.#t("get","tokens")}getSignatures(e){let r=e?p(this.#e.name,e):void 0;return this.#t("get",`signatures${u(r)}`)}linkAddress(e){return e=p(this.#e.name,e),this.#t("post","addresses",JSON.stringify(e))}placeOrder(e){let r={kind:"redeem",...p(this.#e.name,e),counterpart:{...e.counterpart,identifier:p(this.#e.name,e.counterpart.identifier)}};return this.#t("post","orders",JSON.stringify(r))}moveIban(e,{address:r,chain:n}){return this.#t("patch",`ibans/${e}`,JSON.stringify({address:r,chain:g(this.#e.name,n)}))}requestIban({address:e,chain:r,emailNotifications:n=true}){return this.#t("post","ibans",JSON.stringify({address:e,chain:g(this.#e.name,r),emailNotifications:n}))}submitProfileDetails(e,r){return this.#t("put",`profiles/${e}/details`,JSON.stringify(r))}uploadSupportingDocument(e){let r=new FormData;return r.append("file",e),_(`${this.#e.api}/files`,"post",r,{Authorization:this.#s||""})}async#t(e,r,n,i){let s={Authorization:this.#s||"",Accept:"application/vnd.monerium.api-v2+json","Content-Type":`application/${i?"x-www-form-urlencoded":"json"}`};return _(`${this.#e.api}/${r}`,e.toUpperCase(),i?C(n):n,s)}#a=async(e,r,n,i)=>{let s=localStorage.getItem(w)||"";if(!s)throw new Error("Code verifier not found");return this.#r("Use code verifier to authorize"),this.state=i,localStorage.removeItem(w),await this.#o({code:n,redirect_uri:r,client_id:e,code_verifier:s})};#c=async({clientId:e,clientSecret:r})=>await this.#o({client_id:e,client_secret:r});#d=async(e,r)=>await this.#o({refresh_token:r,client_id:e});subscribeOrderNotifications({filter:e,onMessage:r,onError:n}={}){if(!this.bearerProfile?.access_token)return;let{profile:i,state:s}=e||{},a=u({access_token:this.bearerProfile?.access_token,profile:i,state:s}),o,l=E({profile:i,state:s});if(this.#i?.has(l))o=this.#i.get(l);else {let c=`${this.#e.wss}/orders${a}`;o=new WebSocket(c),this.#i?.set(l,o);}return o.onopen=()=>{console.log("Connected to WebSocket server");},o.onmessage=c=>{let y=JSON.parse(c.data);r&&r(y);},o.onclose=()=>{console.log("WebSocket connection closed"),this.#i?.delete(a);},o.onerror=c=>{n&&n(c),console.error("WebSocket error:",c);},o}unsubscribeOrderNotifications(e){if(e){let r=E({profile:e?.profile,state:e?.state}),n=this.#i?.get(r);n&&(n.close(),this.#i?.delete(r));}else this.#i?.forEach(r=>{r?.close();}),this.#i?.clear(),this.#i=void 0;}async disconnect(){d||localStorage.removeItem(w),this.unsubscribeOrderNotifications(),this.#s=void 0,this.bearerProfile=void 0;}async revokeAccess(){d||(localStorage.removeItem(h),localStorage.removeItem(m)),this.disconnect();}getEnvironment=()=>this.#e};var De=I;exports.AccountState=V;exports.Currency=B;exports.IdDocumentKind=J;exports.KYCOutcome=W;exports.KYCState=Q;exports.Method=K;exports.MoneriumClient=I;exports.OrderKind=H;exports.OrderState=X;exports.PaymentStandard=G;exports.Permission=F;exports.ProfileState=L;exports.ProfileType=M;exports.constants=f;exports.default=De;exports.getChain=O;exports.parseChain=b;exports.placeOrderMessage=ee;exports.rfc3339=P;exports.shortenAddress=re;exports.shortenIban=D;exports.siweMessage=te;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z from'crypto-js/enc-base64url.js';import q from'crypto-js/sha256.js';var x={environments:{production:{name:"production",api:"https://api.monerium.app",web:"https://monerium.app",wss:"wss://api.monerium.app"},sandbox:{name:"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 A=()=>{let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=e.length,n=0;for(;n<128;)t+=e.charAt(Math.floor(Math.random()*r)),n+=1;return t},j=t=>z.stringify(q(t)),S=()=>{let t=A(),e=j(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),e},k=()=>{let t=window.location.href;if(!t||!t?.includes("?"))return;let[e,r]=t.split("?");r&&window.history.replaceState(null,"",e);},R=t=>t.code!=null,$=t=>t.refresh_token!=null,v=t=>t.client_secret!=null;var _=async(t,e,r,n)=>{let i=await fetch(`${t}`,{method:e,headers:n,body:r}),s,a=await i.text();try{if(s=JSON.parse(a),Object.keys(s).length===0&&s.constructor===Object)switch(i.status){case 201:case 202:return {status:i.status,statusText:i.statusText}}}catch{throw a}if(!i.ok)throw s;return s};var u=t=>{if(!t)return "";let e=Object.entries(t).filter(([r,n])=>n!==""&&n!==
|
|
1
|
+
import z from'crypto-js/enc-base64url.js';import q from'crypto-js/sha256.js';var x={environments:{production:{name:"production",api:"https://api.monerium.app",web:"https://monerium.app",wss:"wss://api.monerium.app"},sandbox:{name:"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 A=()=>{let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=e.length,n=0;for(;n<128;)t+=e.charAt(Math.floor(Math.random()*r)),n+=1;return t},j=t=>z.stringify(q(t)),S=()=>{let t=A(),e=j(t);return localStorage.setItem(f.STORAGE_CODE_VERIFIER,t||""),e},k=()=>{let t=window.location.href;if(!t||!t?.includes("?"))return;let[e,r]=t.split("?");r&&window.history.replaceState(null,"",e);},R=t=>t.code!=null,$=t=>t.refresh_token!=null,v=t=>t.client_secret!=null;var _=async(t,e,r,n)=>{let i=await fetch(`${t}`,{method:e,headers:n,body:r}),s,a=await i.text();try{if(s=JSON.parse(a),Object.keys(s).length===0&&s.constructor===Object)switch(i.status){case 201:case 202:return {status:i.status,statusText:i.statusText}}}catch{throw a}if(!i.ok)throw s;return s};var u=t=>{if(!t)return "";let e=Object.entries(t).filter(([r,n])=>n!==""&&n!==void 0&&n!==null).map(([r,n])=>`${encodeURIComponent(r)}=${encodeURIComponent(n)}`).join("&");return e?"?"+e:""};var N=t=>t?e=>{console.log("%c [MONERIUM:DEBUG]:","color:orange;",e);}:()=>{};var E=t=>Object.entries(t).filter(([r,n])=>n!=null).map(([r,n])=>`${r}-${n}`).join("-");var B=(i=>(i.eur="eur",i.usd="usd",i.gbp="gbp",i.isk="isk",i))(B||{}),K=(s=>(s.password="password",s.resource="resource",s.jwt="jwt",s.apiKey="apiKey",s.bearer="bearer",s))(K||{}),M=(r=>(r.corporate="corporate",r.personal="personal",r))(M||{}),F=(r=>(r.read="read",r.write="write",r))(F||{}),L=(s=>(s.created="created",s.pending="pending",s.approved="approved",s.rejected="rejected",s.blocked="blocked",s))(L||{}),Q=(i=>(i.absent="absent",i.submitted="submitted",i.pending="pending",i.confirmed="confirmed",i))(Q||{}),W=(n=>(n.approved="approved",n.rejected="rejected",n.unknown="unknown",n))(W||{}),V=(s=>(s.requested="requested",s.approved="approved",s.pending="pending",s.rejected="rejected",s.closed="closed",s))(V||{}),G=(i=>(i.iban="iban",i.scan="scan",i.chain="chain",i.account="account",i))(G||{}),J=(n=>(n.passport="passport",n.nationalIdentityCard="nationalIdentityCard",n.drivingLicense="drivingLicense",n))(J||{}),H=(r=>(r.redeem="redeem",r.issue="issue",r))(H||{}),X=(i=>(i.placed="placed",i.pending="pending",i.processed="processed",i.rejected="rejected",i))(X||{});var P=t=>{if(t.toString()==="Invalid Date")throw t;let e=n=>n<10?"0"+n:n,r=n=>{if(n===0)return "Z";let i=n>0?"-":"+";return n=Math.abs(n),i+e(Math.floor(n/60))+":"+e(n%60)};return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+"T"+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())+r(t.getTimezoneOffset())},Z=t=>{switch(t){case "noble":case "noble-1":case "grand":case "grand-1":return true;default:return false}},Y=t=>{switch(t){case "ethereum":case "sepolia":case "polygon":case "amoy":case "gnosis":case "chiado":case "arbitrum":case "arbitrumsepolia":case "linea":case "lineasepolia":case "scroll":case "scrollsepolia":case "camino":case "columbus":return true;default:return false}},b=t=>{if(typeof t=="number")return O(t);if(Z(t))return t.split("-")[0];if(Y(t))return t;try{return O(parseInt(t))}catch{throw new Error(`Chain not supported: ${t}`)}},g=(t,e)=>b(T(e,t)),ee=(t,e,r,n)=>{let i=`${e?.toUpperCase()||"EUR"}`;return n?`Send ${i} ${t} to ${r} on ${b(n)} at ${P(new Date)}`:i==="EUR"?`Send ${i} ${t} to ${D(r)} at ${P(new Date)}`:`Send ${i} ${t} to ${r} at ${P(new Date)}`},te=({domain:t,address:e,appName:r,redirectUri:n,chainId:i,issuedAt:s=new Date().toISOString(),expiryAt:a=new Date(Date.now()+1e3*60*5).toISOString(),privacyPolicyUrl:o,termsOfServiceUrl:l})=>`${t} wants you to sign in with your Ethereum account:
|
|
2
2
|
${e}
|
|
3
3
|
|
|
4
4
|
Allow ${r} to access my data on Monerium
|
|
@@ -12,4 +12,4 @@ Expiration Time: ${a}
|
|
|
12
12
|
Resources:
|
|
13
13
|
- https://monerium.com/siwe
|
|
14
14
|
- ${o}
|
|
15
|
-
- ${l}`,C=t=>t&&Object.entries(t)?.length>0?Object.entries(t).filter(([e,r])=>r!==
|
|
15
|
+
- ${l}`,C=t=>t&&Object.entries(t)?.length>0?Object.entries(t).filter(([e,r])=>r!==void 0).map(([e,r])=>`${encodeURIComponent(e)}=${encodeURIComponent(r)}`).join("&"):"",O=t=>{switch(t){case 1:return "ethereum";case 11155111:return "sepolia";case 100:return "gnosis";case 10200:return "chiado";case 137:return "polygon";case 80002:return "amoy";case 42161:return "arbitrum";case 421614:return "arbitrumsepolia";case 59144:return "linea";case 59141:return "lineasepolia";case 534352:return "scroll";case 534351:return "scrollsepolia";case 501:return "columbus";case 500:return "camino";default:throw new Error(`Chain not supported: ${t}`)}},D=t=>{if(typeof t!="string"||!t?.length)return t;let e=t.replace(/\s/g,"");return t?.length>11?`${e.substring(0,4)}...${e.substring(e.length-4)}`:t},re=t=>typeof t!="string"||!t?.length?t:t?.length>11?`${t.substring(0,7)}...${t.substring(t.length-5)}`:t;var T=(t,e)=>{if(e==="sandbox")switch(t){case "ethereum":return "sepolia";case "polygon":return "amoy";case "gnosis":return "chiado";case "arbitrum":return "arbitrumsepolia";case "linea":return "lineasepolia";case "scroll":return "scrollsepolia";case "camino":return "columbus";case "noble":return "noble";default:return t}return t},p=(t,e)=>{if(e?.chain){let{chain:r,...n}=e;return {...n,chain:b(T(r,t))}}return e};var {STORAGE_CODE_VERIFIER:w,STORAGE_ACCESS_TOKEN:h,STORAGE_ACCESS_EXPIRY:m}=f,d=typeof window>"u",I=class{#e;#s;bearerProfile;#i=new Map;isAuthorized=!!this.bearerProfile;#r=()=>{};#n;state;constructor(e){if(!e){this.#e=x.environments.sandbox;return}if(typeof e=="string")this.#e=x.environments[e];else if(this.#r=N(e.debug??false),this.#e=x.environments[e.environment||"sandbox"],!d&&!e?.clientSecret){let{clientId:r,redirectUri:n}=e;this.#n={clientId:r,redirectUri:n};}else if(d&&e?.clientSecret){this.#r("Client credentials detected");let{clientId:r,clientSecret:n}=e;this.#n={clientId:r,clientSecret:n};}}async authorize(e){let r=S(),n=e?.address?{address:e?.address,signature:e?.signature,chain:e?.chain?g(this.#e.name,e?.chain):void 0}:{},i=C({client_id:this.#n?.clientId,redirect_uri:this.#n?.redirectUri,code_challenge:r,code_challenge_method:"S256",response_type:"code",state:e?.state,skip_create_account:e?.skipCreateAccount,skip_kyc:e?.skipKyc,email:e?.email,...n}),s=`${this.#e.api}/auth?${i}`;this.#r(`Auth flow URL: ${s}`),window.location.assign(s);}async siwe(e){let r=S(),n=C({client_id:this.#n?.clientId,redirect_uri:this.#n?.redirectUri,message:e.message,signature:e.signature,code_challenge:r,code_challenge_method:"S256",authentication_method:"siwe",state:e?.state}),i=`${this.#e.api}/auth?${n}`;this.#r(`Auth flow SIWE URL: ${i}`),window.location.assign(i);}async getAccess(e){let r=this.#n?.clientId;if(this.#n?.clientSecret){if(d)return await this.#c(this.#n),!!this?.bearerProfile;console.error("\x1B[31m%s\x1B[0m","Use client credentials only on the server where the secret is secure!");}let i=this.#n?.redirectUri;if(!r)throw new Error("Missing ClientId");if(d)throw new Error("This only works client side");let s=new URLSearchParams(window.location.search).get("error")||void 0,a=new URLSearchParams(window.location.search).get("error_description")||void 0;if(s||a)throw new Error(a);let o=new URLSearchParams(window.location.search).get("code")||void 0,l=new URLSearchParams(window.location.search).get("state")||void 0,c=window.localStorage.getItem(h),y=window.localStorage.getItem(m);if(o)return this.#r("Using auth code from auth flow to authorize"),await this.#a(r,i,o,l),this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(e)return this.#r("Using refresh token to authorize"),await this.#d(r,e),this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile;if(c&&y){let U=new Date;if(parseInt(y)<U.getTime())throw window.localStorage.removeItem(h),window.localStorage.removeItem(m),this.isAuthorized=false,this.bearerProfile=void 0,new Error("Access token has expired");this.#r("Access token should still be valid, checking if it is authorized...");try{return this.#s=`Bearer ${c}`,this.isAuthorized=!0,await this.getTokens(),this.#r("Authorized"),!0}catch{throw this.#r("Access token is invalid."),window.localStorage.removeItem(h),window.localStorage.removeItem(m),this.isAuthorized=false,this.bearerProfile=void 0,new Error("Access token is invalid.")}}return this.#r(this.bearerProfile?"Authorized":"Not authorized"),!!this.bearerProfile}async#o(e){let r;if(R(e))r={...e,grant_type:"authorization_code"};else if($(e))r={...e,grant_type:"refresh_token"};else if(v(e))r={...e,grant_type:"client_credentials"};else throw new Error("Authorization grant type could not be detected.");return await this.#t("post","auth/token",r,true).then(n=>{if(this.bearerProfile=n,this.isAuthorized=!!n,this.#s=`Bearer ${n?.access_token}`,!d){let s=new Date().getTime()+n?.expires_in*1e3;window.localStorage.setItem(h,n?.access_token||""),window.localStorage.setItem(m,s?.toString());}}).catch(n=>{throw d||(localStorage.removeItem(w),localStorage.removeItem(h),localStorage.removeItem(m),k()),new Error(n?.message)}),R(e)&&k(),this.bearerProfile}getAuthContext(){return this.#t("get","auth/context")}getProfile(e){return this.#t("get",`profiles/${e}`)}getProfiles(e){return this.#t("get",`profiles${u(e)}`)}getAddress(e){return this.#t("get",`addresses/${e}`)}getAddresses(e){e=p(this.#e.name,e);let r=e?C(e):void 0,n=r?`addresses?${r}`:"addresses";return this.#t("get",n)}getBalances(e,r,n){let i=Array.isArray(n)?n.map(a=>`currency=${a}`).join("&"):n?`currency=${n}`:"",s=g(this.#e.name,r);return this.#t("get",`balances/${s}/${e}${i?`?${i}`:""}`)}getIban(e){return this.#t("get",`ibans/${encodeURI(e)}`)}getIbans(e){let{profile:r,chain:n}=e||{},i=u({profile:r,chain:n?g(this.#e.name,n):""});return this.#t("get",`ibans${i}`)}getOrders(e){return this.#t("get",`orders${u(e)}`)}getOrder(e){return this.#t("get",`orders/${e}`)}getTokens(){return this.#t("get","tokens")}getSignatures(e){let r=e?p(this.#e.name,e):void 0;return this.#t("get",`signatures${u(r)}`)}linkAddress(e){return e=p(this.#e.name,e),this.#t("post","addresses",JSON.stringify(e))}placeOrder(e){let r={kind:"redeem",...p(this.#e.name,e),counterpart:{...e.counterpart,identifier:p(this.#e.name,e.counterpart.identifier)}};return this.#t("post","orders",JSON.stringify(r))}moveIban(e,{address:r,chain:n}){return this.#t("patch",`ibans/${e}`,JSON.stringify({address:r,chain:g(this.#e.name,n)}))}requestIban({address:e,chain:r,emailNotifications:n=true}){return this.#t("post","ibans",JSON.stringify({address:e,chain:g(this.#e.name,r),emailNotifications:n}))}submitProfileDetails(e,r){return this.#t("put",`profiles/${e}/details`,JSON.stringify(r))}uploadSupportingDocument(e){let r=new FormData;return r.append("file",e),_(`${this.#e.api}/files`,"post",r,{Authorization:this.#s||""})}async#t(e,r,n,i){let s={Authorization:this.#s||"",Accept:"application/vnd.monerium.api-v2+json","Content-Type":`application/${i?"x-www-form-urlencoded":"json"}`};return _(`${this.#e.api}/${r}`,e.toUpperCase(),i?C(n):n,s)}#a=async(e,r,n,i)=>{let s=localStorage.getItem(w)||"";if(!s)throw new Error("Code verifier not found");return this.#r("Use code verifier to authorize"),this.state=i,localStorage.removeItem(w),await this.#o({code:n,redirect_uri:r,client_id:e,code_verifier:s})};#c=async({clientId:e,clientSecret:r})=>await this.#o({client_id:e,client_secret:r});#d=async(e,r)=>await this.#o({refresh_token:r,client_id:e});subscribeOrderNotifications({filter:e,onMessage:r,onError:n}={}){if(!this.bearerProfile?.access_token)return;let{profile:i,state:s}=e||{},a=u({access_token:this.bearerProfile?.access_token,profile:i,state:s}),o,l=E({profile:i,state:s});if(this.#i?.has(l))o=this.#i.get(l);else {let c=`${this.#e.wss}/orders${a}`;o=new WebSocket(c),this.#i?.set(l,o);}return o.onopen=()=>{console.log("Connected to WebSocket server");},o.onmessage=c=>{let y=JSON.parse(c.data);r&&r(y);},o.onclose=()=>{console.log("WebSocket connection closed"),this.#i?.delete(a);},o.onerror=c=>{n&&n(c),console.error("WebSocket error:",c);},o}unsubscribeOrderNotifications(e){if(e){let r=E({profile:e?.profile,state:e?.state}),n=this.#i?.get(r);n&&(n.close(),this.#i?.delete(r));}else this.#i?.forEach(r=>{r?.close();}),this.#i?.clear(),this.#i=void 0;}async disconnect(){d||localStorage.removeItem(w),this.unsubscribeOrderNotifications(),this.#s=void 0,this.bearerProfile=void 0;}async revokeAccess(){d||(localStorage.removeItem(h),localStorage.removeItem(m)),this.disconnect();}getEnvironment=()=>this.#e};var De=I;export{V as AccountState,B as Currency,J as IdDocumentKind,W as KYCOutcome,Q as KYCState,K as Method,I as MoneriumClient,H as OrderKind,X as OrderState,G as PaymentStandard,F as Permission,L as ProfileState,M as ProfileType,f as constants,De as default,O as getChain,b as parseChain,ee as placeOrderMessage,P as rfc3339,re as shortenAddress,D as shortenIban,te as siweMessage};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monerium/sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.10",
|
|
4
4
|
"description": "Essential tools to interact with the Monerium API, an electronic money issuer.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
"@types/crypto-js": "^4.2.2",
|
|
34
34
|
"jest-fetch-mock": "^3.0.3",
|
|
35
35
|
"jest-localstorage-mock": "^2.4.26",
|
|
36
|
-
"timezone-mock": "^1.3.6"
|
|
37
|
-
"typescript": "5.7.3"
|
|
36
|
+
"timezone-mock": "^1.3.6"
|
|
38
37
|
},
|
|
39
38
|
"engines": {
|
|
40
39
|
"node": ">= 16.15"
|