Comparing version 6.1.1 to 7.0.0-beta.1
@@ -1,49 +0,46 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { DIDDocument } from 'did-resolver'; | ||
import { IdentityManager } from './identity/identity-manager'; | ||
import { AbstractIdentityProvider } from './identity/abstract-identity-provider'; | ||
import { LastMessageTimestampForInstance } from './service/service-manager'; | ||
import { ServiceControllerDerived } from './service/abstract-service-controller'; | ||
import { MessageHandler } from './message/abstract-message-handler'; | ||
import { ActionHandler } from './action/action-handler'; | ||
import { Action } from './types'; | ||
import { Message, MetaData } from './entities/message'; | ||
import { Connection } from 'typeorm'; | ||
export declare const EventTypes: { | ||
validatedMessage: string; | ||
savedMessage: string; | ||
error: string; | ||
}; | ||
export interface Resolver { | ||
resolve(did: string): Promise<DIDDocument | null>; | ||
import { IAgent, IPluginMethodMap, IAgentPlugin } from './types'; | ||
/** | ||
* @public | ||
*/ | ||
export interface IAgentOptions { | ||
plugins?: IAgentPlugin[]; | ||
overrides?: IPluginMethodMap; | ||
authorizedMethods?: string[]; | ||
context?: Record<string, any>; | ||
} | ||
interface Config { | ||
dbConnection?: Promise<Connection>; | ||
didResolver: Resolver; | ||
identityProviders: AbstractIdentityProvider[]; | ||
serviceControllers?: ServiceControllerDerived[]; | ||
messageHandler?: MessageHandler; | ||
actionHandler?: ActionHandler; | ||
/** | ||
* @public | ||
*/ | ||
export declare class Agent implements IAgent { | ||
readonly methods: IPluginMethodMap; | ||
private context?; | ||
private protectedMethods; | ||
constructor(options?: IAgentOptions); | ||
availableMethods(): string[]; | ||
execute<P = any, R = any>(method: string, args: P): Promise<R>; | ||
} | ||
export declare class Agent extends EventEmitter { | ||
readonly dbConnection: Promise<Connection>; | ||
identityManager: IdentityManager; | ||
didResolver: Resolver; | ||
private serviceManager; | ||
private messageHandler?; | ||
private actionHandler?; | ||
constructor(config: Config); | ||
setupServices(): Promise<void>; | ||
listen(): Promise<void>; | ||
getMessagesSince(ts: LastMessageTimestampForInstance[]): Promise<Message[]>; | ||
private handleServiceMessages; | ||
handleMessage({ raw, metaData, save, }: { | ||
raw: string; | ||
metaData?: MetaData[]; | ||
save?: boolean; | ||
}): Promise<Message>; | ||
handleAction(action: Action): Promise<any>; | ||
} | ||
export {}; | ||
/** | ||
* Returns a new instance of the {@link Agent} class. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { createAgent, TAgent, IResolveDid, IHandleMessage } from 'daf-core' | ||
* import { AgentRestClient } from 'daf-rest' | ||
* const agent = createAgent<TAgent<IResolveDid & IHandleMessage>>({ | ||
* plugins: [ | ||
* new AgentRestClient({ | ||
* url: 'http://localhost:3002/agent', | ||
* enabledMethods: [ | ||
* 'resolveDid', | ||
* 'handleMessage', | ||
* ], | ||
* }), | ||
* ], | ||
* }) | ||
* ``` | ||
* @param options - Agent configuration options | ||
* @returns configured agent | ||
* @public | ||
*/ | ||
export declare function createAgent<T>(options: IAgentOptions): T; | ||
//# sourceMappingURL=agent.d.ts.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
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 function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -66,114 +64,99 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var events_1 = require("events"); | ||
var identity_manager_1 = require("./identity/identity-manager"); | ||
var service_manager_1 = require("./service/service-manager"); | ||
var message_1 = require("./entities/message"); | ||
exports.createAgent = exports.Agent = void 0; | ||
var debug_1 = __importDefault(require("debug")); | ||
var debug = debug_1.default('daf:agent'); | ||
exports.EventTypes = { | ||
validatedMessage: 'validatedMessage', | ||
savedMessage: 'savedMessage', | ||
error: 'error', | ||
/** | ||
* Filters unauthorized methods. By default all methods are authorized | ||
* @internal | ||
*/ | ||
var filterUnauthorizedMethods = function (methods, authorizedMethods) { | ||
var e_1, _a; | ||
if (!authorizedMethods) { | ||
return methods; | ||
} | ||
var result = {}; | ||
try { | ||
for (var _b = __values(Object.keys(methods)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var methodName = _c.value; | ||
if (authorizedMethods.includes(methodName)) { | ||
result[methodName] = methods[methodName]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return result; | ||
}; | ||
var Agent = /** @class */ (function (_super) { | ||
__extends(Agent, _super); | ||
function Agent(config) { | ||
var _this = _super.call(this) || this; | ||
_this.dbConnection = config.dbConnection || null; | ||
_this.identityManager = new identity_manager_1.IdentityManager({ | ||
identityProviders: config.identityProviders, | ||
}); | ||
_this.didResolver = config.didResolver; | ||
_this.serviceManager = new service_manager_1.ServiceManager({ | ||
controllers: config.serviceControllers || [], | ||
didResolver: _this.didResolver, | ||
}); | ||
_this.messageHandler = config.messageHandler; | ||
_this.actionHandler = config.actionHandler; | ||
return _this; | ||
/** | ||
* @public | ||
*/ | ||
var Agent = /** @class */ (function () { | ||
function Agent(options) { | ||
var e_2, _a, e_3, _b; | ||
var _this = this; | ||
this.methods = {}; | ||
this.protectedMethods = ['execute', 'availableMethods']; | ||
this.context = options === null || options === void 0 ? void 0 : options.context; | ||
if (options === null || options === void 0 ? void 0 : options.plugins) { | ||
try { | ||
for (var _c = __values(options.plugins), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var plugin = _d.value; | ||
this.methods = __assign(__assign({}, this.methods), filterUnauthorizedMethods(plugin.methods, options.authorizedMethods)); | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.overrides) { | ||
this.methods = __assign(__assign({}, this.methods), filterUnauthorizedMethods(options.overrides, options.authorizedMethods)); | ||
} | ||
var _loop_1 = function (method) { | ||
if (!this_1.protectedMethods.includes(method)) { | ||
//@ts-ignore | ||
this_1[method] = function (args) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, this.execute(method, args)]; | ||
}); }); }; | ||
} | ||
}; | ||
var this_1 = this; | ||
try { | ||
for (var _e = __values(Object.keys(this.methods)), _f = _e.next(); !_f.done; _f = _e.next()) { | ||
var method = _f.value; | ||
_loop_1(method); | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_f && !_f.done && (_b = _e.return)) _b.call(_e); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
} | ||
Agent.prototype.setupServices = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var identities; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.identityManager.getIdentities()]; | ||
case 1: | ||
identities = _a.sent(); | ||
return [4 /*yield*/, this.serviceManager.setupServices(identities)]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
Agent.prototype.availableMethods = function () { | ||
return Object.keys(this.methods); | ||
}; | ||
Agent.prototype.listen = function () { | ||
Agent.prototype.execute = function (method, args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
debug('Listening for new messages'); | ||
this.serviceManager.on(service_manager_1.ServiceEventTypes.NewMessages, this.handleServiceMessages.bind(this)); | ||
this.serviceManager.listen(); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
Agent.prototype.getMessagesSince = function (ts) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var rawMessages; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.serviceManager.getMessagesSince(ts)]; | ||
case 1: | ||
rawMessages = _a.sent(); | ||
return [2 /*return*/, this.handleServiceMessages(rawMessages)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Agent.prototype.handleServiceMessages = function (messages) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, messages_1, messages_1_1, message, validMessage, e_1, e_2_1; | ||
var e_2, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
result = []; | ||
_b.label = 1; | ||
debug_1.default('daf:agent:' + method)('%o', args); | ||
if (!this.methods[method]) | ||
throw Error('Method not available: ' + method); | ||
return [4 /*yield*/, this.methods[method](args, __assign(__assign({}, this.context), { agent: this }))]; | ||
case 1: | ||
_b.trys.push([1, 8, 9, 10]); | ||
messages_1 = __values(messages), messages_1_1 = messages_1.next(); | ||
_b.label = 2; | ||
case 2: | ||
if (!!messages_1_1.done) return [3 /*break*/, 7]; | ||
message = messages_1_1.value; | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, this.handleMessage({ | ||
raw: message.raw, | ||
metaData: message.metaData, | ||
})]; | ||
case 4: | ||
validMessage = _b.sent(); | ||
result.push(validMessage); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
e_1 = _b.sent(); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
messages_1_1 = messages_1.next(); | ||
return [3 /*break*/, 2]; | ||
case 7: return [3 /*break*/, 10]; | ||
case 8: | ||
e_2_1 = _b.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
try { | ||
if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) _a.call(messages_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
return [7 /*endfinally*/]; | ||
case 10: return [2 /*return*/, result]; | ||
result = _a.sent(); | ||
debug_1.default('daf:agent:' + method + ':result')('%o', result); | ||
return [2 /*return*/, result]; | ||
} | ||
@@ -183,56 +166,33 @@ }); | ||
}; | ||
Agent.prototype.handleMessage = function (_a) { | ||
var raw = _a.raw, metaData = _a.metaData, _b = _a.save, save = _b === void 0 ? true : _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var message, error_1; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
debug('Handle message %o', { raw: raw, metaData: metaData, save: save }); | ||
if (!this.messageHandler) { | ||
return [2 /*return*/, Promise.reject('Message handler not provided')]; | ||
} | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 6, , 7]); | ||
return [4 /*yield*/, this.messageHandler.handle(new message_1.Message({ raw: raw, metaData: metaData }), this)]; | ||
case 2: | ||
message = _c.sent(); | ||
if (message.isValid()) { | ||
debug('Emitting event', exports.EventTypes.validatedMessage); | ||
this.emit(exports.EventTypes.validatedMessage, message); | ||
} | ||
debug('Validated message %o', message); | ||
if (!save) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.dbConnection]; | ||
case 3: return [4 /*yield*/, (_c.sent()).getRepository(message_1.Message).save(message)]; | ||
case 4: | ||
_c.sent(); | ||
debug('Emitting event', exports.EventTypes.savedMessage); | ||
this.emit(exports.EventTypes.savedMessage, message); | ||
_c.label = 5; | ||
case 5: return [2 /*return*/, message]; | ||
case 6: | ||
error_1 = _c.sent(); | ||
this.emit(exports.EventTypes.error, error_1); | ||
return [2 /*return*/, Promise.reject(error_1)]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Agent.prototype.handleAction = function (action) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (!this.actionHandler) { | ||
return [2 /*return*/, Promise.reject('Action handler not provided')]; | ||
} | ||
debug('Handle action %o', action); | ||
return [2 /*return*/, this.actionHandler.handleAction(action, this)]; | ||
}); | ||
}); | ||
}; | ||
return Agent; | ||
}(events_1.EventEmitter)); | ||
}()); | ||
exports.Agent = Agent; | ||
/** | ||
* Returns a new instance of the {@link Agent} class. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { createAgent, TAgent, IResolveDid, IHandleMessage } from 'daf-core' | ||
* import { AgentRestClient } from 'daf-rest' | ||
* const agent = createAgent<TAgent<IResolveDid & IHandleMessage>>({ | ||
* plugins: [ | ||
* new AgentRestClient({ | ||
* url: 'http://localhost:3002/agent', | ||
* enabledMethods: [ | ||
* 'resolveDid', | ||
* 'handleMessage', | ||
* ], | ||
* }), | ||
* ], | ||
* }) | ||
* ``` | ||
* @param options - Agent configuration options | ||
* @returns configured agent | ||
* @public | ||
*/ | ||
function createAgent(options) { | ||
//@ts-ignore | ||
return new Agent(options); | ||
} | ||
exports.createAgent = createAgent; | ||
//# sourceMappingURL=agent.js.map |
@@ -1,27 +0,19 @@ | ||
export { Agent, EventTypes, Resolver } from './agent'; | ||
export { AbstractActionHandler } from './action/action-handler'; | ||
export { IdentityManager } from './identity/identity-manager'; | ||
export { AbstractIdentity } from './identity/abstract-identity'; | ||
export { AbstractIdentityController } from './identity/abstract-identity-controller'; | ||
export { AbstractIdentityProvider, IdentityProviderDerived } from './identity/abstract-identity-provider'; | ||
export { AbstractKeyManagementSystem, AbstractKey, SerializedKey, } from './identity/abstract-key-management-system'; | ||
export { AbstractIdentityStore, SerializedIdentity } from './identity/abstract-identity-store'; | ||
export { AbstractKeyStore } from './identity/abstract-key-store'; | ||
export { AbstractSecretBox } from './identity/abstract-secret-box'; | ||
export { AbstractMessageHandler } from './message/abstract-message-handler'; | ||
export { ServiceManager, LastMessageTimestampForInstance, ServiceEventTypes } from './service/service-manager'; | ||
export { AbstractServiceController } from './service/abstract-service-controller'; | ||
export { Gql } from './graphql/index'; | ||
export { Action } from './types'; | ||
export { IdentityStore } from './identity/identity-store'; | ||
export { KeyStore } from './identity/key-store'; | ||
import { Key, KeyType } from './entities/key'; | ||
import { Identity } from './entities/identity'; | ||
import { Claim } from './entities/claim'; | ||
import { Credential } from './entities/credential'; | ||
import { Presentation } from './entities/presentation'; | ||
import { Message, MetaData } from './entities/message'; | ||
export declare const Entities: (typeof Key | typeof Identity | typeof Claim | typeof Credential | typeof Presentation | typeof Message)[]; | ||
export { KeyType, Key, Identity, Message, Claim, Credential, Presentation, MetaData }; | ||
export { migrations } from './migrations'; | ||
/** | ||
* The main library for creating Decentralized Identity Agents | ||
* | ||
* @packageDocumentation | ||
*/ | ||
export { Agent, createAgent, IAgentOptions } from './agent'; | ||
export * from './types'; | ||
export { IdentityManager, IIdentityManager } from './identity-manager'; | ||
export { KeyManager, IKeyManager } from './key-manager'; | ||
export { MessageHandler, IHandleMessage } from './message-handler'; | ||
export { Message } from './message'; | ||
export { AbstractIdentityProvider } from './abstract/abstract-identity-provider'; | ||
export { AbstractKeyManagementSystem } from './abstract/abstract-key-management-system'; | ||
export { AbstractIdentityStore } from './abstract/abstract-identity-store'; | ||
export { AbstractKeyStore } from './abstract/abstract-key-store'; | ||
export { AbstractSecretBox } from './abstract/abstract-secret-box'; | ||
export { AbstractMessageHandler } from './abstract/abstract-message-handler'; | ||
export { DIDDocument } from 'did-resolver'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* The main library for creating Decentralized Identity Agents | ||
* | ||
* @packageDocumentation | ||
*/ | ||
var agent_1 = require("./agent"); | ||
exports.Agent = agent_1.Agent; | ||
exports.EventTypes = agent_1.EventTypes; | ||
var action_handler_1 = require("./action/action-handler"); | ||
exports.AbstractActionHandler = action_handler_1.AbstractActionHandler; | ||
var identity_manager_1 = require("./identity/identity-manager"); | ||
exports.IdentityManager = identity_manager_1.IdentityManager; | ||
var abstract_identity_1 = require("./identity/abstract-identity"); | ||
exports.AbstractIdentity = abstract_identity_1.AbstractIdentity; | ||
var abstract_identity_controller_1 = require("./identity/abstract-identity-controller"); | ||
exports.AbstractIdentityController = abstract_identity_controller_1.AbstractIdentityController; | ||
var abstract_identity_provider_1 = require("./identity/abstract-identity-provider"); | ||
exports.AbstractIdentityProvider = abstract_identity_provider_1.AbstractIdentityProvider; | ||
var abstract_key_management_system_1 = require("./identity/abstract-key-management-system"); | ||
exports.AbstractKeyManagementSystem = abstract_key_management_system_1.AbstractKeyManagementSystem; | ||
exports.AbstractKey = abstract_key_management_system_1.AbstractKey; | ||
var abstract_identity_store_1 = require("./identity/abstract-identity-store"); | ||
exports.AbstractIdentityStore = abstract_identity_store_1.AbstractIdentityStore; | ||
var abstract_key_store_1 = require("./identity/abstract-key-store"); | ||
exports.AbstractKeyStore = abstract_key_store_1.AbstractKeyStore; | ||
var abstract_secret_box_1 = require("./identity/abstract-secret-box"); | ||
exports.AbstractSecretBox = abstract_secret_box_1.AbstractSecretBox; | ||
var abstract_message_handler_1 = require("./message/abstract-message-handler"); | ||
exports.AbstractMessageHandler = abstract_message_handler_1.AbstractMessageHandler; | ||
var service_manager_1 = require("./service/service-manager"); | ||
exports.ServiceManager = service_manager_1.ServiceManager; | ||
exports.ServiceEventTypes = service_manager_1.ServiceEventTypes; | ||
var abstract_service_controller_1 = require("./service/abstract-service-controller"); | ||
exports.AbstractServiceController = abstract_service_controller_1.AbstractServiceController; | ||
var index_1 = require("./graphql/index"); | ||
exports.Gql = index_1.Gql; | ||
var identity_store_1 = require("./identity/identity-store"); | ||
exports.IdentityStore = identity_store_1.IdentityStore; | ||
var key_store_1 = require("./identity/key-store"); | ||
exports.KeyStore = key_store_1.KeyStore; | ||
var key_1 = require("./entities/key"); | ||
exports.Key = key_1.Key; | ||
var identity_1 = require("./entities/identity"); | ||
exports.Identity = identity_1.Identity; | ||
var claim_1 = require("./entities/claim"); | ||
exports.Claim = claim_1.Claim; | ||
var credential_1 = require("./entities/credential"); | ||
exports.Credential = credential_1.Credential; | ||
var presentation_1 = require("./entities/presentation"); | ||
exports.Presentation = presentation_1.Presentation; | ||
var message_1 = require("./entities/message"); | ||
exports.Message = message_1.Message; | ||
exports.Entities = [key_1.Key, identity_1.Identity, message_1.Message, claim_1.Claim, credential_1.Credential, presentation_1.Presentation]; | ||
var migrations_1 = require("./migrations"); | ||
exports.migrations = migrations_1.migrations; | ||
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } }); | ||
Object.defineProperty(exports, "createAgent", { enumerable: true, get: function () { return agent_1.createAgent; } }); | ||
__exportStar(require("./types"), exports); | ||
var identity_manager_1 = require("./identity-manager"); | ||
Object.defineProperty(exports, "IdentityManager", { enumerable: true, get: function () { return identity_manager_1.IdentityManager; } }); | ||
var key_manager_1 = require("./key-manager"); | ||
Object.defineProperty(exports, "KeyManager", { enumerable: true, get: function () { return key_manager_1.KeyManager; } }); | ||
var message_handler_1 = require("./message-handler"); | ||
Object.defineProperty(exports, "MessageHandler", { enumerable: true, get: function () { return message_handler_1.MessageHandler; } }); | ||
var message_1 = require("./message"); | ||
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.Message; } }); | ||
var abstract_identity_provider_1 = require("./abstract/abstract-identity-provider"); | ||
Object.defineProperty(exports, "AbstractIdentityProvider", { enumerable: true, get: function () { return abstract_identity_provider_1.AbstractIdentityProvider; } }); | ||
var abstract_key_management_system_1 = require("./abstract/abstract-key-management-system"); | ||
Object.defineProperty(exports, "AbstractKeyManagementSystem", { enumerable: true, get: function () { return abstract_key_management_system_1.AbstractKeyManagementSystem; } }); | ||
var abstract_identity_store_1 = require("./abstract/abstract-identity-store"); | ||
Object.defineProperty(exports, "AbstractIdentityStore", { enumerable: true, get: function () { return abstract_identity_store_1.AbstractIdentityStore; } }); | ||
var abstract_key_store_1 = require("./abstract/abstract-key-store"); | ||
Object.defineProperty(exports, "AbstractKeyStore", { enumerable: true, get: function () { return abstract_key_store_1.AbstractKeyStore; } }); | ||
var abstract_secret_box_1 = require("./abstract/abstract-secret-box"); | ||
Object.defineProperty(exports, "AbstractSecretBox", { enumerable: true, get: function () { return abstract_secret_box_1.AbstractSecretBox; } }); | ||
var abstract_message_handler_1 = require("./abstract/abstract-message-handler"); | ||
Object.defineProperty(exports, "AbstractMessageHandler", { enumerable: true, get: function () { return abstract_message_handler_1.AbstractMessageHandler; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,87 @@ | ||
export interface Action { | ||
import { DIDDocument } from 'did-resolver'; | ||
import { Verifiable, W3CCredential, W3CPresentation } from 'did-jwt-vc'; | ||
export declare type VerifiableCredential = Verifiable<W3CCredential>; | ||
export declare type VerifiablePresentation = Verifiable<W3CPresentation>; | ||
export { W3CCredential, W3CPresentation }; | ||
export declare type TKeyType = 'Ed25519' | 'Secp256k1'; | ||
export interface IKey { | ||
kid: string; | ||
kms: string; | ||
type: TKeyType; | ||
publicKeyHex: string; | ||
privateKeyHex?: string; | ||
meta?: Record<string, any>; | ||
} | ||
export interface IService { | ||
id: string; | ||
type: string; | ||
data: any; | ||
serviceEndpoint: string; | ||
description?: string; | ||
} | ||
export interface IIdentity { | ||
did: string; | ||
alias?: string; | ||
provider: string; | ||
controllerKeyId: string; | ||
keys: IKey[]; | ||
services: IService[]; | ||
} | ||
export interface EcdsaSignature { | ||
r: string; | ||
s: string; | ||
recoveryParam?: number; | ||
} | ||
export interface IMetaData { | ||
type: string; | ||
value?: string; | ||
} | ||
export interface IMessage { | ||
id: string; | ||
type: string; | ||
createdAt?: string; | ||
expiresAt?: string; | ||
threadId?: string; | ||
raw?: string; | ||
data?: any; | ||
replyTo?: string[]; | ||
replyUrl?: string; | ||
from?: string; | ||
to?: string; | ||
metaData?: IMetaData[]; | ||
credentials?: VerifiableCredential[]; | ||
presentations?: VerifiablePresentation[]; | ||
} | ||
export interface IAgentBase { | ||
availableMethods: () => string[]; | ||
} | ||
export interface IAgent extends IAgentBase { | ||
execute: <A = any, R = any>(method: string, args: A) => Promise<R>; | ||
} | ||
export interface IPluginMethod { | ||
(args: any, context: any): Promise<any>; | ||
} | ||
export interface IPluginMethodMap extends Record<string, IPluginMethod> { | ||
} | ||
export interface IAgentPlugin { | ||
readonly methods: IPluginMethodMap; | ||
} | ||
export interface RemoveContext<T extends IPluginMethod> { | ||
(args?: Parameters<T>[0] | undefined): ReturnType<T>; | ||
} | ||
export declare type TAgent<T extends IPluginMethodMap> = { | ||
[P in keyof T]: RemoveContext<T[P]>; | ||
} & Pick<IAgentBase, 'availableMethods'>; | ||
export interface IAgentContext<T extends IPluginMethodMap> { | ||
agent: TAgent<T>; | ||
} | ||
export interface IDataStore extends IPluginMethodMap { | ||
dataStoreSaveMessage(args: IMessage): Promise<boolean>; | ||
dataStoreSaveVerifiableCredential(args: VerifiableCredential): Promise<boolean>; | ||
dataStoreSaveVerifiablePresentation(args: VerifiablePresentation): Promise<boolean>; | ||
} | ||
export interface IResolveDid extends IPluginMethodMap { | ||
resolveDid(args: { | ||
didUrl: string; | ||
}): Promise<DIDDocument>; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
128
CHANGELOG.md
@@ -6,37 +6,36 @@ # Change Log | ||
## [6.1.1](https://github.com/uport-project/daf/compare/v6.1.0...v6.1.1) (2020-07-06) | ||
# [7.0.0-beta.1](https://github.com/uport-project/daf/compare/v6.1.1...v7.0.0-beta.1) (2020-07-07) | ||
**Note:** Version bump only for package daf-core | ||
### Bug Fixes | ||
- IdentityManager ([4d2fc90](https://github.com/uport-project/daf/commit/4d2fc9035f409b376c9843c4dc937605da7e0baa)) | ||
- IdentityManager ([396871c](https://github.com/uport-project/daf/commit/396871c436f151c80abc4dac60b94ea3e776aa41)) | ||
- KeyManagerSignEthTX ([6031817](https://github.com/uport-project/daf/commit/60318170f77e532e95c125196088a87bc5978446)) | ||
- MessageHandler chain ([3e6b595](https://github.com/uport-project/daf/commit/3e6b59563b8feac62d6fbf55b541d1efa517e174)) | ||
### Features | ||
- Authorized agent methods ([1894302](https://github.com/uport-project/daf/commit/1894302fda9b7e5bd8b7e472146aa77b86225cec)) | ||
- Debug agent.execute ([6b8fb1b](https://github.com/uport-project/daf/commit/6b8fb1b67779e250020ee26aeb0d7c09703e1cd9)) | ||
## [6.1.1](https://github.com/uport-project/daf/compare/v6.1.0...v6.1.1) (2020-07-06) | ||
**Note:** Version bump only for package daf-core | ||
# [6.0.0](https://github.com/uport-project/daf/compare/v5.7.0...v6.0.0) (2020-05-29) | ||
### Bug Fixes | ||
* Big value handling ([#167](https://github.com/uport-project/daf/issues/167)) ([39a76b6](https://github.com/uport-project/daf/commit/39a76b60ecc085d7ce0c476b0b20e166b415d408)) | ||
- Big value handling ([#167](https://github.com/uport-project/daf/issues/167)) ([39a76b6](https://github.com/uport-project/daf/commit/39a76b60ecc085d7ce0c476b0b20e166b415d408)) | ||
### BREAKING CHANGES | ||
* database schema change required to accept large claims | ||
- database schema change required to accept large claims | ||
# [5.7.0](https://github.com/uport-project/daf/compare/v5.6.7...v5.7.0) (2020-05-29) | ||
### Features | ||
* Identity provider for did:web ([9b20fb1](https://github.com/uport-project/daf/commit/9b20fb13da21865d50f6e0680e0d7da040a3d75c)) | ||
- Identity provider for did:web ([9b20fb1](https://github.com/uport-project/daf/commit/9b20fb13da21865d50f6e0680e0d7da040a3d75c)) | ||
## [5.6.6](https://github.com/uport-project/daf/compare/v5.6.5...v5.6.6) (2020-05-26) | ||
@@ -46,148 +45,87 @@ | ||
## [5.6.5](https://github.com/uport-project/daf/compare/v5.6.4...v5.6.5) (2020-05-25) | ||
### Bug Fixes | ||
* GraphQL orderBy ([bb06094](https://github.com/uport-project/daf/commit/bb060941fab367540d1fd8cdbc4ad6de51fb00ab)) | ||
- GraphQL orderBy ([bb06094](https://github.com/uport-project/daf/commit/bb060941fab367540d1fd8cdbc4ad6de51fb00ab)) | ||
## [5.6.4](https://github.com/uport-project/daf/compare/v5.6.3...v5.6.4) (2020-05-22) | ||
### Bug Fixes | ||
* Credential id type ([39d8d18](https://github.com/uport-project/daf/commit/39d8d18ce7c87db179a4fcb73fc333c544ce841f)) | ||
- Credential id type ([39d8d18](https://github.com/uport-project/daf/commit/39d8d18ce7c87db179a4fcb73fc333c544ce841f)) | ||
# [5.5.0](https://github.com/uport-project/daf/compare/v5.4.0...v5.5.0) (2020-05-13) | ||
### Features | ||
* CLI config ([5a3391e](https://github.com/uport-project/daf/commit/5a3391e77790e0b10268c4e189f34c5f20246616)) | ||
- CLI config ([5a3391e](https://github.com/uport-project/daf/commit/5a3391e77790e0b10268c4e189f34c5f20246616)) | ||
# [5.1.0](https://github.com/uport-project/daf/compare/v5.0.0...v5.1.0) (2020-05-06) | ||
### Bug Fixes | ||
* resolvers and handlers didn't match schema ([85c38a2](https://github.com/uport-project/daf/commit/85c38a206a163e3ed601b1ad2ac330f275d7ac4a)) | ||
- resolvers and handlers didn't match schema ([85c38a2](https://github.com/uport-project/daf/commit/85c38a206a163e3ed601b1ad2ac330f275d7ac4a)) | ||
### Features | ||
* pass along authentication metadata into handlers ([199426b](https://github.com/uport-project/daf/commit/199426b4dba9013d34fea92585583487abdae041)) | ||
- pass along authentication metadata into handlers ([199426b](https://github.com/uport-project/daf/commit/199426b4dba9013d34fea92585583487abdae041)) | ||
# [5.0.0](https://github.com/uport-project/daf/compare/v4.5.0...v5.0.0) (2020-05-05) | ||
### Bug Fixes | ||
* fixes failing audience query tests ([40408dc](https://github.com/uport-project/daf/commit/40408dce03a3c23dff07c89f2455d89c60893ebf)) | ||
* Remove static Credential.credentialStatus ([f9a06af](https://github.com/uport-project/daf/commit/f9a06afcd01fc9e0452535d10d32158414490ea4)) | ||
- fixes failing audience query tests ([40408dc](https://github.com/uport-project/daf/commit/40408dce03a3c23dff07c89f2455d89c60893ebf)) | ||
- Remove static Credential.credentialStatus ([f9a06af](https://github.com/uport-project/daf/commit/f9a06afcd01fc9e0452535d10d32158414490ea4)) | ||
### Features | ||
* Multiple audience dids ([eaa1a40](https://github.com/uport-project/daf/commit/eaa1a40d9d3728533be63660ad4cdef6bdbdeded)) | ||
- Multiple audience dids ([eaa1a40](https://github.com/uport-project/daf/commit/eaa1a40d9d3728533be63660ad4cdef6bdbdeded)) | ||
### BREAKING CHANGES | ||
* DB Schema change | ||
- DB Schema change | ||
# [4.5.0](https://github.com/uport-project/daf/compare/v4.4.0...v4.5.0) (2020-05-05) | ||
### Bug Fixes | ||
* Remove static Credential.credentialStatus ([719fddc](https://github.com/uport-project/daf/commit/719fddc558dd7ec2925e3a8d695a5de4c65e91cd)) | ||
- Remove static Credential.credentialStatus ([719fddc](https://github.com/uport-project/daf/commit/719fddc558dd7ec2925e3a8d695a5de4c65e91cd)) | ||
# [4.4.0](https://github.com/uport-project/daf/compare/v4.3.0...v4.4.0) (2020-04-29) | ||
### Bug Fixes | ||
* DB migrations ([14b578e](https://github.com/uport-project/daf/commit/14b578e87740cd3d19e5ae728791a192cc50bc4c)) | ||
- DB migrations ([14b578e](https://github.com/uport-project/daf/commit/14b578e87740cd3d19e5ae728791a192cc50bc4c)) | ||
### Features | ||
* Encrypting private keys with SecretBox ([8833931](https://github.com/uport-project/daf/commit/883393192cc830534cfec892b4ce271a09bff99d)) | ||
- Encrypting private keys with SecretBox ([8833931](https://github.com/uport-project/daf/commit/883393192cc830534cfec892b4ce271a09bff99d)) | ||
# [4.3.0](https://github.com/uport-project/daf/compare/v4.2.1...v4.3.0) (2020-04-28) | ||
### Bug Fixes | ||
* CredentialStatus field type ([40e97a6](https://github.com/uport-project/daf/commit/40e97a6e6daeb8357332456967799a18434bfbaf)) | ||
- CredentialStatus field type ([40e97a6](https://github.com/uport-project/daf/commit/40e97a6e6daeb8357332456967799a18434bfbaf)) | ||
### Features | ||
* Credential Status in data model ([24e2d5d](https://github.com/uport-project/daf/commit/24e2d5d1e46a33dde96e7a519b171c0453d34401)) | ||
* DB Migration CredentialStatus ([44fd36d](https://github.com/uport-project/daf/commit/44fd36d0a97af96bfca74d1a9953293c00003dcc)) | ||
- Credential Status in data model ([24e2d5d](https://github.com/uport-project/daf/commit/24e2d5d1e46a33dde96e7a519b171c0453d34401)) | ||
- DB Migration CredentialStatus ([44fd36d](https://github.com/uport-project/daf/commit/44fd36d0a97af96bfca74d1a9953293c00003dcc)) | ||
# [4.2.0](https://github.com/uport-project/daf/compare/v4.1.0...v4.2.0) (2020-04-24) | ||
### Features | ||
* Optionally add permissions to gql resolvers ([0d5b212](https://github.com/uport-project/daf/commit/0d5b2126618d81e5f0d1ba5ae30fc33901b8dc94)) | ||
- Optionally add permissions to gql resolvers ([0d5b212](https://github.com/uport-project/daf/commit/0d5b2126618d81e5f0d1ba5ae30fc33901b8dc94)) | ||
# [4.1.0](https://github.com/uport-project/daf/compare/v4.0.0...v4.1.0) (2020-04-23) | ||
## [3.4.2](https://github.com/uport-project/daf/compare/v3.4.1...v3.4.2) (2020-03-23) | ||
### Bug Fixes | ||
* Generating message.id if not set ([5ce04e5](https://github.com/uport-project/daf/commit/5ce04e5f8ebbba4368b84dffc563696d79a8fee2)) | ||
* Removing uuid from id ([df12094](https://github.com/uport-project/daf/commit/df1209461b4b197b5f19c9d5bf4a71caf0c57f7d)) | ||
- Generating message.id if not set ([5ce04e5](https://github.com/uport-project/daf/commit/5ce04e5f8ebbba4368b84dffc563696d79a8fee2)) | ||
- Removing uuid from id ([df12094](https://github.com/uport-project/daf/commit/df1209461b4b197b5f19c9d5bf4a71caf0c57f7d)) | ||
# [4.0.0](https://github.com/uport-project/daf/compare/v4.0.0-beta.48...v4.0.0) (2020-04-22) | ||
@@ -194,0 +132,0 @@ |
{ | ||
"name": "daf-core", | ||
"description": "DID Agent Framework Core", | ||
"version": "6.1.1", | ||
"version": "7.0.0-beta.1", | ||
"main": "build/index.js", | ||
@@ -11,7 +11,5 @@ "types": "build/index.d.ts", | ||
"dependencies": { | ||
"blakejs": "^1.1.0", | ||
"debug": "^4.1.1", | ||
"events": "^3.0.0", | ||
"typeorm": "^0.2.24", | ||
"uuid": "^7.0.2" | ||
"did-jwt-vc": "^1.0.2", | ||
"events": "^3.0.0" | ||
}, | ||
@@ -33,3 +31,3 @@ "devDependencies": { | ||
"keywords": [], | ||
"gitHead": "654f583d2ad3236fdf41da5b27ac288749e2f138" | ||
"gitHead": "43029ee5a2b705a37e43db8923d6b7f40d0acdf0" | ||
} |
205
src/agent.ts
@@ -1,135 +0,110 @@ | ||
import { EventEmitter } from 'events' | ||
import { DIDDocument } from 'did-resolver' | ||
import { IdentityManager } from './identity/identity-manager' | ||
import { AbstractIdentityProvider } from './identity/abstract-identity-provider' | ||
import { ServiceManager, LastMessageTimestampForInstance, ServiceEventTypes } from './service/service-manager' | ||
import { ServiceControllerDerived } from './service/abstract-service-controller' | ||
import { MessageHandler } from './message/abstract-message-handler' | ||
import { ActionHandler } from './action/action-handler' | ||
import { Action } from './types' | ||
import { Message, MetaData } from './entities/message' | ||
import { Connection } from 'typeorm' | ||
import { IAgent, IPluginMethodMap, IAgentPlugin } from './types' | ||
import Debug from 'debug' | ||
const debug = Debug('daf:agent') | ||
export const EventTypes = { | ||
validatedMessage: 'validatedMessage', | ||
savedMessage: 'savedMessage', | ||
error: 'error', | ||
} | ||
export interface Resolver { | ||
resolve(did: string): Promise<DIDDocument | null> | ||
} | ||
interface Config { | ||
dbConnection?: Promise<Connection> | ||
didResolver: Resolver | ||
identityProviders: AbstractIdentityProvider[] | ||
serviceControllers?: ServiceControllerDerived[] | ||
messageHandler?: MessageHandler | ||
actionHandler?: ActionHandler | ||
} | ||
export class Agent extends EventEmitter { | ||
readonly dbConnection: Promise<Connection> | ||
public identityManager: IdentityManager | ||
public didResolver: Resolver | ||
private serviceManager: ServiceManager | ||
private messageHandler?: MessageHandler | ||
private actionHandler?: ActionHandler | ||
constructor(config: Config) { | ||
super() | ||
this.dbConnection = config.dbConnection || null | ||
this.identityManager = new IdentityManager({ | ||
identityProviders: config.identityProviders, | ||
}) | ||
this.didResolver = config.didResolver | ||
this.serviceManager = new ServiceManager({ | ||
controllers: config.serviceControllers || [], | ||
didResolver: this.didResolver, | ||
}) | ||
this.messageHandler = config.messageHandler | ||
this.actionHandler = config.actionHandler | ||
/** | ||
* Filters unauthorized methods. By default all methods are authorized | ||
* @internal | ||
*/ | ||
const filterUnauthorizedMethods = ( | ||
methods: IPluginMethodMap, | ||
authorizedMethods?: string[], | ||
): IPluginMethodMap => { | ||
if (!authorizedMethods) { | ||
return methods | ||
} | ||
async setupServices() { | ||
const identities = await this.identityManager.getIdentities() | ||
await this.serviceManager.setupServices(identities) | ||
const result: IPluginMethodMap = {} | ||
for (const methodName of Object.keys(methods)) { | ||
if (authorizedMethods.includes(methodName)) { | ||
result[methodName] = methods[methodName] | ||
} | ||
} | ||
async listen() { | ||
debug('Listening for new messages') | ||
this.serviceManager.on(ServiceEventTypes.NewMessages, this.handleServiceMessages.bind(this)) | ||
this.serviceManager.listen() | ||
} | ||
return result | ||
} | ||
async getMessagesSince(ts: LastMessageTimestampForInstance[]): Promise<Message[]> { | ||
const rawMessages = await this.serviceManager.getMessagesSince(ts) | ||
return this.handleServiceMessages(rawMessages) | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface IAgentOptions { | ||
plugins?: IAgentPlugin[] | ||
overrides?: IPluginMethodMap | ||
authorizedMethods?: string[] | ||
context?: Record<string, any> | ||
} | ||
private async handleServiceMessages(messages: Message[]): Promise<Message[]> { | ||
const result: Message[] = [] | ||
for (const message of messages) { | ||
try { | ||
const validMessage = await this.handleMessage({ | ||
raw: message.raw, | ||
metaData: message.metaData, | ||
}) | ||
result.push(validMessage) | ||
} catch (e) {} | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export class Agent implements IAgent { | ||
readonly methods: IPluginMethodMap = {} | ||
private context?: Record<string, any> | ||
private protectedMethods = ['execute', 'availableMethods'] | ||
return result | ||
} | ||
constructor(options?: IAgentOptions) { | ||
this.context = options?.context | ||
public async handleMessage({ | ||
raw, | ||
metaData, | ||
save = true, | ||
}: { | ||
raw: string | ||
metaData?: MetaData[] | ||
save?: boolean | ||
}): Promise<Message> { | ||
debug('Handle message %o', { raw, metaData, save }) | ||
if (!this.messageHandler) { | ||
return Promise.reject('Message handler not provided') | ||
if (options?.plugins) { | ||
for (const plugin of options.plugins) { | ||
this.methods = { | ||
...this.methods, | ||
...filterUnauthorizedMethods(plugin.methods, options.authorizedMethods), | ||
} | ||
} | ||
} | ||
try { | ||
const message = await this.messageHandler.handle(new Message({ raw, metaData }), this) | ||
if (message.isValid()) { | ||
debug('Emitting event', EventTypes.validatedMessage) | ||
this.emit(EventTypes.validatedMessage, message) | ||
if (options?.overrides) { | ||
this.methods = { | ||
...this.methods, | ||
...filterUnauthorizedMethods(options.overrides, options.authorizedMethods), | ||
} | ||
} | ||
debug('Validated message %o', message) | ||
if (save) { | ||
await (await this.dbConnection).getRepository(Message).save(message) | ||
debug('Emitting event', EventTypes.savedMessage) | ||
this.emit(EventTypes.savedMessage, message) | ||
for (const method of Object.keys(this.methods)) { | ||
if (!this.protectedMethods.includes(method)) { | ||
//@ts-ignore | ||
this[method] = async (args: any) => this.execute(method, args) | ||
} | ||
return message | ||
} catch (error) { | ||
this.emit(EventTypes.error, error) | ||
return Promise.reject(error) | ||
} | ||
} | ||
public async handleAction(action: Action): Promise<any> { | ||
if (!this.actionHandler) { | ||
return Promise.reject('Action handler not provided') | ||
} | ||
debug('Handle action %o', action) | ||
return this.actionHandler.handleAction(action, this) | ||
availableMethods() { | ||
return Object.keys(this.methods) | ||
} | ||
async execute<P = any, R = any>(method: string, args: P): Promise<R> { | ||
Debug('daf:agent:' + method)('%o', args) | ||
if (!this.methods[method]) throw Error('Method not available: ' + method) | ||
const result = await this.methods[method](args, { ...this.context, agent: this }) | ||
Debug('daf:agent:' + method + ':result')('%o', result) | ||
return result | ||
} | ||
} | ||
/** | ||
* Returns a new instance of the {@link Agent} class. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { createAgent, TAgent, IResolveDid, IHandleMessage } from 'daf-core' | ||
* import { AgentRestClient } from 'daf-rest' | ||
* const agent = createAgent<TAgent<IResolveDid & IHandleMessage>>({ | ||
* plugins: [ | ||
* new AgentRestClient({ | ||
* url: 'http://localhost:3002/agent', | ||
* enabledMethods: [ | ||
* 'resolveDid', | ||
* 'handleMessage', | ||
* ], | ||
* }), | ||
* ], | ||
* }) | ||
* ``` | ||
* @param options - Agent configuration options | ||
* @returns configured agent | ||
* @public | ||
*/ | ||
export function createAgent<T>(options: IAgentOptions): T { | ||
//@ts-ignore | ||
return new Agent(options) | ||
} |
@@ -1,34 +0,18 @@ | ||
export { Agent, EventTypes, Resolver } from './agent' | ||
export { AbstractActionHandler } from './action/action-handler' | ||
export { IdentityManager } from './identity/identity-manager' | ||
export { AbstractIdentity } from './identity/abstract-identity' | ||
export { AbstractIdentityController } from './identity/abstract-identity-controller' | ||
export { AbstractIdentityProvider, IdentityProviderDerived } from './identity/abstract-identity-provider' | ||
export { | ||
AbstractKeyManagementSystem, | ||
AbstractKey, | ||
SerializedKey, | ||
} from './identity/abstract-key-management-system' | ||
export { AbstractIdentityStore, SerializedIdentity } from './identity/abstract-identity-store' | ||
export { AbstractKeyStore } from './identity/abstract-key-store' | ||
export { AbstractSecretBox } from './identity/abstract-secret-box' | ||
export { AbstractMessageHandler } from './message/abstract-message-handler' | ||
export { ServiceManager, LastMessageTimestampForInstance, ServiceEventTypes } from './service/service-manager' | ||
export { AbstractServiceController } from './service/abstract-service-controller' | ||
export { Gql } from './graphql/index' | ||
export { Action } from './types' | ||
export { IdentityStore } from './identity/identity-store' | ||
export { KeyStore } from './identity/key-store' | ||
import { Key, KeyType } from './entities/key' | ||
import { Identity } from './entities/identity' | ||
import { Claim } from './entities/claim' | ||
import { Credential } from './entities/credential' | ||
import { Presentation } from './entities/presentation' | ||
import { Message, MetaData } from './entities/message' | ||
export const Entities = [Key, Identity, Message, Claim, Credential, Presentation] | ||
export { KeyType, Key, Identity, Message, Claim, Credential, Presentation, MetaData } | ||
export { migrations } from './migrations' | ||
/** | ||
* The main library for creating Decentralized Identity Agents | ||
* | ||
* @packageDocumentation | ||
*/ | ||
export { Agent, createAgent, IAgentOptions } from './agent' | ||
export * from './types' | ||
export { IdentityManager, IIdentityManager } from './identity-manager' | ||
export { KeyManager, IKeyManager } from './key-manager' | ||
export { MessageHandler, IHandleMessage } from './message-handler' | ||
export { Message } from './message' | ||
export { AbstractIdentityProvider } from './abstract/abstract-identity-provider' | ||
export { AbstractKeyManagementSystem } from './abstract/abstract-key-management-system' | ||
export { AbstractIdentityStore } from './abstract/abstract-identity-store' | ||
export { AbstractKeyStore } from './abstract/abstract-key-store' | ||
export { AbstractSecretBox } from './abstract/abstract-secret-box' | ||
export { AbstractMessageHandler } from './abstract/abstract-message-handler' | ||
export { DIDDocument } from 'did-resolver' |
103
src/types.ts
@@ -1,4 +0,103 @@ | ||
export interface Action { | ||
import { DIDDocument } from 'did-resolver' | ||
import { Verifiable, W3CCredential, W3CPresentation } from 'did-jwt-vc' | ||
export type VerifiableCredential = Verifiable<W3CCredential> | ||
export type VerifiablePresentation = Verifiable<W3CPresentation> | ||
export { W3CCredential, W3CPresentation } | ||
export type TKeyType = 'Ed25519' | 'Secp256k1' | ||
export interface IKey { | ||
kid: string | ||
kms: string | ||
type: TKeyType | ||
publicKeyHex: string | ||
privateKeyHex?: string | ||
meta?: Record<string, any> | ||
} | ||
export interface IService { | ||
id: string | ||
type: string | ||
data: any | ||
serviceEndpoint: string | ||
description?: string | ||
} | ||
export interface IIdentity { | ||
did: string | ||
alias?: string | ||
provider: string | ||
controllerKeyId: string | ||
keys: IKey[] | ||
services: IService[] | ||
} | ||
// Todo make it a String | ||
export interface EcdsaSignature { | ||
r: string | ||
s: string | ||
recoveryParam?: number | ||
} | ||
export interface IMetaData { | ||
type: string | ||
value?: string | ||
} | ||
export interface IMessage { | ||
id: string | ||
type: string | ||
createdAt?: string | ||
expiresAt?: string | ||
threadId?: string | ||
raw?: string | ||
data?: any | ||
replyTo?: string[] | ||
replyUrl?: string | ||
from?: string | ||
to?: string | ||
metaData?: IMetaData[] | ||
credentials?: VerifiableCredential[] | ||
presentations?: VerifiablePresentation[] | ||
} | ||
export interface IAgentBase { | ||
availableMethods: () => string[] | ||
} | ||
export interface IAgent extends IAgentBase { | ||
execute: <A = any, R = any>(method: string, args: A) => Promise<R> | ||
} | ||
export interface IPluginMethod { | ||
(args: any, context: any): Promise<any> | ||
} | ||
export interface IPluginMethodMap extends Record<string, IPluginMethod> {} | ||
export interface IAgentPlugin { | ||
readonly methods: IPluginMethodMap | ||
} | ||
export interface RemoveContext<T extends IPluginMethod> { | ||
(args?: Parameters<T>[0] | undefined): ReturnType<T> | ||
} | ||
export type TAgent<T extends IPluginMethodMap> = { | ||
[P in keyof T]: RemoveContext<T[P]> | ||
} & | ||
Pick<IAgentBase, 'availableMethods'> | ||
export interface IAgentContext<T extends IPluginMethodMap> { | ||
agent: TAgent<T> | ||
} | ||
export interface IDataStore extends IPluginMethodMap { | ||
dataStoreSaveMessage(args: IMessage): Promise<boolean> | ||
dataStoreSaveVerifiableCredential(args: VerifiableCredential): Promise<boolean> | ||
dataStoreSaveVerifiablePresentation(args: VerifiablePresentation): Promise<boolean> | ||
} | ||
export interface IResolveDid extends IPluginMethodMap { | ||
resolveDid(args: { didUrl: string }): Promise<DIDDocument> | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
3
1
155174
71
2190
2
1
+ Addeddid-jwt-vc@^1.0.2
+ Added@babel/runtime@7.26.0(transitive)
+ Added@stablelib/aead@1.0.1(transitive)
+ Added@stablelib/binary@1.0.1(transitive)
+ Added@stablelib/bytes@1.0.1(transitive)
+ Added@stablelib/chacha@1.0.1(transitive)
+ Added@stablelib/chacha20poly1305@1.0.1(transitive)
+ Added@stablelib/constant-time@1.0.1(transitive)
+ Added@stablelib/ed25519@1.0.3(transitive)
+ Added@stablelib/hash@1.0.1(transitive)
+ Added@stablelib/int@1.0.1(transitive)
+ Added@stablelib/keyagreement@1.0.1(transitive)
+ Added@stablelib/poly1305@1.0.1(transitive)
+ Added@stablelib/random@1.0.2(transitive)
+ Added@stablelib/sha256@1.0.1(transitive)
+ Added@stablelib/sha512@1.0.1(transitive)
+ Added@stablelib/wipe@1.0.1(transitive)
+ Added@stablelib/x25519@1.0.3(transitive)
+ Added@stablelib/xchacha20@1.0.1(transitive)
+ Added@stablelib/xchacha20poly1305@1.0.1(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addeddid-jwt@4.9.0(transitive)
+ Addeddid-jwt-vc@1.2.0(transitive)
+ Addeddid-resolver@2.2.0(transitive)
+ Addedelliptic@6.6.1(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedjs-sha3@0.8.0(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedmultiformats@9.9.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addeduint8arrays@2.1.10(transitive)
- Removedblakejs@^1.1.0
- Removedtypeorm@^0.2.24
- Removeduuid@^7.0.2
- Removed@sqltools/formatter@1.2.5(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedany-promise@1.3.0(transitive)
- Removedapp-root-path@3.1.0(transitive)
- Removedargparse@2.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedblakejs@1.2.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcli-highlight@2.1.11(transitive)
- Removedcliui@7.0.48.0.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddotenv@8.6.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescalade@3.2.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedhighlight.js@10.7.3(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedmz@2.7.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedparse5@5.1.16.0.1(transitive)
- Removedparse5-htmlparser2-tree-adapter@6.0.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedreflect-metadata@0.1.14(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsax@1.4.1(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedthenify@3.3.1(transitive)
- Removedthenify-all@1.6.0(transitive)
- Removedtslib@2.8.1(transitive)
- Removedtypeorm@0.2.45(transitive)
- Removeduuid@7.0.38.3.2(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxml2js@0.4.23(transitive)
- Removedxmlbuilder@11.0.1(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@16.2.017.7.2(transitive)
- Removedyargs-parser@20.2.921.1.1(transitive)
- Removedzen-observable@0.8.15(transitive)
- Removedzen-observable-ts@1.2.5(transitive)