zcashname-sdk 0.8.3 → 0.8.4

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/dist/zns.cjs CHANGED
@@ -45,11 +45,93 @@ var import_bech32 = require("bech32");
45
45
  // src/types.ts
46
46
  var BUY_COMMISSION = 1e4;
47
47
  var LIST_COMMISSION = 1e6;
48
+ function toPendingBuy(raw) {
49
+ return {
50
+ buyer: raw.buyer_ua,
51
+ price: raw.price,
52
+ claimHeight: raw.claim_height,
53
+ expiresAt: raw.expires_at,
54
+ txid: raw.txid
55
+ };
56
+ }
57
+ function toListing(raw) {
58
+ return {
59
+ name: raw.name,
60
+ price: raw.price,
61
+ payTaddr: raw.pay_taddr,
62
+ nonce: raw.nonce,
63
+ txid: raw.txid,
64
+ height: raw.height,
65
+ signature: raw.signature,
66
+ pubkey: raw.pubkey,
67
+ pendingBuy: raw.pending_buy ? toPendingBuy(raw.pending_buy) : void 0
68
+ };
69
+ }
70
+ function toRegistration(raw) {
71
+ return {
72
+ name: raw.name,
73
+ address: raw.address,
74
+ txid: raw.txid,
75
+ height: raw.height,
76
+ nonce: raw.nonce,
77
+ signature: raw.signature,
78
+ lastAction: raw.last_action,
79
+ pubkey: raw.pubkey,
80
+ listing: raw.listing ? toListing(raw.listing) : null
81
+ };
82
+ }
83
+ function toPricing(raw) {
84
+ return {
85
+ nonce: raw.nonce,
86
+ height: raw.height,
87
+ tiers: raw.tiers
88
+ };
89
+ }
90
+ function toStatus(raw) {
91
+ return {
92
+ syncedHeight: raw.synced_height,
93
+ adminPubkey: raw.admin_pubkey,
94
+ uivk: raw.uivk,
95
+ address: raw.address,
96
+ registered: raw.registered,
97
+ listed: raw.listed,
98
+ pricing: raw.pricing ? toPricing(raw.pricing) : null
99
+ };
100
+ }
101
+ function toEvent(raw) {
102
+ return {
103
+ id: raw.id,
104
+ name: raw.name,
105
+ action: raw.action,
106
+ txid: raw.txid,
107
+ height: raw.height,
108
+ ua: raw.ua,
109
+ price: raw.price,
110
+ nonce: raw.nonce,
111
+ signature: raw.signature,
112
+ pubkey: raw.pubkey
113
+ };
114
+ }
115
+ function toEventsFilter(raw) {
116
+ return {
117
+ name: raw.name,
118
+ action: raw.action,
119
+ since_height: raw.sinceHeight,
120
+ limit: raw.limit,
121
+ offset: raw.offset
122
+ };
123
+ }
124
+ function toEventsResult(raw) {
125
+ return {
126
+ events: raw.events.map(toEvent),
127
+ total: raw.total
128
+ };
129
+ }
48
130
 
49
131
  // src/zns.ts
50
132
  var DEFAULT_URL = "https://light.zcash.me/zns-testnet";
51
- var TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
52
- var MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
133
+ var TESTNET_UIVK = "utest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
134
+ var MAINNET_UIVK = "u1k0evt0ahj5qdt6y9ftsxndl8lrkm4ff6rp00u04cjpmqj6hxl9t8hfsxftmn3ht34e03lljh89czn2h8qn67rwrs8x0hm3lsxsucp9q9";
53
135
  var KNOWN_UIVKS = [TESTNET_UIVK, MAINNET_UIVK];
