@xrpname/sdk 0.0.0-stage → 1.0.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/README.md +168 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +208 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.js +1 -0
- package/package.json +53 -4
package/README.md
CHANGED
|
@@ -1,3 +1,169 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xrpname/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official SDK for **XRPName** — the XRP Ledger Name Service (XNS). Resolve `.xrp`
|
|
4
|
+
names, check availability, list names, read order/pending state, and pull
|
|
5
|
+
explorer data.
|
|
6
|
+
|
|
7
|
+
- **Zero dependencies** — talks to the public `xrplnftv3` API over `fetch`.
|
|
8
|
+
- **Node 18+ and browsers** — one codebase.
|
|
9
|
+
- **Typed** — ships `.d.ts`.
|
|
10
|
+
|
|
11
|
+
> Supersedes the old `xrplidjs` package. The 1.x `SDK({ rpcUrl, Issuer })` call and
|
|
12
|
+
> the `getAddress` / `getName` / `getAllNames` methods still work (see Migration).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @xrpname/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createXRPName } from '@xrpname/sdk';
|
|
24
|
+
|
|
25
|
+
const xns = createXRPName();
|
|
26
|
+
|
|
27
|
+
// Resolution
|
|
28
|
+
await xns.resolve('xrpdomains.xrp'); // "rLhi87…" | null (name → owner)
|
|
29
|
+
await xns.reverse('rLhi87…'); // "hello.xrp" | null (address → primary name)
|
|
30
|
+
await xns.isOwner('rLhi87…'); // true | false
|
|
31
|
+
await xns.resolveFull('xrpdomains.xrp');// { owner, nftokenId, metadataUrl, metadata, raw } | null
|
|
32
|
+
|
|
33
|
+
// Availability
|
|
34
|
+
await xns.available('my-new-name'); // true | false (bare name → my-new-name.xrp)
|
|
35
|
+
await xns.checkMany(['a.xrp', 'b.xrp']);// [{ domain, owner, nftokenId, status, issuer }]
|
|
36
|
+
|
|
37
|
+
// Owned names (sorted + paginated)
|
|
38
|
+
await xns.names('rLhi87…', { page: 1, limit: 50, sort: 'newest', keyword: 'xr' });
|
|
39
|
+
// → { items, total, page, limit, totalPages, owner }
|
|
40
|
+
|
|
41
|
+
// Orders & assets
|
|
42
|
+
await xns.order('hello.xrp'); // order record | null (poll after registration)
|
|
43
|
+
await xns.pending('rLhi87…'); // { mint, incoming, outgoing }
|
|
44
|
+
await xns.nft('000800…'); // NFT detail | null
|
|
45
|
+
|
|
46
|
+
// Explorer / analytics
|
|
47
|
+
await xns.explorer.recent(12);
|
|
48
|
+
await xns.explorer.sales(12);
|
|
49
|
+
await xns.explorer.listings(600);
|
|
50
|
+
await xns.explorer.market();
|
|
51
|
+
await xns.explorer.pulse('30d');
|
|
52
|
+
await xns.explorer.minters('7d', 10);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
CommonJS: `const { createXRPName } = require('@xrpname/sdk');`
|
|
56
|
+
|
|
57
|
+
> `createXRPName()` is the recommended entry point (no `new`). The `XrplId` class —
|
|
58
|
+
> also exported as `XRPName` — is still available for `new XRPName()` and for typing;
|
|
59
|
+
> the legacy `SDK({ Issuer })` factory keeps working (see Migration).
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
createXRPName({
|
|
65
|
+
baseUrl: 'https://app.xrpdomains.xyz/api/xrplnftv3', // default (v3)
|
|
66
|
+
issuer: 'raAyaz…', // default mainnet issuer
|
|
67
|
+
defaultTld:'xrp', // bare name → name.xrp
|
|
68
|
+
timeoutMs: 10000,
|
|
69
|
+
retries: 2, // network / 5xx only, never 4xx
|
|
70
|
+
headers: {},
|
|
71
|
+
fetch, // inject for Node < 18 / tests
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Methods
|
|
76
|
+
|
|
77
|
+
| Method | Returns |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `resolve(name)` | `string \| null` — owner address |
|
|
80
|
+
| `resolveFull(name)` | `NameRecord \| null` |
|
|
81
|
+
| `reverse(address)` | `string \| null` — primary name |
|
|
82
|
+
| `isOwner(address)` | `boolean` |
|
|
83
|
+
| `names(address, { page, limit, sort, keyword })` | `NamesPage` |
|
|
84
|
+
| `available(name)` | `boolean` |
|
|
85
|
+
| `checkMany(names[])` | `DomainStatus[]` |
|
|
86
|
+
| `order(domain)` | order record `\| null` |
|
|
87
|
+
| `pending(owner)` | `{ mint, incoming, outgoing }` |
|
|
88
|
+
| `nft(nftokenId)` | record `\| null` |
|
|
89
|
+
| `addresses(name)` | `CoinAddress[]` — multicoin records |
|
|
90
|
+
| `addressOf(name, symbol)` | `string \| null` — e.g. BTC/ETH address |
|
|
91
|
+
| `avatar(name)` | `string \| null` — image URL |
|
|
92
|
+
| `record(name, key)` | `string \| null` — text/profile record |
|
|
93
|
+
| `reverseMany(addresses[])` | `[{ address, name }]` — batch reverse |
|
|
94
|
+
| `explorer.{recent,sales,listings,market,pulse,minters,holders,collections,categories}` | parsed data |
|
|
95
|
+
|
|
96
|
+
Helpers: `isValidAddress(value)`, `normalizeName(name, tld?)`.
|
|
97
|
+
Errors throw `XrplIdError` (`.code`: `bad_request` · `http_error` · `network` · `timeout` ·
|
|
98
|
+
`invalid_response`; `.httpStatus` for HTTP). Unregistered lookups return `null` / `[]`,
|
|
99
|
+
they don't throw.
|
|
100
|
+
|
|
101
|
+
## Underlying API (`xrplnftv3`)
|
|
102
|
+
|
|
103
|
+
All endpoints live under `baseUrl` and return `{ status, code, msg, data }`.
|
|
104
|
+
|
|
105
|
+
| Endpoint | Query | SDK method |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| `GET getAddress` | `domain` | `resolve`, `resolveFull` |
|
|
108
|
+
| `GET getName` | `address` | `reverse` |
|
|
109
|
+
| `GET isOwner` | `address` | `isOwner` |
|
|
110
|
+
| `GET getAllNames` | `address,page,limit,sort,keyword` | `names` |
|
|
111
|
+
| `GET checkDomains` | `domain` (CSV) | `available`, `checkMany` |
|
|
112
|
+
| `GET getOrderbyDomain` | `domain` | `order` |
|
|
113
|
+
| `GET getPendingDomains` | `owner` | `pending` |
|
|
114
|
+
| `GET getNftByTokenId` | `nftoken_id` | `nft` |
|
|
115
|
+
| `GET recent/sales/listings/market/pulse/minters/holders/collections/categories` | varies | `explorer.*` |
|
|
116
|
+
|
|
117
|
+
## Migration from `xrplidjs`
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const { SDK } = require('@xrpname/sdk');
|
|
121
|
+
const sdk = SDK({ Issuer: 'raAyaz…' }); // rpcUrl no longer needed (resolves via REST v3)
|
|
122
|
+
await sdk.getAddress('xrpdomains.xrp'); // still works → alias of resolve()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`getAddress` → `resolve`, `getName` → `reverse`, `getAllNames` → first-page domain strings.
|
|
126
|
+
|
|
127
|
+
## Develop
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm install
|
|
131
|
+
npm run build # dist/ (esm + cjs + d.ts) via tsup
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Publish to npm
|
|
135
|
+
|
|
136
|
+
Scoped public package; run from this `sdk/` folder on a machine whose
|
|
137
|
+
`node_modules` match its OS (the native bundlers are platform-specific).
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# 1. Auth (once). The @xrpname scope/org must exist under your npm account.
|
|
141
|
+
npm login
|
|
142
|
+
|
|
143
|
+
# 2. Clean build (prepublishOnly also runs `npm run build` automatically)
|
|
144
|
+
npm install
|
|
145
|
+
npm run build
|
|
146
|
+
|
|
147
|
+
# 3. Inspect the tarball before shipping — publishes nothing
|
|
148
|
+
npm pack --dry-run # lists files that go to npm (dist/ + README only)
|
|
149
|
+
npm publish --dry-run
|
|
150
|
+
|
|
151
|
+
# 4. Publish. --access public is required for a scoped package's first release
|
|
152
|
+
# (publishConfig.access is already "public", so plain `npm publish` works too).
|
|
153
|
+
npm publish --access public
|
|
154
|
+
# 2FA on? add: --otp=123456
|
|
155
|
+
|
|
156
|
+
# verify
|
|
157
|
+
npm view @xrpname/sdk
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Later releases:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm version patch # 1.0.0 -> 1.0.1 (minor | major for larger changes); tags the commit
|
|
164
|
+
npm publish
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Support
|
|
168
|
+
|
|
169
|
+
info@xrpdomains.xyz · https://xrpdomains.xyz
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var y=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var e in t)y(n,e,{get:t[e],enumerable:!0})},J=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _(t))!k.call(n,s)&&s!==e&&y(n,s,{get:()=>t[s],enumerable:!(r=x(t,s))||r.enumerable});return n};var T=n=>J(y({},"__esModule",{value:!0}),n);var I={};A(I,{DEFAULT_BASE_URL:()=>v,DEFAULT_ISSUER:()=>P,DEFAULT_TLD:()=>L,SDK:()=>S,XRPName:()=>D,XrplId:()=>c,XrplIdError:()=>o,XrplIdExplorer:()=>w,createXRPName:()=>N,default:()=>E,isValidAddress:()=>m,normalizeName:()=>h});module.exports=T(I);var v="https://app.xrpdomains.xyz/api/xrplnftv3",P="raAyazbgEkwzLByXipQuPLWFfnsPS1v1q9",L="xrp",o=class extends Error{constructor(t,e,r){super(t),this.name="XrplIdError",this.code=e,this.httpStatus=r}},R=/^r[1-9A-HJ-NP-Za-km-z]{24,34}$/;function m(n){return typeof n=="string"&&R.test(n)}function h(n,t="xrp"){if(typeof n!="string")throw new o("name must be a string","bad_request");let e=n.trim().toLowerCase();if(!e)throw new o("name must not be empty","bad_request");return e.includes(".")||(e=`${e}.${t.replace(/^\./,"")}`),e}var b=n=>new Promise(t=>setTimeout(t,n)),f=(n,t=0)=>typeof n=="number"&&isFinite(n)?n:t,w=class{constructor(t){this.client=t}recent(t=12){return this.client._explorer("recent",{limit:t})}sales(t=12){return this.client._explorer("sales",{limit:t})}listings(t=600){return this.client._explorer("listings",{limit:t})}market(){return this.client._explorer("market",{})}pulse(t="30d"){return this.client._explorer("pulse",{range:t})}minters(t="7d",e=10){return this.client._explorer("minters",{range:t,limit:e})}holders(t={}){return this.client._explorer("holders",t)}collections(){return this.client._explorer("collections",{})}categories(){return this.client._explorer("categories",{})}},c=class{constructor(t={}){this.baseUrl=(t.baseUrl??v).replace(/\/+$/,""),this.issuer=t.issuer??P,this.defaultTld=(t.defaultTld??"xrp").replace(/^\./,""),this.timeoutMs=t.timeoutMs??1e4,this.retries=Math.max(0,t.retries??2),this.headers={Accept:"application/json",...t.headers};let e=t.fetch??globalThis.fetch;if(typeof e!="function")throw new o("global fetch unavailable; pass config.fetch (Node < 18 needs a polyfill)","bad_request");this._fetch=e.bind(globalThis),this.explorer=new w(this)}async send(t,e){let r=new URL(`${this.baseUrl}/${t}`);for(let[a,d]of Object.entries(e.query??{}))r.searchParams.set(a,String(d));let{query:s,...i}=e,u;for(let a=0;a<=this.retries;a++){let d=new AbortController,p=setTimeout(()=>d.abort(),this.timeoutMs);try{let l=await this._fetch(r.toString(),{...i,headers:{...this.headers,...i.headers},signal:d.signal});if(!l.ok){if(l.status>=500&&a<this.retries){u=new o(`HTTP ${l.status}`,"http_error",l.status),await b(200*(a+1));continue}throw new o(`resolver returned HTTP ${l.status}`,"http_error",l.status)}let g;try{g=await l.json()}catch{throw new o("resolver returned invalid JSON","invalid_response",l.status)}if(!g||typeof g!="object")throw new o("unexpected resolver response","invalid_response",l.status);return g}catch(l){if(l instanceof o){if(l.code==="http_error"&&(l.httpStatus??0)>=500&&a<this.retries){u=l,await b(200*(a+1));continue}throw l}let g=l?.name==="AbortError";if(u=new o(g?`request timed out after ${this.timeoutMs}ms`:`network error: ${String(l)}`,g?"timeout":"network"),a<this.retries){await b(200*(a+1));continue}throw u}finally{clearTimeout(p)}}throw u??new o("request failed","network")}get(t,e={}){return this.send(t,{method:"GET",query:e})}async _explorer(t,e){let r=await this.get(t,e);return r.data??r}async resolve(t){return(await this.resolveFull(t))?.owner??null}async resolveFull(t){let e=h(t,this.defaultTld),r=await this.get("getAddress",{domain:e}),s=r.data??{},i=s.owner;return!r.status||!m(i)?null:{owner:i,nftokenId:typeof s.nftoken_id=="string"?s.nftoken_id:"",metadataUrl:typeof s.metadata_url=="string"?s.metadata_url:"",metadata:s.metadata&&typeof s.metadata=="object"?s.metadata:{},raw:s}}async reverse(t){if(!m(t))throw new o("invalid XRPL address","bad_request");let e=await this.get("getName",{address:t}),r=typeof e.data=="string"?e.data.trim():"";return e.status&&r?r.toLowerCase():null}async isOwner(t){if(!m(t))throw new o("invalid XRPL address","bad_request");let e=await this.get("isOwner",{address:t});return e.status===!0&&e.data===!0}async names(t,e={}){if(!m(t))throw new o("invalid XRPL address","bad_request");let r={address:t};e.page&&(r.page=e.page),e.limit&&(r.limit=e.limit),e.sort&&(r.sort=e.sort),e.keyword&&(r.keyword=e.keyword);let s=await this.get("getAllNames",r),i=Array.isArray(s.data)?s.data:[];return{items:i,total:f(s.total,i.length),page:f(s.page,e.page??1),limit:f(s.limit,e.limit??50),totalPages:f(s.total_pages,1),owner:typeof s.owner=="string"?s.owner:t}}async available(t){let[e]=await this.checkMany([t]);return e?.status==="available"}async checkMany(t){let e=t.map(i=>h(i,this.defaultTld));if(!e.length)return[];let r=await this.get("checkDomains",{domain:e.join(",")});return(Array.isArray(r.data)?r.data:[]).map(i=>({domain:String(i.domain??""),owner:typeof i.owner=="string"?i.owner:"",nftokenId:typeof i.nftoken_id=="string"?i.nftoken_id:"",status:i.status==="available"?"available":"registered",issuer:typeof i.issuer=="string"?i.issuer:this.issuer}))}async order(t){let e=await this.get("getOrderbyDomain",{domain:h(t,this.defaultTld)});return e.status&&e.data&&typeof e.data=="object"?e.data:null}async pending(t){if(!m(t))throw new o("invalid XRPL address","bad_request");let e=await this.get("getPendingDomains",{owner:t}),r=s=>Array.isArray(e[s])?e[s]:[];return{mint:r("mint"),incoming:r("incoming"),outgoing:r("outgoing")}}async nft(t){if(!t)throw new o("nftokenId required","bad_request");let e=await this.get("getNftByTokenId",{nftoken_id:t});return e.status&&e.data&&typeof e.data=="object"?e.data:null}async addresses(t){let e=await this.resolveFull(t);return(e&&Array.isArray(e.raw.addresses)?e.raw.addresses:[]).map(s=>({type:String(s.type??""),symbol:String(s.symbol??""),name:String(s.name??""),address:String(s.address??""),verified:s.verified===!0,visible:s.visible!==!1}))}async addressOf(t,e){let r=e.trim().toLowerCase();return(await this.addresses(t)).find(i=>i.symbol.toLowerCase()===r||i.type.toLowerCase()===r)?.address||null}async avatar(t){let e=await this.resolveFull(t);if(!e)return null;let r=e.metadata.image??e.raw.profile_image;return typeof r=="string"&&r?r:null}async record(t,e){let r=await this.resolveFull(t);if(!r)return null;let s=e.trim().toLowerCase(),i=[r.metadata,r.raw.profile_info,r.raw];for(let a of i)if(a&&typeof a=="object"){for(let[d,p]of Object.entries(a))if(d.toLowerCase()===s&&(typeof p=="string"||typeof p=="number"))return String(p)}let u=r.metadata.attributes??r.raw.attributes;if(Array.isArray(u)){for(let a of u)if(String(a.trait_type??a.key??a.name??"").toLowerCase()===s&&a.value!=null)return String(a.value)}return null}async reverseMany(t,e=5){let r=new Array(t.length),s=0,i=async()=>{for(;;){let u=s++;if(u>=t.length)break;let a=t[u],d=null;try{d=await this.reverse(a)}catch{d=null}r[u]={address:a,name:d}}};return await Promise.all(Array.from({length:Math.max(1,e)},i)),r}getAddress(t){return this.resolve(t)}getName(t){return this.reverse(t)}async getAllNames(t){return(await this.names(t,{limit:100})).items.map(r=>String(r.domain??"")).filter(Boolean)}};function S(n={}){let{Issuer:t,rpcUrl:e,...r}=n;return new c({...r,issuer:r.issuer??t})}function N(n={}){return new c(n)}var D=c,E=c;0&&(module.exports={DEFAULT_BASE_URL,DEFAULT_ISSUER,DEFAULT_TLD,SDK,XRPName,XrplId,XrplIdError,XrplIdExplorer,createXRPName,isValidAddress,normalizeName});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @xrpname/sdk — XRPL Name Service (XRPName / XNS) SDK.
|
|
3
|
+
*
|
|
4
|
+
* Resolve `.xrp` names on the XRP Ledger, check availability, list names,
|
|
5
|
+
* read order/pending state, and pull explorer data. Zero runtime dependencies;
|
|
6
|
+
* talks to the public `xrplnftv3` API over `fetch`, so it runs in Node 18+ and
|
|
7
|
+
* modern browsers.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createXRPName } from '@xrpname/sdk';
|
|
11
|
+
* const xns = createXRPName();
|
|
12
|
+
* await xns.resolve('xrpdomains.xrp'); // -> "raAyaz..." | null
|
|
13
|
+
* await xns.available('free-name.xrp'); // -> true | false
|
|
14
|
+
* await xns.reverse('raAyaz...'); // -> "hello.xrp" | null
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/** Public resolver API base (XRPName mainnet, v3 controller). */
|
|
18
|
+
declare const DEFAULT_BASE_URL = "https://app.xrpdomains.xyz/api/xrplnftv3";
|
|
19
|
+
/** Default XRPName issuer account on XRPL mainnet. */
|
|
20
|
+
declare const DEFAULT_ISSUER = "raAyazbgEkwzLByXipQuPLWFfnsPS1v1q9";
|
|
21
|
+
/** TLD appended to a bare name with no dot. */
|
|
22
|
+
declare const DEFAULT_TLD = "xrp";
|
|
23
|
+
/** Configuration for an {@link XrplId} client. All fields optional. */
|
|
24
|
+
interface XrplIdConfig {
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
issuer?: string;
|
|
27
|
+
defaultTld?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
retries?: number;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
fetch?: typeof fetch;
|
|
32
|
+
}
|
|
33
|
+
/** Standard v3 response envelope. Some endpoints add sibling fields next to `data`. */
|
|
34
|
+
interface Envelope<T = unknown> {
|
|
35
|
+
status: boolean;
|
|
36
|
+
code?: number;
|
|
37
|
+
msg?: string;
|
|
38
|
+
message?: string;
|
|
39
|
+
data: T;
|
|
40
|
+
[extra: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
type Json = Record<string, unknown>;
|
|
43
|
+
/** Full record for a resolved name. */
|
|
44
|
+
interface NameRecord {
|
|
45
|
+
owner: string;
|
|
46
|
+
nftokenId: string;
|
|
47
|
+
metadataUrl: string;
|
|
48
|
+
metadata: Json;
|
|
49
|
+
raw: Json;
|
|
50
|
+
}
|
|
51
|
+
/** One entry from {@link XrplId.checkMany} / availability checks. */
|
|
52
|
+
interface DomainStatus {
|
|
53
|
+
domain: string;
|
|
54
|
+
owner: string;
|
|
55
|
+
nftokenId: string;
|
|
56
|
+
status: 'available' | 'registered';
|
|
57
|
+
issuer: string;
|
|
58
|
+
}
|
|
59
|
+
/** A coin address recorded on a name (multicoin record). */
|
|
60
|
+
interface CoinAddress {
|
|
61
|
+
type: string;
|
|
62
|
+
symbol: string;
|
|
63
|
+
name: string;
|
|
64
|
+
address: string;
|
|
65
|
+
verified: boolean;
|
|
66
|
+
visible: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link XrplId.names}. */
|
|
69
|
+
interface NamesQuery {
|
|
70
|
+
page?: number;
|
|
71
|
+
limit?: number;
|
|
72
|
+
sort?: string;
|
|
73
|
+
keyword?: string;
|
|
74
|
+
}
|
|
75
|
+
/** A page of owned names. */
|
|
76
|
+
interface NamesPage {
|
|
77
|
+
items: Json[];
|
|
78
|
+
total: number;
|
|
79
|
+
page: number;
|
|
80
|
+
limit: number;
|
|
81
|
+
totalPages: number;
|
|
82
|
+
owner: string;
|
|
83
|
+
}
|
|
84
|
+
/** Pending order buckets for an owner. */
|
|
85
|
+
interface PendingDomains {
|
|
86
|
+
mint: Json[];
|
|
87
|
+
incoming: Json[];
|
|
88
|
+
outgoing: Json[];
|
|
89
|
+
}
|
|
90
|
+
/** Error for HTTP, network, validation, or resolver-level failures. */
|
|
91
|
+
declare class XrplIdError extends Error {
|
|
92
|
+
readonly code: string;
|
|
93
|
+
readonly httpStatus?: number;
|
|
94
|
+
constructor(message: string, code: string, httpStatus?: number);
|
|
95
|
+
}
|
|
96
|
+
/** True if `value` is a syntactically valid XRPL classic address. */
|
|
97
|
+
declare function isValidAddress(value: unknown): value is string;
|
|
98
|
+
/** Trim, lowercase, and append the default TLD when the name has no dot. */
|
|
99
|
+
declare function normalizeName(name: string, defaultTld?: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Explorer / analytics endpoints (read-only, beta). Shapes follow the public
|
|
102
|
+
* API and may evolve; methods return the parsed `data`.
|
|
103
|
+
*/
|
|
104
|
+
declare class XrplIdExplorer {
|
|
105
|
+
private readonly client;
|
|
106
|
+
constructor(client: XrplId);
|
|
107
|
+
recent(limit?: number): Promise<Json[]>;
|
|
108
|
+
sales(limit?: number): Promise<Json[]>;
|
|
109
|
+
listings(limit?: number): Promise<Json[]>;
|
|
110
|
+
market(): Promise<Json>;
|
|
111
|
+
pulse(range?: string): Promise<Json>;
|
|
112
|
+
minters(range?: string, limit?: number): Promise<Json[]>;
|
|
113
|
+
holders(opts?: {
|
|
114
|
+
issuer?: string;
|
|
115
|
+
taxon?: number;
|
|
116
|
+
slug?: string;
|
|
117
|
+
limit?: number;
|
|
118
|
+
offset?: number;
|
|
119
|
+
sampleLimit?: number;
|
|
120
|
+
}): Promise<Json>;
|
|
121
|
+
collections(): Promise<Json[]>;
|
|
122
|
+
categories(): Promise<Json[]>;
|
|
123
|
+
}
|
|
124
|
+
/** XRPL Name Service client. Create one and reuse it. */
|
|
125
|
+
declare class XrplId {
|
|
126
|
+
readonly baseUrl: string;
|
|
127
|
+
readonly issuer: string;
|
|
128
|
+
readonly defaultTld: string;
|
|
129
|
+
readonly explorer: XrplIdExplorer;
|
|
130
|
+
private readonly timeoutMs;
|
|
131
|
+
private readonly retries;
|
|
132
|
+
private readonly headers;
|
|
133
|
+
private readonly _fetch;
|
|
134
|
+
constructor(config?: XrplIdConfig);
|
|
135
|
+
private send;
|
|
136
|
+
private get;
|
|
137
|
+
/** @internal */
|
|
138
|
+
_explorer<T = Json>(path: string, query: Record<string, string | number>): Promise<T>;
|
|
139
|
+
/** Resolve a name to its owner's address (`null` if unregistered). */
|
|
140
|
+
resolve(name: string): Promise<string | null>;
|
|
141
|
+
/** Resolve a name to its full record (`null` if unregistered). */
|
|
142
|
+
resolveFull(name: string): Promise<NameRecord | null>;
|
|
143
|
+
/** Reverse-resolve an address to its primary name (`null` if none). */
|
|
144
|
+
reverse(address: string): Promise<string | null>;
|
|
145
|
+
/** True if the address owns at least one XRPName. */
|
|
146
|
+
isOwner(address: string): Promise<boolean>;
|
|
147
|
+
/** A page of names owned by an address, with sort/filter/pagination. */
|
|
148
|
+
names(address: string, query?: NamesQuery): Promise<NamesPage>;
|
|
149
|
+
/** True if a name is available to register. */
|
|
150
|
+
available(name: string): Promise<boolean>;
|
|
151
|
+
/** Batch availability / status check for one or more names. */
|
|
152
|
+
checkMany(names: string[]): Promise<DomainStatus[]>;
|
|
153
|
+
/** Order record for a domain (`null` if none). Useful for polling after registration. */
|
|
154
|
+
order(domain: string): Promise<Json | null>;
|
|
155
|
+
/** Pending order buckets (mint / incoming / outgoing) for an owner. */
|
|
156
|
+
pending(owner: string): Promise<PendingDomains>;
|
|
157
|
+
/** NFT detail by token id (`null` if not found). */
|
|
158
|
+
nft(nftokenId: string): Promise<Json | null>;
|
|
159
|
+
/** All coin addresses recorded for a name (multicoin records). */
|
|
160
|
+
addresses(name: string): Promise<CoinAddress[]>;
|
|
161
|
+
/** The address a name points to for a coin symbol/type (e.g. "XRP", "BTC"). `null` if unset. */
|
|
162
|
+
addressOf(name: string, symbol: string): Promise<string | null>;
|
|
163
|
+
/** Avatar / image URL for a name (`null` if none). */
|
|
164
|
+
avatar(name: string): Promise<string | null>;
|
|
165
|
+
/** A text/profile record for a name by key (searches metadata, profile, attributes). `null` if unset. */
|
|
166
|
+
record(name: string, key: string): Promise<string | null>;
|
|
167
|
+
/** Reverse-resolve many addresses (client-side batch, bounded concurrency). Preserves input order. */
|
|
168
|
+
reverseMany(addresses: string[], concurrency?: number): Promise<Array<{
|
|
169
|
+
address: string;
|
|
170
|
+
name: string | null;
|
|
171
|
+
}>>;
|
|
172
|
+
/** @deprecated Use {@link resolve}. */
|
|
173
|
+
getAddress(domain: string): Promise<string | null>;
|
|
174
|
+
/** @deprecated Use {@link reverse}. */
|
|
175
|
+
getName(address: string): Promise<string | null>;
|
|
176
|
+
/** @deprecated Use {@link names}. Returns the domain strings of the first page. */
|
|
177
|
+
getAllNames(address: string): Promise<string[]>;
|
|
178
|
+
}
|
|
179
|
+
/** Backward-compatible factory matching the old `xrplidjs.SDK(config)` call. */
|
|
180
|
+
declare function SDK(config?: XrplIdConfig & {
|
|
181
|
+
rpcUrl?: string;
|
|
182
|
+
Issuer?: string;
|
|
183
|
+
}): XrplId;
|
|
184
|
+
/**
|
|
185
|
+
* Create an XRPName client — the recommended entry point.
|
|
186
|
+
*
|
|
187
|
+
* Mirrors the ergonomics of other web3-name SDKs (no `new`, just call it):
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { createXRPName } from '@xrpname/sdk';
|
|
191
|
+
*
|
|
192
|
+
* const xns = createXRPName();
|
|
193
|
+
* await xns.resolve('xrpdomains.xrp'); // -> "raAyaz..." | null
|
|
194
|
+
* await xns.available('free-name.xrp'); // -> true | false
|
|
195
|
+
* await xns.reverse('raAyaz...'); // -> "hello.xrp" | null
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* Pass a config to point at a different network or tune transport:
|
|
199
|
+
* `createXRPName({ baseUrl, issuer, timeoutMs, retries, fetch })`.
|
|
200
|
+
*/
|
|
201
|
+
declare function createXRPName(config?: XrplIdConfig): XrplId;
|
|
202
|
+
/** Config alias so callers of {@link createXRPName} can import a matching name. */
|
|
203
|
+
type XRPNameConfig = XrplIdConfig;
|
|
204
|
+
/** Friendly alias for {@link XrplId}: `new XRPName()` reads better than `new XrplId()`. */
|
|
205
|
+
declare const XRPName: typeof XrplId;
|
|
206
|
+
type XRPName = XrplId;
|
|
207
|
+
|
|
208
|
+
export { type CoinAddress, DEFAULT_BASE_URL, DEFAULT_ISSUER, DEFAULT_TLD, type DomainStatus, type Envelope, type NameRecord, type NamesPage, type NamesQuery, type PendingDomains, SDK, XRPName, type XRPNameConfig, XrplId, type XrplIdConfig, XrplIdError, XrplIdExplorer, createXRPName, XrplId as default, isValidAddress, normalizeName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @xrpname/sdk — XRPL Name Service (XRPName / XNS) SDK.
|
|
3
|
+
*
|
|
4
|
+
* Resolve `.xrp` names on the XRP Ledger, check availability, list names,
|
|
5
|
+
* read order/pending state, and pull explorer data. Zero runtime dependencies;
|
|
6
|
+
* talks to the public `xrplnftv3` API over `fetch`, so it runs in Node 18+ and
|
|
7
|
+
* modern browsers.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createXRPName } from '@xrpname/sdk';
|
|
11
|
+
* const xns = createXRPName();
|
|
12
|
+
* await xns.resolve('xrpdomains.xrp'); // -> "raAyaz..." | null
|
|
13
|
+
* await xns.available('free-name.xrp'); // -> true | false
|
|
14
|
+
* await xns.reverse('raAyaz...'); // -> "hello.xrp" | null
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/** Public resolver API base (XRPName mainnet, v3 controller). */
|
|
18
|
+
declare const DEFAULT_BASE_URL = "https://app.xrpdomains.xyz/api/xrplnftv3";
|
|
19
|
+
/** Default XRPName issuer account on XRPL mainnet. */
|
|
20
|
+
declare const DEFAULT_ISSUER = "raAyazbgEkwzLByXipQuPLWFfnsPS1v1q9";
|
|
21
|
+
/** TLD appended to a bare name with no dot. */
|
|
22
|
+
declare const DEFAULT_TLD = "xrp";
|
|
23
|
+
/** Configuration for an {@link XrplId} client. All fields optional. */
|
|
24
|
+
interface XrplIdConfig {
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
issuer?: string;
|
|
27
|
+
defaultTld?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
retries?: number;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
fetch?: typeof fetch;
|
|
32
|
+
}
|
|
33
|
+
/** Standard v3 response envelope. Some endpoints add sibling fields next to `data`. */
|
|
34
|
+
interface Envelope<T = unknown> {
|
|
35
|
+
status: boolean;
|
|
36
|
+
code?: number;
|
|
37
|
+
msg?: string;
|
|
38
|
+
message?: string;
|
|
39
|
+
data: T;
|
|
40
|
+
[extra: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
type Json = Record<string, unknown>;
|
|
43
|
+
/** Full record for a resolved name. */
|
|
44
|
+
interface NameRecord {
|
|
45
|
+
owner: string;
|
|
46
|
+
nftokenId: string;
|
|
47
|
+
metadataUrl: string;
|
|
48
|
+
metadata: Json;
|
|
49
|
+
raw: Json;
|
|
50
|
+
}
|
|
51
|
+
/** One entry from {@link XrplId.checkMany} / availability checks. */
|
|
52
|
+
interface DomainStatus {
|
|
53
|
+
domain: string;
|
|
54
|
+
owner: string;
|
|
55
|
+
nftokenId: string;
|
|
56
|
+
status: 'available' | 'registered';
|
|
57
|
+
issuer: string;
|
|
58
|
+
}
|
|
59
|
+
/** A coin address recorded on a name (multicoin record). */
|
|
60
|
+
interface CoinAddress {
|
|
61
|
+
type: string;
|
|
62
|
+
symbol: string;
|
|
63
|
+
name: string;
|
|
64
|
+
address: string;
|
|
65
|
+
verified: boolean;
|
|
66
|
+
visible: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link XrplId.names}. */
|
|
69
|
+
interface NamesQuery {
|
|
70
|
+
page?: number;
|
|
71
|
+
limit?: number;
|
|
72
|
+
sort?: string;
|
|
73
|
+
keyword?: string;
|
|
74
|
+
}
|
|
75
|
+
/** A page of owned names. */
|
|
76
|
+
interface NamesPage {
|
|
77
|
+
items: Json[];
|
|
78
|
+
total: number;
|
|
79
|
+
page: number;
|
|
80
|
+
limit: number;
|
|
81
|
+
totalPages: number;
|
|
82
|
+
owner: string;
|
|
83
|
+
}
|
|
84
|
+
/** Pending order buckets for an owner. */
|
|
85
|
+
interface PendingDomains {
|
|
86
|
+
mint: Json[];
|
|
87
|
+
incoming: Json[];
|
|
88
|
+
outgoing: Json[];
|
|
89
|
+
}
|
|
90
|
+
/** Error for HTTP, network, validation, or resolver-level failures. */
|
|
91
|
+
declare class XrplIdError extends Error {
|
|
92
|
+
readonly code: string;
|
|
93
|
+
readonly httpStatus?: number;
|
|
94
|
+
constructor(message: string, code: string, httpStatus?: number);
|
|
95
|
+
}
|
|
96
|
+
/** True if `value` is a syntactically valid XRPL classic address. */
|
|
97
|
+
declare function isValidAddress(value: unknown): value is string;
|
|
98
|
+
/** Trim, lowercase, and append the default TLD when the name has no dot. */
|
|
99
|
+
declare function normalizeName(name: string, defaultTld?: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Explorer / analytics endpoints (read-only, beta). Shapes follow the public
|
|
102
|
+
* API and may evolve; methods return the parsed `data`.
|
|
103
|
+
*/
|
|
104
|
+
declare class XrplIdExplorer {
|
|
105
|
+
private readonly client;
|
|
106
|
+
constructor(client: XrplId);
|
|
107
|
+
recent(limit?: number): Promise<Json[]>;
|
|
108
|
+
sales(limit?: number): Promise<Json[]>;
|
|
109
|
+
listings(limit?: number): Promise<Json[]>;
|
|
110
|
+
market(): Promise<Json>;
|
|
111
|
+
pulse(range?: string): Promise<Json>;
|
|
112
|
+
minters(range?: string, limit?: number): Promise<Json[]>;
|
|
113
|
+
holders(opts?: {
|
|
114
|
+
issuer?: string;
|
|
115
|
+
taxon?: number;
|
|
116
|
+
slug?: string;
|
|
117
|
+
limit?: number;
|
|
118
|
+
offset?: number;
|
|
119
|
+
sampleLimit?: number;
|
|
120
|
+
}): Promise<Json>;
|
|
121
|
+
collections(): Promise<Json[]>;
|
|
122
|
+
categories(): Promise<Json[]>;
|
|
123
|
+
}
|
|
124
|
+
/** XRPL Name Service client. Create one and reuse it. */
|
|
125
|
+
declare class XrplId {
|
|
126
|
+
readonly baseUrl: string;
|
|
127
|
+
readonly issuer: string;
|
|
128
|
+
readonly defaultTld: string;
|
|
129
|
+
readonly explorer: XrplIdExplorer;
|
|
130
|
+
private readonly timeoutMs;
|
|
131
|
+
private readonly retries;
|
|
132
|
+
private readonly headers;
|
|
133
|
+
private readonly _fetch;
|
|
134
|
+
constructor(config?: XrplIdConfig);
|
|
135
|
+
private send;
|
|
136
|
+
private get;
|
|
137
|
+
/** @internal */
|
|
138
|
+
_explorer<T = Json>(path: string, query: Record<string, string | number>): Promise<T>;
|
|
139
|
+
/** Resolve a name to its owner's address (`null` if unregistered). */
|
|
140
|
+
resolve(name: string): Promise<string | null>;
|
|
141
|
+
/** Resolve a name to its full record (`null` if unregistered). */
|
|
142
|
+
resolveFull(name: string): Promise<NameRecord | null>;
|
|
143
|
+
/** Reverse-resolve an address to its primary name (`null` if none). */
|
|
144
|
+
reverse(address: string): Promise<string | null>;
|
|
145
|
+
/** True if the address owns at least one XRPName. */
|
|
146
|
+
isOwner(address: string): Promise<boolean>;
|
|
147
|
+
/** A page of names owned by an address, with sort/filter/pagination. */
|
|
148
|
+
names(address: string, query?: NamesQuery): Promise<NamesPage>;
|
|
149
|
+
/** True if a name is available to register. */
|
|
150
|
+
available(name: string): Promise<boolean>;
|
|
151
|
+
/** Batch availability / status check for one or more names. */
|
|
152
|
+
checkMany(names: string[]): Promise<DomainStatus[]>;
|
|
153
|
+
/** Order record for a domain (`null` if none). Useful for polling after registration. */
|
|
154
|
+
order(domain: string): Promise<Json | null>;
|
|
155
|
+
/** Pending order buckets (mint / incoming / outgoing) for an owner. */
|
|
156
|
+
pending(owner: string): Promise<PendingDomains>;
|
|
157
|
+
/** NFT detail by token id (`null` if not found). */
|
|
158
|
+
nft(nftokenId: string): Promise<Json | null>;
|
|
159
|
+
/** All coin addresses recorded for a name (multicoin records). */
|
|
160
|
+
addresses(name: string): Promise<CoinAddress[]>;
|
|
161
|
+
/** The address a name points to for a coin symbol/type (e.g. "XRP", "BTC"). `null` if unset. */
|
|
162
|
+
addressOf(name: string, symbol: string): Promise<string | null>;
|
|
163
|
+
/** Avatar / image URL for a name (`null` if none). */
|
|
164
|
+
avatar(name: string): Promise<string | null>;
|
|
165
|
+
/** A text/profile record for a name by key (searches metadata, profile, attributes). `null` if unset. */
|
|
166
|
+
record(name: string, key: string): Promise<string | null>;
|
|
167
|
+
/** Reverse-resolve many addresses (client-side batch, bounded concurrency). Preserves input order. */
|
|
168
|
+
reverseMany(addresses: string[], concurrency?: number): Promise<Array<{
|
|
169
|
+
address: string;
|
|
170
|
+
name: string | null;
|
|
171
|
+
}>>;
|
|
172
|
+
/** @deprecated Use {@link resolve}. */
|
|
173
|
+
getAddress(domain: string): Promise<string | null>;
|
|
174
|
+
/** @deprecated Use {@link reverse}. */
|
|
175
|
+
getName(address: string): Promise<string | null>;
|
|
176
|
+
/** @deprecated Use {@link names}. Returns the domain strings of the first page. */
|
|
177
|
+
getAllNames(address: string): Promise<string[]>;
|
|
178
|
+
}
|
|
179
|
+
/** Backward-compatible factory matching the old `xrplidjs.SDK(config)` call. */
|
|
180
|
+
declare function SDK(config?: XrplIdConfig & {
|
|
181
|
+
rpcUrl?: string;
|
|
182
|
+
Issuer?: string;
|
|
183
|
+
}): XrplId;
|
|
184
|
+
/**
|
|
185
|
+
* Create an XRPName client — the recommended entry point.
|
|
186
|
+
*
|
|
187
|
+
* Mirrors the ergonomics of other web3-name SDKs (no `new`, just call it):
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { createXRPName } from '@xrpname/sdk';
|
|
191
|
+
*
|
|
192
|
+
* const xns = createXRPName();
|
|
193
|
+
* await xns.resolve('xrpdomains.xrp'); // -> "raAyaz..." | null
|
|
194
|
+
* await xns.available('free-name.xrp'); // -> true | false
|
|
195
|
+
* await xns.reverse('raAyaz...'); // -> "hello.xrp" | null
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* Pass a config to point at a different network or tune transport:
|
|
199
|
+
* `createXRPName({ baseUrl, issuer, timeoutMs, retries, fetch })`.
|
|
200
|
+
*/
|
|
201
|
+
declare function createXRPName(config?: XrplIdConfig): XrplId;
|
|
202
|
+
/** Config alias so callers of {@link createXRPName} can import a matching name. */
|
|
203
|
+
type XRPNameConfig = XrplIdConfig;
|
|
204
|
+
/** Friendly alias for {@link XrplId}: `new XRPName()` reads better than `new XrplId()`. */
|
|
205
|
+
declare const XRPName: typeof XrplId;
|
|
206
|
+
type XRPName = XrplId;
|
|
207
|
+
|
|
208
|
+
export { type CoinAddress, DEFAULT_BASE_URL, DEFAULT_ISSUER, DEFAULT_TLD, type DomainStatus, type Envelope, type NameRecord, type NamesPage, type NamesQuery, type PendingDomains, SDK, XRPName, type XRPNameConfig, XrplId, type XrplIdConfig, XrplIdError, XrplIdExplorer, createXRPName, XrplId as default, isValidAddress, normalizeName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var b="https://app.xrpdomains.xyz/api/xrplnftv3",v="raAyazbgEkwzLByXipQuPLWFfnsPS1v1q9",x="xrp",l=class extends Error{constructor(t,e,r){super(t),this.name="XrplIdError",this.code=e,this.httpStatus=r}},P=/^r[1-9A-HJ-NP-Za-km-z]{24,34}$/;function p(a){return typeof a=="string"&&P.test(a)}function h(a,t="xrp"){if(typeof a!="string")throw new l("name must be a string","bad_request");let e=a.trim().toLowerCase();if(!e)throw new l("name must not be empty","bad_request");return e.includes(".")||(e=`${e}.${t.replace(/^\./,"")}`),e}var w=a=>new Promise(t=>setTimeout(t,a)),f=(a,t=0)=>typeof a=="number"&&isFinite(a)?a:t,y=class{constructor(t){this.client=t}recent(t=12){return this.client._explorer("recent",{limit:t})}sales(t=12){return this.client._explorer("sales",{limit:t})}listings(t=600){return this.client._explorer("listings",{limit:t})}market(){return this.client._explorer("market",{})}pulse(t="30d"){return this.client._explorer("pulse",{range:t})}minters(t="7d",e=10){return this.client._explorer("minters",{range:t,limit:e})}holders(t={}){return this.client._explorer("holders",t)}collections(){return this.client._explorer("collections",{})}categories(){return this.client._explorer("categories",{})}},c=class{constructor(t={}){this.baseUrl=(t.baseUrl??b).replace(/\/+$/,""),this.issuer=t.issuer??v,this.defaultTld=(t.defaultTld??"xrp").replace(/^\./,""),this.timeoutMs=t.timeoutMs??1e4,this.retries=Math.max(0,t.retries??2),this.headers={Accept:"application/json",...t.headers};let e=t.fetch??globalThis.fetch;if(typeof e!="function")throw new l("global fetch unavailable; pass config.fetch (Node < 18 needs a polyfill)","bad_request");this._fetch=e.bind(globalThis),this.explorer=new y(this)}async send(t,e){let r=new URL(`${this.baseUrl}/${t}`);for(let[i,d]of Object.entries(e.query??{}))r.searchParams.set(i,String(d));let{query:s,...n}=e,u;for(let i=0;i<=this.retries;i++){let d=new AbortController,m=setTimeout(()=>d.abort(),this.timeoutMs);try{let o=await this._fetch(r.toString(),{...n,headers:{...this.headers,...n.headers},signal:d.signal});if(!o.ok){if(o.status>=500&&i<this.retries){u=new l(`HTTP ${o.status}`,"http_error",o.status),await w(200*(i+1));continue}throw new l(`resolver returned HTTP ${o.status}`,"http_error",o.status)}let g;try{g=await o.json()}catch{throw new l("resolver returned invalid JSON","invalid_response",o.status)}if(!g||typeof g!="object")throw new l("unexpected resolver response","invalid_response",o.status);return g}catch(o){if(o instanceof l){if(o.code==="http_error"&&(o.httpStatus??0)>=500&&i<this.retries){u=o,await w(200*(i+1));continue}throw o}let g=o?.name==="AbortError";if(u=new l(g?`request timed out after ${this.timeoutMs}ms`:`network error: ${String(o)}`,g?"timeout":"network"),i<this.retries){await w(200*(i+1));continue}throw u}finally{clearTimeout(m)}}throw u??new l("request failed","network")}get(t,e={}){return this.send(t,{method:"GET",query:e})}async _explorer(t,e){let r=await this.get(t,e);return r.data??r}async resolve(t){return(await this.resolveFull(t))?.owner??null}async resolveFull(t){let e=h(t,this.defaultTld),r=await this.get("getAddress",{domain:e}),s=r.data??{},n=s.owner;return!r.status||!p(n)?null:{owner:n,nftokenId:typeof s.nftoken_id=="string"?s.nftoken_id:"",metadataUrl:typeof s.metadata_url=="string"?s.metadata_url:"",metadata:s.metadata&&typeof s.metadata=="object"?s.metadata:{},raw:s}}async reverse(t){if(!p(t))throw new l("invalid XRPL address","bad_request");let e=await this.get("getName",{address:t}),r=typeof e.data=="string"?e.data.trim():"";return e.status&&r?r.toLowerCase():null}async isOwner(t){if(!p(t))throw new l("invalid XRPL address","bad_request");let e=await this.get("isOwner",{address:t});return e.status===!0&&e.data===!0}async names(t,e={}){if(!p(t))throw new l("invalid XRPL address","bad_request");let r={address:t};e.page&&(r.page=e.page),e.limit&&(r.limit=e.limit),e.sort&&(r.sort=e.sort),e.keyword&&(r.keyword=e.keyword);let s=await this.get("getAllNames",r),n=Array.isArray(s.data)?s.data:[];return{items:n,total:f(s.total,n.length),page:f(s.page,e.page??1),limit:f(s.limit,e.limit??50),totalPages:f(s.total_pages,1),owner:typeof s.owner=="string"?s.owner:t}}async available(t){let[e]=await this.checkMany([t]);return e?.status==="available"}async checkMany(t){let e=t.map(n=>h(n,this.defaultTld));if(!e.length)return[];let r=await this.get("checkDomains",{domain:e.join(",")});return(Array.isArray(r.data)?r.data:[]).map(n=>({domain:String(n.domain??""),owner:typeof n.owner=="string"?n.owner:"",nftokenId:typeof n.nftoken_id=="string"?n.nftoken_id:"",status:n.status==="available"?"available":"registered",issuer:typeof n.issuer=="string"?n.issuer:this.issuer}))}async order(t){let e=await this.get("getOrderbyDomain",{domain:h(t,this.defaultTld)});return e.status&&e.data&&typeof e.data=="object"?e.data:null}async pending(t){if(!p(t))throw new l("invalid XRPL address","bad_request");let e=await this.get("getPendingDomains",{owner:t}),r=s=>Array.isArray(e[s])?e[s]:[];return{mint:r("mint"),incoming:r("incoming"),outgoing:r("outgoing")}}async nft(t){if(!t)throw new l("nftokenId required","bad_request");let e=await this.get("getNftByTokenId",{nftoken_id:t});return e.status&&e.data&&typeof e.data=="object"?e.data:null}async addresses(t){let e=await this.resolveFull(t);return(e&&Array.isArray(e.raw.addresses)?e.raw.addresses:[]).map(s=>({type:String(s.type??""),symbol:String(s.symbol??""),name:String(s.name??""),address:String(s.address??""),verified:s.verified===!0,visible:s.visible!==!1}))}async addressOf(t,e){let r=e.trim().toLowerCase();return(await this.addresses(t)).find(n=>n.symbol.toLowerCase()===r||n.type.toLowerCase()===r)?.address||null}async avatar(t){let e=await this.resolveFull(t);if(!e)return null;let r=e.metadata.image??e.raw.profile_image;return typeof r=="string"&&r?r:null}async record(t,e){let r=await this.resolveFull(t);if(!r)return null;let s=e.trim().toLowerCase(),n=[r.metadata,r.raw.profile_info,r.raw];for(let i of n)if(i&&typeof i=="object"){for(let[d,m]of Object.entries(i))if(d.toLowerCase()===s&&(typeof m=="string"||typeof m=="number"))return String(m)}let u=r.metadata.attributes??r.raw.attributes;if(Array.isArray(u)){for(let i of u)if(String(i.trait_type??i.key??i.name??"").toLowerCase()===s&&i.value!=null)return String(i.value)}return null}async reverseMany(t,e=5){let r=new Array(t.length),s=0,n=async()=>{for(;;){let u=s++;if(u>=t.length)break;let i=t[u],d=null;try{d=await this.reverse(i)}catch{d=null}r[u]={address:i,name:d}}};return await Promise.all(Array.from({length:Math.max(1,e)},n)),r}getAddress(t){return this.resolve(t)}getName(t){return this.reverse(t)}async getAllNames(t){return(await this.names(t,{limit:100})).items.map(r=>String(r.domain??"")).filter(Boolean)}};function _(a={}){let{Issuer:t,rpcUrl:e,...r}=a;return new c({...r,issuer:r.issuer??t})}function k(a={}){return new c(a)}var A=c,J=c;export{b as DEFAULT_BASE_URL,v as DEFAULT_ISSUER,x as DEFAULT_TLD,_ as SDK,A as XRPName,c as XrplId,l as XrplIdError,y as XrplIdExplorer,k as createXRPName,J as default,p as isValidAddress,h as normalizeName};
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xrpname/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Official SDK for XRPName — resolve .xrp names on the XRP Ledger (XRPL Name Service / XNS). Zero-dependency, Node + browser.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"xrpl",
|
|
7
|
+
"xrp",
|
|
8
|
+
"name service",
|
|
9
|
+
"xrpname",
|
|
10
|
+
"xns",
|
|
11
|
+
"resolver",
|
|
12
|
+
".xrp",
|
|
13
|
+
"web3",
|
|
14
|
+
"domains"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://xrpdomains.xyz",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"email": "info@xrpdomains.xyz"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --minify",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.4.0"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/XRPDomains"
|
|
54
|
+
}
|
|
55
|
+
}
|