@semaphore-protocol/utils 4.0.0-beta.1 → 4.0.0-beta.10
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/README.md +4 -4
- package/dist/index.cjs +171 -227
- package/dist/index.js +164 -226
- package/dist/lib.commonjs/constants.cjs +17 -0
- package/dist/lib.commonjs/decode-message.cjs +28 -0
- package/dist/lib.commonjs/index.cjs +14 -5
- package/dist/lib.commonjs/networks/deployed-contracts.json.cjs +94 -0
- package/dist/lib.commonjs/networks/index.cjs +66 -0
- package/dist/lib.commonjs/networks/supported-networks.cjs +38 -0
- package/dist/lib.esm/constants.js +14 -0
- package/dist/lib.esm/decode-message.js +26 -0
- package/dist/lib.esm/index.js +7 -5
- package/dist/lib.esm/networks/deployed-contracts.json.js +92 -0
- package/dist/lib.esm/networks/index.js +59 -0
- package/dist/lib.esm/networks/supported-networks.js +36 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/decode-message.d.ts +12 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/networks/index.d.ts +34 -0
- package/dist/types/networks/supported-networks.d.ts +27 -0
- package/package.json +21 -12
- package/src/constants.ts +5 -0
- package/src/decode-message.ts +17 -0
- package/src/index.ts +4 -3
- package/src/networks/deployed-contracts.json +82 -0
- package/src/networks/index.ts +66 -0
- package/src/networks/supported-networks.ts +26 -0
- package/dist/lib.commonjs/errors.cjs +0 -131
- package/dist/lib.commonjs/types.cjs +0 -130
- package/dist/lib.esm/errors.js +0 -121
- package/dist/lib.esm/types.js +0 -119
- package/dist/types/errors.d.ts +0 -64
- package/dist/types/types.d.ts +0 -73
- package/src/errors.ts +0 -132
- package/src/types.ts +0 -123
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var supportedNetworks = {
|
|
12
|
+
sepolia: {
|
|
13
|
+
name: "Sepolia",
|
|
14
|
+
url: "https://rpc2.sepolia.org",
|
|
15
|
+
chainId: 11155111,
|
|
16
|
+
explorer: "https://sepolia.etherscan.io"
|
|
17
|
+
},
|
|
18
|
+
"arbitrum-sepolia": {
|
|
19
|
+
name: "Arbitrum Sepolia",
|
|
20
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
21
|
+
chainId: 421614,
|
|
22
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
23
|
+
},
|
|
24
|
+
"optimism-sepolia": {
|
|
25
|
+
name: "Optimism Sepolia",
|
|
26
|
+
url: "https://sepolia.optimism.io",
|
|
27
|
+
chainId: 11155420,
|
|
28
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
29
|
+
},
|
|
30
|
+
"matic-mumbai": {
|
|
31
|
+
name: "Matic Mumbai",
|
|
32
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
33
|
+
chainId: 80001,
|
|
34
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = supportedNetworks;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
// Minimum supported tree depth.
|
|
10
|
+
const MIN_DEPTH = 1;
|
|
11
|
+
// Maximum supported tree depth.
|
|
12
|
+
const MAX_DEPTH = 32;
|
|
13
|
+
|
|
14
|
+
export { MAX_DEPTH, MIN_DEPTH };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
import { decodeBytes32String } from 'ethers/abi';
|
|
10
|
+
import { toBeHex } from 'ethers/utils';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Typically used for decoding on-chain Semaphore messages.
|
|
14
|
+
* When Semaphore messages are text they are converted to bigints before
|
|
15
|
+
* the proof is generated (and eventually sent on-chain).
|
|
16
|
+
* This function help devs converting bigint messages to text again.
|
|
17
|
+
* If the original message was not text the output of this
|
|
18
|
+
* function won't probably be human-readable text.
|
|
19
|
+
* @param message The Semaphore message as a bigint.
|
|
20
|
+
* @returns The Semaphore message as a text.
|
|
21
|
+
*/
|
|
22
|
+
function decodeMessage(message) {
|
|
23
|
+
return decodeBytes32String(toBeHex(message, 32));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { decodeMessage as default };
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/utils
|
|
3
|
-
* @version 4.0.0-beta.
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
4
|
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
8
|
*/
|
|
9
|
-
import * as
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
export {
|
|
9
|
+
import * as constants from './constants.js';
|
|
10
|
+
export { constants };
|
|
11
|
+
export { default as decodeMessage } from './decode-message.js';
|
|
12
|
+
export { defaultNetwork, getDeployedContract, getHardhatNetworks, isSupportedNetwork } from './networks/index.js';
|
|
13
|
+
export { default as deployedContracts } from './networks/deployed-contracts.json.js';
|
|
14
|
+
export { default as supportedNetworks } from './networks/supported-networks.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
var deployedContracts = [
|
|
10
|
+
{
|
|
11
|
+
network: "sepolia",
|
|
12
|
+
contracts: [
|
|
13
|
+
{
|
|
14
|
+
name: "SemaphoreVerifier",
|
|
15
|
+
address: "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
16
|
+
startBlock: 5539276
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "PoseidonT3",
|
|
20
|
+
address: "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
21
|
+
startBlock: 5539276
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "Semaphore",
|
|
25
|
+
address: "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
26
|
+
startBlock: 5539276
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
network: "arbitrum-sepolia",
|
|
32
|
+
contracts: [
|
|
33
|
+
{
|
|
34
|
+
name: "SemaphoreVerifier",
|
|
35
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
36
|
+
startBlock: 25837653
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "PoseidonT3",
|
|
40
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
41
|
+
startBlock: 25837653
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "Semaphore",
|
|
45
|
+
address: "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
46
|
+
startBlock: 25837653
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
network: "optimism-sepolia",
|
|
52
|
+
contracts: [
|
|
53
|
+
{
|
|
54
|
+
name: "SemaphoreVerifier",
|
|
55
|
+
address: "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
56
|
+
startBlock: 9663266
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "PoseidonT3",
|
|
60
|
+
address: "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
61
|
+
startBlock: 9663266
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "Semaphore",
|
|
65
|
+
address: "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
66
|
+
startBlock: 9663266
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
network: "matic-mumbai",
|
|
72
|
+
contracts: [
|
|
73
|
+
{
|
|
74
|
+
name: "SemaphoreVerifier",
|
|
75
|
+
address: "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
76
|
+
startBlock: 47356015
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "PoseidonT3",
|
|
80
|
+
address: "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
81
|
+
startBlock: 47356015
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "Semaphore",
|
|
85
|
+
address: "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
86
|
+
startBlock: 47356015
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
export { deployedContracts as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
import deployedContracts from './deployed-contracts.json.js';
|
|
10
|
+
import supportedNetworks from './supported-networks.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @module Networks
|
|
14
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
15
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
16
|
+
* by Semaphore.
|
|
17
|
+
*/
|
|
18
|
+
// Default Semaphore network.
|
|
19
|
+
const defaultNetwork = "sepolia";
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
22
|
+
* @param supportedNetwork The network to be checked.
|
|
23
|
+
*/
|
|
24
|
+
function isSupportedNetwork(supportedNetwork) {
|
|
25
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
29
|
+
* If the private key is not defined it returns an empty object.
|
|
30
|
+
* @param privateKey Private key to be used with networks.
|
|
31
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
32
|
+
*/
|
|
33
|
+
function getHardhatNetworks(privateKey) {
|
|
34
|
+
if (!privateKey) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks));
|
|
38
|
+
for (const key in supportedNetworksCopy) {
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
40
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return supportedNetworksCopy;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
47
|
+
* on a specific supported network.
|
|
48
|
+
* @param supportedNetwork The network supported by Semaphore.
|
|
49
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
50
|
+
*/
|
|
51
|
+
function getDeployedContract(supportedNetwork) {
|
|
52
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
53
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`);
|
|
54
|
+
}
|
|
55
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork);
|
|
56
|
+
return deployedContract.contracts.find(({ name }) => name === "Semaphore");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { defaultNetwork, deployedContracts, getDeployedContract, getHardhatNetworks, isSupportedNetwork, supportedNetworks };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/utils
|
|
3
|
+
* @version 4.0.0-beta.10
|
|
4
|
+
* @file A library to provide utility functions to the other Semaphore packages.
|
|
5
|
+
* @copyright Ethereum Foundation 2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/utils}
|
|
8
|
+
*/
|
|
9
|
+
var supportedNetworks = {
|
|
10
|
+
sepolia: {
|
|
11
|
+
name: "Sepolia",
|
|
12
|
+
url: "https://rpc2.sepolia.org",
|
|
13
|
+
chainId: 11155111,
|
|
14
|
+
explorer: "https://sepolia.etherscan.io"
|
|
15
|
+
},
|
|
16
|
+
"arbitrum-sepolia": {
|
|
17
|
+
name: "Arbitrum Sepolia",
|
|
18
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
19
|
+
chainId: 421614,
|
|
20
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
21
|
+
},
|
|
22
|
+
"optimism-sepolia": {
|
|
23
|
+
name: "Optimism Sepolia",
|
|
24
|
+
url: "https://sepolia.optimism.io",
|
|
25
|
+
chainId: 11155420,
|
|
26
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
27
|
+
},
|
|
28
|
+
"matic-mumbai": {
|
|
29
|
+
name: "Matic Mumbai",
|
|
30
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
31
|
+
chainId: 80001,
|
|
32
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { supportedNetworks as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BigNumberish } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Typically used for decoding on-chain Semaphore messages.
|
|
4
|
+
* When Semaphore messages are text they are converted to bigints before
|
|
5
|
+
* the proof is generated (and eventually sent on-chain).
|
|
6
|
+
* This function help devs converting bigint messages to text again.
|
|
7
|
+
* If the original message was not text the output of this
|
|
8
|
+
* function won't probably be human-readable text.
|
|
9
|
+
* @param message The Semaphore message as a bigint.
|
|
10
|
+
* @returns The Semaphore message as a text.
|
|
11
|
+
*/
|
|
12
|
+
export default function decodeMessage(message: BigNumberish): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
export
|
|
1
|
+
import * as constants from "./constants";
|
|
2
|
+
import decodeMessage from "./decode-message";
|
|
3
|
+
export * from "./networks";
|
|
4
|
+
export { constants, decodeMessage };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Networks
|
|
3
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
4
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
5
|
+
* by Semaphore.
|
|
6
|
+
*/
|
|
7
|
+
import deployedContracts from "./deployed-contracts.json";
|
|
8
|
+
import supportedNetworks from "./supported-networks";
|
|
9
|
+
export type SupportedNetwork = keyof typeof supportedNetworks;
|
|
10
|
+
export declare const defaultNetwork: SupportedNetwork;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
13
|
+
* @param supportedNetwork The network to be checked.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSupportedNetwork(supportedNetwork: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
18
|
+
* If the private key is not defined it returns an empty object.
|
|
19
|
+
* @param privateKey Private key to be used with networks.
|
|
20
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getHardhatNetworks(privateKey?: string): any;
|
|
23
|
+
/**
|
|
24
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
25
|
+
* on a specific supported network.
|
|
26
|
+
* @param supportedNetwork The network supported by Semaphore.
|
|
27
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDeployedContract(supportedNetwork: SupportedNetwork): {
|
|
30
|
+
name: string;
|
|
31
|
+
address: string;
|
|
32
|
+
startBlock: number;
|
|
33
|
+
};
|
|
34
|
+
export { deployedContracts, supportedNetworks };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
sepolia: {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
chainId: number;
|
|
6
|
+
explorer: string;
|
|
7
|
+
};
|
|
8
|
+
"arbitrum-sepolia": {
|
|
9
|
+
name: string;
|
|
10
|
+
url: string;
|
|
11
|
+
chainId: number;
|
|
12
|
+
explorer: string;
|
|
13
|
+
};
|
|
14
|
+
"optimism-sepolia": {
|
|
15
|
+
name: string;
|
|
16
|
+
url: string;
|
|
17
|
+
chainId: number;
|
|
18
|
+
explorer: string;
|
|
19
|
+
};
|
|
20
|
+
"matic-mumbai": {
|
|
21
|
+
name: string;
|
|
22
|
+
url: string;
|
|
23
|
+
chainId: number;
|
|
24
|
+
explorer: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
4
|
"description": "A library to provide utility functions to the other Semaphore packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,15 +12,20 @@
|
|
|
12
12
|
"require": "./dist/index.cjs",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
-
"./
|
|
16
|
-
"types": "./dist/types/
|
|
17
|
-
"require": "./dist/lib.commonjs/
|
|
18
|
-
"default": "./dist/lib.esm/
|
|
15
|
+
"./networks": {
|
|
16
|
+
"types": "./dist/types/networks/index.d.ts",
|
|
17
|
+
"require": "./dist/lib.commonjs/networks/index.cjs",
|
|
18
|
+
"default": "./dist/lib.esm/networks/index.js"
|
|
19
19
|
},
|
|
20
|
-
"./
|
|
21
|
-
"types": "./dist/types/
|
|
22
|
-
"require": "./dist/lib.commonjs/
|
|
23
|
-
"default": "./dist/lib.esm/
|
|
20
|
+
"./constants": {
|
|
21
|
+
"types": "./dist/types/constants.d.ts",
|
|
22
|
+
"require": "./dist/lib.commonjs/constants.cjs",
|
|
23
|
+
"default": "./dist/lib.esm/constants.js"
|
|
24
|
+
},
|
|
25
|
+
"./decode-message": {
|
|
26
|
+
"types": "./dist/types/decode-message.d.ts",
|
|
27
|
+
"require": "./dist/lib.commonjs/decode-message.cjs",
|
|
28
|
+
"default": "./dist/lib.esm/decode-message.js"
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"files": [
|
|
@@ -42,9 +47,13 @@
|
|
|
42
47
|
"access": "public"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
50
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
51
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
45
52
|
"rimraf": "^5.0.5",
|
|
46
|
-
"rollup": "^4.
|
|
47
|
-
"rollup-plugin-cleanup": "^3.2.1"
|
|
48
|
-
|
|
53
|
+
"rollup": "^4.12.0",
|
|
54
|
+
"rollup-plugin-cleanup": "^3.2.1"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"ethers": "^6.11.1"
|
|
49
58
|
}
|
|
50
59
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BigNumberish } from "ethers"
|
|
2
|
+
import { decodeBytes32String } from "ethers/abi"
|
|
3
|
+
import { toBeHex } from "ethers/utils"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Typically used for decoding on-chain Semaphore messages.
|
|
7
|
+
* When Semaphore messages are text they are converted to bigints before
|
|
8
|
+
* the proof is generated (and eventually sent on-chain).
|
|
9
|
+
* This function help devs converting bigint messages to text again.
|
|
10
|
+
* If the original message was not text the output of this
|
|
11
|
+
* function won't probably be human-readable text.
|
|
12
|
+
* @param message The Semaphore message as a bigint.
|
|
13
|
+
* @returns The Semaphore message as a text.
|
|
14
|
+
*/
|
|
15
|
+
export default function decodeMessage(message: BigNumberish) {
|
|
16
|
+
return decodeBytes32String(toBeHex(message, 32))
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"network": "sepolia",
|
|
4
|
+
"contracts": [
|
|
5
|
+
{
|
|
6
|
+
"name": "SemaphoreVerifier",
|
|
7
|
+
"address": "0x58AD7a4389E0F5d814815E5D5A3Ab903dAE9284a",
|
|
8
|
+
"startBlock": 5539276
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "PoseidonT3",
|
|
12
|
+
"address": "0x4EFfF6a6a7BB31cdAd9Ee742b0faAA6Bb9BF096B",
|
|
13
|
+
"startBlock": 5539276
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "Semaphore",
|
|
17
|
+
"address": "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
|
|
18
|
+
"startBlock": 5539276
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"network": "arbitrum-sepolia",
|
|
24
|
+
"contracts": [
|
|
25
|
+
{
|
|
26
|
+
"name": "SemaphoreVerifier",
|
|
27
|
+
"address": "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
28
|
+
"startBlock": 25837653
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "PoseidonT3",
|
|
32
|
+
"address": "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
33
|
+
"startBlock": 25837653
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Semaphore",
|
|
37
|
+
"address": "0x220fBdB6F996827b1Cf12f0C181E8d5e6de3a36F",
|
|
38
|
+
"startBlock": 25837653
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"network": "optimism-sepolia",
|
|
44
|
+
"contracts": [
|
|
45
|
+
{
|
|
46
|
+
"name": "SemaphoreVerifier",
|
|
47
|
+
"address": "0x3d3df6CFc6BFf68d9693e097F32bF4a9903E77a5",
|
|
48
|
+
"startBlock": 9663266
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "PoseidonT3",
|
|
52
|
+
"address": "0x5f4edC58142f4395D1D536e793137A0252dA5a49",
|
|
53
|
+
"startBlock": 9663266
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "Semaphore",
|
|
57
|
+
"address": "0x181B7f34538cE3BceC68597d4A212aB3f7881648",
|
|
58
|
+
"startBlock": 9663266
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"network": "matic-mumbai",
|
|
64
|
+
"contracts": [
|
|
65
|
+
{
|
|
66
|
+
"name": "SemaphoreVerifier",
|
|
67
|
+
"address": "0xE5269ae1E996C6FEEf6E832c7032401E73087568",
|
|
68
|
+
"startBlock": 47356015
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "PoseidonT3",
|
|
72
|
+
"address": "0xC0ae1a8D3505B2bE9DCe0e826abd722Afd13F1c9",
|
|
73
|
+
"startBlock": 47356015
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "Semaphore",
|
|
77
|
+
"address": "0x346a936b19071b2f619200848B8ADbb938D72250",
|
|
78
|
+
"startBlock": 47356015
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Networks
|
|
3
|
+
* This module provides a collection of utility functions to provide the other internal
|
|
4
|
+
* packages and developers with information on deployed contracts and networks supported
|
|
5
|
+
* by Semaphore.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import deployedContracts from "./deployed-contracts.json"
|
|
9
|
+
import supportedNetworks from "./supported-networks"
|
|
10
|
+
|
|
11
|
+
export type SupportedNetwork = keyof typeof supportedNetworks
|
|
12
|
+
|
|
13
|
+
// Default Semaphore network.
|
|
14
|
+
export const defaultNetwork: SupportedNetwork = "sepolia"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if a network is supported by Semaphore, false otherwise.
|
|
18
|
+
* @param supportedNetwork The network to be checked.
|
|
19
|
+
*/
|
|
20
|
+
export function isSupportedNetwork(supportedNetwork: string): boolean {
|
|
21
|
+
return Object.keys(supportedNetworks).includes(supportedNetwork)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Utility function to get an object compatible with the Hardhat 'networks' option.
|
|
26
|
+
* If the private key is not defined it returns an empty object.
|
|
27
|
+
* @param privateKey Private key to be used with networks.
|
|
28
|
+
* @returns An object compatible with the Hardhat 'networks' option.
|
|
29
|
+
*/
|
|
30
|
+
export function getHardhatNetworks(privateKey?: string) {
|
|
31
|
+
if (!privateKey) {
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const supportedNetworksCopy = JSON.parse(JSON.stringify(supportedNetworks))
|
|
36
|
+
|
|
37
|
+
for (const key in supportedNetworksCopy) {
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(supportedNetworksCopy, key)) {
|
|
39
|
+
supportedNetworksCopy[key].accounts = [`0x${privateKey}`]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return supportedNetworksCopy
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns name, address and start block of a Semaphore contract deployed
|
|
48
|
+
* on a specific supported network.
|
|
49
|
+
* @param supportedNetwork The network supported by Semaphore.
|
|
50
|
+
* @returns An object with name, address and start block of the deployed contract.
|
|
51
|
+
*/
|
|
52
|
+
export function getDeployedContract(supportedNetwork: SupportedNetwork) {
|
|
53
|
+
if (!isSupportedNetwork(supportedNetwork)) {
|
|
54
|
+
throw new Error(`Semaphore has not been deployed on '${supportedNetwork}' yet`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const deployedContract = deployedContracts.find(({ network }) => network === supportedNetwork)
|
|
58
|
+
|
|
59
|
+
return deployedContract!.contracts.find(({ name }) => name === "Semaphore") as {
|
|
60
|
+
name: string
|
|
61
|
+
address: string
|
|
62
|
+
startBlock: number
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { deployedContracts, supportedNetworks }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
sepolia: {
|
|
3
|
+
name: "Sepolia",
|
|
4
|
+
url: "https://rpc2.sepolia.org",
|
|
5
|
+
chainId: 11155111,
|
|
6
|
+
explorer: "https://sepolia.etherscan.io"
|
|
7
|
+
},
|
|
8
|
+
"arbitrum-sepolia": {
|
|
9
|
+
name: "Arbitrum Sepolia",
|
|
10
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
11
|
+
chainId: 421614,
|
|
12
|
+
explorer: "https://sepolia.arbiscan.io"
|
|
13
|
+
},
|
|
14
|
+
"optimism-sepolia": {
|
|
15
|
+
name: "Optimism Sepolia",
|
|
16
|
+
url: "https://sepolia.optimism.io",
|
|
17
|
+
chainId: 11155420,
|
|
18
|
+
explorer: "https://sepolia-optimism.etherscan.io"
|
|
19
|
+
},
|
|
20
|
+
"matic-mumbai": {
|
|
21
|
+
name: "Matic Mumbai",
|
|
22
|
+
url: "https://rpc-mumbai.polygon.technology",
|
|
23
|
+
chainId: 80001,
|
|
24
|
+
explorer: "https://mumbai.polygonscan.com"
|
|
25
|
+
}
|
|
26
|
+
}
|