zcashname-sdk 0.4.0 → 0.5.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.
- package/dist/zns.cjs +327 -0
- package/dist/zns.d.cts +140 -0
- package/dist/zns.d.ts +140 -0
- package/dist/zns.js +299 -0
- package/package.json +10 -35
- package/dist/chunk-4UY7KDYN.js +0 -61
- package/dist/chunk-E3JAIK65.js +0 -98
- package/dist/chunk-QBUZYA7S.js +0 -45
- package/dist/chunk-QQCGKLYR.js +0 -10
- package/dist/chunk-TNP4GYNO.js +0 -8
- package/dist/chunk-WTD2EDLN.js +0 -99
- package/dist/client-CDXyVte9.d.cts +0 -76
- package/dist/client-CDXyVte9.d.ts +0 -76
- package/dist/client-N6gdk287.d.cts +0 -76
- package/dist/client-N6gdk287.d.ts +0 -76
- package/dist/client.cjs +0 -119
- package/dist/client.d.cts +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -6
- package/dist/index.cjs +0 -261
- package/dist/index.d.cts +0 -26
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -62
- package/dist/memo.cjs +0 -99
- package/dist/memo.d.cts +0 -14
- package/dist/memo.d.ts +0 -14
- package/dist/memo.js +0 -29
- package/dist/pricing.cjs +0 -34
- package/dist/pricing.d.cts +0 -12
- package/dist/pricing.d.ts +0 -12
- package/dist/pricing.js +0 -6
- package/dist/validation.cjs +0 -32
- package/dist/validation.d.cts +0 -3
- package/dist/validation.d.ts +0 -3
- package/dist/validation.js +0 -6
- package/dist/zip321.cjs +0 -72
- package/dist/zip321.d.cts +0 -12
- package/dist/zip321.d.ts +0 -12
- package/dist/zip321.js +0 -12
package/dist/zns.cjs
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/zns.ts
|
|
21
|
+
var zns_exports = {};
|
|
22
|
+
__export(zns_exports, {
|
|
23
|
+
DEFAULT_URL: () => DEFAULT_URL,
|
|
24
|
+
MAINNET_UIVK: () => MAINNET_UIVK,
|
|
25
|
+
TESTNET_UIVK: () => TESTNET_UIVK,
|
|
26
|
+
ZNS: () => ZNS
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(zns_exports);
|
|
29
|
+
var DEFAULT_URL = "https://light.zcash.me/zns-testnet";
|
|
30
|
+
var TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
|
|
31
|
+
var MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
|
|
32
|
+
var KNOWN_UIVKS = [TESTNET_UIVK, MAINNET_UIVK];
|
|
33
|
+
var NAME_RE = /^[a-z0-9]{1,62}$/;
|
|
34
|
+
var ZNS = class _ZNS {
|
|
35
|
+
constructor(url) {
|
|
36
|
+
this.rpcId = 0;
|
|
37
|
+
this._adminPubkey = null;
|
|
38
|
+
this._pricing = null;
|
|
39
|
+
this._registryAddress = null;
|
|
40
|
+
this._verified = false;
|
|
41
|
+
this.url = url;
|
|
42
|
+
}
|
|
43
|
+
static async create(options) {
|
|
44
|
+
const url = options?.url ?? DEFAULT_URL;
|
|
45
|
+
const zns = new _ZNS(url);
|
|
46
|
+
const status = await zns.rpc("status");
|
|
47
|
+
if (!options?.skipVerify) {
|
|
48
|
+
if (!KNOWN_UIVKS.includes(status.uivk)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`UIVK mismatch: indexer returned "${status.uivk.slice(0, 20)}..." which is not a known ZNS instance`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
zns._verified = true;
|
|
54
|
+
}
|
|
55
|
+
zns.pinStatus(status);
|
|
56
|
+
return zns;
|
|
57
|
+
}
|
|
58
|
+
pinStatus(status) {
|
|
59
|
+
this._adminPubkey = status.admin_pubkey;
|
|
60
|
+
this._pricing = status.pricing;
|
|
61
|
+
this._registryAddress = status.address;
|
|
62
|
+
}
|
|
63
|
+
get verified() {
|
|
64
|
+
return this._verified;
|
|
65
|
+
}
|
|
66
|
+
get adminPubkey() {
|
|
67
|
+
return this._adminPubkey;
|
|
68
|
+
}
|
|
69
|
+
get pricing() {
|
|
70
|
+
return this._pricing;
|
|
71
|
+
}
|
|
72
|
+
get registryAddress() {
|
|
73
|
+
return this._registryAddress;
|
|
74
|
+
}
|
|
75
|
+
async resolve(query) {
|
|
76
|
+
const raw = await this.rpc("resolve", { query });
|
|
77
|
+
if (raw === null) return null;
|
|
78
|
+
if (Array.isArray(raw)) {
|
|
79
|
+
const results = [];
|
|
80
|
+
for (const r of raw) results.push(await this.enrichRegistration(r));
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
return this.enrichRegistration(raw);
|
|
84
|
+
}
|
|
85
|
+
async isAvailable(name) {
|
|
86
|
+
const result = await this.resolve(name);
|
|
87
|
+
return result === null;
|
|
88
|
+
}
|
|
89
|
+
async listings() {
|
|
90
|
+
const result = await this.rpc("list_for_sale");
|
|
91
|
+
const enriched = [];
|
|
92
|
+
for (const l of result.listings) enriched.push(await this.enrichListing(l));
|
|
93
|
+
return enriched;
|
|
94
|
+
}
|
|
95
|
+
async status() {
|
|
96
|
+
return this.rpc("status");
|
|
97
|
+
}
|
|
98
|
+
async events(filter) {
|
|
99
|
+
const result = await this.rpc("events", filter ?? {});
|
|
100
|
+
const enriched = [];
|
|
101
|
+
for (const e of result.events) enriched.push(await this.enrichEvent(e));
|
|
102
|
+
return { events: enriched, total: result.total };
|
|
103
|
+
}
|
|
104
|
+
prepareClaim(name, address) {
|
|
105
|
+
this.requireValidName(name);
|
|
106
|
+
const payload = `CLAIM:${name}:${address}`;
|
|
107
|
+
const cost = this.claimCost(name.length);
|
|
108
|
+
const uri = cost != null && this._registryAddress ? this.buildZcashUri(this._registryAddress, cost / 1e8) : void 0;
|
|
109
|
+
return { payload, cost: cost ?? void 0, uri };
|
|
110
|
+
}
|
|
111
|
+
completeClaim(name, address, signature, userPubkey) {
|
|
112
|
+
this.requireValidName(name);
|
|
113
|
+
const memo = userPubkey ? `ZNS:CLAIM:${name}:${address}:${signature}:${userPubkey}` : `ZNS:CLAIM:${name}:${address}:${signature}`;
|
|
114
|
+
const cost = this.claimCost(name.length);
|
|
115
|
+
const uri = this.buildZcashUri(this._registryAddress ?? "", cost != null ? cost / 1e8 : void 0, memo);
|
|
116
|
+
return { memo, uri };
|
|
117
|
+
}
|
|
118
|
+
prepareList(name, price, nonce) {
|
|
119
|
+
this.requireValidName(name);
|
|
120
|
+
return { payload: `LIST:${name}:${price}:${nonce}` };
|
|
121
|
+
}
|
|
122
|
+
completeList(name, price, nonce, signature, userPubkey) {
|
|
123
|
+
this.requireValidName(name);
|
|
124
|
+
const memo = userPubkey ? `ZNS:LIST:${name}:${price}:${nonce}:${signature}:${userPubkey}` : `ZNS:LIST:${name}:${price}:${nonce}:${signature}`;
|
|
125
|
+
return { memo, uri: this.memoUri(memo) };
|
|
126
|
+
}
|
|
127
|
+
prepareDelist(name, nonce) {
|
|
128
|
+
this.requireValidName(name);
|
|
129
|
+
return { payload: `DELIST:${name}:${nonce}` };
|
|
130
|
+
}
|
|
131
|
+
completeDelist(name, nonce, signature, userPubkey) {
|
|
132
|
+
this.requireValidName(name);
|
|
133
|
+
const memo = userPubkey ? `ZNS:DELIST:${name}:${nonce}:${signature}:${userPubkey}` : `ZNS:DELIST:${name}:${nonce}:${signature}`;
|
|
134
|
+
return { memo, uri: this.memoUri(memo) };
|
|
135
|
+
}
|
|
136
|
+
prepareUpdate(name, newAddress, nonce) {
|
|
137
|
+
this.requireValidName(name);
|
|
138
|
+
return { payload: `UPDATE:${name}:${newAddress}:${nonce}` };
|
|
139
|
+
}
|
|
140
|
+
completeUpdate(name, newAddress, nonce, signature, userPubkey) {
|
|
141
|
+
this.requireValidName(name);
|
|
142
|
+
const memo = userPubkey ? `ZNS:UPDATE:${name}:${newAddress}:${nonce}:${signature}:${userPubkey}` : `ZNS:UPDATE:${name}:${newAddress}:${nonce}:${signature}`;
|
|
143
|
+
return { memo, uri: this.memoUri(memo) };
|
|
144
|
+
}
|
|
145
|
+
prepareBuy(name, buyerAddress) {
|
|
146
|
+
this.requireValidName(name);
|
|
147
|
+
return { payload: `BUY:${name}:${buyerAddress}` };
|
|
148
|
+
}
|
|
149
|
+
completeBuy(name, buyerAddress, signature, userPubkey) {
|
|
150
|
+
this.requireValidName(name);
|
|
151
|
+
const memo = userPubkey ? `ZNS:BUY:${name}:${buyerAddress}:${signature}:${userPubkey}` : `ZNS:BUY:${name}:${buyerAddress}:${signature}`;
|
|
152
|
+
return { memo, uri: this.memoUri(memo) };
|
|
153
|
+
}
|
|
154
|
+
prepareRelease(name, nonce) {
|
|
155
|
+
this.requireValidName(name);
|
|
156
|
+
return { payload: `RELEASE:${name}:${nonce}` };
|
|
157
|
+
}
|
|
158
|
+
completeRelease(name, nonce, signature, userPubkey) {
|
|
159
|
+
this.requireValidName(name);
|
|
160
|
+
const memo = userPubkey ? `ZNS:RELEASE:${name}:${nonce}:${signature}:${userPubkey}` : `ZNS:RELEASE:${name}:${nonce}:${signature}`;
|
|
161
|
+
return { memo, uri: this.memoUri(memo) };
|
|
162
|
+
}
|
|
163
|
+
prepareSetPrice(prices, nonce) {
|
|
164
|
+
return { payload: `SETPRICE:${prices.length}:${prices.join(":")}:${nonce}` };
|
|
165
|
+
}
|
|
166
|
+
completeSetPrice(prices, nonce, signature) {
|
|
167
|
+
const memo = `ZNS:SETPRICE:${prices.length}:${prices.join(":")}:${nonce}:${signature}`;
|
|
168
|
+
return { memo, uri: this.memoUri(memo) };
|
|
169
|
+
}
|
|
170
|
+
isValidName(name) {
|
|
171
|
+
return NAME_RE.test(name);
|
|
172
|
+
}
|
|
173
|
+
claimCost(nameLength) {
|
|
174
|
+
if (!this._pricing || this._pricing.tiers.length === 0) return null;
|
|
175
|
+
const idx = Math.min(Math.max(nameLength - 1, 0), this._pricing.tiers.length - 1);
|
|
176
|
+
return this._pricing.tiers[idx];
|
|
177
|
+
}
|
|
178
|
+
parseZip321Uri(uri) {
|
|
179
|
+
const withoutScheme = String(uri ?? "").replace(/^zcash:/i, "");
|
|
180
|
+
const [addressPart, queryPart = ""] = withoutScheme.split("?");
|
|
181
|
+
const address = addressPart.trim();
|
|
182
|
+
const params = new URLSearchParams(queryPart);
|
|
183
|
+
const amount = String(params.get("amount") ?? "").trim();
|
|
184
|
+
const memoRaw = String(params.get("memo") ?? "").trim();
|
|
185
|
+
const memoDecoded = memoRaw ? this.decodeBase64Url(memoRaw) : "";
|
|
186
|
+
return { address, amount, memoRaw, memoDecoded };
|
|
187
|
+
}
|
|
188
|
+
async enrichRegistration(reg) {
|
|
189
|
+
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 };
|
|
199
|
+
}
|
|
200
|
+
async enrichListing(listing) {
|
|
201
|
+
let verified = false;
|
|
202
|
+
if (this._adminPubkey) {
|
|
203
|
+
const payload = this.listingPayload(listing);
|
|
204
|
+
verified = await this.verifyEd25519(payload, listing.signature, this._adminPubkey);
|
|
205
|
+
}
|
|
206
|
+
return { ...listing, verified };
|
|
207
|
+
}
|
|
208
|
+
async enrichEvent(event) {
|
|
209
|
+
if (!event.signature || !this._adminPubkey) return { ...event, verified: false };
|
|
210
|
+
const payload = this.eventPayload(event);
|
|
211
|
+
if (!payload) return { ...event, verified: false };
|
|
212
|
+
const pubkey = event.pubkey ?? this._adminPubkey;
|
|
213
|
+
const verified = await this.verifyEd25519(payload, event.signature, pubkey);
|
|
214
|
+
return { ...event, verified };
|
|
215
|
+
}
|
|
216
|
+
registrationPayload(reg) {
|
|
217
|
+
switch (reg.last_action) {
|
|
218
|
+
case "CLAIM":
|
|
219
|
+
return `CLAIM:${reg.name}:${reg.address}`;
|
|
220
|
+
case "BUY":
|
|
221
|
+
return `BUY:${reg.name}:${reg.address}`;
|
|
222
|
+
case "UPDATE":
|
|
223
|
+
return `UPDATE:${reg.name}:${reg.address}:${reg.nonce}`;
|
|
224
|
+
case "DELIST":
|
|
225
|
+
return `DELIST:${reg.name}:${reg.nonce}`;
|
|
226
|
+
case "RELEASE":
|
|
227
|
+
return `RELEASE:${reg.name}:${reg.nonce}`;
|
|
228
|
+
default:
|
|
229
|
+
return "";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
listingPayload(l) {
|
|
233
|
+
return `LIST:${l.name}:${l.price}:${l.nonce}`;
|
|
234
|
+
}
|
|
235
|
+
eventPayload(e) {
|
|
236
|
+
switch (e.action) {
|
|
237
|
+
case "CLAIM":
|
|
238
|
+
return e.ua ? `CLAIM:${e.name}:${e.ua}` : "";
|
|
239
|
+
case "BUY":
|
|
240
|
+
return e.ua ? `BUY:${e.name}:${e.ua}` : "";
|
|
241
|
+
case "LIST":
|
|
242
|
+
return e.price != null && e.nonce != null ? `LIST:${e.name}:${e.price}:${e.nonce}` : "";
|
|
243
|
+
case "DELIST":
|
|
244
|
+
return e.nonce != null ? `DELIST:${e.name}:${e.nonce}` : "";
|
|
245
|
+
case "RELEASE":
|
|
246
|
+
return e.nonce != null ? `RELEASE:${e.name}:${e.nonce}` : "";
|
|
247
|
+
case "UPDATE":
|
|
248
|
+
return e.ua && e.nonce != null ? `UPDATE:${e.name}:${e.ua}:${e.nonce}` : "";
|
|
249
|
+
default:
|
|
250
|
+
return "";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async verifyEd25519(payload, signatureB64, pubkeyB64) {
|
|
254
|
+
const sigBytes = this.decodeBase64(signatureB64);
|
|
255
|
+
const pkBytes = this.decodeBase64(pubkeyB64);
|
|
256
|
+
if (sigBytes.length !== 64 || pkBytes.length !== 32) return false;
|
|
257
|
+
try {
|
|
258
|
+
const key = await crypto.subtle.importKey("raw", pkBytes.buffer, { name: "Ed25519" }, false, ["verify"]);
|
|
259
|
+
return crypto.subtle.verify("Ed25519", key, sigBytes.buffer, new TextEncoder().encode(payload));
|
|
260
|
+
} catch {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
requireValidName(name) {
|
|
265
|
+
if (!NAME_RE.test(name)) throw new Error(`Invalid ZNS name: ${name}`);
|
|
266
|
+
}
|
|
267
|
+
memoUri(memo) {
|
|
268
|
+
return this._registryAddress ? this.buildZcashUri(this._registryAddress, void 0, memo) : `zcash:?memo=${this.toBase64Url(memo)}`;
|
|
269
|
+
}
|
|
270
|
+
buildZcashUri(address, amount, memo) {
|
|
271
|
+
if (!address) return "";
|
|
272
|
+
const base = `zcash:${address}`;
|
|
273
|
+
const params = [];
|
|
274
|
+
if (amount !== void 0 && amount > 0) params.push(`amount=${amount}`);
|
|
275
|
+
if (memo) params.push(`memo=${this.toBase64Url(memo)}`);
|
|
276
|
+
return params.length ? `${base}?${params.join("&")}` : base;
|
|
277
|
+
}
|
|
278
|
+
toBase64Url(text) {
|
|
279
|
+
try {
|
|
280
|
+
return btoa(unescape(encodeURIComponent(text))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
281
|
+
} catch {
|
|
282
|
+
return "";
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
decodeBase64Url(value) {
|
|
286
|
+
try {
|
|
287
|
+
const normalized = String(value).replace(/-/g, "+").replace(/_/g, "/");
|
|
288
|
+
const padLen = normalized.length % 4 === 0 ? 0 : 4 - normalized.length % 4;
|
|
289
|
+
const padded = normalized + "=".repeat(padLen);
|
|
290
|
+
const binary = atob(padded);
|
|
291
|
+
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
292
|
+
return new TextDecoder().decode(bytes);
|
|
293
|
+
} catch {
|
|
294
|
+
return "";
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
decodeBase64(s) {
|
|
298
|
+
const bin = atob(s);
|
|
299
|
+
const bytes = new Uint8Array(bin.length);
|
|
300
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
301
|
+
return bytes;
|
|
302
|
+
}
|
|
303
|
+
async rpc(method, params = {}) {
|
|
304
|
+
const id = ++this.rpcId;
|
|
305
|
+
const body = JSON.stringify({ jsonrpc: "2.0", id, method, params });
|
|
306
|
+
const res = await fetch(this.url, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
headers: { "Content-Type": "application/json" },
|
|
309
|
+
body
|
|
310
|
+
});
|
|
311
|
+
if (!res.ok) {
|
|
312
|
+
throw new Error(`ZNS HTTP ${res.status}: ${res.statusText}`);
|
|
313
|
+
}
|
|
314
|
+
const json = await res.json();
|
|
315
|
+
if (json.error) {
|
|
316
|
+
throw new Error(`ZNS RPC error ${json.error.code}: ${json.error.message}`);
|
|
317
|
+
}
|
|
318
|
+
return json.result;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
322
|
+
0 && (module.exports = {
|
|
323
|
+
DEFAULT_URL,
|
|
324
|
+
MAINNET_UIVK,
|
|
325
|
+
TESTNET_UIVK,
|
|
326
|
+
ZNS
|
|
327
|
+
});
|
package/dist/zns.d.cts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
interface Registration {
|
|
2
|
+
name: string;
|
|
3
|
+
address: string;
|
|
4
|
+
txid: string;
|
|
5
|
+
height: number;
|
|
6
|
+
nonce: number;
|
|
7
|
+
signature: string | null;
|
|
8
|
+
last_action: LastAction;
|
|
9
|
+
pubkey: string | null;
|
|
10
|
+
}
|
|
11
|
+
type LastAction = "CLAIM" | "BUY" | "UPDATE" | "DELIST" | "RELEASE";
|
|
12
|
+
interface Listing {
|
|
13
|
+
name: string;
|
|
14
|
+
price: number;
|
|
15
|
+
nonce: number;
|
|
16
|
+
txid: string;
|
|
17
|
+
height: number;
|
|
18
|
+
signature: string;
|
|
19
|
+
}
|
|
20
|
+
interface ResolveResult extends Registration {
|
|
21
|
+
listing: Listing | null;
|
|
22
|
+
verified: boolean;
|
|
23
|
+
sovereign: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface VerifiedListing extends Listing {
|
|
26
|
+
verified: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface Pricing {
|
|
29
|
+
nonce: number;
|
|
30
|
+
height: number;
|
|
31
|
+
tiers: number[];
|
|
32
|
+
}
|
|
33
|
+
interface StatusResult {
|
|
34
|
+
synced_height: number;
|
|
35
|
+
admin_pubkey: string;
|
|
36
|
+
uivk: string;
|
|
37
|
+
address: string;
|
|
38
|
+
registered: number;
|
|
39
|
+
listed: number;
|
|
40
|
+
pricing: Pricing | null;
|
|
41
|
+
}
|
|
42
|
+
interface Event {
|
|
43
|
+
id: number;
|
|
44
|
+
name: string;
|
|
45
|
+
action: Action;
|
|
46
|
+
txid: string;
|
|
47
|
+
height: number;
|
|
48
|
+
ua: string | null;
|
|
49
|
+
price: number | null;
|
|
50
|
+
nonce: number | null;
|
|
51
|
+
signature: string | null;
|
|
52
|
+
pubkey: string | null;
|
|
53
|
+
verified?: boolean;
|
|
54
|
+
}
|
|
55
|
+
type Action = "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
|
|
56
|
+
interface EventsFilter {
|
|
57
|
+
name?: string;
|
|
58
|
+
action?: string;
|
|
59
|
+
since_height?: number;
|
|
60
|
+
limit?: number;
|
|
61
|
+
offset?: number;
|
|
62
|
+
}
|
|
63
|
+
interface EventsResult {
|
|
64
|
+
events: Event[];
|
|
65
|
+
total: number;
|
|
66
|
+
}
|
|
67
|
+
interface PreparedAction {
|
|
68
|
+
payload: string;
|
|
69
|
+
cost?: number;
|
|
70
|
+
uri?: string;
|
|
71
|
+
}
|
|
72
|
+
interface CompletedAction {
|
|
73
|
+
memo: string;
|
|
74
|
+
uri: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare const DEFAULT_URL = "https://light.zcash.me/zns-testnet";
|
|
78
|
+
declare const TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
|
|
79
|
+
declare const MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
|
|
80
|
+
declare class ZNS {
|
|
81
|
+
private url;
|
|
82
|
+
private rpcId;
|
|
83
|
+
private _adminPubkey;
|
|
84
|
+
private _pricing;
|
|
85
|
+
private _registryAddress;
|
|
86
|
+
private _verified;
|
|
87
|
+
private constructor();
|
|
88
|
+
static create(options?: {
|
|
89
|
+
url?: string;
|
|
90
|
+
skipVerify?: boolean;
|
|
91
|
+
}): Promise<ZNS>;
|
|
92
|
+
private pinStatus;
|
|
93
|
+
get verified(): boolean;
|
|
94
|
+
get adminPubkey(): string | null;
|
|
95
|
+
get pricing(): Pricing | null;
|
|
96
|
+
get registryAddress(): string | null;
|
|
97
|
+
resolve(query: string): Promise<ResolveResult | ResolveResult[] | null>;
|
|
98
|
+
isAvailable(name: string): Promise<boolean>;
|
|
99
|
+
listings(): Promise<VerifiedListing[]>;
|
|
100
|
+
status(): Promise<StatusResult>;
|
|
101
|
+
events(filter?: EventsFilter): Promise<EventsResult>;
|
|
102
|
+
prepareClaim(name: string, address: string): PreparedAction;
|
|
103
|
+
completeClaim(name: string, address: string, signature: string, userPubkey?: string): CompletedAction;
|
|
104
|
+
prepareList(name: string, price: number, nonce: number): PreparedAction;
|
|
105
|
+
completeList(name: string, price: number, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
106
|
+
prepareDelist(name: string, nonce: number): PreparedAction;
|
|
107
|
+
completeDelist(name: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
108
|
+
prepareUpdate(name: string, newAddress: string, nonce: number): PreparedAction;
|
|
109
|
+
completeUpdate(name: string, newAddress: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
110
|
+
prepareBuy(name: string, buyerAddress: string): PreparedAction;
|
|
111
|
+
completeBuy(name: string, buyerAddress: string, signature: string, userPubkey?: string): CompletedAction;
|
|
112
|
+
prepareRelease(name: string, nonce: number): PreparedAction;
|
|
113
|
+
completeRelease(name: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
114
|
+
prepareSetPrice(prices: number[], nonce: number): PreparedAction;
|
|
115
|
+
completeSetPrice(prices: number[], nonce: number, signature: string): CompletedAction;
|
|
116
|
+
isValidName(name: string): boolean;
|
|
117
|
+
claimCost(nameLength: number): number | null;
|
|
118
|
+
parseZip321Uri(uri: string): {
|
|
119
|
+
address: string;
|
|
120
|
+
amount: string;
|
|
121
|
+
memoRaw: string;
|
|
122
|
+
memoDecoded: string;
|
|
123
|
+
};
|
|
124
|
+
private enrichRegistration;
|
|
125
|
+
private enrichListing;
|
|
126
|
+
private enrichEvent;
|
|
127
|
+
private registrationPayload;
|
|
128
|
+
private listingPayload;
|
|
129
|
+
private eventPayload;
|
|
130
|
+
private verifyEd25519;
|
|
131
|
+
private requireValidName;
|
|
132
|
+
private memoUri;
|
|
133
|
+
private buildZcashUri;
|
|
134
|
+
private toBase64Url;
|
|
135
|
+
private decodeBase64Url;
|
|
136
|
+
private decodeBase64;
|
|
137
|
+
private rpc;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { type Action, type CompletedAction, DEFAULT_URL, type Event, type EventsFilter, type EventsResult, type LastAction, type Listing, MAINNET_UIVK, type PreparedAction, type Pricing, type Registration, type ResolveResult, type StatusResult, TESTNET_UIVK, type VerifiedListing, ZNS };
|
package/dist/zns.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
interface Registration {
|
|
2
|
+
name: string;
|
|
3
|
+
address: string;
|
|
4
|
+
txid: string;
|
|
5
|
+
height: number;
|
|
6
|
+
nonce: number;
|
|
7
|
+
signature: string | null;
|
|
8
|
+
last_action: LastAction;
|
|
9
|
+
pubkey: string | null;
|
|
10
|
+
}
|
|
11
|
+
type LastAction = "CLAIM" | "BUY" | "UPDATE" | "DELIST" | "RELEASE";
|
|
12
|
+
interface Listing {
|
|
13
|
+
name: string;
|
|
14
|
+
price: number;
|
|
15
|
+
nonce: number;
|
|
16
|
+
txid: string;
|
|
17
|
+
height: number;
|
|
18
|
+
signature: string;
|
|
19
|
+
}
|
|
20
|
+
interface ResolveResult extends Registration {
|
|
21
|
+
listing: Listing | null;
|
|
22
|
+
verified: boolean;
|
|
23
|
+
sovereign: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface VerifiedListing extends Listing {
|
|
26
|
+
verified: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface Pricing {
|
|
29
|
+
nonce: number;
|
|
30
|
+
height: number;
|
|
31
|
+
tiers: number[];
|
|
32
|
+
}
|
|
33
|
+
interface StatusResult {
|
|
34
|
+
synced_height: number;
|
|
35
|
+
admin_pubkey: string;
|
|
36
|
+
uivk: string;
|
|
37
|
+
address: string;
|
|
38
|
+
registered: number;
|
|
39
|
+
listed: number;
|
|
40
|
+
pricing: Pricing | null;
|
|
41
|
+
}
|
|
42
|
+
interface Event {
|
|
43
|
+
id: number;
|
|
44
|
+
name: string;
|
|
45
|
+
action: Action;
|
|
46
|
+
txid: string;
|
|
47
|
+
height: number;
|
|
48
|
+
ua: string | null;
|
|
49
|
+
price: number | null;
|
|
50
|
+
nonce: number | null;
|
|
51
|
+
signature: string | null;
|
|
52
|
+
pubkey: string | null;
|
|
53
|
+
verified?: boolean;
|
|
54
|
+
}
|
|
55
|
+
type Action = "CLAIM" | "LIST" | "DELIST" | "RELEASE" | "UPDATE" | "BUY" | "SETPRICE";
|
|
56
|
+
interface EventsFilter {
|
|
57
|
+
name?: string;
|
|
58
|
+
action?: string;
|
|
59
|
+
since_height?: number;
|
|
60
|
+
limit?: number;
|
|
61
|
+
offset?: number;
|
|
62
|
+
}
|
|
63
|
+
interface EventsResult {
|
|
64
|
+
events: Event[];
|
|
65
|
+
total: number;
|
|
66
|
+
}
|
|
67
|
+
interface PreparedAction {
|
|
68
|
+
payload: string;
|
|
69
|
+
cost?: number;
|
|
70
|
+
uri?: string;
|
|
71
|
+
}
|
|
72
|
+
interface CompletedAction {
|
|
73
|
+
memo: string;
|
|
74
|
+
uri: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare const DEFAULT_URL = "https://light.zcash.me/zns-testnet";
|
|
78
|
+
declare const TESTNET_UIVK = "uivktest1hzw7wyadutvzfgpna80yftsk5l7jeyu2p5me5quvp28tytxueta00cx4068wnlzcv7tx9n3t3gfhsy83pe4y6jrhxtzaq0hj6xtg5zrk2dn7zen3vns2a5pgs4fxdjlletmqrhfa42";
|
|
79
|
+
declare const MAINNET_UIVK = "uivk1gl26qy0xjja7lqhyg3pf0x4j4j66kqwewrjkdcg28eqq4wgtzjmujpee7x9cs2ec9xhnlgrm8ptlw8z80j2aryw8nqtssser2ys778a0s00uvgkdjnfr58sndhfvc3f4zqjs6ywva6";
|
|
80
|
+
declare class ZNS {
|
|
81
|
+
private url;
|
|
82
|
+
private rpcId;
|
|
83
|
+
private _adminPubkey;
|
|
84
|
+
private _pricing;
|
|
85
|
+
private _registryAddress;
|
|
86
|
+
private _verified;
|
|
87
|
+
private constructor();
|
|
88
|
+
static create(options?: {
|
|
89
|
+
url?: string;
|
|
90
|
+
skipVerify?: boolean;
|
|
91
|
+
}): Promise<ZNS>;
|
|
92
|
+
private pinStatus;
|
|
93
|
+
get verified(): boolean;
|
|
94
|
+
get adminPubkey(): string | null;
|
|
95
|
+
get pricing(): Pricing | null;
|
|
96
|
+
get registryAddress(): string | null;
|
|
97
|
+
resolve(query: string): Promise<ResolveResult | ResolveResult[] | null>;
|
|
98
|
+
isAvailable(name: string): Promise<boolean>;
|
|
99
|
+
listings(): Promise<VerifiedListing[]>;
|
|
100
|
+
status(): Promise<StatusResult>;
|
|
101
|
+
events(filter?: EventsFilter): Promise<EventsResult>;
|
|
102
|
+
prepareClaim(name: string, address: string): PreparedAction;
|
|
103
|
+
completeClaim(name: string, address: string, signature: string, userPubkey?: string): CompletedAction;
|
|
104
|
+
prepareList(name: string, price: number, nonce: number): PreparedAction;
|
|
105
|
+
completeList(name: string, price: number, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
106
|
+
prepareDelist(name: string, nonce: number): PreparedAction;
|
|
107
|
+
completeDelist(name: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
108
|
+
prepareUpdate(name: string, newAddress: string, nonce: number): PreparedAction;
|
|
109
|
+
completeUpdate(name: string, newAddress: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
110
|
+
prepareBuy(name: string, buyerAddress: string): PreparedAction;
|
|
111
|
+
completeBuy(name: string, buyerAddress: string, signature: string, userPubkey?: string): CompletedAction;
|
|
112
|
+
prepareRelease(name: string, nonce: number): PreparedAction;
|
|
113
|
+
completeRelease(name: string, nonce: number, signature: string, userPubkey?: string): CompletedAction;
|
|
114
|
+
prepareSetPrice(prices: number[], nonce: number): PreparedAction;
|
|
115
|
+
completeSetPrice(prices: number[], nonce: number, signature: string): CompletedAction;
|
|
116
|
+
isValidName(name: string): boolean;
|
|
117
|
+
claimCost(nameLength: number): number | null;
|
|
118
|
+
parseZip321Uri(uri: string): {
|
|
119
|
+
address: string;
|
|
120
|
+
amount: string;
|
|
121
|
+
memoRaw: string;
|
|
122
|
+
memoDecoded: string;
|
|
123
|
+
};
|
|
124
|
+
private enrichRegistration;
|
|
125
|
+
private enrichListing;
|
|
126
|
+
private enrichEvent;
|
|
127
|
+
private registrationPayload;
|
|
128
|
+
private listingPayload;
|
|
129
|
+
private eventPayload;
|
|
130
|
+
private verifyEd25519;
|
|
131
|
+
private requireValidName;
|
|
132
|
+
private memoUri;
|
|
133
|
+
private buildZcashUri;
|
|
134
|
+
private toBase64Url;
|
|
135
|
+
private decodeBase64Url;
|
|
136
|
+
private decodeBase64;
|
|
137
|
+
private rpc;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { type Action, type CompletedAction, DEFAULT_URL, type Event, type EventsFilter, type EventsResult, type LastAction, type Listing, MAINNET_UIVK, type PreparedAction, type Pricing, type Registration, type ResolveResult, type StatusResult, TESTNET_UIVK, type VerifiedListing, ZNS };
|