zcashname-sdk 0.3.0 → 0.4.0

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.
@@ -0,0 +1,99 @@
1
+ // src/errors.ts
2
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
3
+ ErrorType2[ErrorType2["ParseError"] = -32700] = "ParseError";
4
+ ErrorType2[ErrorType2["InvalidRequest"] = -32600] = "InvalidRequest";
5
+ ErrorType2[ErrorType2["MethodNotFound"] = -32601] = "MethodNotFound";
6
+ ErrorType2[ErrorType2["InvalidParams"] = -32602] = "InvalidParams";
7
+ ErrorType2[ErrorType2["InternalError"] = -32603] = "InternalError";
8
+ ErrorType2[ErrorType2["HttpError"] = -1] = "HttpError";
9
+ ErrorType2[ErrorType2["UivkMismatch"] = -2] = "UivkMismatch";
10
+ return ErrorType2;
11
+ })(ErrorType || {});
12
+ var ZNSError = class extends Error {
13
+ constructor(type, message) {
14
+ super(message ?? ErrorType[type]);
15
+ this.name = "ZNSError";
16
+ this.type = type;
17
+ }
18
+ };
19
+
20
+ // src/constants.ts
21
+ var DEFAULT_URL = "https://light.zcash.me/zns-testnet";
22
+ var TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
23
+ var MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
24
+ var KNOWN_UIVKS = [TESTNET_UIVK, MAINNET_UIVK];
25
+
26
+ // src/rpc.ts
27
+ async function rpc(url, method, params = {}, id = 1) {
28
+ const body = JSON.stringify({ jsonrpc: "2.0", id, method, params });
29
+ const res = await fetch(url, {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json" },
32
+ body
33
+ });
34
+ if (!res.ok) {
35
+ throw new ZNSError(-1 /* HttpError */, `HTTP ${res.status}: ${res.statusText}`);
36
+ }
37
+ const json = await res.json();
38
+ if (json.error) {
39
+ const type = Object.values(ErrorType).includes(json.error.code) ? json.error.code : -32603 /* InternalError */;
40
+ throw new ZNSError(type, json.error.message);
41
+ }
42
+ return json.result;
43
+ }
44
+
45
+ // src/client.ts
46
+ async function createClient(url = DEFAULT_URL, options = {}) {
47
+ let nextId = 1;
48
+ let verified = false;
49
+ async function call(method, params = {}) {
50
+ return rpc(url, method, params, nextId++);
51
+ }
52
+ if (!options.skipVerify) {
53
+ const s = await call("status");
54
+ if (!KNOWN_UIVKS.includes(s.uivk)) {
55
+ throw new ZNSError(
56
+ -2 /* UivkMismatch */,
57
+ `UIVK mismatch: indexer returned "${s.uivk.slice(0, 20)}..." which is not a known ZNS instance`
58
+ );
59
+ }
60
+ verified = true;
61
+ }
62
+ const client = {
63
+ url,
64
+ verified,
65
+ async resolve(query) {
66
+ return call("resolve", { query });
67
+ },
68
+ async listings() {
69
+ const result = await call("list_for_sale");
70
+ return result.listings;
71
+ },
72
+ async status() {
73
+ return call("status");
74
+ },
75
+ async isAvailable(name) {
76
+ const result = await client.resolve(name);
77
+ return result === null;
78
+ },
79
+ async events(filter = {}) {
80
+ return call("events", filter);
81
+ },
82
+ async getNonce(name) {
83
+ const result = await client.resolve(name);
84
+ if (result === null || Array.isArray(result)) return null;
85
+ return result.nonce;
86
+ }
87
+ };
88
+ return client;
89
+ }
90
+
91
+ export {
92
+ ErrorType,
93
+ ZNSError,
94
+ DEFAULT_URL,
95
+ TESTNET_UIVK,
96
+ MAINNET_UIVK,
97
+ KNOWN_UIVKS,
98
+ createClient
99
+ };
@@ -0,0 +1,76 @@
1
+ interface Registration {
2
+ name: string;
3
+ address: string;
4
+ txid: string;
5
+ height: number;
6
+ nonce: number;
7
+ signature: string | null;
8
+ }
9
+ interface Listing {
10
+ name: string;
11
+ price: number;
12
+ txid: string;
13
+ height: number;
14
+ signature: string;
15
+ }
16
+ interface ResolveResult extends Registration {
17
+ listing: Listing | null;
18
+ }
19
+ interface ListForSaleResult {
20
+ listings: Listing[];
21
+ }
22
+ interface Pricing {
23
+ nonce: number;
24
+ height: number;
25
+ /** Per-character claim prices in zats.
26
+ * Index 0 = 1-char names, index 1 = 2-char, etc.
27
+ * Names longer than the array clamp to the last entry. */
28
+ tiers: number[];
29
+ }
30
+ interface StatusResult {
31
+ synced_height: number;
32
+ admin_pubkey: string;
33
+ uivk: string;
34
+ registered: number;
35
+ listed: number;
36
+ pricing: Pricing | null;
37
+ }
38
+ interface Event {
39
+ id: number;
40
+ name: string;
41
+ action: "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
42
+ txid: string;
43
+ height: number;
44
+ ua: string | null;
45
+ price: number | null;
46
+ nonce: number | null;
47
+ signature: string | null;
48
+ }
49
+ interface EventsFilter {
50
+ name?: string;
51
+ action?: string;
52
+ since_height?: number;
53
+ limit?: number;
54
+ offset?: number;
55
+ }
56
+ interface EventsResult {
57
+ events: Event[];
58
+ total: number;
59
+ }
60
+
61
+ interface ClientOptions {
62
+ skipVerify?: boolean;
63
+ }
64
+ interface ZNSClient {
65
+ readonly url: string;
66
+ readonly verified: boolean;
67
+ resolve(query: string): Promise<ResolveResult | ResolveResult[] | null>;
68
+ listings(): Promise<Listing[]>;
69
+ status(): Promise<StatusResult>;
70
+ events(filter?: EventsFilter): Promise<EventsResult>;
71
+ isAvailable(name: string): Promise<boolean>;
72
+ getNonce(name: string): Promise<number | null>;
73
+ }
74
+ declare function createClient(url?: string, options?: ClientOptions): Promise<ZNSClient>;
75
+
76
+ export { type ClientOptions as C, type Event as E, type ListForSaleResult as L, type Pricing as P, type Registration as R, type StatusResult as S, type ZNSClient as Z, type EventsFilter as a, type EventsResult as b, type Listing as c, type ResolveResult as d, createClient as e };
@@ -0,0 +1,76 @@
1
+ interface Registration {
2
+ name: string;
3
+ address: string;
4
+ txid: string;
5
+ height: number;
6
+ nonce: number;
7
+ signature: string | null;
8
+ }
9
+ interface Listing {
10
+ name: string;
11
+ price: number;
12
+ txid: string;
13
+ height: number;
14
+ signature: string;
15
+ }
16
+ interface ResolveResult extends Registration {
17
+ listing: Listing | null;
18
+ }
19
+ interface ListForSaleResult {
20
+ listings: Listing[];
21
+ }
22
+ interface Pricing {
23
+ nonce: number;
24
+ height: number;
25
+ /** Per-character claim prices in zats.
26
+ * Index 0 = 1-char names, index 1 = 2-char, etc.
27
+ * Names longer than the array clamp to the last entry. */
28
+ tiers: number[];
29
+ }
30
+ interface StatusResult {
31
+ synced_height: number;
32
+ admin_pubkey: string;
33
+ uivk: string;
34
+ registered: number;
35
+ listed: number;
36
+ pricing: Pricing | null;
37
+ }
38
+ interface Event {
39
+ id: number;
40
+ name: string;
41
+ action: "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
42
+ txid: string;
43
+ height: number;
44
+ ua: string | null;
45
+ price: number | null;
46
+ nonce: number | null;
47
+ signature: string | null;
48
+ }
49
+ interface EventsFilter {
50
+ name?: string;
51
+ action?: string;
52
+ since_height?: number;
53
+ limit?: number;
54
+ offset?: number;
55
+ }
56
+ interface EventsResult {
57
+ events: Event[];
58
+ total: number;
59
+ }
60
+
61
+ interface ClientOptions {
62
+ skipVerify?: boolean;
63
+ }
64
+ interface ZNSClient {
65
+ readonly url: string;
66
+ readonly verified: boolean;
67
+ resolve(query: string): Promise<ResolveResult | ResolveResult[] | null>;
68
+ listings(): Promise<Listing[]>;
69
+ status(): Promise<StatusResult>;
70
+ events(filter?: EventsFilter): Promise<EventsResult>;
71
+ isAvailable(name: string): Promise<boolean>;
72
+ getNonce(name: string): Promise<number | null>;
73
+ }
74
+ declare function createClient(url?: string, options?: ClientOptions): Promise<ZNSClient>;
75
+
76
+ export { type ClientOptions as C, type Event as E, type ListForSaleResult as L, type Pricing as P, type Registration as R, type StatusResult as S, type ZNSClient as Z, type EventsFilter as a, type EventsResult as b, type Listing as c, type ResolveResult as d, createClient as e };
package/dist/client.cjs CHANGED
@@ -107,7 +107,8 @@ async function createClient(url = DEFAULT_URL, options = {}) {
107
107
  },
