opportunity-service 0.0.606 → 0.0.607
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/OpportunityService.js +7 -2
- package/dist/OpportunityService.js.map +1 -1
- package/dist/modules/whisper/ChatHandler.js +78 -0
- package/dist/modules/whisper/ChatHandler.js.map +1 -0
- package/package.json +1 -1
- package/src/OpportunityService.ts +8 -1
- package/src/modules/whisper/ChatHandler.ts +78 -0
@@ -14,7 +14,7 @@ import { ethers } from "ethers";
|
|
14
14
|
import { startEventListeners } from "./events/start-event-listeners";
|
15
15
|
import opportunityAPI from './api/index';
|
16
16
|
import Web3 from 'web3';
|
17
|
-
import
|
17
|
+
import WhisperHandler from "./modules/whisper/ChatHandler";
|
18
18
|
class OpportunityService {
|
19
19
|
/**
|
20
20
|
* The Singleton's constructor should always be private to prevent direct
|
@@ -30,6 +30,7 @@ class OpportunityService {
|
|
30
30
|
this.storageProvider = null;
|
31
31
|
this.currentAccount = null;
|
32
32
|
this.ethNetwork = 'rinkeby';
|
33
|
+
this.whisperProvider = null;
|
33
34
|
this.storage = null;
|
34
35
|
this.api = opportunityAPI;
|
35
36
|
this.ethNetwork = 'rinkeby';
|
@@ -48,6 +49,7 @@ class OpportunityService {
|
|
48
49
|
}
|
49
50
|
assignDefaultProvider(provider) {
|
50
51
|
OpportunityService.defaultProvider = provider;
|
52
|
+
this.whisperProvider = new WhisperHandler(provider);
|
51
53
|
}
|
52
54
|
assignProvider(provider) {
|
53
55
|
this.ethersProvider = provider;
|
@@ -72,7 +74,7 @@ class OpportunityService {
|
|
72
74
|
default:
|
73
75
|
this.ethNetwork = 'rinkeby';
|
74
76
|
}
|
75
|
-
this.storageProvider = new OpportunityStorageProvider(dbAddress)
|
77
|
+
//this.storageProvider = new OpportunityStorageProvider(dbAddress)
|
76
78
|
}
|
77
79
|
getEthNetwork() {
|
78
80
|
return this.ethNetwork;
|
@@ -130,6 +132,9 @@ class OpportunityService {
|
|
130
132
|
getSignersInterface() {
|
131
133
|
return this.ethersSigner;
|
132
134
|
}
|
135
|
+
getWhisperProvider() {
|
136
|
+
return this.whisperProvider;
|
137
|
+
}
|
133
138
|
}
|
134
139
|
OpportunityService.defaultProvider = new Web3('http://localhost:8545');
|
135
140
|
const opportunityService = OpportunityService.getInstance();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"OpportunityService.js","sourceRoot":"","sources":["../src/OpportunityService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA6B,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,uBAAuB,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,cAAc,MAAM,aAAa,CAAC;AAGzC,OAAO,IAAI,MAAM,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"OpportunityService.js","sourceRoot":"","sources":["../src/OpportunityService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA6B,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,uBAAuB,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,cAAc,MAAM,aAAa,CAAC;AAGzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,cAAc,MAAM,+BAA+B,CAAC;AAE3D,MAAM,kBAAkB;IAkBpB;;;OAGG;IACH;QArBQ,iBAAY,GAAG,uBAAuB,CAAC;QACvC,YAAO,GAAY,KAAK,CAAC;QACzB,YAAO,GAAY,KAAK,CAAC;QACzB,mBAAc,GAA+B,MAAM,CAAC,kBAAkB,CAA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C,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACT,OAAO,CAAC,GAAG,CAAC,qCAAqC,GAAG,GAAG,CAAC,CAAA;YACxD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC,CAAA;IACV,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,2BAA2B;QACvB,OAAO,kBAAkB,CAAC,eAAe,CAAC;IAC9C,CAAC;IAED,oBAAoB;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,mBAAmB;QACf,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,kBAAkB;QACd,OAAO,IAAI,CAAC,eAAe,CAAA;IAC/B,CAAC;;AAnIc,kCAAe,GAAG,IAAI,IAAI,CAAC,uBAAuB,CAAC,CAAA;AAsItE,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;AAC5D,eAAe,kBAAkB,CAAC"}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
import opportunityEventEmitter from "../../events/OpportunityEventEmitter";
|
11
|
+
const POW_TIME = 100;
|
12
|
+
const TTL = 20;
|
13
|
+
const POW_TARGET = 2;
|
14
|
+
class WhisperHandler {
|
15
|
+
constructor(web3) {
|
16
|
+
this.web3 = web3;
|
17
|
+
this.generateKeypair();
|
18
|
+
}
|
19
|
+
generateKeypair() {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
const keyPair = yield this.web3.shh.newKeyPair();
|
22
|
+
this.keypair = keyPair;
|
23
|
+
// Obtain public key
|
24
|
+
const pubKey = yield this.web3.shh.getPublicKey(keyPair);
|
25
|
+
this.pubKey = pubKey;
|
26
|
+
});
|
27
|
+
}
|
28
|
+
getWhisperPubKey() {
|
29
|
+
return this.pubKey;
|
30
|
+
}
|
31
|
+
sendPrivateMessage(toPubKey, msg, topic) {
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
33
|
+
// Send private message
|
34
|
+
this.web3.shh.post({
|
35
|
+
pubKey: toPubKey,
|
36
|
+
sig: this.keypair,
|
37
|
+
ttl: TTL,
|
38
|
+
topic,
|
39
|
+
payload: this.web3.utils.fromAscii(msg),
|
40
|
+
powTime: POW_TIME,
|
41
|
+
powTarget: POW_TARGET
|
42
|
+
});
|
43
|
+
});
|
44
|
+
}
|
45
|
+
subscribeToTopic(topic) {
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
// Subscribe to private messages
|
48
|
+
const subscribe = (topic) => __awaiter(this, void 0, void 0, function* () {
|
49
|
+
this.web3.shh.subscribe("messages", {
|
50
|
+
minPow: POW_TARGET,
|
51
|
+
privateKeyID: this.keypair,
|
52
|
+
topics: [topic]
|
53
|
+
}).on('data', (data) => {
|
54
|
+
console.log('Receieved data: ');
|
55
|
+
console.log(data);
|
56
|
+
console.log(this.web3.utils.toAscii(data.payload));
|
57
|
+
opportunityEventEmitter.emit('WHISPER_RECEIVED', data);
|
58
|
+
}).on('error', (err) => {
|
59
|
+
console.log('Couldnt decode message');
|
60
|
+
console.log(err);
|
61
|
+
});
|
62
|
+
});
|
63
|
+
const receivedWhisper = (data) => {
|
64
|
+
console.log(data);
|
65
|
+
};
|
66
|
+
yield subscribe(topic)
|
67
|
+
.then(() => {
|
68
|
+
opportunityEventEmitter.subscribeToEvent('WHISPER_RECEIVED', receivedWhisper);
|
69
|
+
})
|
70
|
+
.catch(error => {
|
71
|
+
console.log('Error trying to subscribe to topic');
|
72
|
+
console.log(error);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
export default WhisperHandler;
|
78
|
+
//# sourceMappingURL=ChatHandler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ChatHandler.js","sourceRoot":"","sources":["../../../src/modules/whisper/ChatHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAG3E,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,MAAM,cAAc;IAKhB,YAAY,IAAU;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,EAAE,CAAA;IAC1B,CAAC;IAEK,eAAe;;YACjB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;YACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YAEvB,oBAAoB;YACpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;KAAA;IAGD,gBAAgB;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAEK,kBAAkB,CAAC,QAAgB,EAAE,GAAW,EAAE,KAAa;;YACjE,uBAAuB;YACvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;gBACf,MAAM,EAAE,QAAQ;gBAChB,GAAG,EAAE,IAAI,CAAC,OAAO;gBACjB,GAAG,EAAE,GAAG;gBACR,KAAK;gBACL,OAA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CAAA;YACjF,CAAC,CAAC;iBACD,KAAK,CAAC,KAAK,CAAC,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAA;gBACjD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YACtB,CAAC,CAAC,CAAA;QACN,CAAC;KAAA;CACJ;AAED,eAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
@@ -14,6 +14,7 @@ import opportunityStorageProvider from "./modules/storage/OpportunityStorageProv
|
|
14
14
|
import Web3 from 'web3';
|
15
15
|
import OpportunityStorageProvider from "./modules/storage/OpportunityStorageProvider";
|
16
16
|
import { EthNetworkID } from "dvote-js";
|
17
|
+
import WhisperHandler from "./modules/whisper/ChatHandler";
|
17
18
|
|
18
19
|
class OpportunityService {
|
19
20
|
private eventEmitter = opportunityEventEmitter;
|
@@ -26,6 +27,7 @@ class OpportunityService {
|
|
26
27
|
private storageProvider = null;
|
27
28
|
private currentAccount = null;
|
28
29
|
private ethNetwork : EthNetworkID | string = 'rinkeby'
|
30
|
+
private whisperProvider = null;
|
29
31
|
public storage = null
|
30
32
|
|
31
33
|
private static instance: OpportunityService;
|
@@ -56,6 +58,7 @@ class OpportunityService {
|
|
56
58
|
|
57
59
|
assignDefaultProvider(provider : Web3) {
|
58
60
|
OpportunityService.defaultProvider = provider;
|
61
|
+
this.whisperProvider = new WhisperHandler(provider);
|
59
62
|
}
|
60
63
|
|
61
64
|
assignProvider(provider : any) {
|
@@ -86,7 +89,7 @@ class OpportunityService {
|
|
86
89
|
this.ethNetwork = 'rinkeby'
|
87
90
|
}
|
88
91
|
|
89
|
-
this.storageProvider = new OpportunityStorageProvider(dbAddress)
|
92
|
+
//this.storageProvider = new OpportunityStorageProvider(dbAddress)
|
90
93
|
}
|
91
94
|
|
92
95
|
public getEthNetwork(): EthNetworkID | string {
|
@@ -147,6 +150,10 @@ class OpportunityService {
|
|
147
150
|
getSignersInterface() : providers.JsonRpcSigner {
|
148
151
|
return this.ethersSigner;
|
149
152
|
}
|
153
|
+
|
154
|
+
getWhisperProvider() : any {
|
155
|
+
return this.whisperProvider
|
156
|
+
}
|
150
157
|
}
|
151
158
|
|
152
159
|
const opportunityService = OpportunityService.getInstance();
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import opportunityEventEmitter from "../../events/OpportunityEventEmitter";
|
2
|
+
import Web3 from "web3";
|
3
|
+
|
4
|
+
const POW_TIME = 100;
|
5
|
+
const TTL = 20;
|
6
|
+
const POW_TARGET = 2;
|
7
|
+
|
8
|
+
class WhisperHandler {
|
9
|
+
private web3;
|
10
|
+
private keypair;
|
11
|
+
private pubKey;
|
12
|
+
|
13
|
+
constructor(web3: Web3) {
|
14
|
+
this.web3 = web3;
|
15
|
+
this.generateKeypair()
|
16
|
+
}
|
17
|
+
|
18
|
+
async generateKeypair() {
|
19
|
+
const keyPair = await this.web3.shh.newKeyPair();
|
20
|
+
this.keypair = keyPair;
|
21
|
+
|
22
|
+
// Obtain public key
|
23
|
+
const pubKey = await this.web3.shh.getPublicKey(keyPair);
|
24
|
+
this.pubKey = pubKey;
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
getWhisperPubKey() {
|
29
|
+
return this.pubKey;
|
30
|
+
}
|
31
|
+
|
32
|
+
async sendPrivateMessage(toPubKey: string, msg: string, topic: string) {
|
33
|
+
// Send private message
|
34
|
+
this.web3.shh.post({
|
35
|
+
pubKey: toPubKey,
|
36
|
+
sig: this.keypair,
|
37
|
+
ttl: TTL,
|
38
|
+
topic,
|
39
|
+
payload: this.web3.utils.fromAscii(msg),
|
40
|
+
powTime: POW_TIME,
|
41
|
+
powTarget: POW_TARGET
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
45
|
+
async subscribeToTopic(topic: string) {
|
46
|
+
// Subscribe to private messages
|
47
|
+
const subscribe = async (topic: string) => {
|
48
|
+
this.web3.shh.subscribe("messages", {
|
49
|
+
minPow: POW_TARGET,
|
50
|
+
privateKeyID: this.keypair,
|
51
|
+
topics: [topic]
|
52
|
+
}).on('data', (data) => {
|
53
|
+
console.log('Receieved data: ')
|
54
|
+
console.log(data)
|
55
|
+
console.log(this.web3.utils.toAscii(data.payload))
|
56
|
+
opportunityEventEmitter.emit('WHISPER_RECEIVED', data)
|
57
|
+
}).on('error', (err) => {
|
58
|
+
console.log('Couldnt decode message')
|
59
|
+
console.log(err)
|
60
|
+
});
|
61
|
+
}
|
62
|
+
|
63
|
+
const receivedWhisper = (data) => {
|
64
|
+
console.log(data)
|
65
|
+
}
|
66
|
+
|
67
|
+
await subscribe(topic)
|
68
|
+
.then(() => {
|
69
|
+
opportunityEventEmitter.subscribeToEvent('WHISPER_RECEIVED', receivedWhisper)
|
70
|
+
})
|
71
|
+
.catch(error => {
|
72
|
+
console.log('Error trying to subscribe to topic')
|
73
|
+
console.log(error)
|
74
|
+
})
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
export default WhisperHandler;
|