-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from fm2055/feat/sns-name-resolver
feat: added SNS name resolver
- Loading branch information
Showing
9 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { SupportedChains, SNS } from "@bonfida/sns-warp-evm"; | ||
import { BaseResolver, CoinType } from "../types"; | ||
import { getTLD } from "../utils"; | ||
import { ChainMap, Resolvers, SNSOptions } from "./types"; | ||
|
||
const MAINNET_CHAIN_MAP: ChainMap = { | ||
"BASE": SupportedChains.BASE, | ||
"BNB": SupportedChains.BNBMainnet | ||
} | ||
|
||
const TESTNET_CHAIN_MAP: ChainMap = { | ||
"BASE": SupportedChains.BASESepolia, | ||
"BNB": SupportedChains.BNBTestNet | ||
} | ||
|
||
class SNSResolver implements BaseResolver { | ||
options: SNSOptions; | ||
|
||
name: string; | ||
|
||
chainMap: ChainMap; | ||
|
||
chainResolvers: Resolvers; | ||
|
||
constructor(options: SNSOptions) { | ||
this.options = options; | ||
this.name = "sns"; | ||
this.chainMap = options.network === "testnet" | ||
? TESTNET_CHAIN_MAP | ||
: MAINNET_CHAIN_MAP; | ||
this.chainResolvers = Object.fromEntries( | ||
Object.entries(this.chainMap).map(([key, val]) => ( | ||
[key, new SNS(val)] | ||
)) | ||
); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-empty-function | ||
public async init(): Promise<void> { } | ||
|
||
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars | ||
public async resolveReverseName(_address: string): Promise<string | null> { | ||
return null | ||
} | ||
|
||
public async resolveAddress( | ||
name: string, | ||
coin: CoinType = "ETH" | ||
): Promise<string | null> { | ||
const resolver = this.chainResolvers[coin]; | ||
if (resolver) { | ||
return resolver.resolveName(name) | ||
.then((address) => address ?? null) | ||
.catch(() => null) | ||
} | ||
|
||
return null | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public isSupportedName(name: string): boolean { | ||
return getTLD(name) === "sol"; | ||
} | ||
} | ||
|
||
export default SNSResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SupportedChains, SNS } from "@bonfida/sns-warp-evm"; | ||
|
||
type SupportedNetwork = "BASE" | "BNB"; | ||
|
||
export interface SNSOptions { | ||
network: "testnet" | "mainnet"; | ||
} | ||
|
||
export type ChainMap = Record<SupportedNetwork, SupportedChains>; | ||
|
||
export type Resolvers = Record<string, SNS>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from "chai"; | ||
import SNSResolver from "../src/sns" | ||
|
||
describe("SNS Name resolving", () => { | ||
// the tests container | ||
it("it should properly resolve address", async () => { | ||
const resolver = new SNSResolver({ network: "testnet" }); | ||
await resolver.init(); | ||
const address = await resolver.resolveAddress("mock3.sol", "BNB"); | ||
expect(address).to.be.eq("0x1D719d2dB763f905b1924F46a5185e001Dd93786"); | ||
}).timeout(10000); | ||
|
||
it("it should return null if not found", async () => { | ||
const resolver = new SNSResolver({ network: "testnet" }); | ||
await resolver.init(); | ||
const name = await resolver.resolveReverseName( | ||
"0xe5dc07bdcdb8c98850050c7f67de7e164b1ea392" | ||
); | ||
expect(name).to.be.eq(null); | ||
const address = await resolver.resolveAddress( | ||
"sdfsfsdfsdfsdf.sol", | ||
"BASE" | ||
); | ||
expect(address).to.be.eq(null); | ||
}).timeout(10000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fc65990
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/516f7986197350193fbec633ed4e2c9b07cb330b8586a2b2192bd4d71d0223db
firefox:
https://www.virustotal.com/gui/file/1e26155be968a8eaa3594c60a48d06d55be8bf09f97671db28c5239e2a010983