zcashname-sdk 0.5.0 → 0.5.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 ADDED
@@ -0,0 +1,93 @@
1
+ # Zcash Name System (ZNS) SDK
2
+
3
+ TypeScript SDK for interacting with the Zcash Name System — a decentralized naming system built on Zcash.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install zcashname-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { ZNS } from "zcashname-sdk";
15
+
16
+ const zns = await ZNS.create();
17
+
18
+ const name = "alice";
19
+ const resolved = await zns.resolve(name);
20
+ if (resolved === null) {
21
+ console.log(`${name} is available`);
22
+ } else {
23
+ console.log(`${name} resolves to ${resolved.address}`);
24
+ }
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### `ZNS.create(options?)`
30
+ Create a new ZNS instance connected to the default testnet endpoint.
31
+
32
+ ```ts
33
+ const zns = await ZNS.create();
34
+ const znsMainnet = await ZNS.create({ url: "https://light.zcash.me/zns-mainnet" });
35
+ ```
36
+
37
+ ### `zns.resolve(query)`
38
+ Resolve a name to its registered address. Returns `null` if the name is available.
39
+
40
+ ```ts
41
+ const result = await zns.resolve("alice");
42
+ ```
43
+
44
+ ### `zns.isAvailable(name)`
45
+ Check if a name is available for registration.
46
+
47
+ ```ts
48
+ const available = await zns.isAvailable("bob");
49
+ ```
50
+
51
+ ### `zns.listings()`
52
+ Get all names currently listed for sale.
53
+
54
+ ```ts
55
+ const listings = await zns.listings();
56
+ ```
57
+
58
+ ### `zns.events(filter?)`
59
+ Query blockchain events (claims, buys, lists, delists, updates, releases).
60
+
61
+ ```ts
62
+ const { events } = await zns.events({ action: "CLAIM", limit: 50 });
63
+ ```
64
+
65
+ ### Action Helpers
66
+
67
+ The SDK provides prepare/complete pairs for all ZNS actions:
68
+
69
+ - `zns.prepareClaim(name, address)` / `zns.completeClaim(...)` — claim a name
70
+ - `zns.prepareList(name, price, nonce)` / `zns.completeList(...)` — list a name for sale
71
+ - `zns.prepareDelist(name, nonce)` / `zns.completeDelist(...)` — delist a name
72
+ - `zns.prepareUpdate(name, newAddress, nonce)` / `zns.completeUpdate(...)` — update a name's address
73
+ - `zns.prepareBuy(name, buyerAddress)` / `zns.completeBuy(...)` — buy a name
74
+ - `zns.prepareRelease(name, nonce)` / `zns.completeRelease(...)` — release a name
75
+
76
+ Each `complete*` method returns a `{ memo, uri }` object suitable for constructing a ZIP 321 URI.
77
+
78
+ ### `zns.parseZip321Uri(uri)`
79
+ Parse a ZIP 321 URI into its components.
80
+
81
+ ```ts
82
+ const parsed = zns.parseZip321Uri("zcash:addr?amount=0.1&memo=...");
83
+ ```
84
+
85
+ ## Constants
86
+
87
+ - `DEFAULT_URL` — default testnet endpoint
88
+ - `TESTNET_UIVK` — expected testnet UIVK for verification
89
+ - `MAINNET_UIVK` — expected mainnet UIVK for verification
90
+
91
+ ## License
92
+
93
+ MIT
package/dist/zns.cjs CHANGED
@@ -185,17 +185,23 @@ var ZNS = class _ZNS {
185
185
  const memoDecoded = memoRaw ? this.decodeBase64Url(memoRaw) : "";
186
186
  return { address, amount, memoRaw, memoDecoded };
187
187
  }
