eth-sig-util

  • Version 3.0.1
  • Published
  • 51.8 kB
  • 4 dependencies
  • ISC license

Install

npm i eth-sig-util
yarn add eth-sig-util
pnpm add eth-sig-util

Overview

A few useful functions for signing ethereum data

Index

Variables

variable TYPED_MESSAGE_SCHEMA

const TYPED_MESSAGE_SCHEMA: {
type: string;
properties: {
types: {
type: string;
additionalProperties: {
type: string;
items: {
type: string;
properties: { name: { type: string }; type: { type: string } };
required: string[];
};
};
};
primaryType: { type: string };
domain: { type: string };
message: { type: string };
};
required: string[];
};

    variable TypedDataUtils

    const TypedDataUtils: {
    encodeData(
    primaryType: string,
    data: Record<string, unknown>,
    types: Record<string, MessageTypeProperty[]>,
    useV4?: boolean
    ): Buffer;
    encodeType(
    primaryType: string,
    types: Record<string, MessageTypeProperty[]>
    ): string;
    findTypeDependencies(
    primaryType: string,
    types: Record<string, MessageTypeProperty[]>,
    results?: string[]
    ): string[];
    hashStruct(
    primaryType: string,
    data: Record<string, unknown>,
    types: Record<string, unknown>,
    useV4?: boolean
    ): Buffer;
    hashType(primaryType: string, types: Record<string, unknown>): Buffer;
    sanitizeData<T extends MessageTypes>(
    data: string | EIP712TypedData | EIP712TypedData[] | TypedMessage<T>
    ): TypedMessage<T>;
    sign<T_1 extends MessageTypes>(
    typedData:
    | string
    | EIP712TypedData[]
    | Partial<EIP712TypedData>
    | Partial<TypedMessage<T_1>>,
    useV4?: boolean
    ): Buffer;
    };
    • A collection of utility functions used for signing typed data

    Functions

    function concatSig

    concatSig: (v: Buffer, r: Buffer, s: Buffer) => string;

      function decrypt

      decrypt: (encryptedData: EthEncryptedData, receiverPrivateKey: string) => string;

        function decryptSafely

        decryptSafely: (
        encryptedData: EthEncryptedData,
        receiverPrivateKey: string
        ) => string;

          function encrypt

          encrypt: <T extends MessageTypes>(
          receiverPublicKey: string,
          msgParams: MsgParams<TypedData | TypedMessage<T>>,
          version: string
          ) => EthEncryptedData;

            function encryptSafely

            encryptSafely: <T extends MessageTypes>(
            receiverPublicKey: string,
            msgParams: MsgParams<TypedData | TypedMessage<T>>,
            version: string
            ) => EthEncryptedData;

              function extractPublicKey

              extractPublicKey: <T extends MessageTypes>(
              msgParams: SignedMsgParams<TypedData | TypedMessage<T>>
              ) => string;

                function getEncryptionPublicKey

                getEncryptionPublicKey: (privateKey: string) => string;

                  function normalize

                  normalize: (input: number | string) => string;

                    function personalSign

                    personalSign: <T extends MessageTypes>(
                    privateKey: Buffer,
                    msgParams: MsgParams<TypedData | TypedMessage<T>>
                    ) => string;

                      function recoverPersonalSignature

                      recoverPersonalSignature: <T extends MessageTypes>(
                      msgParams: SignedMsgParams<TypedData | TypedMessage<T>>
                      ) => string;

                        function recoverTypedMessage

                        recoverTypedMessage: <T extends MessageTypes>(
                        msgParams: SignedMsgParams<TypedData | TypedMessage<T>>,
                        version?: Version
                        ) => string;

                          function recoverTypedSignature

                          recoverTypedSignature: <T extends MessageTypes>(
                          msgParams: SignedMsgParams<TypedData | TypedMessage<T>>
                          ) => string;

                            function recoverTypedSignature_v4

                            recoverTypedSignature_v4: <T extends MessageTypes>(
                            msgParams: SignedMsgParams<TypedData | TypedMessage<T>>
                            ) => string;

                              function recoverTypedSignatureLegacy

                              recoverTypedSignatureLegacy: <T extends MessageTypes>(
                              msgParams: SignedMsgParams<TypedData | TypedMessage<T>>
                              ) => string;

                                function signTypedData

                                signTypedData: <T extends MessageTypes>(
                                privateKey: Buffer,
                                msgParams: MsgParams<TypedData | TypedMessage<T>>
                                ) => string;

                                  function signTypedData_v4

                                  signTypedData_v4: <T extends MessageTypes>(
                                  privateKey: Buffer,
                                  msgParams: MsgParams<TypedData | TypedMessage<T>>
                                  ) => string;

                                    function signTypedDataLegacy

                                    signTypedDataLegacy: <T extends MessageTypes>(
                                    privateKey: Buffer,
                                    msgParams: MsgParams<TypedData | TypedMessage<T>>
                                    ) => string;

                                      function signTypedMessage

                                      signTypedMessage: <T extends MessageTypes>(
                                      privateKey: Buffer,
                                      msgParams: MsgParams<TypedData | TypedMessage<T>>,
                                      version?: Version
                                      ) => string;
                                      • A generic entry point for all typed data methods to be passed, includes a version parameter.

                                      function typedSignatureHash

                                      typedSignatureHash: (typedData: EIP712TypedData[]) => string;

                                        Interfaces

                                        interface EthEncryptedData

                                        interface EthEncryptedData {}

                                          property ciphertext

                                          ciphertext: string;

                                            property ephemPublicKey

                                            ephemPublicKey: string;

                                              property nonce

                                              nonce: string;

                                                property version

                                                version: string;

                                                  interface MsgParams

                                                  interface MsgParams<D> {}

                                                    property data

                                                    data: D;

                                                      property sig

                                                      sig?: string;

                                                        interface TypedMessage

                                                        interface TypedMessage<T extends MessageTypes> {}

                                                          property domain

                                                          domain: {
                                                          name?: string;
                                                          version?: string;
                                                          chainId?: number;
                                                          verifyingContract?: string;
                                                          };

                                                            property message

                                                            message: Record<string, unknown>;

                                                              property primaryType

                                                              primaryType: keyof T;

                                                                property types

                                                                types: T;

                                                                  Type Aliases

                                                                  type SignedMsgParams

                                                                  type SignedMsgParams<D> = Required<MsgParams<D>>;

                                                                    type TypedData

                                                                    type TypedData = string | EIP712TypedData | EIP712TypedData[];

                                                                      type Version

                                                                      type Version = 'V1' | 'V2' | 'V3' | 'V4';

                                                                        Package Files (1)

                                                                        Dependencies (4)

                                                                        Dev Dependencies (12)

                                                                        Peer Dependencies (0)

                                                                        No peer dependencies.

                                                                        Badge

                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/eth-sig-util.

                                                                        • Markdown
                                                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/eth-sig-util)
                                                                        • HTML
                                                                          <a href="https://www.jsdocs.io/package/eth-sig-util"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>