@maskarajr/unrl 0.1.0 → 0.1.1
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 +21 -0
- package/README.md +15 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +34 -10
- package/dist/index.mjs +34 -10
- package/package.json +9 -6
- package/LICENSE.md +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sameer Mukhtar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# UNRL — Universal Naming Resolution Layer
|
|
2
2
|
|
|
3
|
+
[](https://github.com/maskarajr/unrl/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@maskarajr/unrl)
|
|
5
|
+
|
|
3
6
|
> One call. Name → address. TLD picks the module.
|
|
4
7
|
|
|
5
8
|
**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
9
|
|
|
10
|
+
Install: [`@maskarajr/unrl`](https://www.npmjs.com/package/@maskarajr/unrl) (unscoped `unrl` is blocked on npm as too similar to existing names).
|
|
11
|
+
|
|
7
12
|
## Supported namespaces
|
|
8
13
|
|
|
9
14
|
| TLD | Module | Address family |
|
|
@@ -38,7 +43,10 @@ await unrl.resolve("brad.crypto"); // resolver: "unstoppable"
|
|
|
38
43
|
|
|
39
44
|
await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
40
45
|
// { name: "vitalik.eth", resolver: "ens" }
|
|
41
|
-
// extra hits: "foo.eth, foo.base.eth" / "ens, basenames"
|
|
46
|
+
// extra EVM hits: "foo.eth, foo.base.eth" / "ens, basenames"
|
|
47
|
+
|
|
48
|
+
await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
49
|
+
// { name: "couponvault.sol", resolver: "sns" }
|
|
42
50
|
|
|
43
51
|
await unrl.resolveMany(["vitalik.eth", "toly.sol"]);
|
|
44
52
|
unrl.whichResolver("toly.sol"); // "sns"
|
|
@@ -80,3 +88,9 @@ Wallets and dApps should not integrate every naming SDK. UNRL is TLD routing onl
|
|
|
80
88
|
## License
|
|
81
89
|
|
|
82
90
|
MIT
|
|
91
|
+
|
|
92
|
+
## More
|
|
93
|
+
|
|
94
|
+
- [example](examples/resolve-names.ts)
|
|
95
|
+
- [changelog](CHANGELOG.md) — per-version notes; GitHub Releases copy the same
|
|
96
|
+
- [contributing](CONTRIBUTING.md) — PRs from a feature branch into `main`
|
package/dist/index.d.mts
CHANGED
|
@@ -47,13 +47,16 @@ declare class UNRL {
|
|
|
47
47
|
*/
|
|
48
48
|
resolve<T extends string>(name: CheckName<T>): Promise<ResolvedName>;
|
|
49
49
|
/**
|
|
50
|
-
* Reverse resolve a wallet address to human-readable
|
|
51
|
-
*
|
|
50
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
51
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
52
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
52
53
|
*
|
|
53
54
|
* @example
|
|
54
55
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
55
56
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
56
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
57
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
58
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
59
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
57
60
|
*/
|
|
58
61
|
reverseResolve(address: string): Promise<ReverseResolvedName>;
|
|
59
62
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -47,13 +47,16 @@ declare class UNRL {
|
|
|
47
47
|
*/
|
|
48
48
|
resolve<T extends string>(name: CheckName<T>): Promise<ResolvedName>;
|
|
49
49
|
/**
|
|
50
|
-
* Reverse resolve a wallet address to human-readable
|
|
51
|
-
*
|
|
50
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
51
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
52
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
52
53
|
*
|
|
53
54
|
* @example
|
|
54
55
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
55
56
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
56
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
57
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
58
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
59
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
57
60
|
*/
|
|
58
61
|
reverseResolve(address: string): Promise<ReverseResolvedName>;
|
|
59
62
|
/**
|
package/dist/index.js
CHANGED
|
@@ -136,6 +136,11 @@ function isSolanaAddress(value) {
|
|
|
136
136
|
|
|
137
137
|
// src/resolvers/sns.ts
|
|
138
138
|
var SNS_API = "https://sdk-proxy-v2.sns.id";
|
|
139
|
+
function snsPrimaryLabel(result) {
|
|
140
|
+
if (typeof result === "string") return nonempty(result);
|
|
141
|
+
if (result && typeof result === "object") return nonempty(result.reverse);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
139
144
|
var SNSResolver = class {
|
|
140
145
|
constructor(rpcUrl) {
|
|
141
146
|
this.name = "sns";
|
|
@@ -153,7 +158,7 @@ var SNSResolver = class {
|
|
|
153
158
|
if (!res.ok) throw new Error("SNS resolve failed");
|
|
154
159
|
const data = await res.json();
|
|
155
160
|
if (data.s !== "ok") throw new Error("SNS resolve error");
|
|
156
|
-
const address = isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
161
|
+
const address = typeof data.result === "string" && isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
157
162
|
return {
|
|
158
163
|
name,
|
|
159
164
|
address,
|
|
@@ -167,12 +172,12 @@ var SNSResolver = class {
|
|
|
167
172
|
async reverseResolve(address) {
|
|
168
173
|
try {
|
|
169
174
|
const res = await fetch(
|
|
170
|
-
this.endpoint(`
|
|
175
|
+
this.endpoint(`primary-domain/${encodeURIComponent(address)}`)
|
|
171
176
|
);
|
|
172
177
|
if (!res.ok) throw new Error("SNS reverse lookup failed");
|
|
173
178
|
const data = await res.json();
|
|
174
179
|
if (data.s !== "ok") throw new Error("SNS reverse error");
|
|
175
|
-
const rawName =
|
|
180
|
+
const rawName = snsPrimaryLabel(data.result);
|
|
176
181
|
return {
|
|
177
182
|
address,
|
|
178
183
|
name: rawName ? rawName.endsWith(".sol") ? rawName : `${rawName}.sol` : null,
|
|
@@ -596,25 +601,44 @@ var UNRL = class {
|
|
|
596
601
|
return publicForward(result);
|
|
597
602
|
}
|
|
598
603
|
/**
|
|
599
|
-
* Reverse resolve a wallet address to human-readable
|
|
600
|
-
*
|
|
604
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
605
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
606
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
601
607
|
*
|
|
602
608
|
* @example
|
|
603
609
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
604
610
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
605
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
611
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
612
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
613
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
606
614
|
*/
|
|
607
615
|
async reverseResolve(address) {
|
|
616
|
+
const empty = {
|
|
617
|
+
name: null,
|
|
618
|
+
resolver: null
|
|
619
|
+
};
|
|
620
|
+
const solanaAddress = address.trim();
|
|
621
|
+
if (isSolanaAddress(solanaAddress)) {
|
|
622
|
+
const cacheKey2 = `rev:${solanaAddress}`;
|
|
623
|
+
if (!this.noCache) {
|
|
624
|
+
const cached = this.reverseCache.get(cacheKey2);
|
|
625
|
+
if (cached) return publicReverse(cached);
|
|
626
|
+
}
|
|
627
|
+
const sns = this.resolvers.get("sol");
|
|
628
|
+
if (!sns?.reverseResolve) return empty;
|
|
629
|
+
const hit = await sns.reverseResolve(solanaAddress);
|
|
630
|
+
if (!hit.name) return empty;
|
|
631
|
+
if (!this.noCache) {
|
|
632
|
+
this.reverseCache.set(cacheKey2, hit, this.cacheTtl);
|
|
633
|
+
}
|
|
634
|
+
return publicReverse(hit);
|
|
635
|
+
}
|
|
608
636
|
const normalized = address.toLowerCase().trim();
|
|
609
637
|
const cacheKey = `rev:${normalized}`;
|
|
610
638
|
if (!this.noCache) {
|
|
611
639
|
const cached = this.reverseCache.get(cacheKey);
|
|
612
640
|
if (cached) return publicReverse(cached);
|
|
613
641
|
}
|
|
614
|
-
const empty = {
|
|
615
|
-
name: null,
|
|
616
|
-
resolver: null
|
|
617
|
-
};
|
|
618
642
|
if (!/^0x[0-9a-fA-F]{40}$/.test(normalized)) {
|
|
619
643
|
return empty;
|
|
620
644
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -109,6 +109,11 @@ function isSolanaAddress(value) {
|
|
|
109
109
|
|
|
110
110
|
// src/resolvers/sns.ts
|
|
111
111
|
var SNS_API = "https://sdk-proxy-v2.sns.id";
|
|
112
|
+
function snsPrimaryLabel(result) {
|
|
113
|
+
if (typeof result === "string") return nonempty(result);
|
|
114
|
+
if (result && typeof result === "object") return nonempty(result.reverse);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
112
117
|
var SNSResolver = class {
|
|
113
118
|
constructor(rpcUrl) {
|
|
114
119
|
this.name = "sns";
|
|
@@ -126,7 +131,7 @@ var SNSResolver = class {
|
|
|
126
131
|
if (!res.ok) throw new Error("SNS resolve failed");
|
|
127
132
|
const data = await res.json();
|
|
128
133
|
if (data.s !== "ok") throw new Error("SNS resolve error");
|
|
129
|
-
const address = isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
134
|
+
const address = typeof data.result === "string" && isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
130
135
|
return {
|
|
131
136
|
name,
|
|
132
137
|
address,
|
|
@@ -140,12 +145,12 @@ var SNSResolver = class {
|
|
|
140
145
|
async reverseResolve(address) {
|
|
141
146
|
try {
|
|
142
147
|
const res = await fetch(
|
|
143
|
-
this.endpoint(`
|
|
148
|
+
this.endpoint(`primary-domain/${encodeURIComponent(address)}`)
|
|
144
149
|
);
|
|
145
150
|
if (!res.ok) throw new Error("SNS reverse lookup failed");
|
|
146
151
|
const data = await res.json();
|
|
147
152
|
if (data.s !== "ok") throw new Error("SNS reverse error");
|
|
148
|
-
const rawName =
|
|
153
|
+
const rawName = snsPrimaryLabel(data.result);
|
|
149
154
|
return {
|
|
150
155
|
address,
|
|
151
156
|
name: rawName ? rawName.endsWith(".sol") ? rawName : `${rawName}.sol` : null,
|
|
@@ -569,25 +574,44 @@ var UNRL = class {
|
|
|
569
574
|
return publicForward(result);
|
|
570
575
|
}
|
|
571
576
|
/**
|
|
572
|
-
* Reverse resolve a wallet address to human-readable
|
|
573
|
-
*
|
|
577
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
578
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
579
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
574
580
|
*
|
|
575
581
|
* @example
|
|
576
582
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
577
583
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
578
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
584
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
585
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
586
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
579
587
|
*/
|
|
580
588
|
async reverseResolve(address) {
|
|
589
|
+
const empty = {
|
|
590
|
+
name: null,
|
|
591
|
+
resolver: null
|
|
592
|
+
};
|
|
593
|
+
const solanaAddress = address.trim();
|
|
594
|
+
if (isSolanaAddress(solanaAddress)) {
|
|
595
|
+
const cacheKey2 = `rev:${solanaAddress}`;
|
|
596
|
+
if (!this.noCache) {
|
|
597
|
+
const cached = this.reverseCache.get(cacheKey2);
|
|
598
|
+
if (cached) return publicReverse(cached);
|
|
599
|
+
}
|
|
600
|
+
const sns = this.resolvers.get("sol");
|
|
601
|
+
if (!sns?.reverseResolve) return empty;
|
|
602
|
+
const hit = await sns.reverseResolve(solanaAddress);
|
|
603
|
+
if (!hit.name) return empty;
|
|
604
|
+
if (!this.noCache) {
|
|
605
|
+
this.reverseCache.set(cacheKey2, hit, this.cacheTtl);
|
|
606
|
+
}
|
|
607
|
+
return publicReverse(hit);
|
|
608
|
+
}
|
|
581
609
|
const normalized = address.toLowerCase().trim();
|
|
582
610
|
const cacheKey = `rev:${normalized}`;
|
|
583
611
|
if (!this.noCache) {
|
|
584
612
|
const cached = this.reverseCache.get(cacheKey);
|
|
585
613
|
if (cached) return publicReverse(cached);
|
|
586
614
|
}
|
|
587
|
-
const empty = {
|
|
588
|
-
name: null,
|
|
589
|
-
resolver: null
|
|
590
|
-
};
|
|
591
615
|
if (!/^0x[0-9a-fA-F]{40}$/.test(normalized)) {
|
|
592
616
|
return empty;
|
|
593
617
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maskarajr/unrl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Preview: TLD-routed name resolution for ENS, SNS, Base Names, and Unstoppable Domains",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "maskarajr",
|
|
@@ -34,17 +34,20 @@
|
|
|
34
34
|
"test": "vitest run",
|
|
35
35
|
"test:watch": "vitest",
|
|
36
36
|
"test:live": "vitest run --config vitest.live.config.mts",
|
|
37
|
-
"
|
|
37
|
+
"example": "npx tsx examples/resolve-names.ts",
|
|
38
38
|
"prepack": "npm run build"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"ens",
|
|
42
|
-
"
|
|
43
|
-
"basenames",
|
|
44
|
-
"unstoppable-domains",
|
|
42
|
+
"solana",
|
|
45
43
|
"web3",
|
|
44
|
+
"typescript",
|
|
46
45
|
"naming",
|
|
47
|
-
"
|
|
46
|
+
"blockchain",
|
|
47
|
+
"sdk",
|
|
48
|
+
"sns",
|
|
49
|
+
"basenames",
|
|
50
|
+
"unstoppable-domains"
|
|
48
51
|
],
|
|
49
52
|
"dependencies": {
|
|
50
53
|
"viem": "^2.21.0"
|
package/LICENSE.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Placeholder for the license - Will Fill up later
|