108
108
  async getNonce(name) {
109
109
  const result = await client.resolve(name);
110
- return result?.nonce ?? null;
110
+ if (result === null || Array.isArray(result)) return null;
111
+ return result.nonce;
111
112
  }
112
113
  };
113
114
  return client;
package/dist/client.d.cts CHANGED
@@ -1 +1 @@
1
- export { C as ClientOptions, Z as ZNSClient, e as createClient } from './client-N6gdk287.cjs';
1
+ export { C as ClientOptions, Z as ZNSClient, e as createClient } from './client-CDXyVte9.cjs';
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { C as ClientOptions, Z as ZNSClient, e as createClient } from './client-N6gdk287.js';
1
+ export { C as ClientOptions, Z as ZNSClient, e as createClient } from './client-CDXyVte9.js';
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createClient
3
- } from "./chunk-E3JAIK65.js";
3
+ } from "./chunk-WTD2EDLN.js";
4
4
  export {
5
5
  createClient
6
6
  };
package/dist/index.cjs CHANGED
@@ -136,7 +136,8 @@ async function createClient(url = DEFAULT_URL, options = {}) {
136
136
  },
137
137
  async getNonce(name) {
138
138
  const result = await client.resolve(name);
139
- return result?.nonce ?? null;
139
+ if (result === null || Array.isArray(result)) return null;
140
+ return result.nonce;
140
141
  }
