navio-blsct
    Preparing search index...

    Class Scalar

    Represents an element of the finite field $\mathbb{F}_r$, where $r$ is the order of the generator point of the BLS12-381 G1 group. A wrapper of MclScalar in navio-core.

    Examples:

    const { Scalar } = require('navio-blsct')
    const s1 = new Scalar() // random scalar
    const s2 = new Scalar(12345)
    s2.toNumber() // returns 12345
    const s3 = Scalar.deserialize(s2.serialize())
    s3.equals(s2) // true
    const ser = s1.serialize()
    const deser = Scalar.deserialize(ser)
    ser === deser.serialize() // true

    Hierarchy (View Summary)

    Index

    Constructors

    • Constructs a new Scalar instance.

      • If no parameter is provided, a random scalar is generated.
      • If a number is provided, it is converted to a scalar.

      Parameters

      • Optionalobj: any

      Returns Scalar

    Properties

    obj: any
    objSize: number

    Methods

    • Returns if the scalar is equal to the provided scalar.

      Parameters

      • other: Scalar

        The scalar to compare with.

      Returns boolean

      true if the scalars are equal, false otherwise.

    • Returns the underlying C++ object, transferring ownership from this instance to the caller.

      Returns any

      The underlying object of the instance.

    • Returns the size of the underlying C++ object.

      Returns number

      The size of the underlying C++ object in bytes.

    • Converts the scalar to an integer. *

      Returns number

      The scalar as a number.

    • Returns a string representation of the instance.

      Returns string

      A string representation of the instance.

    • Deserializes a hexadecimal string into a Scalar instance.

      Parameters

      • this: new (obj: any) => Scalar
      • hex: string

        The hexadecimal string to convert.

      Returns Scalar

      The Scalar instance represented by the input string.

    • Constucts a new instance using the provided object.

      Type Parameters

      Parameters

      • this: new (obj: any, objSize?: number) => T
      • obj: any

        The object to use for the new instance.

      Returns T

      A new instance of the class.

    • Constructs a new instance using the provided object and size.

      Type Parameters

      Parameters

      • this: new (obj: any) => T
      • obj: any

        The object to use for the new instance.

      • objSize: number

        The size of the object.

      Returns T

      A new instance of the class.

    • Generates a random scalar.

      Returns Scalar

      A random scalar in the finite field $\mathbb{F}_r$.