bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 30쪽
ess we want to authenticate for.
* @param mainENSNodeHash The main ENS Node Hash
* @param authAddress The address of the authentication wallet
* @param authENSNodeHash The auth ENS Node Hash
*/
function validate(
address ensRegistry,
address mainAddress,
bytes32 mainENSNodeHash,
string calldata authKey,
address authAddress,
bytes32 authENSNodeHash
) internal view returns (bool) {
_verifyMainENS(ensRegistry, mainAddress, mainENSNodeHash, authKey, authAddress);
_verifyAuthENS(ensRegistry, mainAddress, authKey, authAddress, authENSNodeHash);
return true;
}
// *********************
// Helper Functions
// *********************
function _verifyMainENS(
address ensRegistry,
address mainAddress,
bytes32 mainENSNodeHash,
string calldata authKey,
address authAddress
) private view {
// Check if the ENS nodes resolve correctly to the provided addresses
address mainResolver = ENS(ensRegistry).resolver(mainENSNodeHash);
require(mainResolver != address(0), "Main ENS not registered");
require(mainAddress == Resolver(mainResolver).addr(mainENSNodeHash), "Main address is wrong");
// Verify the authKey TEXT record is set to authAddress by mainENS
string memory authText = Resolver(mainResolver).text(mainENSNodeHash, string(abi.encodePacked("eip5131:", authKey)));
require(
keccak256(bytes(authText)) == keccak256(bytes(_addressToString(authAddress))),
"Invalid auth address"
);
}
function _verifyAuthENS(
address ensRegistry,
address mainAddress,
string memory authKey,
address authAddress,
bytes32 authENSNodeHash
) private view {
// Check if the ENS nodes resolve correctly to the provided addresses
address authResolver = ENS(ensRegistry).resolver(authENSNodeHash);
require(authResolver != address(0), "Auth ENS not registered");
require(authAddress == Resolver(authResolver).addr(authENSNodeHash), "Auth address is wrong");
// Verify the TEXT record is appropriately set by authENS
string memory vaultText = Resolver(authResolver).text(authENSNodeHash, "eip5131:vault");
require(
keccak256(abi.encodePacked(authKey, ":", _addressToString(mainAddress))) ==
keccak256(bytes(vaultText)),
"Invalid auth text record"
);
}
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
function sha3HexAddress(address addr) private pure returns (bytes32 ret) {
uint256 value = uint256(uint160(addr));
bytes memory buffer = new bytes(40);
for (uint256 i = 39; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
return keccak256(buffer);
}
function _addressToString(address addr) private pure returns (string memory ptr) {
// solhint-disable-next-line no-inline-assembly
assembly {
ptr := mload(0x40)
// Adjust mem ptr and keep 32 byte aligned
// 32 bytes to store string length; address is 42 bytes long
mstore(0x40, add(ptr, 96))
// Store (string length, '0', 'x') (42, 48, 120)
// Single write by offsetting across 32 byte boundary
ptr := add(ptr, 2)
mstore(ptr, 0x2a3078)
// Write string backwards
for {
// end is at 'x', ptr is at lsb char
let end := add(ptr, 31)
ptr := add(ptr, 71)
} gt(ptr, end) {
ptr := sub(ptr, 1)
addr := shr(4, addr)
} {
let v := and(addr, 0xf)
// if > 9, use ascii 'a-f' (no conditional required)
v := add(v, mul(gt(v, 9), 39))
// Add ascii for '0'
v := add(v, 48)
mstore8(ptr, v)
}
// return ptr to point to length (32 + 2 for '0x' - 1)
ptr := sub(ptr, 33)
}
return string(ptr);
}
}
```
### Security Considerations
The core purpose of this EIP is to enhance security and promote a safer way to authenticate wallet control and asset ownership when the main wallet is not needed and assets held by the main wallet do not need to be moved. Consider it a way to do 'read only' authentication.
### Copyright
Copyright and related rights waived via [CC0](https://eips.ethereum.org/LICENSE).
import { EnsipHeader } from "../../components/EnsipHeader";
## ENSIP-14: On Chain Source Parameter
<EnsipHeader authors={["slobo.eth","avsa.eth"]} created="February 7, 2021" status="draft" />
Using the reveal secret as a way to have on chain information about the source of the registration.
### Abstract
We have many reasons to measure user registration names. Knowing our ecosystem and which apps are popular is essential for identifying the creators who contribute. Retroactive funding via grants is often better than proactive funding, as it allows us to detect what has already worked, rather than relying on guesses. This community often sees unexpected successes that we can't predict.
At the same time, it's important to make the process transparent, open source, and privacy-preserving. Source data would also help create referral programs.
### Specification
The ETH Registrar Controller takes a random secret as part of its input. This secret parameter is random data that obscures the name before the final step of the registration process is complete. It is 32 bytes of entropy and the ens manager app on app.ens.domains generates it by calling `require('crypto').randomBytes(32)`.
This proposal suggests a social convention that generates the secret from a combination of the first **4 bytes of the namehash**, plus another **4 bytes for user referrals**, combined with the appropriate number of random bytes.
In hex formatted string it means that the first 8 chars of the secret would be the platform name and the next 8 would be used as an identifier of the user referral. For example, if the above was registered via ensfairy, the secret would be:
> 0x **1b7f8b3c** **612c63bc** c635528d3b7196bc89d13566c1be2068af0cad6fb3ecebf0
With this, we can attribute registrations using the first 16 chars of the secret. The loss of entropy of 64 bits is not relevant, since the only goal of the secret is to obscure the details of the bid to avoid front-running during the short period (usually a few minutes, but it could be as long as a week) before the reveal transaction is executed. The secret still retains 192 bits, which is highly secure, especially for such a short time frame.
### User Referral Data
The goal of this ENSIP is to empower app makers and anyone who wants to start a registration campaign. Any app that conforms to this standard should accept a referral link in the form of `?ensref=12345678` (or a similar scheme for mobile apps and other platforms). When a new user arrives at the site via a referral code, the platform should try to remember the user if they later register an ENS name, by appending the code to the platform code, followed by the rest of the secret. Standard cookie and private data regulations apply. While we encourage users to derive their code from a namehash, any random code should be accepted.
The extra data can be used in this example:
* Alice refers Bob to an ENS registrar app using a custom link like `app.ens.domains/?ensref=deadbeef`
* If Bob clicks the link, the information is saved on the cookies/local storage (until it's overwritten by another referral code, Bob clears his memory, or the code expires).
* Later, Bob wants to register a name; the secret will be prepended by the first 8 letters of the platform, followed by the code provided by Alice.
This allows individuals who don't own a name registrar app, but have their own audience, to have a cross-registrar referral, which registrars can choose to share revenue with.
### Privacy Concerns
This action makes it public which apps users are using to register names, and may reveal who they are friends with or who they follow. It could also reveal some demographic information about accounts - if a registrar app is known to be popular in a certain country or to only have a UI in a certain language, it can indicate that a specific Ethereum address might be from that demographic. This is not unlike seeing a user send funds to a known exchange address.
To address these concerns, we ask app makers to make the process transparent and allow users to opt-out of either the referral code or the whole platform code being added to their secret.
This would also enable comparison of different clients' usage - again, this is by design. If a given platform doesn't want any of their numbers to be public, they can simply not implement it.
### A Reverse Code Registry
Since the source code is derived from the namehash, it's not reversible. Therefore, some sort of registry of names is needed to make sense of these names. Such registrars could be made on-chain or simply be a git text file with multiple forks across many repos. A registrar definition is outside the scope of this ENSIP, as if the ground truth was on-chain it would be relatively easy to game.
With a purely random number, it would take about 30,000 registrants to create a 10% chance of an accidental collision, and by 77,163 codes that chance increases to 50%. This means it should be quite rare for an accidental collision to happen, but it is still trivial to create such a collision or to spam a registry. Therefore, instead of trying to play the security cat and mouse game, we would rather leave the "truth" of the codes to their usage. If someone is using them to create a ranking website or launch a referral program, each should simply exercise common sense to maintain their own copy of the registry for the very top of the ranking, where it should be easier to disambiguate.
import { EnsipHeader } from "../../components/EnsipHeader";
## ENSIP-15: Name Normalization
<EnsipHeader authors={["raffy.eth"]} created="April 3, 2023" status="final" />
### Abstract
This ENSIP standardizes Ethereum Name Service (ENS) name normalization process outlined in [ENSIP-1 § Name Syntax](/ensip/1#name-syntax).
### Motivation
* Since [ENSIP-1](/ensip/1) (originally [EIP-137](https://eips.ethereum.org/EIPS/eip-137)) was finalized in 2016, Unicode has [evolved](https://unicode.org/history/publicationdates.html) from version 8.0.0 to 15.0.0 and incorporated many new characters, including complex emoji sequences.
* ENSIP-1 does not state the version of Unicode.
* ENSIP-1 implies but does not state an explicit flavor of IDNA processing.
* [UTS-46](https://unicode.org/reports/tr46/) is insufficient to normalize emoji sequences. Correct emoji processing is only possible with [UTS-51](https://www.unicode.org/reports/tr51/).
* Validation tests are needed to ensure implementation compliance.
* The success of ENS has encouraged spoofing via the following techniques:
1. Insertion of zero-width characters.
2. Using names which normalize differently between algorithms.
3. Using names which appear differently between applications and devices.
4. Substitution of confusable (look-alike) characters.
5. Mixing incompatible scripts.
### Specification
* Unicode version `17.0.0` ([Versions](#versions))
* Normalization is a living specification and should use the latest stable version of Unicode.
* [`spec.json`](https://github.com/adraffy/ens-normalize.js/blob/main/derive/output/spec.json) contains all [necessary data](#description-of-specjson) for normalization.
* [`nf.json`](https://github.com/adraffy/ens-normalize.js/blob/main/derive/output/nf.json) contains all [necessary data](#description-of-nfjson) for [Unicode Normalization Forms](https://unicode.org/reports/tr15/) NFC and NFD.
#### Definitions
* Terms in **bold** throughout this document correspond with [components of `spec.json`](#description-of-specjson).
* A string is a sequence of Unicode codepoints.
* Example: `"abc"` is `61 62 63`
* An [Unicode emoji](https://www.unicode.org/reports/tr51/) is a [single entity](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) composed of one or more codepoints:
* An **Emoji Sequence** is the preferred form of an emoji, resulting from input that [tokenized](#tokenize) into an `Emoji` token.
* Example: `💩︎︎ [1F4A9]` → `Emoji[1F4A9 FE0F]`
* `1F4A9 FE0F` is the **Emoji Sequence**.
* [`spec.json`](#description-of-specjson) contains the complete [list of valid](https://github.com/adraffy/ens-normalize.js/blob/main/tools/ensip/emoji.md) **Emoji Sequences**.
* [Derivation](#derivation) defines which emoji are normalizable.
* Not all Unicode emoji are valid.
* `‼ [203C] double exclamation mark` → *error: Disallowed character*
* `🈁 [1F201] Japanese “here” button` → `Text["ココ"]`
* An **Emoji Sequence** may contain characters that are disallowed:
* `👩❤️👨 [1F469 200D 2764 FE0F 200D 1F468] couple with heart: woman, man` — contains ZWJ
* `#️⃣ [23 FE0F 20E3] keycap: #` — contains `23 (#)`
* `🏴 [1F3F4 E0067 E0062 E0065 E006E E0067 E007F]` — contains `E00XX`
* An **Emoji Sequence** may contain other emoji:
* Example: `❤️ [2764 FE0F] red heart` is a substring of `❤️🔥 [2764 FE0F 200D 1F525] heart on fire`
* Single-codepoint emoji may have various [presentation styles](https://www.unicode.org/reports/tr51/#Presentation_Style) on input:
* Default: `❤ [2764]`
* Text: `❤︎ [2764 FE0E]`
* Emoji: `❤️ [2764 FE0F]`
* However, these all [tokenize](#tokenize) to the same **Emoji Sequence**.
* All **Emoji Sequence** have explicit emoji-presentation.
* The convention of ignoring presentation is difficult to change because:
* Presentation characters (`FE0F` and `FE0E`) are **Ignored**
* [ENSIP-1](/ensip/1) did not treat emoji differently from text
* Registration hashes are immutable
* [Beautification](#annex-beautification) can be used to restore emoji-presentation in normalized names.
#### Algorithm
* Normalization is the process of canonicalizing a name before for [hashing](/ensip/1#namehash-algorithm).
* It is idempotent: applying normalization multiple times produces the same result.
* For user convenience, leading and trailing whitespace should be trimmed before normalization, as all whitespace codepoints are disallowed. Inner characters should remain unmodified.
* No other string transformations (like case-folding) should be applied to the input.
1. [Split](#split) the name into [labels](/ensip/1#name-syntax).
2. [Normalize](#normalize) each label.
3. [Join](#join) the labels together into a name again.
#### Normalize
1. [Tokenize](#tokenize) — transform the label into `Text` and `Emoji` tokens.
* If there are no tokens, the label cannot be normalized.
2. Apply [NFC](https://unicode.org/reports/tr15/#Norm_Forms) to each `Text` token.
* Example: `Text["à"]` → `[61 300] → [E0]` → `Text["à"]`
3. Strip `FE0F` from each `Emoji` token.
4. [Validate](#validate) — check if the tokens are valid and obtain the **Label Type**.
* The **Label Type** and **Restricted** state may be presented to user for additional security.
5. Concatenate the tokens together.
* Return the normalized label.
Examples:
1. `"_$A" [5F 24 41]` → `"_$a" [5F 24 61]` — *ASCII*
2. `"E︎̃" [45 FE0E 303]` → `"ẽ" [1EBD]` — *Latin*
3. `"𓆏🐸" [1318F 1F438]` → `"𓆏🐸" [1318F 1F438]` — *Restricted: Egyp*
4. `"nı̇ck" [6E 131 307 63 6B]` → *error: Disallowed character*
#### Tokenize
Convert a label into a list of `Text` and `Emoji` tokens, each with a payload of codepoints. The complete list of character types and [emoji sequences](#appendix-additional-resources) can be found in [`spec.json`](#description-of-specjson).
1. Allocate an empty codepoint buffer.
2. Find the longest **Emoji Sequence** that matches the remaining input.
* Example: `👨🏻💻 [1F468 1F3FB 200D 1F4BB]`
* Match (1): `👨️ [1F468] man`
* Match (2): `👨🏻 [1F468 1F3FB] man: light skin tone`
* Match (4): `👨🏻💻 [1F468 1F3FB 200D 1F4BB] man technologist: light skin tone` — longest match!
* `FE0F` is optional from the input during matching.
* Example: `👨❤️👨 [1F468 200D 2764 FE0F 200D 1F468]`
* Match: `1F468 200D 2764 FE0F 200D 1F468` — fully-qualified
* Match: `1F468 200D 2764 200D 1F468` — missing `FE0F`
* No match: `1F468 FE0F 200D 2764 FE0F 200D 1F468` — extra `FE0F`
* No match: `1F468 200D 2764 FE0F FE0F 200D 1F468` — has (2) `FE0F`
* This is equivalent to `/^(emoji1|emoji2|...)/` where `\uFE0F` is replaced with `\uFE0F?` and `*` is replaced with `\x2A`.
3. If an **Emoji Sequence** is found:
* If the buffer is nonempty, emit a `Text` token, and clear the buffer.
* Emit an `Emoji` token with the fully-qualified matching sequence.
* Remove the matched sequence from the input.
4. Otherwise:
1. Remove the leading codepoint from the input.
2. Determine the character type:
* If **Valid**, append the codepoint to the buffer.
* This set can be precomputed from the union of characters in all groups and their NFD decompositions.
* If **Mapped**, append the corresponding mapped codepoint(s) to the buffer.
* If **Ignored**, do nothing.
* Otherwise, the label cannot be normalized.
5. Repeat until all the input is consumed.
6. If the buffer is nonempty, emit a final `Text` token with its contents.
* Return the list of emitted tokens.
Examples:
1. `"xyz👨🏻" [78 79 7A 1F468 1F3FB]` → `Text["xyz"]` + `Emoji["👨🏻"]`
2. `"A💩︎︎b" [41 FE0E 1F4A9 FE0E FE0E 62]` → `Text["a"]` + `Emoji["💩️"]` + `Text["b"]`
3. `"a™️" [61 2122 FE0F]` → `Text["atm"]`
#### Validate
Given a list of `Emoji` and `Text` tokens, determine if the label is valid and return the **Label Type**. If any assertion fails, the name cannot be normalized.
1. If only `Emoji` tokens:
* Return `"Emoji"`
2. If a single `Text` token and every characters is ASCII (`00..7F`):
* `5F (_) LOW LINE` can only occur at the start.
* Must match `/^_*[^_]*$/`
* Examples: `"___"` and `"__abc"` are valid, `"abc__"` and `"_abc_"` are invalid.
* The 3rd and 4th characters must not both be `2D (-) HYPHEN-MINUS`.
* Must not match `/^..--/`
* Examples: `"ab-c"` and `"---a"`are valid, `"xn--"` and `----` are invalid.
* Return `"ASCII"`
* The label is free of **Fenced** and **Combining Mark** characters, and not confusable.
3. Concatenate all the tokens together.
* `5F (_) LOW LINE` can only occur at the start.
* The first and last characters cannot be **Fenced**.
* Examples: `"a’s"` and `"a・a"` are valid, `"’85"` and `"joneses’"` and `"・a・"` are invalid.
* **Fenced** characters cannot be contiguous.
* Examples: `"a・a’s"` is valid, `"6’0’’"` and `"a・・a"` are invalid.
4. The first character of every `Text` token must not be a **Combining Mark**.
5. Concatenate the `Text` tokens together.
6. Find the first **Group** that contain every text character:
* If no group is found, the label cannot be normalized.
7. If the group is not **CM Whitelisted**:
* Apply NFD to the concatenated text characters.
* For every contiguous sequence of **NSM** characters:
* Each character must be unique.
* Example: `"x̀̀" [78 300 300]` has (2) grave accents.
* The number of **NSM** characters cannot exceed **Maximum NSM** (4).
* Example: ` "إؐؑؒؓؔ" [625 610 611 612 613 614]` has (6) **NSM**.
8. [Wholes](#wholes) — check if text characters form a confusable.
9. The label is valid.
* Return the name of the group as the **Label Type**.
Examples:
1. `Emoji["💩️"]` + `Emoji["💩️"]` → `"Emoji"`
2. `Text["abc$123"]` → `"ASCII"`
3. `Emoji["🚀️"]` + `Text["à"]` → `"Latin"`
#### Wholes
A label is [whole-script confusable](https://unicode.org/reports/tr39/#def_whole_script_confusables) if a similarly-looking valid label can be constructed using one alternative character from a different group. The complete list of **Whole Confusables** can be found in [`spec.json`](#description-of-specjson). Each **Whole Confusable** has a set of non-confusing characters (`"valid"`) and a set of confusing characters (`"confused"`) where each character may be the member of one or more groups.
Example: **Whole Confusable** for `"g"`
| Type | Code | Form | Character | Latn | Hani | Japn | Kore | Armn | Cher | Lisu |
| :------: | -----: | :--: | :----------------------- | :--: | :--: | :--: | :--: | :--: | :--: | :--: |
| valid | `67` | `g` | LATIN SMALL LETTER G | A | A | A | A | | | |
| confused | `581` | `ց` | ARMENIAN SMALL LETTER CO | | | | | B | | |
| confused | `13C0` | `Ꮐ` | CHEROKEE LETTER NAH | | | | | | C | |
| confused | `13F3` | `Ᏻ` | CHEROKEE LETTER YU | | | | | | C | |
| confused | 프로젝트로 돌아가기