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

daf-core

Package Overview
Dependencies
Maintainers
6
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 3.1.3 to 3.1.4-beta.2

5

build/core.d.ts

@@ -38,2 +38,7 @@ /// <reference types="node" />

validateMessage(message: Message): Promise<Message>;
saveNewMessage(input: {
raw: string;
metaDataType?: string;
metaDataValue?: string;
}): Promise<Message>;
handleAction(action: Action): Promise<any>;

@@ -40,0 +45,0 @@ }

@@ -70,2 +70,3 @@ "use strict";

var abstract_message_validator_1 = require("./message/abstract-message-validator");
var message_1 = require("./entities/message");
var debug_1 = __importDefault(require("debug"));

@@ -209,2 +210,31 @@ var debug = debug_1.default('daf:core');

};
Core.prototype.saveNewMessage = function (input) {
return __awaiter(this, void 0, void 0, function () {
var message, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
return [4 /*yield*/, this.validateMessage(new message_1.Message({
raw: input.raw,
meta: {
type: input.metaDataType,
value: input.metaDataValue
}
}))];
case 1:
message = _a.sent();
return [4 /*yield*/, message.save()];
case 2:
_a.sent();
return [2 /*return*/, message];
case 3:
error_2 = _a.sent();
this.emit(exports.EventTypes.error, error_2);
return [2 /*return*/, Promise.reject(error_2)];
case 4: return [2 /*return*/];
}
});
});
};
Core.prototype.handleAction = function (action) {

@@ -211,0 +241,0 @@ return __awaiter(this, void 0, void 0, function () {

8

build/entities/claim.js

@@ -38,7 +38,11 @@ "use strict";

__decorate([
typeorm_1.ManyToOne(function (type) { return identity_1.Identity; }, function (identity) { return identity.issuedPresentations; }),
typeorm_1.ManyToOne(function (type) { return identity_1.Identity; }, function (identity) { return identity.issuedPresentations; }, {
eager: true
}),
__metadata("design:type", identity_1.Identity)
], Claim.prototype, "issuer", void 0);
__decorate([
typeorm_1.ManyToOne(function (type) { return identity_1.Identity; }, function (identity) { return identity.receivedPresentations; }),
typeorm_1.ManyToOne(function (type) { return identity_1.Identity; }, function (identity) { return identity.receivedPresentations; }, {
eager: true
}),
__metadata("design:type", identity_1.Identity)

@@ -45,0 +49,0 @@ ], Claim.prototype, "subject", void 0);

@@ -89,2 +89,3 @@ "use strict";

cascade: ['insert'],
eager: true
}),

@@ -96,2 +97,3 @@ __metadata("design:type", identity_1.Identity)

cascade: ['insert'],
eager: true
}),

@@ -127,3 +129,3 @@ __metadata("design:type", identity_1.Identity)

__decorate([
typeorm_1.ManyToMany(function (type) { return message_1.Message; }),
typeorm_1.ManyToMany(function (type) { return message_1.Message; }, function (message) { return message.credentials; }),
__metadata("design:type", Array)

@@ -130,0 +132,0 @@ ], Credential.prototype, "messages", void 0);

@@ -115,2 +115,3 @@ "use strict";

cascade: ['insert'],
eager: true
}),

@@ -123,2 +124,3 @@ __metadata("design:type", identity_1.Identity)

cascade: ['insert'],
eager: true
}),

@@ -139,5 +141,3 @@ __metadata("design:type", identity_1.Identity)

__decorate([
typeorm_1.ManyToMany(function (type) { return credential_1.Credential; }, {
cascade: true,
}),
typeorm_1.ManyToMany(function (type) { return credential_1.Credential; }, function (credential) { return credential.messages; }, { cascade: true }),
typeorm_1.JoinTable(),

@@ -144,0 +144,0 @@ __metadata("design:type", Array)

@@ -58,2 +58,3 @@ "use strict";

cascade: ['insert'],
eager: true
}),

@@ -65,2 +66,3 @@ __metadata("design:type", identity_1.Identity)

cascade: ['insert'],
eager: true
}),

