Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

daf-core

Package Overview
Dependencies
Maintainers
8
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daf-core - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

build/message.d.ts

6

build/core.d.ts

@@ -8,4 +8,5 @@ /// <reference types="node" />

import { ActionHandler } from './action-handler';
import { ValidatedMessage, RawMessage, Action } from './types';
import { Action } from './types';
import { EncryptionKeyManager } from './encryption-manager';
import { Message } from './message';
export declare const EventTypes: {

@@ -36,6 +37,5 @@ validatedMessage: string;

syncServices(lastMessageTimestamps: LastMessageTimestamp[]): Promise<void>;
onRawMessage(rawMessage: RawMessage): Promise<ValidatedMessage | null>;
private isValidatedMessage;
validateMessage(message: Message): Promise<Message>;
handleAction(action: Action): Promise<any>;
}
export {};

@@ -15,13 +15,2 @@ "use strict";

})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -70,3 +59,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var service_manager_1 = require("./service-manager");
var blakejs_1 = __importDefault(require("blakejs"));
var debug_1 = __importDefault(require("debug"));

@@ -89,3 +77,3 @@ var debug = debug_1.default('core');

serviceControllersWithConfig: config.serviceControllersWithConfig,
onRawMessage: _this.onRawMessage.bind(_this),
validateMessage: _this.validateMessage.bind(_this),
didResolver: _this.didResolver,

@@ -128,17 +116,16 @@ });

};
Core.prototype.onRawMessage = function (rawMessage) {
Core.prototype.validateMessage = function (message) {
return __awaiter(this, void 0, void 0, function () {
var preValidatedMessage, validatedMessage, error_1;
var validatedMessage, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
debug('Raw message %O', rawMessage);
debug('Raw message %O', message);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.messageValidator.validate(rawMessage, this)];
return [4 /*yield*/, this.messageValidator.validate(message, this)];
case 2:
preValidatedMessage = _a.sent();
if (preValidatedMessage !== null && this.isValidatedMessage(preValidatedMessage)) {
validatedMessage = __assign(__assign({}, preValidatedMessage), { hash: blakejs_1.default.blake2bHex(preValidatedMessage.raw) });
validatedMessage = _a.sent();
if (validatedMessage.isValid()) {
this.emit(exports.EventTypes.validatedMessage, validatedMessage);

@@ -150,5 +137,5 @@ return [2 /*return*/, validatedMessage];

error_1 = _a.sent();
this.emit(exports.EventTypes.error, error_1, rawMessage);
return [3 /*break*/, 4];
case 4: return [2 /*return*/, null];
this.emit(exports.EventTypes.error, error_1, message);
return [2 /*return*/, Promise.reject(error_1)];
case 4: return [2 /*return*/, Promise.reject('Unsupported message type')];
}

@@ -158,20 +145,2 @@ });

};
Core.prototype.isValidatedMessage = function (message) {
if (message === null) {
return false;
}
if (!message.type || message.type == '') {
debug('Missing `type` in %o', message);
return false;
}
if (!message.issuer || message.issuer == '') {
debug('Missing `issuer` in %o', message);
return false;
}
if (!message.raw || message.raw == '') {
debug('Missing `raw` in %o', message);
return false;
}
return true;
};
Core.prototype.handleAction = function (action) {

@@ -178,0 +147,0 @@ return __awaiter(this, void 0, void 0, function () {

@@ -1,1 +0,1 @@

export declare const baseTypeDefs = "\n type Query \n\n type Mutation \n \n type Identity {\n did: ID!\n }\n \n type Message {\n hash: ID!\n rowId: String!\n type: String!\n }\n \n";
export declare const baseTypeDefs = "\n type Query \n\n type Mutation \n \n type Identity {\n did: ID!\n }\n \n type Message {\n id: ID!\n threadId: String\n rowId: String!\n type: String!\n sender: Identity\n receiver: Identity\n raw: String!\n data: String\n timestamp: Int\n metaData: [MessageMetaData]\n thread: [Message]\n }\n\n type MessageMetaData {\n rowId: String!\n type: String!\n id: String\n data: String\n }\n \n";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.baseTypeDefs = "\n type Query \n\n type Mutation \n \n type Identity {\n did: ID!\n }\n \n type Message {\n hash: ID!\n rowId: String!\n type: String!\n }\n \n";
exports.baseTypeDefs = "\n type Query \n\n type Mutation \n \n type Identity {\n did: ID!\n }\n \n type Message {\n id: ID!\n threadId: String\n rowId: String!\n type: String!\n sender: Identity\n receiver: Identity\n raw: String!\n data: String\n timestamp: Int\n metaData: [MessageMetaData]\n thread: [Message]\n }\n\n type MessageMetaData {\n rowId: String!\n type: String!\n id: String\n data: String\n }\n \n";
//# sourceMappingURL=graphql-base-type-defs.js.map
import { Core } from './core';
import { Message } from './message';
interface Context {

@@ -11,3 +12,3 @@ core: Core;

sourceId?: string | undefined;
}, ctx: Context) => Promise<import("./types").ValidatedMessage | null>;
}, ctx: Context) => Promise<Message>;
};

