Represents a Keyless Public Key used for authentication.

This class encapsulates the public key functionality for keyless authentication, including methods for generating and verifying signatures, as well as serialization and deserialization of the key. The KeylessPublicKey is represented in the SDK as AnyPublicKey.

Hierarchy (View Summary, Expand)

Implementation - BCS

  • Serializes a Serializable value to its BCS representation. This function is the TypeScript SDK equivalent of bcs::to_bytes in Move.

    Returns Uint8Array

    the BCS representation of the Serializable instance as a byte buffer.

  • Converts the BCS-serialized bytes of a value into a Hex instance. This function provides a Hex representation of the BCS-serialized data for easier handling and manipulation.

    Returns Hex

    A Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array.

Implementation - Serialization

idCommitment: Uint8Array

A value representing a cryptographic commitment to a user identity.

It is calculated from the aud, uidKey, uidVal, pepper.

iss: string

The value of the 'iss' claim on the JWT which identifies the OIDC provider.

ID_COMMITMENT_LENGTH: number = 32

The number of bytes that idCommitment should be

  • Serializes the current instance into a format suitable for transmission or storage. This function ensures that all relevant fields are properly serialized, including the proof and optional fields.

    Parameters

    • serializer: Serializer

      The serializer instance used to perform the serialization.

    Returns void

  • Creates a KeylessPublicKey from the JWT components plus pepper

    Parameters

    • args: { aud: string; iss: string; pepper: HexInput; uidKey: string; uidVal: string }
      • aud: string

        the client ID of the application

      • iss: string

        the iss of the identity

      • pepper: HexInput

        The pepper used to maintain privacy of the account

      • uidKey: string

        the key to use to get the uidVal in the JWT token

      • uidVal: string

        the value of the uidKey in the JWT token

    Returns KeylessPublicKey

    KeylessPublicKey

  • Creates a KeylessPublicKey instance from a JWT and a pepper value. This function is useful for generating a public key that can be used for authentication based on the provided JWT claims and pepper.

    Parameters

    • args: { jwt: string; pepper: HexInput; uidKey?: string }

      The arguments for creating the KeylessPublicKey.

      • jwt: string

        The JSON Web Token to decode.

      • pepper: HexInput

        The pepper value used in the key creation process.

      • OptionaluidKey?: string

        An optional key to retrieve the unique identifier from the JWT payload, defaults to "sub".

    Returns KeylessPublicKey

    A KeylessPublicKey instance created from the provided JWT and pepper.

  • Checks if the provided public key is a valid instance by verifying its structure and types.

    Parameters

    • publicKey: PublicKey

      The public key to validate.

    Returns boolean

    A boolean indicating whether the public key is a valid instance.

  • Loads a KeylessPublicKey instance from the provided deserializer. This function is used to deserialize the necessary components to create a KeylessPublicKey.

    Parameters

    • deserializer: Deserializer

      The deserializer used to extract the string and byte data.

      A class that provides methods for deserializing various data types from a byte buffer. It supports deserialization of primitive types, strings, and complex objects using a BCS (Binary Common Serialization) layout.

      • constructor:function
        • Creates a new instance of the class with a copy of the provided data buffer. This prevents outside mutation of the buffer.

          Parameters

          • data: Uint8Array

            The data to be copied into the internal buffer as a Uint8Array.

          Returns Deserializer

      • deserialize:function
        • Helper function that primarily exists to support alternative syntax for deserialization. That is, if we have a const deserializer: new Deserializer(...), instead of having to use MyClass.deserialize(deserializer), we can call deserializer.deserialize(MyClass).

          Type Parameters

          • T

          Parameters

          • cls: Deserializable<T>

            The BCS-deserializable class to deserialize the buffered bytes into.

          Returns T

          the deserialized value of class type T

          const deserializer = new Deserializer(new Uint8Array([1, 2, 3]));
          const value = deserializer.deserialize(MyClass); // where MyClass has a `deserialize` function
          // value is now an instance of MyClass
          // equivalent to `const value = MyClass.deserialize(deserializer)`
      • deserializeBool:function
        • Deserializes a boolean value from a byte stream.

          The BCS layout for a boolean uses one byte, where "0x01" represents true and "0x00" represents false. An error is thrown if the byte value is not valid.

          Returns boolean

          The deserialized boolean value.

          Throws an error if the boolean value is invalid.

      • deserializeBytes:function
        • Deserializes an array of bytes.

          The BCS layout for "bytes" consists of a bytes_length followed by the bytes themselves, where bytes_length is a u32 integer encoded as a uleb128 integer, indicating the length of the bytes array.

          Returns Uint8Array

          The deserialized array of bytes.

      • deserializeFixedBytes:function
        • Deserializes an array of bytes of a specified length.

          Parameters

          • len: number

            The number of bytes to read from the source.

          Returns Uint8Array

      • deserializeOption:function
        • Deserializes an optional value from the buffer.

          The BCS layout for Optional starts with a boolean byte (0 if none, 1 if some), followed by the value if present.

          Parameters

          • type: "string"

            Either a Deserializable class or one of the string literals: "string", "bytes", or "fixedBytes"

          Returns undefined | string

          The deserialized value if present, undefined otherwise

          When "fixedBytes" is specified without a length

          // Deserialize an optional string
          const deserializer = new Deserializer(new Uint8Array([1, 3, 97, 98, 99]));
          const optStr = deserializer.deserializeOption("string");
          // optStr === "abc"

          // Deserialize an optional custom type
          const deserializer = new Deserializer(new Uint8Array([0]));
          const optValue = deserializer.deserializeOption(MyClass);
          // optValue === undefined

          // Deserialize optional bytes
          const deserializer = new Deserializer(new Uint8Array([1, 3, 1, 2, 3]));
          const optBytes = deserializer.deserializeOption("bytes");
          // optBytes === Uint8Array[1, 2, 3]

          // Deserialize optional fixed bytes
          const deserializer = new Deserializer(new Uint8Array([1, 1, 2, 3, 4]));
          const optBytes = deserializer.deserializeOption("fixedBytes", 4);
          // optBytes === Uint8Array[1, 2, 3, 4]
        • Deserializes an optional value from the buffer.

          The BCS layout for Optional starts with a boolean byte (0 if none, 1 if some), followed by the value if present.

          Parameters

          • type: "bytes"

            Either a Deserializable class or one of the string literals: "string", "bytes", or "fixedBytes"

          Returns undefined | Uint8Array<ArrayBufferLike>

          The deserialized value if present, undefined otherwise

          When "fixedBytes" is specified without a length

          // Deserialize an optional string
          const deserializer = new Deserializer(new Uint8Array([1, 3, 97, 98, 99]));
          const optStr = deserializer.deserializeOption("string");
          // optStr === "abc"

          // Deserialize an optional custom type
          const deserializer = new Deserializer(new Uint8Array([0]));
          const optValue = deserializer.deserializeOption(MyClass);
          // optValue === undefined

          // Deserialize optional bytes
          const deserializer = new Deserializer(new Uint8Array([1, 3, 1, 2, 3]));
          const optBytes = deserializer.deserializeOption("bytes");
          // optBytes === Uint8Array[1, 2, 3]

          // Deserialize optional fixed bytes
          const deserializer = new Deserializer(new Uint8Array([1, 1, 2, 3, 4]));
          const optBytes = deserializer.deserializeOption("fixedBytes", 4);
          // optBytes === Uint8Array[1, 2, 3, 4]
        • Deserializes an optional value from the buffer.

          The BCS layout for Optional starts with a boolean byte (0 if none, 1 if some), followed by the value if present.

          Parameters

          • type: "fixedBytes"

            Either a Deserializable class or one of the string literals: "string", "bytes", or "fixedBytes"

          • len: number

            Required length when type is "fixedBytes", ignored otherwise

          Returns undefined | Uint8Array<ArrayBufferLike>

          The deserialized value if present, undefined otherwise

          When "fixedBytes" is specified without a length

          // Deserialize an optional string
          const deserializer = new Deserializer(new Uint8Array([1, 3, 97, 98, 99]));
          const optStr = deserializer.deserializeOption("string");
          // optStr === "abc"

          // Deserialize an optional custom type
          const deserializer = new Deserializer(new Uint8Array([0]));
          const optValue = deserializer.deserializeOption(MyClass);
          // optValue === undefined

          // Deserialize optional bytes
          const deserializer = new Deserializer(new Uint8Array([1, 3, 1, 2, 3]));
          const optBytes = deserializer.deserializeOption("bytes");
          // optBytes === Uint8Array[1, 2, 3]

          // Deserialize optional fixed bytes
          const deserializer = new Deserializer(new Uint8Array([1, 1, 2, 3, 4]));
          const optBytes = deserializer.deserializeOption("fixedBytes", 4);
          // optBytes === Uint8Array[1, 2, 3, 4]
        • Deserializes an optional value from the buffer.

          The BCS layout for Optional starts with a boolean byte (0 if none, 1 if some), followed by the value if present.

          Type Parameters

          • T

            The type of the value to deserialize

          Parameters

          • type: Deserializable<T>

            Either a Deserializable class or one of the string literals: "string", "bytes", or "fixedBytes"

          Returns undefined | T

          The deserialized value if present, undefined otherwise

          When "fixedBytes" is specified without a length

          // Deserialize an optional string
          const deserializer = new Deserializer(new Uint8Array([1, 3, 97, 98, 99]));
          const optStr = deserializer.deserializeOption("string");
          // optStr === "abc"

          // Deserialize an optional custom type
          const deserializer = new Deserializer(new Uint8Array([0]));
          const optValue = deserializer.deserializeOption(MyClass);
          // optValue === undefined

          // Deserialize optional bytes
          const deserializer = new Deserializer(new Uint8Array([1, 3, 1, 2, 3]));
          const optBytes = deserializer.deserializeOption("bytes");
          // optBytes === Uint8Array[1, 2, 3]

          // Deserialize optional fixed bytes
          const deserializer = new Deserializer(new Uint8Array([1, 1, 2, 3, 4]));
          const optBytes = deserializer.deserializeOption("fixedBytes", 4);
          // optBytes === Uint8Array[1, 2, 3, 4]
      • deserializeOptionStr:function
        • Returns undefined | string

          The deserialized string if it exists, otherwise undefined.

          use deserializeOption("string") instead.

          The BCS layout for Optional is 0 if none, else 1 followed by the string length and string content.

          const deserializer = new Deserializer(new Uint8Array([0x00]));
          assert(deserializer.deserializeOptionStr() === undefined);
          const deserializer = new Deserializer(new Uint8Array([1, 8, 49, 50, 51, 52, 97, 98, 99, 100]));
          assert(deserializer.deserializeOptionStr() === "1234abcd");
      • deserializeStr:function
        • Deserializes a UTF-8 encoded string from a byte array. It first reads the length of the string in bytes, followed by the actual byte content, and decodes it into a string.

          BCS layout for "string": string_length | string_content where string_length is a u32 integer encoded as a uleb128 integer, equal to the number of bytes in string_content.

          Returns string

          const deserializer = new Deserializer(new Uint8Array([8, 49, 50, 51, 52, 97, 98, 99, 100]));
          assert(deserializer.deserializeStr() === "1234abcd");
      • deserializeU128:function
        • Deserializes a uint128 number from its binary representation. This function combines two 64-bit values to return a single uint128 value in little-endian format.

          Returns bigint

          The deserialized uint128 number.

      • deserializeU16:function
        • Deserializes a uint16 number from a binary format in little-endian representation.

          BCS layout for "uint16": Two bytes.

          Returns number

          const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]));
          assert(deserializer.deserializeU16() === 4660);
      • deserializeU256:function
        • Deserializes a uint256 number from its binary representation.

          The BCS layout for "uint256" consists of thirty-two bytes in little-endian format.

          Returns bigint

          The deserialized uint256 number.

      • deserializeU32:function
        • Deserializes a uint32 number from a binary format in little-endian representation.

          BCS layout for "uint32": Four bytes.

          Returns number

          const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]));
          assert(deserializer.deserializeU32() === 305419896);
      • deserializeU64:function
        • Deserializes a uint64 number.

          This function combines two 32-bit values to return a 64-bit unsigned integer in little-endian representation.

          Returns bigint

          const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
          assert(deserializer.deserializeU64() === 1311768467750121216);
      • deserializeU8:function
        • Deserializes a uint8 number from the binary data.

          BCS layout for "uint8": One byte. Binary format in little-endian representation.

          Returns number

          The deserialized uint8 number.

      • deserializeUleb128AsU32:function
        • Deserializes a uleb128 encoded uint32 number.

          This function is used for interpreting lengths of variable-length sequences and tags of enum values in BCS encoding.

          Returns number

          The deserialized uint32 value.

          Throws an error if the parsed value exceeds the maximum uint32 number.

      • deserializeVector:function
        • Deserializes an array of BCS Deserializable values given an existing Deserializer instance with a loaded byte buffer.

          Type Parameters

          • T

          Parameters

          • cls: Deserializable<T>

            The BCS-deserializable class to deserialize the buffered bytes into.

          Returns T[]

          An array of deserialized values of type T.

          // serialize a vector of addresses
          const addresses = new Array<AccountAddress>(
          AccountAddress.from("0x1"),
          AccountAddress.from("0x2"),
          AccountAddress.from("0xa"),
          AccountAddress.from("0xb"),
          );
          const serializer = new Serializer();
          serializer.serializeVector(addresses);
          const serializedBytes = serializer.toUint8Array();

          // deserialize the bytes into an array of addresses
          const deserializer = new Deserializer(serializedBytes);
          const deserializedAddresses = deserializer.deserializeVector(AccountAddress);
          // deserializedAddresses is now an array of AccountAddress instances
      • remaining:function
        • Returns the number of bytes remaining in the buffer.

          This information is useful to determine if there's more data to be read.

          Returns number

          The number of bytes remaining in the buffer.

      • fromHex:function

    Returns KeylessPublicKey

    A new instance of KeylessPublicKey.

Methods

  • Verifies a keyless signature for a given message. It will fetch the keyless configuration and the JWK to use for verification from the appropriate network as defined by the aptosConfig.

    Parameters

    • args: {
          aptosConfig: AptosConfig;
          message: HexInput;
          options?: { throwErrorWithReason?: boolean };
          signature: Signature;
      }
      • aptosConfig: AptosConfig

        The aptos config to use for fetching the keyless configuration.

      • message: HexInput

        The message to verify the signature against.

      • Optionaloptions?: { throwErrorWithReason?: boolean }
        • OptionalthrowErrorWithReason?: boolean

          Whether to throw an error with the reason for the failure instead of returning false.

      • signature: Signature

        The signature to verify.

    Returns Promise<boolean>

    true if the signature is valid

MMNEPVFCICPMFPCPTTAAATR