diff --git a/packages/daf-cli/src/setup.ts b/packages/daf-cli/src/setup.ts index e14bf4a5c..5d3663649 100644 --- a/packages/daf-cli/src/setup.ts +++ b/packages/daf-cli/src/setup.ts @@ -17,7 +17,7 @@ import { DataStore } from 'daf-data-store' import ws from 'ws' import Debug from 'debug' -const debug = Debug('main') +const debug = Debug('daf:cli') const defaultPath = process.env.HOME + '/.daf' diff --git a/packages/daf-core/src/old-service-manager.ts b/packages/daf-core/src/old-service-manager.ts deleted file mode 100644 index d4c45a480..000000000 --- a/packages/daf-core/src/old-service-manager.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { DIDDocument } from 'did-resolver' -import { Resolver } from './core' -import { Issuer } from './identity/identity-manager' -import { Message } from './message/message' - -export interface ServiceControllerOptions { - config: any - issuer: Issuer - didDoc: DIDDocument - validateMessage: (message: Message) => Promise -} - -export interface ServiceInstanceId { - sourceType: string - did: string -} - -export interface LastMessageTimestamp extends ServiceInstanceId { - timestamp: number -} - -export declare class ServiceController { - constructor(options: ServiceControllerOptions) - sync: (since: number) => Promise - init: () => Promise - instanceId: () => ServiceInstanceId -} - -export type ServiceControllerWithConfig = { - controller: typeof ServiceController - config: any -} - -interface Options { - didResolver: Resolver - serviceControllersWithConfig: ServiceControllerWithConfig[] - validateMessage: (message: Message) => Promise -} - -export class ServiceManager { - private serviceControllersWithConfig: ServiceControllerWithConfig[] - private validateMessage: (message: Message) => Promise - private serviceControllers: ServiceController[] - private didResolver: Resolver - - constructor(options: Options) { - this.serviceControllersWithConfig = options.serviceControllersWithConfig - this.validateMessage = options.validateMessage - this.serviceControllers = [] - this.didResolver = options.didResolver - } - - async configureServices(issuers: Issuer[]) { - for (const issuer of issuers) { - const didDoc = await this.didResolver.resolve(issuer.did) - if (didDoc !== null) { - for (const { controller, config } of this.serviceControllersWithConfig) { - this.serviceControllers.push( - new controller({ - config, - issuer, - didDoc, - validateMessage: this.validateMessage, - }), - ) - } - } - } - } - - async initServices() { - for (const serviceController of this.serviceControllers) { - await serviceController.init() - } - } - - async syncServices(lastMessageTimestamps: LastMessageTimestamp[]) { - for (const serviceController of this.serviceControllers) { - const instanceId = serviceController.instanceId() - const lastMessage = lastMessageTimestamps.find( - item => item.did === instanceId.did && item.sourceType === instanceId.sourceType, - ) - let since = lastMessage ? lastMessage.timestamp : 0 - await serviceController.sync(since) - } - } -} diff --git a/packages/daf-data-store/src/migrations/index.ts b/packages/daf-data-store/src/migrations/index.ts index 3d3433087..05767413c 100644 --- a/packages/daf-data-store/src/migrations/index.ts +++ b/packages/daf-data-store/src/migrations/index.ts @@ -3,7 +3,7 @@ import { second } from './002.second' import { DbDriver } from '../types' import Debug from 'debug' -const debug = Debug('db-migrations') +const debug = Debug('daf:data-store:db-migrations') const availableMigrations = [initial, second] @@ -16,23 +16,12 @@ export const insertLastMigrationId = (db: DbDriver, id: number) => { export const runMigrations = async (db: DbDriver) => { debug('Running migrations...') - await db.run( - 'CREATE TABLE IF NOT EXISTS migrations (migrationId TEXT, timestamp TEXT)', - [], - ) - const rows = await db.rows( - 'SELECT * FROM migrations ORDER BY migrationId DESC LIMIT 1', - [], - ) + await db.run('CREATE TABLE IF NOT EXISTS migrations (migrationId TEXT, timestamp TEXT)', []) + const rows = await db.rows('SELECT * FROM migrations ORDER BY migrationId DESC LIMIT 1', []) let lastMigrationId = -1 if (rows[0] && rows[0].migrationId) { - debug( - 'Latest migrationId:' + - rows[0].migrationId + - ' finished at:' + - rows[0].timestamp, - ) + debug('Latest migrationId:' + rows[0].migrationId + ' finished at:' + rows[0].timestamp) lastMigrationId = parseInt(rows[0].migrationId, 10) } diff --git a/packages/daf-debug/src/action-handler.ts b/packages/daf-debug/src/action-handler.ts index 39c5e0441..d0dc4670c 100644 --- a/packages/daf-debug/src/action-handler.ts +++ b/packages/daf-debug/src/action-handler.ts @@ -1,7 +1,7 @@ import { Core, AbstractActionHandler, Types } from 'daf-core' import Debug from 'debug' -const debug = Debug('action') +const debug = Debug('daf:debug:action-handler') export class ActionHandler extends AbstractActionHandler { public async handleAction(action: Types.Action, core: Core) { diff --git a/packages/daf-debug/src/message-validator.ts b/packages/daf-debug/src/message-validator.ts index b7ff424c3..893cbc532 100644 --- a/packages/daf-debug/src/message-validator.ts +++ b/packages/daf-debug/src/message-validator.ts @@ -1,7 +1,7 @@ import { Core, AbstractMessageValidator, Message } from 'daf-core' import Debug from 'debug' -const debug = Debug('message') +const debug = Debug('daf:debug:message-validator') export class MessageValidator extends AbstractMessageValidator { async validate(message: Message, core: Core): Promise { diff --git a/packages/daf-did-comm/src/action-handler.ts b/packages/daf-did-comm/src/action-handler.ts index 3a45e742d..ff721b5a8 100644 --- a/packages/daf-did-comm/src/action-handler.ts +++ b/packages/daf-did-comm/src/action-handler.ts @@ -3,7 +3,7 @@ import { DIDComm } from 'DIDComm-js' import uuid from 'uuid' import Debug from 'debug' -const debug = Debug('did-comm-action-handler') +const debug = Debug('daf:did-comm:action-handler') export const ActionTypes = { sendJwt: 'action.sendJwt', diff --git a/packages/daf-did-comm/src/message-validator.ts b/packages/daf-did-comm/src/message-validator.ts index be5bd3193..a99df996b 100644 --- a/packages/daf-did-comm/src/message-validator.ts +++ b/packages/daf-did-comm/src/message-validator.ts @@ -1,7 +1,7 @@ import { Core, AbstractMessageValidator, Message } from 'daf-core' import { DIDComm } from 'DIDComm-js' import Debug from 'debug' -const debug = Debug('did-comm-message-validator') +const debug = Debug('daf:did-comm:message-validator') export class MessageValidator extends AbstractMessageValidator { private didcomm: DIDComm diff --git a/packages/daf-did-jwt/src/message-validator.ts b/packages/daf-did-jwt/src/message-validator.ts index 129fef630..469b54ad6 100644 --- a/packages/daf-did-jwt/src/message-validator.ts +++ b/packages/daf-did-jwt/src/message-validator.ts @@ -1,7 +1,7 @@ import { Core, AbstractMessageValidator, Message, Resolver } from 'daf-core' import { verifyJWT, decodeJWT } from 'did-jwt' import Debug from 'debug' -const debug = Debug('did-jwt-validator') +const debug = Debug('daf:did-jwt:message-validator') export class MessageValidator extends AbstractMessageValidator { async validate(message: Message, core: Core): Promise { diff --git a/packages/daf-ethr-did-fs/src/identity-controller.ts b/packages/daf-ethr-did-fs/src/identity-controller.ts index 6db3eef77..4212461a9 100644 --- a/packages/daf-ethr-did-fs/src/identity-controller.ts +++ b/packages/daf-ethr-did-fs/src/identity-controller.ts @@ -2,7 +2,7 @@ import { IdentityController, Issuer } from 'daf-core' const EthrDID = require('ethr-did') const fs = require('fs') import Debug from 'debug' -const debug = Debug('fs-ethr-did-controller') +const debug = Debug('daf:ethr-did-fs:identity-controller') interface Identity { address: string diff --git a/packages/daf-ethr-did-react-native/src/index.ts b/packages/daf-ethr-did-react-native/src/index.ts index ad6526a82..f07562edf 100644 --- a/packages/daf-ethr-did-react-native/src/index.ts +++ b/packages/daf-ethr-did-react-native/src/index.ts @@ -2,7 +2,7 @@ import { IdentityController, Issuer } from 'daf-core' import { RNUportHDSigner, getSignerForHDPath } from 'react-native-uport-signer' import Debug from 'debug' -const debug = Debug('ethr-did-controller') +const debug = Debug('daf:ethr-did-react-native:identity-controller') // ANDROID OPTIONS // diff --git a/packages/daf-node-sqlite3/src/index.ts b/packages/daf-node-sqlite3/src/index.ts index c7dd3e911..7e0e8fa04 100644 --- a/packages/daf-node-sqlite3/src/index.ts +++ b/packages/daf-node-sqlite3/src/index.ts @@ -2,7 +2,7 @@ import sqlite3 from 'sqlite3' import { Types } from 'daf-data-store' import Debug from 'debug' -const debug = Debug('daf-node-sqlite3') +const debug = Debug('daf:node-sqlite3') export class NodeSqlite3 implements Types.DbDriver { private db: any diff --git a/packages/daf-react-native-sqlite3/src/index.ts b/packages/daf-react-native-sqlite3/src/index.ts index 501ba9a67..9b481234e 100644 --- a/packages/daf-react-native-sqlite3/src/index.ts +++ b/packages/daf-react-native-sqlite3/src/index.ts @@ -2,7 +2,7 @@ import { openDatabase } from 'react-native-sqlite-storage' import { Types } from 'daf-data-store' import Debug from 'debug' -const debug = Debug('rn-sqlite3') +const debug = Debug('daf:react-native-sqlite3') class RnSqlite3 implements Types.DbDriver { private db: any diff --git a/packages/daf-resolver-universal/src/resolver.ts b/packages/daf-resolver-universal/src/resolver.ts index 0247d5687..c768b9e52 100644 --- a/packages/daf-resolver-universal/src/resolver.ts +++ b/packages/daf-resolver-universal/src/resolver.ts @@ -1,7 +1,7 @@ import 'cross-fetch/polyfill' import Debug from 'debug' -const debug = Debug('resolver-universal') +const debug = Debug('daf:resolver-universal') interface Options { url: string diff --git a/packages/daf-resolver/src/resolver.ts b/packages/daf-resolver/src/resolver.ts index c4a764ba1..3c5eaf190 100644 --- a/packages/daf-resolver/src/resolver.ts +++ b/packages/daf-resolver/src/resolver.ts @@ -1,10 +1,10 @@ import { Resolver } from 'did-resolver' import { getResolver as ethrDidResolver } from 'ethr-did-resolver' import { resolver as naclDidResolver } from 'nacl-did' -import { getResolver as webDidResolver} from 'web-did-resolver' +import { getResolver as webDidResolver } from 'web-did-resolver' import Debug from 'debug' -const debug = Debug('resolver') +const debug = Debug('daf:resolver') interface Options { infuraProjectId: string @@ -19,7 +19,7 @@ export class DafResolver { rpcUrl: 'https://mainnet.infura.io/v3/' + options.infuraProjectId, }), ...webDidResolver(), - nacl: naclDidResolver + nacl: naclDidResolver, }) } diff --git a/packages/daf-selective-disclosure/src/action-handler.ts b/packages/daf-selective-disclosure/src/action-handler.ts index 4a5a446ef..59f3c4543 100644 --- a/packages/daf-selective-disclosure/src/action-handler.ts +++ b/packages/daf-selective-disclosure/src/action-handler.ts @@ -2,7 +2,7 @@ import { Core, AbstractActionHandler, Types } from 'daf-core' import { createJWT } from 'did-jwt' import Debug from 'debug' -const debug = Debug('sdr-action-handler') +const debug = Debug('daf:selective-disclosure:action-handler') export const ActionTypes = { signSdr: 'action.sign.sdr', diff --git a/packages/daf-selective-disclosure/src/message-validator.ts b/packages/daf-selective-disclosure/src/message-validator.ts index b53616542..9f29f131c 100644 --- a/packages/daf-selective-disclosure/src/message-validator.ts +++ b/packages/daf-selective-disclosure/src/message-validator.ts @@ -1,7 +1,7 @@ import { Core, AbstractMessageValidator, Message } from 'daf-core' import Debug from 'debug' -const debug = Debug('daf:sdr-validator') +const debug = Debug('daf:daf:selective-disclosure:message-validator') export const MessageTypes = { sdr: 'sdr', diff --git a/packages/daf-sodium-fs/src/encryption-key-manager.ts b/packages/daf-sodium-fs/src/encryption-key-manager.ts index e79acfa4d..aee57522d 100644 --- a/packages/daf-sodium-fs/src/encryption-key-manager.ts +++ b/packages/daf-sodium-fs/src/encryption-key-manager.ts @@ -3,7 +3,7 @@ import sodium from 'libsodium-wrappers' const fs = require('fs') import Debug from 'debug' -const debug = Debug('sodium-fs-encryption-key-manager') +const debug = Debug('daf:sodium-fs-encryption-key-manager') interface DidKeyPairMap { [did: string]: KeyPair @@ -23,7 +23,7 @@ export class SodiumFsEncryptionKeyManager implements EncryptionKeyManager { if (fs.existsSync(this.fileName)) { const raw = fs.readFileSync(this.fileName) const parsed = JSON.parse(raw) - + Object.keys(parsed).forEach(did => { const i = parsed[did] this.didKeyPairMap[did] = { diff --git a/packages/daf-trust-graph/src/action-handler.ts b/packages/daf-trust-graph/src/action-handler.ts index 161e6d4e4..238eaad90 100644 --- a/packages/daf-trust-graph/src/action-handler.ts +++ b/packages/daf-trust-graph/src/action-handler.ts @@ -2,7 +2,7 @@ import { Core, AbstractActionHandler, Types, Message } from 'daf-core' import { ServiceController } from './service-controller' import Debug from 'debug' -const debug = Debug('trust-graph-action-handler') +const debug = Debug('daf:trust-graph:action-handler') export const ActionTypes = { sendJwt: 'action.sendJwt', diff --git a/packages/daf-w3c/src/action-handler.ts b/packages/daf-w3c/src/action-handler.ts index 0747d419e..fa9e8612f 100644 --- a/packages/daf-w3c/src/action-handler.ts +++ b/packages/daf-w3c/src/action-handler.ts @@ -1,12 +1,9 @@ import { Core, AbstractActionHandler, Types } from 'daf-core' import { createVerifiableCredential, createPresentation } from 'did-jwt-vc' -import { - PresentationPayload, - VerifiableCredentialPayload, -} from 'did-jwt-vc/src/types' +import { PresentationPayload, VerifiableCredentialPayload } from 'did-jwt-vc/src/types' import Debug from 'debug' -const debug = Debug('w3c-action-handler') +const debug = Debug('daf:w3c:action-handler') export const ActionTypes = { signVc: 'action.sign.w3c.vc', diff --git a/packages/daf-w3c/src/message-validator.ts b/packages/daf-w3c/src/message-validator.ts index 46676c856..f4ec1e2dd 100644 --- a/packages/daf-w3c/src/message-validator.ts +++ b/packages/daf-w3c/src/message-validator.ts @@ -7,7 +7,7 @@ import { } from 'did-jwt-vc' import Debug from 'debug' -const debug = Debug('w3c-validator') +const debug = Debug('daf:w3c:message-validator') export const MessageTypes = { vc: 'w3c.vc',