-
Hi, Our team wants to use the Veramo API on the chrome extension, but face some problem. code : const DATABASE_FILE = 'database.sqlite'
const INFURA_PROJECT_ID = 'my_project_id'
// This will be the secret key for the KMS
const KMS_SECRET_KEY =
'some_key_generate'
const dbConnection = createConnection({
type: 'sqlite',
database: DATABASE_FILE,
synchronize: false,
migrations,
migrationsRun: true,
logging: ['error', 'info', 'warn'],
entities: Entities,
})
export const agent = createAgent<IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver>({
plugins: [
new KeyManager({
store: new KeyStore(dbConnection),
kms: {
local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY))),
},
}),
new DIDManager({
store: new DIDStore(dbConnection),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
}),
},
}),
new DIDResolverPlugin({
resolver: new Resolver({
...ethrDidResolver({ infuraProjectId: INFURA_PROJECT_ID }),
...webDidResolver(),
}),
}),
new CredentialIssuer(),
new MessageHandler({
messageHandlers: [
new JwtMessageHandler(),
new W3cMessageHandler(),
],
}),
],
}) After import setup.ts : export class DIDManager {
async createDID (didMnemonic?: string) {
let wallet: Wallet
if (typeof didMnemonic === 'undefined') {
wallet = Wallet.createRandom()
} else {
if (!isValidMnemonic(didMnemonic)) throw new Error('invalid Mnemonic')
wallet = Wallet.fromMnemonic(didMnemonic)
}
const publicKeyHex = wallet.publicKey.substring(2)
const privateKeyHex = wallet.privateKey.substring(2)
const compressedPublicKey = computePublicKey(`0x${publicKeyHex}`, true)
const identifier = `did:ethr:rinkeby:${compressedPublicKey}`
try {
const identity = await agent.didManagerImport({
did: identifier,
provider: 'did:ethr:rinkeby',
controllerKeyId: publicKeyHex,
keys: [
{
kid: publicKeyHex,
kms: 'local',
type: 'Secp256k1',
publicKeyHex: publicKeyHex,
privateKeyHex: privateKeyHex,
},
],
services: [],
})
console.log('New identity created')
const did: ICreatedDID = { //ICreatedDID is interface I defined
mnemonic: wallet.mnemonic.phrase,
privateKey: wallet.privateKey,
publicKey: wallet.publicKey,
address: wallet.address,
identity: identity,
}
return did
} catch (err) {
console.log(err)
}
}
} Use it in my React code : didManager.createDID().then(did => {
alert(did)
}) I can build the code to chrome extension, but when using the above function, I get the following error and the sqlite database is not built : I'm guessing what's causing the error : It is impossible to create sqlite by some function in chrome extension? Then I found a setup.ts using json as the database in the source code(as below), but I couldn't find const memoryJsonStore = {
notifyUpdate: () => Promise.resolve()
}
type InstalledPlugins =
IResolver
& IKeyManager
& IDIDManager
& ICredentialIssuer
& IDataStoreORM
& IDataStore
& ISelectiveDisclosure
& IDIDComm
export const agent: TAgent<InstalledPlugins> = createAgent<InstalledPlugins>({
plugins: [
new DIDResolverPlugin({
resolver: new Resolver({
...ethrDidResolver({ infuraProjectId: INFURA_PROJECT_ID }),
...webDidResolver(),
/**
* `getDidKeyResolver` throws error:
* "Field 'browser' doesn't contain a valid alias configuration"
* Can't resolve 'stream'
* 'stream-browserify' can be installed for brower env
*/
// ...getDidKeyResolver(),
// ...new FakeDidResolver(() => agent).getDidFakeResolver(),
}),
}),
new KeyManager({
store: new KeyStoreJson(memoryJsonStore),
kms: {
local: new KeyManagementSystem(new PrivateKeyStoreJson(memoryJsonStore)),
},
}),
new DIDManager({
store: new DIDStoreJson(memoryJsonStore),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrDIDProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrDIDProvider({
defaultKms: 'local',
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:421611': new EthrDIDProvider({
defaultKms: 'local',
network: 421611,
rpcUrl: 'https://arbitrum-rinkeby.infura.io/v3/' + INFURA_PROJECT_ID,
registry: '0x8f54f62CA28D481c3C30b1914b52ef935C1dF820',
}),
'did:web': new WebDIDProvider({
defaultKms: 'local',
}),
/**
* `KeyDIDProvider` throws error:
* "Field 'browser' doesn't contain a valid alias configuration"
* Can't resolve 'stream'
* 'stream-browserify' can be installed for browser env
*/
// 'did:key': new KeyDIDProvider({
// defaultKms: 'local',
// }),
// 'did:fake': new FakeDidProvider(),
},
}),
new DataStoreJson(memoryJsonStore),
new MessageHandler({
messageHandlers: [
new DIDCommMessageHandler(),
new JwtMessageHandler(),
new W3cMessageHandler(),
new SdrMessageHandler(),
],
}),
new DIDComm(),
new CredentialIssuer(),
/**
* `CredentialIssuerLD` throws error:
* Can't resolve 'path'
* 'path-browserify' can be installed for brower env
*/
// new CredentialIssuerLD({
// contextMaps: [LdDefaultContexts],
// suites: [new VeramoEcdsaSecp256k1RecoverySignature2020(), new VeramoEd25519Signature2018()],
// }),
new SelectiveDisclosure(),
],
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The code you see on github on te To use it you need to install all your veramo dependencies from the Keep in mind that the Veramo is flexible enough to support any plugin you can imagine, so you can also adapt things to match your needs. There is a team that has adopted a slightly different strategy for storage in veramo and you can read all about it here: https://medium.com/@blockchainlabum/its-time-to-prove-your-worth-in-dao-ssi-using-metamask-snaps-part-1-3-cfed7c10e6f7 |
Beta Was this translation helpful? Give feedback.
The code you see on github on te
next
branch is not yet released as a stable version, which is why you are seeing the differences.To use it you need to install all your veramo dependencies from the
@next
distTag, for exampleyarn add @veramo/core@next
Keep in mind that the
@next
dist can change as we adjust the api and fix stuff before the release.Veramo is flexible enough to support any plugin you can imagine, so you can also adapt things to match your needs.
There is a team that has adopted a slightly different strategy for storage in veramo and you can read all about it here: https://medium.com/@blockchainlabum/its-time-to-prove-your-worth-in-dao-ssi-using-metamask-snaps-part-1-3-cfe…