Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SIP-12 with multiple resolutions & optimization #116

Merged
merged 11 commits into from
Feb 1, 2024
35 changes: 27 additions & 8 deletions SIPS/sip-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This SIP proposes a new endowment, `endowment:name-lookup`, that enables a way f

hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
## Motivation

Currently, the MetaMask wallet allows for ENS domain resolution. The implementation is hardcoded and limited to just the ENS protocol. In an effort to increasingly modularize the wallet and allow for resolution beyond ENS, we decided to open up domain/address resolution to snaps. A snap would be able to provide resolution based on a domain or address provided with a chain ID. The address resolution is in essence "reverse resolution". The functionality provided by this API is also beneficial as a base layer for a petname system (**see definition**). With plans to bring petnames to MetaMask, resolutions would be fed into the petname system and used as a means for cache invalidation.
Currently, the MetaMask wallet allows for ENS domain resolution. The implementation is hardcoded and limited to just the ENS protocol. In an effort to increasingly modularize the wallet and allow for resolution beyond ENS, we decided to open up domain/address resolution to snaps. A snap would be able to provide resolutions based on a domain or address provided with a chain ID. The address resolution is in essence "reverse resolution". The functionality provided by this API is also beneficial as a base layer for a petname system (**see definition**). With plans to bring petnames to MetaMask, resolutions would be fed into the petname system and used as a means for cache invalidation.
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved

## Specification

Expand Down Expand Up @@ -51,12 +51,18 @@ This permission is specified as follows in `snap.manifest.json` files:
"initialPermissions": {
"endowment:name-lookup": {
"chains": ["eip155:1", "bip122:000000000019d6689c085ae165831e93"],
"matchers": { "tlds": ["lens"], "schemes": ["farcaster"] }
}
}
}
```

`chains` - An array of CAIP-2 chain IDs that the snap supports. This field is useful for a client in order to avoid unnecessary overhead.
`chains` - An optional non-empty array of CAIP-2 chain IDs that the snap supports. This field is useful for a client in order to avoid unnecessary overhead.
`matchers` - An optional non-empty object that MUST contain 1 or both of the below properties. These matchers are useful for a client for validating input for domain resolution, also helpful in reducing overhead.
`tlds` - An optional non-empty array of top level domains that the snap will provide resolution for.
`schemes` - An optional non-empty array of prefixes that the snap expects for non-tld domain lookup.

**Note:** Tld domains are presumed to end with "." and one of the `tlds`. Non-tld domains are presumed to start with one of the `schemes` followed by ":" then the domain. Respectively, an example of each would be `hassan.lens` and `farcaster:hbm88`.
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved

### Snap Implementation

Expand All @@ -71,11 +77,11 @@ export const onNameLookup: OnNameLookupHandler = async ({
address
}) => {
if (domain) {
return { resolvedAddress: /* Get domain resolution */ }
return { resolvedAddresses: /* Get domain resolution */ }
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
}

if (address) {
return { resolvedDomain: /* Get address resolution */ };
return { resolvedDomains: /* Get address resolution */ };
}

return null;
Expand Down Expand Up @@ -107,16 +113,29 @@ the request is looking for resolution to a domain.
The interface for the return value of an `onNameLookup` export is:

```typescript
type AddressResolution = {
protocol: string;
resolvedAddress: AccountAddress;
};

type DomainResolution = {
protocol: string;
resolvedDomain: string;
};

type OnNameLookupResponse =
| {
resolvedAddress: AccountAddress;
resolvedDomain?: never;
resolvedAddresses: AddressResolution[];
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved
resolvedDomains?: never;
}
| { resolvedDomain: string; resolvedAddress?: never }
| { resolvedDomains: DomainResolution[]; resolvedAddresses?: never }
| null;
```

**Note:** `resolvedDomain` and `resolvedAddress` MUST be the keys that the resolved address/domain being queried is indexed by in the protocol that the snap is resolving for. These returned values are un-opinionated at the API layer to allow the client to use them as they see fit.
**Note:**
1. The `resolvedDomain` or `resolvedAddress` in a resolution object MUST be the key that the address or domain being queried is indexed by in the protocol that the snap is resolving for. These returned values are un-opinionated at the API layer to allow the client to use them as they see fit.
2. There MUST NOT be duplicate resolutions for the same protocol in either `resolvedAddresses` or `resolvedDomains`.
3. `protocol` refers to the name of the protocol providing resolution for said `resolvedAddress`/`resolvedDomain`.
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved

## Copyright

Expand Down
Loading