1.0.0 • Published 10 months ago

oreid-provider v1.0.0

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
10 months ago

OreIdProviderEip1193

OreIdProviderEip1193 is a JavaScript class that provides an EIP-1193 provider for the ORE ID service. This provider is an adapter layer that interfaces with Ethereum's JSON RPC and allows the use of ORE ID with Ethereum-based libraries and services, like Web3.js and ethers.js, which expect an EIP-1193 provider.

This library is a short circuit to developers re-implementing common functionality when integrating ORE ID with Ethereum-based libraries and services. It is designed to be used in applications that need to interact with Ethereum-based networks through ORE ID.

Dependencies

This package uses the following dependencies:

  • "oreid-js": The ORE ID library.
  • "@ethersproject/providers": Ethers' set of provider abstractions to interact with Ethereum nodes.

Key Components

  • Eip1193Provider Interface: An object containing the methods required by Ethereum's EIP-1193 provider standard.
  • ChainNameIdMapping Interface and ChainNameIdMappings Object: Contain chain names and their corresponding IDs.
  • OreIdProviderEip1193 Class: The main class in this module, providing EIP-1193 compatibility to ORE ID.
  • Constructor: The constructor method is used to initialize the class, setting up the ORE ID instance, selected chain account, selected chain ID, and listeners object.
  • request method: This method is used to handle various JSON-RPC method requests, allowing the class to support transactions, message signing, account fetching, balance checking, and other operations.
  • on and off methods: These methods are used to register and unregister event listeners.
  • handleTransaction, sendTransaction, and signTransaction methods: These methods are used to handle, send, and sign Ethereum transactions using ORE ID.
  • signString method: This method is used to sign a string using a specified signing method via ORE ID.
  • getNonce, getChainAccountsForSelectedChain, getBalance, getBlockNumber, and getChainId methods: These methods are used to interact with the Ethereum network, fetching various pieces of data such as account nonce, chain accounts, account balance, the current block number, and the chain ID.
  • getEthersProvider and getNetworkUrl methods: These methods are used to create an ethers.js provider and fetch the JSON-RPC URL for the specified chain network.

Usage

To use this provider, you will need to:

  • Import the required dependencies.
  • Create an instance of the OreIdProviderEip1193 class, passing the required arguments to the constructor.
  • Call the request method to interact with the Ethereum network. This method handles various JSON-RPC methods according to the method specified in the payload.
  • Register event listeners using the on method and unregister them using the off method.
  • Use the provided methods to interact with the Ethereum network and perform operations like sending and signing transactions.

Events (TODO)

The OreIdProviderEip1193 class can emit various events that you can listen to:

  • connect: Fired when the connection is successfully established.
  • disconnect: Fired when the user disconnects their wallet.
  • accountsChanged: Fired when the selected account changes.
  • chainChanged: Fired when the selected chain changes.
  • networkChanged: Fired when the network changes.
  • message: Fired for incoming messages.

Unfinished work and caveats

  • Add event emitters above for easier integration with wallet abstraction libraries.
  • Add all ORE ID onchain logic I.e. account resolution.
    • Currently a lot of this logic lives in connectors so there's a lot of duplicated code and it's not easy to test.
    • It will make future wallet abstraction libraries trivial to implement with no risk of bugs due to duplicated logic handling wallet lifecycle.

Note: This package is primarily designed for use in applications that need to interact with Ethereum-based networks through ORE ID.