Initializes the class attributes based on a given private key, which must be text or a buffer. If the private key is not passed as a parameter, a random private key will be generated. The EdDSAPoseidon class is used to generate the secret scalar and the public key. Additionally, the constructor computes a commitment of the public key using a hash function (Poseidon).
Optional
privateKey: string | Buffer | Uint8ArrayThe private key used to derive the public key (hexadecimal or string).
// Generates an identity.
const { privateKey, publicKey, commitment } = new Identity("private-key")
// Generates an identity with a random private key.
const { privateKey, publicKey, commitment } = new Identity()
Private
_commitmentPrivate
_privatePrivate
_publicPrivate
_secretReturns the commitment hash of the public key.
The commitment as a string.
Returns the private key.
The private key as a buffer or text.
Returns the secret scalar.
The secret scalar as a string.
Generates a signature for a given message using the private key. This method demonstrates how to sign a message and could be used for authentication or data integrity.
The message to be signed.
A Signature object containing the signature components.
const identity = new Identity()
const signature = identity.signMessage("message")
Static
generateGenerates the commitment from the given public key. This static method is particularly useful after signature verification, as it allows retrieval of the corresponding commitment associated with the public key.
The public key to generate the commitment.
The Semaphore identity commitment.
const identity = new Identity()
Identity.generateCommitment(identity.publicKey)
Static
importStatic
verifyVerifies a signature against a given message and public key. This static method allows for the verification of signatures without needing an instance of the Identity class. It's useful for cases where you only have the public key, the message and a signature, and need to verify if they match.
A boolean indicating whether the signature is valid.
const identity = new Identity()
const signature = identity.signMessage("message")
Identity.verifySignature("message", signature, identity.publicKey)
The Semaphore identity is essentially an EdDSA public/private key pair. The EdDSA implementation in this library uses Baby Jubjub for public key generation and Poseidon for signatures. In addition, the commitment, i.e. the hash of the public key, is used to represent Semaphore identities in groups, adding an additional layer of privacy and security. The private key of the identity can be exported as a base64 string.