@@ -14,0 +15,0 @@ };

@@ -39,12 +39,13 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var message_1 = require("./message");
var newMessage = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ctx.core.onRawMessage({
case 0: return [4 /*yield*/, ctx.core.validateMessage(new message_1.Message({
raw: args.raw,
meta: [{
sourceType: args.sourceType,
sourceId: args.sourceId
}]
})];
meta: {
type: args.sourceType,
id: args.sourceId,
},
}))];
case 1: return [2 /*return*/, _a.sent()];

@@ -51,0 +52,0 @@ }

@@ -6,2 +6,3 @@ export { Core, EventTypes, Resolver } from './core';

export { AbstractMessageValidator } from './message-validator';
export { Message } from './message';
export { ServiceController, ServiceControllerOptions, ServiceControllerWithConfig, ServiceInstanceId, } from './service-manager';

@@ -8,0 +9,0 @@ import * as Types from './types';

@@ -19,2 +19,4 @@ "use strict";

exports.AbstractMessageValidator = message_validator_1.AbstractMessageValidator;
var message_1 = require("./message");
exports.Message = message_1.Message;
var service_manager_1 = require("./service-manager");

@@ -21,0 +23,0 @@ exports.ServiceController = service_manager_1.ServiceController;

@@ -1,6 +0,6 @@

import { RawMessage, PreValidatedMessage } from './types';
import { Message } from './message';
import { Core } from './core';
export interface MessageValidator {
setNext(messageValidator: MessageValidator): MessageValidator;
validate: (rawMessage: RawMessage, core: Core) => Promise<PreValidatedMessage | null>;
validate: (message: Message, core: Core) => Promise<Message>;
}

@@ -10,3 +10,3 @@ export declare abstract class AbstractMessageValidator implements MessageValidator {

setNext(messageValidator: MessageValidator): MessageValidator;
validate(rawMessage: RawMessage, core: Core): Promise<PreValidatedMessage | null>;
validate(message: Message, core: Core): Promise<Message>;
}

@@ -46,9 +46,9 @@ "use strict";

};
AbstractMessageValidator.prototype.validate = function (rawMessage, core) {
AbstractMessageValidator.prototype.validate = function (message, core) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (this.nextMessageValidator) {
return [2 /*return*/, this.nextMessageValidator.validate(rawMessage, core)];
return [2 /*return*/, this.nextMessageValidator.validate(message, core)];
}
return [2 /*return*/, null];
return [2 /*return*/, Promise.reject('Unsupported message type')];
});

@@ -55,0 +55,0 @@ });

import { DIDDocument } from 'did-resolver';
import { Resolver } from './core';
import { Issuer } from './identity-manager';
import { RawMessage, ValidatedMessage } from './types';
import { Message } from './message';
export interface ServiceControllerOptions {

@@ -9,3 +9,3 @@ config: any;

didDoc: DIDDocument;
onRawMessage: (rawMessage: RawMessage) => Promise<ValidatedMessage | null>;
validateMessage: (message: Message) => Promise<Message>;
}

@@ -32,7 +32,7 @@ export interface ServiceInstanceId {

serviceControllersWithConfig: ServiceControllerWithConfig[];
onRawMessage: (rawMessage: RawMessage) => Promise<ValidatedMessage | null>;
validateMessage: (message: Message) => Promise<Message>;
}
export declare class ServiceManager {
private serviceControllersWithConfig;
private onRawMessage;
private validateMessage;
private serviceControllers;

@@ -39,0 +39,0 @@ private didResolver;

@@ -53,3 +53,3 @@ "use strict";

this.serviceControllersWithConfig = options.serviceControllersWithConfig;
this.onRawMessage = options.onRawMessage;
this.validateMessage = options.validateMessage;
this.serviceControllers = [];

@@ -82,3 +82,3 @@ this.didResolver = options.didResolver;

didDoc: didDoc,
onRawMessage: this.onRawMessage,
validateMessage: this.validateMessage,
}));

