Skip to main content

Class: PrivateKeyProvider

GalaChain core SDK 1.0.0-rc.8


GalaChain core SDK 1.0.0-rc.8 / providers / PrivateKeyProvider

Class: PrivateKeyProvider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:429

A wallet provider over a private key. Always ready to sign: connect() / disconnect() only toggle isConnected().

Example​

const provider = new PrivateKeyProvider(process.env.PRIVATE_KEY!);
const signature = await provider.signMessage('Hello');
const signer = provider.getSigner(); // native GalaChain signing

Implements​

Constructors​

Constructor​

new PrivateKeyProvider(privateKey): PrivateKeyProvider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:437

Parameters​

privateKey​

string

0x plus 64 hex digits, or the 64 digits (any case).

Returns​

PrivateKeyProvider

Throws​

GalaSDKError INVALID_PRIVATE_KEY (bad_encoding, not_on_curve). The key is never part of the error.

Properties​

providerType​

readonly providerType: WalletProviderType

Defined in: packages/gala-core-sdk/dist/providers.d.ts:431

Whether the provider holds a raw key (privateKey) or signs in a wallet (external).

Implementation of​

WalletProvider.providerType

Methods​

connect()​

connect(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:463

Marks the provider connected (it always can sign) and returns its account.

Returns​

Promise<string>

Implementation of​

WalletProvider.connect


disconnect()​

disconnect(): Promise<void>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:465

Marks the provider disconnected; it can still sign.

Returns​

Promise<void>

Implementation of​

WalletProvider.disconnect


exportPrivateKey()​

exportPrivateKey(): string

Defined in: packages/gala-core-sdk/dist/providers.d.ts:474

The key, synchronously: 0x plus 64 lower-case hex digits. For code that must build its own signer from it (an ethers Wallet) in a synchronous path.

Returns​

string


getAddress()​

getAddress(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:457

The key's account: 0x plus the EIP-55 digits.

Returns​

Promise<string>

Implementation of​

WalletProvider.getAddress


getGalaAddress()​

getGalaAddress(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:459

The key's account as GalaChain spells it: eth| plus the EIP-55 digits.

Returns​

Promise<string>

Implementation of​

WalletProvider.getGalaAddress


getPrivateKey()​

getPrivateKey(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:469

The key: 0x plus 64 lower-case hex digits.

Returns​

Promise<string>

Implementation of​

WalletProvider.getPrivateKey


getSigner()​

getSigner(): GalaChainSigner

Defined in: packages/gala-core-sdk/dist/providers.d.ts:461

The core PrivateKeySigner (native GalaChain signing) over this key.

Returns​

GalaChainSigner

Implementation of​

WalletProvider.getSigner


isConnected()​

isConnected(): boolean

Defined in: packages/gala-core-sdk/dist/providers.d.ts:467

True until disconnect() (again after connect()).

Returns​

boolean

Implementation of​

WalletProvider.isConnected


onAccountChanged()​

onAccountChanged(listener): () => void

Defined in: packages/gala-core-sdk/dist/providers.d.ts:480

Calls listener with the account on connect() and null on disconnect().

Parameters​

listener​

AccountListener

Returns​

The function that stops the calls.

() => void

Implementation of​

WalletProvider.onAccountChanged


signMessage()​

signMessage(message): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:448

Signs message as personal_sign does (EIP-191 over its UTF-8 bytes).

Parameters​

message​

string

Returns​

Promise<string>

Throws​

GalaSDKError SIGNING_FAILED for a message with a lone surrogate (it has no UTF-8 encoding; a wallet would sign U+FFFD instead of what was shown).

Implementation of​

WalletProvider.signMessage


signTypedData()​

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

Defined in: packages/gala-core-sdk/dist/providers.d.ts:455

Signs EIP-712 typed data (eth_signTypedData_v4) with core's encoder, which fails closed on a value ethers would have coerced (TYPED_DATA_*).

Parameters​

domain​

TypedDataDomain

types​

Record<string, TypedDataField[]>

value​

Record<string, unknown>

Returns​

Promise<string>

Throws​

GalaSDKError TYPED_DATA_* for typed data the encoder refuses, SIGNING_FAILED.

Implementation of​

WalletProvider.signTypedData


fromWallet()​

static fromWallet(wallet): PrivateKeyProvider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:439

A provider over the key an ethers Wallet (or any { privateKey }) holds.

Parameters​

wallet​
privateKey​

string

Returns​

PrivateKeyProvider