@bonfida/spl-name-service 0.1.66 → 0.2.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.
@@ -51,13 +51,16 @@ export declare function transferNameOwnership(connection: Connection, name: stri
51
51
  export declare function deleteNameRegistry(connection: Connection, name: string, refundTargetKey: PublicKey, nameClass?: PublicKey, nameParent?: PublicKey): Promise<TransactionInstruction>;
52
52
  /**
53
53
  * This function can be used to register a .sol domain
54
+ * @param connection The Solana RPC connection object
54
55
  * @param name The domain name to register e.g bonfida if you want to register bonfida.sol
55
56
  * @param space The domain name account size (max 10kB)
56
57
  * @param buyer The public key of the buyer
57
58
  * @param buyerTokenAccount The buyer token account (USDC)
59
+ * @param mint Optional mint used to purchase the domain, defaults to USDC
60
+ * @param referrerKey Optional referrer key
58
61
  * @returns
59
62
  */
60
- export declare const registerDomainName: (name: string, space: number, buyer: PublicKey, buyerTokenAccount: PublicKey) => Promise<TransactionInstruction[][]>;
63
+ export declare const registerDomainName: (connection: Connection, name: string, space: number, buyer: PublicKey, buyerTokenAccount: PublicKey, mint?: PublicKey, referrerKey?: PublicKey) => Promise<TransactionInstruction[][]>;
61
64
  /**
62
65
  *
63
66
  * @param nameAccount The name account to create the reverse account for
@@ -40,3 +40,8 @@ export declare const TWITTER_ROOT_PARENT_REGISTRY_KEY: PublicKey;
40
40
  */
41
41
  export declare const SOL_RECORD_SIG_LEN = 96;
42
42
  export declare const BONFIDA_USDC_BNB: PublicKey;
43
+ export declare const USDC_MINT: PublicKey;
44
+ export declare const REFERRERS: PublicKey[];
45
+ export declare const TOKENS_SYM_MINT: Map<string, string>;
46
+ export declare const PYTH_MAPPING_ACC: PublicKey;
47
+ export declare const VAULT_OWNER: PublicKey;
@@ -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("@pythnetwork/client"),n=require("@bonfida/name-offers"),o=require("tweetnacl");class c 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 u 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 p(t,r,i,a,s,n,o,u,p,l,f){const d=[Buffer.from(Int8Array.from([0])),new c(n.length).toBuffer(),n,o.toBuffer(),u.toBuffer()],y=Buffer.concat(d),w=[{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 p?w.push({pubkey:p,isSigner:!0,isWritable:!1}):w.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l?w.push({pubkey:l,isSigner:!1,isWritable:!1}):w.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),f&&w.push({pubkey:f,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:w,programId:t,data:y})}function l(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new c(a.length).toBuffer(),a],o=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:o})}function f(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),p=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&p.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||p.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),p.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:p,programId:t,data:u})}function d(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 y{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(y.schema,this)}getInstruction(r,i,a,s,n,o,c,u,p,l,f){const d=Buffer.from(this.serialize()),y=[{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:p,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:t.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:y,programId:r,data:d})}}y.schema=new Map([[y,{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 p=Buffer.from(this.serialize());let l=[{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");l.push({pubkey:c,isSigner:!1,isWritable:!0}),l.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:l,programId:t,data:p})}}w.schema=new Map([[w,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class g{constructor(e){this.tag=13,this.name=e.name,this.space=e.space,this.referrerIdxOpt=e.referrerIdxOpt}serialize(){return i.serialize(g.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u,p,l,f,d,y,w,g,m){const b=Buffer.from(this.serialize());let h=[];return h.push({pubkey:r,isSigner:!1,isWritable:!1}),h.push({pubkey:i,isSigner:!1,isWritable:!1}),h.push({pubkey:a,isSigner:!1,isWritable:!0}),h.push({pubkey:s,isSigner:!1,isWritable:!0}),h.push({pubkey:n,isSigner:!1,isWritable:!1}),h.push({pubkey:o,isSigner:!1,isWritable:!1}),h.push({pubkey:c,isSigner:!0,isWritable:!0}),h.push({pubkey:u,isSigner:!1,isWritable:!0}),h.push({pubkey:p,isSigner:!1,isWritable:!1}),h.push({pubkey:l,isSigner:!1,isWritable:!1}),h.push({pubkey:f,isSigner:!1,isWritable:!1}),h.push({pubkey:d,isSigner:!1,isWritable:!0}),h.push({pubkey:y,isSigner:!1,isWritable:!1}),h.push({pubkey:w,isSigner:!1,isWritable:!1}),h.push({pubkey:g,isSigner:!1,isWritable:!1}),m&&h.push({pubkey:m,isSigner:!1,isWritable:!0}),new e.TransactionInstruction({keys:h,programId:t,data:b})}}g.schema=new Map([[g,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const m=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),b=Buffer.from("tokenized_name"),h=async(r,i)=>{try{const[a]=await e.PublicKey.findProgramAddress([b,i.toBuffer()],m);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 S{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,S,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,S,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}}S.HEADER_LEN=96,S.schema=new Map([[S,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class R{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(R.schema,this)}static deserialize(e){return i.deserializeUnchecked(R.schema,R,e)}}R.schema=new Map([[R,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class x{constructor(e){this.mint=e.mint}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:[["mint",[32]]]}]]);const k=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),v="SPL Name Service",E=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),B=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),P=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),I=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),A=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),T=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),W=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),K=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),N=new e.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),D=[],_=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"]]),O=new e.PublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),H=new e.PublicKey("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi");async function L(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return S.retrieve(e,t)}async function F(e){const t=v+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")}async function M(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,k);return s}const C=async(e,t=E)=>{let r=await F(e);return{pubkey:await M(r,void 0,t),hashed:r}},z=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 C(r[1]);return{...await C(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await C(r[2]),{pubkey:t}=await C("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await C(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await C(e,E),isSub:!1,parent:void 0}},U=e=>{const t=v+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")},G=(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,k);return s};async function Y(e,t){const i=U(t.toBase58()),a=G(i,A),{registry:s}=await S.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 q=(e,t=E)=>{let r=U(e);return{pubkey:G(r,void 0,t),hashed:r}},V=(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}=q(r[1]);return{...q(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=q(r[2]),{pubkey:t}=q("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...q(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...q(e,E),isSub:!1,parent:void 0}};async function j(e,t,r,i,a){const s=await F(t),n=await M(s,i,a);let o;o=i||(await S.retrieve(e,n)).registry.owner;return d(k,n,r,o)}class Z{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,Z,r.data.slice(S.HEADER_LEN))}}async function X(t,r,a,s,n){const o=await F(s.toString()),f=await M(o,T,W);let d=i.serialize(Z.schema,new Z({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[p(k,e.SystemProgram.programId,f,s,n,o,new u(await t.getMinimumBalanceForRentExemption(d.length+S.HEADER_LEN)),new c(d.length),T,W,T),l(k,f,new c(0),Buffer.from(d),T)]}Z.schema=new Map([[Z,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const J=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),Q=async(e,t)=>{const r=await M(await F(t.toBase58()),void 0,J),{registry:i}=await S.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return R.deserialize(i.data)};var $;exports.Record=void 0,($=exports.Record||(exports.Record={})).IPFS="IPFS",$.ARWV="ARWV",$.SOL="SOL",$.ETH="ETH",$.BTC="BTC",$.LTC="LTC",$.DOGE="DOGE",$.Email="email",$.Url="url",$.Discord="discord",$.Github="github",$.Reddit="reddit",$.Twitter="twitter",$.Telegram="telegram",$.Pic="pic",$.SHDW="SHDW",$.POINT="POINT",$.BSC="BSC",$.Injective="INJECT";const ee=(e,t)=>{const{pubkey:r}=V(t+"."+e,!0);return r},te=async(e,t,r)=>{var i,a;const s=ee(t,r);let{registry:n}=await S.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},re=async(e,t)=>await te(e,t,exports.Record.SOL),ie=(e,t,r)=>o.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=I,exports.BONFIDA_USDC_BNB=K,exports.HASH_PREFIX=v,exports.MINT_PREFIX=b,exports.Mint=x,exports.NAME_PROGRAM_ID=k,exports.NAME_TOKENIZER_ID=m,exports.NameRegistryState=S,exports.Numberu32=c,exports.Numberu64=u,exports.PYTH_FIDA_PRICE_ACC=P,exports.PYTH_MAPPING_ACC=O,exports.REFERRERS=D,exports.REGISTER_PROGRAM_ID=B,exports.REVERSE_LOOKUP_CLASS=A,exports.ROOT_DOMAIN_ACCOUNT=E,exports.ReverseTwitterRegistryState=Z,exports.SOL_RECORD_SIG_LEN=96,exports.TOKENS_SYM_MINT=_,exports.TOKEN_TLD=J,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=W,exports.TWITTER_VERIFICATION_AUTHORITY=T,exports.TokenData=R,exports.USDC_MINT=N,exports.VAULT_OWNER=H,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await F(e),s=await M(a,void 0,W);return[l(k,s,new c(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await F(t),n=await M(s,void 0,W);let o=[f(k,n,i,r,void 0)];const c=await F(r.toString());return await M(c,T,void 0),o.push(await j(e,r.toString(),a,T,W)),o=o.concat(await X(e,t,n,i,a)),o},exports.checkSolRecord=ie,exports.createInstruction=p,exports.createInstructionV3=g,exports.createNameRegistry=async function(t,r,i,a,s,n,o,l){const f=await F(r),d=await M(f,o,l),y=n||await t.getMinimumBalanceForRentExemption(i);let w;if(l){const{registry:e}=await L(t,l);w=e.owner}return p(k,e.SystemProgram.programId,d,s,a,f,new u(y),new c(i),o,l,w)},exports.createReverseInstruction=w,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),o=await F(t.toBase58()),c=await M(o,n,a);return[[],[new w({name:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,k,E,c,n,i,a,s)]]},exports.createReverseTwitterRegistry=X,exports.createV2Instruction=y,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await F(r),o=await M(n,void 0,W),l=await t.getMinimumBalanceForRentExemption(a+S.HEADER_LEN);let f=[p(k,e.SystemProgram.programId,o,i,s,n,new u(l),new c(a),void 0,W,T)];return f=f.concat(await X(t,r,o,i,s)),f},exports.deleteInstruction=d,exports.deleteNameRegistry=j,exports.deleteTwitterRegistry=async function(e,t){const r=await F(e),i=await M(r,void 0,W),a=await F(t.toString()),s=await M(a,T,W);return[d(k,i,t,t),d(k,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:A.toBase58()}}],i=await e.getProgramAccounts(k,{filters:r}),a=await Y(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=>V(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:E.toBase58()}}];return(await e.getProgramAccounts(k,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:E.toBase58()}}];return await e.getProgramAccounts(k,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await te(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await te(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await te(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await te(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await te(e,t,exports.Record.DOGE),exports.getDomainKey=z,exports.getDomainKeySync=V,exports.getEmailRecord=async(e,t)=>await te(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await te(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await n.FavouriteDomain.getKey(n.NAME_OFFERS_ID,new e.PublicKey(r)),a=await n.FavouriteDomain.retrieve(t,i),s=await Y(t,a.nameAccount);return{domain:a.nameAccount,reverse:s}},exports.getGithubRecord=async(e,t)=>await te(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await F(r.toString()),a=await M(i,T,W);let s=await Z.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=F,exports.getHashedNameSync=U,exports.getInjectiveRecord=async(e,t)=>await te(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await te(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await te(e,t,exports.Record.LTC),exports.getNameAccountKey=M,exports.getNameAccountKeySync=G,exports.getNameOwner=L,exports.getPicRecord=async(e,t)=>await te(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await te(e,t,exports.Record.POINT),exports.getRecord=te,exports.getRecordKeySync=ee,exports.getRedditRecord=async(e,t)=>await te(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await z(e),a=await F(r.toBase58());return await M(a,A,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=V(e),a=U(r.toBase58());return G(a,A,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await te(e,t,exports.Record.SHDW),exports.getSolRecord=re,exports.getTelegramRecord=async(e,t)=>await te(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=Q,exports.getTokenInfoFromName=async(t,r)=>{const i=await M(await F(r),void 0,J),{registry:a}=await S.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(x.deserialize(a.data).mint);return await Q(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:T.toBase58()}}],s=await t.getProgramAccounts(k,{filters:a});for(const t of s)if(t.account.data.length>S.HEADER_LEN+32){let r=t.account.data.slice(S.HEADER_LEN),a=i.deserializeUnchecked(Z.schema,Z,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await te(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await F(t),i=await M(r,void 0,W),{registry:a}=await S.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(k,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(S.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await F(e);return await M(t,void 0,W)},exports.getUrlRecord=async(e,t)=>await te(e,t,exports.Record.Url),exports.performReverseLookup=async function(e,t){const i=await F(t.toBase58()),a=await M(i,A),{registry:s}=await S.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 F(e.toBase58()),r=await M(t,A);i.push(r)}return(await S.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(r,i,a,n,o,c=N,u)=>{const[p]=e.PublicKey.findProgramAddressSync([B.toBuffer()],B),l=U(i),f=G(l,void 0,E),d=U(f.toBase58()),y=G(d,p),[w]=e.PublicKey.findProgramAddressSync([f.toBuffer()],B),m=D.findIndex((e=>null==u?void 0:u.equals(e))),b=new s.PythHttpClient(r,s.getPythProgramKeyForCluster("mainnet-beta")),h=await b.getData(),S=_.get(c.toBase58());if(!S)throw new Error("Symbol not found");const R=h.productPrice.get("Crypto."+S+"/USD"),x=h.productFromSymbol.get("Crypto."+S+"/USD"),v=t.getAssociatedTokenAddressSync(c,H);return[[],[new g({name:i,space:a,referrerIdxOpt:-1!=m?m:null}).getInstruction(B,k,E,f,y,e.SystemProgram.programId,p,n,o,O,R.productAccountKey,new e.PublicKey(x.price_account),v,t.TOKEN_PROGRAM_ID,e.SYSVAR_RENT_PUBKEY,w,u)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=V(r),{registry:a,nftOwner:s}=await S.retrieve(t,i);if(s)return s;try{const i=V(exports.Record.SOL+"."+r,!0),s=await re(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(!ie(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=Y,exports.reverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=U(e.toBase58()),r=G(t,A);i.push(r)}return(await S.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=f,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await F(t),o=await M(n,i,a);let c;return c=i||(await S.retrieve(e,o)).registry.owner,f(k,o,r,c,i,a,s)},exports.updateInstruction=l,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await F(t),o=await M(n,a,s);let u;return u=a||(await S.retrieve(e,o)).registry.owner,l(k,o,new c(r),i,u)};
@@ -2,6 +2,11 @@
2
2
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
3
3
  import { Numberu32, Numberu64 } from "./int";
4
4
  import { Schema } from "borsh";
5
+ export interface AccountKey {
6
+ pubkey: PublicKey;
7
+ isSigner: boolean;
8
+ isWritable: boolean;
9
+ }
5
10
  export declare function createInstruction(nameProgramId: PublicKey, systemProgramId: PublicKey, nameKey: PublicKey, nameOwnerKey: PublicKey, payerKey: PublicKey, hashed_name: Buffer, lamports: Numberu64, space: Numberu32, nameClassKey?: PublicKey, nameParent?: PublicKey, nameParentOwner?: PublicKey): TransactionInstruction;
6
11
  export declare function updateInstruction(nameProgramId: PublicKey, nameAccountKey: PublicKey, offset: Numberu32, input_data: Buffer, nameUpdateSigner: PublicKey): TransactionInstruction;
7
12
  export declare function transferInstruction(nameProgramId: PublicKey, nameAccountKey: PublicKey, newOwnerKey: PublicKey, currentNameOwnerKey: PublicKey, nameClassKey?: PublicKey, nameParent?: PublicKey, parentOwner?: PublicKey): TransactionInstruction;
@@ -28,3 +33,17 @@ export declare class createReverseInstruction {
28
33
  serialize(): Uint8Array;
29
34
  getInstruction(programId: PublicKey, rentSysvarAccount: PublicKey, namingServiceProgram: PublicKey, rootDomain: PublicKey, reverseLookupAccount: PublicKey, centralStateAccount: PublicKey, feePayer: PublicKey, parentName?: PublicKey, parentNameOwner?: PublicKey): TransactionInstruction;
30
35
  }
36
+ export declare class createInstructionV3 {
37
+ tag: number;
38
+ name: string;
39
+ space: number;
40
+ referrerIdxOpt: number | null;
41
+ static schema: Schema;
42
+ constructor(obj: {
43
+ name: string;
44
+ space: number;
45
+ referrerIdxOpt: number | null;
46
+ });
47
+ serialize(): Uint8Array;
48
+ getInstruction(programId: PublicKey, namingServiceProgram: PublicKey, rootDomain: PublicKey, name: PublicKey, reverseLookup: PublicKey, systemProgram: PublicKey, centralState: PublicKey, buyer: PublicKey, buyerTokenSource: PublicKey, pythMappingAcc: PublicKey, pythProductAcc: PublicKey, pythPriceAcc: PublicKey, vault: PublicKey, splTokenProgram: PublicKey, rentSysvar: PublicKey, state: PublicKey, referrerAccountOpt?: PublicKey): TransactionInstruction;
49
+ }
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.2.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -54,7 +54,8 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@bonfida/name-offers": "^0.0.4",
57
- "@ethersproject/sha2": "^5.5.0"
57
+ "@ethersproject/sha2": "^5.5.0",
58
+ "@pythnetwork/client": "^2.17.0"
58
59
  },
59
60
  "peerDependencies": {
60
61
  "@solana/buffer-layout": "^4.0.0",
package/src/bindings.ts CHANGED
@@ -10,18 +10,35 @@ import {
10
10
  deleteInstruction,
11
11
  transferInstruction,
12
12
  updateInstruction,
13
- createV2Instruction,
14
13
  createReverseInstruction,
14
+ createInstructionV3,
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,
22
26
  REGISTER_PROGRAM_ID,
23
- BONFIDA_USDC_BNB,
27
+ REFERRERS,
28
+ USDC_MINT,
29
+ TOKENS_SYM_MINT,
30
+ PYTH_MAPPING_ACC,
31
+ VAULT_OWNER,
24
32
  } from "./constants";
33
+ import {
34
+ getPythProgramKeyForCluster,
35
+ PythHttpClient,
36
+ } from "@pythnetwork/client";
37
+ import { getHashedNameSync, getNameAccountKeySync } from "./utils";
38
+ import {
39
+ TOKEN_PROGRAM_ID,
40
+ getAssociatedTokenAddressSync,
41
+ } from "@solana/spl-token";
25
42
 
26
43
  /**
27
44
  * Creates a name account with the given rent budget, allocated space, owner and class.
@@ -223,53 +240,85 @@ export async function deleteNameRegistry(
223
240
 
224
241
  /**
225
242
  * This function can be used to register a .sol domain
243
+ * @param connection The Solana RPC connection object
226
244
  * @param name The domain name to register e.g bonfida if you want to register bonfida.sol
227
245
  * @param space The domain name account size (max 10kB)
228
246
  * @param buyer The public key of the buyer
229
247
  * @param buyerTokenAccount The buyer token account (USDC)
248
+ * @param mint Optional mint used to purchase the domain, defaults to USDC
249
+ * @param referrerKey Optional referrer key
230
250
  * @returns
231
251
  */
232
252
  export const registerDomainName = async (
253
+ connection: Connection,
233
254
  name: string,
234
255
  space: number,
235
256
  buyer: PublicKey,
236
- buyerTokenAccount: PublicKey
257
+ buyerTokenAccount: PublicKey,
258
+ mint = USDC_MINT,
259
+ referrerKey?: PublicKey
237
260
  ) => {
238
- const [centralState] = await PublicKey.findProgramAddress(
261
+ const [cs] = PublicKey.findProgramAddressSync(
239
262
  [REGISTER_PROGRAM_ID.toBuffer()],
240
263
  REGISTER_PROGRAM_ID
241
264
  );
242
265
 
243
- const hashed = await getHashedName(name);
244
- const nameAccount = await getNameAccountKey(
266
+ const hashed = getHashedNameSync(name);
267
+ const nameAccount = getNameAccountKeySync(
245
268
  hashed,
246
269
  undefined,
247
270
  ROOT_DOMAIN_ACCOUNT
248
271
  );
249
272
 
250
- const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
251
- const reverseLookupAccount = await getNameAccountKey(
252
- hashedReverseLookup,
253
- centralState
254
- );
273
+ const hashedReverseLookup = getHashedNameSync(nameAccount.toBase58());
274
+ const reverseLookupAccount = getNameAccountKeySync(hashedReverseLookup, cs);
255
275
 
256
- const [derived_state] = await PublicKey.findProgramAddress(
276
+ const [derived_state] = PublicKey.findProgramAddressSync(
257
277
  [nameAccount.toBuffer()],
258
278
  REGISTER_PROGRAM_ID
259
279
  );
260
280
 
261
- const ix = new createV2Instruction({ name, space }).getInstruction(
281
+ const referrerIdx = REFERRERS.findIndex((e) => referrerKey?.equals(e));
282
+
283
+ const pythConnection = new PythHttpClient(
284
+ connection,
285
+ getPythProgramKeyForCluster("mainnet-beta")
286
+ );
287
+ const data = await pythConnection.getData();
288
+
289
+ const symbol = TOKENS_SYM_MINT.get(mint.toBase58());
290
+
291
+ if (!symbol) {
292
+ throw new Error("Symbol not found");
293
+ }
294
+
295
+ const priceData = data.productPrice.get("Crypto." + symbol + "/USD")!;
296
+ const productData = data.productFromSymbol.get("Crypto." + symbol + "/USD")!;
297
+
298
+ const vault = getAssociatedTokenAddressSync(mint, VAULT_OWNER);
299
+
300
+ const ix = new createInstructionV3({
301
+ name,
302
+ space,
303
+ referrerIdxOpt: referrerIdx != -1 ? referrerIdx : null,
304
+ }).getInstruction(
262
305
  REGISTER_PROGRAM_ID,
263
- SYSVAR_RENT_PUBKEY,
264
306
  NAME_PROGRAM_ID,
265
307
  ROOT_DOMAIN_ACCOUNT,
266
308
  nameAccount,
267
309
  reverseLookupAccount,
268
- centralState,
310
+ SystemProgram.programId,
311
+ cs,
269
312
  buyer,
270
313
  buyerTokenAccount,
271
- BONFIDA_USDC_BNB,
272
- derived_state
314
+ PYTH_MAPPING_ACC,
315
+ priceData.productAccountKey,
316
+ new PublicKey(productData.price_account),
317
+ vault,
318
+ TOKEN_PROGRAM_ID,
319
+ SYSVAR_RENT_PUBKEY,
320
+ derived_state,
321
+ referrerKey
273
322
  );
274
323
 
275
324
  return [[], [ix]];
package/src/constants.ts CHANGED
@@ -69,3 +69,26 @@ export const SOL_RECORD_SIG_LEN = 96;
69
69
  export const BONFIDA_USDC_BNB = new PublicKey(
70
70
  "DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"
71
71
  );
72
+
73
+ export const USDC_MINT = new PublicKey(
74
+ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
75
+ );
76
+
77
+ export const REFERRERS: PublicKey[] = [];
78
+
79
+ export const TOKENS_SYM_MINT = new Map<string, string>([
80
+ ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "USDC"],
81
+ ["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", "USDT"],
82
+ ["So11111111111111111111111111111111111111112", "SOL"],
83
+ ["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp", "FIDA"],
84
+ ["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf", "ETH"],
85
+ ["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So", "MSOL"],
86
+ ]);
87
+
88
+ export const PYTH_MAPPING_ACC = new PublicKey(
89
+ "AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"
90
+ );
91
+
92
+ export const VAULT_OWNER = new PublicKey(
93
+ "GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"
94
+ );
@@ -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";
@@ -7,6 +7,12 @@ import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
7
7
  import { Numberu32, Numberu64 } from "./int";
8
8
  import { Schema, serialize } from "borsh";
9
9
 
10
+ export interface AccountKey {
11
+ pubkey: PublicKey;
12
+ isSigner: boolean;
13
+ isWritable: boolean;
14
+ }
15
+
10
16
  export function createInstruction(
11
17
  nameProgramId: PublicKey,
12
18
  systemProgramId: PublicKey,
@@ -434,3 +440,146 @@ export class createReverseInstruction {
434
440
  });
435
441
  }
436
442
  }
443
+
444
+ export class createInstructionV3 {
445
+ tag: number;
446
+ name: string;
447
+ space: number;
448
+ referrerIdxOpt: number | null;
449
+ static schema: Schema = new Map([
450
+ [
451
+ createInstructionV3,
452
+ {
453
+ kind: "struct",
454
+ fields: [
455
+ ["tag", "u8"],
456
+ ["name", "string"],
457
+ ["space", "u32"],
458
+ ["referrerIdxOpt", { kind: "option", type: "u16" }],
459
+ ],
460
+ },
461
+ ],
462
+ ]);
463
+ constructor(obj: {
464
+ name: string;
465
+ space: number;
466
+ referrerIdxOpt: number | null;
467
+ }) {
468
+ this.tag = 13;
469
+ this.name = obj.name;
470
+ this.space = obj.space;
471
+ this.referrerIdxOpt = obj.referrerIdxOpt;
472
+ }
473
+ serialize(): Uint8Array {
474
+ return serialize(createInstructionV3.schema, this);
475
+ }
476
+ getInstruction(
477
+ programId: PublicKey,
478
+ namingServiceProgram: PublicKey,
479
+ rootDomain: PublicKey,
480
+ name: PublicKey,
481
+ reverseLookup: PublicKey,
482
+ systemProgram: PublicKey,
483
+ centralState: PublicKey,
484
+ buyer: PublicKey,
485
+ buyerTokenSource: PublicKey,
486
+ pythMappingAcc: PublicKey,
487
+ pythProductAcc: PublicKey,
488
+ pythPriceAcc: PublicKey,
489
+ vault: PublicKey,
490
+ splTokenProgram: PublicKey,
491
+ rentSysvar: PublicKey,
492
+ state: PublicKey,
493
+ referrerAccountOpt?: PublicKey
494
+ ): TransactionInstruction {
495
+ const data = Buffer.from(this.serialize());
496
+ let keys: AccountKey[] = [];
497
+ keys.push({
498
+ pubkey: namingServiceProgram,
499
+ isSigner: false,
500
+ isWritable: false,
501
+ });
502
+ keys.push({
503
+ pubkey: rootDomain,
504
+ isSigner: false,
505
+ isWritable: false,
506
+ });
507
+ keys.push({
508
+ pubkey: name,
509
+ isSigner: false,
510
+ isWritable: true,
511
+ });
512
+ keys.push({
513
+ pubkey: reverseLookup,
514
+ isSigner: false,
515
+ isWritable: true,
516
+ });
517
+ keys.push({
518
+ pubkey: systemProgram,
519
+ isSigner: false,
520
+ isWritable: false,
521
+ });
522
+ keys.push({
523
+ pubkey: centralState,
524
+ isSigner: false,
525
+ isWritable: false,
526
+ });
527
+ keys.push({
528
+ pubkey: buyer,
529
+ isSigner: true,
530
+ isWritable: true,
531
+ });
532
+ keys.push({
533
+ pubkey: buyerTokenSource,
534
+ isSigner: false,
535
+ isWritable: true,
536
+ });
537
+ keys.push({
538
+ pubkey: pythMappingAcc,
539
+ isSigner: false,
540
+ isWritable: false,
541
+ });
542
+ keys.push({
543
+ pubkey: pythProductAcc,
544
+ isSigner: false,
545
+ isWritable: false,
546
+ });
547
+ keys.push({
548
+ pubkey: pythPriceAcc,
549
+ isSigner: false,
550
+ isWritable: false,
551
+ });
552
+ keys.push({
553
+ pubkey: vault,
554
+ isSigner: false,
555
+ isWritable: true,
556
+ });
557
+ keys.push({
558
+ pubkey: splTokenProgram,
559
+ isSigner: false,
560
+ isWritable: false,
561
+ });
562
+ keys.push({
563
+ pubkey: rentSysvar,
564
+ isSigner: false,
565
+ isWritable: false,
566
+ });
567
+ keys.push({
568
+ pubkey: state,
569
+ isSigner: false,
570
+ isWritable: false,
571
+ });
572
+ if (!!referrerAccountOpt) {
573
+ keys.push({
574
+ pubkey: referrerAccountOpt,
575
+ isSigner: false,
576
+ isWritable: true,
577
+ });
578
+ }
579
+ return new TransactionInstruction({
580
+ keys,
581
+ programId,
582
+ data,
583
+ });
584
+ }
585
+ }
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