A library to create Semaphore identities.
This library provides a class that can be used to create identities compatible with the Semaphore circuits. Each identity contains an EdDSA private key, its public key, and the identity commitment, which is the Poseidon hash of the public key. |
---|
Install the @semaphore-protocol/identity
package with npm:
npm i @semaphore-protocol/identity
or yarn:
yarn add @semaphore-protocol/identity
For more information on the functions provided by @semaphore-protocol/identity
, please refer to the TypeDoc documentation.
# new Identity(privateKey?: BigNumberish): Identity
import { Identity } from "@semaphore-protocol/identity"
// The identity will be generated randomly.
const { privateKey, publicKey, commitment } = new Identity()
// Alternatively, you can pass your private key.
const identity = new Identity("your-private-key")
# identity.export(): string
import { Identity } from "@semaphore-protocol/identity"
const identity = new Identity()
const privateKey = identity.export()
# identity.import(privateKey: string): Identity
import { Identity } from "@semaphore-protocol/identity"
const identity = new Identity()
const privateKey = identity.export()
const identity2 = Identity.import(privateKey)
# identity.signMessage(message: BigNumberish): Signature<string>
import { Identity } from "@semaphore-protocol/identity"
const message = "message"
const identity = new Identity()
const signature = identity.signMessage(message)
# Identity.verifySignature(message: BigNumberish, signature: Signature, publicKey: Point): boolean
import { Identity } from "@semaphore-protocol/identity"
const message = "message"
const identity = new Identity()
const signature = identity.signMessage(message)
Identity.verifySignature(message, signature, identity.publicKey)
# Identity.generateCommitment(publicKey: Point): bigint
import { Identity } from "@semaphore-protocol/identity"
Identity.generateCommitment(identity.publicKey)