Skip to content

Commit ca143a8

Browse files
authored
Merge pull request #119 from datapartyjs/topic-sender
Topic sender
2 parents 5e925d4 + 332caef commit ca143a8

9 files changed

Lines changed: 45 additions & 20 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"express-ipfilter": "^1.3.2",
8686
"express-list-routes": "^1.1.9",
8787
"git-repo-info": "^2.1.1",
88-
"joi": "^17.9.1",
88+
"joi": "^17.13.3",
8989
"joi-objectid": "^4.0.2",
9090
"jshashes": "^1.0.8",
9191
"jsonpath-plus": "^0.20.1",

src/comms/host/host-protocol-scheme.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ const OP_HEADER = Joi.object().keys({
1515
).required()
1616
})
1717

18+
const validateUint8Array = (value, helpers)=>{
19+
if(value instanceof Uint8Array){
20+
return value
21+
}
22+
23+
throw new Error('expected Uint8Arry but got ['+typeof value+'] instead')
24+
}
1825

1926
const AUTH_OP = Joi.object().keys({
2027
id: ID_SCHEME.required(),
@@ -37,7 +44,8 @@ const AUTH_OP = Joi.object().keys({
3744
seed: Joi.allow(null)
3845
}).required(),
3946
pqCipherText: Joi.string().required(),
40-
streamNonce: Joi.string().required()
47+
streamNonce: Joi.any().custom(validateUint8Array, 'Uint8Array validation').required(),
48+
mode: Joi.string().required()
4149
}).required(),
4250
signature: Joi.object().keys({
4351
timestamp: Joi.number().required(),

src/comms/isocket-comms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ISocketComms extends EventEmitter {
169169
async send(input){
170170
debug('send - ', typeof input, input)
171171

172-
if(typeof input != 'object'){
172+
if(typeof input == 'string'){
173173
input = JSON.parse(input)
174174
}
175175

src/comms/op/auth-op.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const debug = require('debug')('dataparty.op.auth-op')
22
const SocketOp = require('./socket-op')
33

4-
const {Routines} = require('@dataparty/crypto')
4+
const {Routines, AESStream} = require('@dataparty/crypto')
55

66

77
class AuthOp extends SocketOp {
@@ -14,9 +14,9 @@ class AuthOp extends SocketOp {
1414

1515
async run(){
1616
const actor = this.socket.party.privateIdentity
17-
const aesStreamOffer = await actor.createStream( this.socket.remoteIdentity )
18-
19-
this.stream = aesStreamOffer.stream
17+
this.stream = await AESStream.createStream( actor, this.socket.remoteIdentity, true, 'random' )
18+
const aesStreamOffer = this.stream.offer
19+
2020

2121
const offer = {
2222
sender: {
@@ -28,7 +28,8 @@ class AuthOp extends SocketOp {
2828
}
2929
},
3030
pqCipherText: aesStreamOffer.pqCipherText,
31-
streamNonce: aesStreamOffer.streamNonce
31+
streamNonce: aesStreamOffer.streamNonce,
32+
mode: aesStreamOffer.mode
3233
}
3334

3435
const offerBSON = Routines.BSON.serializeBSONWithoutOptimiser( offer )

src/comms/peer-comms.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
const {Routines, Identity} = require('@dataparty/crypto')
2+
const {Routines, Identity, AESStream} = require('@dataparty/crypto')
33
const debug = require('debug')('dataparty.comms.peercomms')
44
const uuidv4 = require('uuid/v4')
55
const HttpMocks = require('node-mocks-http')
@@ -231,8 +231,8 @@ class PeerComms extends ISocketComms {
231231
this.close()
232232
}
233233

234-
async close(){
235-
debug('close', this.uuid)
234+
async close(event){
235+
debug('close', this.uuid, event)
236236

237237
if(this.party.topics){
238238
await this.party.topics.destroyNode(this)
@@ -369,7 +369,8 @@ class PeerComms extends ISocketComms {
369369
const offer = {
370370
sender: new Identity(op.input.offer.sender),
371371
pqCipherText: op.input.offer.pqCipherText,
372-
streamNonce: op.input.offer.streamNonce
372+
streamNonce: op.input.offer.streamNonce,
373+
mode: op.input.offer.mode
373374
}
374375

375376
const signature = {
@@ -419,9 +420,16 @@ class PeerComms extends ISocketComms {
419420
}
420421
}
421422

423+
debug('clienr auth op offer -', offer)
422424
debug('ALLOW - allowing client - ', this.remoteIdentity)
423425

424-
this.aesStream = await this.party.privateIdentity.recoverStream(offer, true)
426+
this.aesStream = await AESStream.recoverStream(
427+
this.party.privateIdentity,
428+
offer,
429+
true
430+
)
431+
432+
debug('aes-stream', this.aesStream)
425433

426434
clearTimeout(this._host_auth_timeout)
427435
this._host_auth_timeout = null

src/comms/websocket-shim.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class WebsocketShim extends EventEmitter {
1818
setTimeout(()=>{this.emit('connect')}, 1)
1919
}
2020

21-
this.conn.onclose = () => {
22-
this.emit('close')
21+
this.conn.onclose = (event) => {
22+
debug('onclose', event)
23+
this.emit('close', event)
2324
}
2425

2526
this.conn.onerror = (err) => {

src/index-browser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
var Buffer = require('buffer/').Buffer
2+
3+
if(!window.Buffer){
4+
window.Buffer = Buffer
5+
}
6+
17
const Comms = require('./comms')
28
const Party = require('./party/index-browser')
39
const Topics = require('./topics')
@@ -26,4 +32,5 @@ let lib = {
2632

2733

2834
module.exports = lib
29-
window.Dataparty = lib
35+
window.Dataparty = lib
36+

src/service/endpoints/service-identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = class ServiceIdentity extends IEndpoint {
2727
id: Joi.string(),
2828
key: {
2929
type: Joi.alternatives().try(
30-
Joi.string().valid('nacl,nacl,ml_kem768,ml_dsa65,slh_dsa_sha2_128f')
30+
Joi.string().valid('nacl,nacl,ml_kem1024,ml_dsa65,slh_dsa_sha2_128f')
3131
),
3232
hash: Joi.string(),
3333
public: Joi.object().keys({

src/topics/peer-node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class PeerNode {
2929
msg: data
3030
})*/
3131

32-
await this.peer.send(JSON.stringify({
32+
await this.peer.send({
3333
op: 'publish',
3434
id: 'publish:'+this.peer.opId,
3535
topic: topic.path,
36-
sender: { uuid: this.peer.uuid, identity: this.peer.remoteIdentity },
36+
sender: sender ? { uuid: sender.uuid, identity: sender.peer.remoteIdentity } : {system: true},
3737
msg: data
38-
}))
38+
})
3939

4040
}
4141
}

0 commit comments

Comments
 (0)