mrpc-js 1.0.0 → 2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/mrpc.js +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrpc-js",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Zero-dependency mRPC request encoder and HMAC-SHA256 response validator",
5
5
  "keywords": [
6
6
  "mrpc",
package/src/mrpc.js CHANGED
@@ -11,6 +11,9 @@
11
11
  export async function create_mRPC(user_id, token, version, payload) {
12
12
  const seed = random_hex();
13
13
  const tag = random_hex();
14
+ const timestamp = Date.now();
15
+
16
+ const envelope = user_id + version + tag + seed + timestamp;
14
17
 
15
18
  const json_out = {
16
19
  user_id: user_id,
@@ -18,8 +21,8 @@ export async function create_mRPC(user_id, token, version, payload) {
18
21
  request_tag: tag,
19
22
  seed: seed,
20
23
  data: payload,
21
- timestamp: Date.now(),
22
- auth: await auth_hash(seed, token, payload)
24
+ timestamp: timestamp,
25
+ auth: await auth_hash(envelope, token, payload)
23
26
  };
24
27
 
25
28
  return json_out;
@@ -71,7 +74,9 @@ export async function validate_mRPC_response(response, tag, token, window= 300)
71
74
  return false;
72
75
  }
73
76
 
74
- const hash = await auth_hash(response.seed, token, response.data);
77
+ const envelope = response.action + response.tag + response.seed + response.timestamp;
78
+
79
+ const hash = await auth_hash(envelope, token, response.data);
75
80
 
76
81
  return hash === response.auth;
77
82
  }