@maskarajr/unrl 0.1.0 → 0.1.2
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 +40 -11
- package/dist/index.mjs +40 -11
- 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,14 @@ 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
|
+
}
|
|
144
|
+
function snsResolveDomain(name) {
|
|
145
|
+
return name.replace(/\.sol$/i, ".sns");
|
|
146
|
+
}
|
|
139
147
|
var SNSResolver = class {
|
|
140
148
|
constructor(rpcUrl) {
|
|
141
149
|
this.name = "sns";
|
|
@@ -149,11 +157,13 @@ var SNSResolver = class {
|
|
|
149
157
|
}
|
|
150
158
|
async resolve(name) {
|
|
151
159
|
try {
|
|
152
|
-
const res = await fetch(
|
|
160
|
+
const res = await fetch(
|
|
161
|
+
this.endpoint(`resolve/${encodeURIComponent(snsResolveDomain(name))}`)
|
|
162
|
+
);
|
|
153
163
|
if (!res.ok) throw new Error("SNS resolve failed");
|
|
154
164
|
const data = await res.json();
|
|
155
165
|
if (data.s !== "ok") throw new Error("SNS resolve error");
|
|
156
|
-
const address = isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
166
|
+
const address = typeof data.result === "string" && isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
157
167
|
return {
|
|
158
168
|
name,
|
|
159
169
|
address,
|
|
@@ -167,12 +177,12 @@ var SNSResolver = class {
|
|
|
167
177
|
async reverseResolve(address) {
|
|
168
178
|
try {
|
|
169
179
|
const res = await fetch(
|
|
170
|
-
this.endpoint(`
|
|
180
|
+
this.endpoint(`primary-domain/${encodeURIComponent(address)}`)
|
|
171
181
|
);
|
|
172
182
|
if (!res.ok) throw new Error("SNS reverse lookup failed");
|
|
173
183
|
const data = await res.json();
|
|
174
184
|
if (data.s !== "ok") throw new Error("SNS reverse error");
|
|
175
|
-
const rawName =
|
|
185
|
+
const rawName = snsPrimaryLabel(data.result);
|
|
176
186
|
return {
|
|
177
187
|
address,
|
|
178
188
|
name: rawName ? rawName.endsWith(".sol") ? rawName : `${rawName}.sol` : null,
|
|
@@ -596,25 +606,44 @@ var UNRL = class {
|
|
|
596
606
|
return publicForward(result);
|
|
597
607
|
}
|
|
598
608
|
/**
|
|
599
|
-
* Reverse resolve a wallet address to human-readable
|
|
600
|
-
*
|
|
609
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
610
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
611
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
601
612
|
*
|
|
602
613
|
* @example
|
|
603
614
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
604
615
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
605
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
616
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
617
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
618
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
606
619
|
*/
|
|
607
620
|
async reverseResolve(address) {
|
|
621
|
+
const empty = {
|
|
622
|
+
name: null,
|
|
623
|
+
resolver: null
|
|
624
|
+
};
|
|
625
|
+
const solanaAddress = address.trim();
|
|
626
|
+
if (isSolanaAddress(solanaAddress)) {
|
|
627
|
+
const cacheKey2 = `rev:${solanaAddress}`;
|
|
628
|
+
if (!this.noCache) {
|
|
629
|
+
const cached = this.reverseCache.get(cacheKey2);
|
|
630
|
+
if (cached) return publicReverse(cached);
|
|
631
|
+
}
|
|
632
|
+
const sns = this.resolvers.get("sol");
|
|
633
|
+
if (!sns?.reverseResolve) return empty;
|
|
634
|
+
const hit = await sns.reverseResolve(solanaAddress);
|
|
635
|
+
if (!hit.name) return empty;
|
|
636
|
+
if (!this.noCache) {
|
|
637
|
+
this.reverseCache.set(cacheKey2, hit, this.cacheTtl);
|
|
638
|
+
}
|
|
639
|
+
return publicReverse(hit);
|
|
640
|
+
}
|
|
608
641
|
const normalized = address.toLowerCase().trim();
|
|
609
642
|
const cacheKey = `rev:${normalized}`;
|
|
610
643
|
if (!this.noCache) {
|
|
611
644
|
const cached = this.reverseCache.get(cacheKey);
|
|
612
645
|
if (cached) return publicReverse(cached);
|
|
613
646
|
}
|
|
614
|
-
const empty = {
|
|
615
|
-
name: null,
|
|
616
|
-
resolver: null
|
|
617
|
-
};
|
|
618
647
|
if (!/^0x[0-9a-fA-F]{40}$/.test(normalized)) {
|
|
619
648
|
return empty;
|
|
620
649
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -109,6 +109,14 @@ 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
|
+
}
|
|
117
|
+
function snsResolveDomain(name) {
|
|
118
|
+
return name.replace(/\.sol$/i, ".sns");
|
|
119
|
+
}
|
|
112
120
|
var SNSResolver = class {
|
|
113
121
|
constructor(rpcUrl) {
|
|
114
122
|
this.name = "sns";
|
|
@@ -122,11 +130,13 @@ var SNSResolver = class {
|
|
|
122
130
|
}
|
|
123
131
|
async resolve(name) {
|
|
124
132
|
try {
|
|
125
|
-
const res = await fetch(
|
|
133
|
+
const res = await fetch(
|
|
134
|
+
this.endpoint(`resolve/${encodeURIComponent(snsResolveDomain(name))}`)
|
|
135
|
+
);
|
|
126
136
|
if (!res.ok) throw new Error("SNS resolve failed");
|
|
127
137
|
const data = await res.json();
|
|
128
138
|
if (data.s !== "ok") throw new Error("SNS resolve error");
|
|
129
|
-
const address = isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
139
|
+
const address = typeof data.result === "string" && isSolanaAddress(data.result) ? data.result.trim() : null;
|
|
130
140
|
return {
|
|
131
141
|
name,
|
|
132
142
|
address,
|
|
@@ -140,12 +150,12 @@ var SNSResolver = class {
|
|
|
140
150
|
async reverseResolve(address) {
|
|
141
151
|
try {
|
|
142
152
|
const res = await fetch(
|
|
143
|
-
this.endpoint(`
|
|
153
|
+
this.endpoint(`primary-domain/${encodeURIComponent(address)}`)
|
|
144
154
|
);
|
|
145
155
|
if (!res.ok) throw new Error("SNS reverse lookup failed");
|
|
146
156
|
const data = await res.json();
|
|
147
157
|
if (data.s !== "ok") throw new Error("SNS reverse error");
|
|
148
|
-
const rawName =
|
|
158
|
+
const rawName = snsPrimaryLabel(data.result);
|
|
149
159
|
return {
|
|
150
160
|
address,
|
|
151
161
|
name: rawName ? rawName.endsWith(".sol") ? rawName : `${rawName}.sol` : null,
|
|
@@ -569,25 +579,44 @@ var UNRL = class {
|
|
|
569
579
|
return publicForward(result);
|
|
570
580
|
}
|
|
571
581
|
/**
|
|
572
|
-
* Reverse resolve a wallet address to human-readable
|
|
573
|
-
*
|
|
582
|
+
* Reverse resolve a wallet address to a human-readable name.
|
|
583
|
+
* 0x addresses query ENS, Base Names, and Unstoppable in parallel.
|
|
584
|
+
* Solana addresses query the SNS primary (.sol) domain.
|
|
574
585
|
*
|
|
575
586
|
* @example
|
|
576
587
|
* await unrl.reverseResolve("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
|
|
577
588
|
* // → { name: "vitalik.eth", resolver: "ens" }
|
|
578
|
-
* // several hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
589
|
+
* // several EVM hits → "foo.eth, foo.base.eth", "ens, basenames"
|
|
590
|
+
* await unrl.reverseResolve("Fw1ETanDZafof7xEULsnq9UY6o71Tpds89tNwPkWLb1v");
|
|
591
|
+
* // → { name: "couponvault.sol", resolver: "sns" }
|
|
579
592
|
*/
|
|
580
593
|
async reverseResolve(address) {
|
|
594
|
+
const empty = {
|
|
595
|
+
name: null,
|
|
596
|
+
resolver: null
|
|
597
|
+
};
|
|
598
|
+
const solanaAddress = address.trim();
|
|
599
|
+
if (isSolanaAddress(solanaAddress)) {
|
|
600
|
+
const cacheKey2 = `rev:${solanaAddress}`;
|
|
601
|
+
if (!this.noCache) {
|
|
602
|
+
const cached = this.reverseCache.get(cacheKey2);
|
|
603
|
+
if (cached) return publicReverse(cached);
|
|
604
|
+
}
|
|
605
|
+
const sns = this.resolvers.get("sol");
|
|
606
|
+
if (!sns?.reverseResolve) return empty;
|
|
607
|
+
const hit = await sns.reverseResolve(solanaAddress);
|
|
608
|
+
if (!hit.name) return empty;
|
|
609
|
+
if (!this.noCache) {
|
|
610
|
+
this.reverseCache.set(cacheKey2, hit, this.cacheTtl);
|
|
611
|
+
}
|
|
612
|
+
return publicReverse(hit);
|
|
613
|
+
}
|
|
581
614
|
const normalized = address.toLowerCase().trim();
|
|
582
615
|
const cacheKey = `rev:${normalized}`;
|
|
583
616
|
if (!this.noCache) {
|
|
584
617
|
const cached = this.reverseCache.get(cacheKey);
|
|
585
618
|
if (cached) return publicReverse(cached);
|
|
586
619
|
}
|
|
587
|
-
const empty = {
|
|
588
|
-
name: null,
|
|
589
|
-
resolver: null
|
|
590
|
-
};
|
|
591
620
|
if (!/^0x[0-9a-fA-F]{40}$/.test(normalized)) {
|
|
592
621
|
return empty;
|
|
593
622
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maskarajr/unrl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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
|