UNPKG

@ew-did-registry/did-ethr-resolver

Version:

The package resolve CRUD operations on DID Documents

69 lines (68 loc) 3.34 kB
import { Signer, providers, utils } from 'ethers'; import { ProviderSettings } from '@ew-did-registry/did-resolver-interface'; type EIP1193ProviderType = providers.ExternalProvider | providers.JsonRpcFetchFunc; /** * A signer class that encapsulates the ethers Signer and ensures that publicKey is available. * The public is necessary for verification of signatures made by the signer. * The purpose of the ethers encapsulation is to allow consumers more flexiblity in ethers version. */ export declare class EwSigner extends Signer { readonly signer: Signer; readonly privateKey?: string | undefined; readonly provider: providers.Provider; readonly publicKey: string; /** * A private constructor as this class uses factory method for instantiation API. */ private constructor(); getAddress(): Promise<string>; sendTransaction(transaction: providers.TransactionRequest): Promise<providers.TransactionResponse>; signMessage(message: string | utils.Bytes): Promise<string>; signTransaction(transaction: providers.TransactionRequest): Promise<string>; connect(provider: providers.Provider): Signer; /** * A factory method to create an EwSigner from a private key. * ```typescript * import { * Operator, * EwSigner * } from '@ew-did-registry/did-ethr-resolver'; * import { Keys } from '@ew-did-registry/keys'; * * const keys = new Keys(); * const providerSettings = { type: ProviderTypes.HTTP, }; * const signer = EwSigner.fromPrivateKey(keys.privateKey, providerSettings); * const operator = new Operator(signer, registrySettings); * ``` * @param privateKey a secp256k1 private key. * @param providerSettings settings from which a web3 provider can be obtained */ static fromPrivateKey(privateKey: string, providerSettings: ProviderSettings): EwSigner; /** * A factory method to create an EwSigner using an ethers library Signer. * This is convenient if a suitable ethers signer is available. * If instead an EIP1993 provider is available, see {@linkcode fromEIP1193} * @param signer an ethers Signer connected to chain * @param publicKey the publicKey of the signer associated with the provider */ static fromEthersSigner(signer: Signer, publicKey: string): EwSigner; /** * A factory method to create an EwSigner without needing a specific ethers object. * Instead, any object which conforms to the necessary interface can be used. * See https://docs.ethers.io/v5/api/providers/other/#Web3Provider for interface description. * * @example * ```typescript * import { Operator, EwSigner } from '@ew-did-registry/did-ethr-resolver'; * import detectMetamask from "@metamask/detect-provider"; * * const web3Provider = await detectMetamask(); * const web3Signer = EwSigner.fromEIP1193(web3Provider, publicKey); * const operator = new Operator(web3Signer, registrySettings); * ``` * @param eip1993Provider an EIP1193 provider (https://docs.ethers.io/v5/api/providers/other/#Web3Provider) * @param publicKey the publicKey of the signer associated with the provider */ static fromEIP1193(eip1993Provider: EIP1193ProviderType, publicKey: string): Promise<EwSigner>; } export {};