@@ -67,0 +69,0 @@ __metadata("design:type", identity_1.Identity)

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

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 type: String!\n value: String\n }\n \n";
export declare const baseTypeDefs = "\n type Query \n\n type Mutation \n\n type Identity {\n did: ID!\n provider: String\n }\n\n";
//# sourceMappingURL=graphql-base-type-defs.d.ts.map
"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 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 type: String!\n value: String\n }\n \n";
exports.baseTypeDefs = "\n type Query \n\n type Mutation \n\n type Identity {\n did: ID!\n provider: String\n }\n\n";
//# sourceMappingURL=graphql-base-type-defs.js.map
import { Core } from '../core';
import { LastMessageTimestampForInstance } from '../service/service-manager';
import { Message } from '../entities/message';
import { Presentation } from '../entities/presentation';
import { Credential } from '../entities/credential';
import { Claim } from '../entities/claim';
import { Identity } from '../entities/identity';
export interface Context {
core: Core;
}
export interface FindOptions {
take?: number;
skip?: number;
}
export declare const resolvers: {
Query: {
serviceMessagesSince: (_: any, args: {
ts: LastMessageTimestampForInstance[];
}, ctx: Context) => Promise<any[]>;
};
Mutation: {
newMessage: (_: any, args: {
saveNewMessage: (_: any, args: {
raw: string;
sourceType: string;
sourceId?: string;
}, ctx: Context) => Promise<{
sender: import("..").Identity;
receiver: import("..").Identity;
data: string;
id: string;
raw: string;
__typename: string;
saveDate: Date;
updateDate: Date;
createdAt?: Date;
expiresAt?: Date;
threadId?: string;
type: string;
replyTo?: string[];
replyUrl?: string;
from?: import("..").Identity;
to?: import("..").Identity;
metaData?: import("../entities/message").MetaData[];
presentations: import("..").Presentation[];
credentials: import("..").Credential[];
}>;
metaDataType?: string;
metaDataValue?: string;
}, ctx: Context) => Promise<Message>;
};
Query: {
identity: (_: any, { did }: {
did: any;
}) => Promise<Identity>;
identities: (_: any, { input }: {
input: any;
}) => Promise<Identity[]>;
message: (_: any, { id }: {
id: any;
}) => Promise<Message>;
messages: (_: any, { input }: {
input?: {
options?: FindOptions;
from?: string[];
to?: string[];
type?: string[];
threadId?: string[];
};
}) => Promise<Message[]>;
presentation: (_: any, { hash }: {
hash: any;
}) => Promise<Presentation>;
presentations: (_: any, { input }: {
input?: {
options?: FindOptions;
issuer?: string[];
audience?: string[];
type?: string[];
context?: string[];
};
}) => Promise<Presentation[]>;
credential: (_: any, { hash }: {
hash: any;
}) => Promise<Credential>;
credentials: (_: any, { input }: {
input?: {
options?: FindOptions;
issuer?: string[];
subject?: string[];
type?: string[];
context?: string[];
};
}) => Promise<Credential[]>;
claim: (_: any, { hash }: {
hash: any;
}) => Promise<Claim>;
claims: (_: any, { input }: {
input?: {
options?: FindOptions;
issuer?: string[];
subject?: string[];
type?: string[];
value?: string[];
};
}) => Promise<Claim[]>;
};
Identity: {
sentMessages: (identity: Identity) => Promise<Message[]>;
receivedMessages: (identity: Identity) => Promise<Message[]>;
issuedPresentations: (identity: Identity) => Promise<Presentation[]>;
receivedPresentations: (identity: Identity) => Promise<Presentation[]>;
issuedCredentials: (identity: Identity) => Promise<Credential[]>;
receivedCredentials: (identity: Identity) => Promise<Credential[]>;
issuedClaims: (identity: Identity) => Promise<Claim[]>;
receivedClaims: (identity: Identity) => Promise<Claim[]>;
};
Credential: {
claims: (credential: Credential) => Promise<Claim[]>;
messages: (credential: Credential) => Promise<Message[]>;
presentations: (credential: Credential) => Promise<Presentation[]>;
};
Presentation: {
credentials: (presentation: Presentation) => Promise<Credential[]>;
messages: (presentation: Presentation) => Promise<Message[]>;
};
Message: {
presentations: (message: Message) => Promise<Presentation[]>;
credentials: (message: Message) => Promise<Credential[]>;
};
};
export declare const typeDefs = "\n input LastMessageTimestampForInstance {\n timestamp: Int!\n did: String!\n type: String!\n id: String!\n }\n\n type ServiceMessage {\n id: String!\n threadId: String,\n timestamp: Int,\n sender: String,\n receiver: String,\n type: String,\n raw: String,\n data: String,\n metaData: [MessageMetaData]\n }\n\n extend type Query {\n serviceMessagesSince(ts: [LastMessageTimestampForInstance]!): [ServiceMessage]\n }\n\n extend type Mutation {\n newMessage(raw: String!, sourceType: String!, sourceId: String): Message\n }\n";
export declare const typeDefs = "\n\n input FindOptions {\n take: Int\n skip: Int\n }\n\n input IdentitiesInput {\n options: FindOptions\n }\n\n input MessagesInput {\n from: [String]\n to: [String]\n type: [String]\n threadId: [String]\n options: FindOptions\n }\n\n input PresentationsInput {\n issuer: [String]\n audience: [String]\n type: [String]\n context: [String]\n options: FindOptions\n }\n\n input CredentialsInput {\n issuer: [String]\n subject: [String]\n type: [String]\n context: [String]\n options: FindOptions\n }\n\n input ClaimsInput {\n issuer: [ID]\n subject: [ID]\n type: [String]\n value: [String]\n options: FindOptions\n }\n\n extend type Query {\n identity(did: ID!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n }\n\n extend type Mutation {\n saveNewMessage(raw: String!, metaDataType: String, metaDataValue: String): Message\n }\n\n\n extend type Identity {\n sentMessages: [Message]\n receivedMessages: [Message]\n issuedPresentations: [Presentation]\n receivedPresentations: [Presentation]\n issuedCredentials: [Credential]\n receivedCredentials: [Credential]\n issuedClaims: [Claim]\n receivedClaims: [Claim]\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: [String]\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n raw: String!\n issuer: Identity!\n audience: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n raw: String!\n issuer: Identity!\n subject: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity!\n credential: Credential!\n type: String!\n value: String!\n isObj: Boolean\n } \n";
//# sourceMappingURL=graphql-core.d.ts.map

