• Asserts that an arbitrary string is a base58-encoded Ed25519 signature.

    Useful when you receive a string from user input or an untrusted network API that you expect to represent an Ed25519 signature (eg. of a transaction).

    Parameters

    • putativeSignature: string

    Returns asserts putativeSignature is Signature

    import { assertIsSignature } from '@solana/keys';

    // Imagine a function that asserts whether a user-supplied signature is valid or not.
    function handleSubmit() {
    // We know only that what the user typed conforms to the `string` type.
    const signature: string = signatureInput.value;
    try {
    // If this type assertion function doesn't throw, then
    // Typescript will upcast `signature` to `Signature`.
    assertIsSignature(signature);
    // At this point, `signature` is a `Signature` that can be used with the RPC.
    const {
    value: [status],
    } = await rpc.getSignatureStatuses([signature]).send();
    } catch (e) {
    // `signature` turned out not to be a base58-encoded signature
    }
    }