@bonfida/spl-name-service 0.2.13 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bindings.d.ts +27 -0
- package/dist/error.d.ts +27 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/record.d.ts +52 -31
- package/dist/types/record.d.ts +6 -1
- package/dist/utils.d.ts +2 -0
- package/package.json +4 -1
package/dist/bindings.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
3
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
4
|
+
import { Record } from "./types/record";
|
|
4
5
|
/**
|
|
5
6
|
* Creates a name account with the given rent budget, allocated space, owner and class.
|
|
6
7
|
*
|
|
@@ -32,6 +33,7 @@ export declare function updateNameRegistryData(connection: Connection, name: str
|
|
|
32
33
|
* @param connection The solana connection object to the RPC node
|
|
33
34
|
* @param name The name of the name account
|
|
34
35
|
* @param newOwner The new owner to be set
|
|
36
|
+
* @param curentNameOwner the current name Owner
|
|
35
37
|
* @param nameClass The class of this name, if it exsists
|
|
36
38
|
* @param nameParent The parent name of this name, if it exists
|
|
37
39
|
* @param parentOwner Parent name owner
|
|
@@ -79,3 +81,28 @@ export declare const createReverseName: (nameAccount: PublicKey, name: string, f
|
|
|
79
81
|
* @param space The space to allocate to the subdomain (defaults to 2kb)
|
|
80
82
|
*/
|
|
81
83
|
export declare const createSubdomain: (connection: Connection, subdomain: string, owner: PublicKey, space?: number) => Promise<TransactionInstruction[][]>;
|
|
84
|
+
/**
|
|
85
|
+
* This function can be used be create a record, it handles the serialization of the record data
|
|
86
|
+
* To create a SOL record use `createSolRecordInstruction`
|
|
87
|
+
* @param connection The Solana RPC connection object
|
|
88
|
+
* @param domain The .sol domain name
|
|
89
|
+
* @param record The record enum object
|
|
90
|
+
* @param data The data (as a UTF-8 string) to store in the record account
|
|
91
|
+
* @param owner The owner of the domain
|
|
92
|
+
* @param payer The fee payer of the transaction
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
export declare const createRecordInstruction: (connection: Connection, domain: string, record: Record, data: string, owner: PublicKey, payer: PublicKey) => Promise<TransactionInstruction>;
|
|
96
|
+
export declare const updateRecordInstruction: (connection: Connection, domain: string, record: Record, data: string, owner: PublicKey, payer: PublicKey) => Promise<TransactionInstruction[]>;
|
|
97
|
+
/**
|
|
98
|
+
* This function can be used to create a SOL record
|
|
99
|
+
* @param connection The Solana RPC connection object
|
|
100
|
+
* @param domain The .sol domain name
|
|
101
|
+
* @param content The content of the SOL record i.e the public key to store as destination of the domain
|
|
102
|
+
* @param signer The signer of the SOL record i.e the owner of the domain
|
|
103
|
+
* @param signature The signature of the record
|
|
104
|
+
* @param payer The fee payer of the transaction
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
export declare const createSolRecordInstruction: (connection: Connection, domain: string, content: PublicKey, signer: PublicKey, signature: Uint8Array, payer: PublicKey) => Promise<TransactionInstruction[]>;
|
|
108
|
+
export declare const updateSolRecordInstruction: (connection: Connection, domain: string, content: PublicKey, signer: PublicKey, signature: Uint8Array, payer: PublicKey) => Promise<(TransactionInstruction | TransactionInstruction[])[]>;
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum ErrorType {
|
|
2
|
+
SymbolNotFound = "SymbolNotFound",
|
|
3
|
+
InvalidSubdomain = "InvalidSubdomain",
|
|
4
|
+
FavouriteDomainNotFound = "FavouriteDomainNotFound",
|
|
5
|
+
MissingParentOwner = "MissingParentOwner",
|
|
6
|
+
U32Overflow = "U32Overflow",
|
|
7
|
+
InvalidBufferLength = "InvalidBufferLength",
|
|
8
|
+
U64Overflow = "U64Overflow",
|
|
9
|
+
NoRecordData = "NoRecordData",
|
|
10
|
+
InvalidRecordData = "InvalidRecordData",
|
|
11
|
+
UnsupportedRecord = "UnsupportedRecord",
|
|
12
|
+
InvalidEvmAddress = "InvalidEvmAddress",
|
|
13
|
+
InvalidInjectiveAddress = "InvalidInjectiveAddress",
|
|
14
|
+
InvalidARecord = "InvalidARecord",
|
|
15
|
+
InvalidAAAARecord = "InvalidAAAARecord",
|
|
16
|
+
InvalidRecordInput = "InvalidRecordInput",
|
|
17
|
+
InvalidSignature = "InvalidSignature",
|
|
18
|
+
AccountDoesNotExist = "AccountDoesNotExist",
|
|
19
|
+
MultipleRegistries = "MultipleRegistries",
|
|
20
|
+
InvalidReverseTwitter = "InvalidReverseTwitter",
|
|
21
|
+
NoAccountData = "NoAccountData",
|
|
22
|
+
InvalidInput = "InvalidInput"
|
|
23
|
+
}
|
|
24
|
+
export declare class SNSError extends Error {
|
|
25
|
+
type: ErrorType;
|
|
26
|
+
constructor(type: ErrorType, message?: string);
|
|
27
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@solana/web3.js"),t=require("buffer"),r=require("@solana/spl-token"),i=require("bn.js"),a=require("borsh"),s=require("@bonfida/name-tokenizer"),n=require("@ethersproject/sha2"),o=require("@pythnetwork/client");function c(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=c(require("tweetnacl"));class p extends i{toBuffer(){const e=super.toArray().reverse(),r=t.Buffer.from(e);if(4===r.length)return r;if(r.length>4)throw new Error("Numberu32 too large");const i=t.Buffer.alloc(4);return r.copy(i),i}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new i([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class l extends i{toBuffer(){const e=super.toArray().reverse(),r=t.Buffer.from(e);if(8===r.length)return r;if(r.length>8)throw new Error("Numberu64 too large");const i=t.Buffer.alloc(8);return r.copy(i),i}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new i([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function f(r,i,a,s,n,o,c,u,l,f,d){const y=[t.Buffer.from(Int8Array.from([0])),new p(o.length).toBuffer(),o,c.toBuffer(),u.toBuffer()],w=t.Buffer.concat(y),g=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1}];return l?g.push({pubkey:l,isSigner:!0,isWritable:!1}):g.push({pubkey:new e.PublicKey(t.Buffer.alloc(32)),isSigner:!1,isWritable:!1}),f?g.push({pubkey:f,isSigner:!1,isWritable:!1}):g.push({pubkey:new e.PublicKey(t.Buffer.alloc(32)),isSigner:!1,isWritable:!1}),d&&g.push({pubkey:d,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:g,programId:r,data:w})}function d(r,i,a,s,n){const o=[t.Buffer.from(Int8Array.from([1])),a.toBuffer(),new p(s.length).toBuffer(),s],c=t.Buffer.concat(o),u=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:r,data:c})}function y(r,i,a,s,n,o,c){const u=[t.Buffer.from(Int8Array.from([2])),a.toBuffer()],p=t.Buffer.concat(u),l=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:c||s,isSigner:!0,isWritable:!1}];return n&&l.push({pubkey:n,isSigner:!0,isWritable:!1}),c&&o&&(n||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:o,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:r,data:p})}function w(r,i,a,s){const n=[t.Buffer.from(Int8Array.from([3]))],o=t.Buffer.concat(n),c=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:c,programId:r,data:o})}class g{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return a.serialize(g.schema,this)}getInstruction(i,a,s,n,o,c,u,p,l,f,d){const y=t.Buffer.from(this.serialize()),w=[{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:f,isSigner:!1,isWritable:!0},{pubkey:r.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:w,programId:i,data:y})}}g.schema=new Map([[g,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class m{constructor(e){this.tag=5,this.name=e.name}serialize(){return a.serialize(m.schema,this)}getInstruction(r,i,a,s,n,o,c,u,p){const l=t.Buffer.from(this.serialize());let f=[{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:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!0,isWritable:!0}];if(u){if(!p)throw new Error("Missing parent name owner");f.push({pubkey:u,isSigner:!1,isWritable:!0}),f.push({pubkey:p,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:f,programId:r,data:l})}}m.schema=new Map([[m,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class b{constructor(e){this.tag=13,this.name=e.name,this.space=e.space,this.referrerIdxOpt=e.referrerIdxOpt}serialize(){return a.serialize(b.schema,this)}getInstruction(r,i,a,s,n,o,c,u,p,l,f,d,y,w,g,m,b){const h=t.Buffer.from(this.serialize());let S=[];return S.push({pubkey:i,isSigner:!1,isWritable:!1}),S.push({pubkey:a,isSigner:!1,isWritable:!1}),S.push({pubkey:s,isSigner:!1,isWritable:!0}),S.push({pubkey:n,isSigner:!1,isWritable:!0}),S.push({pubkey:o,isSigner:!1,isWritable:!1}),S.push({pubkey:c,isSigner:!1,isWritable:!1}),S.push({pubkey:u,isSigner:!0,isWritable:!0}),S.push({pubkey:p,isSigner:!1,isWritable:!0}),S.push({pubkey:l,isSigner:!1,isWritable:!1}),S.push({pubkey:f,isSigner:!1,isWritable:!1}),S.push({pubkey:d,isSigner:!1,isWritable:!1}),S.push({pubkey:y,isSigner:!1,isWritable:!0}),S.push({pubkey:w,isSigner:!1,isWritable:!1}),S.push({pubkey:g,isSigner:!1,isWritable:!1}),S.push({pubkey:m,isSigner:!1,isWritable:!1}),b&&S.push({pubkey:b,isSigner:!1,isWritable:!0}),new e.TransactionInstruction({keys:S,programId:r,data:h})}}b.schema=new Map([[b,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const h=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),S="SPL Name Service",R=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),x=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),k=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),v=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),E=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),B=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),P=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),A=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),I=new e.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),K=[new e.PublicKey("3ogYncmMM5CmytsGCqKHydmXmKUZ6sGWvizkzqwT7zb1"),new e.PublicKey("DM1jJCkZZEwY5tmWbgvKRxsDFzXCdbfrYCCH1CtwguEs"),new e.PublicKey("ADCp4QXFajHrhy4f43pD6GJFtQLkdBY2mjS9DfCk7tNW")],T=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx","GMT"],["AFbX8oGjGpmVFywbVouvhQSRmiW2aR1mohfahi4Y2AdB","GST"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"],["DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263","BONK"],["EPeUFDgHRxs9xxEPVaL6kfGQvCon7jmAWKVUHuux1Tpz","BAT"]]),W=new e.PublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),N=new e.PublicKey("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"),D=e=>{const r=S+e,i=n.sha256(t.Buffer.from(r,"utf8")).slice(2);return t.Buffer.from(i,"hex")},_=(r,i,a)=>{const s=[r];i?s.push(i.toBuffer()):s.push(t.Buffer.alloc(32)),a?s.push(a.toBuffer()):s.push(t.Buffer.alloc(32));const[n]=e.PublicKey.findProgramAddressSync(s,h);return n};async function O(e,t){const r=D(t.toBase58()),a=_(r,E),{registry:s}=await G.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new i(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}async function z(e,t){let r=[];for(let e of t){const t=D(e.toBase58()),i=_(t,E);r.push(i)}return(await G.retrieveBatch(e,r)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new i(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))}const H=(e,t=R)=>{let r=D(e);return{pubkey:_(r,void 0,t),hashed:r}},M=(e,r=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const i=e.split(".");if(2===i.length){const e=t.Buffer.from([r?1:0]).toString().concat(i[0]),{pubkey:a}=H(i[1]);return{...H(e,a),isSub:!0,parent:a}}if(3===i.length&&r){const{pubkey:e}=H(i[2]),{pubkey:r}=H("\0".concat(i[1]),e),a=t.Buffer.from([1]).toString();return{...H(a.concat(i[0]),r),isSub:!0,parent:e,isSubRecord:!0}}if(i.length>=3)throw new Error("Invalid derivation input");return{...H(e,R),isSub:!1,parent:void 0}};const F=async(t,i)=>{try{const[a]=await e.PublicKey.findProgramAddress([s.MINT_PREFIX,i.toBuffer()],s.NAME_TOKENIZER_ID);if("0"===(await r.getMint(t,a)).supply.toString())return;const n=[{memcmp:{offset:0,bytes:a.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],o=await t.getProgramAccounts(r.TOKEN_PROGRAM_ID,{filters:n});if(1!=o.length)return;return new e.PublicKey(o[0].account.data.slice(32,64))}catch{return}},L=e=>[{memcmp:{offset:32,bytes:e}},{memcmp:{offset:64,bytes:"2"}}],C=async(e,t)=>{const i=[...L(t.toBase58()),{dataSize:165}],a=(await e.getProgramAccounts(r.TOKEN_PROGRAM_ID,{filters:i})).map((e=>r.AccountLayout.decode(e.account.data))).map((t=>(async(e,t)=>{const r=await s.getRecordFromMint(e,t.mint);if(1===r.length)return s.NftRecord.deserialize(r[0].account.data)})(e,t)));return(await Promise.all(a)).filter((e=>void 0!==e))};class G{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 i=await e.getAccountInfo(t);if(!i)throw new Error("Invalid name account provided");let s=a.deserializeUnchecked(this.schema,G,i.data);s.data=null===(r=i.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await F(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),i=e=>{if(!e)return;const t=a.deserializeUnchecked(this.schema,G,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>i(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}}G.HEADER_LEN=96,G.schema=new Map([[G,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class U{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 a.serialize(U.schema,this)}static deserialize(e){return a.deserializeUnchecked(U.schema,U,e)}}U.schema=new Map([[U,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class Y{constructor(e){this.mint=e.mint}serialize(){return a.serialize(Y.schema,this)}static deserialize(e){return a.deserializeUnchecked(Y.schema,Y,e)}}async function j(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return G.retrieve(e,t)}async function V(e){const r=S+e,i=n.sha256(t.Buffer.from(r,"utf8")).slice(2);return t.Buffer.from(i,"hex")}async function q(r,i,a){const s=[r];i?s.push(i.toBuffer()):s.push(t.Buffer.alloc(32)),a?s.push(a.toBuffer()):s.push(t.Buffer.alloc(32));const[n]=await e.PublicKey.findProgramAddress(s,h);return n}Y.schema=new Map([[Y,{kind:"struct",fields:[["mint",[32]]]}]]);const X=async(e,t=R)=>{let r=await V(e);return{pubkey:await q(r,void 0,t),hashed:r}},Z=async(e,r=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const i=e.split(".");if(2===i.length){const e=t.Buffer.from([r?1:0]).toString().concat(i[0]),{pubkey:a}=await X(i[1]);return{...await X(e,a),isSub:!0,parent:a}}if(3===i.length&&r){const{pubkey:e}=await X(i[2]),{pubkey:r}=await X("\0".concat(i[1]),e),a=t.Buffer.from([1]).toString();return{...await X(a.concat(i[0]),r),isSub:!0,parent:e,isSubRecord:!0}}if(i.length>=3)throw new Error("Invalid derivation input");return{...await X(e,R),isSub:!1,parent:void 0}};async function J(t,r,i,a,s,n,o,c){const u=await V(r),d=await q(u,o,c),y=n||await t.getMinimumBalanceForRentExemption(i);let w;if(c){const{registry:e}=await j(t,c);w=e.owner}return f(h,e.SystemProgram.programId,d,s,a,u,new l(y),new p(i),o,c,w)}async function Q(e,t,r,i,a){const s=await V(t),n=await q(s,i,a);let o;o=i||(await G.retrieve(e,n)).registry.owner;return w(h,n,r,o)}const $=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([x.toBuffer()],x),o=await V(t.toBase58()),c=await q(o,n,a);return[[],[new m({name:r}).getInstruction(x,e.SYSVAR_RENT_PUBKEY,h,R,c,n,i,a,s)]]};class ee{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 a.deserializeUnchecked(this.schema,ee,r.data.slice(G.HEADER_LEN))}}async function te(r,i,s,n,o){const c=await V(n.toString()),u=await q(c,B,P);let y=a.serialize(ee.schema,new ee({twitterRegistryKey:s.toBytes(),twitterHandle:i}));return[f(h,e.SystemProgram.programId,u,n,o,c,new l(await r.getMinimumBalanceForRentExemption(y.length+G.HEADER_LEN)),new p(y.length),B,P,B),d(h,u,new p(0),t.Buffer.from(y),B)]}ee.schema=new Map([[ee,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const re=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),ie=async(e,t)=>{const r=await q(await V(t.toBase58()),void 0,re),{registry:i}=await G.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return U.deserialize(i.data)},ae=new e.PublicKey("85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29");class se{constructor(t){this.tag=t.tag,this.nameAccount=new e.PublicKey(t.nameAccount)}static deserialize(e){return a.deserialize(this.schema,se,e)}static async retrieve(e,t){const r=await e.getAccountInfo(t);if(!r||!r.data)throw new Error("Favourite domain not found");return this.deserialize(r.data)}static async getKey(r,i){return await e.PublicKey.findProgramAddress([t.Buffer.from("favourite_domain"),i.toBuffer()],r)}static getKeySync(r,i){return e.PublicKey.findProgramAddressSync([t.Buffer.from("favourite_domain"),i.toBuffer()],r)}}se.schema=new Map([[se,{kind:"struct",fields:[["tag","u8"],["nameAccount",[32]]]}]]);var ne;exports.Record=void 0,(ne=exports.Record||(exports.Record={})).IPFS="IPFS",ne.ARWV="ARWV",ne.SOL="SOL",ne.ETH="ETH",ne.BTC="BTC",ne.LTC="LTC",ne.DOGE="DOGE",ne.Email="email",ne.Url="url",ne.Discord="discord",ne.Github="github",ne.Reddit="reddit",ne.Twitter="twitter",ne.Telegram="telegram",ne.Pic="pic",ne.SHDW="SHDW",ne.POINT="POINT",ne.BSC="BSC",ne.Injective="INJ",ne.Backpack="backpack";const oe=e=>{if(!e)return;const t=Array.from(e);return t.length-1-t.reverse().findIndex((e=>0!==e))+1},ce=(e,t)=>{const{pubkey:r}=M(t+"."+e,!0);return r},ue=async(e,t,r)=>{var i;const a=ce(t,r);let{registry:s}=await G.retrieve(e,a);const n=r===exports.Record.SOL?96:oe(s.data);return s.data=null===(i=s.data)||void 0===i?void 0:i.slice(0,n),s},pe=async(e,t)=>await ue(e,t,exports.Record.SOL),le=(e,t,r)=>u.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=v,exports.BONFIDA_USDC_BNB=A,exports.FavouriteDomain=se,exports.HASH_PREFIX=S,exports.Mint=Y,exports.NAME_OFFERS_ID=ae,exports.NAME_PROGRAM_ID=h,exports.NameRegistryState=G,exports.Numberu32=p,exports.Numberu64=l,exports.PYTH_FIDA_PRICE_ACC=k,exports.PYTH_MAPPING_ACC=W,exports.REFERRERS=K,exports.REGISTER_PROGRAM_ID=x,exports.REVERSE_LOOKUP_CLASS=E,exports.ROOT_DOMAIN_ACCOUNT=R,exports.ReverseTwitterRegistryState=ee,exports.SOL_RECORD_SIG_LEN=96,exports.TOKENS_SYM_MINT=T,exports.TOKEN_TLD=re,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=P,exports.TWITTER_VERIFICATION_AUTHORITY=B,exports.TokenData=U,exports.USDC_MINT=I,exports.VAULT_OWNER=N,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await V(e),s=await q(a,void 0,P);return[d(h,s,new p(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await V(t),n=await q(s,void 0,P);let o=[y(h,n,i,r,void 0)];const c=await V(r.toString());return await q(c,B,void 0),o.push(await Q(e,r.toString(),a,B,P)),o=o.concat(await te(e,t,n,i,a)),o},exports.checkSolRecord=le,exports.createInstruction=f,exports.createInstructionV3=b,exports.createNameRegistry=J,exports.createReverseInstruction=m,exports.createReverseName=$,exports.createReverseTwitterRegistry=te,exports.createSubdomain=async(e,t,r,i=2e3)=>{const a=[],s=t.split(".")[0];if(!s)throw new Error("Invalid subdomain input");const{parent:n,pubkey:o}=M(t),c=await e.getMinimumBalanceForRentExemption(i+G.HEADER_LEN),u=await J(e,"\0".concat(s),i,r,r,c,void 0,n);a.push(u);const[,p]=await $(o,"\0".concat(s),r,n,r);return a.push(...p),[[],a]},exports.createV2Instruction=g,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await V(r),o=await q(n,void 0,P),c=await t.getMinimumBalanceForRentExemption(a+G.HEADER_LEN);let u=[f(h,e.SystemProgram.programId,o,i,s,n,new l(c),new p(a),void 0,P,B)];return u=u.concat(await te(t,r,o,i,s)),u},exports.deleteInstruction=w,exports.deleteNameRegistry=Q,exports.deleteTwitterRegistry=async function(e,t){const r=await V(e),i=await q(r,void 0,P),a=await V(t.toString()),s=await q(a,B,P);return[w(h,i,t,t),w(h,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:E.toBase58()}}],i=await e.getProgramAccounts(h,{filters:r}),a=await O(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=>M(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:R.toBase58()}}];return(await e.getProgramAccounts(h,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:R.toBase58()}}];return await e.getProgramAccounts(h,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await ue(e,t,exports.Record.ARWV),exports.getBackpackRecord=async(e,t)=>await ue(e,t,exports.Record.Backpack),exports.getBscRecord=async(e,t)=>await ue(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await ue(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await ue(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await ue(e,t,exports.Record.DOGE),exports.getDomainKey=Z,exports.getDomainKeySync=M,exports.getEmailRecord=async(e,t)=>await ue(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await ue(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=se.getKeySync(ae,new e.PublicKey(r)),a=await se.retrieve(t,i),s=await O(t,a.nameAccount);return{domain:a.nameAccount,reverse:s}},exports.getGithubRecord=async(e,t)=>await ue(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await V(r.toString()),a=await q(i,B,P);let s=await ee.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=V,exports.getHashedNameSync=D,exports.getInjectiveRecord=async(e,t)=>await ue(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await ue(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await ue(e,t,exports.Record.LTC),exports.getNameAccountKey=q,exports.getNameAccountKeySync=_,exports.getNameOwner=j,exports.getPicRecord=async(e,t)=>await ue(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await ue(e,t,exports.Record.POINT),exports.getRecord=ue,exports.getRecordKeySync=ce,exports.getRecords=async(e,t,r)=>{const i=r.map((e=>ce(t,e)));return(await G.retrieveBatch(e,i)).map(((e,t)=>{var i;if(!e)return;const a=r[t]===exports.Record.SOL?96:oe(e.data);return e.data=null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.slice(0,a),e}))},exports.getRedditRecord=async(e,t)=>await ue(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await Z(e),a=await V(r.toBase58());return await q(a,E,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=M(e),a=D(r.toBase58());return _(a,E,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await ue(e,t,exports.Record.SHDW),exports.getSolRecord=pe,exports.getTelegramRecord=async(e,t)=>await ue(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=ie,exports.getTokenInfoFromName=async(t,r)=>{const i=await q(await V(r),void 0,re),{registry:a}=await G.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(Y.deserialize(a.data).mint);return await ie(t,s)},exports.getTokenizedDomains=async(e,t)=>{const r=await C(e,t);return(await z(e,r.map((e=>e.nameAccount)))).map(((e,t)=>({key:r[t].nameAccount,mint:r[t].nftMint,reverse:e}))).filter((e=>!!e.reverse))},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const i=[{memcmp:{offset:0,bytes:P.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:B.toBase58()}}],s=await t.getProgramAccounts(h,{filters:i});for(const t of s)if(t.account.data.length>G.HEADER_LEN+32){let r=t.account.data.slice(G.HEADER_LEN),i=a.deserializeUnchecked(ee.schema,ee,r);return[i.twitterHandle,new e.PublicKey(i.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await ue(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await V(t),i=await q(r,void 0,P),{registry:a}=await G.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(r,i){const a=[{memcmp:{offset:0,bytes:P.toBase58()}},{memcmp:{offset:32,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(t.Buffer.alloc(32,0)).toBase58()}}],s=await r.getProgramAccounts(h,{filters:a});if(s.length>1)throw new Error("Found more than one registry.");return s[0].account.data.slice(G.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await V(e);return await q(t,void 0,P)},exports.getUrlRecord=async(e,t)=>await ue(e,t,exports.Record.Url),exports.performReverseLookup=async function(e,t){const r=await V(t.toBase58()),a=await q(r,E),{registry:s}=await G.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new i(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()},exports.performReverseLookupBatch=async function(e,t){let r=[];for(let e of t){const t=await V(e.toBase58()),i=await q(t,E);r.push(i)}return(await G.retrieveBatch(e,r)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new i(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.registerDomainName=async(t,i,a,s,n,c=I,u)=>{const[p]=e.PublicKey.findProgramAddressSync([x.toBuffer()],x),l=D(i),f=_(l,void 0,R),d=D(f.toBase58()),y=_(d,p),[w]=e.PublicKey.findProgramAddressSync([f.toBuffer()],x),g=K.findIndex((e=>null==u?void 0:u.equals(e)));let m;const S=[];if(-1!==g&&u){m=r.getAssociatedTokenAddressSync(c,u,!0);const e=await t.getAccountInfo(m);if(!(null==e?void 0:e.data)){const e=r.createAssociatedTokenAccountInstruction(s,m,u,c);S.push(e)}}const k=new o.PythHttpClient(t,o.getPythProgramKeyForCluster("mainnet-beta")),v=await k.getData(),E=T.get(c.toBase58());if(!E)throw new Error("Symbol not found");const B=v.productPrice.get("Crypto."+E+"/USD"),P=v.productFromSymbol.get("Crypto."+E+"/USD"),A=r.getAssociatedTokenAddressSync(c,N),O=new b({name:i,space:a,referrerIdxOpt:-1!=g?g:null}).getInstruction(x,h,R,f,y,e.SystemProgram.programId,p,s,n,W,B.productAccountKey,new e.PublicKey(P.price_account),A,r.TOKEN_PROGRAM_ID,e.SYSVAR_RENT_PUBKEY,w,m);return S.push(O),[[],S]},exports.resolve=async(r,i)=>{const{pubkey:a}=M(i),{registry:s,nftOwner:n}=await G.retrieve(r,a);if(n)return n;try{const a=M(exports.Record.SOL+"."+i,!0),n=await pe(r,i);if(!n.data)throw new Error("Invalid SOL record data");const o=new TextEncoder,c=t.Buffer.concat([n.data.slice(0,32),a.pubkey.toBuffer()]),u=o.encode(c.toString("hex"));if(!le(u,n.data.slice(32),s.owner))throw new Error("Signature invalid");return new e.PublicKey(n.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return s.owner},exports.retrieveNftOwner=F,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(s.NAME_TOKENIZER_ID,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=O,exports.reverseLookupBatch=z,exports.transferInstruction=y,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await V(t),o=await q(n,i,a);let c;return c=i||(await G.retrieve(e,o)).registry.owner,y(h,o,r,c,i,a,s)},exports.updateInstruction=d,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await V(t),o=await q(n,a,s);let c;return c=a||(await G.retrieve(e,o)).registry.owner,d(h,o,new p(r),i,c)};
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t=require("buffer"),r=require("@solana/spl-token"),i=require("bn.js"),o=require("borsh"),s=require("@bonfida/name-tokenizer"),n=require("@ethersproject/sha2"),a=require("@pythnetwork/client"),c=require("bech32-buffer"),u=require("tweetnacl"),p=require("bs58"),d=require("ipaddr.js"),l=require("punycode");function f(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var y,w=f(u);exports.ErrorType=void 0,(y=exports.ErrorType||(exports.ErrorType={})).SymbolNotFound="SymbolNotFound",y.InvalidSubdomain="InvalidSubdomain",y.FavouriteDomainNotFound="FavouriteDomainNotFound",y.MissingParentOwner="MissingParentOwner",y.U32Overflow="U32Overflow",y.InvalidBufferLength="InvalidBufferLength",y.U64Overflow="U64Overflow",y.NoRecordData="NoRecordData",y.InvalidRecordData="InvalidRecordData",y.UnsupportedRecord="UnsupportedRecord",y.InvalidEvmAddress="InvalidEvmAddress",y.InvalidInjectiveAddress="InvalidInjectiveAddress",y.InvalidARecord="InvalidARecord",y.InvalidAAAARecord="InvalidAAAARecord",y.InvalidRecordInput="InvalidRecordInput",y.InvalidSignature="InvalidSignature",y.AccountDoesNotExist="AccountDoesNotExist",y.MultipleRegistries="MultipleRegistries",y.InvalidReverseTwitter="InvalidReverseTwitter",y.NoAccountData="NoAccountData",y.InvalidInput="InvalidInput";class g extends Error{constructor(e,t){super(t),this.name="SNSError",this.type=e,Error.captureStackTrace&&Error.captureStackTrace(this,g)}}class m extends i{toBuffer(){const e=super.toArray().reverse(),r=t.Buffer.from(e);if(4===r.length)return r;if(r.length>4)throw new g(exports.ErrorType.U32Overflow);const i=t.Buffer.alloc(4);return r.copy(i),i}static fromBuffer(e){if(4!==e.length)throw new g(exports.ErrorType.InvalidBufferLength,`Invalid buffer length: ${e.length}`);return new i([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class b extends i{toBuffer(){const e=super.toArray().reverse(),r=t.Buffer.from(e);if(8===r.length)return r;if(r.length>8)throw new g(exports.ErrorType.U64Overflow);const i=t.Buffer.alloc(8);return r.copy(i),i}static fromBuffer(e){if(8!==e.length)throw new g(exports.ErrorType.U64Overflow,`Invalid buffer length: ${e.length}`);return new i([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function x(r,i,o,s,n,a,c,u,p,d,l){const f=[t.Buffer.from(Int8Array.from([0])),new m(a.length).toBuffer(),a,c.toBuffer(),u.toBuffer()],y=t.Buffer.concat(f),w=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1}];return p?w.push({pubkey:p,isSigner:!0,isWritable:!1}):w.push({pubkey:new e.PublicKey(t.Buffer.alloc(32)),isSigner:!1,isWritable:!1}),d?w.push({pubkey:d,isSigner:!1,isWritable:!1}):w.push({pubkey:new e.PublicKey(t.Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l&&w.push({pubkey:l,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:w,programId:r,data:y})}function h(r,i,o,s,n){const a=[t.Buffer.from(Int8Array.from([1])),o.toBuffer(),new m(s.length).toBuffer(),s],c=t.Buffer.concat(a),u=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:r,data:c})}function R(r,i,o,s,n,a,c){const u=[t.Buffer.from(Int8Array.from([2])),o.toBuffer()],p=t.Buffer.concat(u),d=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:c||s,isSigner:!0,isWritable:!1}];return n&&d.push({pubkey:n,isSigner:!0,isWritable:!1}),c&&a&&(n||d.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),d.push({pubkey:a,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:d,programId:r,data:p})}function S(r,i,o,s){const n=[t.Buffer.from(Int8Array.from([3]))],a=t.Buffer.concat(n),c=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:c,programId:r,data:a})}class v{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return o.serialize(v.schema,this)}getInstruction(i,o,s,n,a,c,u,p,d,l,f){const y=t.Buffer.from(this.serialize()),w=[{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!0,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:r.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:w,programId:i,data:y})}}v.schema=new Map([[v,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class A{constructor(e){this.tag=5,this.name=e.name}serialize(){return o.serialize(A.schema,this)}getInstruction(r,i,o,s,n,a,c,u,p){const d=t.Buffer.from(this.serialize());let l=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!0,isWritable:!0}];if(u){if(!p)throw new g(exports.ErrorType.MissingParentOwner);l.push({pubkey:u,isSigner:!1,isWritable:!0}),l.push({pubkey:p,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:l,programId:r,data:d})}}A.schema=new Map([[A,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class E{constructor(e){this.tag=13,this.name=e.name,this.space=e.space,this.referrerIdxOpt=e.referrerIdxOpt}serialize(){return o.serialize(E.schema,this)}getInstruction(r,i,o,s,n,a,c,u,p,d,l,f,y,w,g,m,b){const x=t.Buffer.from(this.serialize());let h=[];return h.push({pubkey:i,isSigner:!1,isWritable:!1}),h.push({pubkey:o,isSigner:!1,isWritable:!1}),h.push({pubkey:s,isSigner:!1,isWritable:!0}),h.push({pubkey:n,isSigner:!1,isWritable:!0}),h.push({pubkey:a,isSigner:!1,isWritable:!1}),h.push({pubkey:c,isSigner:!1,isWritable:!1}),h.push({pubkey:u,isSigner:!0,isWritable:!0}),h.push({pubkey:p,isSigner:!1,isWritable:!0}),h.push({pubkey:d,isSigner:!1,isWritable:!1}),h.push({pubkey:l,isSigner:!1,isWritable:!1}),h.push({pubkey:f,isSigner:!1,isWritable:!1}),h.push({pubkey:y,isSigner:!1,isWritable:!0}),h.push({pubkey:w,isSigner:!1,isWritable:!1}),h.push({pubkey:g,isSigner:!1,isWritable:!1}),h.push({pubkey:m,isSigner:!1,isWritable:!1}),b&&h.push({pubkey:b,isSigner:!1,isWritable:!0}),new e.TransactionInstruction({keys:h,programId:r,data:x})}}E.schema=new Map([[E,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const B=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),I="SPL Name Service",k=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),T=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),P=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),N=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),D=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),K=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),W=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),O=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),_=new e.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),M=[new e.PublicKey("3ogYncmMM5CmytsGCqKHydmXmKUZ6sGWvizkzqwT7zb1"),new e.PublicKey("DM1jJCkZZEwY5tmWbgvKRxsDFzXCdbfrYCCH1CtwguEs"),new e.PublicKey("ADCp4QXFajHrhy4f43pD6GJFtQLkdBY2mjS9DfCk7tNW")],L=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx","GMT"],["AFbX8oGjGpmVFywbVouvhQSRmiW2aR1mohfahi4Y2AdB","GST"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"],["DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263","BONK"],["EPeUFDgHRxs9xxEPVaL6kfGQvCon7jmAWKVUHuux1Tpz","BAT"]]),F=new e.PublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),H=new e.PublicKey("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"),z=e=>{const r=I+e,i=n.sha256(t.Buffer.from(r,"utf8")).slice(2);return t.Buffer.from(i,"hex")},C=(r,i,o)=>{const s=[r];i?s.push(i.toBuffer()):s.push(t.Buffer.alloc(32)),o?s.push(o.toBuffer()):s.push(t.Buffer.alloc(32));const[n]=e.PublicKey.findProgramAddressSync(s,B);return n};async function U(e,t){const r=z(t.toBase58()),o=C(r,D),{registry:s}=await J.retrieve(e,o);if(!s.data)throw new g(exports.ErrorType.NoAccountData);const n=new i(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}async function j(e,t){let r=[];for(let e of t){const t=z(e.toBase58()),i=C(t,D);r.push(i)}return(await J.retrieveBatch(e,r)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new i(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))}const G=(e,t=k)=>{let r=z(e);return{pubkey:C(r,void 0,t),hashed:r}},Y=(e,r=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const i=e.split(".");if(2===i.length){const e=t.Buffer.from([r?1:0]).toString().concat(i[0]),{pubkey:o}=G(i[1]);return{...G(e,o),isSub:!0,parent:o}}if(3===i.length&&r){const{pubkey:e}=G(i[2]),{pubkey:r}=G("\0".concat(i[1]),e),o=t.Buffer.from([1]).toString();return{...G(o.concat(i[0]),r),isSub:!0,parent:e,isSubRecord:!0}}if(i.length>=3)throw new g(exports.ErrorType.InvalidInput);return{...G(e,k),isSub:!1,parent:void 0}};const q=(e,t)=>{if(!e)throw new g(t)},V=async(t,i)=>{try{const[o]=await e.PublicKey.findProgramAddress([s.MINT_PREFIX,i.toBuffer()],s.NAME_TOKENIZER_ID);if("0"===(await r.getMint(t,o)).supply.toString())return;const n=[{memcmp:{offset:0,bytes:o.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],a=await t.getProgramAccounts(r.TOKEN_PROGRAM_ID,{filters:n});if(1!=a.length)return;return new e.PublicKey(a[0].account.data.slice(32,64))}catch{return}},X=e=>[{memcmp:{offset:32,bytes:e}},{memcmp:{offset:64,bytes:"2"}}],Z=async(e,t)=>{const i=[...X(t.toBase58()),{dataSize:165}],o=(await e.getProgramAccounts(r.TOKEN_PROGRAM_ID,{filters:i})).map((e=>r.AccountLayout.decode(e.account.data))).map((t=>(async(e,t)=>{const r=await s.getRecordFromMint(e,t.mint);if(1===r.length)return s.NftRecord.deserialize(r[0].account.data)})(e,t)));return(await Promise.all(o)).filter((e=>void 0!==e))};class J{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 i=await e.getAccountInfo(t);if(!i)throw new g(exports.ErrorType.AccountDoesNotExist);let s=o.deserializeUnchecked(this.schema,J,i.data);s.data=null===(r=i.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await V(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),i=e=>{if(!e)return;const t=o.deserializeUnchecked(this.schema,J,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>i(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}}J.HEADER_LEN=96,J.schema=new Map([[J,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class Q{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 o.serialize(Q.schema,this)}static deserialize(e){return o.deserializeUnchecked(Q.schema,Q,e)}}Q.schema=new Map([[Q,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class ${constructor(e){this.mint=e.mint}serialize(){return o.serialize($.schema,this)}static deserialize(e){return o.deserializeUnchecked($.schema,$,e)}}async function ee(e,t){if(!await e.getAccountInfo(t))throw new g(exports.ErrorType.AccountDoesNotExist);return J.retrieve(e,t)}async function te(e){const r=I+e,i=n.sha256(t.Buffer.from(r,"utf8")).slice(2);return t.Buffer.from(i,"hex")}async function re(r,i,o){const s=[r];i?s.push(i.toBuffer()):s.push(t.Buffer.alloc(32)),o?s.push(o.toBuffer()):s.push(t.Buffer.alloc(32));const[n]=await e.PublicKey.findProgramAddress(s,B);return n}$.schema=new Map([[$,{kind:"struct",fields:[["mint",[32]]]}]]);const ie=async(e,t=k)=>{let r=await te(e);return{pubkey:await re(r,void 0,t),hashed:r}},oe=async(e,r=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const i=e.split(".");if(2===i.length){const e=t.Buffer.from([r?1:0]).toString().concat(i[0]),{pubkey:o}=await ie(i[1]);return{...await ie(e,o),isSub:!0,parent:o}}if(3===i.length&&r){const{pubkey:e}=await ie(i[2]),{pubkey:r}=await ie("\0".concat(i[1]),e),o=t.Buffer.from([1]).toString();return{...await ie(o.concat(i[0]),r),isSub:!0,parent:e,isSubRecord:!0}}if(i.length>=3)throw new g(exports.ErrorType.InvalidInput);return{...await ie(e,k),isSub:!1,parent:void 0}};var se;exports.Record=void 0,(se=exports.Record||(exports.Record={})).IPFS="IPFS",se.ARWV="ARWV",se.SOL="SOL",se.ETH="ETH",se.BTC="BTC",se.LTC="LTC",se.DOGE="DOGE",se.Email="email",se.Url="url",se.Discord="discord",se.Github="github",se.Reddit="reddit",se.Twitter="twitter",se.Telegram="telegram",se.Pic="pic",se.SHDW="SHDW",se.POINT="POINT",se.BSC="BSC",se.Injective="INJ",se.Backpack="backpack",se.A="A",se.AAAA="AAAA",se.CNAME="CNAME",se.TXT="TXT";const ne=new Map([[exports.Record.SOL,96],[exports.Record.ETH,20],[exports.Record.BSC,20],[exports.Record.Injective,20],[exports.Record.A,4],[exports.Record.AAAA,16]]),ae=(e,t,r)=>w.sign.detached.verify(e,t,r.toBytes()),ce=(e,t)=>{const{pubkey:r}=Y(t+"."+e,!0);return r};async function ue(e,t,r,i){const o=ce(t,r);let{registry:s}=await J.retrieve(e,o);if(!s.data)throw new g(exports.ErrorType.NoRecordData);if(i)return de(s,r,o);const n=ne.get(r);return s.data=s.data.slice(0,n),s}const pe=async(e,t)=>await ue(e,t,exports.Record.SOL),de=(e,r,i)=>{const o=null==e?void 0:e.data;if(!o)return;const s=ne.get(r),n=(e=>{const t=Array.from(e);return t.length-1-t.reverse().findIndex((e=>0!==e))+1})(o);if(!s)return o.slice(0,n).toString("utf-8");if(s&&n!==s){const e=o.slice(0,n).toString("utf-8");if(r===exports.Record.Injective){const t=c.decode(e);if("inj"===t.prefix&&20===t.data.length)return e}else if(r===exports.Record.BSC||r===exports.Record.ETH){const r=e.slice(0,2),i=e.slice(2);if("0x"===r&&20===t.Buffer.from(i,"hex").length)return e}else if((r===exports.Record.A||r===exports.Record.AAAA)&&d.isValid(e))return e;throw new g(exports.ErrorType.InvalidRecordData)}if(r===exports.Record.SOL){const r=new TextEncoder,s=t.Buffer.concat([o.slice(0,32),i.toBuffer()]),n=r.encode(s.toString("hex"));if(ae(n,o.slice(32),e.owner))return p.encode(o.slice(0,32))}else{if(r===exports.Record.ETH||r===exports.Record.BSC)return"0x"+o.toString("hex");if(r===exports.Record.Injective)return c.encode("inj",o,"bech32");if(r===exports.Record.A||r===exports.Record.AAAA)return d.fromByteArray([...o.slice(0,s)]).toString()}throw new g(exports.ErrorType.InvalidRecordData)},le=(e,r)=>{if(!ne.get(r))return r!==exports.Record.CNAME&&r!==exports.Record.TXT||(e=l.encode(e)),t.Buffer.from(e,"utf-8");if(r===exports.Record.SOL)throw new g(exports.ErrorType.UnsupportedRecord,"Use `serializeSolRecord` for SOL record");if(r===exports.Record.ETH||r===exports.Record.BSC)return q("0x"===e.slice(0,2),exports.ErrorType.InvalidEvmAddress),t.Buffer.from(e.slice(2),"hex");if(r===exports.Record.Injective){const r=c.decode(e);return q("inj"===r.prefix,exports.ErrorType.InvalidInjectiveAddress),q(20===r.data.length,exports.ErrorType.InvalidInjectiveAddress),t.Buffer.from(r.data)}if(r===exports.Record.A){const r=d.parse(e).toByteArray();return q(4===r.length,exports.ErrorType.InvalidARecord),t.Buffer.from(r)}if(r===exports.Record.AAAA){const r=d.parse(e).toByteArray();return q(16===r.length,exports.ErrorType.InvalidAAAARecord),t.Buffer.from(r)}throw new g(exports.ErrorType.InvalidRecordInput)},fe=(e,r,i,o)=>{const s=t.Buffer.concat([e.toBuffer(),r.toBuffer()]),n=ae(s,o,i);return q(n,exports.ErrorType.InvalidSignature),t.Buffer.concat([e.toBuffer(),o])};async function ye(t,r,i,o,s,n,a,c){const u=await te(r),p=await re(u,a,c),d=n||await t.getMinimumBalanceForRentExemption(i);let l;if(c){const{registry:e}=await ee(t,c);l=e.owner}return x(B,e.SystemProgram.programId,p,s,o,u,new b(d),new m(i),a,c,l)}async function we(e,t,r,i,o){const s=await te(t),n=await re(s,i,o);let a;a=i||(await J.retrieve(e,n)).registry.owner;return S(B,n,r,a)}const ge=async(t,r,i,o,s)=>{let[n]=await e.PublicKey.findProgramAddress([T.toBuffer()],T),a=await te(t.toBase58()),c=await re(a,n,o);return[[],[new A({name:r}).getInstruction(T,e.SYSVAR_RENT_PUBKEY,B,k,c,n,i,o,s)]]},me=async(t,r,i,o,s,n)=>{q(i!==exports.Record.SOL,exports.ErrorType.UnsupportedRecord);const{pubkey:a,hashed:c,parent:u}=Y(`${i}.${r}`,!0),p=le(o,i).length,d=await t.getMinimumBalanceForRentExemption(p+J.HEADER_LEN);return x(B,e.SystemProgram.programId,a,s,n,c,new b(d),new m(p),void 0,u,s)},be=async(t,r,i,o,s,n)=>{const{pubkey:a,hashed:c,parent:u}=Y(`${exports.Record.SOL}.${r}`,!0),p=fe(i,a,o,s).length,d=await t.getMinimumBalanceForRentExemption(p+J.HEADER_LEN);return[x(B,e.SystemProgram.programId,a,o,n,c,new b(d),new m(p),void 0,u,o)]};class xe{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 g(exports.ErrorType.InvalidReverseTwitter);return o.deserializeUnchecked(this.schema,xe,r.data.slice(J.HEADER_LEN))}}async function he(r,i,s,n,a){const c=await te(n.toString()),u=await re(c,K,W);let p=o.serialize(xe.schema,new xe({twitterRegistryKey:s.toBytes(),twitterHandle:i}));return[x(B,e.SystemProgram.programId,u,n,a,c,new b(await r.getMinimumBalanceForRentExemption(p.length+J.HEADER_LEN)),new m(p.length),K,W,K),h(B,u,new m(0),t.Buffer.from(p),K)]}xe.schema=new Map([[xe,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const Re=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),Se=async(e,t)=>{const r=await re(await te(t.toBase58()),void 0,Re),{registry:i}=await J.retrieve(e,r);if(!i.data)throw new g(exports.ErrorType.NoAccountData);return Q.deserialize(i.data)},ve=new e.PublicKey("85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29");class Ae{constructor(t){this.tag=t.tag,this.nameAccount=new e.PublicKey(t.nameAccount)}static deserialize(e){return o.deserialize(this.schema,Ae,e)}static async retrieve(e,t){const r=await e.getAccountInfo(t);if(!r||!r.data)throw new g(exports.ErrorType.FavouriteDomainNotFound);return this.deserialize(r.data)}static async getKey(r,i){return await e.PublicKey.findProgramAddress([t.Buffer.from("favourite_domain"),i.toBuffer()],r)}static getKeySync(r,i){return e.PublicKey.findProgramAddressSync([t.Buffer.from("favourite_domain"),i.toBuffer()],r)}}Ae.schema=new Map([[Ae,{kind:"struct",fields:[["tag","u8"],["nameAccount",[32]]]}]]);exports.BONFIDA_FIDA_BNB=N,exports.BONFIDA_USDC_BNB=O,exports.FavouriteDomain=Ae,exports.HASH_PREFIX=I,exports.Mint=$,exports.NAME_OFFERS_ID=ve,exports.NAME_PROGRAM_ID=B,exports.NameRegistryState=J,exports.Numberu32=m,exports.Numberu64=b,exports.PYTH_FIDA_PRICE_ACC=P,exports.PYTH_MAPPING_ACC=F,exports.RECORD_V1_SIZE=ne,exports.REFERRERS=M,exports.REGISTER_PROGRAM_ID=T,exports.REVERSE_LOOKUP_CLASS=D,exports.ROOT_DOMAIN_ACCOUNT=k,exports.ReverseTwitterRegistryState=xe,exports.SNSError=g,exports.SOL_RECORD_SIG_LEN=96,exports.TOKENS_SYM_MINT=L,exports.TOKEN_TLD=Re,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=W,exports.TWITTER_VERIFICATION_AUTHORITY=K,exports.TokenData=Q,exports.USDC_MINT=_,exports.VAULT_OWNER=H,exports.changeTwitterRegistryData=async function(e,t,r,i){const o=await te(e),s=await re(o,void 0,W);return[h(B,s,new m(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,o){const s=await te(t),n=await re(s,void 0,W);let a=[R(B,n,i,r,void 0)];const c=await te(r.toString());return await re(c,K,void 0),a.push(await we(e,r.toString(),o,K,W)),a=a.concat(await he(e,t,n,i,o)),a},exports.check=q,exports.checkSolRecord=ae,exports.createInstruction=x,exports.createInstructionV3=E,exports.createNameRegistry=ye,exports.createRecordInstruction=me,exports.createReverseInstruction=A,exports.createReverseName=ge,exports.createReverseTwitterRegistry=he,exports.createSolRecordInstruction=be,exports.createSubdomain=async(e,t,r,i=2e3)=>{const o=[],s=t.split(".")[0];if(!s)throw new g(exports.ErrorType.InvalidSubdomain);const{parent:n,pubkey:a}=Y(t),c=await e.getMinimumBalanceForRentExemption(i+J.HEADER_LEN),u=await ye(e,"\0".concat(s),i,r,r,c,void 0,n);o.push(u);const[,p]=await ge(a,"\0".concat(s),r,n,r);return o.push(...p),[[],o]},exports.createV2Instruction=v,exports.createVerifiedTwitterRegistry=async function(t,r,i,o,s){const n=await te(r),a=await re(n,void 0,W),c=await t.getMinimumBalanceForRentExemption(o+J.HEADER_LEN);let u=[x(B,e.SystemProgram.programId,a,i,s,n,new b(c),new m(o),void 0,W,K)];return u=u.concat(await he(t,r,a,i,s)),u},exports.deleteInstruction=S,exports.deleteNameRegistry=we,exports.deleteTwitterRegistry=async function(e,t){const r=await te(e),i=await re(r,void 0,W),o=await te(t.toString()),s=await re(o,K,W);return[S(B,i,t,t),S(B,s,t,t)]},exports.deserializeRecord=de,exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:D.toBase58()}}],i=await e.getProgramAccounts(B,{filters:r}),o=await U(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=>Y(e+"."+o).pubkey)),a=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!a[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:k.toBase58()}}];return(await e.getProgramAccounts(B,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:k.toBase58()}}];return await e.getProgramAccounts(B,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await ue(e,t,exports.Record.ARWV,!0),exports.getBackpackRecord=async(e,t)=>await ue(e,t,exports.Record.Backpack,!0),exports.getBscRecord=async(e,t)=>await ue(e,t,exports.Record.BSC,!0),exports.getBtcRecord=async(e,t)=>await ue(e,t,exports.Record.BTC,!0),exports.getDiscordRecord=async(e,t)=>await ue(e,t,exports.Record.Discord,!0),exports.getDogeRecord=async(e,t)=>await ue(e,t,exports.Record.DOGE,!0),exports.getDomainKey=oe,exports.getDomainKeySync=Y,exports.getEmailRecord=async(e,t)=>await ue(e,t,exports.Record.Email,!0),exports.getEthRecord=async(e,t)=>await ue(e,t,exports.Record.ETH,!0),exports.getFavoriteDomain=async(t,r)=>{const[i]=Ae.getKeySync(ve,new e.PublicKey(r)),o=await Ae.retrieve(t,i),s=await U(t,o.nameAccount);return{domain:o.nameAccount,reverse:s}},exports.getGithubRecord=async(e,t)=>await ue(e,t,exports.Record.Github,!0),exports.getHandleAndRegistryKey=async function(t,r){const i=await te(r.toString()),o=await re(i,K,W);let s=await xe.retrieve(t,o);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=te,exports.getHashedNameSync=z,exports.getInjectiveRecord=async(e,t)=>await ue(e,t,exports.Record.Injective,!0),exports.getIpfsRecord=async(e,t)=>await ue(e,t,exports.Record.IPFS,!0),exports.getLtcRecord=async(e,t)=>await ue(e,t,exports.Record.LTC,!0),exports.getNameAccountKey=re,exports.getNameAccountKeySync=C,exports.getNameOwner=ee,exports.getPicRecord=async(e,t)=>await ue(e,t,exports.Record.Pic,!0),exports.getPointRecord=async(e,t)=>await ue(e,t,exports.Record.POINT,!0),exports.getRecord=ue,exports.getRecordKeySync=ce,exports.getRecords=async function(e,t,r,i){const o=r.map((e=>ce(t,e))),s=await J.retrieveBatch(e,o);return i?s.map(((e,i)=>{if(e)return de(e,r[i],ce(t,r[i]))})):s},exports.getRedditRecord=async(e,t)=>await ue(e,t,exports.Record.Reddit,!0),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await oe(e),o=await te(r.toBase58());return await re(o,D,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=Y(e),o=z(r.toBase58());return C(o,D,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await ue(e,t,exports.Record.SHDW,!0),exports.getSolRecord=pe,exports.getTelegramRecord=async(e,t)=>await ue(e,t,exports.Record.Telegram,!0),exports.getTokenInfoFromMint=Se,exports.getTokenInfoFromName=async(t,r)=>{const i=await re(await te(r),void 0,Re),{registry:o}=await J.retrieve(t,i);if(!o.data)throw new g(exports.ErrorType.NoAccountData);const s=new e.PublicKey($.deserialize(o.data).mint);return await Se(t,s)},exports.getTokenizedDomains=async(e,t)=>{const r=await Z(e,t);return(await j(e,r.map((e=>e.nameAccount)))).map(((e,t)=>({key:r[t].nameAccount,mint:r[t].nftMint,reverse:e}))).filter((e=>!!e.reverse))},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const i=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:K.toBase58()}}],s=await t.getProgramAccounts(B,{filters:i});for(const t of s)if(t.account.data.length>J.HEADER_LEN+32){let r=t.account.data.slice(J.HEADER_LEN),i=o.deserializeUnchecked(xe.schema,xe,r);return[i.twitterHandle,new e.PublicKey(i.twitterRegistryKey)]}throw new g(exports.ErrorType.AccountDoesNotExist)},exports.getTwitterRecord=async(e,t)=>await ue(e,t,exports.Record.Twitter,!0),exports.getTwitterRegistry=async function(e,t){const r=await te(t),i=await re(r,void 0,W),{registry:o}=await J.retrieve(e,i);return o},exports.getTwitterRegistryData=async function(r,i){const o=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(t.Buffer.alloc(32,0)).toBase58()}}],s=await r.getProgramAccounts(B,{filters:o});if(s.length>1)throw new g(exports.ErrorType.MultipleRegistries);return s[0].account.data.slice(J.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await te(e);return await re(t,void 0,W)},exports.getUrlRecord=async(e,t)=>await ue(e,t,exports.Record.Url,!0),exports.performReverseLookup=async function(e,t){const r=await te(t.toBase58()),o=await re(r,D),{registry:s}=await J.retrieve(e,o);if(!s.data)throw new g(exports.ErrorType.NoAccountData);const n=new i(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()},exports.performReverseLookupBatch=async function(e,t){let r=[];for(let e of t){const t=await te(e.toBase58()),i=await re(t,D);r.push(i)}return(await J.retrieveBatch(e,r)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new i(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.registerDomainName=async(t,i,o,s,n,c=_,u)=>{const[p]=e.PublicKey.findProgramAddressSync([T.toBuffer()],T),d=z(i),l=C(d,void 0,k),f=z(l.toBase58()),y=C(f,p),[w]=e.PublicKey.findProgramAddressSync([l.toBuffer()],T),m=M.findIndex((e=>null==u?void 0:u.equals(e)));let b;const x=[];if(-1!==m&&u){b=r.getAssociatedTokenAddressSync(c,u,!0);const e=await t.getAccountInfo(b);if(!(null==e?void 0:e.data)){const e=r.createAssociatedTokenAccountInstruction(s,b,u,c);x.push(e)}}const h=new a.PythHttpClient(t,a.getPythProgramKeyForCluster("mainnet-beta")),R=await h.getData(),S=L.get(c.toBase58());if(!S)throw new g(exports.ErrorType.SymbolNotFound,`No symbol found for mint ${c.toBase58()}`);const v=R.productPrice.get("Crypto."+S+"/USD"),A=R.productFromSymbol.get("Crypto."+S+"/USD"),I=r.getAssociatedTokenAddressSync(c,H),P=new E({name:i,space:o,referrerIdxOpt:-1!=m?m:null}).getInstruction(T,B,k,l,y,e.SystemProgram.programId,p,s,n,F,v.productAccountKey,new e.PublicKey(A.price_account),I,r.TOKEN_PROGRAM_ID,e.SYSVAR_RENT_PUBKEY,w,b);return x.push(P),[[],x]},exports.resolve=async(r,i)=>{const{pubkey:o}=Y(i),{registry:s,nftOwner:n}=await J.retrieve(r,o);if(n)return n;try{const o=ce(i,exports.Record.SOL),n=await pe(r,i);if(!(null==n?void 0:n.data))throw new g(exports.ErrorType.NoRecordData);const a=new TextEncoder,c=t.Buffer.concat([n.data.slice(0,32),o.toBuffer()]),u=a.encode(c.toString("hex"));if(!ae(u,n.data.slice(32),s.owner))throw new g(exports.ErrorType.InvalidSignature);return new e.PublicKey(n.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e}return s.owner},exports.retrieveNftOwner=V,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(s.NAME_TOKENIZER_ID,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=U,exports.reverseLookupBatch=j,exports.serializeRecord=le,exports.serializeSolRecord=fe,exports.transferInstruction=R,exports.transferNameOwnership=async function(e,t,r,i,o,s){const n=await te(t),a=await re(n,i,o);let c;return c=i||(await J.retrieve(e,a)).registry.owner,R(B,a,r,c,i,o,s)},exports.updateInstruction=h,exports.updateNameRegistryData=async function(e,t,r,i,o,s){const n=await te(t),a=await re(n,o,s);let c;return c=o||(await J.retrieve(e,a)).registry.owner,h(B,a,new m(r),i,c)},exports.updateRecordInstruction=async(e,t,r,i,o,s)=>{q(r!==exports.Record.SOL,exports.ErrorType.UnsupportedRecord);const{pubkey:n}=Y(`${r}.${t}`,!0),a=await e.getAccountInfo(n);q(!!(null==a?void 0:a.data),exports.ErrorType.AccountDoesNotExist);const c=le(i,r);if((null==a?void 0:a.data.slice(96).length)!==c.length)return[S(B,n,s,o),await me(e,t,r,i,o,s)];return[h(B,n,new m(0),c,o)]},exports.updateSolRecordInstruction=async(e,t,r,i,o,s)=>{const{pubkey:n}=Y(`${exports.Record.SOL}.${t}`,!0),a=await e.getAccountInfo(n);if(q(!!(null==a?void 0:a.data),exports.ErrorType.AccountDoesNotExist),96!==(null==a?void 0:a.data.length))return[S(B,n,s,i),await be(e,t,r,i,o,s)];const c=fe(r,n,i,o);return[h(B,n,new m(0),c,i)]};
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PublicKey as t,TransactionInstruction as e,SystemProgram as r,SYSVAR_RENT_PUBKEY as i}from"@solana/web3.js";import{Buffer as a}from"buffer";import{TOKEN_PROGRAM_ID as n,getMint as s,AccountLayout as o,getAssociatedTokenAddressSync as c,createAssociatedTokenAccountInstruction as u}from"@solana/spl-token";import w from"bn.js";import{serialize as l,deserializeUnchecked as f,deserialize as p}from"borsh";import{MINT_PREFIX as d,NAME_TOKENIZER_ID as m,getRecordFromMint as y,NftRecord as g}from"@bonfida/name-tokenizer";import{sha256 as h}from"@ethersproject/sha2";import{PythHttpClient as b,getPythProgramKeyForCluster as S}from"@pythnetwork/client";import*as k from"tweetnacl";class v extends w{toBuffer(){const t=super.toArray().reverse(),e=a.from(t);if(4===e.length)return e;if(e.length>4)throw new Error("Numberu32 too large");const r=a.alloc(4);return e.copy(r),r}static fromBuffer(t){if(4!==t.length)throw new Error(`Invalid buffer length: ${t.length}`);return new w([...t].reverse().map((t=>`00${t.toString(16)}`.slice(-2))).join(""),16)}}class E extends w{toBuffer(){const t=super.toArray().reverse(),e=a.from(t);if(8===e.length)return e;if(e.length>8)throw new Error("Numberu64 too large");const r=a.alloc(8);return e.copy(r),r}static fromBuffer(t){if(8!==t.length)throw new Error(`Invalid buffer length: ${t.length}`);return new w([...t].reverse().map((t=>`00${t.toString(16)}`.slice(-2))).join(""),16)}}function B(r,i,n,s,o,c,u,w,l,f,p){const d=[a.from(Int8Array.from([0])),new v(c.length).toBuffer(),c,u.toBuffer(),w.toBuffer()],m=a.concat(d),y=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1}];return l?y.push({pubkey:l,isSigner:!0,isWritable:!1}):y.push({pubkey:new t(a.alloc(32)),isSigner:!1,isWritable:!1}),f?y.push({pubkey:f,isSigner:!1,isWritable:!1}):y.push({pubkey:new t(a.alloc(32)),isSigner:!1,isWritable:!1}),p&&y.push({pubkey:p,isSigner:!0,isWritable:!1}),new e({keys:y,programId:r,data:m})}function W(t,r,i,n,s){const o=[a.from(Int8Array.from([1])),i.toBuffer(),new v(n.length).toBuffer(),n],c=a.concat(o);return new e({keys:[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}],programId:t,data:c})}function A(r,i,n,s,o,c,u){const w=[a.from(Int8Array.from([2])),n.toBuffer()],l=a.concat(w),f=[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:u||s,isSigner:!0,isWritable:!1}];return o&&f.push({pubkey:o,isSigner:!0,isWritable:!1}),u&&c&&(o||f.push({pubkey:t.default,isSigner:!1,isWritable:!1}),f.push({pubkey:c,isSigner:!1,isWritable:!1})),new e({keys:f,programId:r,data:l})}function I(t,r,i,n){const s=[a.from(Int8Array.from([3]))],o=a.concat(s);return new e({keys:[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}],programId:t,data:o})}class R{constructor(t){this.tag=9,this.name=t.name,this.space=t.space}serialize(){return l(R.schema,this)}getInstruction(t,i,s,o,c,u,w,l,f,p,d){const m=a.from(this.serialize()),y=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:r.programId,isSigner:!1,isWritable:!1},{pubkey:w,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!0,isWritable:!0},{pubkey:f,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1}];return new e({keys:y,programId:t,data:m})}}R.schema=new Map([[R,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class D{constructor(t){this.tag=5,this.name=t.name}serialize(){return l(D.schema,this)}getInstruction(r,i,n,s,o,c,u,w,l){const f=a.from(this.serialize());let p=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:t.default,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0}];if(w){if(!l)throw new Error("Missing parent name owner");p.push({pubkey:w,isSigner:!1,isWritable:!0}),p.push({pubkey:l,isSigner:!0,isWritable:!1})}return new e({keys:p,programId:r,data:f})}}D.schema=new Map([[D,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class P{constructor(t){this.tag=13,this.name=t.name,this.space=t.space,this.referrerIdxOpt=t.referrerIdxOpt}serialize(){return l(P.schema,this)}getInstruction(t,r,i,n,s,o,c,u,w,l,f,p,d,m,y,g,h){const b=a.from(this.serialize());let S=[];return S.push({pubkey:r,isSigner:!1,isWritable:!1}),S.push({pubkey:i,isSigner:!1,isWritable:!1}),S.push({pubkey:n,isSigner:!1,isWritable:!0}),S.push({pubkey:s,isSigner:!1,isWritable:!0}),S.push({pubkey:o,isSigner:!1,isWritable:!1}),S.push({pubkey:c,isSigner:!1,isWritable:!1}),S.push({pubkey:u,isSigner:!0,isWritable:!0}),S.push({pubkey:w,isSigner:!1,isWritable:!0}),S.push({pubkey:l,isSigner:!1,isWritable:!1}),S.push({pubkey:f,isSigner:!1,isWritable:!1}),S.push({pubkey:p,isSigner:!1,isWritable:!1}),S.push({pubkey:d,isSigner:!1,isWritable:!0}),S.push({pubkey:m,isSigner:!1,isWritable:!1}),S.push({pubkey:y,isSigner:!1,isWritable:!1}),S.push({pubkey:g,isSigner:!1,isWritable:!1}),h&&S.push({pubkey:h,isSigner:!1,isWritable:!0}),new e({keys:S,programId:t,data:b})}}P.schema=new Map([[P,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const H=new t("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),L="SPL Name Service",z=new t("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),T=new t("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),C=new t("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),F=new t("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),N=new t("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),M=new t("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),x=new t("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),G=96,K=new t("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),j=new t("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),U=[new t("3ogYncmMM5CmytsGCqKHydmXmKUZ6sGWvizkzqwT7zb1"),new t("DM1jJCkZZEwY5tmWbgvKRxsDFzXCdbfrYCCH1CtwguEs"),new t("ADCp4QXFajHrhy4f43pD6GJFtQLkdBY2mjS9DfCk7tNW")],X=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx","GMT"],["AFbX8oGjGpmVFywbVouvhQSRmiW2aR1mohfahi4Y2AdB","GST"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"],["DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263","BONK"],["EPeUFDgHRxs9xxEPVaL6kfGQvCon7jmAWKVUHuux1Tpz","BAT"]]),Y=new t("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),Z=new t("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"),q=t=>{const e=L+t,r=h(a.from(e,"utf8")).slice(2);return a.from(r,"hex")},O=(e,r,i)=>{const n=[e];r?n.push(r.toBuffer()):n.push(a.alloc(32)),i?n.push(i.toBuffer()):n.push(a.alloc(32));const[s]=t.findProgramAddressSync(n,H);return s};async function V(t,e){const r=q(e.toBase58()),i=O(r,N),{registry:a}=await ct.retrieve(t,i);if(!a.data)throw new Error("Could not retrieve name data");const n=new w(a.data.slice(0,4),"le").toNumber();return a.data.slice(4,4+n).toString()}async function J(t,e){let r=[];for(let t of e){const e=q(t.toBase58()),i=O(e,N);r.push(i)}return(await ct.retrieveBatch(t,r)).map((t=>{if(void 0===t||void 0===t.data)return;let e=new w(t.data.slice(0,4),"le").toNumber();return t.data.slice(4,4+e).toString()}))}const Q=async(t,e)=>{const r=[{memcmp:{offset:0,bytes:e.toBase58()}},{memcmp:{offset:64,bytes:N.toBase58()}}],i=await t.getProgramAccounts(H,{filters:r}),a=await V(t,e),n=i.map((t=>{var e;return null===(e=t.account.data.slice(97).toString("utf-8"))||void 0===e?void 0:e.split("\0").join("")})),s=n.map((t=>$(t+"."+a).pubkey)),o=await t.getMultipleAccountsInfo(s);return n.filter(((t,e)=>!!o[e]))},_=(t,e=z)=>{let r=q(t);return{pubkey:O(r,void 0,e),hashed:r}},$=(t,e=!1)=>{t.endsWith(".sol")&&(t=t.slice(0,-4));const r=t.split(".");if(2===r.length){const t=a.from([e?1:0]).toString().concat(r[0]),{pubkey:i}=_(r[1]);return{..._(t,i),isSub:!0,parent:i}}if(3===r.length&&e){const{pubkey:t}=_(r[2]),{pubkey:e}=_("\0".concat(r[1]),t),i=a.from([1]).toString();return{..._(i.concat(r[0]),e),isSub:!0,parent:t,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{..._(t,z),isSub:!1,parent:void 0}};async function tt(t,e){const r=[{memcmp:{offset:32,bytes:e.toBase58()}},{memcmp:{offset:0,bytes:z.toBase58()}}];return(await t.getProgramAccounts(H,{filters:r})).map((t=>t.pubkey))}const et=async t=>{const e=[{memcmp:{offset:0,bytes:z.toBase58()}}];return await t.getProgramAccounts(H,{dataSlice:{offset:32,length:32},filters:e})},rt=(t,e)=>{const{pubkey:r,parent:i}=$(t),a=q(r.toBase58());return O(a,N,e?i:void 0)},it=async(e,r)=>{try{const[i]=await t.findProgramAddress([d,r.toBuffer()],m);if("0"===(await s(e,i)).supply.toString())return;const a=[{memcmp:{offset:0,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],o=await e.getProgramAccounts(n,{filters:a});if(1!=o.length)return;return new t(o[0].account.data.slice(32,64))}catch{return}},at=async e=>{const r=await e.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((e=>new t(e.account.data.slice(66,98))))},nt=t=>[{memcmp:{offset:32,bytes:t}},{memcmp:{offset:64,bytes:"2"}}],st=async(t,e)=>{const r=[...nt(e.toBase58()),{dataSize:165}],i=(await t.getProgramAccounts(n,{filters:r})).map((t=>o.decode(t.account.data))).map((e=>(async(t,e)=>{const r=await y(t,e.mint);if(1===r.length)return g.deserialize(r[0].account.data)})(t,e)));return(await Promise.all(i)).filter((t=>void 0!==t))},ot=async(t,e)=>{const r=await st(t,e);return(await J(t,r.map((t=>t.nameAccount)))).map(((t,e)=>({key:r[e].nameAccount,mint:r[e].nftMint,reverse:t}))).filter((t=>!!t.reverse))};class ct{constructor(e){this.parentName=new t(e.parentName),this.owner=new t(e.owner),this.class=new t(e.class)}static async retrieve(t,e){var r;const i=await t.getAccountInfo(e);if(!i)throw new Error("Invalid name account provided");let a=f(this.schema,ct,i.data);a.data=null===(r=i.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:a,nftOwner:await it(t,e)}}static async _retrieveBatch(t,e){const r=await t.getMultipleAccountsInfo(e),i=t=>{if(!t)return;const e=f(this.schema,ct,t);return e.data=null==t?void 0:t.slice(this.HEADER_LEN),e};return r.map((t=>i(null==t?void 0:t.data)))}static async retrieveBatch(t,e){let r=[];const i=[...e];for(;i.length>0;)r.push(...await this._retrieveBatch(t,i.splice(0,100)));return r}}ct.HEADER_LEN=96,ct.schema=new Map([[ct,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class ut{constructor(t){this.name=t.name,this.ticker=t.ticker,this.mint=t.mint,this.decimals=t.decimals,this.website=null==t?void 0:t.website,this.logoUri=null==t?void 0:t.logoUri}serialize(){return l(ut.schema,this)}static deserialize(t){return f(ut.schema,ut,t)}}ut.schema=new Map([[ut,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class wt{constructor(t){this.mint=t.mint}serialize(){return l(wt.schema,this)}static deserialize(t){return f(wt.schema,wt,t)}}async function lt(t,e){if(!await t.getAccountInfo(e))throw new Error("Unable to find the given account.");return ct.retrieve(t,e)}async function ft(t){const e=L+t,r=h(a.from(e,"utf8")).slice(2);return a.from(r,"hex")}async function pt(e,r,i){const n=[e];r?n.push(r.toBuffer()):n.push(a.alloc(32)),i?n.push(i.toBuffer()):n.push(a.alloc(32));const[s]=await t.findProgramAddress(n,H);return s}async function dt(t,e){const r=await ft(e.toBase58()),i=await pt(r,N),{registry:a}=await ct.retrieve(t,i);if(!a.data)throw new Error("Could not retrieve name data");const n=new w(a.data.slice(0,4),"le").toNumber();return a.data.slice(4,4+n).toString()}async function mt(t,e){let r=[];for(let t of e){const e=await ft(t.toBase58()),i=await pt(e,N);r.push(i)}return(await ct.retrieveBatch(t,r)).map((t=>{if(void 0===t||void 0===t.data)return;let e=new w(t.data.slice(0,4),"le").toNumber();return t.data.slice(4,4+e).toString()}))}wt.schema=new Map([[wt,{kind:"struct",fields:[["mint",[32]]]}]]);const yt=async(t,e=z)=>{let r=await ft(t);return{pubkey:await pt(r,void 0,e),hashed:r}},gt=async(t,e=!1)=>{t.endsWith(".sol")&&(t=t.slice(0,-4));const r=t.split(".");if(2===r.length){const t=a.from([e?1:0]).toString().concat(r[0]),{pubkey:i}=await yt(r[1]);return{...await yt(t,i),isSub:!0,parent:i}}if(3===r.length&&e){const{pubkey:t}=await yt(r[2]),{pubkey:e}=await yt("\0".concat(r[1]),t),i=a.from([1]).toString();return{...await yt(i.concat(r[0]),e),isSub:!0,parent:t,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await yt(t,z),isSub:!1,parent:void 0}},ht=async(t,e)=>{const{pubkey:r,parent:i}=await gt(t),a=await ft(r.toBase58());return await pt(a,N,e?i:void 0)};async function bt(t,e,i,a,n,s,o,c){const u=await ft(e),w=await pt(u,o,c),l=s||await t.getMinimumBalanceForRentExemption(i);let f;if(c){const{registry:e}=await lt(t,c);f=e.owner}return B(H,r.programId,w,n,a,u,new E(l),new v(i),o,c,f)}async function St(t,e,r,i,a,n){const s=await ft(e),o=await pt(s,a,n);let c;c=a||(await ct.retrieve(t,o)).registry.owner;return W(H,o,new v(r),i,c)}async function kt(t,e,r,i,a,n){const s=await ft(e),o=await pt(s,i,a);let c;c=i||(await ct.retrieve(t,o)).registry.owner;return A(H,o,r,c,i,a,n)}async function vt(t,e,r,i,a){const n=await ft(e),s=await pt(n,i,a);let o;o=i||(await ct.retrieve(t,s)).registry.owner;return I(H,s,r,o)}const Et=async(e,a,s,o,w,l=j,f)=>{const[p]=t.findProgramAddressSync([T.toBuffer()],T),d=q(a),m=O(d,void 0,z),y=q(m.toBase58()),g=O(y,p),[h]=t.findProgramAddressSync([m.toBuffer()],T),k=U.findIndex((t=>null==f?void 0:f.equals(t)));let v;const E=[];if(-1!==k&&f){v=c(l,f,!0);const t=await e.getAccountInfo(v);if(!(null==t?void 0:t.data)){const t=u(o,v,f,l);E.push(t)}}const B=new b(e,S("mainnet-beta")),W=await B.getData(),A=X.get(l.toBase58());if(!A)throw new Error("Symbol not found");const I=W.productPrice.get("Crypto."+A+"/USD"),R=W.productFromSymbol.get("Crypto."+A+"/USD"),D=c(l,Z),L=new P({name:a,space:s,referrerIdxOpt:-1!=k?k:null}).getInstruction(T,H,z,m,g,r.programId,p,o,w,Y,I.productAccountKey,new t(R.price_account),D,n,i,h,v);return E.push(L),[[],E]},Bt=async(e,r,a,n,s)=>{let[o]=await t.findProgramAddress([T.toBuffer()],T),c=await ft(e.toBase58()),u=await pt(c,o,n);return[[],[new D({name:r}).getInstruction(T,i,H,z,u,o,a,n,s)]]},Wt=async(t,e,r,i=2e3)=>{const a=[],n=e.split(".")[0];if(!n)throw new Error("Invalid subdomain input");const{parent:s,pubkey:o}=$(e),c=await t.getMinimumBalanceForRentExemption(i+ct.HEADER_LEN),u=await bt(t,"\0".concat(n),i,r,r,c,void 0,s);a.push(u);const[,w]=await Bt(o,"\0".concat(n),r,s,r);return a.push(...w),[[],a]};async function At(t,e,i,a,n){const s=await ft(e),o=await pt(s,void 0,x),c=await t.getMinimumBalanceForRentExemption(a+ct.HEADER_LEN);let u=[B(H,r.programId,o,i,n,s,new E(c),new v(a),void 0,x,M)];return u=u.concat(await Ft(t,e,o,i,n)),u}async function It(t,e,r,i){const a=await ft(t),n=await pt(a,void 0,x);return[W(H,n,new v(r),i,e)]}async function Rt(t,e,r,i,a){const n=await ft(e),s=await pt(n,void 0,x);let o=[A(H,s,i,r,void 0)];const c=await ft(r.toString());return await pt(c,M,void 0),o.push(await vt(t,r.toString(),a,M,x)),o=o.concat(await Ft(t,e,s,i,a)),o}async function Dt(t,e){const r=await ft(t),i=await pt(r,void 0,x),a=await ft(e.toString()),n=await pt(a,M,x);return[I(H,i,e,e),I(H,n,e,e)]}async function Pt(t){const e=await ft(t);return await pt(e,void 0,x)}async function Ht(t,e){const r=await ft(e),i=await pt(r,void 0,x),{registry:a}=await ct.retrieve(t,i);return a}async function Lt(e,r){const i=await ft(r.toString()),a=await pt(i,M,x);let n=await Ct.retrieve(e,a);return[n.twitterHandle,new t(n.twitterRegistryKey)]}async function zt(e,r){const i=[{memcmp:{offset:0,bytes:x.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:M.toBase58()}}],a=await e.getProgramAccounts(H,{filters:i});for(const e of a)if(e.account.data.length>ct.HEADER_LEN+32){let r=e.account.data.slice(ct.HEADER_LEN),i=f(Ct.schema,Ct,r);return[i.twitterHandle,new t(i.twitterRegistryKey)]}throw new Error("Registry not found.")}async function Tt(e,r){const i=[{memcmp:{offset:0,bytes:x.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new t(a.alloc(32,0)).toBase58()}}],n=await e.getProgramAccounts(H,{filters:i});if(n.length>1)throw new Error("Found more than one registry.");return n[0].account.data.slice(ct.HEADER_LEN)}class Ct{constructor(t){this.twitterRegistryKey=t.twitterRegistryKey,this.twitterHandle=t.twitterHandle}static async retrieve(t,e){let r=await t.getAccountInfo(e,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return f(this.schema,Ct,r.data.slice(ct.HEADER_LEN))}}async function Ft(t,e,i,n,s){const o=await ft(n.toString()),c=await pt(o,M,x);let u=l(Ct.schema,new Ct({twitterRegistryKey:i.toBytes(),twitterHandle:e}));return[B(H,r.programId,c,n,s,o,new E(await t.getMinimumBalanceForRentExemption(u.length+ct.HEADER_LEN)),new v(u.length),M,x,M),W(H,c,new v(0),a.from(u),M)]}Ct.schema=new Map([[Ct,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const Nt=new t("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),Mt=async(t,e)=>{const r=await pt(await ft(e.toBase58()),void 0,Nt),{registry:i}=await ct.retrieve(t,r);if(!i.data)throw new Error("Invalid account data");return ut.deserialize(i.data)},xt=async(e,r)=>{const i=await pt(await ft(r),void 0,Nt),{registry:a}=await ct.retrieve(e,i);if(!a.data)throw new Error("Invalid account data");const n=new t(wt.deserialize(a.data).mint);return await Mt(e,n)},Gt=new t("85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29");class Kt{constructor(e){this.tag=e.tag,this.nameAccount=new t(e.nameAccount)}static deserialize(t){return p(this.schema,Kt,t)}static async retrieve(t,e){const r=await t.getAccountInfo(e);if(!r||!r.data)throw new Error("Favourite domain not found");return this.deserialize(r.data)}static async getKey(e,r){return await t.findProgramAddress([a.from("favourite_domain"),r.toBuffer()],e)}static getKeySync(e,r){return t.findProgramAddressSync([a.from("favourite_domain"),r.toBuffer()],e)}}Kt.schema=new Map([[Kt,{kind:"struct",fields:[["tag","u8"],["nameAccount",[32]]]}]]);const jt=async(e,r)=>{const[i]=Kt.getKeySync(Gt,new t(r)),a=await Kt.retrieve(e,i),n=await V(e,a.nameAccount);return{domain:a.nameAccount,reverse:n}};var Ut;!function(t){t.IPFS="IPFS",t.ARWV="ARWV",t.SOL="SOL",t.ETH="ETH",t.BTC="BTC",t.LTC="LTC",t.DOGE="DOGE",t.Email="email",t.Url="url",t.Discord="discord",t.Github="github",t.Reddit="reddit",t.Twitter="twitter",t.Telegram="telegram",t.Pic="pic",t.SHDW="SHDW",t.POINT="POINT",t.BSC="BSC",t.Injective="INJ",t.Backpack="backpack"}(Ut||(Ut={}));const Xt=t=>{if(!t)return;const e=Array.from(t);return e.length-1-e.reverse().findIndex((t=>0!==t))+1},Yt=(t,e)=>{const{pubkey:r}=$(e+"."+t,!0);return r},Zt=async(t,e,r)=>{var i;const a=Yt(e,r);let{registry:n}=await ct.retrieve(t,a);const s=r===Ut.SOL?96:Xt(n.data);return n.data=null===(i=n.data)||void 0===i?void 0:i.slice(0,s),n},qt=async(t,e,r)=>{const i=r.map((t=>Yt(e,t)));return(await ct.retrieveBatch(t,i)).map(((t,e)=>{var i;if(!t)return;const a=r[e]===Ut.SOL?96:Xt(t.data);return t.data=null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.slice(0,a),t}))},Ot=async(t,e)=>await Zt(t,e,Ut.IPFS),Vt=async(t,e)=>await Zt(t,e,Ut.ARWV),Jt=async(t,e)=>await Zt(t,e,Ut.ETH),Qt=async(t,e)=>await Zt(t,e,Ut.BTC),_t=async(t,e)=>await Zt(t,e,Ut.LTC),$t=async(t,e)=>await Zt(t,e,Ut.DOGE),te=async(t,e)=>await Zt(t,e,Ut.Email),ee=async(t,e)=>await Zt(t,e,Ut.Url),re=async(t,e)=>await Zt(t,e,Ut.Discord),ie=async(t,e)=>await Zt(t,e,Ut.Github),ae=async(t,e)=>await Zt(t,e,Ut.Reddit),ne=async(t,e)=>await Zt(t,e,Ut.Twitter),se=async(t,e)=>await Zt(t,e,Ut.Telegram),oe=async(t,e)=>await Zt(t,e,Ut.Pic),ce=async(t,e)=>await Zt(t,e,Ut.SHDW),ue=async(t,e)=>await Zt(t,e,Ut.SOL),we=async(t,e)=>await Zt(t,e,Ut.POINT),le=async(t,e)=>await Zt(t,e,Ut.BSC),fe=async(t,e)=>await Zt(t,e,Ut.Injective),pe=async(t,e)=>await Zt(t,e,Ut.Backpack),de=(t,e,r)=>k.sign.detached.verify(t,e,r.toBytes()),me=async(e,r)=>{const{pubkey:i}=$(r),{registry:n,nftOwner:s}=await ct.retrieve(e,i);if(s)return s;try{const i=$(Ut.SOL+"."+r,!0),s=await ue(e,r);if(!s.data)throw new Error("Invalid SOL record data");const o=new TextEncoder,c=a.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),u=o.encode(c.toString("hex"));if(!de(u,s.data.slice(32),n.owner))throw new Error("Signature invalid");return new t(s.data.slice(0,32))}catch(t){if(t instanceof Error&&"FetchError"===t.name)throw t;console.log(t)}return n.owner};export{F as BONFIDA_FIDA_BNB,K as BONFIDA_USDC_BNB,Kt as FavouriteDomain,L as HASH_PREFIX,wt as Mint,Gt as NAME_OFFERS_ID,H as NAME_PROGRAM_ID,ct as NameRegistryState,v as Numberu32,E as Numberu64,C as PYTH_FIDA_PRICE_ACC,Y as PYTH_MAPPING_ACC,U as REFERRERS,T as REGISTER_PROGRAM_ID,N as REVERSE_LOOKUP_CLASS,z as ROOT_DOMAIN_ACCOUNT,Ut as Record,Ct as ReverseTwitterRegistryState,G as SOL_RECORD_SIG_LEN,X as TOKENS_SYM_MINT,Nt as TOKEN_TLD,x as TWITTER_ROOT_PARENT_REGISTRY_KEY,M as TWITTER_VERIFICATION_AUTHORITY,ut as TokenData,j as USDC_MINT,Z as VAULT_OWNER,It as changeTwitterRegistryData,Rt as changeVerifiedPubkey,de as checkSolRecord,B as createInstruction,P as createInstructionV3,bt as createNameRegistry,D as createReverseInstruction,Bt as createReverseName,Ft as createReverseTwitterRegistry,Wt as createSubdomain,R as createV2Instruction,At as createVerifiedTwitterRegistry,I as deleteInstruction,vt as deleteNameRegistry,Dt as deleteTwitterRegistry,Q as findSubdomains,tt as getAllDomains,et as getAllRegisteredDomains,Vt as getArweaveRecord,pe as getBackpackRecord,le as getBscRecord,Qt as getBtcRecord,re as getDiscordRecord,$t as getDogeRecord,gt as getDomainKey,$ as getDomainKeySync,te as getEmailRecord,Jt as getEthRecord,jt as getFavoriteDomain,ie as getGithubRecord,Lt as getHandleAndRegistryKey,ft as getHashedName,q as getHashedNameSync,fe as getInjectiveRecord,Ot as getIpfsRecord,_t as getLtcRecord,pt as getNameAccountKey,O as getNameAccountKeySync,lt as getNameOwner,oe as getPicRecord,we as getPointRecord,Zt as getRecord,Yt as getRecordKeySync,qt as getRecords,ae as getRedditRecord,ht as getReverseKey,rt as getReverseKeySync,ce as getShdwRecord,ue as getSolRecord,se as getTelegramRecord,Mt as getTokenInfoFromMint,xt as getTokenInfoFromName,ot as getTokenizedDomains,zt as getTwitterHandleandRegistryKeyViaFilters,ne as getTwitterRecord,Ht as getTwitterRegistry,Tt as getTwitterRegistryData,Pt as getTwitterRegistryKey,ee as getUrlRecord,dt as performReverseLookup,mt as performReverseLookupBatch,Et as registerDomainName,me as resolve,it as retrieveNftOwner,at as retrieveNfts,V as reverseLookup,J as reverseLookupBatch,A as transferInstruction,kt as transferNameOwnership,W as updateInstruction,St as updateNameRegistryData};
|
|
1
|
+
import{PublicKey as t,TransactionInstruction as e,SystemProgram as i,SYSVAR_RENT_PUBKEY as r}from"@solana/web3.js";import{Buffer as n}from"buffer";import{TOKEN_PROGRAM_ID as a,getMint as s,AccountLayout as o,getAssociatedTokenAddressSync as c,createAssociatedTokenAccountInstruction as u}from"@solana/spl-token";import l from"bn.js";import{serialize as f,deserializeUnchecked as w,deserialize as d}from"borsh";import{MINT_PREFIX as p,NAME_TOKENIZER_ID as m,getRecordFromMint as y,NftRecord as g}from"@bonfida/name-tokenizer";import{sha256 as h}from"@ethersproject/sha2";import{PythHttpClient as b,getPythProgramKeyForCluster as v}from"@pythnetwork/client";import{decode as S,encode as A}from"bech32-buffer";import*as k from"tweetnacl";import B from"bs58";import I from"ipaddr.js";import{encode as E}from"punycode";var R;!function(t){t.SymbolNotFound="SymbolNotFound",t.InvalidSubdomain="InvalidSubdomain",t.FavouriteDomainNotFound="FavouriteDomainNotFound",t.MissingParentOwner="MissingParentOwner",t.U32Overflow="U32Overflow",t.InvalidBufferLength="InvalidBufferLength",t.U64Overflow="U64Overflow",t.NoRecordData="NoRecordData",t.InvalidRecordData="InvalidRecordData",t.UnsupportedRecord="UnsupportedRecord",t.InvalidEvmAddress="InvalidEvmAddress",t.InvalidInjectiveAddress="InvalidInjectiveAddress",t.InvalidARecord="InvalidARecord",t.InvalidAAAARecord="InvalidAAAARecord",t.InvalidRecordInput="InvalidRecordInput",t.InvalidSignature="InvalidSignature",t.AccountDoesNotExist="AccountDoesNotExist",t.MultipleRegistries="MultipleRegistries",t.InvalidReverseTwitter="InvalidReverseTwitter",t.NoAccountData="NoAccountData",t.InvalidInput="InvalidInput"}(R||(R={}));class W extends Error{constructor(t,e){super(e),this.name="SNSError",this.type=t,Error.captureStackTrace&&Error.captureStackTrace(this,W)}}class D extends l{toBuffer(){const t=super.toArray().reverse(),e=n.from(t);if(4===e.length)return e;if(e.length>4)throw new W(R.U32Overflow);const i=n.alloc(4);return e.copy(i),i}static fromBuffer(t){if(4!==t.length)throw new W(R.InvalidBufferLength,`Invalid buffer length: ${t.length}`);return new l([...t].reverse().map((t=>`00${t.toString(16)}`.slice(-2))).join(""),16)}}class N extends l{toBuffer(){const t=super.toArray().reverse(),e=n.from(t);if(8===e.length)return e;if(e.length>8)throw new W(R.U64Overflow);const i=n.alloc(8);return e.copy(i),i}static fromBuffer(t){if(8!==t.length)throw new W(R.U64Overflow,`Invalid buffer length: ${t.length}`);return new l([...t].reverse().map((t=>`00${t.toString(16)}`.slice(-2))).join(""),16)}}function x(i,r,a,s,o,c,u,l,f,w,d){const p=[n.from(Int8Array.from([0])),new D(c.length).toBuffer(),c,u.toBuffer(),l.toBuffer()],m=n.concat(p),y=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1}];return f?y.push({pubkey:f,isSigner:!0,isWritable:!1}):y.push({pubkey:new t(n.alloc(32)),isSigner:!1,isWritable:!1}),w?y.push({pubkey:w,isSigner:!1,isWritable:!1}):y.push({pubkey:new t(n.alloc(32)),isSigner:!1,isWritable:!1}),d&&y.push({pubkey:d,isSigner:!0,isWritable:!1}),new e({keys:y,programId:i,data:m})}function T(t,i,r,a,s){const o=[n.from(Int8Array.from([1])),r.toBuffer(),new D(a.length).toBuffer(),a],c=n.concat(o);return new e({keys:[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}],programId:t,data:c})}function H(i,r,a,s,o,c,u){const l=[n.from(Int8Array.from([2])),a.toBuffer()],f=n.concat(l),w=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:u||s,isSigner:!0,isWritable:!1}];return o&&w.push({pubkey:o,isSigner:!0,isWritable:!1}),u&&c&&(o||w.push({pubkey:t.default,isSigner:!1,isWritable:!1}),w.push({pubkey:c,isSigner:!1,isWritable:!1})),new e({keys:w,programId:i,data:f})}function L(t,i,r,a){const s=[n.from(Int8Array.from([3]))],o=n.concat(s);return new e({keys:[{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0}],programId:t,data:o})}class P{constructor(t){this.tag=9,this.name=t.name,this.space=t.space}serialize(){return f(P.schema,this)}getInstruction(t,r,s,o,c,u,l,f,w,d,p){const m=n.from(this.serialize()),y=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:i.programId,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!0,isWritable:!0},{pubkey:w,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1}];return new e({keys:y,programId:t,data:m})}}P.schema=new Map([[P,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class F{constructor(t){this.tag=5,this.name=t.name}serialize(){return f(F.schema,this)}getInstruction(i,r,a,s,o,c,u,l,f){const w=n.from(this.serialize());let d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:t.default,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0}];if(l){if(!f)throw new W(R.MissingParentOwner);d.push({pubkey:l,isSigner:!1,isWritable:!0}),d.push({pubkey:f,isSigner:!0,isWritable:!1})}return new e({keys:d,programId:i,data:w})}}F.schema=new Map([[F,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class M{constructor(t){this.tag=13,this.name=t.name,this.space=t.space,this.referrerIdxOpt=t.referrerIdxOpt}serialize(){return f(M.schema,this)}getInstruction(t,i,r,a,s,o,c,u,l,f,w,d,p,m,y,g,h){const b=n.from(this.serialize());let v=[];return v.push({pubkey:i,isSigner:!1,isWritable:!1}),v.push({pubkey:r,isSigner:!1,isWritable:!1}),v.push({pubkey:a,isSigner:!1,isWritable:!0}),v.push({pubkey:s,isSigner:!1,isWritable:!0}),v.push({pubkey:o,isSigner:!1,isWritable:!1}),v.push({pubkey:c,isSigner:!1,isWritable:!1}),v.push({pubkey:u,isSigner:!0,isWritable:!0}),v.push({pubkey:l,isSigner:!1,isWritable:!0}),v.push({pubkey:f,isSigner:!1,isWritable:!1}),v.push({pubkey:w,isSigner:!1,isWritable:!1}),v.push({pubkey:d,isSigner:!1,isWritable:!1}),v.push({pubkey:p,isSigner:!1,isWritable:!0}),v.push({pubkey:m,isSigner:!1,isWritable:!1}),v.push({pubkey:y,isSigner:!1,isWritable:!1}),v.push({pubkey:g,isSigner:!1,isWritable:!1}),h&&v.push({pubkey:h,isSigner:!1,isWritable:!0}),new e({keys:v,programId:t,data:b})}}M.schema=new Map([[M,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const z=new t("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),C="SPL Name Service",j=new t("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),U=new t("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),O=new t("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),G=new t("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),K=new t("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),X=new t("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),Y=new t("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),V=96,Z=new t("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),q=new t("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),J=[new t("3ogYncmMM5CmytsGCqKHydmXmKUZ6sGWvizkzqwT7zb1"),new t("DM1jJCkZZEwY5tmWbgvKRxsDFzXCdbfrYCCH1CtwguEs"),new t("ADCp4QXFajHrhy4f43pD6GJFtQLkdBY2mjS9DfCk7tNW")],_=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx","GMT"],["AFbX8oGjGpmVFywbVouvhQSRmiW2aR1mohfahi4Y2AdB","GST"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"],["DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263","BONK"],["EPeUFDgHRxs9xxEPVaL6kfGQvCon7jmAWKVUHuux1Tpz","BAT"]]),Q=new t("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),$=new t("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"),tt=t=>{const e=C+t,i=h(n.from(e,"utf8")).slice(2);return n.from(i,"hex")},et=(e,i,r)=>{const a=[e];i?a.push(i.toBuffer()):a.push(n.alloc(32)),r?a.push(r.toBuffer()):a.push(n.alloc(32));const[s]=t.findProgramAddressSync(a,z);return s};async function it(t,e){const i=tt(e.toBase58()),r=et(i,K),{registry:n}=await yt.retrieve(t,r);if(!n.data)throw new W(R.NoAccountData);const a=new l(n.data.slice(0,4),"le").toNumber();return n.data.slice(4,4+a).toString()}async function rt(t,e){let i=[];for(let t of e){const e=tt(t.toBase58()),r=et(e,K);i.push(r)}return(await yt.retrieveBatch(t,i)).map((t=>{if(void 0===t||void 0===t.data)return;let e=new l(t.data.slice(0,4),"le").toNumber();return t.data.slice(4,4+e).toString()}))}const nt=async(t,e)=>{const i=[{memcmp:{offset:0,bytes:e.toBase58()}},{memcmp:{offset:64,bytes:K.toBase58()}}],r=await t.getProgramAccounts(z,{filters:i}),n=await it(t,e),a=r.map((t=>{var e;return null===(e=t.account.data.slice(97).toString("utf-8"))||void 0===e?void 0:e.split("\0").join("")})),s=a.map((t=>st(t+"."+n).pubkey)),o=await t.getMultipleAccountsInfo(s);return a.filter(((t,e)=>!!o[e]))},at=(t,e=j)=>{let i=tt(t);return{pubkey:et(i,void 0,e),hashed:i}},st=(t,e=!1)=>{t.endsWith(".sol")&&(t=t.slice(0,-4));const i=t.split(".");if(2===i.length){const t=n.from([e?1:0]).toString().concat(i[0]),{pubkey:r}=at(i[1]);return{...at(t,r),isSub:!0,parent:r}}if(3===i.length&&e){const{pubkey:t}=at(i[2]),{pubkey:e}=at("\0".concat(i[1]),t),r=n.from([1]).toString();return{...at(r.concat(i[0]),e),isSub:!0,parent:t,isSubRecord:!0}}if(i.length>=3)throw new W(R.InvalidInput);return{...at(t,j),isSub:!1,parent:void 0}};async function ot(t,e){const i=[{memcmp:{offset:32,bytes:e.toBase58()}},{memcmp:{offset:0,bytes:j.toBase58()}}];return(await t.getProgramAccounts(z,{filters:i})).map((t=>t.pubkey))}const ct=async t=>{const e=[{memcmp:{offset:0,bytes:j.toBase58()}}];return await t.getProgramAccounts(z,{dataSlice:{offset:32,length:32},filters:e})},ut=(t,e)=>{const{pubkey:i,parent:r}=st(t),n=tt(i.toBase58());return et(n,K,e?r:void 0)},lt=(t,e)=>{if(!t)throw new W(e)},ft=async(e,i)=>{try{const[r]=await t.findProgramAddress([p,i.toBuffer()],m);if("0"===(await s(e,r)).supply.toString())return;const n=[{memcmp:{offset:0,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],o=await e.getProgramAccounts(a,{filters:n});if(1!=o.length)return;return new t(o[0].account.data.slice(32,64))}catch{return}},wt=async e=>{const i=await e.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return i.map((e=>new t(e.account.data.slice(66,98))))},dt=t=>[{memcmp:{offset:32,bytes:t}},{memcmp:{offset:64,bytes:"2"}}],pt=async(t,e)=>{const i=[...dt(e.toBase58()),{dataSize:165}],r=(await t.getProgramAccounts(a,{filters:i})).map((t=>o.decode(t.account.data))).map((e=>(async(t,e)=>{const i=await y(t,e.mint);if(1===i.length)return g.deserialize(i[0].account.data)})(t,e)));return(await Promise.all(r)).filter((t=>void 0!==t))},mt=async(t,e)=>{const i=await pt(t,e);return(await rt(t,i.map((t=>t.nameAccount)))).map(((t,e)=>({key:i[e].nameAccount,mint:i[e].nftMint,reverse:t}))).filter((t=>!!t.reverse))};class yt{constructor(e){this.parentName=new t(e.parentName),this.owner=new t(e.owner),this.class=new t(e.class)}static async retrieve(t,e){var i;const r=await t.getAccountInfo(e);if(!r)throw new W(R.AccountDoesNotExist);let n=w(this.schema,yt,r.data);n.data=null===(i=r.data)||void 0===i?void 0:i.slice(this.HEADER_LEN);return{registry:n,nftOwner:await ft(t,e)}}static async _retrieveBatch(t,e){const i=await t.getMultipleAccountsInfo(e),r=t=>{if(!t)return;const e=w(this.schema,yt,t);return e.data=null==t?void 0:t.slice(this.HEADER_LEN),e};return i.map((t=>r(null==t?void 0:t.data)))}static async retrieveBatch(t,e){let i=[];const r=[...e];for(;r.length>0;)i.push(...await this._retrieveBatch(t,r.splice(0,100)));return i}}yt.HEADER_LEN=96,yt.schema=new Map([[yt,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class gt{constructor(t){this.name=t.name,this.ticker=t.ticker,this.mint=t.mint,this.decimals=t.decimals,this.website=null==t?void 0:t.website,this.logoUri=null==t?void 0:t.logoUri}serialize(){return f(gt.schema,this)}static deserialize(t){return w(gt.schema,gt,t)}}gt.schema=new Map([[gt,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class ht{constructor(t){this.mint=t.mint}serialize(){return f(ht.schema,this)}static deserialize(t){return w(ht.schema,ht,t)}}async function bt(t,e){if(!await t.getAccountInfo(e))throw new W(R.AccountDoesNotExist);return yt.retrieve(t,e)}async function vt(t){const e=C+t,i=h(n.from(e,"utf8")).slice(2);return n.from(i,"hex")}async function St(e,i,r){const a=[e];i?a.push(i.toBuffer()):a.push(n.alloc(32)),r?a.push(r.toBuffer()):a.push(n.alloc(32));const[s]=await t.findProgramAddress(a,z);return s}async function At(t,e){const i=await vt(e.toBase58()),r=await St(i,K),{registry:n}=await yt.retrieve(t,r);if(!n.data)throw new W(R.NoAccountData);const a=new l(n.data.slice(0,4),"le").toNumber();return n.data.slice(4,4+a).toString()}async function kt(t,e){let i=[];for(let t of e){const e=await vt(t.toBase58()),r=await St(e,K);i.push(r)}return(await yt.retrieveBatch(t,i)).map((t=>{if(void 0===t||void 0===t.data)return;let e=new l(t.data.slice(0,4),"le").toNumber();return t.data.slice(4,4+e).toString()}))}ht.schema=new Map([[ht,{kind:"struct",fields:[["mint",[32]]]}]]);const Bt=async(t,e=j)=>{let i=await vt(t);return{pubkey:await St(i,void 0,e),hashed:i}},It=async(t,e=!1)=>{t.endsWith(".sol")&&(t=t.slice(0,-4));const i=t.split(".");if(2===i.length){const t=n.from([e?1:0]).toString().concat(i[0]),{pubkey:r}=await Bt(i[1]);return{...await Bt(t,r),isSub:!0,parent:r}}if(3===i.length&&e){const{pubkey:t}=await Bt(i[2]),{pubkey:e}=await Bt("\0".concat(i[1]),t),r=n.from([1]).toString();return{...await Bt(r.concat(i[0]),e),isSub:!0,parent:t,isSubRecord:!0}}if(i.length>=3)throw new W(R.InvalidInput);return{...await Bt(t,j),isSub:!1,parent:void 0}},Et=async(t,e)=>{const{pubkey:i,parent:r}=await It(t),n=await vt(i.toBase58());return await St(n,K,e?r:void 0)};var Rt;!function(t){t.IPFS="IPFS",t.ARWV="ARWV",t.SOL="SOL",t.ETH="ETH",t.BTC="BTC",t.LTC="LTC",t.DOGE="DOGE",t.Email="email",t.Url="url",t.Discord="discord",t.Github="github",t.Reddit="reddit",t.Twitter="twitter",t.Telegram="telegram",t.Pic="pic",t.SHDW="SHDW",t.POINT="POINT",t.BSC="BSC",t.Injective="INJ",t.Backpack="backpack",t.A="A",t.AAAA="AAAA",t.CNAME="CNAME",t.TXT="TXT"}(Rt||(Rt={}));const Wt=new Map([[Rt.SOL,96],[Rt.ETH,20],[Rt.BSC,20],[Rt.Injective,20],[Rt.A,4],[Rt.AAAA,16]]),Dt=(t,e,i)=>k.sign.detached.verify(t,e,i.toBytes()),Nt=async(e,i)=>{const{pubkey:r}=st(i),{registry:a,nftOwner:s}=await yt.retrieve(e,r);if(s)return s;try{const r=xt(i,Rt.SOL),s=await qt(e,i);if(!(null==s?void 0:s.data))throw new W(R.NoRecordData);const o=new TextEncoder,c=n.concat([s.data.slice(0,32),r.toBuffer()]),u=o.encode(c.toString("hex"));if(!Dt(u,s.data.slice(32),a.owner))throw new W(R.InvalidSignature);return new t(s.data.slice(0,32))}catch(t){if(t instanceof Error&&"FetchError"===t.name)throw t}return a.owner},xt=(t,e)=>{const{pubkey:i}=st(e+"."+t,!0);return i};async function Tt(t,e,i,r){const n=xt(e,i);let{registry:a}=await yt.retrieve(t,n);if(!a.data)throw new W(R.NoRecordData);if(r)return te(a,i,n);const s=Wt.get(i);return a.data=a.data.slice(0,s),a}async function Ht(t,e,i,r){const n=i.map((t=>xt(e,t))),a=await yt.retrieveBatch(t,n);return r?a.map(((t,r)=>{if(t)return te(t,i[r],xt(e,i[r]))})):a}const Lt=async(t,e)=>await Tt(t,e,Rt.IPFS,!0),Pt=async(t,e)=>await Tt(t,e,Rt.ARWV,!0),Ft=async(t,e)=>await Tt(t,e,Rt.ETH,!0),Mt=async(t,e)=>await Tt(t,e,Rt.BTC,!0),zt=async(t,e)=>await Tt(t,e,Rt.LTC,!0),Ct=async(t,e)=>await Tt(t,e,Rt.DOGE,!0),jt=async(t,e)=>await Tt(t,e,Rt.Email,!0),Ut=async(t,e)=>await Tt(t,e,Rt.Url,!0),Ot=async(t,e)=>await Tt(t,e,Rt.Discord,!0),Gt=async(t,e)=>await Tt(t,e,Rt.Github,!0),Kt=async(t,e)=>await Tt(t,e,Rt.Reddit,!0),Xt=async(t,e)=>await Tt(t,e,Rt.Twitter,!0),Yt=async(t,e)=>await Tt(t,e,Rt.Telegram,!0),Vt=async(t,e)=>await Tt(t,e,Rt.Pic,!0),Zt=async(t,e)=>await Tt(t,e,Rt.SHDW,!0),qt=async(t,e)=>await Tt(t,e,Rt.SOL),Jt=async(t,e)=>await Tt(t,e,Rt.POINT,!0),_t=async(t,e)=>await Tt(t,e,Rt.BSC,!0),Qt=async(t,e)=>await Tt(t,e,Rt.Injective,!0),$t=async(t,e)=>await Tt(t,e,Rt.Backpack,!0),te=(t,e,i)=>{const r=null==t?void 0:t.data;if(!r)return;const a=Wt.get(e),s=(t=>{const e=Array.from(t);return e.length-1-e.reverse().findIndex((t=>0!==t))+1})(r);if(!a)return r.slice(0,s).toString("utf-8");if(a&&s!==a){const t=r.slice(0,s).toString("utf-8");if(e===Rt.Injective){const e=S(t);if("inj"===e.prefix&&20===e.data.length)return t}else if(e===Rt.BSC||e===Rt.ETH){const e=t.slice(0,2),i=t.slice(2);if("0x"===e&&20===n.from(i,"hex").length)return t}else if((e===Rt.A||e===Rt.AAAA)&&I.isValid(t))return t;throw new W(R.InvalidRecordData)}if(e===Rt.SOL){const e=new TextEncoder,a=n.concat([r.slice(0,32),i.toBuffer()]),s=e.encode(a.toString("hex"));if(Dt(s,r.slice(32),t.owner))return B.encode(r.slice(0,32))}else{if(e===Rt.ETH||e===Rt.BSC)return"0x"+r.toString("hex");if(e===Rt.Injective)return A("inj",r,"bech32");if(e===Rt.A||e===Rt.AAAA)return I.fromByteArray([...r.slice(0,a)]).toString()}throw new W(R.InvalidRecordData)},ee=(t,e)=>{if(!Wt.get(e))return e!==Rt.CNAME&&e!==Rt.TXT||(t=E(t)),n.from(t,"utf-8");if(e===Rt.SOL)throw new W(R.UnsupportedRecord,"Use `serializeSolRecord` for SOL record");if(e===Rt.ETH||e===Rt.BSC)return lt("0x"===t.slice(0,2),R.InvalidEvmAddress),n.from(t.slice(2),"hex");if(e===Rt.Injective){const e=S(t);return lt("inj"===e.prefix,R.InvalidInjectiveAddress),lt(20===e.data.length,R.InvalidInjectiveAddress),n.from(e.data)}if(e===Rt.A){const e=I.parse(t).toByteArray();return lt(4===e.length,R.InvalidARecord),n.from(e)}if(e===Rt.AAAA){const e=I.parse(t).toByteArray();return lt(16===e.length,R.InvalidAAAARecord),n.from(e)}throw new W(R.InvalidRecordInput)},ie=(t,e,i,r)=>{const a=n.concat([t.toBuffer(),e.toBuffer()]),s=Dt(a,r,i);return lt(s,R.InvalidSignature),n.concat([t.toBuffer(),r])};async function re(t,e,r,n,a,s,o,c){const u=await vt(e),l=await St(u,o,c),f=s||await t.getMinimumBalanceForRentExemption(r);let w;if(c){const{registry:e}=await bt(t,c);w=e.owner}return x(z,i.programId,l,a,n,u,new N(f),new D(r),o,c,w)}async function ne(t,e,i,r,n,a){const s=await vt(e),o=await St(s,n,a);let c;c=n||(await yt.retrieve(t,o)).registry.owner;return T(z,o,new D(i),r,c)}async function ae(t,e,i,r,n,a){const s=await vt(e),o=await St(s,r,n);let c;c=r||(await yt.retrieve(t,o)).registry.owner;return H(z,o,i,c,r,n,a)}async function se(t,e,i,r,n){const a=await vt(e),s=await St(a,r,n);let o;o=r||(await yt.retrieve(t,s)).registry.owner;return L(z,s,i,o)}const oe=async(e,n,s,o,l,f=q,w)=>{const[d]=t.findProgramAddressSync([U.toBuffer()],U),p=tt(n),m=et(p,void 0,j),y=tt(m.toBase58()),g=et(y,d),[h]=t.findProgramAddressSync([m.toBuffer()],U),S=J.findIndex((t=>null==w?void 0:w.equals(t)));let A;const k=[];if(-1!==S&&w){A=c(f,w,!0);const t=await e.getAccountInfo(A);if(!(null==t?void 0:t.data)){const t=u(o,A,w,f);k.push(t)}}const B=new b(e,v("mainnet-beta")),I=await B.getData(),E=_.get(f.toBase58());if(!E)throw new W(R.SymbolNotFound,`No symbol found for mint ${f.toBase58()}`);const D=I.productPrice.get("Crypto."+E+"/USD"),N=I.productFromSymbol.get("Crypto."+E+"/USD"),x=c(f,$),T=new M({name:n,space:s,referrerIdxOpt:-1!=S?S:null}).getInstruction(U,z,j,m,g,i.programId,d,o,l,Q,D.productAccountKey,new t(N.price_account),x,a,r,h,A);return k.push(T),[[],k]},ce=async(e,i,n,a,s)=>{let[o]=await t.findProgramAddress([U.toBuffer()],U),c=await vt(e.toBase58()),u=await St(c,o,a);return[[],[new F({name:i}).getInstruction(U,r,z,j,u,o,n,a,s)]]},ue=async(t,e,i,r=2e3)=>{const n=[],a=e.split(".")[0];if(!a)throw new W(R.InvalidSubdomain);const{parent:s,pubkey:o}=st(e),c=await t.getMinimumBalanceForRentExemption(r+yt.HEADER_LEN),u=await re(t,"\0".concat(a),r,i,i,c,void 0,s);n.push(u);const[,l]=await ce(o,"\0".concat(a),i,s,i);return n.push(...l),[[],n]},le=async(t,e,r,n,a,s)=>{lt(r!==Rt.SOL,R.UnsupportedRecord);const{pubkey:o,hashed:c,parent:u}=st(`${r}.${e}`,!0),l=ee(n,r).length,f=await t.getMinimumBalanceForRentExemption(l+yt.HEADER_LEN);return x(z,i.programId,o,a,s,c,new N(f),new D(l),void 0,u,a)},fe=async(t,e,i,r,n,a)=>{lt(i!==Rt.SOL,R.UnsupportedRecord);const{pubkey:s}=st(`${i}.${e}`,!0),o=await t.getAccountInfo(s);lt(!!(null==o?void 0:o.data),R.AccountDoesNotExist);const c=ee(r,i);if((null==o?void 0:o.data.slice(96).length)!==c.length)return[L(z,s,a,n),await le(t,e,i,r,n,a)];return[T(z,s,new D(0),c,n)]},we=async(t,e,r,n,a,s)=>{const{pubkey:o,hashed:c,parent:u}=st(`${Rt.SOL}.${e}`,!0),l=ie(r,o,n,a).length,f=await t.getMinimumBalanceForRentExemption(l+yt.HEADER_LEN);return[x(z,i.programId,o,n,s,c,new N(f),new D(l),void 0,u,n)]},de=async(t,e,i,r,n,a)=>{const{pubkey:s}=st(`${Rt.SOL}.${e}`,!0),o=await t.getAccountInfo(s);if(lt(!!(null==o?void 0:o.data),R.AccountDoesNotExist),96!==(null==o?void 0:o.data.length))return[L(z,s,a,r),await we(t,e,i,r,n,a)];const c=ie(i,s,r,n);return[T(z,s,new D(0),c,r)]};async function pe(t,e,r,n,a){const s=await vt(e),o=await St(s,void 0,Y),c=await t.getMinimumBalanceForRentExemption(n+yt.HEADER_LEN);let u=[x(z,i.programId,o,r,a,s,new N(c),new D(n),void 0,Y,X)];return u=u.concat(await Be(t,e,o,r,a)),u}async function me(t,e,i,r){const n=await vt(t),a=await St(n,void 0,Y);return[T(z,a,new D(i),r,e)]}async function ye(t,e,i,r,n){const a=await vt(e),s=await St(a,void 0,Y);let o=[H(z,s,r,i,void 0)];const c=await vt(i.toString());return await St(c,X,void 0),o.push(await se(t,i.toString(),n,X,Y)),o=o.concat(await Be(t,e,s,r,n)),o}async function ge(t,e){const i=await vt(t),r=await St(i,void 0,Y),n=await vt(e.toString()),a=await St(n,X,Y);return[L(z,r,e,e),L(z,a,e,e)]}async function he(t){const e=await vt(t);return await St(e,void 0,Y)}async function be(t,e){const i=await vt(e),r=await St(i,void 0,Y),{registry:n}=await yt.retrieve(t,r);return n}async function ve(e,i){const r=await vt(i.toString()),n=await St(r,X,Y);let a=await ke.retrieve(e,n);return[a.twitterHandle,new t(a.twitterRegistryKey)]}async function Se(e,i){const r=[{memcmp:{offset:0,bytes:Y.toBase58()}},{memcmp:{offset:32,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:X.toBase58()}}],n=await e.getProgramAccounts(z,{filters:r});for(const e of n)if(e.account.data.length>yt.HEADER_LEN+32){let i=e.account.data.slice(yt.HEADER_LEN),r=w(ke.schema,ke,i);return[r.twitterHandle,new t(r.twitterRegistryKey)]}throw new W(R.AccountDoesNotExist)}async function Ae(e,i){const r=[{memcmp:{offset:0,bytes:Y.toBase58()}},{memcmp:{offset:32,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:new t(n.alloc(32,0)).toBase58()}}],a=await e.getProgramAccounts(z,{filters:r});if(a.length>1)throw new W(R.MultipleRegistries);return a[0].account.data.slice(yt.HEADER_LEN)}class ke{constructor(t){this.twitterRegistryKey=t.twitterRegistryKey,this.twitterHandle=t.twitterHandle}static async retrieve(t,e){let i=await t.getAccountInfo(e,"processed");if(!i)throw new W(R.InvalidReverseTwitter);return w(this.schema,ke,i.data.slice(yt.HEADER_LEN))}}async function Be(t,e,r,a,s){const o=await vt(a.toString()),c=await St(o,X,Y);let u=f(ke.schema,new ke({twitterRegistryKey:r.toBytes(),twitterHandle:e}));return[x(z,i.programId,c,a,s,o,new N(await t.getMinimumBalanceForRentExemption(u.length+yt.HEADER_LEN)),new D(u.length),X,Y,X),T(z,c,new D(0),n.from(u),X)]}ke.schema=new Map([[ke,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const Ie=new t("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),Ee=async(t,e)=>{const i=await St(await vt(e.toBase58()),void 0,Ie),{registry:r}=await yt.retrieve(t,i);if(!r.data)throw new W(R.NoAccountData);return gt.deserialize(r.data)},Re=async(e,i)=>{const r=await St(await vt(i),void 0,Ie),{registry:n}=await yt.retrieve(e,r);if(!n.data)throw new W(R.NoAccountData);const a=new t(ht.deserialize(n.data).mint);return await Ee(e,a)},We=new t("85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29");class De{constructor(e){this.tag=e.tag,this.nameAccount=new t(e.nameAccount)}static deserialize(t){return d(this.schema,De,t)}static async retrieve(t,e){const i=await t.getAccountInfo(e);if(!i||!i.data)throw new W(R.FavouriteDomainNotFound);return this.deserialize(i.data)}static async getKey(e,i){return await t.findProgramAddress([n.from("favourite_domain"),i.toBuffer()],e)}static getKeySync(e,i){return t.findProgramAddressSync([n.from("favourite_domain"),i.toBuffer()],e)}}De.schema=new Map([[De,{kind:"struct",fields:[["tag","u8"],["nameAccount",[32]]]}]]);const Ne=async(e,i)=>{const[r]=De.getKeySync(We,new t(i)),n=await De.retrieve(e,r),a=await it(e,n.nameAccount);return{domain:n.nameAccount,reverse:a}};export{G as BONFIDA_FIDA_BNB,Z as BONFIDA_USDC_BNB,R as ErrorType,De as FavouriteDomain,C as HASH_PREFIX,ht as Mint,We as NAME_OFFERS_ID,z as NAME_PROGRAM_ID,yt as NameRegistryState,D as Numberu32,N as Numberu64,O as PYTH_FIDA_PRICE_ACC,Q as PYTH_MAPPING_ACC,Wt as RECORD_V1_SIZE,J as REFERRERS,U as REGISTER_PROGRAM_ID,K as REVERSE_LOOKUP_CLASS,j as ROOT_DOMAIN_ACCOUNT,Rt as Record,ke as ReverseTwitterRegistryState,W as SNSError,V as SOL_RECORD_SIG_LEN,_ as TOKENS_SYM_MINT,Ie as TOKEN_TLD,Y as TWITTER_ROOT_PARENT_REGISTRY_KEY,X as TWITTER_VERIFICATION_AUTHORITY,gt as TokenData,q as USDC_MINT,$ as VAULT_OWNER,me as changeTwitterRegistryData,ye as changeVerifiedPubkey,lt as check,Dt as checkSolRecord,x as createInstruction,M as createInstructionV3,re as createNameRegistry,le as createRecordInstruction,F as createReverseInstruction,ce as createReverseName,Be as createReverseTwitterRegistry,we as createSolRecordInstruction,ue as createSubdomain,P as createV2Instruction,pe as createVerifiedTwitterRegistry,L as deleteInstruction,se as deleteNameRegistry,ge as deleteTwitterRegistry,te as deserializeRecord,nt as findSubdomains,ot as getAllDomains,ct as getAllRegisteredDomains,Pt as getArweaveRecord,$t as getBackpackRecord,_t as getBscRecord,Mt as getBtcRecord,Ot as getDiscordRecord,Ct as getDogeRecord,It as getDomainKey,st as getDomainKeySync,jt as getEmailRecord,Ft as getEthRecord,Ne as getFavoriteDomain,Gt as getGithubRecord,ve as getHandleAndRegistryKey,vt as getHashedName,tt as getHashedNameSync,Qt as getInjectiveRecord,Lt as getIpfsRecord,zt as getLtcRecord,St as getNameAccountKey,et as getNameAccountKeySync,bt as getNameOwner,Vt as getPicRecord,Jt as getPointRecord,Tt as getRecord,xt as getRecordKeySync,Ht as getRecords,Kt as getRedditRecord,Et as getReverseKey,ut as getReverseKeySync,Zt as getShdwRecord,qt as getSolRecord,Yt as getTelegramRecord,Ee as getTokenInfoFromMint,Re as getTokenInfoFromName,mt as getTokenizedDomains,Se as getTwitterHandleandRegistryKeyViaFilters,Xt as getTwitterRecord,be as getTwitterRegistry,Ae as getTwitterRegistryData,he as getTwitterRegistryKey,Ut as getUrlRecord,At as performReverseLookup,kt as performReverseLookupBatch,oe as registerDomainName,Nt as resolve,ft as retrieveNftOwner,wt as retrieveNfts,it as reverseLookup,rt as reverseLookupBatch,ee as serializeRecord,ie as serializeSolRecord,H as transferInstruction,ae as transferNameOwnership,T as updateInstruction,ne as updateNameRegistryData,fe as updateRecordInstruction,de as updateSolRecordInstruction};
|
package/dist/record.d.ts
CHANGED
|
@@ -1,159 +1,180 @@
|
|
|
1
1
|
import { Record } from "./types/record";
|
|
2
|
-
import { Connection } from "@solana/web3.js";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { NameRegistryState } from "./state";
|
|
4
|
+
import { Buffer } from "buffer";
|
|
4
5
|
/**
|
|
5
6
|
* This function can be used to derive a record key
|
|
6
7
|
* @param domain The .sol domain name
|
|
7
8
|
* @param record The record to derive the key for
|
|
8
9
|
* @returns
|
|
9
10
|
*/
|
|
10
|
-
export declare const getRecordKeySync: (domain: string, record: Record) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param record The record to search for
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
export declare const getRecord: (connection: Connection, domain: string, record: Record) => Promise<NameRegistryState>;
|
|
19
|
-
export declare const getRecords: (connection: Connection, domain: string, records: Record[]) => Promise<(NameRegistryState | undefined)[]>;
|
|
11
|
+
export declare const getRecordKeySync: (domain: string, record: Record) => PublicKey;
|
|
12
|
+
export declare function getRecord(connection: Connection, domain: string, record: Record, deserialize: true): Promise<string | undefined>;
|
|
13
|
+
export declare function getRecord(connection: Connection, domain: string, record: Record, deserialize?: false): Promise<NameRegistryState | undefined>;
|
|
14
|
+
export declare function getRecords(connection: Connection, domain: string, records: Record[], deserialize: true): Promise<string[]>;
|
|
15
|
+
export declare function getRecords(connection: Connection, domain: string, records: Record[], deserialize?: false): Promise<NameRegistryState[]>;
|
|
20
16
|
/**
|
|
21
17
|
* This function can be used to retrieve the IPFS record of a domain name
|
|
22
18
|
* @param connection The Solana RPC connection object
|
|
23
19
|
* @param domain The .sol domain name
|
|
24
20
|
* @returns
|
|
25
21
|
*/
|
|
26
|
-
export declare const getIpfsRecord: (connection: Connection, domain: string) => Promise<
|
|
22
|
+
export declare const getIpfsRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
27
23
|
/**
|
|
28
24
|
* This function can be used to retrieve the Arweave record of a domain name
|
|
29
25
|
* @param connection The Solana RPC connection object
|
|
30
26
|
* @param domain The .sol domain name
|
|
31
27
|
* @returns
|
|
32
28
|
*/
|
|
33
|
-
export declare const getArweaveRecord: (connection: Connection, domain: string) => Promise<
|
|
29
|
+
export declare const getArweaveRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
34
30
|
/**
|
|
35
31
|
* This function can be used to retrieve the ETH record of a domain name
|
|
36
32
|
* @param connection The Solana RPC connection object
|
|
37
33
|
* @param domain The .sol domain name
|
|
38
34
|
* @returns
|
|
39
35
|
*/
|
|
40
|
-
export declare const getEthRecord: (connection: Connection, domain: string) => Promise<
|
|
36
|
+
export declare const getEthRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
41
37
|
/**
|
|
42
38
|
* This function can be used to retrieve the BTC record of a domain name
|
|
43
39
|
* @param connection The Solana RPC connection object
|
|
44
40
|
* @param domain The .sol domain name
|
|
45
41
|
* @returns
|
|
46
42
|
*/
|
|
47
|
-
export declare const getBtcRecord: (connection: Connection, domain: string) => Promise<
|
|
43
|
+
export declare const getBtcRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
48
44
|
/**
|
|
49
45
|
* This function can be used to retrieve the LTC record of a domain name
|
|
50
46
|
* @param connection The Solana RPC connection object
|
|
51
47
|
* @param domain The .sol domain name
|
|
52
48
|
* @returns
|
|
53
49
|
*/
|
|
54
|
-
export declare const getLtcRecord: (connection: Connection, domain: string) => Promise<
|
|
50
|
+
export declare const getLtcRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
55
51
|
/**
|
|
56
52
|
* This function can be used to retrieve the DOGE record of a domain name
|
|
57
53
|
* @param connection The Solana RPC connection object
|
|
58
54
|
* @param domain The .sol domain name
|
|
59
55
|
* @returns
|
|
60
56
|
*/
|
|
61
|
-
export declare const getDogeRecord: (connection: Connection, domain: string) => Promise<
|
|
57
|
+
export declare const getDogeRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
62
58
|
/**
|
|
63
59
|
* This function can be used to retrieve the email record of a domain name
|
|
64
60
|
* @param connection The Solana RPC connection object
|
|
65
61
|
* @param domain The .sol domain name
|
|
66
62
|
* @returns
|
|
67
63
|
*/
|
|
68
|
-
export declare const getEmailRecord: (connection: Connection, domain: string) => Promise<
|
|
64
|
+
export declare const getEmailRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
69
65
|
/**
|
|
70
66
|
* This function can be used to retrieve the URL record of a domain name
|
|
71
67
|
* @param connection The Solana RPC connection object
|
|
72
68
|
* @param domain The .sol domain name
|
|
73
69
|
* @returns
|
|
74
70
|
*/
|
|
75
|
-
export declare const getUrlRecord: (connection: Connection, domain: string) => Promise<
|
|
71
|
+
export declare const getUrlRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
76
72
|
/**
|
|
77
73
|
* This function can be used to retrieve the Discord record of a domain name
|
|
78
74
|
* @param connection The Solana RPC connection object
|
|
79
75
|
* @param domain The .sol domain name
|
|
80
76
|
* @returns
|
|
81
77
|
*/
|
|
82
|
-
export declare const getDiscordRecord: (connection: Connection, domain: string) => Promise<
|
|
78
|
+
export declare const getDiscordRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
83
79
|
/**
|
|
84
80
|
* This function can be used to retrieve the Github record of a domain name
|
|
85
81
|
* @param connection The Solana RPC connection object
|
|
86
82
|
* @param domain The .sol domain name
|
|
87
83
|
* @returns
|
|
88
84
|
*/
|
|
89
|
-
export declare const getGithubRecord: (connection: Connection, domain: string) => Promise<
|
|
85
|
+
export declare const getGithubRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
90
86
|
/**
|
|
91
87
|
* This function can be used to retrieve the Reddit record of a domain name
|
|
92
88
|
* @param connection The Solana RPC connection object
|
|
93
89
|
* @param domain The .sol domain name
|
|
94
90
|
* @returns
|
|
95
91
|
*/
|
|
96
|
-
export declare const getRedditRecord: (connection: Connection, domain: string) => Promise<
|
|
92
|
+
export declare const getRedditRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
97
93
|
/**
|
|
98
94
|
* This function can be used to retrieve the Twitter record of a domain name
|
|
99
95
|
* @param connection The Solana RPC connection object
|
|
100
96
|
* @param domain The .sol domain name
|
|
101
97
|
* @returns
|
|
102
98
|
*/
|
|
103
|
-
export declare const getTwitterRecord: (connection: Connection, domain: string) => Promise<
|
|
99
|
+
export declare const getTwitterRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
104
100
|
/**
|
|
105
101
|
* This function can be used to retrieve the Telegram record of a domain name
|
|
106
102
|
* @param connection The Solana RPC connection object
|
|
107
103
|
* @param domain The .sol domain name
|
|
108
104
|
* @returns
|
|
109
105
|
*/
|
|
110
|
-
export declare const getTelegramRecord: (connection: Connection, domain: string) => Promise<
|
|
106
|
+
export declare const getTelegramRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
111
107
|
/**
|
|
112
108
|
* This function can be used to retrieve the pic record of a domain name
|
|
113
109
|
* @param connection The Solana RPC connection object
|
|
114
110
|
* @param domain The .sol domain name
|
|
115
111
|
* @returns
|
|
116
112
|
*/
|
|
117
|
-
export declare const getPicRecord: (connection: Connection, domain: string) => Promise<
|
|
113
|
+
export declare const getPicRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
118
114
|
/**
|
|
119
115
|
* This function can be used to retrieve the SHDW record of a domain name
|
|
120
116
|
* @param connection The Solana RPC connection object
|
|
121
117
|
* @param domain The .sol domain name
|
|
122
118
|
* @returns
|
|
123
119
|
*/
|
|
124
|
-
export declare const getShdwRecord: (connection: Connection, domain: string) => Promise<
|
|
120
|
+
export declare const getShdwRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
125
121
|
/**
|
|
126
122
|
* This function can be used to retrieve the SOL record of a domain name
|
|
127
123
|
* @param connection The Solana RPC connection object
|
|
128
124
|
* @param domain The .sol domain name
|
|
129
125
|
* @returns
|
|
130
126
|
*/
|
|
131
|
-
export declare const getSolRecord: (connection: Connection, domain: string) => Promise<NameRegistryState>;
|
|
127
|
+
export declare const getSolRecord: (connection: Connection, domain: string) => Promise<NameRegistryState | undefined>;
|
|
132
128
|
/**
|
|
133
129
|
* This function can be used to retrieve the POINT record of a domain name
|
|
134
130
|
* @param connection The Solana RPC connection object
|
|
135
131
|
* @param domain The .sol domain name
|
|
136
132
|
* @returns
|
|
137
133
|
*/
|
|
138
|
-
export declare const getPointRecord: (connection: Connection, domain: string) => Promise<
|
|
134
|
+
export declare const getPointRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
139
135
|
/**
|
|
140
136
|
* This function can be used to retrieve the BSC record of a domain name
|
|
141
137
|
* @param connection The Solana RPC connection object
|
|
142
138
|
* @param domain The .sol domain name
|
|
143
139
|
* @returns
|
|
144
140
|
*/
|
|
145
|
-
export declare const getBscRecord: (connection: Connection, domain: string) => Promise<
|
|
141
|
+
export declare const getBscRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
146
142
|
/**
|
|
147
143
|
* This function can be used to retrieve the Injective record of a domain name
|
|
148
144
|
* @param connection The Solana RPC connection object
|
|
149
145
|
* @param domain The .sol domain name
|
|
150
146
|
* @returns
|
|
151
147
|
*/
|
|
152
|
-
export declare const getInjectiveRecord: (connection: Connection, domain: string) => Promise<
|
|
148
|
+
export declare const getInjectiveRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
153
149
|
/**
|
|
154
150
|
* This function can be used to retrieve the Backpack record of a domain name
|
|
155
151
|
* @param connection The Solana RPC connection object
|
|
156
152
|
* @param domain The .sol domain name
|
|
157
153
|
* @returns
|
|
158
154
|
*/
|
|
159
|
-
export declare const getBackpackRecord: (connection: Connection, domain: string) => Promise<
|
|
155
|
+
export declare const getBackpackRecord: (connection: Connection, domain: string) => Promise<string | undefined>;
|
|
156
|
+
/**
|
|
157
|
+
* This function can be used to deserialize the content of a record. If the content is invalid it will throw an error
|
|
158
|
+
* @param registry The name registry state object of the record being deserialized
|
|
159
|
+
* @param record The record enum being deserialized
|
|
160
|
+
* @param recordKey The public key of the record being deserialized
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
export declare const deserializeRecord: (registry: NameRegistryState | undefined, record: Record, recordKey: PublicKey) => string | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* This function can be used to serialize a user input string into a buffer that will be stored into a record account data
|
|
166
|
+
* For serializing SOL records use `serializeSolRecord`
|
|
167
|
+
* @param str The string being serialized into the record account data
|
|
168
|
+
* @param record The record enum being serialized
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
export declare const serializeRecord: (str: string, record: Record) => Buffer;
|
|
172
|
+
/**
|
|
173
|
+
* This function can be used to build the content of a SOL record
|
|
174
|
+
* @param content The public key being stored in the SOL record
|
|
175
|
+
* @param recordKey The record public key
|
|
176
|
+
* @param signer The signer of the record i.e the domain owner
|
|
177
|
+
* @param signature The signature of the record's content
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
export declare const serializeSolRecord: (content: PublicKey, recordKey: PublicKey, signer: PublicKey, signature: Uint8Array) => Buffer;
|
package/dist/types/record.d.ts
CHANGED
|
@@ -21,5 +21,10 @@ export declare enum Record {
|
|
|
21
21
|
POINT = "POINT",
|
|
22
22
|
BSC = "BSC",
|
|
23
23
|
Injective = "INJ",
|
|
24
|
-
Backpack = "backpack"
|
|
24
|
+
Backpack = "backpack",
|
|
25
|
+
A = "A",
|
|
26
|
+
AAAA = "AAAA",
|
|
27
|
+
CNAME = "CNAME",
|
|
28
|
+
TXT = "TXT"
|
|
25
29
|
}
|
|
30
|
+
export declare const RECORD_V1_SIZE: Map<Record, number>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { Buffer } from "buffer";
|
|
4
|
+
import { ErrorType } from "./error";
|
|
4
5
|
export declare const getHashedNameSync: (name: string) => Buffer;
|
|
5
6
|
export declare const getNameAccountKeySync: (hashed_name: Buffer, nameClass?: PublicKey, nameParent?: PublicKey) => PublicKey;
|
|
6
7
|
/**
|
|
@@ -71,3 +72,4 @@ export declare const getAllRegisteredDomains: (connection: Connection) => Promis
|
|
|
71
72
|
* @returns The public key of the reverse account
|
|
72
73
|
*/
|
|
73
74
|
export declare const getReverseKeySync: (domain: string, isSub?: boolean) => PublicKey;
|
|
75
|
+
export declare const check: (bool: boolean, errorType: ErrorType) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonfida/spl-name-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -63,9 +63,12 @@
|
|
|
63
63
|
"@pythnetwork/client": "2.17.0",
|
|
64
64
|
"@solana/buffer-layout": "^4.0.1",
|
|
65
65
|
"@solana/spl-token": "0.3.7 ",
|
|
66
|
+
"bech32-buffer": "^0.2.1",
|
|
66
67
|
"bn.js": "^5.2.1",
|
|
67
68
|
"borsh": "^0.7.0",
|
|
68
69
|
"buffer": "^6.0.3",
|
|
70
|
+
"ipaddr.js": "^2.1.0",
|
|
71
|
+
"punycode": "^2.3.0",
|
|
69
72
|
"tweetnacl": "^1.0.3"
|
|
70
73
|
},
|
|
71
74
|
"peerDependencies": {
|