188
- async enrichRegistration(reg) {
188
+ async enrichRegistration(raw) {
189
+ const { listing: rawListing, ...reg } = raw;
189
190
  const sovereign = reg.pubkey != null && reg.pubkey !== this._adminPubkey;
190
- let verified = false;
191
- if (reg.signature && this._adminPubkey) {
192
- const payload = this.registrationPayload(reg);
193
- if (payload) {
194
- const pubkey = sovereign ? reg.pubkey : this._adminPubkey;
195
- verified = await this.verifyEd25519(payload, reg.signature, pubkey);
196
- }
197
- }
198
- return { ...reg, listing: null, verified, sovereign };
191
+ const verified = await this.verifyRegistration(reg, sovereign);
192
+ const listing = rawListing ? await this.verifyListing(rawListing) : null;
193
+ return { ...reg, listing, verified, sovereign };
194
+ }
195
+ async verifyRegistration(reg, sovereign) {
196
+ if (!reg.signature || !this._adminPubkey) return false;
197
+ const payload = this.registrationPayload(reg);
198
+ if (!payload) return false;
199
+ const pubkey = sovereign ? reg.pubkey : this._adminPubkey;
200
+ return this.verifyEd25519(payload, reg.signature, pubkey);
201
+ }
202
+ async verifyListing(listing) {
203
+ const verified = this._adminPubkey ? await this.verifyEd25519(this.listingPayload(listing), listing.signature, this._adminPubkey) : false;
204
+ return { ...listing, verified };
199
205
  }
200
206
  async enrichListing(listing) {
201
207
  let verified = false;
package/dist/zns.d.cts CHANGED
@@ -18,7 +18,7 @@ interface Listing {
18
18
  signature: string;
19
19
  }
20
20
  interface ResolveResult extends Registration {
21
- listing: Listing | null;
21
+ listing: VerifiedListing | null;
22
22
  verified: boolean;
23
23
  sovereign: boolean;
24
24
  }
@@ -122,6 +122,8 @@ declare class ZNS {
122
122
  memoDecoded: string;
123
123
  };
124
124
  private enrichRegistration;
125
+ private verifyRegistration;
126
+ private verifyListing;
125
127
  private enrichListing;
126
128
  private enrichEvent;
127
129
  private registrationPayload;
package/dist/zns.d.ts CHANGED
@@ -18,7 +18,7 @@ interface Listing {
18
18
  signature: string;
19
19
  }
20
20
  interface ResolveResult extends Registration {
21
- listing: Listing | null;
21
+ listing: VerifiedListing | null;
22
22
  verified: boolean;
23
23
  sovereign: boolean;
24
24
  }
@@ -122,6 +122,8 @@ declare class ZNS {
122
122
  memoDecoded: string;
123
123
  };
124
124
  private enrichRegistration;
125
+ private verifyRegistration;
126
+ private verifyListing;
125
127
  private enrichListing;
126
128
  private enrichEvent;
127
129
  private registrationPayload;
package/dist/zns.js CHANGED
@@ -158,17 +158,23 @@ var ZNS = class _ZNS {
158
158
  const memoDecoded = memoRaw ? this.decodeBase64Url(memoRaw) : "";
159
159
  return { address, amount, memoRaw, memoDecoded };
160
160
  }
161
- async enrichRegistration(reg) {
161
+ async enrichRegistration(raw) {
162
+ const { listing: rawListing, ...reg } = raw;
162
163
  const sovereign = reg.pubkey != null && reg.pubkey !== this._adminPubkey;
163
- let verified = false;
164
- if (reg.signature && this._adminPubkey) {
165
- const payload = this.registrationPayload(reg);
166
- if (payload) {
167
- const pubkey = sovereign ? reg.pubkey : this._adminPubkey;
168
- verified = await this.verifyEd25519(payload, reg.signature, pubkey);
169
- }
170
- }
171
- return { ...reg, listing: null, verified, sovereign };
164
+ const verified = await this.verifyRegistration(reg, sovereign);
165
+ const listing = rawListing ? await this.verifyListing(rawListing) : null;
166
+ return { ...reg, listing, verified, sovereign };
167
+ }
168
+ async verifyRegistration(reg, sovereign) {
169
+ if (!reg.signature || !this._adminPubkey) return false;
170
+ const payload = this.registrationPayload(reg);
171
+ if (!payload) return false;
172
+ const pubkey = sovereign ? reg.pubkey : this._adminPubkey;
173
+ return this.verifyEd25519(payload, reg.signature, pubkey);
174
+ }
175
+ async verifyListing(listing) {
176
+ const verified = this._adminPubkey ? await this.verifyEd25519(this.listingPayload(listing), listing.signature, this._adminPubkey) : false;
177
+ return { ...listing, verified };
172
178
  }
173
179
  async enrichListing(listing) {
174
180
  let verified = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcashname-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Zcash Name System (ZNS)",
6
6
  "main": "dist/zns.cjs",
@@ -14,7 +14,8 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "dist"
17
+ "dist",
18
+ "README.md"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "tsup src/zns.ts --format cjs,esm --dts",