@semaphore-protocol/proof 2.2.0 → 2.3.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.mjs +6 -2
- package/dist/index.node.js +6 -2
- package/package.json +2 -2
- package/src/generateSignalHash.ts +6 -1
- package/src/index.test.ts +7 -0
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 2.
|
|
3
|
+
* @version 2.3.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { poseidon } from 'circomlibjs';
|
|
10
10
|
import { groth16 } from 'snarkjs';
|
|
11
|
+
import { isHexString } from '@ethersproject/bytes';
|
|
11
12
|
import { keccak256 } from '@ethersproject/solidity';
|
|
12
13
|
import { formatBytes32String } from '@ethersproject/strings';
|
|
13
14
|
|
|
@@ -80,7 +81,10 @@ function __generator(thisArg, body) {
|
|
|
80
81
|
* @returns The signal hash.
|
|
81
82
|
*/
|
|
82
83
|
function genSignalHash(signal) {
|
|
83
|
-
|
|
84
|
+
if (!isHexString(signal, 32)) {
|
|
85
|
+
signal = formatBytes32String(signal);
|
|
86
|
+
}
|
|
87
|
+
return BigInt(keccak256(["bytes32"], [signal])) >> BigInt(8);
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
function generateProof(identity, groupOrMerkleProof, externalNullifier, signal, snarkArtifacts) {
|
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 2.
|
|
3
|
+
* @version 2.3.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
12
12
|
|
|
13
13
|
var circomlibjs = require('circomlibjs');
|
|
14
14
|
var snarkjs = require('snarkjs');
|
|
15
|
+
var bytes = require('@ethersproject/bytes');
|
|
15
16
|
var solidity = require('@ethersproject/solidity');
|
|
16
17
|
var strings = require('@ethersproject/strings');
|
|
17
18
|
|
|
@@ -84,7 +85,10 @@ function __generator(thisArg, body) {
|
|
|
84
85
|
* @returns The signal hash.
|
|
85
86
|
*/
|
|
86
87
|
function genSignalHash(signal) {
|
|
87
|
-
|
|
88
|
+
if (!bytes.isHexString(signal, 32)) {
|
|
89
|
+
signal = strings.formatBytes32String(signal);
|
|
90
|
+
}
|
|
91
|
+
return BigInt(solidity.keccak256(["bytes32"], [signal])) >> BigInt(8);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
function generateProof(identity, groupOrMerkleProof, externalNullifier, signal, snarkArtifacts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/proof",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A library to generate and verify Semaphore proofs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typedoc": "^0.22.11"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ethersproject/bytes": "^5.
|
|
37
|
+
"@ethersproject/bytes": "^5.7.0",
|
|
38
38
|
"@ethersproject/solidity": "^5.5.0",
|
|
39
39
|
"@ethersproject/strings": "^5.5.0",
|
|
40
40
|
"@semaphore-protocol/group": "2.0.0",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isHexString } from "@ethersproject/bytes"
|
|
1
2
|
import { keccak256 } from "@ethersproject/solidity"
|
|
2
3
|
import { formatBytes32String } from "@ethersproject/strings"
|
|
3
4
|
|
|
@@ -7,5 +8,9 @@ import { formatBytes32String } from "@ethersproject/strings"
|
|
|
7
8
|
* @returns The signal hash.
|
|
8
9
|
*/
|
|
9
10
|
export default function genSignalHash(signal: string): bigint {
|
|
10
|
-
|
|
11
|
+
if (!isHexString(signal, 32)) {
|
|
12
|
+
signal = formatBytes32String(signal)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return BigInt(keccak256(["bytes32"], [signal])) >> BigInt(8)
|
|
11
16
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatBytes32String } from "@ethersproject/strings"
|
|
1
2
|
import { Group } from "@semaphore-protocol/group"
|
|
2
3
|
import { Identity } from "@semaphore-protocol/identity"
|
|
3
4
|
import download from "download"
|
|
@@ -105,6 +106,12 @@ describe("Proof", () => {
|
|
|
105
106
|
|
|
106
107
|
expect(signalHash.toString()).toBe(fullProof.publicSignals.signalHash)
|
|
107
108
|
})
|
|
109
|
+
|
|
110
|
+
it("Should generate a valid signal hash by passing a valid hex string", async () => {
|
|
111
|
+
const signalHash = generateSignalHash(formatBytes32String(signal))
|
|
112
|
+
|
|
113
|
+
expect(signalHash.toString()).toBe(fullProof.publicSignals.signalHash)
|
|
114
|
+
})
|
|
108
115
|
})
|
|
109
116
|
|
|
110
117
|
describe("# generateNullifierHash", () => {
|