@@ -50,49 +50,257 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var typeorm_1 = require("typeorm");
var message_1 = require("../entities/message");
var newMessage = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () {
var message, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ctx.core.validateMessage(new message_1.Message({
raw: args.raw,
meta: {
type: args.sourceType,
value: args.sourceId,
},
}))];
case 1:
message = _a.sent();
res = __assign(__assign({}, message), { sender: message.from, receiver: message.to, data: JSON.stringify(message.data), id: message.id, raw: message.raw, __typename: 'Message' });
return [2 /*return*/, res];
}
var presentation_1 = require("../entities/presentation");
var credential_1 = require("../entities/credential");
var claim_1 = require("../entities/claim");
var identity_1 = require("../entities/identity");
var messages = function (_, _a) {
var input = _a.input;
return __awaiter(void 0, void 0, void 0, function () {
var options;
var _b, _c;
return __generator(this, function (_d) {
options = {
where: {}
};
if (input === null || input === void 0 ? void 0 : input.from)
options.where['from'] = typeorm_1.In(input.from);
if (input === null || input === void 0 ? void 0 : input.to)
options.where['to'] = typeorm_1.In(input.to);
if (input === null || input === void 0 ? void 0 : input.type)
options.where['type'] = typeorm_1.In(input.type);
if (input === null || input === void 0 ? void 0 : input.threadId)
options.where['threadId'] = typeorm_1.In(input.threadId);
if ((_b = input === null || input === void 0 ? void 0 : input.options) === null || _b === void 0 ? void 0 : _b.skip)
options['skip'] = input.options.skip;
if ((_c = input === null || input === void 0 ? void 0 : input.options) === null || _c === void 0 ? void 0 : _c.take)
options['take'] = input.options.take;
return [2 /*return*/, message_1.Message.find(options)];
});
});
}); };
var serviceMessagesSince = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ctx.core.getMessagesSince(args.ts)];
case 1:
res = _a.sent();
return [2 /*return*/, []
// return res.map(msg => ({
// ...msg,
// id: msg.id,
// data: JSON.stringify(msg.data),
// raw: msg.raw,
// metaData: msg.allMeta,
// }))
]; // FIXME
}
};
var presentations = function (_, _a) {
var input = _a.input;
return __awaiter(void 0, void 0, void 0, function () {
var options;
var _b, _c;
return __generator(this, function (_d) {
options = {
where: {}
};
if (input === null || input === void 0 ? void 0 : input.issuer)
options.where['issuer'] = typeorm_1.In(input.issuer);
if (input === null || input === void 0 ? void 0 : input.audience)
options.where['audience'] = typeorm_1.In(input.audience);
if (input === null || input === void 0 ? void 0 : input.type)
options.where['type'] = typeorm_1.In(input.type);
if (input === null || input === void 0 ? void 0 : input.context)
options.where['context'] = typeorm_1.In(input.context);
if ((_b = input === null || input === void 0 ? void 0 : input.options) === null || _b === void 0 ? void 0 : _b.skip)
options['skip'] = input.options.skip;
if ((_c = input === null || input === void 0 ? void 0 : input.options) === null || _c === void 0 ? void 0 : _c.take)
options['take'] = input.options.take;
return [2 /*return*/, presentation_1.Presentation.find(options)];
});
});
}); };
};
var credentials = function (_, _a) {
var input = _a.input;
return __awaiter(void 0, void 0, void 0, function () {
var options;
var _b, _c;
return __generator(this, function (_d) {
options = {
where: {}
};
if (input === null || input === void 0 ? void 0 : input.issuer)
options.where['issuer'] = typeorm_1.In(input.issuer);
if (input === null || input === void 0 ? void 0 : input.subject)
options.where['audience'] = typeorm_1.In(input.subject);
if (input === null || input === void 0 ? void 0 : input.type)
options.where['type'] = typeorm_1.In(input.type);
if (input === null || input === void 0 ? void 0 : input.context)
options.where['context'] = typeorm_1.In(input.context);
if ((_b = input === null || input === void 0 ? void 0 : input.options) === null || _b === void 0 ? void 0 : _b.skip)
options['skip'] = input.options.skip;
if ((_c = input === null || input === void 0 ? void 0 : input.options) === null || _c === void 0 ? void 0 : _c.take)
options['take'] = input.options.take;
return [2 /*return*/, credential_1.Credential.find(options)];
});
});
};
var claims = function (_, _a) {
var input = _a.input;
return __awaiter(void 0, void 0, void 0, function () {
var options;
var _b, _c;
return __generator(this, function (_d) {
options = {
relations: ['credential'],
where: {}
};
if (input === null || input === void 0 ? void 0 : input.issuer)
options.where['issuer'] = typeorm_1.In(input.issuer);
if (input === null || input === void 0 ? void 0 : input.subject)
options.where['subject'] = typeorm_1.In(input.subject);
if (input === null || input === void 0 ? void 0 : input.type)
options.where['type'] = typeorm_1.In(input.type);
if (input === null || input === void 0 ? void 0 : input.value)
options.where['value'] = typeorm_1.In(input.value);
if ((_b = input === null || input === void 0 ? void 0 : input.options) === null || _b === void 0 ? void 0 : _b.skip)
options['skip'] = input.options.skip;
if ((_c = input === null || input === void 0 ? void 0 : input.options) === null || _c === void 0 ? void 0 : _c.take)
options['take'] = input.options.take;
return [2 /*return*/, claim_1.Claim.find(options)];
});
});
};
exports.resolvers = {
Mutation: {
saveNewMessage: function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, ctx.core.saveNewMessage(args)];
}); }); },
},
Query: {
serviceMessagesSince: serviceMessagesSince,
identity: function (_, _a) {
var did = _a.did;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, identity_1.Identity.findOne(did)];
}); });
},
identities: function (_, _a) {
var input = _a.input;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, identity_1.Identity.find(__assign({}, input === null || input === void 0 ? void 0 : input.options))];
}); });
},
message: function (_, _a) {
var id = _a.id;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, message_1.Message.findOne(id)];
}); });
},
messages: messages,
presentation: function (_, _a) {
var hash = _a.hash;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, presentation_1.Presentation.findOne(hash)];
}); });
},
presentations: presentations,
credential: function (_, _a) {
var hash = _a.hash;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, credential_1.Credential.findOne(hash)];
}); });
},
credentials: credentials,
claim: function (_, _a) {
var hash = _a.hash;
return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
return [2 /*return*/, claim_1.Claim.findOne(hash, { relations: ['credential'] })];
}); });
},
claims: claims,
},
Mutation: {
newMessage: newMessage,
Identity: {
sentMessages: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['sentMessages'] })];
case 1: return [2 /*return*/, (_a.sent()).sentMessages];
}
}); }); },
receivedMessages: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['receivedMessages'] })];
case 1: return [2 /*return*/, (_a.sent()).receivedMessages];
}
}); }); },
issuedPresentations: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['issuedPresentations'] })];
case 1: return [2 /*return*/, (_a.sent()).issuedPresentations];
}
}); }); },
receivedPresentations: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['receivedPresentations'] })];
case 1: return [2 /*return*/, (_a.sent()).receivedPresentations];
}
}); }); },
issuedCredentials: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['issuedCredentials'] })];
case 1: return [2 /*return*/, (_a.sent()).issuedCredentials];
}
}); }); },
receivedCredentials: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['receivedCredentials'] })];
case 1: return [2 /*return*/, (_a.sent()).receivedCredentials];
}
}); }); },
issuedClaims: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['issuedClaims'] })];
case 1: return [2 /*return*/, (_a.sent()).issuedClaims];
}
}); }); },
receivedClaims: function (identity) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, identity_1.Identity.findOne(identity.did, { relations: ['receivedClaims'] })];
case 1: return [2 /*return*/, (_a.sent()).receivedClaims];
}
}); }); },
},
Credential: {
claims: function (credential) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, credential_1.Credential.findOne(credential.hash, { relations: ['claims'] })];
case 1: return [2 /*return*/, (_a.sent()).claims];
}
}); }); },
messages: function (credential) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, credential_1.Credential.findOne(credential.hash, { relations: ['messages'] })];
case 1: return [2 /*return*/, (_a.sent()).messages];
}
}); }); },
presentations: function (credential) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, credential_1.Credential.findOne(credential.hash, { relations: ['presentations'] })];
case 1: return [2 /*return*/, (_a.sent()).presentations];
}
}); }); },
},
Presentation: {
credentials: function (presentation) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, presentation_1.Presentation.findOne(presentation.hash, { relations: ['credentials'] })];
case 1: return [2 /*return*/, (_a.sent()).credentials];
}
}); }); },
messages: function (presentation) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, presentation_1.Presentation.findOne(presentation.hash, { relations: ['messages'] })];
case 1: return [2 /*return*/, (_a.sent()).messages];
}
}); }); }
},
Message: {
presentations: function (message) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, message_1.Message.findOne(message.id, { relations: ['presentations'] })];
case 1: return [2 /*return*/, (_a.sent()).presentations];
}
}); }); },
credentials: function (message) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, message_1.Message.findOne(message.id, { relations: ['credentials'] })];
case 1: return [2 /*return*/, (_a.sent()).credentials];
}
}); }); },
},
};
exports.typeDefs = "\n input LastMessageTimestampForInstance {\n timestamp: Int!\n did: String!\n type: String!\n id: String!\n }\n\n type ServiceMessage {\n id: String!\n threadId: String,\n timestamp: Int,\n sender: String,\n receiver: String,\n type: String,\n raw: String,\n data: String,\n metaData: [MessageMetaData]\n }\n\n extend type Query {\n serviceMessagesSince(ts: [LastMessageTimestampForInstance]!): [ServiceMessage]\n }\n\n extend type Mutation {\n newMessage(raw: String!, sourceType: String!, sourceId: String): Message\n }\n";
exports.typeDefs = "\n\n input FindOptions {\n take: Int\n skip: Int\n }\n\n input IdentitiesInput {\n options: FindOptions\n }\n\n input MessagesInput {\n from: [String]\n to: [String]\n type: [String]\n threadId: [String]\n options: FindOptions\n }\n\n input PresentationsInput {\n issuer: [String]\n audience: [String]\n type: [String]\n context: [String]\n options: FindOptions\n }\n\n input CredentialsInput {\n issuer: [String]\n subject: [String]\n type: [String]\n context: [String]\n options: FindOptions\n }\n\n input ClaimsInput {\n issuer: [ID]\n subject: [ID]\n type: [String]\n value: [String]\n options: FindOptions\n }\n\n extend type Query {\n identity(did: ID!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n }\n\n extend type Mutation {\n saveNewMessage(raw: String!, metaDataType: String, metaDataValue: String): Message\n }\n\n\n extend type Identity {\n sentMessages: [Message]\n receivedMessages: [Message]\n issuedPresentations: [Presentation]\n receivedPresentations: [Presentation]\n issuedCredentials: [Credential]\n receivedCredentials: [Credential]\n issuedClaims: [Claim]\n receivedClaims: [Claim]\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: [String]\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n raw: String!\n issuer: Identity!\n audience: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n raw: String!\n issuer: Identity!\n subject: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity!\n credential: Credential!\n type: String!\n value: String!\n isObj: Boolean\n } \n";
//# sourceMappingURL=graphql-core.js.map

