The Semaphore group is a LeanIMT (Lean Incremental Merkle Tree), i.e. an optimized version of the incremental binary Merkle tree used by Semaphore V3. The new tree does not use zero hashes, and its depth is dynamic. The members of a Semaphore group, or the leaves of a tree, are the identity commitments. Thanks to the properties of Merkle trees, it can be efficiently demonstrated that a group member belongs to the group. This class supports operations such as member addition, update, removal and Merkle proof generation and verification. Groups can also be exported or imported.

Constructors

  • Creates a new instance of the Group. Optionally, a list of identity commitments can be passed as a parameter. Adding members in chunks is more efficient than adding them one by one with the addMember function.

    Parameters

    • members: BigNumber[] = []

      A list of identity commitments.

    Returns Group

Properties

leanIMT: default<bigint>

Accessors

  • get members(): bigint[]
  • Returns the members (i.e. identity commitments) of the group.

    Returns bigint[]

    The list of members of the group.

  • get size(): number
  • Returns the size of the tree (i.e. number of leaves).

    Returns number

    The tree size as a number.

Methods

  • Adds a new member to the group.

    Parameters

    • member: BigNumber

      The new member to be added.

    Returns void

  • Adds new members to the group.

    Parameters

    • members: BigNumber[]

      New members.

    Returns void

  • Enables the conversion of the group into a JSON string that can be re-used for future imports. This approach is beneficial for large groups, as it avoids re-calculating the tree hashes.

    Returns string

    The stringified JSON of the group.

  • Returns the index of a member. If the member does not exist it returns -1.

    Parameters

    • member: BigNumber

      A member of the group.

    Returns number

    The index of the member, or -1 if it does not exist.

  • Removes a member from the group.

    Parameters

    • index: number

      The index of the member to be removed.

    Returns void

  • Updates a member in the group.

    Parameters

    • index: number

      Index of the member to be updated.

    • member: BigNumber

      New member value.

    Returns void

  • Imports an entire group by initializing the tree without calculating any hashes. Note that it is crucial to ensure the integrity of the exported group.

    Parameters

    • nodes: string

      The stringified JSON of the group.

    Returns Group

    The Group instance.