mezon-sdk 2.8.12 → 2.8.14

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.
Files changed (68) hide show
  1. package/README.md +96 -23
  2. package/dist/cjs/api/api.d.ts +263 -67
  3. package/dist/cjs/api/api.js +528 -84
  4. package/dist/cjs/api/api.js.map +1 -1
  5. package/dist/cjs/index.d.ts +2 -0
  6. package/dist/cjs/index.js +2 -0
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/interfaces/client.d.ts +56 -3
  9. package/dist/cjs/interfaces/client.js +1 -0
  10. package/dist/cjs/interfaces/client.js.map +1 -1
  11. package/dist/cjs/mezon-client/client/MezonClient.d.ts +11 -3
  12. package/dist/cjs/mezon-client/client/MezonClient.js +63 -5
  13. package/dist/cjs/mezon-client/client/MezonClient.js.map +1 -1
  14. package/dist/cjs/mezon-client/structures/ButtonBuilder.d.ts +6 -0
  15. package/dist/cjs/mezon-client/structures/ButtonBuilder.js +22 -0
  16. package/dist/cjs/mezon-client/structures/ButtonBuilder.js.map +1 -0
  17. package/dist/cjs/mezon-client/structures/Clan.d.ts +4 -1
  18. package/dist/cjs/mezon-client/structures/Clan.js +12 -1
  19. package/dist/cjs/mezon-client/structures/Clan.js.map +1 -1
  20. package/dist/cjs/mezon-client/structures/InteractiveMessage.d.ts +16 -0
  21. package/dist/cjs/mezon-client/structures/InteractiveMessage.js +120 -0
  22. package/dist/cjs/mezon-client/structures/InteractiveMessage.js.map +1 -0
  23. package/dist/cjs/mezon-client/structures/TextChannel.js +2 -1
  24. package/dist/cjs/mezon-client/structures/TextChannel.js.map +1 -1
  25. package/dist/cjs/mezon-client/structures/User.d.ts +6 -2
  26. package/dist/cjs/mezon-client/structures/User.js +46 -8
  27. package/dist/cjs/mezon-client/structures/User.js.map +1 -1
  28. package/dist/cjs/mezon-client/utils/helper.d.ts +1 -0
  29. package/dist/cjs/mezon-client/utils/helper.js +29 -0
  30. package/dist/cjs/mezon-client/utils/helper.js.map +1 -0
  31. package/dist/cjs/rtapi/realtime.d.ts +898 -635
  32. package/dist/cjs/rtapi/realtime.js +278 -5
  33. package/dist/cjs/rtapi/realtime.js.map +1 -1
  34. package/dist/esm/api/api.d.ts +263 -67
  35. package/dist/esm/api/api.js +518 -78
  36. package/dist/esm/api/api.js.map +1 -1
  37. package/dist/esm/index.d.ts +2 -0
  38. package/dist/esm/index.js +2 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/interfaces/client.d.ts +56 -3
  41. package/dist/esm/interfaces/client.js +1 -0
  42. package/dist/esm/interfaces/client.js.map +1 -1
  43. package/dist/esm/mezon-client/client/MezonClient.d.ts +11 -3
  44. package/dist/esm/mezon-client/client/MezonClient.js +67 -5
  45. package/dist/esm/mezon-client/client/MezonClient.js.map +1 -1
  46. package/dist/esm/mezon-client/structures/ButtonBuilder.d.ts +6 -0
  47. package/dist/esm/mezon-client/structures/ButtonBuilder.js +16 -0
  48. package/dist/esm/mezon-client/structures/ButtonBuilder.js.map +1 -0
  49. package/dist/esm/mezon-client/structures/Clan.d.ts +4 -1
  50. package/dist/esm/mezon-client/structures/Clan.js +14 -1
  51. package/dist/esm/mezon-client/structures/Clan.js.map +1 -1
  52. package/dist/esm/mezon-client/structures/InteractiveMessage.d.ts +16 -0
  53. package/dist/esm/mezon-client/structures/InteractiveMessage.js +116 -0
  54. package/dist/esm/mezon-client/structures/InteractiveMessage.js.map +1 -0
  55. package/dist/esm/mezon-client/structures/TextChannel.js +2 -1
  56. package/dist/esm/mezon-client/structures/TextChannel.js.map +1 -1
  57. package/dist/esm/mezon-client/structures/User.d.ts +6 -2
  58. package/dist/esm/mezon-client/structures/User.js +46 -7
  59. package/dist/esm/mezon-client/structures/User.js.map +1 -1
  60. package/dist/esm/mezon-client/utils/helper.d.ts +1 -0
  61. package/dist/esm/mezon-client/utils/helper.js +25 -0
  62. package/dist/esm/mezon-client/utils/helper.js.map +1 -0
  63. package/dist/esm/rtapi/realtime.d.ts +898 -635
  64. package/dist/esm/rtapi/realtime.js +270 -0
  65. package/dist/esm/rtapi/realtime.js.map +1 -1
  66. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +4 -3
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Mezon JavaScript Client
2
- ========================
1
+ # Mezon JavaScript Client
3
2
 
4
3
  > JavaScript client for Mezon server written in TypeScript. For browser and React Native projects.
5
4
 
@@ -13,18 +12,18 @@ You'll need access to an instance of the Mezon server before you can connect wit
13
12
 
14
13
  1. Import the client into your project. It's [available on NPM](https://www.npmjs/package/mezon-sdk).
15
14
 
16
- ```shell
17
- npm install mezon-sdk
18
- ```
15
+ ```shell
16
+ npm install mezon-sdk
17
+ ```
19
18
 