@@ -5,34 +5,88 @@ declare const Gql: {

resolvers: {
Query: {
serviceMessagesSince: (_: any, args: {
ts: import("..").LastMessageTimestampForInstance[];
}, ctx: import("./graphql-core").Context) => Promise<any[]>;
};
Mutation: {
newMessage: (_: any, args: {
saveNewMessage: (_: any, args: {
raw: string;
sourceType: string;
sourceId?: string;
}, ctx: import("./graphql-core").Context) => Promise<{
sender: import("..").Identity;
receiver: import("..").Identity;
data: string;
id: string;
raw: string;
__typename: string;
saveDate: Date;
updateDate: Date;
createdAt?: Date;
expiresAt?: Date;
threadId?: string;
type: string;
replyTo?: string[];
replyUrl?: string;
from?: import("..").Identity;
to?: import("..").Identity;
metaData?: import("../entities/message").MetaData[];
presentations: import("..").Presentation[];
credentials: import("..").Credential[];
}>;
metaDataType?: string;
metaDataValue?: string;
}, ctx: import("./graphql-core").Context) => Promise<import("..").Message>;
};
Query: {
identity: (_: any, { did }: {
did: any;
}) => Promise<import("..").Identity>;
identities: (_: any, { input }: {
input: any;
}) => Promise<import("..").Identity[]>;
message: (_: any, { id }: {
id: any;
}) => Promise<import("..").Message>;
messages: (_: any, { input }: {
input?: {
options?: import("./graphql-core").FindOptions;
from?: string[];
to?: string[];
type?: string[];
threadId?: string[];
};
}) => Promise<import("..").Message[]>;
presentation: (_: any, { hash }: {
hash: any;
}) => Promise<import("..").Presentation>;
presentations: (_: any, { input }: {
input?: {
options?: import("./graphql-core").FindOptions;
issuer?: string[];
audience?: string[];
type?: string[];
context?: string[];
};
}) => Promise<import("..").Presentation[]>;
credential: (_: any, { hash }: {
hash: any;
}) => Promise<import("..").Credential>;
credentials: (_: any, { input }: {
input?: {
options?: import("./graphql-core").FindOptions;
issuer?: string[];
subject?: string[];
type?: string[];
context?: string[];
};
}) => Promise<import("..").Credential[]>;
claim: (_: any, { hash }: {
hash: any;
}) => Promise<import("..").Claim>;
claims: (_: any, { input }: {
input?: {
options?: import("./graphql-core").FindOptions;
issuer?: string[];
subject?: string[];
type?: string[];
value?: string[];
};
}) => Promise<import("..").Claim[]>;
};
Identity: {
sentMessages: (identity: import("..").Identity) => Promise<import("..").Message[]>;
receivedMessages: (identity: import("..").Identity) => Promise<import("..").Message[]>;
issuedPresentations: (identity: import("..").Identity) => Promise<import("..").Presentation[]>;
receivedPresentations: (identity: import("..").Identity) => Promise<import("..").Presentation[]>;
issuedCredentials: (identity: import("..").Identity) => Promise<import("..").Credential[]>;
receivedCredentials: (identity: import("..").Identity) => Promise<import("..").Credential[]>;
issuedClaims: (identity: import("..").Identity) => Promise<import("..").Claim[]>;
receivedClaims: (identity: import("..").Identity) => Promise<import("..").Claim[]>;
};
Credential: {
claims: (credential: import("..").Credential) => Promise<import("..").Claim[]>;
messages: (credential: import("..").Credential) => Promise<import("..").Message[]>;
presentations: (credential: import("..").Credential) => Promise<import("..").Presentation[]>;
};
Presentation: {
credentials: (presentation: import("..").Presentation) => Promise<import("..").Credential[]>;
messages: (presentation: import("..").Presentation) => Promise<import("..").Message[]>;
};
Message: {
presentations: (message: import("..").Message) => Promise<import("..").Presentation[]>;
credentials: (message: import("..").Message) => Promise<import("..").Credential[]>;
};
};

@@ -39,0 +93,0 @@ typeDefs: string;

{
"name": "daf-core",
"description": "DID Agent Framework Core",
"version": "3.1.3",
"version": "3.1.4-beta.2+526ec35",
"main": "build/index.js",

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

"keywords": [],
"gitHead": "40041bb9c40d406dea7b0b4111a96eef75ec8664"
"gitHead": "526ec35e925ab39ffc0fc8ea803e9af2fee2e785"
}
# DID Agent Framework Core
### Core functions
- Validates messages
- Handles actions
- Bridge between service controllers and identity providers

@@ -105,2 +105,21 @@ import { EventEmitter } from 'events'

public async saveNewMessage(input: { raw: string, metaDataType?: string, metaDataValue?: string }): Promise<Message> {
try {
const message = await this.validateMessage(
new Message({
raw: input.raw,
meta:{
type: input.metaDataType,
value: input.metaDataValue
}
})
)
await message.save()
return message
} catch (error) {
this.emit(EventTypes.error, error)
return Promise.reject(error)
}
}
public async handleAction(action: Action): Promise<any> {

@@ -107,0 +126,0 @@ if (!this.actionHandler) {

@@ -6,7 +6,3 @@ import {

ManyToOne,
JoinTable,
PrimaryColumn,
OneToMany,
ManyToMany,
BeforeInsert,
} from 'typeorm'

@@ -23,3 +19,5 @@ import { Identity } from './identity'

type => Identity,
identity => identity.issuedPresentations,
identity => identity.issuedPresentations, {
eager: true
}
)

@@ -30,3 +28,5 @@ issuer: Identity

type => Identity,
identity => identity.receivedPresentations,
identity => identity.receivedPresentations, {
eager: true
}
)

@@ -33,0 +33,0 @@ subject: Identity

@@ -7,7 +7,5 @@ import { blake2bHex } from 'blakejs'

ManyToOne,
JoinTable,
PrimaryColumn,
OneToMany,
ManyToMany,
BeforeInsert,
} from 'typeorm'

