@semaphore-protocol/identity 0.2.1 → 0.2.2
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 +8 -7
- package/dist/index.node.js +8 -11
- package/package.json +4 -4
- package/src/identity.ts +3 -3
- package/src/utils.ts +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/identity
|
|
3
|
-
* @version 0.2.
|
|
3
|
+
* @version 0.2.2
|
|
4
4
|
* @file A library for managing Semaphore identities.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
import { BigNumber } from '@ethersproject/bignumber';
|
|
10
10
|
import { poseidon } from 'circomlibjs';
|
|
11
11
|
import { randomBytes } from '@ethersproject/random';
|
|
12
|
-
import
|
|
12
|
+
import { sha256 as sha256$1 } from '@ethersproject/sha2';
|
|
13
|
+
import { toUtf8Bytes } from '@ethersproject/strings';
|
|
13
14
|
|
|
14
15
|
function checkParameter(value, name, type) {
|
|
15
16
|
if (typeof value !== type) {
|
|
@@ -23,8 +24,8 @@ function checkParameter(value, name, type) {
|
|
|
23
24
|
* @returns The hexadecimal hash of the message.
|
|
24
25
|
*/
|
|
25
26
|
function sha256(message) {
|
|
26
|
-
var hash =
|
|
27
|
-
return hash
|
|
27
|
+
var hash = sha256$1(toUtf8Bytes(message));
|
|
28
|
+
return hash;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* Generates a random big number.
|
|
@@ -62,9 +63,9 @@ var Identity = /** @class */ (function () {
|
|
|
62
63
|
}
|
|
63
64
|
checkParameter(identityOrMessage, "identityOrMessage", "string");
|
|
64
65
|
if (!isJsonArray(identityOrMessage)) {
|
|
65
|
-
var messageHash = sha256(identityOrMessage);
|
|
66
|
-
this._trapdoor = BigNumber.from(
|
|
67
|
-
this._nullifier = BigNumber.from(
|
|
66
|
+
var messageHash = sha256(identityOrMessage).slice(2);
|
|
67
|
+
this._trapdoor = BigNumber.from(sha256("".concat(messageHash, "identity_trapdoor"))).toBigInt();
|
|
68
|
+
this._nullifier = BigNumber.from(sha256("".concat(messageHash, "identity_nullifier"))).toBigInt();
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
var _a = JSON.parse(identityOrMessage), trapdoor = _a[0], nullifier = _a[1];
|
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/identity
|
|
3
|
-
* @version 0.2.
|
|
3
|
+
* @version 0.2.2
|
|
4
4
|
* @file A library for managing Semaphore identities.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -13,11 +13,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
13
13
|
var bignumber = require('@ethersproject/bignumber');
|
|
14
14
|
var circomlibjs = require('circomlibjs');
|
|
15
15
|
var random = require('@ethersproject/random');
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
-
|
|
20
|
-
var _sha256__default = /*#__PURE__*/_interopDefaultLegacy(_sha256);
|
|
16
|
+
var sha2 = require('@ethersproject/sha2');
|
|
17
|
+
var strings = require('@ethersproject/strings');
|
|
21
18
|
|
|
22
19
|
function checkParameter(value, name, type) {
|
|
23
20
|
if (typeof value !== type) {
|
|
@@ -31,8 +28,8 @@ function checkParameter(value, name, type) {
|
|
|
31
28
|
* @returns The hexadecimal hash of the message.
|
|
32
29
|
*/
|
|
33
30
|
function sha256(message) {
|
|
34
|
-
var hash =
|
|
35
|
-
return hash
|
|
31
|
+
var hash = sha2.sha256(strings.toUtf8Bytes(message));
|
|
32
|
+
return hash;
|
|
36
33
|
}
|
|
37
34
|
/**
|
|
38
35
|
* Generates a random big number.
|
|
@@ -70,9 +67,9 @@ var Identity = /** @class */ (function () {
|
|
|
70
67
|
}
|
|
71
68
|
checkParameter(identityOrMessage, "identityOrMessage", "string");
|
|
72
69
|
if (!isJsonArray(identityOrMessage)) {
|
|
73
|
-
var messageHash = sha256(identityOrMessage);
|
|
74
|
-
this._trapdoor = bignumber.BigNumber.from(
|
|
75
|
-
this._nullifier = bignumber.BigNumber.from(
|
|
70
|
+
var messageHash = sha256(identityOrMessage).slice(2);
|
|
71
|
+
this._trapdoor = bignumber.BigNumber.from(sha256("".concat(messageHash, "identity_trapdoor"))).toBigInt();
|
|
72
|
+
this._nullifier = bignumber.BigNumber.from(sha256("".concat(messageHash, "identity_nullifier"))).toBigInt();
|
|
76
73
|
return;
|
|
77
74
|
}
|
|
78
75
|
var _a = JSON.parse(identityOrMessage), trapdoor = _a[0], nullifier = _a[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/identity",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A library for managing Semaphore identities.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/crypto-js": "^4.1.1",
|
|
31
30
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
32
31
|
"rollup-plugin-typescript2": "^0.31.2",
|
|
33
32
|
"typedoc": "^0.22.11"
|
|
@@ -35,7 +34,8 @@
|
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"@ethersproject/bignumber": "^5.5.0",
|
|
37
36
|
"@ethersproject/random": "^5.5.1",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
37
|
+
"@ethersproject/sha2": "^5.6.1",
|
|
38
|
+
"@ethersproject/strings": "^5.6.1",
|
|
39
|
+
"circomlibjs": "0.0.8"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/identity.ts
CHANGED
|
@@ -22,10 +22,10 @@ export default class Identity {
|
|
|
22
22
|
checkParameter(identityOrMessage, "identityOrMessage", "string")
|
|
23
23
|
|
|
24
24
|
if (!isJsonArray(identityOrMessage)) {
|
|
25
|
-
const messageHash = sha256(identityOrMessage)
|
|
25
|
+
const messageHash = sha256(identityOrMessage).slice(2)
|
|
26
26
|
|
|
27
|
-
this._trapdoor = BigNumber.from(
|
|
28
|
-
this._nullifier = BigNumber.from(
|
|
27
|
+
this._trapdoor = BigNumber.from(sha256(`${messageHash}identity_trapdoor`)).toBigInt()
|
|
28
|
+
this._nullifier = BigNumber.from(sha256(`${messageHash}identity_nullifier`)).toBigInt()
|
|
29
29
|
|
|
30
30
|
return
|
|
31
31
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber"
|
|
2
2
|
import { randomBytes } from "@ethersproject/random"
|
|
3
|
-
import _sha256 from "
|
|
3
|
+
import { sha256 as _sha256 } from "@ethersproject/sha2"
|
|
4
|
+
import { toUtf8Bytes } from "@ethersproject/strings"
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Returns an hexadecimal sha256 hash of the message passed as parameter.
|
|
@@ -8,9 +9,9 @@ import _sha256 from "crypto-js/sha256"
|
|
|
8
9
|
* @returns The hexadecimal hash of the message.
|
|
9
10
|
*/
|
|
10
11
|
export function sha256(message: string): string {
|
|
11
|
-
const hash = _sha256(message)
|
|
12
|
+
const hash = _sha256(toUtf8Bytes(message))
|
|
12
13
|
|
|
13
|
-
return hash
|
|
14
|
+
return hash
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|