54
136
  var REGISTRY_ADDRESSES = {
55
137
  testnet: "utest1f32kn6c4zvn54xr8wfsnxmj9hzpu2mwgtxzpzwcw34906tdccdvzs0z2dx38lly7tpan77x6udt8pjczqm22ymsdhlz9j0tk5yq664nl",
@@ -81,7 +163,7 @@ var ZNS = class {
81
163
  * @throws Error if the server's UIVK is not recognized
82
164
  */
83
165
  async verify() {
84
- const status = await this.rpc("status");
166
+ const status = await this.status();
85
167
  if (!KNOWN_UIVKS.includes(status.uivk)) {
86
168
  throw new Error(
87
169
  `UIVK mismatch: indexer returned "${status.uivk.slice(0, 20)}..." which is not a known ZNS instance`
@@ -103,29 +185,33 @@ var ZNS = class {
103
185
  }
104
186
  /** Fetch current server status including pricing and configuration. */
105
187
  async status() {
106
- return this.rpc("status");
188
+ const raw = await this.rpc("status");
189
+ return toStatus(raw);
107
190
  }
108
191
  /** Resolve a ZNS name to its registration. Returns null if not registered. */
109
192
  async resolveName(name) {
110
- return this.rpc("resolve", { query: name });
193
+ const raw = await this.rpc("resolve", { query: name });
194
+ return raw ? toRegistration(raw) : null;
111
195
  }
112
196
  /** Resolve a Zcash Unified Address to all names pointing to it. Returns empty array if none.
113
197
  * Supports pagination with limit (default 50, max 500) and offset (default 0). */
114
198
  async resolveAddress(address, limit, offset) {
115
- return this.rpc("resolve", {
199
+ const raw = await this.rpc("resolve", {
116
200
  query: address,
117
201
  limit,
118
202
  offset
119
203
  });
204
+ return raw.map(toRegistration);
120
205
  }
121
206
  /** List all registered names. Useful for explorers or browsers.
122
207
  * Supports pagination with limit (default 50, max 500) and offset (default 0). */
123
208
  async listAllRegistrations(limit, offset) {
124
- return this.rpc("resolve", {
209
+ const raw = await this.rpc("resolve", {
125
210
  query: "",
126
211
  limit,
127
212
  offset
128
213
  });
214
+ return raw.map(toRegistration);
129
215
  }
130
216
  /** Check if a name is available for registration.
131
217
  * Returns false immediately for invalid names without hitting the server. */
@@ -154,13 +240,33 @@ var ZNS = class {
154
240
  limit,
155
241
  offset
156
242
  });
157
- return result;
243
+ return {
244
+ listings: result.listings.map((l) => ({
245
+ name: l.name,
246
+ price: l.price,
247
+ payTaddr: l.pay_taddr,
248
+ nonce: l.nonce,
249
+ txid: l.txid,
250
+ height: l.height,
251
+ signature: l.signature,
252
+ pubkey: l.pubkey,
253
+ pendingBuy: l.pending_buy ? {
254
+ buyer: l.pending_buy.buyer_ua,
255
+ price: l.pending_buy.price,
256
+ claimHeight: l.pending_buy.claim_height,
257
+ expiresAt: l.pending_buy.expires_at,
258
+ txid: l.pending_buy.txid
259
+ } : void 0
260
+ })),
261
+ total: result.total
262
+ };
158
263
  }
159
264
  async events(filter) {
160
- return this.rpc(
265
+ const raw = await this.rpc(
161
266
  "events",
162
- filter ?? {}
267
+ toEventsFilter(filter ?? {})
163
268
  );
269
+ return toEventsResult(raw);
164
270
  }
165
271
  /**
166
272
  * Verify a listing's signature.
@@ -170,7 +276,7 @@ var ZNS = class {
170
276
  */
171
277
  async verifyListing(listing, adminPubkey) {
172
278
  const pubkey = listing.pubkey ?? adminPubkey;
173
- const payload = `LIST:${listing.name}:${listing.price}:${listing.pay_taddr}:${listing.nonce}`;
279
+ const payload = `LIST:${listing.name}:${listing.price}:${listing.payTaddr}:${listing.nonce}`;
174
280
  return this.verifyEd25519(payload, listing.signature, pubkey);
175
281
  }
176
282
  /**
@@ -360,16 +466,16 @@ var ZNS = class {
360
466
  }
361
467
  };
362
468
  }
363
- prepareList(name, price, pay_taddr, nonce) {
469
+ prepareList(name, price, payTaddr, nonce) {
364
470
  this.requireValidName(name);
365
471
  return {
366
472
  name,
367
473
  price,
368
- pay_taddr,
474
+ payTaddr,
369
475
  nonce,
370
- payload: `LIST:${name}:${price}:${pay_taddr}:${nonce}`,
476
+ payload: `LIST:${name}:${price}:${payTaddr}:${nonce}`,
371
477
  complete: (signature, userPubkey) => {
372
- const memo = userPubkey ? `ZNS:LIST:${name}:${price}:${pay_taddr}:${nonce}:${signature}:${userPubkey}` : `ZNS:LIST:${name}:${price}:${pay_taddr}:${nonce}:${signature}`;
478
+ const memo = userPubkey ? `ZNS:LIST:${name}:${price}:${payTaddr}:${nonce}:${signature}:${userPubkey}` : `ZNS:LIST:${name}:${price}:${payTaddr}:${nonce}:${signature}`;
373
479
  return { memo, uri: this.buildZcashUri(this.registryAddress, LIST_COMMISSION, memo) };
374
480
  }
375
481
  };
@@ -443,7 +549,7 @@ var ZNS = class {
443
549
  }
444
550
  // ── Private helpers ────────────────────────────────────────────────────────
445
551
  registrationPayload(reg) {
446
- switch (reg.last_action) {
552
+ switch (reg.lastAction) {
447
553
  case "CLAIM":
448
554
  return `CLAIM:${reg.name}:${reg.address}`;
449
555
  case "BUY":
package/dist/zns.d.cts CHANGED
@@ -1,59 +1,67 @@
1
- /** Amount in zatoshis (1 ZEC = 100,000,000 zats).
2
- * All monetary values in ZNS are denominated in zats.
3
- * Note: JavaScript number precision degrades above 2^53 (~9e15 zats, or ~90M ZEC) */
1
+ /**
2
+ * Internal types that mirror the Rust indexer API exactly (snake_case).
3
+ * These are used for raw data passthrough and debugging.
4
+ * Public SDK consumers should use the camelCase types exported below.
5
+ */
4
6
  type Zats = number;
5
7
  /** Commission sent with a BUY claim memo (0.0001 ZEC = 10,000 zats). */
6
8
  declare const BUY_COMMISSION: Zats;
7
9
  /** Listing commission sent with a LIST memo (0.01 ZEC = 1,000,000 zats).
8
10
  * Mirrors the indexer's formula: min_tier × 1000. */
9
11
  declare const LIST_COMMISSION: Zats;
10
- interface Registration {
11
- name: string;
12
- address: string;
13
- txid: string;
14
- height: number;
15
- nonce: number;
16
- signature: string | null;
17
- last_action: LastAction;
18
- pubkey: string | null;
19
- listing: Listing | null;
20
- }
21
12
  /** Actions that can be the 'last action' on a Registration (ownership-changing actions) */
22
13
  type LastAction = "CLAIM" | "BUY" | "UPDATE" | "DELIST" | "RELEASE";
23
14
  /** All actions that can appear in the Event log (includes non-ownership actions like LIST) */
24
15
  type EventAction = "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
16
+ /** Pending purchase for a listed name. */
17
+ interface PendingBuy {
18
+ buyer: string;
19
+ price: Zats;
20
+ claimHeight: number;
21
+ expiresAt: number;
22
+ txid: string;
23
+ }
24
+ /** A name listing in the marketplace. */
25
25
  interface Listing {
26
26
  name: string;
27
27
  price: Zats;
28
- pay_taddr: string;
28
+ payTaddr: string;
29
29
  nonce: number;
30
30
  txid: string;
31
31
  height: number;
32
32
  signature: string;
33
33
  pubkey: string | null;
34
- pending_buy: PendingBuy | null;
34
+ pendingBuy: PendingBuy | undefined;
35
35
  }
36
- interface PendingBuy {
37
- buyer_ua: string;
38
- price: Zats;
39
- claim_height: number;
40
- expires_at: number;
36
+ /** A registered ZNS name. */
37
+ interface Registration {
38
+ name: string;
39
+ address: string;
41
40
  txid: string;
41
+ height: number;
42
+ nonce: number;
43
+ signature: string | null;
44
+ lastAction: LastAction;
45
+ pubkey: string | null;
46
+ listing: Listing | null;
42
47
  }
48
+ /** Pricing tiers for name registration. */
43
49
  interface Pricing {
44
50
  nonce: number;
45
51
  height: number;
46
52
  tiers: Zats[];
47
53
  }
54
+ /** Current indexer status including pricing configuration. */
48
55
  interface Status {
49
- synced_height: number;
50
- admin_pubkey: string;
56
+ syncedHeight: number;
57
+ adminPubkey: string;
51
58
  uivk: string;
52
59
  address: string;
53
60
  registered: number;
54
61
  listed: number;
55
62
  pricing: Pricing | null;
56
63
  }
64
+ /** An event in the ZNS event log. */
57
65
  interface Event {
58
66
  id: number;
59
67
  name: string;
@@ -66,13 +74,15 @@ interface Event {
66
74
  signature: string | null;
67
75
  pubkey: string | null;
68
76
  }
77
+ /** Filter options for querying events. */
69
78
  interface EventsFilter {
70
79
  name?: string;
71
80
  action?: EventAction;
72
- since_height?: number;
81
+ sinceHeight?: number;
73
82
  limit?: number;
74
83
  offset?: number;
75
84
  }
85
+ /** Paginated events result. */
76
86
  interface EventsResult {
77
87
  events: Event[];
78
88
  total: number;
@@ -103,7 +113,7 @@ interface PreparedClaim extends PreparedAction {
103
113
  interface PreparedList extends PreparedAction {
104
114
  readonly name: string;
105
115
  readonly price: Zats;
106
- readonly pay_taddr: string;
116
+ readonly payTaddr: string;
107
117
  readonly nonce: number;
108
118
  }
109
119
  /** Prepared DELIST action */
@@ -151,8 +161,8 @@ interface PayloadValidationResult {
151
161
  }
152
162
 
153
163
  declare const DEFAULT_URL = "https://light.zcash.me/zns-testnet";
154
- declare const TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
155
- declare const MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
164
+ declare const TESTNET_UIVK = "utest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
165
+ declare const MAINNET_UIVK = "u1k0evt0ahj5qdt6y9ftsxndl8lrkm4ff6rp00u04cjpmqj6hxl9t8hfsxftmn3ht34e03lljh89czn2h8qn67rwrs8x0hm3lsxsucp9q9";
156
166
  /** Actions accepted by {@link validatePayload}. Exposed for consumers who need
157
167
  * to build action selectors or dynamic validation. */
158
168
  declare const ZNS_ACTIONS: readonly ["CLAIM", "BUY", "UPDATE", "LIST", "DELIST", "RELEASE"];
@@ -269,7 +279,7 @@ declare class ZNS {
269
279
  * @returns Prepared claim ready for signature completion
270
280
  */
271
281
  prepareClaim(name: string, address: string, cost: Zats): PreparedClaim;
272
- prepareList(name: string, price: Zats, pay_taddr: string, nonce: number): PreparedList;
282
+ prepareList(name: string, price: Zats, payTaddr: string, nonce: number): PreparedList;
273
283
  prepareDelist(name: string, nonce: number): PreparedDelist;
274
284
  prepareUpdate(name: string, newAddress: string, nonce: number): PreparedUpdate;
275
285
  prepareBuy(name: string, buyerAddress: string, price: Zats): PreparedBuy;
package/dist/zns.d.ts CHANGED
@@ -1,59 +1,67 @@
1
- /** Amount in zatoshis (1 ZEC = 100,000,000 zats).
2
- * All monetary values in ZNS are denominated in zats.
3
- * Note: JavaScript number precision degrades above 2^53 (~9e15 zats, or ~90M ZEC) */
1
+ /**
2
+ * Internal types that mirror the Rust indexer API exactly (snake_case).
3
+ * These are used for raw data passthrough and debugging.
4
+ * Public SDK consumers should use the camelCase types exported below.
5
+ */
4
6
  type Zats = number;
5
7
  /** Commission sent with a BUY claim memo (0.0001 ZEC = 10,000 zats). */
6
8
  declare const BUY_COMMISSION: Zats;
7
9
  /** Listing commission sent with a LIST memo (0.01 ZEC = 1,000,000 zats).
8
10
  * Mirrors the indexer's formula: min_tier × 1000. */
9
11
  declare const LIST_COMMISSION: Zats;
10
- interface Registration {
11
- name: string;
12
- address: string;
13
- txid: string;
14
- height: number;
15
- nonce: number;
16
- signature: string | null;
17
- last_action: LastAction;
18
- pubkey: string | null;
19
- listing: Listing | null;
20
- }
21
12
  /** Actions that can be the 'last action' on a Registration (ownership-changing actions) */
22
13
  type LastAction = "CLAIM" | "BUY" | "UPDATE" | "DELIST" | "RELEASE";
23
14
  /** All actions that can appear in the Event log (includes non-ownership actions like LIST) */
24
15
  type EventAction = "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
16
+ /** Pending purchase for a listed name. */
17
+ interface PendingBuy {
18
+ buyer: string;
19
+ price: Zats;
20
+ claimHeight: number;
21
+ expiresAt: number;
22
+ txid: string;
23
+ }
24
+ /** A name listing in the marketplace. */
25
25
  interface Listing {
26
26
  name: string;
27
27
  price: Zats;
28
- pay_taddr: string;
28
+ payTaddr: string;
29
29
  nonce: number;
30
30
  txid: string;
31
31
  height: number;
32
32
  signature: string;
33
33
  pubkey: string | null;
34
- pending_buy: PendingBuy | null;
34
+ pendingBuy: PendingBuy | undefined;
35
35
  }
36
- interface PendingBuy {
37
- buyer_ua: string;
38
- price: Zats;
39
- claim_height: number;
40
- expires_at: number;
36
+ /** A registered ZNS name. */
37
+ interface Registration {
38
+ name: string;
39
+ address: string;
41
40
  txid: string;
41
+ height: number;
42
+ nonce: number;
43
+ signature: string | null;
44
+ lastAction: LastAction;
45
+ pubkey: string | null;
46
+ listing: Listing | null;
42
47
  }
48
+ /** Pricing tiers for name registration. */
43
49
  interface Pricing {
44
50
  nonce: number;
45
51
  height: number;
46
52
  tiers: Zats[];
47
53
  }
54
+ /** Current indexer status including pricing configuration. */
48
55
  interface Status {
49
- synced_height: number;
50
- admin_pubkey: string;
56
+ syncedHeight: number;
57
+ adminPubkey: string;
51
58
  uivk: string;
52
59
  address: string;
53
60
  registered: number;
54
61
  listed: number;
55
62
  pricing: Pricing | null;
56
63
  }
64
+ /** An event in the ZNS event log. */
57
65
  interface Event {
58
66
  id: number;
59
67
  name: string;
@@ -66,13 +74,15 @@ interface Event {
66
74
  signature: string | null;
67
75
  pubkey: string | null;
68
76
  }
77
+ /** Filter options for querying events. */
69
78
  interface EventsFilter {
70
79
  name?: string;
71
80
  action?: EventAction;
72
- since_height?: number;
81
+ sinceHeight?: number;
73
82
  limit?: number;
74
83
  offset?: number;
75
84
  }
85
+ /** Paginated events result. */
76
86
  interface EventsResult {
77
87
  events: Event[];
78
88
  total: number;
@@ -103,7 +113,7 @@ interface PreparedClaim extends PreparedAction {
103
113
  interface PreparedList extends PreparedAction {
104
114
  readonly name: string;
105
115
  readonly price: Zats;
106
- readonly pay_taddr: string;
116
+ readonly payTaddr: string;
107
117
  readonly nonce: number;
108
118
  }
109
119
  /** Prepared DELIST action */
@@ -151,8 +161,8 @@ interface PayloadValidationResult {
151
161
  }
152
162
 
153
163
  declare const DEFAULT_URL = "https://light.zcash.me/zns-testnet";
154
- declare const TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
155
- declare const MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
164
+ declare const TESTNET_UIVK = "utest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
165
+ declare const MAINNET_UIVK = "u1k0evt0ahj5qdt6y9ftsxndl8lrkm4ff6rp00u04cjpmqj6hxl9t8hfsxftmn3ht34e03lljh89czn2h8qn67rwrs8x0hm3lsxsucp9q9";
156
166
  /** Actions accepted by {@link validatePayload}. Exposed for consumers who need
157
167
  * to build action selectors or dynamic validation. */
158
168
  declare const ZNS_ACTIONS: readonly ["CLAIM", "BUY", "UPDATE", "LIST", "DELIST", "RELEASE"];
@@ -269,7 +279,7 @@ declare class ZNS {
269
279
  * @returns Prepared claim ready for signature completion
270
280
  */
271
281
  prepareClaim(name: string, address: string, cost: Zats): PreparedClaim;
272
- prepareList(name: string, price: Zats, pay_taddr: string, nonce: number): PreparedList;
282
+ prepareList(name: string, price: Zats, payTaddr: string, nonce: number): PreparedList;
273
283
  prepareDelist(name: string, nonce: number): PreparedDelist;
274
284
  prepareUpdate(name: string, newAddress: string, nonce: number): PreparedUpdate;
275
285
  prepareBuy(name: string, buyerAddress: string, price: Zats): PreparedBuy;
package/dist/zns.js CHANGED
@@ -5,11 +5,93 @@ import { bech32m } from "bech32";
5
5
  // src/types.ts
6
6
  var BUY_COMMISSION = 1e4;
7
7
  var LIST_COMMISSION = 1e6;
8
+ function toPendingBuy(raw) {
9
+ return {
10
+ buyer: raw.buyer_ua,
11
+ price: raw.price,
12
+ claimHeight: raw.claim_height,
13
+ expiresAt: raw.expires_at,
14
+ txid: raw.txid
15
+ };
16
+ }
17
+ function toListing(raw) {
18
+ return {
19
+ name: raw.name,
20
+ price: raw.price,
21
+ payTaddr: raw.pay_taddr,
22
+ nonce: raw.nonce,
23
+ txid: raw.txid,
24
+ height: raw.height,
25
+ signature: raw.signature,
26
+ pubkey: raw.pubkey,
27
+ pendingBuy: raw.pending_buy ? toPendingBuy(raw.pending_buy) : void 0
28
+ };
29
+ }
30
+ function toRegistration(raw) {
31
+ return {
32
+ name: raw.name,
33
+ address: raw.address,
34
+ txid: raw.txid,
35
+ height: raw.height,
36
+ nonce: raw.nonce,
37
+ signature: raw.signature,
38
+ lastAction: raw.last_action,
39
+ pubkey: raw.pubkey,
40
+ listing: raw.listing ? toListing(raw.listing) : null
41
+ };
42
+ }
43
+ function toPricing(raw) {
44
+ return {
45
+ nonce: raw.nonce,
46
+ height: raw.height,
47
+ tiers: raw.tiers
48
+ };
49
+ }
50
+ function toStatus(raw) {
51
+ return {
52
+ syncedHeight: raw.synced_height,
53
+ adminPubkey: raw.admin_pubkey,
54
+ uivk: raw.uivk,
55
+ address: raw.address,
56
+ registered: raw.registered,
57
+ listed: raw.listed,
58
+ pricing: raw.pricing ? toPricing(raw.pricing) : null
59
+ };
60
+ }
61
+ function toEvent(raw) {
62
+ return {
63
+ id: raw.id,
64
+ name: raw.name,
65
+ action: raw.action,
66
+ txid: raw.txid,
67
+ height: raw.height,
68
+ ua: raw.ua,
69
+ price: raw.price,
70
+ nonce: raw.nonce,
71
+ signature: raw.signature,
72
+ pubkey: raw.pubkey
73
+ };
74
+ }
75
+ function toEventsFilter(raw) {
76
+ return {
77
+ name: raw.name,
78
+ action: raw.action,
79
+ since_height: raw.sinceHeight,
80
+ limit: raw.limit,
81
+ offset: raw.offset
82
+ };
83
+ }
84
+ function toEventsResult(raw) {
85
+ return {
86
+ events: raw.events.map(toEvent),
87
+ total: raw.total
88
+ };
89
+ }
8
90
 
9
91
  // src/zns.ts
10
92
  var DEFAULT_URL = "https://light.zcash.me/zns-testnet";
11
- var TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
12
- var MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
93
+ var TESTNET_UIVK = "utest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
94
+ var MAINNET_UIVK = "u1k0evt0ahj5qdt6y9ftsxndl8lrkm4ff6rp00u04cjpmqj6hxl9t8hfsxftmn3ht34e03lljh89czn2h8qn67rwrs8x0hm3lsxsucp9q9";
13
95
  var KNOWN_UIVKS = [TESTNET_UIVK, MAINNET_UIVK];
14
96
  var REGISTRY_ADDRESSES = {
15
97
  testnet: "utest1f32kn6c4zvn54xr8wfsnxmj9hzpu2mwgtxzpzwcw34906tdccdvzs0z2dx38lly7tpan77x6udt8pjczqm22ymsdhlz9j0tk5yq664nl",
@@ -41,7 +123,7 @@ var ZNS = class {
41
123
  * @throws Error if the server's UIVK is not recognized
42
124
  */
43
125
  async verify() {
44
- const status = await this.rpc("status");
126
+ const status = await this.status();
45
127
  if (!KNOWN_UIVKS.includes(status.uivk)) {
46
128
  throw new Error(
47
129
  `UIVK mismatch: indexer returned "${status.uivk.slice(0, 20)}..." which is not a known ZNS instance`
@@ -63,29 +145,33 @@ var ZNS = class {
63
145
  }
64
146
  /** Fetch current server status including pricing and configuration. */
65
147
  async status() {
66
- return this.rpc("status");
148
+ const raw = await this.rpc("status");
149
+ return toStatus(raw);
67
150
  }
68
151
  /** Resolve a ZNS name to its registration. Returns null if not registered. */
69
152
  async resolveName(name) {
70
- return this.rpc("resolve", { query: name });
153
+ const raw = await this.rpc("resolve", { query: name });
154
+ return raw ? toRegistration(raw) : null;
71
155
  }
72
156
  /** Resolve a Zcash Unified Address to all names pointing to it. Returns empty array if none.
73
157
  * Supports pagination with limit (default 50, max 500) and offset (default 0). */
74
158
  async resolveAddress(address, limit, offset) {
75
- return this.rpc("resolve", {
159
+ const raw = await this.rpc("resolve", {
76
160
  query: address,
77
161
  limit,
78
162
  offset
79
163
  });
164
+ return raw.map(toRegistration);
80
165
  }
81
166
  /** List all registered names. Useful for explorers or browsers.
82
167
  * Supports pagination with limit (default 50, max 500) and offset (default 0). */
83
168
  async listAllRegistrations(limit, offset) {
84
- return this.rpc("resolve", {
169
+ const raw = await this.rpc("resolve", {
85
170
  query: "",
86
171
  limit,
87
172
  offset
88
173
  });
174
+ return raw.map(toRegistration);
89
175
  }
90
176
  /** Check if a name is available for registration.
91
177
  * Returns false immediately for invalid names without hitting the server. */
@@ -114,13 +200,33 @@ var ZNS = class {
114
200
  limit,
115
201
  offset
116
202
  });
117
- return result;
203
+ return {
204
+ listings: result.listings.map((l) => ({
205
+ name: l.name,
206
+ price: l.price,
207
+ payTaddr: l.pay_taddr,
208
+ nonce: l.nonce,
209
+ txid: l.txid,
210
+ height: l.height,
211
+ signature: l.signature,
212
+ pubkey: l.pubkey,
213
+ pendingBuy: l.pending_buy ? {
214
+ buyer: l.pending_buy.buyer_ua,
215
+ price: l.pending_buy.price,
216
+ claimHeight: l.pending_buy.claim_height,
217
+ expiresAt: l.pending_buy.expires_at,
218
+ txid: l.pending_buy.txid
219
+ } : void 0
220
+ })),
221
+ total: result.total
222
+ };
118
223
  }
119
224
  async events(filter) {
120
- return this.rpc(
225
+ const raw = await this.rpc(
121
226
  "events",
122
- filter ?? {}
227
+ toEventsFilter(filter ?? {})
123
228
  );
229
+ return toEventsResult(raw);
124
230
  }
125
231
  /**
126
232
  * Verify a listing's signature.
@@ -130,7 +236,7 @@ var ZNS = class {
130
236
  */
131
237
  async verifyListing(listing, adminPubkey) {
132
238
  const pubkey = listing.pubkey ?? adminPubkey;
133
- const payload = `LIST:${listing.name}:${listing.price}:${listing.pay_taddr}:${listing.nonce}`;
239
+ const payload = `LIST:${listing.name}:${listing.price}:${listing.payTaddr}:${listing.nonce}`;
134
240
  return this.verifyEd25519(payload, listing.signature, pubkey);
135
241
  }
136
242
  /**
@@ -320,16 +426,16 @@ var ZNS = class {
320
426
  }
321
427
  };
322
428
  }
323
- prepareList(name, price, pay_taddr, nonce) {
429
+ prepareList(name, price, payTaddr, nonce) {
324
430
  this.requireValidName(name);
325
431
  return {
326
432
  name,
327
433
  price,
328
- pay_taddr,
434
+ payTaddr,
329
435
  nonce,
330
- payload: `LIST:${name}:${price}:${pay_taddr}:${nonce}`,
436
+ payload: `LIST:${name}:${price}:${payTaddr}:${nonce}`,
331
437
  complete: (signature, userPubkey) => {
332
- const memo = userPubkey ? `ZNS:LIST:${name}:${price}:${pay_taddr}:${nonce}:${signature}:${userPubkey}` : `ZNS:LIST:${name}:${price}:${pay_taddr}:${nonce}:${signature}`;
438
+ const memo = userPubkey ? `ZNS:LIST:${name}:${price}:${payTaddr}:${nonce}:${signature}:${userPubkey}` : `ZNS:LIST:${name}:${price}:${payTaddr}:${nonce}:${signature}`;
333
439
  return { memo, uri: this.buildZcashUri(this.registryAddress, LIST_COMMISSION, memo) };
334
440
  }
335
441
  };
@@ -403,7 +509,7 @@ var ZNS = class {
403
509
  }
404
510
  // ── Private helpers ────────────────────────────────────────────────────────
405
511
  registrationPayload(reg) {
406
- switch (reg.last_action) {
512
+ switch (reg.lastAction) {
407
513
  case "CLAIM":
408
514
  return `CLAIM:${reg.name}:${reg.address}`;
409
515
  case "BUY":
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "zcashname-sdk",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
- "description": "TypeScript SDK for the Zcash Name System (ZNS)",
5
+ "description": "TypeScript SDK for the Zcash Name System (ZNS).",
6
6
  "main": "dist/zns.cjs",
7
7
  "module": "dist/zns.js",
8
8
  "types": "dist/zns.d.ts",