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

Integration of IDriss into Taho Wallet #3672

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions background/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"dexie": "^3.0.4",
"emittery": "^0.9.2",
"ethers": "5.7.2",
"idriss-crypto": "^1.8.10",
"immer": "^9.0.1",
"jsondiffpatch": "^0.4.1",
"lodash": "^4.17.21",
Expand Down
2 changes: 2 additions & 0 deletions background/services/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ensResolverFor,
unsResolver,
rnsResolver,
idrissResolver,
} from "./resolvers"
import PreferenceService from "../preferences"
import { isFulfilledPromise } from "../../lib/utils/type-guards"
Expand Down Expand Up @@ -123,6 +124,7 @@ export default class NameService extends BaseService<Events> {
ensResolverFor(chainService),
unsResolver(),
rnsResolver(),
idrissResolver(),
]

preferenceService.emitter.on(
Expand Down
61 changes: 61 additions & 0 deletions background/services/name/resolvers/idriss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { IdrissCrypto } from "idriss-crypto/lib/browser"
import { AddressOnNetwork, NameOnNetwork } from "../../../accounts"
import { ETHEREUM, MINUTE, POLYGON, BINANCE_SMART_CHAIN, ARBITRUM_ONE, OPTIMISM, ZK_SYNC } from "../../../constants"
import { isDefined } from "../../../lib/utils/type-guards"
import { sameNetwork } from "../../../networks"
import { NameResolver } from "../name-resolver"
import { normalizeEVMAddress } from "../../../lib/utils"


const IDRISS_SUPPORTED_NETWORKS = [ETHEREUM, POLYGON, BINANCE_SMART_CHAIN, ARBITRUM_ONE, OPTIMISM, ZK_SYNC]


export default function idrissResolver(): NameResolver<"idriss"> {
return {
type: "idriss",
canAttemptNameResolution(): boolean {
return true
},
canAttemptAvatarResolution(): boolean {
return false
},
canAttemptAddressResolution({ name, network }: NameOnNetwork): boolean {
return (
IdrissCrypto.matchInput(name) !== null &&
IDRISS_SUPPORTED_NETWORKS.some((supportedNetwork) =>
sameNetwork(network, supportedNetwork),
)
)
},

async lookUpAddressForName({
name,
network,
}: NameOnNetwork): Promise<AddressOnNetwork | undefined> {
const resolver = new IdrissCrypto()
const result = await resolver.resolve(name, { network: "evm" })
const address = result["Public ETH"] ?? Object.values(result)[0]
if (address) {
const normalizedAddress = normalizeEVMAddress(address)
return { address: normalizedAddress, network }
}
return undefined
},
async lookUpAvatar(
addressOrNameOnNetwork: AddressOnNetwork | NameOnNetwork,
) {
return undefined
},
async lookUpNameForAddress({
address,
network,
}: AddressOnNetwork): Promise<NameOnNetwork | undefined> {
const resolver = new IdrissCrypto()
const result = await resolver.reverseResolve(address)
if (result) {
return { name: result, network }
}
return undefined
},
}
}
3 changes: 3 additions & 0 deletions background/services/name/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import addressBookResolverFor from "./address-book"
import knownContractResolverFor from "./known-contracts"
import unsResolver from "./uns"
import rnsResolver from "./rns"
import idrissResolver from "./idriss"

const resolvers = {
ensResolverFor,
addressBookResolverFor,
knownContractResolverFor,
unsResolver,
rnsResolver,
idrissResolver,
}

type ResolverConstructors = ReturnType<
Expand All @@ -24,4 +26,5 @@ export {
knownContractResolverFor,
unsResolver,
rnsResolver,
idrissResolver,
}
Loading