141
142
  };
142
143
  return client;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as ClientOptions, E as Event, a as EventsFilter, b as EventsResult, L as ListForSaleResult, c as Listing, P as Pricing, R as Registration, d as ResolveResult, S as StatusResult, Z as ZNSClient, e as createClient } from './client-N6gdk287.cjs';
1
+ export { C as ClientOptions, E as Event, a as EventsFilter, b as EventsResult, L as ListForSaleResult, c as Listing, P as Pricing, R as Registration, d as ResolveResult, S as StatusResult, Z as ZNSClient, e as createClient } from './client-CDXyVte9.cjs';
2
2
  export { isValidName } from './validation.cjs';
3
3
  export { claimCost } from './pricing.cjs';
4
4
  export { buildBuyMemo, buildClaimMemo, buildDelistMemo, buildListMemo, buildSetPriceMemo, buildUpdateMemo, buyPayload, claimPayload, delistPayload, listPayload, setPricePayload, updatePayload } from './memo.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as ClientOptions, E as Event, a as EventsFilter, b as EventsResult, L as ListForSaleResult, c as Listing, P as Pricing, R as Registration, d as ResolveResult, S as StatusResult, Z as ZNSClient, e as createClient } from './client-N6gdk287.js';
1
+ export { C as ClientOptions, E as Event, a as EventsFilter, b as EventsResult, L as ListForSaleResult, c as Listing, P as Pricing, R as Registration, d as ResolveResult, S as StatusResult, Z as ZNSClient, e as createClient } from './client-CDXyVte9.js';
2
2
  export { isValidName } from './validation.js';
3
3
  export { claimCost } from './pricing.js';
4
4
  export { buildBuyMemo, buildClaimMemo, buildDelistMemo, buildListMemo, buildSetPriceMemo, buildUpdateMemo, buyPayload, claimPayload, delistPayload, listPayload, setPricePayload, updatePayload } from './memo.js';
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  TESTNET_UIVK,
7
7
  ZNSError,
8
8
  createClient
9
- } from "./chunk-E3JAIK65.js";
9
+ } from "./chunk-WTD2EDLN.js";
10
10
  import {
11
11
  buildBuyMemo,
12
12
  buildClaimMemo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcashname-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Zcash Name System (ZNS) JSON-RPC API",
6
6
  "main": "dist/index.cjs",