Kit
Functions

assertIsOffCurveAddress

assertIsOffCurveAddress<TAddress>(putativeOffCurveAddress): asserts putativeOffCurveAddress is OffCurveAddress<TAddress>

From time to time you might acquire an Address, that you expect to validate as an off-curve address, from an untrusted source. Use this function to assert that such an address is off-curve.

Type Parameters

Type Parameter
TAddress extends Address

Parameters

ParameterType
putativeOffCurveAddressTAddress

Returns

asserts putativeOffCurveAddress is OffCurveAddress<TAddress>

Example

import { assertIsOffCurveAddress } from '@solana/addresses';
 
// Imagine a function that fetches an account's balance when a user submits a form.
function handleSubmit() {
    // We know only that the input conforms to the `string` type.
    const address: string = accountAddressInput.value;
    try {
        // If this type assertion function doesn't throw, then
        // Typescript will upcast `address` to `Address`.
        assertIsAddress(address);
        // If this type assertion function doesn't throw, then
        // Typescript will upcast `address` to `OffCurveAddress`.
        assertIsOffCurveAddress(address);
        // At this point, `address` is an `OffCurveAddress` that can be used with the RPC.
        const balanceInLamports = await rpc.getBalance(address).send();
    } catch (e) {
        // `address` turned out to NOT be a base58-encoded off-curve address
    }
}

On this page