@@ -67,2 +65,3 @@ import { Identity } from './identity'

cascade: ['insert'],
eager: true
},

@@ -77,2 +76,3 @@ )

cascade: ['insert'],
eager: true
},

@@ -109,4 +109,7 @@ )

@ManyToMany(type => Message)
@ManyToMany(
type => Message,
message => message.credentials
)
messages: Message[]
}

@@ -8,3 +8,2 @@ import {

PrimaryGeneratedColumn,
OneToMany,
JoinTable,

@@ -76,2 +75,3 @@ CreateDateColumn,

cascade: ['insert'],
eager: true
},

@@ -87,2 +87,3 @@ )

cascade: ['insert'],
eager: true
},

@@ -105,5 +106,7 @@ )

@ManyToMany(type => Credential, {
cascade: true,
})
@ManyToMany(
type => Credential,
credential => credential.messages,
{ cascade: true }
)
@JoinTable()

@@ -110,0 +113,0 @@ credentials: Credential[]

@@ -38,2 +38,3 @@ import { blake2bHex } from 'blakejs'

cascade: ['insert'],
eager: true
},

@@ -48,2 +49,3 @@ )

cascade: ['insert'],
eager: true
},

@@ -50,0 +52,0 @@ )

@@ -5,26 +5,8 @@ export const baseTypeDefs = `

type Mutation
type Identity {
did: ID!
provider: String
}
type Message {
id: ID!
threadId: String
rowId: String!
type: String!
sender: Identity
receiver: Identity
raw: String!
data: String
timestamp: Int
metaData: [MessageMetaData]
thread: [Message]
}
type MessageMetaData {
type: String!
value: String
}
`

