@arcblock/event-hub 1.18.74 → 1.18.76

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/lib/client.js +20 -5
  2. package/package.json +5 -5
package/lib/client.js CHANGED
@@ -3,7 +3,9 @@ const { EventEmitter } = require('events');
3
3
  const axon = require('axon');
4
4
  const roundrobin = require('axon/lib/plugins/round-robin');
5
5
  const queue = require('axon/lib/plugins/queue');
6
- const { fromSecretKey } = require('@ocap/wallet');
6
+ const { fromSecretKey, WalletType } = require('@ocap/wallet');
7
+ const { DidType, isEthereumType } = require('@arcblock/did');
8
+
7
9
  const JWT = require('@arcblock/jwt');
8
10
  const { toTypeInfo } = require('@arcblock/did');
9
11
 
@@ -15,6 +17,18 @@ const checkEvent = (event) => {
15
17
  }
16
18
  };
17
19
 
20
+ const getWallet = (appSk, type) => {
21
+ let t = type;
22
+ let sk = appSk;
23
+
24
+ if (isEthereumType(DidType(type))) {
25
+ sk = appSk.slice(0, 66);
26
+ t = WalletType(type);
27
+ }
28
+
29
+ return fromSecretKey(sk, t);
30
+ };
31
+
18
32
  const defaultOpts = {
19
33
  port: undefined,
20
34
  hostname: '0.0.0.0',
@@ -28,12 +42,13 @@ class Socket extends axon.SubEmitterSocket {
28
42
  constructor(opts) {
29
43
  super();
30
44
 
45
+ const wallet = getWallet(opts.sk, toTypeInfo(opts.did));
46
+
31
47
  this.sock.use((sock) => {
32
48
  sock.on('connect', () => {
33
- const { did, pk, sk } = opts;
34
49
  sock.send(EVENT_AUTH, {
35
- pk,
36
- token: JWT.sign(did, sk),
50
+ pk: wallet.publicKey,
51
+ token: JWT.sign(wallet.address, wallet.secretKey),
37
52
  });
38
53
 
39
54
  sock.on(EVENT_AUTH_FAIL, ({ msg } = {}) => {
@@ -61,7 +76,7 @@ class Client extends EventEmitter {
61
76
  throw new Error('did, sk should not be empty');
62
77
  }
63
78
 
64
- const wallet = fromSecretKey(opts.sk, toTypeInfo(opts.did));
79
+ const wallet = getWallet(opts.sk, toTypeInfo(opts.did));
65
80
 
66
81
  if (wallet.address !== opts.did) {
67
82
  throw new Error('did, sk does not match');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.74",
6
+ "version": "1.18.76",
7
7
  "description": "A nodejs module for local and remote Inter Process Event",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -23,14 +23,14 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@arcblock/did": "1.18.74",
27
- "@arcblock/jwt": "1.18.74",
28
- "@ocap/wallet": "1.18.74",
26
+ "@arcblock/did": "1.18.76",
27
+ "@arcblock/jwt": "1.18.76",
28
+ "@ocap/wallet": "1.18.76",
29
29
  "amp-message": "~0.1.2",
30
30
  "axon": "^2.0.3"
31
31
  },
32
32
  "devDependencies": {
33
33
  "jest": "^27.5.1"
34
34
  },
35
- "gitHead": "87ab9471b0de6669100b56138193ec1705a97fb2"
35
+ "gitHead": "5a69ad290c7b3e1c0b498e7f733a317ea400a578"
36
36
  }