Skip to content

Commit 397cc04

Browse files
committed
Refactor registry related event and functions to a new interface
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
1 parent ec475c2 commit 397cc04

File tree

5 files changed

+53
-27
lines changed

5 files changed

+53
-27
lines changed

solidity/contracts/lib/interfaces/izeto.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ interface IZeto {
5353
address indexed submitter,
5454
bytes data
5555
);
56-
event IdentityRegistered(uint256[2] publicKey, bytes data);
5756

5857
/**
5958
* @dev Returns the name of the token.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright © 2025 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
pragma solidity ^0.8.27;
17+
18+
import {Commonlib} from "../common.sol";
19+
20+
interface IZetoKyc {
21+
event IdentityRegistered(uint256[2] publicKey, bytes data);
22+
23+
function register(
24+
uint256[2] memory publicKey,
25+
bytes calldata data
26+
) external;
27+
28+
function isRegistered(
29+
uint256[2] memory publicKey
30+
) external view returns (bool);
31+
32+
function getIdentitiesRoot() external view returns (uint256);
33+
}

solidity/contracts/lib/registry.sol

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {SmtLib} from "@iden3/contracts/lib/SmtLib.sol";
2020
import {PoseidonUnit2L, PoseidonUnit3L} from "@iden3/contracts/lib/Poseidon.sol";
2121
import {Commonlib} from "./common.sol";
2222
import {IZeto} from "./interfaces/izeto.sol";
23+
import {IZetoKyc} from "./interfaces/izeto_kyc.sol";
2324

2425
uint256 constant MAX_SMT_DEPTH = 64;
2526

@@ -29,7 +30,7 @@ uint256 constant MAX_SMT_DEPTH = 64;
2930
/// submitters can generate proofs of membership for the
3031
/// accounts in a privacy-preserving manner.
3132
/// @author Kaleido, Inc.
32-
abstract contract Registry is OwnableUpgradeable {
33+
abstract contract Registry is OwnableUpgradeable, IZetoKyc {
3334
SmtLib.Data internal _publicKeysTree;
3435
using SmtLib for SmtLib.Data;
3536

@@ -39,19 +40,11 @@ abstract contract Registry is OwnableUpgradeable {
3940
_publicKeysTree.initialize(MAX_SMT_DEPTH);
4041
}
4142

42-
/// @dev Register a new Zeto account
43-
/// @param publicKey The public Babyjubjub key to register
44-
function _register(
43+
function register(
4544
uint256[2] memory publicKey,
4645
bytes calldata data
47-
) internal {
48-
uint256 nodeHash = _getIdentitiesLeafNodeHash(publicKey);
49-
SmtLib.Node memory node = _publicKeysTree.getNode(nodeHash);
50-
if (node.nodeType != SmtLib.NodeType.EMPTY) {
51-
revert AlreadyRegistered(publicKey);
52-
}
53-
_publicKeysTree.addLeaf(nodeHash, nodeHash);
54-
emit IZeto.IdentityRegistered(publicKey, data);
46+
) public onlyOwner {
47+
_register(publicKey, data);
5548
}
5649

5750
/// @dev returns whether the given public key is registered
@@ -69,6 +62,21 @@ abstract contract Registry is OwnableUpgradeable {
6962
return _publicKeysTree.getRoot();
7063
}
7164

65+
/// @dev Register a new Zeto account
66+
/// @param publicKey The public Babyjubjub key to register
67+
function _register(
68+
uint256[2] memory publicKey,
69+
bytes calldata data
70+
) internal {
71+
uint256 nodeHash = _getIdentitiesLeafNodeHash(publicKey);
72+
SmtLib.Node memory node = _publicKeysTree.getNode(nodeHash);
73+
if (node.nodeType != SmtLib.NodeType.EMPTY) {
74+
revert AlreadyRegistered(publicKey);
75+
}
76+
_publicKeysTree.addLeaf(nodeHash, nodeHash);
77+
emit IdentityRegistered(publicKey, data);
78+
}
79+
7280
function _getIdentitiesLeafNodeHash(
7381
uint256[2] memory publicKey
7482
) internal pure returns (uint256) {

solidity/contracts/zeto_anon_enc_nullifier_kyc.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ contract Zeto_AnonEncNullifierKyc is
7474

7575
function _authorizeUpgrade(address) internal override onlyOwner {}
7676

77-
function register(
78-
uint256[2] memory publicKey,
79-
bytes calldata data
80-
) public onlyOwner {
81-
_register(publicKey, data);
82-
}
83-
8477
function constructPublicInputs(
8578
uint256[] memory nullifiers,
8679
uint256[] memory outputs,

solidity/contracts/zeto_anon_nullifier_kyc.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ contract Zeto_AnonNullifierKyc is
8989

9090
function _authorizeUpgrade(address) internal override onlyOwner {}
9191

92-
function register(
93-
uint256[2] memory publicKey,
94-
bytes calldata data
95-
) public onlyOwner {
96-
_register(publicKey, data);
97-
}
98-
9992
function constructPublicInputs(
10093
uint256[] memory nullifiers,
10194
uint256[] memory outputs,

0 commit comments

Comments
 (0)