digitalbazaar / bedrock-did-io

Other
0 stars 0 forks source link

Library needs a way of extending the did:method drivers it uses #15

Open aljones15 opened 2 years ago

aljones15 commented 2 years ago

Currently this library is configured to only allow the did:v1 and did:key drivers, but we might need to include more did drivers in the future or allow variants of a did:method driver with a different identifier and driver options.

So I am proposing something like this for the config:

/*!
 * Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
 */
import {config} from '@bedrock/core';
import {didKeyDriver} from 'did-method-key';
// hypothetical driver
import btcDriver from 'btcr-driver';

const namespace = 'did-io';
const cfg = config[namespace] = {}; 

cfg.methods = [{
  method: 'btcr',
  driver: btcrDriver,
  driverOptions: {
    foo: bar
  }
}, {
  method: 'key',
  driver: didKeyDriver,
  driverOptions: {
    enableExperimentalKeyTypes: true
  }
}]

This would allow the use of other did:method drivers just by adding a function to the cfg section for the driver. This would also allow projects that use this library to extend the did:method drivers that did-io has access to.

dlongley commented 2 years ago

The bedrock configuration is meant to be JSON, i.e., no functions. Additionally, bedrock-did-io's current design is to be an audited and approved list of acceptable DID methods for any bedrock application, not for general purpose. That doesn't mean it needs to remain that way (be non-extensible), but if we are to add extensions, I would think we'd need to do so via methods we expose on the library rather than directly via mixing code into the configuration.

cc: @davidlehn, @mattcollier

aljones15 commented 2 years ago

If that is the case then currently adding new methods like this:

import {didIo} from '@bedrock/did-io';

didIo.use(experimentalMethodDriver);

Works.