A class extending BytearrayWrapper containing instruments for dealing with message encoding/decoding.

Hierarchy (view full)

Constructors

Properties

value: Uint8Array
maxEncodedLength = 32

The field element size is 32 bytes so the maximum byte size of encoded message must be 32.

textDecoder: TextDecoder = ...
textEncoder: TextEncoder = ...

Accessors

  • get bytes(): Uint8Array
  • Return the wrapped bytearray

    Returns Uint8Array

  • get hex(): string
  • Return the hex representation of the wrapped bytearray

    Returns string

  • get length(): number
  • Return the length of the wrapped bytearray

    Returns number

Methods

  • This is an irreversible encoding as a hash function is used to convert a message of arbitrary length to a fixed length encoding.

    Parameters

    • message: Uint8Array

    Returns Uint8Array

  • This is an irreversible encoding as a hash function is used to convert a message of arbitrary length to a fixed length encoding.

    Parameters

    • message: Uint8Array

    Returns Uint8Array

  • Generates a blind signature over the commitment of unrevealed messages and revealed messages

    Parameters

    • commitment: Uint8Array

      Commitment over unrevealed messages sent by the requester of the blind signature. Its assumed that the signers has verified the knowledge of committed messages

    • revealedMessages: Map<number, Uint8Array>
    • secretKey: BBSPlusSecretKey
    • params: BBSPlusSignatureParamsG1
    • encodeMessages: boolean

    Returns BBSPlusBlindSignatureG1

  • Generate a request for a blind signature

    Parameters

    • messagesToBlind: Map<number, Uint8Array>

      messages the requester wants to hide from the signer. The key of the map is the index of the message as per the params.

    • params: BBSPlusSignatureParamsG1
    • encodeMessages: boolean
    • Optionalblinding: Uint8Array

      If not provided, a random blinding is generated

    • OptionalrevealedMessages: Map<number, Uint8Array>

      Any messages that the requester wishes to inform the signer about. This is for informational purpose only and has no cryptographic use.

    Returns [Uint8Array, BBSPlusBlindSignatureRequest]

  • Decode the given representation. This should only be used when the encoding was done using this.reversibleEncodeStringMessageForSigning. Also, this function trims any characters from the first occurrence of a null characters (UTF-16 code unit 0) so if the encoded (using this.reversibleEncodeStringMessageForSigning) string also had a null then the decoded string will be different from it.

    Parameters

    • message: Uint8Array
    • decompress: boolean = false

      whether to decompress the bytes before converting to a string

    Returns string

  • Encode the given string to bytes and create a field element by considering the bytes in little-endian format. Use this way of encoding only if the input string's UTF-8 representation is <= 32 bytes else this will throw an error. Also adds trailing 0s to the bytes to make the size 32 bytes so use this function carefully. The only place this is currently useful is verifiable encryption as in some cases the prover might not be willing/available at the time of decryption and thus the decryptor must be able to decrypt it independently. This is different from selective disclosure where the verifier can check that the revealed message is same as the encoded one before even verifying the proof.

    Parameters

    • message: string

      utf-8 string of at most 32 bytes

    • compress: boolean = false

      whether to compress the text before encoding to bytes. Compression might not always help as things like public keys, DIDs, UUIDs, etc. are designed to be random and thus won't be compressed

    Returns Uint8Array