@maskarajr/unrl 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1 @@
1
+ # Placeholder for the license - Will Fill up later
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # UNRL — Universal Naming Resolution Layer
2
+
3
+ > One call. Name → address. TLD picks the module.
4
+
5
+ **Status: `0.1.x` preview.** Thin TypeScript SDK — not a full identity/profile layer. Paste a name, get `{ address, resolver }`. Missing on-chain records → `address: null`. Unknown TLD / reverse miss → `resolver: null`.
6
+
7
+ ## Supported namespaces
8
+
9
+ | TLD | Module | Address family |
10
+ |-----|--------|----------------|
11
+ | `.eth` | ENS (viem, Ethereum L1) | EVM |
12
+ | `.sol` | SNS / Bonfida (proxy v2) | Solana |
13
+ | `.base` | Base Names as `*.base.eth` on L1 | EVM |
14
+ | `.crypto` `.wallet` `.nft` `.x` `.polygon` `.dao` `.888` `.blockchain` | Unstoppable (on-chain ProxyReader; optional API key) | EVM |
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @maskarajr/unrl
20
+ ```
21
+
22
+ Package is preview. Pin a version. Do not treat this as production identity infrastructure.
23
+
24
+ ## Quick start
25
+
26
+ ```typescript
27
+ import { UNRL } from "@maskarajr/unrl";
28
+
29
+ const unrl = new UNRL();
30
+
31
+ await unrl.resolve("vitalik.eth");
32
+ // { address: "0xd8dA…", resolver: "ens" }
33
+
34
+ await unrl.resolve("toly.sol"); // resolver: "sns"
35
+ await unrl.resolve("jesse.base"); // resolver: "basenames"
36
+ await unrl.resolve("brad.crypto"); // resolver: "unstoppable"
37
+ // await unrl.resolve("vitalik.eh") // type error: not a valid name
38
+
39
+ await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
40
+ // { name: "vitalik.eth", resolver: "ens" }
41
+ // extra hits: "foo.eth, foo.base.eth" / "ens, basenames"
42
+
43
+ await unrl.resolveMany(["vitalik.eth", "toly.sol"]);
44
+ unrl.whichResolver("toly.sol"); // "sns"
45
+ unrl.clearCache();
46
+ ```
47
+
48
+ ## Config
49
+
50
+ ```typescript
51
+ const unrl = new UNRL({
52
+ // EVM JSON-RPC. Default: viem public transport (not Cloudflare).
53
+ rpcUrl: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
54
+
55
+ // Optional SNS proxy `rpc` query param.
56
+ solanaRpcUrl: "https://api.mainnet-beta.solana.com",
57
+
58
+ // Optional Unstoppable REST key. Without it, Polygon then Ethereum ProxyReader.
59
+ udApiKey: "YOUR_UD_API_KEY",
60
+
61
+ // Cache entry cap (ms). Default 5 minutes. Misses with ttl 0 are not cached.
62
+ cacheTtl: 10 * 60 * 1000,
63
+
64
+ noCache: false,
65
+ });
66
+ ```
67
+
68
+ ## Scripts
69
+
70
+ ```bash
71
+ npm test # offline unit tests
72
+ npm run test:live # live names (RPC; flaky)
73
+ npm run build
74
+ ```
75
+
76
+ ## Why this stays small
77
+
78
+ Wallets and dApps should not integrate every naming SDK. UNRL is TLD routing only. No text records, avatars, IPFS, or L2 network picker — send UIs still choose Arbitrum vs Base when the address is EVM.
79
+
80
+ ## License
81
+
82
+ MIT
@@ -0,0 +1,82 @@
1
+ type SupportedTLD = "eth" | "sol" | "base" | "crypto" | "wallet" | "nft" | "x" | "polygon" | "dao" | "888" | "blockchain";
2
+ type ResolverName = "ens" | "sns" | "basenames" | "unstoppable";
3
+ /** Literal names UNRL accepts (last label is a supported TLD). `foo.base.eth` matches `.eth`. */
4
+ type SupportedName = `${string}.eth` | `${string}.sol` | `${string}.base` | `${string}.crypto` | `${string}.wallet` | `${string}.nft` | `${string}.x` | `${string}.polygon` | `${string}.dao` | `${string}.888` | `${string}.blockchain`;
5
+ /**
6
+ * Compile-time TLD check for string literals. Opaque `string` (user input) still allowed.
7
+ * Mistyped suffix becomes `Not a valid name: …` so `resolve("vitalik.eh")` fails typecheck.
8
+ */
9
+ type CheckName<T extends string> = string extends T ? T : T extends SupportedName ? T : `Not a valid name: ${T}`;
10
+ interface ResolvedName {
11
+ address: string | null;
12
+ resolver: ResolverName | null;
13
+ }
14
+ interface ReverseResolvedName {
15
+ name: string | null;
16
+ resolver: string | null;
17
+ }
18
+ interface ResolverConfig {
19
+ /** RPC URL for EVM chains */
20
+ rpcUrl?: string;
21
+ /** Solana RPC URL */
22
+ solanaRpcUrl?: string;
23
+ /** Unstoppable Domains API key (optional — falls back to on-chain) */
24
+ udApiKey?: string;
25
+ /** Cache TTL in ms. Default: 5 minutes */
26
+ cacheTtl?: number;
27
+ /** Disable cache entirely */
28
+ noCache?: boolean;
29
+ }
30
+
31
+ declare class UNRL {
32
+ private resolvers;
33
+ private cache;
34
+ private reverseCache;
35
+ private noCache;
36
+ private cacheTtl;
37
+ constructor(config?: ResolverConfig);
38
+ /**
39
+ * Resolve a human-readable name to a wallet address.
40
+ *
41
+ * @example
42
+ * const unrl = new UNRL();
43
+ * await unrl.resolve("vitalik.eth"); // → { address: "0xd8dA...", resolver: "ens" }
44
+ * await unrl.resolve("toly.sol"); // → { address: "7...", resolver: "sns" }
45
+ * await unrl.resolve("jesse.base"); // → { address: "0x...", resolver: "basenames" }
46
+ * await unrl.resolve("brad.crypto"); // → { address: "0x...", resolver: "unstoppable" }
47
+ */
48
+ resolve<T extends string>(name: CheckName<T>): Promise<ResolvedName>;
49
+ /**
50
+ * Reverse resolve a wallet address to human-readable names.
51
+ * Queries ENS, Base Names, and Unstoppable in parallel.
52
+ *
53
+ * @example
54
+ * await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
55
+ * // → { name: "vitalik.eth", resolver: "ens" }
56
+ * // several hits → "foo.eth, foo.base.eth", "ens, basenames"
57
+ */
58
+ reverseResolve(address: string): Promise<ReverseResolvedName>;
59
+ /**
60
+ * Resolve multiple names in parallel.
61
+ */
62
+ resolveMany<T extends string>(names: CheckName<T>[]): Promise<ResolvedName[]>;
63
+ /**
64
+ * Check which resolver will handle a given name.
65
+ */
66
+ whichResolver(name: string): ResolverName | null;
67
+ /** Clear the resolution cache. */
68
+ clearCache(): void;
69
+ }
70
+
71
+ type NameTypecheck = {
72
+ ok: true;
73
+ tld: SupportedTLD;
74
+ } | {
75
+ ok: false;
76
+ reason: "invalid";
77
+ message: "not a valid name";
78
+ };
79
+ /** Runtime check: empty, `.et`, mistyped TLD, bare suffix → not a valid name. */
80
+ declare function typecheckName(name: string): NameTypecheck;
81
+
82
+ export { type CheckName, type NameTypecheck, type ResolvedName, type ResolverConfig, type ResolverName, type ReverseResolvedName, type SupportedName, type SupportedTLD, UNRL, typecheckName };
@@ -0,0 +1,82 @@
1
+ type SupportedTLD = "eth" | "sol" | "base" | "crypto" | "wallet" | "nft" | "x" | "polygon" | "dao" | "888" | "blockchain";
2
+ type ResolverName = "ens" | "sns" | "basenames" | "unstoppable";
3
+ /** Literal names UNRL accepts (last label is a supported TLD). `foo.base.eth` matches `.eth`. */
4
+ type SupportedName = `${string}.eth` | `${string}.sol` | `${string}.base` | `${string}.crypto` | `${string}.wallet` | `${string}.nft` | `${string}.x` | `${string}.polygon` | `${string}.dao` | `${string}.888` | `${string}.blockchain`;
5
+ /**
6
+ * Compile-time TLD check for string literals. Opaque `string` (user input) still allowed.
7
+ * Mistyped suffix becomes `Not a valid name: …` so `resolve("vitalik.eh")` fails typecheck.
8
+ */
9
+ type CheckName<T extends string> = string extends T ? T : T extends SupportedName ? T : `Not a valid name: ${T}`;
10
+ interface ResolvedName {
11
+ address: string | null;
12
+ resolver: ResolverName | null;
13
+ }
14
+ interface ReverseResolvedName {
15
+ name: string | null;
16
+ resolver: string | null;
17
+ }
18
+ interface ResolverConfig {
19
+ /** RPC URL for EVM chains */
20
+ rpcUrl?: string;
21
+ /** Solana RPC URL */
22
+ solanaRpcUrl?: string;
23
+ /** Unstoppable Domains API key (optional — falls back to on-chain) */
24
+ udApiKey?: string;
25
+ /** Cache TTL in ms. Default: 5 minutes */
26
+ cacheTtl?: number;
27
+ /** Disable cache entirely */
28
+ noCache?: boolean;
29
+ }
30
+
31
+ declare class UNRL {
32
+ private resolvers;
33
+ private cache;
34
+ private reverseCache;
35
+ private noCache;
36
+ private cacheTtl;
37
+ constructor(config?: ResolverConfig);
38
+ /**
39
+ * Resolve a human-readable name to a wallet address.
40
+ *
41
+ * @example
42
+ * const unrl = new UNRL();
43
+ * await unrl.resolve("vitalik.eth"); // → { address: "0xd8dA...", resolver: "ens" }
44
+ * await unrl.resolve("toly.sol"); // → { address: "7...", resolver: "sns" }
45
+ * await unrl.resolve("jesse.base"); // → { address: "0x...", resolver: "basenames" }
46
+ * await unrl.resolve("brad.crypto"); // → { address: "0x...", resolver: "unstoppable" }
47
+ */
48
+ resolve<T extends string>(name: CheckName<T>): Promise<ResolvedName>;
49
+ /**
50
+ * Reverse resolve a wallet address to human-readable names.
51
+ * Queries ENS, Base Names, and Unstoppable in parallel.
52
+ *
53
+ * @example
54
+ * await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
55
+ * // → { name: "vitalik.eth", resolver: "ens" }
56
+ * // several hits → "foo.eth, foo.base.eth", "ens, basenames"
57
+ */
58
+ reverseResolve(address: string): Promise<ReverseResolvedName>;
59
+ /**
60
+ * Resolve multiple names in parallel.
61
+ */
62
+ resolveMany<T extends string>(names: CheckName<T>[]): Promise<ResolvedName[]>;
63
+ /**
64
+ * Check which resolver will handle a given name.
65
+ */
66
+ whichResolver(name: string): ResolverName | null;
67
+ /** Clear the resolution cache. */
68
+ clearCache(): void;
69
+ }
70
+
71
+ type NameTypecheck = {
72
+ ok: true;
73
+ tld: SupportedTLD;
74
+ } | {
75
+ ok: false;
76
+ reason: "invalid";
77
+ message: "not a valid name";
78
+ };
79
+ /** Runtime check: empty, `.et`, mistyped TLD, bare suffix → not a valid name. */
80
+ declare function typecheckName(name: string): NameTypecheck;
81
+
82
+ export { type CheckName, type NameTypecheck, type ResolvedName, type ResolverConfig, type ResolverName, type ReverseResolvedName, type SupportedName, type SupportedTLD, UNRL, typecheckName };