Key Provider

Class Name KeyProvider
Implements KeyProviderInterface
Extends Logger
Extends key-provider.ts
Source key-provider.ts

This DApp browser KeyProvider is a adaption of the original DBCP KeyProvider returns given decryption/encryption keys for a given CryptoInfo. They use a given evan.network profile to retrieve the needed keys to encrypt/decrypt the envelope


constructor

new KeyProvider(keys, accountId)

Creates a new KeyProvider instance.

Parameters

  1. keys - any: object with key mappings of accounts (can be empty, will be filled dynamically).
  2. accountId - string: create KeyProvider for specific accountId, default the current logged in accountId will be used.

Returns

KeyProvider instance

Example

const keyProvider = new KeyProvider({ });

setKeys

keyProvider.setKeys();

set the keys for the within the constructor provided or global accountId

Example

runtime.keyProvider.setKeys();

setKeys

keyProvider.setKeys();

Uses an account id and an encryptionKey to set account specific encryption keys.

Example

keyProvider.setKeysForAccount(this.origin.currentAccountHash, encryptionKey);

getKey

keyProvider.getKey(info);

get a encryption/decryption key for a specific CryptoInfo from the associated AccountStore or the loaded evan.network profile

Parameters

  1. cryptoAlgo - string: crypto algorithm

Returns

Promise resolves to string: the found key for the cryptoinfo.

Example

const cryptoInfo = {
  "public": {
    "name": "envelope example"
  },
  "private": "...",
  "cryptoInfo": {
    "algorithm": "unencrypted",
    "keyLength": 256,
    "originator": "0x0000000000000000000000000000000000000001,0x0000000000000000000000000000000000000002",
    "block": 123
  }
};
const key = runtime.keyProvider.getKey(info);