@bonfida/spl-name-service 0.2.4 → 0.2.5

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.
@@ -1,186 +0,0 @@
1
- import { Connection, PublicKey, MemcmpFilter } from "@solana/web3.js";
2
- import BN from "bn.js";
3
- import { sha256 } from "@ethersproject/sha2";
4
- import {
5
- HASH_PREFIX,
6
- NAME_PROGRAM_ID,
7
- ROOT_DOMAIN_ACCOUNT,
8
- } from "../constants";
9
- import { NameRegistryState } from "../state";
10
- import { REVERSE_LOOKUP_CLASS } from "../constants";
11
-
12
- /**
13
- * @deprecated Use {@link resolve} instead
14
- */
15
- export async function getNameOwner(
16
- connection: Connection,
17
- nameAccountKey: PublicKey
18
- ) {
19
- const nameAccount = await connection.getAccountInfo(nameAccountKey);
20
- if (!nameAccount) {
21
- throw new Error("Unable to find the given account.");
22
- }
23
- return NameRegistryState.retrieve(connection, nameAccountKey);
24
- }
25
-
26
- /**
27
- * @deprecated Use {@link getHashedNameSync} instead
28
- */
29
- export async function getHashedName(name: string): Promise<Buffer> {
30
- const input = HASH_PREFIX + name;
31
- const str = sha256(Buffer.from(input, "utf8")).slice(2);
32
- return Buffer.from(str, "hex");
33
- }
34
-
35
- /**
36
- * @deprecated Use {@link getNameAccountKeySync} instead
37
- */
38
- export async function getNameAccountKey(
39
- hashed_name: Buffer,
40
- nameClass?: PublicKey,
41
- nameParent?: PublicKey
42
- ): Promise<PublicKey> {
43
- const seeds = [hashed_name];
44
- if (nameClass) {
45
- seeds.push(nameClass.toBuffer());
46
- } else {
47
- seeds.push(Buffer.alloc(32));
48
- }
49
- if (nameParent) {
50
- seeds.push(nameParent.toBuffer());
51
- } else {
52
- seeds.push(Buffer.alloc(32));
53
- }
54
- const [nameAccountKey] = await PublicKey.findProgramAddress(
55
- seeds,
56
- NAME_PROGRAM_ID
57
- );
58
- return nameAccountKey;
59
- }
60
-
61
- /**
62
- * This function can be used to perform a reverse look up
63
- * @deprecated Use {@link reverseLookup} instead
64
- * @param connection The Solana RPC connection
65
- * @param nameAccount The public key of the domain to look up
66
- * @returns The human readable domain name
67
- */
68
- export async function performReverseLookup(
69
- connection: Connection,
70
- nameAccount: PublicKey
71
- ): Promise<string> {
72
- const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
73
- const reverseLookupAccount = await getNameAccountKey(
74
- hashedReverseLookup,
75
- REVERSE_LOOKUP_CLASS
76
- );
77
-
78
- const { registry } = await NameRegistryState.retrieve(
79
- connection,
80
- reverseLookupAccount
81
- );
82
- if (!registry.data) {
83
- throw new Error("Could not retrieve name data");
84
- }
85
- const nameLength = new BN(registry.data.slice(0, 4), "le").toNumber();
86
- return registry.data.slice(4, 4 + nameLength).toString();
87
- }
88
-
89
- /**
90
- * This function can be used to perform a reverse look up
91
- * @deprecated Use {@link reverseLookupBatch} instead
92
- * @param connection The Solana RPC connection
93
- * @param nameAccount The public keys of the domains to look up
94
- * @returns The human readable domain names
95
- */
96
- export async function performReverseLookupBatch(
97
- connection: Connection,
98
- nameAccounts: PublicKey[]
99
- ): Promise<(string | undefined)[]> {
100
- let reverseLookupAccounts: PublicKey[] = [];
101
- for (let nameAccount of nameAccounts) {
102
- const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
103
- const reverseLookupAccount = await getNameAccountKey(
104
- hashedReverseLookup,
105
- REVERSE_LOOKUP_CLASS
106
- );
107
- reverseLookupAccounts.push(reverseLookupAccount);
108
- }
109
-
110
- let names = await NameRegistryState.retrieveBatch(
111
- connection,
112
- reverseLookupAccounts
113
- );
114
-
115
- return names.map((name) => {
116
- if (name === undefined || name.data === undefined) {
117
- return undefined;
118
- }
119
- let nameLength = new BN(name.data.slice(0, 4), "le").toNumber();
120
- return name.data.slice(4, 4 + nameLength).toString();
121
- });
122
- }
123
-
124
- const _derive = async (
125
- name: string,
126
- parent: PublicKey = ROOT_DOMAIN_ACCOUNT
127
- ) => {
128
- let hashed = await getHashedName(name);
129
- let pubkey = await getNameAccountKey(hashed, undefined, parent);
130
- return { pubkey, hashed };
131
- };
132
-
133
- /**
134
- * This function can be used to compute the public key of a domain or subdomain
135
- * @deprecated Use {@link getDomainKeySync} instead
136
- * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
137
- * @param record Optional parameter: If the domain being resolved is a record
138
- * @returns
139
- */
140
- export const getDomainKey = async (domain: string, record = false) => {
141
- if (domain.endsWith(".sol")) {
142
- domain = domain.slice(0, -4);
143
- }
144
- const splitted = domain.split(".");
145
- if (splitted.length === 2) {
146
- const prefix = Buffer.from([record ? 1 : 0]).toString();
147
- const sub = prefix.concat(splitted[0]);
148
- const { pubkey: parentKey } = await _derive(splitted[1]);
149
- const result = await _derive(sub, parentKey);
150
- return { ...result, isSub: true, parent: parentKey };
151
- } else if (splitted.length === 3 && record) {
152
- // Parent key
153
- const { pubkey: parentKey } = await _derive(splitted[2]);
154
- // Sub domain
155
- const { pubkey: subKey } = await _derive(
156
- "\0".concat(splitted[1]),
157
- parentKey
158
- );
159
- // Sub record
160
- const recordPrefix = Buffer.from([1]).toString();
161
- const result = await _derive(recordPrefix.concat(splitted[0]), subKey);
162
- return { ...result, isSub: true, parent: parentKey, isSubRecord: true };
163
- } else if (splitted.length >= 3) {
164
- throw new Error("Invalid derivation input");
165
- }
166
- const result = await _derive(domain, ROOT_DOMAIN_ACCOUNT);
167
- return { ...result, isSub: false, parent: undefined };
168
- };
169
-
170
- /**
171
- * This function can be used to get the key of the reverse account
172
- * @deprecated Use {@link getReverseKeySync} instead
173
- * @param domain The domain to compute the reverse for
174
- * @param isSub Whether the domain is a subdomain or not
175
- * @returns The public key of the reverse account
176
- */
177
- export const getReverseKey = async (domain: string, isSub?: boolean) => {
178
- const { pubkey, parent } = await getDomainKey(domain);
179
- const hashedReverseLookup = await getHashedName(pubkey.toBase58());
180
- const reverseLookupAccount = await getNameAccountKey(
181
- hashedReverseLookup,
182
- REVERSE_LOOKUP_CLASS,
183
- isSub ? parent : undefined
184
- );
185
- return reverseLookupAccount;
186
- };
@@ -1,25 +0,0 @@
1
- import { FavouriteDomain, NAME_OFFERS_ID } from "@bonfida/name-offers";
2
- import { reverseLookup } from "./utils";
3
- import { PublicKey, Connection } from "@solana/web3.js";
4
-
5
- /**
6
- * This function can be used to retrieve the favorite domain of a user
7
- * @param connection The Solana RPC connection object
8
- * @param owner The owner you want to retrieve the favorite domain for
9
- * @returns
10
- */
11
- export const getFavoriteDomain = async (
12
- connection: Connection,
13
- owner: PublicKey
14
- ) => {
15
- const [favKey] = await FavouriteDomain.getKey(
16
- NAME_OFFERS_ID,
17
- new PublicKey(owner)
18
- );
19
-
20
- const favorite = await FavouriteDomain.retrieve(connection, favKey);
21
-
22
- const reverse = await reverseLookup(connection, favorite.nameAccount);
23
-
24
- return { domain: favorite.nameAccount, reverse };
25
- };
package/src/index.ts DELETED
@@ -1,14 +0,0 @@
1
- export * from "./bindings";
2
- export * from "./state";
3
- export * from "./twitter_bindings";
4
- export * from "./deprecated/tokens";
5
- export * from "./utils";
6
- export * from "./instructions";
7
- export * from "./nft";
8
- export * from "./favorite-domain";
9
- export * from "./constants";
10
- export * from "./int";
11
- export * from "./record";
12
- export * from "./types/record";
13
- export * from "./resolve";
14
- export * from "./deprecated/utils";