@bonfida/spl-name-service 0.1.66 → 0.1.67

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,5 +1,14 @@
1
1
  import { PublicKey, Connection } from "@solana/web3.js";
2
- import { TokenData } from "./state";
2
+ import { TokenData } from "../state";
3
+ /**
4
+ * @deprecated
5
+ */
3
6
  export declare const TOKEN_TLD: PublicKey;
7
+ /**
8
+ * @deprecated
9
+ */
4
10
  export declare const getTokenInfoFromMint: (connection: Connection, mint: PublicKey) => Promise<TokenData>;
11
+ /**
12
+ * @deprecated
13
+ */
5
14
  export declare const getTokenInfoFromName: (connection: Connection, name: string) => Promise<TokenData>;
@@ -0,0 +1,66 @@
1
+ /// <reference types="node" />
2
+ import { Connection, PublicKey } from "@solana/web3.js";
3
+ import { NameRegistryState } from "../state";
4
+ /**
5
+ * @deprecated Use {@link resolve} instead
6
+ */
7
+ export declare function getNameOwner(connection: Connection, nameAccountKey: PublicKey): Promise<{
8
+ registry: NameRegistryState;
9
+ nftOwner: PublicKey | undefined;
10
+ }>;
11
+ /**
12
+ * @deprecated Use {@link getHashedNameSync} instead
13
+ */
14
+ export declare function getHashedName(name: string): Promise<Buffer>;
15
+ /**
16
+ * @deprecated Use {@link getNameAccountKeySync} instead
17
+ */
18
+ export declare function getNameAccountKey(hashed_name: Buffer, nameClass?: PublicKey, nameParent?: PublicKey): Promise<PublicKey>;
19
+ /**
20
+ * This function can be used to perform a reverse look up
21
+ * @deprecated Use {@link reverseLookup} instead
22
+ * @param connection The Solana RPC connection
23
+ * @param nameAccount The public key of the domain to look up
24
+ * @returns The human readable domain name
25
+ */
26
+ export declare function performReverseLookup(connection: Connection, nameAccount: PublicKey): Promise<string>;
27
+ /**
28
+ * This function can be used to perform a reverse look up
29
+ * @deprecated Use {@link reverseLookupBatch} instead
30
+ * @param connection The Solana RPC connection
31
+ * @param nameAccount The public keys of the domains to look up
32
+ * @returns The human readable domain names
33
+ */
34
+ export declare function performReverseLookupBatch(connection: Connection, nameAccounts: PublicKey[]): Promise<(string | undefined)[]>;
35
+ /**
36
+ * This function can be used to compute the public key of a domain or subdomain
37
+ * @deprecated Use {@link getDomainKeySync} instead
38
+ * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
39
+ * @param record Optional parameter: If the domain being resolved is a record
40
+ * @returns
41
+ */
42
+ export declare const getDomainKey: (domain: string, record?: boolean) => Promise<{
43
+ isSub: boolean;
44
+ parent: PublicKey;
45
+ pubkey: PublicKey;
46
+ hashed: Buffer;
47
+ } | {
48
+ isSub: boolean;
49
+ parent: PublicKey;
50
+ isSubRecord: boolean;
51
+ pubkey: PublicKey;
52
+ hashed: Buffer;
53
+ } | {
54
+ isSub: boolean;
55
+ parent: undefined;
56
+ pubkey: PublicKey;
57
+ hashed: Buffer;
58
+ }>;
59
+ /**
60
+ * This function can be used to get the key of the reverse account
61
+ * @deprecated Use {@link getReverseKeySync} instead
62
+ * @param domain The domain to compute the reverse for
63
+ * @param isSub Whether the domain is a subdomain or not
64
+ * @returns The public key of the reverse account
65
+ */
66
+ export declare const getReverseKey: (domain: string, isSub?: boolean) => Promise<PublicKey>;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- export * from "./utils";
2
1
  export * from "./bindings";
3
2
  export * from "./state";
4
3
  export * from "./twitter_bindings";
5
- export * from "./tokens";
4
+ export * from "./deprecated/tokens";
6
5
  export * from "./utils";
7
6
  export * from "./instructions";
8
7
  export * from "./nft";
@@ -12,3 +11,4 @@ export * from "./int";
12
11
  export * from "./record";
13
12
  export * from "./types/record";
14
13
  export * from "./resolve";
14
+ export * from "./deprecated/utils";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@solana/web3.js"),t=require("bn.js"),r=require("@ethersproject/sha2"),i=require("borsh"),a=require("@solana/spl-token"),s=require("@bonfida/name-offers"),n=require("tweetnacl");const o=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),c="SPL Name Service",u=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),l=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),p=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),f=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),w=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),d=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),y=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),g=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),m=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),b=Buffer.from("tokenized_name"),h=async(t,r)=>{try{const[i]=await e.PublicKey.findProgramAddress([b,r.toBuffer()],m);if("0"===(await a.getMint(t,i)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await t.getProgramAccounts(a.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class R{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,R,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await h(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,R,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}R.HEADER_LEN=96,R.schema=new Map([[R,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class x{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(x.schema,this)}static deserialize(e){return i.deserializeUnchecked(x.schema,x,e)}}x.schema=new Map([[x,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class S{constructor(e){this.mint=e.mint}serialize(){return i.serialize(S.schema,this)}static deserialize(e){return i.deserializeUnchecked(S.schema,S,e)}}async function v(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return R.retrieve(e,t)}async function B(e){const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")}S.schema=new Map([[S,{kind:"struct",fields:[["mint",[32]]]}]]);const k=e=>{const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")};async function E(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,o);return s}const P=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,o);return s};async function I(e,r){const i=await B(r.toBase58()),a=await E(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}async function A(e,r){const i=k(r.toBase58()),a=P(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const T=async(e,t=u)=>{let r=await B(e);return{pubkey:await E(r,void 0,t),hashed:r}},K=(e,t=u)=>{let r=k(e);return{pubkey:P(r,void 0,t),hashed:r}},N=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await T(r[1]);return{...await T(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await T(r[2]),{pubkey:t}=await T("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await T(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await T(e,u),isSub:!1,parent:void 0}},W=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=K(r[1]);return{...K(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=K(r[2]),{pubkey:t}=K("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...K(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...K(e,u),isSub:!1,parent:void 0}};class D extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class _ extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function H(t,r,i,a,s,n,o,c,u,l,p){const f=[Buffer.from(Int8Array.from([0])),new D(n.length).toBuffer(),n,o.toBuffer(),c.toBuffer()],w=Buffer.concat(f),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return u?d.push({pubkey:u,isSigner:!0,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l?d.push({pubkey:l,isSigner:!1,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),p&&d.push({pubkey:p,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:d,programId:t,data:w})}function O(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new D(a.length).toBuffer(),a],o=Buffer.concat(n),c=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:c,programId:t,data:o})}function L(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),l=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&l.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:t,data:u})}function z(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class F{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(F.schema,this)}getInstruction(t,r,i,s,n,o,c,u,l,p,f){const w=Buffer.from(this.serialize()),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:d,programId:t,data:w})}}F.schema=new Map([[F,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class M{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(M.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const l=Buffer.from(this.serialize());let p=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");p.push({pubkey:c,isSigner:!1,isWritable:!0}),p.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:p,programId:t,data:l})}}async function U(e,t,r,i,a){const s=await B(t),n=await E(s,i,a);let c;c=i||(await R.retrieve(e,n)).registry.owner;return z(o,n,r,c)}M.schema=new Map([[M,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class C{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,C,r.data.slice(R.HEADER_LEN))}}async function V(t,r,a,s,n){const c=await B(s.toString()),u=await E(c,d,y);let l=i.serialize(C.schema,new C({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[H(o,e.SystemProgram.programId,u,s,n,c,new _(await t.getMinimumBalanceForRentExemption(l.length+R.HEADER_LEN)),new D(l.length),d,y,d),O(o,u,new D(0),Buffer.from(l),d)]}C.schema=new Map([[C,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const j=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),G=async(e,t)=>{const r=await E(await B(t.toBase58()),void 0,j),{registry:i}=await R.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return x.deserialize(i.data)};var q;exports.Record=void 0,(q=exports.Record||(exports.Record={})).IPFS="IPFS",q.ARWV="ARWV",q.SOL="SOL",q.ETH="ETH",q.BTC="BTC",q.LTC="LTC",q.DOGE="DOGE",q.Email="email",q.Url="url",q.Discord="discord",q.Github="github",q.Reddit="reddit",q.Twitter="twitter",q.Telegram="telegram",q.Pic="pic",q.SHDW="SHDW",q.POINT="POINT",q.BSC="BSC",q.Injective="INJECT";const Y=async(e,t)=>{const{pubkey:r}=await N(t+"."+e,!0);return r},X=async(e,t,r)=>{var i,a;const s=await Y(t,r);let{registry:n}=await R.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},Z=async(e,t)=>await X(e,t,exports.Record.SOL),J=(e,t,r)=>n.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=f,exports.BONFIDA_USDC_BNB=g,exports.HASH_PREFIX=c,exports.MINT_PREFIX=b,exports.Mint=S,exports.NAME_PROGRAM_ID=o,exports.NAME_TOKENIZER_ID=m,exports.NameRegistryState=R,exports.Numberu32=D,exports.Numberu64=_,exports.PYTH_FIDA_PRICE_ACC=p,exports.REGISTER_PROGRAM_ID=l,exports.REVERSE_LOOKUP_CLASS=w,exports.ROOT_DOMAIN_ACCOUNT=u,exports.ReverseTwitterRegistryState=C,exports.SOL_RECORD_SIG_LEN=96,exports.TOKEN_TLD=j,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=y,exports.TWITTER_VERIFICATION_AUTHORITY=d,exports.TokenData=x,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await B(e),s=await E(a,void 0,y);return[O(o,s,new D(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await B(t),n=await E(s,void 0,y);let c=[L(o,n,i,r,void 0)];const u=await B(r.toString());return await E(u,d,void 0),c.push(await U(e,r.toString(),a,d,y)),c=c.concat(await V(e,t,n,i,a)),c},exports.checkSolRecord=J,exports.createInstruction=H,exports.createNameRegistry=async function(t,r,i,a,s,n,c,u){const l=await B(r),p=await E(l,c,u),f=n||await t.getMinimumBalanceForRentExemption(i);let w;if(u){const{registry:e}=await v(t,u);w=e.owner}return H(o,e.SystemProgram.programId,p,s,a,l,new _(f),new D(i),c,u,w)},exports.createReverseInstruction=M,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),c=await B(t.toBase58()),p=await E(c,n,a);return[[],[new M({name:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,p,n,i,a,s)]]},exports.createReverseTwitterRegistry=V,exports.createV2Instruction=F,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await B(r),c=await E(n,void 0,y),u=await t.getMinimumBalanceForRentExemption(a+R.HEADER_LEN);let l=[H(o,e.SystemProgram.programId,c,i,s,n,new _(u),new D(a),void 0,y,d)];return l=l.concat(await V(t,r,c,i,s)),l},exports.deleteInstruction=z,exports.deleteNameRegistry=U,exports.deleteTwitterRegistry=async function(e,t){const r=await B(e),i=await E(r,void 0,y),a=await B(t.toString()),s=await E(a,d,y);return[z(o,i,t,t),z(o,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:w.toBase58()}}],i=await e.getProgramAccounts(o,{filters:r}),a=await A(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>W(e+"."+a).pubkey)),c=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!c[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:u.toBase58()}}];return(await e.getProgramAccounts(o,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:u.toBase58()}}];return await e.getProgramAccounts(o,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await X(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await X(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await X(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await X(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await X(e,t,exports.Record.DOGE),exports.getDomainKey=N,exports.getDomainKeySync=W,exports.getEmailRecord=async(e,t)=>await X(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await X(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await s.FavouriteDomain.getKey(s.NAME_OFFERS_ID,new e.PublicKey(r)),a=await s.FavouriteDomain.retrieve(t,i),n=await I(t,a.nameAccount);return{domain:a.nameAccount,reverse:n}},exports.getGithubRecord=async(e,t)=>await X(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await B(r.toString()),a=await E(i,d,y);let s=await C.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=B,exports.getHashedNameSync=k,exports.getInjectiveRecord=async(e,t)=>await X(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await X(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await X(e,t,exports.Record.LTC),exports.getNameAccountKey=E,exports.getNameAccountKeySync=P,exports.getNameOwner=v,exports.getPicRecord=async(e,t)=>await X(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await X(e,t,exports.Record.POINT),exports.getRecord=X,exports.getRecordKey=Y,exports.getRecordKeySync=(e,t)=>{const{pubkey:r}=W(t+"."+e,!0);return r},exports.getRedditRecord=async(e,t)=>await X(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await N(e),a=await B(r.toBase58());return await E(a,w,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=W(e),a=k(r.toBase58());return P(a,w,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await X(e,t,exports.Record.SHDW),exports.getSolRecord=Z,exports.getTelegramRecord=async(e,t)=>await X(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=G,exports.getTokenInfoFromName=async(t,r)=>{const i=await E(await B(r),void 0,j),{registry:a}=await R.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(S.deserialize(a.data).mint);return await G(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:d.toBase58()}}],s=await t.getProgramAccounts(o,{filters:a});for(const t of s)if(t.account.data.length>R.HEADER_LEN+32){let r=t.account.data.slice(R.HEADER_LEN),a=i.deserializeUnchecked(C.schema,C,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await X(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await B(t),i=await E(r,void 0,y),{registry:a}=await R.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(o,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(R.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await B(e);return await E(t,void 0,y)},exports.getUrlRecord=async(e,t)=>await X(e,t,exports.Record.Url),exports.performReverseLookup=I,exports.performReverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=await B(e.toBase58()),r=await E(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.registerDomainName=async(t,r,i,a)=>{const[s]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),n=await B(t),c=await E(n,void 0,u),p=await B(c.toBase58()),f=await E(p,s),[w]=await e.PublicKey.findProgramAddress([c.toBuffer()],l);return[[],[new F({name:t,space:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,c,f,s,i,a,g,w)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=await N(r),{registry:a,nftOwner:s}=await R.retrieve(t,i);if(s)return s;try{const i=await N(exports.Record.SOL+"."+r,!0),s=await Z(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!J(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=h,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=A,exports.reverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=k(e.toBase58()),r=P(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.transferInstruction=L,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,i,a);let u;return u=i||(await R.retrieve(e,c)).registry.owner,L(o,c,r,u,i,a,s)},exports.updateInstruction=O,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,a,s);let u;return u=a||(await R.retrieve(e,c)).registry.owner,O(o,c,new D(r),i,u)};
1
+ "use strict";var e=require("@solana/web3.js"),t=require("@solana/spl-token"),r=require("bn.js"),i=require("borsh"),a=require("@ethersproject/sha2"),s=require("@bonfida/name-offers"),n=require("tweetnacl");class o extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class c extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function u(t,r,i,a,s,n,c,u,l,p,f){const d=[Buffer.from(Int8Array.from([0])),new o(n.length).toBuffer(),n,c.toBuffer(),u.toBuffer()],w=Buffer.concat(d),y=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return l?y.push({pubkey:l,isSigner:!0,isWritable:!1}):y.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),p?y.push({pubkey:p,isSigner:!1,isWritable:!1}):y.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),f&&y.push({pubkey:f,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:y,programId:t,data:w})}function l(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new o(a.length).toBuffer(),a],c=Buffer.concat(n),u=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:t,data:c})}function p(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),l=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&l.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:t,data:u})}function f(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class d{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(d.schema,this)}getInstruction(r,i,a,s,n,o,c,u,l,p,f){const d=Buffer.from(this.serialize()),w=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:t.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:w,programId:r,data:d})}}d.schema=new Map([[d,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class w{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(w.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const l=Buffer.from(this.serialize());let p=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");p.push({pubkey:c,isSigner:!1,isWritable:!0}),p.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:p,programId:t,data:l})}}w.schema=new Map([[w,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);const y=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),g=Buffer.from("tokenized_name"),m=async(r,i)=>{try{const[a]=await e.PublicKey.findProgramAddress([g,i.toBuffer()],y);if("0"===(await t.getMint(r,a)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:a.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await r.getProgramAccounts(t.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class b{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,b,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await m(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,b,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}b.HEADER_LEN=96,b.schema=new Map([[b,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class h{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(h.schema,this)}static deserialize(e){return i.deserializeUnchecked(h.schema,h,e)}}h.schema=new Map([[h,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class R{constructor(e){this.mint=e.mint}serialize(){return i.serialize(R.schema,this)}static deserialize(e){return i.deserializeUnchecked(R.schema,R,e)}}R.schema=new Map([[R,{kind:"struct",fields:[["mint",[32]]]}]]);const x=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),S="SPL Name Service",v=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),B=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),k=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),E=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),P=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),I=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),A=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),T=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7");async function N(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return b.retrieve(e,t)}async function K(e){const t=S+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")}async function W(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,x);return s}const D=async(e,t=v)=>{let r=await K(e);return{pubkey:await W(r,void 0,t),hashed:r}},_=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await D(r[1]);return{...await D(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await D(r[2]),{pubkey:t}=await D("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await D(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await D(e,v),isSub:!1,parent:void 0}};async function H(e,t,r,i,a){const s=await K(t),n=await W(s,i,a);let o;o=i||(await b.retrieve(e,n)).registry.owner;return f(x,n,r,o)}class O{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,O,r.data.slice(b.HEADER_LEN))}}async function L(t,r,a,s,n){const p=await K(s.toString()),f=await W(p,I,A);let d=i.serialize(O.schema,new O({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[u(x,e.SystemProgram.programId,f,s,n,p,new c(await t.getMinimumBalanceForRentExemption(d.length+b.HEADER_LEN)),new o(d.length),I,A,I),l(x,f,new o(0),Buffer.from(d),I)]}O.schema=new Map([[O,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const z=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),F=async(e,t)=>{const r=await W(await K(t.toBase58()),void 0,z),{registry:i}=await b.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return h.deserialize(i.data)},M=e=>{const t=S+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")},U=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,x);return s};async function C(e,t){const i=M(t.toBase58()),a=U(i,P),{registry:s}=await b.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const V=(e,t=v)=>{let r=M(e);return{pubkey:U(r,void 0,t),hashed:r}},j=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=V(r[1]);return{...V(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=V(r[2]),{pubkey:t}=V("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...V(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...V(e,v),isSub:!1,parent:void 0}};var G;exports.Record=void 0,(G=exports.Record||(exports.Record={})).IPFS="IPFS",G.ARWV="ARWV",G.SOL="SOL",G.ETH="ETH",G.BTC="BTC",G.LTC="LTC",G.DOGE="DOGE",G.Email="email",G.Url="url",G.Discord="discord",G.Github="github",G.Reddit="reddit",G.Twitter="twitter",G.Telegram="telegram",G.Pic="pic",G.SHDW="SHDW",G.POINT="POINT",G.BSC="BSC",G.Injective="INJECT";const q=(e,t)=>{const{pubkey:r}=j(t+"."+e,!0);return r},Y=async(e,t,r)=>{var i,a;const s=q(t,r);let{registry:n}=await b.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},X=async(e,t)=>await Y(e,t,exports.Record.SOL),Z=(e,t,r)=>n.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=E,exports.BONFIDA_USDC_BNB=T,exports.HASH_PREFIX=S,exports.MINT_PREFIX=g,exports.Mint=R,exports.NAME_PROGRAM_ID=x,exports.NAME_TOKENIZER_ID=y,exports.NameRegistryState=b,exports.Numberu32=o,exports.Numberu64=c,exports.PYTH_FIDA_PRICE_ACC=k,exports.REGISTER_PROGRAM_ID=B,exports.REVERSE_LOOKUP_CLASS=P,exports.ROOT_DOMAIN_ACCOUNT=v,exports.ReverseTwitterRegistryState=O,exports.SOL_RECORD_SIG_LEN=96,exports.TOKEN_TLD=z,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=A,exports.TWITTER_VERIFICATION_AUTHORITY=I,exports.TokenData=h,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await K(e),s=await W(a,void 0,A);return[l(x,s,new o(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await K(t),n=await W(s,void 0,A);let o=[p(x,n,i,r,void 0)];const c=await K(r.toString());return await W(c,I,void 0),o.push(await H(e,r.toString(),a,I,A)),o=o.concat(await L(e,t,n,i,a)),o},exports.checkSolRecord=Z,exports.createInstruction=u,exports.createNameRegistry=async function(t,r,i,a,s,n,l,p){const f=await K(r),d=await W(f,l,p),w=n||await t.getMinimumBalanceForRentExemption(i);let y;if(p){const{registry:e}=await N(t,p);y=e.owner}return u(x,e.SystemProgram.programId,d,s,a,f,new c(w),new o(i),l,p,y)},exports.createReverseInstruction=w,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),o=await K(t.toBase58()),c=await W(o,n,a);return[[],[new w({name:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,x,v,c,n,i,a,s)]]},exports.createReverseTwitterRegistry=L,exports.createV2Instruction=d,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await K(r),l=await W(n,void 0,A),p=await t.getMinimumBalanceForRentExemption(a+b.HEADER_LEN);let f=[u(x,e.SystemProgram.programId,l,i,s,n,new c(p),new o(a),void 0,A,I)];return f=f.concat(await L(t,r,l,i,s)),f},exports.deleteInstruction=f,exports.deleteNameRegistry=H,exports.deleteTwitterRegistry=async function(e,t){const r=await K(e),i=await W(r,void 0,A),a=await K(t.toString()),s=await W(a,I,A);return[f(x,i,t,t),f(x,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:P.toBase58()}}],i=await e.getProgramAccounts(x,{filters:r}),a=await C(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>j(e+"."+a).pubkey)),o=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!o[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:v.toBase58()}}];return(await e.getProgramAccounts(x,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:v.toBase58()}}];return await e.getProgramAccounts(x,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await Y(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await Y(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await Y(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await Y(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await Y(e,t,exports.Record.DOGE),exports.getDomainKey=_,exports.getDomainKeySync=j,exports.getEmailRecord=async(e,t)=>await Y(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await Y(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await s.FavouriteDomain.getKey(s.NAME_OFFERS_ID,new e.PublicKey(r)),a=await s.FavouriteDomain.retrieve(t,i),n=await C(t,a.nameAccount);return{domain:a.nameAccount,reverse:n}},exports.getGithubRecord=async(e,t)=>await Y(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await K(r.toString()),a=await W(i,I,A);let s=await O.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=K,exports.getHashedNameSync=M,exports.getInjectiveRecord=async(e,t)=>await Y(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await Y(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await Y(e,t,exports.Record.LTC),exports.getNameAccountKey=W,exports.getNameAccountKeySync=U,exports.getNameOwner=N,exports.getPicRecord=async(e,t)=>await Y(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await Y(e,t,exports.Record.POINT),exports.getRecord=Y,exports.getRecordKeySync=q,exports.getRedditRecord=async(e,t)=>await Y(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await _(e),a=await K(r.toBase58());return await W(a,P,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=j(e),a=M(r.toBase58());return U(a,P,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await Y(e,t,exports.Record.SHDW),exports.getSolRecord=X,exports.getTelegramRecord=async(e,t)=>await Y(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=F,exports.getTokenInfoFromName=async(t,r)=>{const i=await W(await K(r),void 0,z),{registry:a}=await b.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(R.deserialize(a.data).mint);return await F(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:A.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:I.toBase58()}}],s=await t.getProgramAccounts(x,{filters:a});for(const t of s)if(t.account.data.length>b.HEADER_LEN+32){let r=t.account.data.slice(b.HEADER_LEN),a=i.deserializeUnchecked(O.schema,O,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await Y(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await K(t),i=await W(r,void 0,A),{registry:a}=await b.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:A.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(x,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(b.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await K(e);return await W(t,void 0,A)},exports.getUrlRecord=async(e,t)=>await Y(e,t,exports.Record.Url),exports.performReverseLookup=async function(e,t){const i=await K(t.toBase58()),a=await W(i,P),{registry:s}=await b.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()},exports.performReverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=await K(e.toBase58()),r=await W(t,P);i.push(r)}return(await b.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.registerDomainName=async(t,r,i,a)=>{const[s]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),n=await K(t),o=await W(n,void 0,v),c=await K(o.toBase58()),u=await W(c,s),[l]=await e.PublicKey.findProgramAddress([o.toBuffer()],B);return[[],[new d({name:t,space:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,x,v,o,u,s,i,a,T,l)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=j(r),{registry:a,nftOwner:s}=await b.retrieve(t,i);if(s)return s;try{const i=j(exports.Record.SOL+"."+r,!0),s=await X(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!Z(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=m,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(y,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=C,exports.reverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=M(e.toBase58()),r=U(t,P);i.push(r)}return(await b.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.transferInstruction=p,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await K(t),o=await W(n,i,a);let c;return c=i||(await b.retrieve(e,o)).registry.owner,p(x,o,r,c,i,a,s)},exports.updateInstruction=l,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await K(t),c=await W(n,a,s);let u;return u=a||(await b.retrieve(e,c)).registry.owner,l(x,c,new o(r),i,u)};
package/dist/record.d.ts CHANGED
@@ -1,14 +1,6 @@
1
1
  import { Record } from "./types/record";
2
2
  import { Connection } from "@solana/web3.js";
3
3
  import { NameRegistryState } from "./state";
4
- /**
5
- * @deprecated Use {@link getRecordKeySync} instead
6
- * This function can be used to derive a record key
7
- * @param domain The .sol domain name
8
- * @param record The record to derive the key for
9
- * @returns
10
- */
11
- export declare const getRecordKey: (domain: string, record: Record) => Promise<import("@solana/web3.js").PublicKey>;
12
4
  /**
13
5
  * This function can be used to derive a record key
14
6
  * @param domain The .sol domain name
package/dist/utils.d.ts CHANGED
@@ -1,31 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Connection, PublicKey } from "@solana/web3.js";
3
- import { NameRegistryState } from "./state";
4
- /**
5
- * @deprecated Use {@link resolve} instead
6
- */
7
- export declare function getNameOwner(connection: Connection, nameAccountKey: PublicKey): Promise<{
8
- registry: NameRegistryState;
9
- nftOwner: PublicKey | undefined;
10
- }>;
11
- /**
12
- * @deprecated Use {@link getHashedNameSync} instead
13
- */
14
- export declare function getHashedName(name: string): Promise<Buffer>;
15
3
  export declare const getHashedNameSync: (name: string) => Buffer;
16
- /**
17
- * @deprecated Use {@link getNameAccountKeySync} instead
18
- */
19
- export declare function getNameAccountKey(hashed_name: Buffer, nameClass?: PublicKey, nameParent?: PublicKey): Promise<PublicKey>;
20
4
  export declare const getNameAccountKeySync: (hashed_name: Buffer, nameClass?: PublicKey, nameParent?: PublicKey) => PublicKey;
21
- /**
22
- * This function can be used to perform a reverse look up
23
- * @deprecated Use {@link reverseLookup} instead
24
- * @param connection The Solana RPC connection
25
- * @param nameAccount The public key of the domain to look up
26
- * @returns The human readable domain name
27
- */
28
- export declare function performReverseLookup(connection: Connection, nameAccount: PublicKey): Promise<string>;
29
5
  /**
30
6
  * This function can be used to perform a reverse look up
31
7
  * @param connection The Solana RPC connection
@@ -33,14 +9,6 @@ export declare function performReverseLookup(connection: Connection, nameAccount
33
9
  * @returns The human readable domain name
34
10
  */
35
11
  export declare function reverseLookup(connection: Connection, nameAccount: PublicKey): Promise<string>;
36
- /**
37
- * This function can be used to perform a reverse look up
38
- * @deprecated Use {@link reverseLookupBatch} instead
39
- * @param connection The Solana RPC connection
40
- * @param nameAccount The public keys of the domains to look up
41
- * @returns The human readable domain names
42
- */
43
- export declare function performReverseLookupBatch(connection: Connection, nameAccounts: PublicKey[]): Promise<(string | undefined)[]>;
44
12
  /**
45
13
  * This function can be used to perform a reverse look up
46
14
  * @param connection The Solana RPC connection
@@ -55,30 +23,6 @@ export declare function reverseLookupBatch(connection: Connection, nameAccounts:
55
23
  * @returns
56
24
  */
57
25
  export declare const findSubdomains: (connection: Connection, parentKey: PublicKey) => Promise<string[]>;
58
- /**
59
- * This function can be used to compute the public key of a domain or subdomain
60
- * @deprecated Use {@link getDomainKeySync} instead
61
- * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
62
- * @param record Optional parameter: If the domain being resolved is a record
63
- * @returns
64
- */
65
- export declare const getDomainKey: (domain: string, record?: boolean) => Promise<{
66
- isSub: boolean;
67
- parent: PublicKey;
68
- pubkey: PublicKey;
69
- hashed: Buffer;
70
- } | {
71
- isSub: boolean;
72
- parent: PublicKey;
73
- isSubRecord: boolean;
74
- pubkey: PublicKey;
75
- hashed: Buffer;
76
- } | {
77
- isSub: boolean;
78
- parent: undefined;
79
- pubkey: PublicKey;
80
- hashed: Buffer;
81
- }>;
82
26
  /**
83
27
  * This function can be used to compute the public key of a domain or subdomain
84
28
  * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
@@ -119,14 +63,6 @@ export declare const getAllRegisteredDomains: (connection: Connection) => Promis
119
63
  pubkey: PublicKey;
120
64
  account: import("@solana/web3.js").AccountInfo<Buffer>;
121
65
  }[]>;
122
- /**
123
- * This function can be used to get the key of the reverse account
124
- * @deprecated Use {@link getReverseKeySync} instead
125
- * @param domain The domain to compute the reverse for
126
- * @param isSub Whether the domain is a subdomain or not
127
- * @returns The public key of the reverse account
128
- */
129
- export declare const getReverseKey: (domain: string, isSub?: boolean) => Promise<PublicKey>;
130
66
  /**
131
67
  * This function can be used to get the key of the reverse account
132
68
  * @param domain The domain to compute the reverse for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonfida/spl-name-service",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
package/src/bindings.ts CHANGED
@@ -15,7 +15,11 @@ import {
15
15
  } from "./instructions";
16
16
  import { NameRegistryState } from "./state";
17
17
  import { Numberu64, Numberu32 } from "./int";
18
- import { getHashedName, getNameAccountKey, getNameOwner } from "./utils";
18
+ import {
19
+ getHashedName,
20
+ getNameAccountKey,
21
+ getNameOwner,
22
+ } from "./deprecated/utils";
19
23
  import {
20
24
  NAME_PROGRAM_ID,
21
25
  ROOT_DOMAIN_ACCOUNT,
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -0,0 +1,14 @@
1
+ import { Record } from "../types/record";
2
+ import { getDomainKey } from "./utils";
3
+
4
+ /**
5
+ * @deprecated Use {@link getRecordKeySync} instead
6
+ * This function can be used to derive a record key
7
+ * @param domain The .sol domain name
8
+ * @param record The record to derive the key for
9
+ * @returns
10
+ */
11
+ export const getRecordKey = async (domain: string, record: Record) => {
12
+ const { pubkey } = await getDomainKey(record + "." + domain, true);
13
+ return pubkey;
14
+ };
@@ -1,11 +1,17 @@
1
1
  import { PublicKey, Connection } from "@solana/web3.js";
2
2
  import { getHashedName, getNameAccountKey } from "./utils";
3
- import { NameRegistryState, TokenData, Mint } from "./state";
3
+ import { NameRegistryState, TokenData, Mint } from "../state";
4
4
 
5
+ /**
6
+ * @deprecated
7
+ */
5
8
  export const TOKEN_TLD = new PublicKey(
6
9
  "6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"
7
10
  );
8
11
 
12
+ /**
13
+ * @deprecated
14
+ */
9
15
  export const getTokenInfoFromMint = async (
10
16
  connection: Connection,
11
17
  mint: PublicKey
@@ -22,6 +28,9 @@ export const getTokenInfoFromMint = async (
22
28
  return TokenData.deserialize(registry.data);
23
29
  };
24
30
 
31
+ /**
32
+ * @deprecated
33
+ */
25
34
  export const getTokenInfoFromName = async (
26
35
  connection: Connection,
27
36
  name: string
@@ -0,0 +1,186 @@
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,5 +1,5 @@
1
1
  import { FavouriteDomain, NAME_OFFERS_ID } from "@bonfida/name-offers";
2
- import { performReverseLookup } from "./utils";
2
+ import { reverseLookup } from "./utils";
3
3
  import { PublicKey, Connection } from "@solana/web3.js";
4
4
 
5
5
  /**
@@ -19,7 +19,7 @@ export const getFavoriteDomain = async (
19
19
 
20
20
  const favorite = await FavouriteDomain.retrieve(connection, favKey);
21
21
 
22
- const reverse = await performReverseLookup(connection, favorite.nameAccount);
22
+ const reverse = await reverseLookup(connection, favorite.nameAccount);
23
23
 
24
24
  return { domain: favorite.nameAccount, reverse };
25
25
  };
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
- export * from "./utils";
2
1
  export * from "./bindings";
3
2
  export * from "./state";
4
3
  export * from "./twitter_bindings";
5
- export * from "./tokens";
4
+ export * from "./deprecated/tokens";
6
5
  export * from "./utils";
7
6
  export * from "./instructions";
8
7
  export * from "./nft";
@@ -12,3 +11,4 @@ export * from "./int";
12
11
  export * from "./record";
13
12
  export * from "./types/record";
14
13
  export * from "./resolve";
14
+ export * from "./deprecated/utils";
package/src/record.ts CHANGED
@@ -1,21 +1,9 @@
1
1
  import { Record } from "./types/record";
2
2
  import { Connection } from "@solana/web3.js";
3
- import { getDomainKey, getDomainKeySync } from "./utils";
3
+ import { getDomainKeySync } from "./utils";
4
4
  import { NameRegistryState } from "./state";
5
5
  import { SOL_RECORD_SIG_LEN } from "./constants";
6
6
 
7
- /**
8
- * @deprecated Use {@link getRecordKeySync} instead
9
- * This function can be used to derive a record key
10
- * @param domain The .sol domain name
11
- * @param record The record to derive the key for
12
- * @returns
13
- */
14
- export const getRecordKey = async (domain: string, record: Record) => {
15
- const { pubkey } = await getDomainKey(record + "." + domain, true);
16
- return pubkey;
17
- };
18
-
19
7
  /**
20
8
  * This function can be used to derive a record key
21
9
  * @param domain The .sol domain name
@@ -39,7 +27,7 @@ export const getRecord = async (
39
27
  domain: string,
40
28
  record: Record
41
29
  ) => {
42
- const pubkey = await getRecordKey(domain, record);
30
+ const pubkey = getRecordKeySync(domain, record);
43
31
  let { registry } = await NameRegistryState.retrieve(connection, pubkey);
44
32
 
45
33
  // Remove trailling 0s
package/src/resolve.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Connection, PublicKey } from "@solana/web3.js";
2
2
  import { getSolRecord } from "./record";
3
- import { getDomainKey } from "./utils";
3
+ import { getDomainKeySync } from "./utils";
4
4
  import { NameRegistryState } from "./state";
5
5
  import { sign } from "tweetnacl";
6
6
  import { Record } from "./types/record";
@@ -27,7 +27,7 @@ export const checkSolRecord = (
27
27
  * @returns
28
28
  */
29
29
  export const resolve = async (connection: Connection, domain: string) => {
30
- const { pubkey } = await getDomainKey(domain);
30
+ const { pubkey } = getDomainKeySync(domain);
31
31
 
32
32
  const { registry, nftOwner } = await NameRegistryState.retrieve(
33
33
  connection,
@@ -39,7 +39,7 @@ export const resolve = async (connection: Connection, domain: string) => {
39
39
  }
40
40
 
41
41
  try {
42
- const recordKey = await getDomainKey(Record.SOL + "." + domain, true);
42
+ const recordKey = getDomainKeySync(Record.SOL + "." + domain, true);
43
43
  const solRecord = await getSolRecord(connection, domain);
44
44
 
45
45
  if (!solRecord.data) {
@@ -17,7 +17,7 @@ import {
17
17
  updateInstruction,
18
18
  } from "./instructions";
19
19
  import { NameRegistryState } from "./state";
20
- import { getHashedName, getNameAccountKey } from "./utils";
20
+ import { getHashedName, getNameAccountKey } from "./deprecated/utils";
21
21
  import { Numberu32, Numberu64 } from "./int";
22
22
  import { deserializeUnchecked, Schema, serialize } from "borsh";
23
23
 
package/src/utils.ts CHANGED
@@ -5,61 +5,12 @@ import { HASH_PREFIX, NAME_PROGRAM_ID, ROOT_DOMAIN_ACCOUNT } from "./constants";
5
5
  import { NameRegistryState } from "./state";
6
6
  import { REVERSE_LOOKUP_CLASS } from "./constants";
7
7
 
8
- /**
9
- * @deprecated Use {@link resolve} instead
10
- */
11
- export async function getNameOwner(
12
- connection: Connection,
13
- nameAccountKey: PublicKey
14
- ) {
15
- const nameAccount = await connection.getAccountInfo(nameAccountKey);
16
- if (!nameAccount) {
17
- throw new Error("Unable to find the given account.");
18
- }
19
- return NameRegistryState.retrieve(connection, nameAccountKey);
20
- }
21
-
22
- /**
23
- * @deprecated Use {@link getHashedNameSync} instead
24
- */
25
- export async function getHashedName(name: string): Promise<Buffer> {
26
- const input = HASH_PREFIX + name;
27
- const str = sha256(Buffer.from(input, "utf8")).slice(2);
28
- return Buffer.from(str, "hex");
29
- }
30
-
31
8
  export const getHashedNameSync = (name: string): Buffer => {
32
9
  const input = HASH_PREFIX + name;
33
10
  const str = sha256(Buffer.from(input, "utf8")).slice(2);
34
11
  return Buffer.from(str, "hex");
35
12
  };
36
13
 
37
- /**
38
- * @deprecated Use {@link getNameAccountKeySync} instead
39
- */
40
- export async function getNameAccountKey(
41
- hashed_name: Buffer,
42
- nameClass?: PublicKey,
43
- nameParent?: PublicKey
44
- ): Promise<PublicKey> {
45
- const seeds = [hashed_name];
46
- if (nameClass) {
47
- seeds.push(nameClass.toBuffer());
48
- } else {
49
- seeds.push(Buffer.alloc(32));
50
- }
51
- if (nameParent) {
52
- seeds.push(nameParent.toBuffer());
53
- } else {
54
- seeds.push(Buffer.alloc(32));
55
- }
56
- const [nameAccountKey] = await PublicKey.findProgramAddress(
57
- seeds,
58
- NAME_PROGRAM_ID
59
- );
60
- return nameAccountKey;
61
- }
62
-
63
14
  export const getNameAccountKeySync = (
64
15
  hashed_name: Buffer,
65
16
  nameClass?: PublicKey,
@@ -83,34 +34,6 @@ export const getNameAccountKeySync = (
83
34
  return nameAccountKey;
84
35
  };
85
36
 
86
- /**
87
- * This function can be used to perform a reverse look up
88
- * @deprecated Use {@link reverseLookup} instead
89
- * @param connection The Solana RPC connection
90
- * @param nameAccount The public key of the domain to look up
91
- * @returns The human readable domain name
92
- */
93
- export async function performReverseLookup(
94
- connection: Connection,
95
- nameAccount: PublicKey
96
- ): Promise<string> {
97
- const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
98
- const reverseLookupAccount = await getNameAccountKey(
99
- hashedReverseLookup,
100
- REVERSE_LOOKUP_CLASS
101
- );
102
-
103
- const { registry } = await NameRegistryState.retrieve(
104
- connection,
105
- reverseLookupAccount
106
- );
107
- if (!registry.data) {
108
- throw new Error("Could not retrieve name data");
109
- }
110
- const nameLength = new BN(registry.data.slice(0, 4), "le").toNumber();
111
- return registry.data.slice(4, 4 + nameLength).toString();
112
- }
113
-
114
37
  /**
115
38
  * This function can be used to perform a reverse look up
116
39
  * @param connection The Solana RPC connection
@@ -138,41 +61,6 @@ export async function reverseLookup(
138
61
  return registry.data.slice(4, 4 + nameLength).toString();
139
62
  }
140
63
 
141
- /**
142
- * This function can be used to perform a reverse look up
143
- * @deprecated Use {@link reverseLookupBatch} instead
144
- * @param connection The Solana RPC connection
145
- * @param nameAccount The public keys of the domains to look up
146
- * @returns The human readable domain names
147
- */
148
- export async function performReverseLookupBatch(
149
- connection: Connection,
150
- nameAccounts: PublicKey[]
151
- ): Promise<(string | undefined)[]> {
152
- let reverseLookupAccounts: PublicKey[] = [];
153
- for (let nameAccount of nameAccounts) {
154
- const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
155
- const reverseLookupAccount = await getNameAccountKey(
156
- hashedReverseLookup,
157
- REVERSE_LOOKUP_CLASS
158
- );
159
- reverseLookupAccounts.push(reverseLookupAccount);
160
- }
161
-
162
- let names = await NameRegistryState.retrieveBatch(
163
- connection,
164
- reverseLookupAccounts
165
- );
166
-
167
- return names.map((name) => {
168
- if (name === undefined || name.data === undefined) {
169
- return undefined;
170
- }
171
- let nameLength = new BN(name.data.slice(0, 4), "le").toNumber();
172
- return name.data.slice(4, 4 + nameLength).toString();
173
- });
174
- }
175
-
176
64
  /**
177
65
  * This function can be used to perform a reverse look up
178
66
  * @param connection The Solana RPC connection
@@ -247,58 +135,12 @@ export const findSubdomains = async (
247
135
  return subs.filter((_, idx) => !!subsAcc[idx]);
248
136
  };
249
137
 
250
- const _derive = async (
251
- name: string,
252
- parent: PublicKey = ROOT_DOMAIN_ACCOUNT
253
- ) => {
254
- let hashed = await getHashedName(name);
255
- let pubkey = await getNameAccountKey(hashed, undefined, parent);
256
- return { pubkey, hashed };
257
- };
258
-
259
138
  const _deriveSync = (name: string, parent: PublicKey = ROOT_DOMAIN_ACCOUNT) => {
260
139
  let hashed = getHashedNameSync(name);
261
140
  let pubkey = getNameAccountKeySync(hashed, undefined, parent);
262
141
  return { pubkey, hashed };
263
142
  };
264
143
 
265
- /**
266
- * This function can be used to compute the public key of a domain or subdomain
267
- * @deprecated Use {@link getDomainKeySync} instead
268
- * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
269
- * @param record Optional parameter: If the domain being resolved is a record
270
- * @returns
271
- */
272
- export const getDomainKey = async (domain: string, record = false) => {
273
- if (domain.endsWith(".sol")) {
274
- domain = domain.slice(0, -4);
275
- }
276
- const splitted = domain.split(".");
277
- if (splitted.length === 2) {
278
- const prefix = Buffer.from([record ? 1 : 0]).toString();
279
- const sub = prefix.concat(splitted[0]);
280
- const { pubkey: parentKey } = await _derive(splitted[1]);
281
- const result = await _derive(sub, parentKey);
282
- return { ...result, isSub: true, parent: parentKey };
283
- } else if (splitted.length === 3 && record) {
284
- // Parent key
285
- const { pubkey: parentKey } = await _derive(splitted[2]);
286
- // Sub domain
287
- const { pubkey: subKey } = await _derive(
288
- "\0".concat(splitted[1]),
289
- parentKey
290
- );
291
- // Sub record
292
- const recordPrefix = Buffer.from([1]).toString();
293
- const result = await _derive(recordPrefix.concat(splitted[0]), subKey);
294
- return { ...result, isSub: true, parent: parentKey, isSubRecord: true };
295
- } else if (splitted.length >= 3) {
296
- throw new Error("Invalid derivation input");
297
- }
298
- const result = await _derive(domain, ROOT_DOMAIN_ACCOUNT);
299
- return { ...result, isSub: false, parent: undefined };
300
- };
301
-
302
144
  /**
303
145
  * This function can be used to compute the public key of a domain or subdomain
304
146
  * @param domain The domain to compute the public key for (e.g `bonfida.sol`, `dex.bonfida.sol`)
@@ -386,24 +228,6 @@ export const getAllRegisteredDomains = async (connection: Connection) => {
386
228
  return accounts;
387
229
  };
388
230
 
389
- /**
390
- * This function can be used to get the key of the reverse account
391
- * @deprecated Use {@link getReverseKeySync} instead
392
- * @param domain The domain to compute the reverse for
393
- * @param isSub Whether the domain is a subdomain or not
394
- * @returns The public key of the reverse account
395
- */
396
- export const getReverseKey = async (domain: string, isSub?: boolean) => {
397
- const { pubkey, parent } = await getDomainKey(domain);
398
- const hashedReverseLookup = await getHashedName(pubkey.toBase58());
399
- const reverseLookupAccount = await getNameAccountKey(
400
- hashedReverseLookup,
401
- REVERSE_LOOKUP_CLASS,
402
- isSub ? parent : undefined
403
- );
404
- return reverseLookupAccount;
405
- };
406
-
407
231
  /**
408
232
  * This function can be used to get the key of the reverse account
409
233
  * @param domain The domain to compute the reverse for