From bf33a2de268cf07b06faa04283ec066573c37ffc Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Tue, 10 Dec 2019 13:27:45 +0200 Subject: [PATCH] fix: Renaming to sender and receiver --- packages/daf-core/src/__tests__/message.test.ts | 12 ++++++------ packages/daf-core/src/message.ts | 11 ++--------- packages/daf-data-store/src/data-store.ts | 6 +++--- .../src/message-validator.ts | 4 ++-- packages/daf-w3c/src/message-validator.ts | 8 ++++---- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/daf-core/src/__tests__/message.test.ts b/packages/daf-core/src/__tests__/message.test.ts index 1fb41ac39..f0e9835e9 100644 --- a/packages/daf-core/src/__tests__/message.test.ts +++ b/packages/daf-core/src/__tests__/message.test.ts @@ -7,8 +7,8 @@ it('empty message should not be valid', () => { const msg = new Message({ raw: '', meta: { type: '' } }) expect(msg.type).toEqual(null) expect(msg.threadId).toEqual(null) - expect(msg.from).toEqual(null) - expect(msg.to).toEqual(null) + expect(msg.sender).toEqual(null) + expect(msg.receiver).toEqual(null) expect(msg.isValid()).toEqual(false) }) @@ -23,11 +23,11 @@ it('valid message should be valid', () => { msg.threadId = '456' expect(msg.threadId).toEqual('456') - msg.from = 'did:example:abc' - expect(msg.from).toEqual('did:example:abc') + msg.sender = 'did:example:abc' + expect(msg.sender).toEqual('did:example:abc') - msg.to = 'did:example:xyz' - expect(msg.to).toEqual('did:example:xyz') + msg.receiver = 'did:example:xyz' + expect(msg.receiver).toEqual('did:example:xyz') expect(msg.isValid()).toEqual(true) }) diff --git a/packages/daf-core/src/message.ts b/packages/daf-core/src/message.ts index bb1880f80..8f128a3fb 100644 --- a/packages/daf-core/src/message.ts +++ b/packages/daf-core/src/message.ts @@ -18,8 +18,8 @@ export class Message { private _id: string | null = null public type: string | null = null public threadId: string | null = null - public from: string | null = null - public to: string | null = null + public sender: string | null = null + public receiver: string | null = null public timestamp: number | null = null public vc?: any @@ -71,17 +71,10 @@ export class Message { } isValid() { - if (this.from === null) { - return false - } if (this.type === null || this.type === '') { debug('Missing `type` in %o', this) return false } - if (this.from === null || this.from === '') { - debug('Missing `from` in %o', this) - return false - } if (!this.raw || this.raw === null || this.raw === '') { debug('Missing `raw` in %o', this) return false diff --git a/packages/daf-data-store/src/data-store.ts b/packages/daf-data-store/src/data-store.ts index 9c7fa5216..d3bf7d25d 100644 --- a/packages/daf-data-store/src/data-store.ts +++ b/packages/daf-data-store/src/data-store.ts @@ -293,8 +293,8 @@ export class DataStore { const query = sql .insert('messages', { id: messageId, - sender: message.from, - receiver: message.to, + sender: message.sender, + receiver: message.receiver, timestamp: message.timestamp, type: message.type, thread_id: message.threadId, @@ -309,7 +309,7 @@ export class DataStore { await this.saveVerifiableCredentials(message) } - return { hash: message.id, iss: { did: message.from } } + return { hash: message.id, iss: { did: message.sender } } } private async updateMetaData(message: Message) { diff --git a/packages/daf-selective-disclosure/src/message-validator.ts b/packages/daf-selective-disclosure/src/message-validator.ts index 28b67c722..b53616542 100644 --- a/packages/daf-selective-disclosure/src/message-validator.ts +++ b/packages/daf-selective-disclosure/src/message-validator.ts @@ -15,8 +15,8 @@ export class MessageValidator extends AbstractMessageValidator { debug('JWT type is', MessageTypes.sdr) message.type = MessageTypes.sdr - message.from = message.data.iss - message.to = message.data.sub + message.sender = message.data.iss + message.receiver = message.data.sub message.threadId = message.data.tag message.timestamp = message.data.nbf || message.data.iat return message diff --git a/packages/daf-w3c/src/message-validator.ts b/packages/daf-w3c/src/message-validator.ts index 55a1158c4..46676c856 100644 --- a/packages/daf-w3c/src/message-validator.ts +++ b/packages/daf-w3c/src/message-validator.ts @@ -31,8 +31,8 @@ export class MessageValidator extends AbstractMessageValidator { ) message.type = MessageTypes.vp - message.from = message.data.iss - message.to = message.data.aud + message.sender = message.data.iss + message.receiver = message.data.aud message.threadId = message.data.tag message.timestamp = message.data.nbf || message.data.iat message.vc = vc @@ -45,8 +45,8 @@ export class MessageValidator extends AbstractMessageValidator { debug('JWT is', MessageTypes.vc) message.type = MessageTypes.vc - message.from = message.data.iss - message.to = message.data.sub + message.sender = message.data.iss + message.receiver = message.data.sub message.threadId = message.data.tag message.timestamp = message.data.nbf || message.data.iat message.vc = [{ payload: message.data, jwt: message.raw }]