@@ -85,0 +85,0 @@ }

@@ -1,29 +0,4 @@

export interface ServiceMetaData {
sourceType?: string;
sourceId?: string;
data?: any;
}
export interface RawMessage {
raw: string;
meta?: ServiceMetaData[];
}
export interface PreValidatedMessage {
type: string;
issuer: string;
subject?: string;
time?: string;
tag?: string;
raw: string;
verified?: any;
custom?: any;
meta?: ServiceMetaData[];
}
export interface ValidatedMessage extends PreValidatedMessage {
hash: string;
}
export interface Action {
type: string;
parentMessage?: ValidatedMessage;
parentMessageHash?: string;
data: any;
}

@@ -6,2 +6,20 @@ # Change Log

# [0.10.0](https://github.com/uport-project/daf/compare/v0.9.0...v0.10.0) (2019-12-10)
### Bug Fixes
* Renaming to sender and receiver ([bf33a2d](https://github.com/uport-project/daf/commit/bf33a2de268cf07b06faa04283ec066573c37ffc))
* Typo ([0a47c70](https://github.com/uport-project/daf/commit/0a47c70fac8c9624c73343c8067d11fab3cd2c9d))
### Features
* Data deduplication ([c5c10b1](https://github.com/uport-project/daf/commit/c5c10b17eebd1d6f82a43f0d5cc46da9b9270c3e))
* Message object with validation ([8bf6a9d](https://github.com/uport-project/daf/commit/8bf6a9d47e73d6e2be9003854718b67f59c636dd))
# [0.9.0](https://github.com/uport-project/daf/compare/v0.8.0...v0.9.0) (2019-12-05)

@@ -8,0 +26,0 @@

{
"name": "daf-core",
"description": "DID Agent Framework Core",
"version": "0.9.0",
"version": "0.10.0",
"main": "build/index.js",

@@ -30,3 +30,3 @@ "types": "build/index.d.ts",

"keywords": [],
"gitHead": "d185517608d45eaff66690b6be2128ded6946b1c"
"gitHead": "a194a5cf6c9bbe98b033f3add2044175dcc68391"
}

@@ -7,5 +7,5 @@ import { EventEmitter } from 'events'

import { ActionHandler } from './action-handler'
import { ValidatedMessage, PreValidatedMessage, RawMessage, Action } from './types'
import { Action } from './types'
import { EncryptionKeyManager } from './encryption-manager'
import blake from 'blakejs'
import { Message } from './message'

@@ -54,3 +54,3 @@ import Debug from 'debug'

serviceControllersWithConfig: config.serviceControllersWithConfig,
onRawMessage: this.onRawMessage.bind(this),
validateMessage: this.validateMessage.bind(this),
didResolver: this.didResolver,

@@ -74,11 +74,7 @@ })

public async onRawMessage(rawMessage: RawMessage): Promise<ValidatedMessage | null> {
debug('Raw message %O', rawMessage)
public async validateMessage(message: Message): Promise<Message> {
debug('Raw message %O', message)
try {
const preValidatedMessage = await this.messageValidator.validate(rawMessage, this)
if (preValidatedMessage !== null && this.isValidatedMessage(preValidatedMessage)) {
const validatedMessage = {
...preValidatedMessage,
hash: blake.blake2bHex(preValidatedMessage.raw),
}
const validatedMessage = await this.messageValidator.validate(message, this)
if (validatedMessage.isValid()) {
this.emit(EventTypes.validatedMessage, validatedMessage)

@@ -88,26 +84,8 @@ return validatedMessage

} catch (error) {
this.emit(EventTypes.error, error, rawMessage)
this.emit(EventTypes.error, error, message)
return Promise.reject(error)
}
return null
return Promise.reject('Unsupported message type')
}
private isValidatedMessage(message: PreValidatedMessage): boolean {
if (message === null) {
return false
}
if (!message.type || message.type == '') {
debug('Missing `type` in %o', message)
return false
}
if (!message.issuer || message.issuer == '') {
debug('Missing `issuer` in %o', message)
return false
}
if (!message.raw || message.raw == '') {
debug('Missing `raw` in %o', message)
return false
}
return true
}
public async handleAction(action: Action): Promise<any> {

@@ -114,0 +92,0 @@ if (this.actionHandler) {

@@ -11,7 +11,22 @@ export const baseTypeDefs = `

type Message {
hash: ID!
id: ID!
threadId: String
rowId: String!
type: String!
sender: Identity
receiver: Identity
raw: String!
data: String
timestamp: Int
metaData: [MessageMetaData]
thread: [Message]
}
type MessageMetaData {
rowId: String!
type: String!
id: String
data: String
}
`
import { Core } from './core'
import { Message } from './message'

@@ -7,10 +8,16 @@ interface Context {

const newMessage = async (_: any, args: { raw: string, sourceType: string, sourceId?: string }, ctx: Context) => {
return await ctx.core.onRawMessage({
raw: args.raw,
meta: [{
sourceType: args.sourceType,
sourceId: args.sourceId
}]
})
const newMessage = async (
_: any,
args: { raw: string; sourceType: string; sourceId?: string },
ctx: Context,
) => {
return await ctx.core.validateMessage(
new Message({
raw: args.raw,
meta: {
type: args.sourceType,
id: args.sourceId,
},
}),
)
}

@@ -17,0 +24,0 @@

@@ -6,2 +6,3 @@ export { Core, EventTypes, Resolver } from './core'

export { AbstractMessageValidator } from './message-validator'
export { Message } from './message'
export {

@@ -8,0 +9,0 @@ ServiceController,

@@ -1,2 +0,2 @@

import { RawMessage, ValidatedMessage, PreValidatedMessage } from './types'
import { Message } from './message'
import { Core } from './core'

@@ -6,6 +6,3 @@

setNext(messageValidator: MessageValidator): MessageValidator
validate: (
rawMessage: RawMessage,
core: Core,
) => Promise<PreValidatedMessage | null>
validate: (message: Message, core: Core) => Promise<Message>
}

@@ -21,11 +18,8 @@

public async validate(
rawMessage: RawMessage,
core: Core,
): Promise<PreValidatedMessage | null> {
public async validate(message: Message, core: Core): Promise<Message> {
if (this.nextMessageValidator) {
return this.nextMessageValidator.validate(rawMessage, core)
return this.nextMessageValidator.validate(message, core)
}
return null
return Promise.reject('Unsupported message type')
}
}
import { DIDDocument } from 'did-resolver'
import { Resolver } from './core'
import { Issuer } from './identity-manager'
import { RawMessage, ValidatedMessage } from './types'
import { Message } from './message'

@@ -10,3 +10,3 @@ export interface ServiceControllerOptions {

didDoc: DIDDocument
onRawMessage: (rawMessage: RawMessage) => Promise<ValidatedMessage | null>
validateMessage: (message: Message) => Promise<Message>
}

@@ -38,3 +38,3 @@

serviceControllersWithConfig: ServiceControllerWithConfig[]
onRawMessage: (rawMessage: RawMessage) => Promise<ValidatedMessage | null>
validateMessage: (message: Message) => Promise<Message>
}

@@ -44,3 +44,3 @@

private serviceControllersWithConfig: ServiceControllerWithConfig[]
private onRawMessage: (rawMessage: RawMessage) => Promise<ValidatedMessage | null>
private validateMessage: (message: Message) => Promise<Message>
private serviceControllers: ServiceController[]

@@ -51,3 +51,3 @@ private didResolver: Resolver

this.serviceControllersWithConfig = options.serviceControllersWithConfig
this.onRawMessage = options.onRawMessage
this.validateMessage = options.validateMessage
this.serviceControllers = []

@@ -67,3 +67,3 @@ this.didResolver = options.didResolver

didDoc,
onRawMessage: this.onRawMessage,
validateMessage: this.validateMessage,
}),

@@ -70,0 +70,0 @@ )

@@ -1,33 +0,4 @@

export interface ServiceMetaData {
sourceType?: string
sourceId?: string
data?: any
}
export interface RawMessage {
raw: string
meta?: ServiceMetaData[]
}
export interface PreValidatedMessage {
type: string
issuer: string
subject?: string
time?: string
tag?: string
raw: string
verified?: any
custom?: any
meta?: ServiceMetaData[]
}
export interface ValidatedMessage extends PreValidatedMessage {
hash: string
}
export interface Action {
type: string
parentMessage?: ValidatedMessage
parentMessageHash?: string
data: any
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc