UNPKG

@veramo/remote-server

Version:

Express.js module that can expose some agent methods and messaging endpoints

48 lines 1.91 kB
import parse from 'url-parse'; /** * This can be used to automatically create a did:web with signing and encryption keys and listing messaging and * DIDComm service endpoints. * * @param options - The options guiding the creation of the default DID * * @beta This API may change without a BREAKING CHANGE notice. */ export async function createDefaultDid(options) { if (!options.agent) throw Error('[createDefaultDid] Agent is required'); if (!options.baseUrl) throw Error('[createDefaultDid] baseUrl is required'); const hostname = parse(options.baseUrl).hostname; const serverIdentifier = await options?.agent?.didManagerGetOrCreate({ provider: 'did:web', alias: hostname, options: { keyType: 'Ed25519', }, }); console.log('🆔', serverIdentifier?.did); if (serverIdentifier && options.messagingServiceEndpoint) { const messagingServiceEndpoint = options.baseUrl + options.messagingServiceEndpoint; console.log('📨 Messaging endpoint', messagingServiceEndpoint); await options?.agent?.didManagerAddService({ did: serverIdentifier.did, service: { id: serverIdentifier.did + '#msg', type: 'Messaging', description: 'Handles incoming POST messages', serviceEndpoint: messagingServiceEndpoint, }, }); // list DIDCommMessaging service at the same endpoint await options?.agent?.didManagerAddService({ did: serverIdentifier.did, service: { id: serverIdentifier.did + '#msg-didcomm', type: 'DIDCommMessaging', description: 'Handles incoming DIDComm messages', serviceEndpoint: messagingServiceEndpoint, }, }); } } //# sourceMappingURL=default-did.js.map