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 | Uint8Array | BufferThe 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 public key as a Baby Jubjub Point.
The public key as a point.
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
importReturns a Semaphore identity based on a private key encoded as a base64 string. The private key will be converted to a buffer, regardless of its original type.
The private key as a base64 string.
The Semaphore identity.
Static
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.
The message that was signed.
The signature to verify.
The public key to use for verification.
A boolean indicating whether the signature is valid.
const identity = new Identity()
const signature = identity.signMessage("message")
Identity.verifySignature("message", signature, identity.publicKey)
Generated using TypeDoc
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.