Skip to main content

Class: Wallet

A Wallet manages a private key and can sign messages.

example

import { Wallet } from 'essential-eth';

const wallet = new Wallet('0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
console.log(wallet.address); // checksummed Ethereum address

const sig = await wallet.signMessage('hello');
console.log(sig); // 0x... (65-byte hex signature)

Constructors

constructor

new Wallet(privateKey)

Creates a new Wallet instance.

Parameters

NameTypeDescription
privateKeystringA 32-byte private key as a hex string (with or without 0x prefix)

Defined in

classes/Wallet.ts:36

Properties

_privateKey

Private Readonly _privateKey: Uint8Array

Defined in

classes/Wallet.ts:29


_provider

Private _provider: unknown = null

Defined in

classes/Wallet.ts:30

Accessors

address

get address(): string

The checksummed Ethereum address derived from the private key.

Returns

string

Defined in

classes/Wallet.ts:51


provider

get provider(): unknown

The currently connected provider, if any.

Returns

unknown

Defined in

classes/Wallet.ts:144


publicKey

get publicKey(): string

The uncompressed public key (with 04 prefix) as a hex string.

Returns

string

Defined in

classes/Wallet.ts:62

Methods

connect

connect(provider): Wallet

Returns a new Wallet connected to the specified provider. The provider is stored for future sendTransaction support.

Parameters

NameTypeDescription
providerunknownA JSON-RPC provider instance

Returns

Wallet

This wallet instance with the provider attached

Defined in

classes/Wallet.ts:136


signMessage

signMessage(message): Promise<string>

Signs a message following EIP-191 (personal_sign) standard.

The message is prefixed with "\x19Ethereum Signed Message:\n" + message.length before being hashed with keccak256 and signed with secp256k1.

Parameters

NameTypeDescription
messagestring | Uint8ArrayThe message to sign (string or Uint8Array)

Returns

Promise<string>

The signature as a hex string (r + s + v, 65 bytes / 130 hex chars + 0x prefix)

Defined in

classes/Wallet.ts:75


signTypedData

signTypedData(_domain, _types, _value): Promise<string>

Signs EIP-712 typed data. Not yet implemented.

throws Always throws "Not yet implemented"

Parameters

NameType
_domainunknown
_typesunknown
_valueunknown

Returns

Promise<string>

Defined in

classes/Wallet.ts:122