Skip to main content

Function: createLazyPrivateKeySigner()

GalaChain core SDK 1.0.0-rc.8


GalaChain core SDK 1.0.0-rc.8 / index / createLazyPrivateKeySigner

Function: createLazyPrivateKeySigner()

createLazyPrivateKeySigner(getPrivateKey, options?): GalaChainSigner

Defined in: packages/gala-core-sdk/dist/index.d.ts:1398

Creates the native-signing equivalent of PrivateKeySigner for apps that must not hold a key in a long-lived object (an extension that reads its session key at sign time).

getPrivateKey is called once per signObject call, never cached, never shared between calls (concurrent signatures each fetch their own key), and the normalized key bytes are zeroed before signObject settles, also on failure. A rejection or exception from getPrivateKey (the app's "wallet is locked", a storage read that failed) is a KEY_PROVIDER_FAILED error with the original error as cause: nothing has been sent, so classifyFailure says not_sent and Retry is safe, and the app needs no error class of its own to tell this apart. A provider that returns no usable string ('', undefined) is INVALID_PRIVATE_KEY with reason: 'no_key_provided', classified the same way; any other key that is not a valid secp256k1 key string is an INVALID_PRIVATE_KEY error. An SDK error the provider throws itself is passed through. Signatures are byte-identical to new PrivateKeySigner(key).signObject(...).

A JavaScript string cannot be wiped; the provider owns the lifetime of the string it returns.

Parameters​

getPrivateKey​

PrivateKeyProvider

options?​

LazyPrivateKeySignerOptions

Returns​

GalaChainSigner

Example​

const signer = createLazyPrivateKeySigner(
() => SecurityHelper.getSessionSecret(SecurityHelper.SESSION_PRIVATE_KEY_KEY),
{ expectedAddress: account.address },
);
const gswap = new GSwap({ signer });