|
| 1 | +================================================================================ |
| 2 | +Account Store |
| 3 | +================================================================================ |
| 4 | + |
| 5 | +.. list-table:: |
| 6 | + :widths: auto |
| 7 | + :stub-columns: 1 |
| 8 | + |
| 9 | + * - Class Name |
| 10 | + - AccountStore |
| 11 | + * - Implements |
| 12 | + - `KeyStoreInterface <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`__ |
| 13 | + * - Extends |
| 14 | + - `Logger </common/logger.html>`_ |
| 15 | + * - Source |
| 16 | + - `account-store.ts <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`__ |
| 17 | + |
| 18 | +The `AccountStore <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`_ implements the `KeyStoreInterface <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`_ and is a wrapper for a storage, where evan.network account ids are stored. The default `AccountStore <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`_ takes an account --> private key mapping as a pojo as its arguments and uses this to perform lookups, when the :ref:`getPrivateKey <accountstore_getPrivateKey>` function is called. This lookup needs to be done, when transactions are signed by the `InternalSigner <https://github.com/evannetwork/dbcp/tree/master/src/contracts/signer-internal.ts>`_ (see `Signer </blockchain/signer.html>`_). |
| 19 | + |
| 20 | +Note that the return value of the :ref:`getPrivateKey <accountstore_getPrivateKey>` function is a promise. This may not be required in the default `AccountStore <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`_, but this allows you to implement own implementations of the `KeyStoreInterface <https://github.com/evannetwork/dbcp/tree/master/src/account-store.ts>`_, which may enforce a more strict security behavior or are able to access other sources for private keys. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +------------------------------------------------------------------------------ |
| 25 | + |
| 26 | +.. _accountstore_constructor: |
| 27 | + |
| 28 | +constructor |
| 29 | +================================================================================ |
| 30 | + |
| 31 | +.. code-block:: typescript |
| 32 | +
|
| 33 | + new AccountStore(options); |
| 34 | +
|
| 35 | +Creates a new AccountStore instance. |
| 36 | + |
| 37 | +---------- |
| 38 | +Parameters |
| 39 | +---------- |
| 40 | + |
| 41 | +#. ``options`` - ``AccountStoreOptions``: options for AccountStore constructor. |
| 42 | + * ``accounts`` - ``any``: object with accountid/privatekey mapping |
| 43 | + * ``log`` - ``Function`` (optional): function to use for logging: ``(message, level) => {...}`` |
| 44 | + * ``logLevel`` - |source logLevel|_ (optional): messages with this level will be logged with ``log`` |
| 45 | + * ``logLog`` - |source logLogInterface|_ (optional): container for collecting log messages |
| 46 | + * ``logLogLevel`` - |source logLevel|_ (optional): messages with this level will be pushed to ``logLog`` |
| 47 | + |
| 48 | +------- |
| 49 | +Returns |
| 50 | +------- |
| 51 | + |
| 52 | +``AccountStore`` instance |
| 53 | + |
| 54 | +------- |
| 55 | +Example |
| 56 | +------- |
| 57 | + |
| 58 | +.. code-block:: typescript |
| 59 | + |
| 60 | + const accountStore = new AccountStore({ |
| 61 | + accounts: { |
| 62 | + '0x1234': '12479abc3df' |
| 63 | + } |
| 64 | + }); |
| 65 | +
|
| 66 | +
|
| 67 | +
|
| 68 | +-------------------------------------------------------------------------------- |
| 69 | + |
| 70 | +.. _accountstore_getPrivateKey: |
| 71 | + |
| 72 | +getPrivateKey |
| 73 | +=================== |
| 74 | + |
| 75 | +.. code-block:: javascript |
| 76 | +
|
| 77 | + accountStore.getPrivateKey(accountId); |
| 78 | +
|
| 79 | +get private key for given account |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +---------- |
| 84 | +Parameters |
| 85 | +---------- |
| 86 | + |
| 87 | +#. ``accountId`` - ``string``: eth accountId |
| 88 | + |
| 89 | +------- |
| 90 | +Returns |
| 91 | +------- |
| 92 | + |
| 93 | +Promise resolves to ``string``: private key for this account |
| 94 | + |
| 95 | +------- |
| 96 | +Example |
| 97 | +------- |
| 98 | + |
| 99 | +.. code-block:: javascript |
| 100 | +
|
| 101 | + const privateKey = await runtime.accountStore.getPrivateKey('0x0000000000000000000000000000000000000002'); |
| 102 | +
|
| 103 | +.. required for building markup |
| 104 | +
|
| 105 | +.. |source logLevel| replace:: ``LogLevel`` |
| 106 | +.. _source logLevel: /common/logger.html#loglevel |
| 107 | + |
| 108 | +.. |source logLogInterface| replace:: ``LogLogInterface`` |
| 109 | +.. _source logLogInterface: /common/logger.html#logloginterface |
0 commit comments