Key Provider

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

The 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(options);

Creates a new KeyProvider instance.

Parameters

  1. options - KeyProviderOptions: options for KeyProvider constructor.
    • keys - any (optional): object with key mappings of accounts
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog

Returns

KeyProvider instance

Example

const keyProvider = new KeyProvider({
    keys: {
      '0x123': 'abcdeF9043'
    }
  });

init

keyProvider.init(_profile);

initialize a new KeyProvider with a given evan.network Profile

Parameters

  1. _profile - Profile: initialized evan.network profile

Example

runtime.keyProvider.init(runtime.profile);

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);