import"@openzeppelin/contracts/access/Ownable.sol";contractDecentralisedRegistryisIERC7738{structScriptEntry{mapping(address=>string[])scriptURIs;address[]addrList;}mapping(address=>ScriptEntry)private_scriptURIs;functionsetScriptURI(addresscontractAddress,string[]memoryscriptURIList)public{require(scriptURIList.length>0,"> 0 entries required in scriptURIList");boolisOwnerOrExistingEntry=Ownable(contractAddress).owner()==msg.sender||_scriptURIs[contractAddress].scriptURIs[msg.sender].length>0;_scriptURIs[contractAddress].scriptURIs[msg.sender]=scriptURIList;if(!isOwnerOrExistingEntry){_scriptURIs[contractAddress].addrList.push(msg.sender);}emitScriptUpdate(contractAddress,msg.sender,scriptURIList);}// Return the list of scriptURI for this contract.
// Order the return list so `Owner()` assigned scripts are first in the list
// 返回此合约的 scriptURI 列表。
// 对返回列表进行排序,以便 `Owner()` 分配的脚本在列表中排在第一位
functionscriptURI(addresscontractAddress)publicviewreturns(string[]memory){//build scriptURI return list, owner first
//构建 scriptURI 返回列表,所有者优先
addresscontractOwner=Ownable(contractAddress).owner();address[]memoryaddrList=_scriptURIs[contractAddress].addrList;uint256i;//now calculate list length
//现在计算列表长度
uint256listLen=_scriptURIs[contractAddress].scriptURIs[contractOwner].length;for(i=0;i<addrList.length;i++){listLen+=_scriptURIs[contractAddress].scriptURIs[addrList[i]].length;}string[]memoryownerScripts=newstring[](listLen);// Add owner scripts
// 添加所有者脚本
uint256scriptIndex=_addScriptURIs(contractOwner,contractAddress,ownerScripts,0);// Add remainder scripts
// 添加剩余脚本
for(uint256i=0;i<addrList.length;i++){scriptIndex=_addScriptURIs(addrList[i],contractAddress,ownerScripts,scriptIndex);}returnownerScripts;}function_addScriptURIs(addressuser,addresscontractAddress,string[]memoryownerScripts,uint256scriptIndex)internalviewreturns(uint256){for(uint256j=0;j<_scriptURIs[contractAddress].scriptURIs[user].length;j++){stringmemorythisScriptURI=_scriptURIs[contractAddress].scriptURIs[user][j];if(bytes(thisScriptURI).length>0){ownerScripts[scriptIndex++]=thisScriptURI;}}returnscriptIndex;}}
如果合约未实现 Ownable,则可以采取进一步的步骤:
a. 托管应用/钱包可以使用第三方 API 或区块浏览器确定部署密钥。然后,实现钱包、dapp 或查看器将检查签名是否与此部署密钥匹配。
b. 可以通过嵌入式密钥链由托管应用预先验证签名密钥。
c. governance token 可以允许脚本委员会对设置和验证密钥的请求进行身份验证。
Victor Zhang (@zhangzhongnan928), James Brown (@JamesSmartCell), "ERC-7738: 免许可脚本注册表 [DRAFT]," Ethereum Improvement Proposals, no. 7738, July 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7738.