Skip to content

Class: SignerService

modules/signer.SignerService

Service responsible for signing messages and sending transactions to the blockchain

const { signerService } = await initWithPrivateKeySigner(privateKey, rpcUrl);
signerService.signMessage(...);

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new SignerService(_signer, _providerType)

Parameters

Name Type
_signer Required<SignerT>
_providerType ProviderType

Accessors

accountInfo

get accountInfo(): AccountInfo

Get account info, including chain id, chain name and user address.

signerService.accountInfo;

Returns

AccountInfo

account info


address

get address(): string

Get user address.

signerService.address;

Returns

string

user address


chainId

get chainId(): number

Get current connection chain id.

signerService.chainId;

Returns

number

chain id


did

get did(): string

Get current user DID

signerService.did;

Returns

string

DID


didHex

get didHex(): string

Get current user DID address with hex representation of the chain id.

signerService.didHex;

Returns

string

DID address


isEthSigner

get isEthSigner(): boolean

If signer is EIP-191 compliant https://eips.ethereum.org/EIPS/eip-191.

signerService.isEthSigner;

Returns

boolean

true if the signer is EIP-191 compliant.


provider

get provider(): Provider

Get connection provider.

signerService.provider;

Returns

Provider

connection provider


providerType

get providerType(): ProviderType

Get provider type of current signer connection.

signerService.providerType;

Returns

ProviderType

provider type


signer

get signer(): Required<SignerT>

The instance of the ether library signer in use by the service

signerService.signer;

Returns

Required<SignerT>

signer

Methods

balance

balance(): Promise<BigNumber>

Get current user balance.

signerService.getBalance();

Returns

Promise<BigNumber>

user balance


call

call(options): Promise<string>

Makes a (readonly) call to a smart contract. https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/-%23-Provider-call

signerService.call({
    to: ':0x00...0',
    data: contract.interface.encodeFunctionData(...)
});

Parameters

Name Type Description
options TransactionRequest object with options

Returns

Promise<string>

the result of the call


chainName

chainName(): string

Get current chain name.

signerService.chainName();

Returns

string

chain name


closeConnection

closeConnection(): Promise<boolean>

Close connection with the signer wallet.

signerService.closeConnection();

Returns

Promise<boolean>

true if connection was closed


connect

connect(signer, providerType): Promise<void>

Parameters

Name Type
signer Required<SignerT>
providerType ProviderType

Returns

Promise<void>


emit

emit(e): Promise<void>

Parameters

Name Type
e ProviderEvent

Returns

Promise<void>


init

init(): Promise<void>

Returns

Promise<void>


initEventHandlers

initEventHandlers(): void

Add event handler for certain events

Returns

void

Requires

to be called after the connection to wallet was initialized


on

on(event, cb): void

Parameters

Name Type
event ProviderEvent
cb any

Returns

void


onInit

onInit(initializer): void

Registers reinitialization of dependent service on signer reconnection

Parameters

Name Type
initializer ServiceInitializer

Returns

void


publicKey

publicKey(): Promise<string>

Get current user public key.

signerService.publicKey();

Returns

Promise<string>

public key


publicKeyAndIdentityToken

publicKeyAndIdentityToken(force?): Promise<IPubKeyAndIdentityToken>

Generate public key and identity token for authentication purposes.

signerService.publicKeyAndIdentityToken();

Parameters

Name Type Default value Description
force boolean false when true recalculates token even if it is already present

Returns

Promise<IPubKeyAndIdentityToken>

object with public key and identity token


send

send(options): Promise<TransactionReceipt>

Send transaction to the blockchain.

signerService.send({
    to: ':0x00...0',
    data: contract.interface.encodeFunctionData(...)
});

Parameters

Name Type Description
options TransactionRequest object with options

Returns

Promise<TransactionReceipt>

transaction receipt


signMessage

signMessage(message): Promise<string>

Tries to create eth_sign conformant signature (https://eth.wiki/json-rpc/API#eth_sign). Whether or not to hash the message prior to signature is depends on whether is signer EIP-191 compliant. When running in browser isEthSigner variable should be stored in local storage.

signerService.signMessage(arrayify('Hello World'));

Parameters

Name Type Description
message Uint8Array The message to be signed. The message should have binary representation to avoid confusion of text with hexadecimal binary data

Returns

Promise<string>

the signature


signTypedData

signTypedData(domain, types, message): Promise<string>

Tries to create conformant EIP-712 signature (https://eips.ethereum.org/EIPS/eip-712).

signerService.signTypedData(
    { name: 'MyToken', version: '1.0' },
    { Model: [{ name: 'name', type: 'string' }, { name: 'type', type: 'string' }] },
    { name: 'MyToken', type: 'erc721' },
);

Parameters

Name Type Description
domain TypedDataDomain EIP-712 domain object
types Record<string, TypedDataField[]> EIP-712 types object
message Record<string, unknown> EIP-712 message object

Returns

Promise<string>

the signature