@@ -0,5 +1,8 @@

import { In} from 'typeorm'
import { Core } from '../core'
import { LastMessageTimestampForInstance } from '../service/service-manager'
import { Message } from '../entities/message'
import { Presentation } from '../entities/presentation'
import { Credential } from '../entities/credential'
import { Claim } from '../entities/claim'
import { Identity } from '../entities/identity'

@@ -10,81 +13,295 @@ export interface Context {

const newMessage = async (
export interface FindOptions {
take?: number,
skip?: number,
}
const messages = async (
_: any,
args: { raw: string; sourceType: string; sourceId?: string },
ctx: Context,
{ input } : {
input?: {
options?: FindOptions,
from?: string[],
to?: string[],
type?: string[],
threadId?: string[],
}
},
) => {
const message = await ctx.core.validateMessage(
new Message({
raw: args.raw,
meta: {
type: args.sourceType,
value: args.sourceId,
},
}),
)
const options = {
where: {}
}
const res = {
...message,
sender: message.from,
receiver: message.to,
data: JSON.stringify(message.data),
id: message.id,
raw: message.raw,
__typename: 'Message',
}
return res
if (input?.from) options.where['from'] = In(input.from)
if (input?.to) options.where['to'] = In(input.to)
if (input?.type) options.where['type'] = In(input.type)
if (input?.threadId) options.where['threadId'] = In(input.threadId)
if (input?.options?.skip) options['skip'] = input.options.skip
if (input?.options?.take) options['take'] = input.options.take
return Message.find(options)
}
const serviceMessagesSince = async (
const presentations = async (
_: any,
args: { ts: LastMessageTimestampForInstance[] },
ctx: Context,
{ input } : {
input?: {
options?: FindOptions,
issuer?: string[],
audience?: string[],
type?: string[],
context?: string[],
}
},
) => {
const res = await ctx.core.getMessagesSince(args.ts)
return [] // FIXME
// return res.map(msg => ({
// ...msg,
// id: msg.id,
// data: JSON.stringify(msg.data),
// raw: msg.raw,
// metaData: msg.allMeta,
// }))
const options = {
where: {}
}
if (input?.issuer) options.where['issuer'] = In(input.issuer)
if (input?.audience) options.where['audience'] = In(input.audience)
if (input?.type) options.where['type'] = In(input.type)
if (input?.context) options.where['context'] = In(input.context)
if (input?.options?.skip) options['skip'] = input.options.skip
if (input?.options?.take) options['take'] = input.options.take
return Presentation.find(options)
}
const credentials = async (
_: any,
{ input } : {
input?: {
options?: FindOptions,
issuer?: string[],
subject?: string[],
type?: string[],
context?: string[],
}
},
) => {
const options = {
where: {}
}
if (input?.issuer) options.where['issuer'] = In(input.issuer)
if (input?.subject) options.where['audience'] = In(input.subject)
if (input?.type) options.where['type'] = In(input.type)
if (input?.context) options.where['context'] = In(input.context)
if (input?.options?.skip) options['skip'] = input.options.skip
if (input?.options?.take) options['take'] = input.options.take
return Credential.find(options)
}
const claims = async (
_: any,
{ input }:{
input?: {
options?: FindOptions,
issuer?: string[],
subject?: string[],
type?: string[],
value?: string[],
}
},
) => {
const options = {
relations: ['credential'],
where: {}
}
if (input?.issuer) options.where['issuer'] = In(input.issuer)
if (input?.subject) options.where['subject'] = In(input.subject)
if (input?.type) options.where['type'] = In(input.type)
if (input?.value) options.where['value'] = In(input.value)
if (input?.options?.skip) options['skip'] = input.options.skip
if (input?.options?.take) options['take'] = input.options.take
return Claim.find(options)
}
export const resolvers = {
Mutation: {
saveNewMessage: async (_: any, args: { raw: string; metaDataType?: string; metaDataValue?: string }, ctx: Context) => ctx.core.saveNewMessage(args),
},
Query: {
serviceMessagesSince,
identity: async (_: any, { did }) => Identity.findOne(did),
identities: async (_: any, { input }) => Identity.find({...input?.options}),
message: async (_: any, { id }) => Message.findOne(id),
messages,
presentation: async (_: any, { hash }) => Presentation.findOne(hash),
presentations,
credential: async (_: any, { hash }) => Credential.findOne(hash),
credentials,
claim: async (_: any, { hash }) => Claim.findOne(hash, { relations: ['credential'] }),
claims,
},
Mutation: {
newMessage,
Identity: {
sentMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['sentMessages'] })).sentMessages,
receivedMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedMessages'] })).receivedMessages,
issuedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedPresentations'] })).issuedPresentations,
receivedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedPresentations'] })).receivedPresentations,
issuedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedCredentials'] })).issuedCredentials,
receivedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedCredentials'] })).receivedCredentials,
issuedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedClaims'] })).issuedClaims,
receivedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedClaims'] })).receivedClaims,
},
Credential: {
claims: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['claims'] })).claims,
messages: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['messages'] })).messages,
presentations: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['presentations'] })).presentations,
},
Presentation: {
credentials: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['credentials'] })).credentials,
messages: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['messages'] })).messages
},
Message: {
presentations: async (message: Message) => (await Message.findOne(message.id, { relations: ['presentations'] })).presentations,
credentials: async (message: Message) => (await Message.findOne(message.id, { relations: ['credentials'] })).credentials,
},
}
export const typeDefs = `
input LastMessageTimestampForInstance {
timestamp: Int!
did: String!
type: String!
id: String!
input FindOptions {
take: Int
skip: Int
}
type ServiceMessage {
id: String!
threadId: String,
timestamp: Int,
sender: String,
receiver: String,
type: String,
raw: String,
data: String,
metaData: [MessageMetaData]
input IdentitiesInput {
options: FindOptions
}
input MessagesInput {
from: [String]
to: [String]
type: [String]
threadId: [String]
options: FindOptions
}
input PresentationsInput {
issuer: [String]
audience: [String]
type: [String]
context: [String]
options: FindOptions
}
input CredentialsInput {
issuer: [String]
subject: [String]
type: [String]
context: [String]
options: FindOptions
}
input ClaimsInput {
issuer: [ID]
subject: [ID]
type: [String]
value: [String]
options: FindOptions
}
extend type Query {
serviceMessagesSince(ts: [LastMessageTimestampForInstance]!): [ServiceMessage]
identity(did: ID!): Identity
identities(input: IdentitiesInput): [Identity]
message(id: ID!): Message
messages(input: MessagesInput): [Message]
presentation(hash: ID!): Presentation
presentations(input: PresentationsInput): [Presentation]
credential(hash: ID!): Credential
credentials(input: CredentialsInput): [Credential]
claim(hash: ID!): Claim
claims(input: ClaimsInput): [Claim]
}
extend type Mutation {
newMessage(raw: String!, sourceType: String!, sourceId: String): Message
saveNewMessage(raw: String!, metaDataType: String, metaDataValue: String): Message
}
extend type Identity {
sentMessages: [Message]
receivedMessages: [Message]
issuedPresentations: [Presentation]
receivedPresentations: [Presentation]
issuedCredentials: [Credential]
receivedCredentials: [Credential]
issuedClaims: [Claim]
receivedClaims: [Claim]
}
scalar Object
scalar Date
type Message {
id: ID!
saveDate: Date!
updateDate: Date!
createdAt: Date
expiresAt: Date
threadId: String
type: String!
raw: String
data: Object
replyTo: [String]
replyUrl: [String]
from: Identity
to: Identity
metaData: [MetaData]
presentations: [Presentation]
credentials: [Credential]
}
type MetaData {
type: String!
value: String
}
type Presentation {
hash: ID!
raw: String!
issuer: Identity!
audience: Identity!
issuanceDate: Date!
expirationDate: Date
context: [String]
type: [String]
credentials: [Credential]
messages: [Message]
}
type Credential {
hash: ID!
raw: String!
issuer: Identity!
subject: Identity!
issuanceDate: Date!
expirationDate: Date
context: [String]
type: [String]
credentialSubject: Object
claims: [Claim]
presentations: [Presentation]
messages: [Message]
}
type Claim {
hash: ID!
issuer: Identity!
subject: Identity!
credential: Credential!
type: String!
value: String!
isObj: Boolean
}
`

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

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

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