---
eip: 927
label: ERC-927
title: Generalised authorisations
status: Stagnant
type: Standards Track
category: ERC
created: 2018-03-12
requires: 926
official: https://eips.ethereum.org/EIPS/eip-927
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-927.md
canonical: https://eips.huatuo.xyz/zh/eip-927/
lang: zh
tldr: 提议的单一授权接口 canCall(owner, caller, callee, func)，任何合约都可以用它，而不必重新发明 ERC-20 的 approve 或 ERC-777 的 operator。处于 Stagnant 状态。
tags: [authorization, access-control, permissions, stagnant]
---

# ERC-927: Generalised authorisations

> This EIP specifies a generic authorisation mechanism, which can be used to implement a variety of authorisation patterns, replacing approvals in ERC20, operators in ERC777, and bespoke authorisation patterns in a variety of other types of contract.

**TL;DR:** 提议的单一授权接口 canCall(owner, caller, callee, func)，任何合约都可以用它，而不必重新发明 ERC-20 的 approve 或 ERC-777 的 operator。处于 Stagnant 状态。

## 它解决什么问题？

许多合约允许第三方代表用户行事。例子包括 ERC-20 的 `approve`/`transferFrom`、ERC-777 的 operator，以及 ENS 名称控制器。每个标准都为这种"Alice 允许 Bob 做 X"的模式设计了自己的版本。这些版本彼此不兼容，用户必须在每个合约中分别管理权限。

Nick Johnson 提出的 ERC-927 建议建立**一种通用机制**，让所有此类合约共用。它受到 DappHub 的 `ds-auth` 和 OAuth 的启发。

## 它如何运作

授权信息存储在每个用户各自的**提供者（provider）**合约中。用户在 [ERC-926](/eip-926/) 的地址元数据注册表中登记自己的提供者，该注册表位于一个众所周知的地址。提供者回答一个问题：

```solidity
function canCall(address owner, address caller, address callee, bytes4 func)
    external view returns (bool);
```

| 参数 | 含义 |
| --- | --- |
| `owner` | 其资源被操作的用户。被批准的调用会被视为由该地址发出。 |
| `caller` | 当前发起调用的人（`msg.sender`）。 |
| `callee` | 被调用的合约，例如代币合约。 |
| `func` | 被调用函数的 4 字节选择器。 |

流程：当 Bob 对某个代币调用 `transferFrom(alice, ...)` 时，代币合约会在 ERC-926 注册表中查找 Alice 的提供者。然后调用 `canCall(alice, bob, address(this), msg.sig)`，如果答案为 `false` 就 revert。

提供者**应当**同时提供管理权限的标准方式：

```solidity
function authoriseCaller(address owner, address caller, address callee, bytes4 func);
function revokeCaller(address owner, address caller, address callee, bytes4 func);
```

`func == 0` 表示"`callee` 上的所有函数"。只有所有者本人或所有者授权过的人才能更改该所有者的设置。

## 示例代码

代币在代表他人行事之前可能如何检查权限（示意）：

```solidity
interface IMetadataRegistry { function provider(address addr) external view returns (address); }
interface IAuthProvider {
    function canCall(address owner, address caller, address callee, bytes4 func) external view returns (bool);
}

modifier authorised(address owner) {
    if (msg.sender != owner) {
        address p = REGISTRY.provider(owner);   // ERC-926 查询
        require(p != address(0) &&
                IAuthProvider(p).canCall(owner, msg.sender, address(this), msg.sig),
                "not authorised");
    }
    _;
}

function transferFrom(address from, address to, uint256 v) external authorised(from) { /* ... */ }
```

## 需要注意

- **该提案处于 Stagnant 状态，从未被采纳。** 它所依赖的 [ERC-926](/eip-926/) 同样是 Stagnant，没有任何注册表或提供者成为标准。
- 规范中没有参考实现（"Example implementation TBD"）。上面所示的 `provider(address)` 查询是 ERC-926 中定义的注册表函数。`REGISTRY` 代表注册表那个众所周知的地址，规范并未给出该地址。
- 权限是按函数选择器划分的，而不是按数额。单靠它无法像 ERC-20 的 allowance 那样表达"Bob 最多可以花 100 个代币"。
- 实际上，生态系统转向了基于签名的授权（[ERC-2612](/eip-2612/) permit）和带有自身权限模块的智能合约账户，而不是一个全局的授权注册表。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-927
