Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@amplitude/analytics-browser": "^2.14.0",
"@bonfida/spl-name-service": "^3.0.10",
"@enkryptcom/extension-bridge": "workspace:^",
"@enkryptcom/hw-wallets": "workspace:^",
"@enkryptcom/keyring": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/libs/name-resolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class GenericNameResolver {
});
}

async resolveName(name: string, coins: CoinType[]): Promise<string | null> {
async resolveName(name: string, coins: CoinType[], providerChain?: string): Promise<string | null> {
let response: string | null = null;
for (const coin of coins) {
response = await this.nameResolver
.resolveAddress(name, coin)
.resolveAddress(name, coin, providerChain)
.catch(() => null);
if (response) return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,11 @@ const inputAddressFrom = (text: string) => {
const inputAddressTo = async (text: string) => {
const debounceResolve = debounce(() => {
nameResolver
.resolveName(text, [props.network.name as CoinType, 'ETH'])
.resolveName(
text,
[props.network.name as CoinType, 'ETH'],
props.network?.provider as string,
)
.then(resolved => {
if (resolved) {
addressTo.value = resolved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,11 @@ const inputAddressFrom = (text: string) => {
const inputAddressTo = async (text: string) => {
const debounceResolve = debounce(() => {
nameResolver
.resolveName(text, [props.network.name as CoinType, 'ETH'])
.resolveName(
text,
[props.network.name as CoinType, 'ETH'],
props.network?.provider as string,
)
.then(resolved => {
if (resolved) {
addressTo.value = resolved;
Expand Down
6 changes: 5 additions & 1 deletion packages/extension/src/ui/action/views/swap/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ const setMax = () => {
const inputAddress = (text: string) => {
const debounceResolve = debounce(() => {
nameResolver
.resolveName(text, [props.network.name as CoinType, 'ETH'])
.resolveName(
text,
[props.network.name as CoinType, 'ETH'],
props.network?.provider as string,
)
.then(resolved => {
if (resolved) {
inputAddress(resolved);
Expand Down
2 changes: 2 additions & 0 deletions packages/name-resolution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"dependencies": {
"@ensdomains/address-encoder": "^1.1.2",
"@siddomains/sidjs": "0.1.29",
"@solana/web3.js": "^1.98.0",
"@unstoppabledomains/resolution": "^9.3.3",
"@web3-name-sdk/core": "^0.4.1",
"ethers": "^5.8.0"
}
}
5 changes: 3 additions & 2 deletions packages/name-resolution/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ class NameResolver {

public async resolveAddress(
name: string,
coin: CoinType = "ETH"
coin: CoinType = "ETH",
paymentIdChain?: string
): Promise<string | null> {
return this.initDone.then(() => {
if (this.sid.isSupportedName(name)) return this.sid.resolveAddress(name);
if (this.sid.isSupportedName(name)) return this.sid.resolveAddress(name, coin, paymentIdChain);
if (this.rns.isSupportedName(name))
return this.rns.resolveAddress(name, coin);
if (this.ud.isSupportedName(name))
Expand Down
138 changes: 90 additions & 48 deletions packages/name-resolution/src/sid/index.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,114 @@
import { ethers } from "ethers";
import SID, { getSidAddress } from "@siddomains/sidjs";
import { BaseResolver } from "../types";
import { createWeb3Name } from "@web3-name-sdk/core";
import { BaseResolver, CoinType } from "../types";
import { PAYMENT_ID_CHAINS_MAP, PaymentIdChain, SIDOptions, TIMEOUT_PRESETS } from "./types";
import { createSolName } from "@web3-name-sdk/core/solName";
import { createPaymentIdName } from "@web3-name-sdk/core/paymentIdName";
import { isValidPaymentId } from "./utils";
import { getTLD } from "../utils";
import { SIDOptions } from "./types";
// demo: https://sdk-demo-git-main-space-id.vercel.app/
const evm_tlds = [
"bnb",
"arb",
"wod",
"mph",
"g",
"eth",
"btc",
"burger",
"alien",
"zkf",
"merlin",
"taiko",
"tomo",
"gno",
"floki",
"ll",
"ip",
"mode",
"mint",
"manta",
"cake",
"zeta",
"ail",
"duck",
];

class SIDResolver implements BaseResolver {
name: string;

supportedTLDs = ["bnb", "arb"];

timeout: number;
// The supported tlds for sid in evm and solana
supportedTLDs = ["sol", ...evm_tlds];
rpc: SIDOptions;
solanaNameResolver: ReturnType<typeof createSolName>;
paymentIdNameResolver: ReturnType<typeof createPaymentIdName>;
web3NameResolver: ReturnType<typeof createWeb3Name>;

constructor(options: SIDOptions) {
this.rpc = options;
this.timeout = options.timeout || TIMEOUT_PRESETS.normal;
this.name = "spaceid";
this.solanaNameResolver = createSolName({ timeout: this.timeout });
this.paymentIdNameResolver = createPaymentIdName();
this.web3NameResolver = createWeb3Name();
}

// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-empty-function
public async init(): Promise<void> {}

public async resolveReverseName(address: string): Promise<string | null> {
const bnbProvider = new ethers.providers.JsonRpcProvider({
url: this.rpc.node.bnb,
headers: {
"user-agent": "enkrypt/name-resolver",
},
});
const sidBNB = new SID({
provider: bnbProvider,
sidAddress: getSidAddress("56"),
// The PaymentId only supports getAddress resolution.
public async handlePaymentIdGetAddress(
name: string,
paymentIdChain?: string
): Promise<string | null> {
return await this.paymentIdNameResolver.getAddress({
name,
chainId: PAYMENT_ID_CHAINS_MAP[paymentIdChain?.toLowerCase()] || PaymentIdChain.Ethereum,
});
const nameBnb = await sidBNB.getName(address);
if (nameBnb) return nameBnb.name;
const arbProvider = new ethers.providers.JsonRpcProvider({
url: this.rpc.node.arb,
headers: {
"user-agent": "enkrypt/name-resolver",
},
});
const sidArb = new SID({
provider: arbProvider,
sidAddress: getSidAddress("42161"),
});
const nameArb = await sidArb.getName(address);
if (nameArb) return nameArb.name;
return null;
}

public async resolveAddress(name: string): Promise<string | null> {
const provider = new ethers.providers.JsonRpcProvider({
url: this.rpc.node[getTLD(name)],
headers: {
"user-agent": "enkrypt/name-resolver",
},
});
const sid = new SID({
provider,
sidAddress: getSidAddress(getTLD(name) === "bnb" ? "56" : "42161"),
});
const address = await sid.name(name).getAddress();
if (parseInt(address, 16) === 0) {
public async resolveReverseName(address: string): Promise<string | null> {
try {
let name = await this.web3NameResolver.getDomainName({
timeout: this.timeout,
address,
});
if (!name) {
name = await this.solanaNameResolver.getDomainName({
address,
});
}
return name;
} catch (error) {
return null;
}
return address;
}

public async resolveAddress(
name: string,
coint: CoinType,
paymentIdChain?: string,
): Promise<string | null> {
if (isValidPaymentId(name)) {
console.log("PaymentId name", name, coint);
return this.handlePaymentIdGetAddress(name, paymentIdChain);
}

const tld = getTLD(name);
switch (tld) {
case "sol":
const solAddress = await this.solanaNameResolver.getAddress({
name,
});
return solAddress;
default:
const address = await this.web3NameResolver.getAddress(name, {
timeout: this.timeout,
});
return parseInt(address, 16) === 0 ? null : address;
}
Comment on lines +103 to +107
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid parseInt for zero-address detection

parseInt('0x…', 16) can overflow Number.MAX_SAFE_INTEGER, and any non-numeric characters after the first invalid hex digit are silently ignored. A safer test is to compare against the canonical zero address:

-return parseInt(address, 16) === 0 ? null : address;
+return /^0x0{40}$/i.test(address) ? null : address;

If the SDK already returns null/undefined on failure, you can omit the check entirely.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const address = await this.web3NameResolver.getAddress(name, {
timeout: this.timeout,
});
return parseInt(address, 16) === 0 ? null : address;
}
const address = await this.web3NameResolver.getAddress(name, {
timeout: this.timeout,
});
return /^0x0{40}$/i.test(address) ? null : address;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 103-105: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

}
Comment on lines +96 to +108
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix lexical-declaration leak inside switch cases

Declaring const variables directly in a case clause without wrapping it in braces violates the ECMAScript spec and is flagged by Biome (noSwitchDeclarations).
Wrap each clause in its own block to contain the scope:

switch (tld) {
-  case "sol":
-    const solAddress = await this.solanaNameResolver.getAddress({
-      name,
-    });
-    return solAddress;
-  default:
-    const address = await this.web3NameResolver.getAddress(name, {
-      timeout: this.timeout,
-    });
-    return parseInt(address, 16) === 0 ? null : address;
+  case "sol": {
+    const solAddress = await this.solanaNameResolver.getAddress({ name });
+    return solAddress;
+  }
+  default: {
+    const address = await this.web3NameResolver.getAddress(name, {
+      timeout: this.timeout,
+    });
+    return parseInt(address, 16) === 0 ? null : address;
+  }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch (tld) {
case "sol":
const solAddress = await this.solanaNameResolver.getAddress({
name,
});
return solAddress;
default:
const address = await this.web3NameResolver.getAddress(name, {
timeout: this.timeout,
});
return parseInt(address, 16) === 0 ? null : address;
}
}
switch (tld) {
case "sol": {
const solAddress = await this.solanaNameResolver.getAddress({ name });
return solAddress;
}
default: {
const address = await this.web3NameResolver.getAddress(name, {
timeout: this.timeout,
});
return parseInt(address, 16) === 0 ? null : address;
}
}
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 98-100: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 103-105: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

public isSupportedName(name: string): boolean {
return this.supportedTLDs.includes(getTLD(name));
// Compatible with TLD and paymentId
return this.supportedTLDs.includes(getTLD(name)) || isValidPaymentId(name);
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/name-resolution/src/sid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,36 @@ export interface SIDOptions {
bnb: string;
arb: string;
};
timeout?: number
}

export type Protocol = "EVM" | "Solana" | "PaymentID";
export enum PaymentIdChain {
Bitcoin = 0,
Ethereum = 1,
Solana = 2,
Tron = 3,
Aptos = 4,
Sui = 5,
}
export const PAYMENT_ID_CHAINS_MAP = {
"bitcoin": 0,
"ethereum": 1,
"solana": 2,
"tron": 3,
"aptos": 4,
"sui": 5,
};
export type Method =
| "getAddress"
| "getDomainName"
| "batchGetDomainNameByChainId"
| "getMetadata"
| "getContentHash";


export const TIMEOUT_PRESETS = {
veryShort: 100, // Intentionally short to test timeout
normal: 5000, // Normal timeout (5s)
long: 15000, // Long timeout (15s)
};
3 changes: 3 additions & 0 deletions packages/name-resolution/src/sid/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const paymentIdRegex = /^[a-zA-Z0-9]+@[a-zA-Z0-9]+$/
export const isValidPaymentId = (id: string) => paymentIdRegex.test(id)

5 changes: 3 additions & 2 deletions packages/name-resolution/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENSOptions } from "./ens/types";
import { SIDOptions } from "./sid/types";
import { SIDOptions } from "./sid/types";

export type CoinType =
| "BTC"
Expand Down Expand Up @@ -146,7 +146,8 @@ export abstract class BaseResolver {

public abstract resolveAddress(
name: string,
coint: CoinType
coint: CoinType,
paymentIdChain?: string
): Promise<string | null>;

public abstract resolveReverseName(address: string): Promise<string | null>;
Expand Down
5 changes: 4 additions & 1 deletion packages/name-resolution/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"outDir": "dist",
"resolveJsonModule": true,
"esModuleInterop": true,
"declaration": true
"declaration": true,
"paths": {
"@web3-name-sdk/core/*": ["node_modules/@web3-name-sdk/core/dist/*"]
},
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"exclude": [
Expand Down
Loading