@semaphore-protocol/identity 4.3.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/identity
3
- * @version 4.3.1
3
+ * @version 4.4.0
4
4
  * @file A library to create Semaphore identities.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -126,6 +126,21 @@ class Identity {
126
126
  static verifySignature(message, signature, publicKey) {
127
127
  return eddsaPoseidon.verifySignature(message, signature, publicKey);
128
128
  }
129
+ /**
130
+ * Generates the commitment from the given public key.
131
+ * This static method is particularly useful after signature verification,
132
+ * as it allows retrieval of the corresponding commitment associated with the public key.
133
+ *
134
+ * @example
135
+ * const identity = new Identity()
136
+ * Identity.generateCommitment(identity.publicKey)
137
+ *
138
+ * @param publicKey The public key to generate the commitment.
139
+ * @returns The Semaphore identity commitment.
140
+ */
141
+ static generateCommitment(publicKey) {
142
+ return poseidon2.poseidon2(publicKey);
143
+ }
129
144
  }
130
145
 
131
146
  exports.Identity = Identity;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/identity
3
- * @version 4.3.1
3
+ * @version 4.4.0
4
4
  * @file A library to create Semaphore identities.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -124,6 +124,21 @@ class Identity {
124
124
  static verifySignature(message, signature, publicKey) {
125
125
  return verifySignature(message, signature, publicKey);
126
126
  }
127
+ /**
128
+ * Generates the commitment from the given public key.
129
+ * This static method is particularly useful after signature verification,
130
+ * as it allows retrieval of the corresponding commitment associated with the public key.
131
+ *
132
+ * @example
133
+ * const identity = new Identity()
134
+ * Identity.generateCommitment(identity.publicKey)
135
+ *
136
+ * @param publicKey The public key to generate the commitment.
137
+ * @returns The Semaphore identity commitment.
138
+ */
139
+ static generateCommitment(publicKey) {
140
+ return poseidon2(publicKey);
141
+ }
127
142
  }
128
143
 
129
144
  export { Identity };
@@ -94,4 +94,17 @@ export declare class Identity {
94
94
  * @returns A boolean indicating whether the signature is valid.
95
95
  */
96
96
  static verifySignature(message: BigNumberish, signature: Signature, publicKey: Point): boolean;
97
+ /**
98
+ * Generates the commitment from the given public key.
99
+ * This static method is particularly useful after signature verification,
100
+ * as it allows retrieval of the corresponding commitment associated with the public key.
101
+ *
102
+ * @example
103
+ * const identity = new Identity()
104
+ * Identity.generateCommitment(identity.publicKey)
105
+ *
106
+ * @param publicKey The public key to generate the commitment.
107
+ * @returns The Semaphore identity commitment.
108
+ */
109
+ static generateCommitment(publicKey: Point): bigint;
97
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/identity",
3
- "version": "4.3.1",
3
+ "version": "4.4.0",
4
4
  "description": "A library to create Semaphore identities.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -138,4 +138,20 @@ export class Identity {
138
138
  static verifySignature(message: BigNumberish, signature: Signature, publicKey: Point): boolean {
139
139
  return verifySignature(message, signature, publicKey)
140
140
  }
141
+
142
+ /**
143
+ * Generates the commitment from the given public key.
144
+ * This static method is particularly useful after signature verification,
145
+ * as it allows retrieval of the corresponding commitment associated with the public key.
146
+ *
147
+ * @example
148
+ * const identity = new Identity()
149
+ * Identity.generateCommitment(identity.publicKey)
150
+ *
151
+ * @param publicKey The public key to generate the commitment.
152
+ * @returns The Semaphore identity commitment.
153
+ */
154
+ static generateCommitment(publicKey: Point): bigint {
155
+ return poseidon2(publicKey)
156
+ }
141
157
  }