20
19
  You'll now see the code in the "node_modules" folder and package listed in your "package.json".
21
20
 
22
21
  2. Use the connection credentials to build a client object.
23
22
 
24
- ```js
25
- import {Client} from "mezon-sdk";
26
- const client = new Client("apiKey");
27
- ```
23
+ ```js
24
+ import { Client } from 'mezon-sdk';
25
+ const client = new Client('apiKey');
26
+ ```
28
27
 
29
28
  ## Usage
30
29
 
@@ -37,11 +36,13 @@ To authenticate with the Mezon server you must provide an identifier for the use
37
36
  ```js
38
37
  const appId = "<AppId>";
39
38
 
40
- client.authenticate(appId)
41
- .then(session => {
39
+ client
40
+ .authenticate(appId)
41
+ .then((session) => {
42
42
  _session = session;
43
43
  console.info("Authenticated:", session);
44
- }).catch(error => {
44
+ })
45
+ .catch((error) => {
45
46
  console.error("Error:", error);
46
47
  });
47
48
  ```
@@ -55,7 +56,10 @@ console.info(session.token); // raw JWT token
55
56
  console.info(session.refreshToken); // refresh token
56
57
  console.info("Session has expired?", session.isexpired(Date.now() / 1000));
57
58
  const expiresAt = session.expires_at;
58
- console.warn("Session will expire at:", new Date(expiresAt * 1000).toISOString());
59
+ console.warn(
60
+ "Session will expire at:",
61
+ new Date(expiresAt * 1000).toISOString()
62
+ );
59
63
  ```
60
64
 
61
65
  It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.
@@ -69,23 +73,20 @@ let session = satorijs.Session.restore(authtoken, refreshtoken);
69
73
 
70
74
  // Check whether a session is close to expiry.
71
75
 
72
- const unixTimeInFuture = Date.now() + 8.64e+7; // one day from now
76
+ const unixTimeInFuture = Date.now() + 8.64e7; // one day from now
73
77
 
74
78
  if (session.isexpired(unixTimeInFuture / 1000)) {
75
- try
76
- {
77
- session = await client.sessionRefresh(session);
78
- }
79
- catch (e)
80
- {
81
- console.info("Session can no longer be refreshed. Must reauthenticate!");
82
- }
79
+ try {
80
+ session = await client.sessionRefresh(session);
81
+ } catch (e) {
82
+ console.info("Session can no longer be refreshed. Must reauthenticate!");
83
+ }
83
84
  }
84
85
  ```
85
86
 
86
87
  ### Requests
87
88
 
88
- The client includes lots of builtin APIs for various featyures of the Mezon server. These can be accessed with the methods which return Promise objects.
89
+ The client includes lots of builtin APIs for various features of the Mezon server. These can be accessed with the methods which return Promise objects.
89
90
 
90
91
  Most requests are sent with a session object which authorizes the client.
91
92
 
@@ -94,6 +95,78 @@ const flags = await client.getFlags(session);
94
95
  console.info("Flags:", flags);
95
96
  ```
96
97
 
98
+ ### Token Transfers
99
+
100
+ The mezon-sdk supports secure token transfers using the **Mezon Money Network (MMN)** with zero-knowledge proofs for enhanced privacy and security.
101
+
102
+ #### Required Steps for Token Transfer
103
+
104
+ Before sending tokens, you must complete these steps to gather the required data:
105
+
106
+ **Step 1: Generate Ephemeral Key Pair**
107
+
108
+ ```js
109
+ const keyPair = await client.getEphemeralKeyPair();
110
+ // Returns: { publicKey: string, privateKey: string }
111
+ ```
112
+
113
+ **Step 2: Get Recipient Wallet Address**
114
+
115
+ ```js
116
+ const address = await client.getAddress(senderId);
117
+ // Returns: string (wallet address)
118
+ ```
119
+
120
+ **Step 3: Fetch Current Nonce**
121
+
122
+ ```js
123
+ const nonce = await client.getCurrentNonce(senderId, 'pending');
124
+ // Returns: number (transaction sequence)
125
+ ```
126
+
127
+ **Step 4: Generate Zero-Knowledge Proof**
128
+
129
+ ```js
130
+ const session = client.sessionManager.getSession();
131
+ const zkProofs = await client.getZkProofs({
132
+ user_id: senderId,
133
+ jwt: session.token,
134
+ address: address,
135
+ ephemeral_public_key: keyPair.publicKey,
136
+ });
137
+ // Returns: { zkProof: string, zkPub: string }
138
+ ```
139
+
140
+ **Step 5: Execute Token Transfer**
141
+
142
+ ```js
143
+ const tokenEvent = {
144
+ ...,
145
+ nonce: nonce + 1
146
+ };
147
+
148
+ const result = await client.sendToken(tokenEvent);
149
+ // Returns: { transactionId: string, status: string, ... }
150
+ ```
151
+
152
+ #### Setting Up the Client for Token Transfers
153
+
154
+ ```js
155
+ import { MezonClient } from 'mezon-sdk';
156
+
157
+ const client = new MezonClient(
158
+ 'token_id',
159
+ 'host',
160
+ 'port',
161
+ true,
162
+ "mmn-api",
163
+ "zk-api"
164
+ );
165
+
166
+ // Login to initialize session
167
+ await client.login();
168
+ ```
169
+
97
170
  ## Contribute
98
171
 
99
172
  The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested in enhancing the code please open an issue to discuss the changes or drop in and discuss it in the [community forum](https://forum.mezon.ai).