@bonfida/spl-name-service 0.1.65 → 0.1.66
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/index.js +1 -1
- package/dist/record.d.ts +8 -0
- package/package.json +1 -1
- package/src/record.ts +13 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@solana/web3.js"),t=require("bn.js"),r=require("@ethersproject/sha2"),i=require("borsh"),a=require("@solana/spl-token"),s=require("@bonfida/name-offers"),n=require("tweetnacl");const o=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),c="SPL Name Service",u=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),l=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),p=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),f=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),w=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),d=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),y=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),g=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),m=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),b=Buffer.from("tokenized_name"),h=async(t,r)=>{try{const[i]=await e.PublicKey.findProgramAddress([b,r.toBuffer()],m);if("0"===(await a.getMint(t,i)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await t.getProgramAccounts(a.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class R{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,R,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await h(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,R,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}R.HEADER_LEN=96,R.schema=new Map([[R,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class x{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(x.schema,this)}static deserialize(e){return i.deserializeUnchecked(x.schema,x,e)}}x.schema=new Map([[x,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class S{constructor(e){this.mint=e.mint}serialize(){return i.serialize(S.schema,this)}static deserialize(e){return i.deserializeUnchecked(S.schema,S,e)}}async function v(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return R.retrieve(e,t)}async function B(e){const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")}S.schema=new Map([[S,{kind:"struct",fields:[["mint",[32]]]}]]);const k=e=>{const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")};async function E(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,o);return s}const P=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,o);return s};async function I(e,r){const i=await B(r.toBase58()),a=await E(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}async function A(e,r){const i=k(r.toBase58()),a=P(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const T=async(e,t=u)=>{let r=await B(e);return{pubkey:await E(r,void 0,t),hashed:r}},N=(e,t=u)=>{let r=k(e);return{pubkey:P(r,void 0,t),hashed:r}},K=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await T(r[1]);return{...await T(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await T(r[2]),{pubkey:t}=await T("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await T(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await T(e,u),isSub:!1,parent:void 0}},W=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=N(r[1]);return{...N(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=N(r[2]),{pubkey:t}=N("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...N(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...N(e,u),isSub:!1,parent:void 0}};class D extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class _ extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function H(t,r,i,a,s,n,o,c,u,l,p){const f=[Buffer.from(Int8Array.from([0])),new D(n.length).toBuffer(),n,o.toBuffer(),c.toBuffer()],w=Buffer.concat(f),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return u?d.push({pubkey:u,isSigner:!0,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l?d.push({pubkey:l,isSigner:!1,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),p&&d.push({pubkey:p,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:d,programId:t,data:w})}function O(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new D(a.length).toBuffer(),a],o=Buffer.concat(n),c=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:c,programId:t,data:o})}function L(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),l=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&l.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:t,data:u})}function z(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class F{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(F.schema,this)}getInstruction(t,r,i,s,n,o,c,u,l,p,f){const w=Buffer.from(this.serialize()),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:d,programId:t,data:w})}}F.schema=new Map([[F,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class M{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(M.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const l=Buffer.from(this.serialize());let p=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");p.push({pubkey:c,isSigner:!1,isWritable:!0}),p.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:p,programId:t,data:l})}}async function U(e,t,r,i,a){const s=await B(t),n=await E(s,i,a);let c;c=i||(await R.retrieve(e,n)).registry.owner;return z(o,n,r,c)}M.schema=new Map([[M,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class C{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,C,r.data.slice(R.HEADER_LEN))}}async function V(t,r,a,s,n){const c=await B(s.toString()),u=await E(c,d,y);let l=i.serialize(C.schema,new C({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[H(o,e.SystemProgram.programId,u,s,n,c,new _(await t.getMinimumBalanceForRentExemption(l.length+R.HEADER_LEN)),new D(l.length),d,y,d),O(o,u,new D(0),Buffer.from(l),d)]}C.schema=new Map([[C,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const j=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),G=async(e,t)=>{const r=await E(await B(t.toBase58()),void 0,j),{registry:i}=await R.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return x.deserialize(i.data)};var q;exports.Record=void 0,(q=exports.Record||(exports.Record={})).IPFS="IPFS",q.ARWV="ARWV",q.SOL="SOL",q.ETH="ETH",q.BTC="BTC",q.LTC="LTC",q.DOGE="DOGE",q.Email="email",q.Url="url",q.Discord="discord",q.Github="github",q.Reddit="reddit",q.Twitter="twitter",q.Telegram="telegram",q.Pic="pic",q.SHDW="SHDW",q.POINT="POINT",q.BSC="BSC",q.Injective="INJECT";const Y=async(e,t)=>{const{pubkey:r}=await K(t+"."+e,!0);return r},X=async(e,t,r)=>{var i,a;const s=await Y(t,r);let{registry:n}=await R.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},Z=async(e,t)=>await X(e,t,exports.Record.SOL),J=(e,t,r)=>n.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=f,exports.BONFIDA_USDC_BNB=g,exports.HASH_PREFIX=c,exports.MINT_PREFIX=b,exports.Mint=S,exports.NAME_PROGRAM_ID=o,exports.NAME_TOKENIZER_ID=m,exports.NameRegistryState=R,exports.Numberu32=D,exports.Numberu64=_,exports.PYTH_FIDA_PRICE_ACC=p,exports.REGISTER_PROGRAM_ID=l,exports.REVERSE_LOOKUP_CLASS=w,exports.ROOT_DOMAIN_ACCOUNT=u,exports.ReverseTwitterRegistryState=C,exports.SOL_RECORD_SIG_LEN=96,exports.TOKEN_TLD=j,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=y,exports.TWITTER_VERIFICATION_AUTHORITY=d,exports.TokenData=x,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await B(e),s=await E(a,void 0,y);return[O(o,s,new D(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await B(t),n=await E(s,void 0,y);let c=[L(o,n,i,r,void 0)];const u=await B(r.toString());return await E(u,d,void 0),c.push(await U(e,r.toString(),a,d,y)),c=c.concat(await V(e,t,n,i,a)),c},exports.checkSolRecord=J,exports.createInstruction=H,exports.createNameRegistry=async function(t,r,i,a,s,n,c,u){const l=await B(r),p=await E(l,c,u),f=n||await t.getMinimumBalanceForRentExemption(i);let w;if(u){const{registry:e}=await v(t,u);w=e.owner}return H(o,e.SystemProgram.programId,p,s,a,l,new _(f),new D(i),c,u,w)},exports.createReverseInstruction=M,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),c=await B(t.toBase58()),p=await E(c,n,a);return[[],[new M({name:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,p,n,i,a,s)]]},exports.createReverseTwitterRegistry=V,exports.createV2Instruction=F,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await B(r),c=await E(n,void 0,y),u=await t.getMinimumBalanceForRentExemption(a+R.HEADER_LEN);let l=[H(o,e.SystemProgram.programId,c,i,s,n,new _(u),new D(a),void 0,y,d)];return l=l.concat(await V(t,r,c,i,s)),l},exports.deleteInstruction=z,exports.deleteNameRegistry=U,exports.deleteTwitterRegistry=async function(e,t){const r=await B(e),i=await E(r,void 0,y),a=await B(t.toString()),s=await E(a,d,y);return[z(o,i,t,t),z(o,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:w.toBase58()}}],i=await e.getProgramAccounts(o,{filters:r}),a=await A(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>W(e+"."+a).pubkey)),c=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!c[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:u.toBase58()}}];return(await e.getProgramAccounts(o,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:u.toBase58()}}];return await e.getProgramAccounts(o,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await X(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await X(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await X(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await X(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await X(e,t,exports.Record.DOGE),exports.getDomainKey=K,exports.getDomainKeySync=W,exports.getEmailRecord=async(e,t)=>await X(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await X(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await s.FavouriteDomain.getKey(s.NAME_OFFERS_ID,new e.PublicKey(r)),a=await s.FavouriteDomain.retrieve(t,i),n=await I(t,a.nameAccount);return{domain:a.nameAccount,reverse:n}},exports.getGithubRecord=async(e,t)=>await X(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await B(r.toString()),a=await E(i,d,y);let s=await C.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=B,exports.getHashedNameSync=k,exports.getInjectiveRecord=async(e,t)=>await X(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await X(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await X(e,t,exports.Record.LTC),exports.getNameAccountKey=E,exports.getNameAccountKeySync=P,exports.getNameOwner=v,exports.getPicRecord=async(e,t)=>await X(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await X(e,t,exports.Record.POINT),exports.getRecord=X,exports.getRecordKey=Y,exports.getRedditRecord=async(e,t)=>await X(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await K(e),a=await B(r.toBase58());return await E(a,w,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=W(e),a=k(r.toBase58());return P(a,w,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await X(e,t,exports.Record.SHDW),exports.getSolRecord=Z,exports.getTelegramRecord=async(e,t)=>await X(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=G,exports.getTokenInfoFromName=async(t,r)=>{const i=await E(await B(r),void 0,j),{registry:a}=await R.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(S.deserialize(a.data).mint);return await G(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:d.toBase58()}}],s=await t.getProgramAccounts(o,{filters:a});for(const t of s)if(t.account.data.length>R.HEADER_LEN+32){let r=t.account.data.slice(R.HEADER_LEN),a=i.deserializeUnchecked(C.schema,C,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await X(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await B(t),i=await E(r,void 0,y),{registry:a}=await R.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(o,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(R.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await B(e);return await E(t,void 0,y)},exports.getUrlRecord=async(e,t)=>await X(e,t,exports.Record.Url),exports.performReverseLookup=I,exports.performReverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=await B(e.toBase58()),r=await E(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.registerDomainName=async(t,r,i,a)=>{const[s]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),n=await B(t),c=await E(n,void 0,u),p=await B(c.toBase58()),f=await E(p,s),[w]=await e.PublicKey.findProgramAddress([c.toBuffer()],l);return[[],[new F({name:t,space:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,c,f,s,i,a,g,w)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=await K(r),{registry:a,nftOwner:s}=await R.retrieve(t,i);if(s)return s;try{const i=await K(exports.Record.SOL+"."+r,!0),s=await Z(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!J(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=h,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=A,exports.reverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=k(e.toBase58()),r=P(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.transferInstruction=L,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,i,a);let u;return u=i||(await R.retrieve(e,c)).registry.owner,L(o,c,r,u,i,a,s)},exports.updateInstruction=O,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,a,s);let u;return u=a||(await R.retrieve(e,c)).registry.owner,O(o,c,new D(r),i,u)};
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t=require("bn.js"),r=require("@ethersproject/sha2"),i=require("borsh"),a=require("@solana/spl-token"),s=require("@bonfida/name-offers"),n=require("tweetnacl");const o=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),c="SPL Name Service",u=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),l=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),p=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),f=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),w=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),d=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),y=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),g=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),m=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),b=Buffer.from("tokenized_name"),h=async(t,r)=>{try{const[i]=await e.PublicKey.findProgramAddress([b,r.toBuffer()],m);if("0"===(await a.getMint(t,i)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:i.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await t.getProgramAccounts(a.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class R{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,R,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await h(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,R,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}R.HEADER_LEN=96,R.schema=new Map([[R,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class x{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(x.schema,this)}static deserialize(e){return i.deserializeUnchecked(x.schema,x,e)}}x.schema=new Map([[x,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class S{constructor(e){this.mint=e.mint}serialize(){return i.serialize(S.schema,this)}static deserialize(e){return i.deserializeUnchecked(S.schema,S,e)}}async function v(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return R.retrieve(e,t)}async function B(e){const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")}S.schema=new Map([[S,{kind:"struct",fields:[["mint",[32]]]}]]);const k=e=>{const t=c+e,i=r.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(i,"hex")};async function E(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,o);return s}const P=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,o);return s};async function I(e,r){const i=await B(r.toBase58()),a=await E(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}async function A(e,r){const i=k(r.toBase58()),a=P(i,w),{registry:s}=await R.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new t(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const T=async(e,t=u)=>{let r=await B(e);return{pubkey:await E(r,void 0,t),hashed:r}},K=(e,t=u)=>{let r=k(e);return{pubkey:P(r,void 0,t),hashed:r}},N=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await T(r[1]);return{...await T(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await T(r[2]),{pubkey:t}=await T("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await T(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await T(e,u),isSub:!1,parent:void 0}},W=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=K(r[1]);return{...K(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=K(r[2]),{pubkey:t}=K("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...K(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...K(e,u),isSub:!1,parent:void 0}};class D extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class _ extends t{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new t([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function H(t,r,i,a,s,n,o,c,u,l,p){const f=[Buffer.from(Int8Array.from([0])),new D(n.length).toBuffer(),n,o.toBuffer(),c.toBuffer()],w=Buffer.concat(f),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return u?d.push({pubkey:u,isSigner:!0,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l?d.push({pubkey:l,isSigner:!1,isWritable:!1}):d.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),p&&d.push({pubkey:p,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:d,programId:t,data:w})}function O(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new D(a.length).toBuffer(),a],o=Buffer.concat(n),c=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:c,programId:t,data:o})}function L(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),l=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&l.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:t,data:u})}function z(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class F{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(F.schema,this)}getInstruction(t,r,i,s,n,o,c,u,l,p,f){const w=Buffer.from(this.serialize()),d=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:d,programId:t,data:w})}}F.schema=new Map([[F,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class M{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(M.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const l=Buffer.from(this.serialize());let p=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");p.push({pubkey:c,isSigner:!1,isWritable:!0}),p.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:p,programId:t,data:l})}}async function U(e,t,r,i,a){const s=await B(t),n=await E(s,i,a);let c;c=i||(await R.retrieve(e,n)).registry.owner;return z(o,n,r,c)}M.schema=new Map([[M,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class C{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,C,r.data.slice(R.HEADER_LEN))}}async function V(t,r,a,s,n){const c=await B(s.toString()),u=await E(c,d,y);let l=i.serialize(C.schema,new C({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[H(o,e.SystemProgram.programId,u,s,n,c,new _(await t.getMinimumBalanceForRentExemption(l.length+R.HEADER_LEN)),new D(l.length),d,y,d),O(o,u,new D(0),Buffer.from(l),d)]}C.schema=new Map([[C,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const j=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),G=async(e,t)=>{const r=await E(await B(t.toBase58()),void 0,j),{registry:i}=await R.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return x.deserialize(i.data)};var q;exports.Record=void 0,(q=exports.Record||(exports.Record={})).IPFS="IPFS",q.ARWV="ARWV",q.SOL="SOL",q.ETH="ETH",q.BTC="BTC",q.LTC="LTC",q.DOGE="DOGE",q.Email="email",q.Url="url",q.Discord="discord",q.Github="github",q.Reddit="reddit",q.Twitter="twitter",q.Telegram="telegram",q.Pic="pic",q.SHDW="SHDW",q.POINT="POINT",q.BSC="BSC",q.Injective="INJECT";const Y=async(e,t)=>{const{pubkey:r}=await N(t+"."+e,!0);return r},X=async(e,t,r)=>{var i,a;const s=await Y(t,r);let{registry:n}=await R.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},Z=async(e,t)=>await X(e,t,exports.Record.SOL),J=(e,t,r)=>n.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=f,exports.BONFIDA_USDC_BNB=g,exports.HASH_PREFIX=c,exports.MINT_PREFIX=b,exports.Mint=S,exports.NAME_PROGRAM_ID=o,exports.NAME_TOKENIZER_ID=m,exports.NameRegistryState=R,exports.Numberu32=D,exports.Numberu64=_,exports.PYTH_FIDA_PRICE_ACC=p,exports.REGISTER_PROGRAM_ID=l,exports.REVERSE_LOOKUP_CLASS=w,exports.ROOT_DOMAIN_ACCOUNT=u,exports.ReverseTwitterRegistryState=C,exports.SOL_RECORD_SIG_LEN=96,exports.TOKEN_TLD=j,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=y,exports.TWITTER_VERIFICATION_AUTHORITY=d,exports.TokenData=x,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await B(e),s=await E(a,void 0,y);return[O(o,s,new D(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await B(t),n=await E(s,void 0,y);let c=[L(o,n,i,r,void 0)];const u=await B(r.toString());return await E(u,d,void 0),c.push(await U(e,r.toString(),a,d,y)),c=c.concat(await V(e,t,n,i,a)),c},exports.checkSolRecord=J,exports.createInstruction=H,exports.createNameRegistry=async function(t,r,i,a,s,n,c,u){const l=await B(r),p=await E(l,c,u),f=n||await t.getMinimumBalanceForRentExemption(i);let w;if(u){const{registry:e}=await v(t,u);w=e.owner}return H(o,e.SystemProgram.programId,p,s,a,l,new _(f),new D(i),c,u,w)},exports.createReverseInstruction=M,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),c=await B(t.toBase58()),p=await E(c,n,a);return[[],[new M({name:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,p,n,i,a,s)]]},exports.createReverseTwitterRegistry=V,exports.createV2Instruction=F,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await B(r),c=await E(n,void 0,y),u=await t.getMinimumBalanceForRentExemption(a+R.HEADER_LEN);let l=[H(o,e.SystemProgram.programId,c,i,s,n,new _(u),new D(a),void 0,y,d)];return l=l.concat(await V(t,r,c,i,s)),l},exports.deleteInstruction=z,exports.deleteNameRegistry=U,exports.deleteTwitterRegistry=async function(e,t){const r=await B(e),i=await E(r,void 0,y),a=await B(t.toString()),s=await E(a,d,y);return[z(o,i,t,t),z(o,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:w.toBase58()}}],i=await e.getProgramAccounts(o,{filters:r}),a=await A(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>W(e+"."+a).pubkey)),c=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!c[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:u.toBase58()}}];return(await e.getProgramAccounts(o,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:u.toBase58()}}];return await e.getProgramAccounts(o,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await X(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await X(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await X(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await X(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await X(e,t,exports.Record.DOGE),exports.getDomainKey=N,exports.getDomainKeySync=W,exports.getEmailRecord=async(e,t)=>await X(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await X(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await s.FavouriteDomain.getKey(s.NAME_OFFERS_ID,new e.PublicKey(r)),a=await s.FavouriteDomain.retrieve(t,i),n=await I(t,a.nameAccount);return{domain:a.nameAccount,reverse:n}},exports.getGithubRecord=async(e,t)=>await X(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await B(r.toString()),a=await E(i,d,y);let s=await C.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=B,exports.getHashedNameSync=k,exports.getInjectiveRecord=async(e,t)=>await X(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await X(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await X(e,t,exports.Record.LTC),exports.getNameAccountKey=E,exports.getNameAccountKeySync=P,exports.getNameOwner=v,exports.getPicRecord=async(e,t)=>await X(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await X(e,t,exports.Record.POINT),exports.getRecord=X,exports.getRecordKey=Y,exports.getRecordKeySync=(e,t)=>{const{pubkey:r}=W(t+"."+e,!0);return r},exports.getRedditRecord=async(e,t)=>await X(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await N(e),a=await B(r.toBase58());return await E(a,w,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=W(e),a=k(r.toBase58());return P(a,w,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await X(e,t,exports.Record.SHDW),exports.getSolRecord=Z,exports.getTelegramRecord=async(e,t)=>await X(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=G,exports.getTokenInfoFromName=async(t,r)=>{const i=await E(await B(r),void 0,j),{registry:a}=await R.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(S.deserialize(a.data).mint);return await G(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:d.toBase58()}}],s=await t.getProgramAccounts(o,{filters:a});for(const t of s)if(t.account.data.length>R.HEADER_LEN+32){let r=t.account.data.slice(R.HEADER_LEN),a=i.deserializeUnchecked(C.schema,C,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await X(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await B(t),i=await E(r,void 0,y),{registry:a}=await R.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:y.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(o,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(R.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await B(e);return await E(t,void 0,y)},exports.getUrlRecord=async(e,t)=>await X(e,t,exports.Record.Url),exports.performReverseLookup=I,exports.performReverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=await B(e.toBase58()),r=await E(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.registerDomainName=async(t,r,i,a)=>{const[s]=await e.PublicKey.findProgramAddress([l.toBuffer()],l),n=await B(t),c=await E(n,void 0,u),p=await B(c.toBase58()),f=await E(p,s),[w]=await e.PublicKey.findProgramAddress([c.toBuffer()],l);return[[],[new F({name:t,space:r}).getInstruction(l,e.SYSVAR_RENT_PUBKEY,o,u,c,f,s,i,a,g,w)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=await N(r),{registry:a,nftOwner:s}=await R.retrieve(t,i);if(s)return s;try{const i=await N(exports.Record.SOL+"."+r,!0),s=await Z(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!J(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=h,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=A,exports.reverseLookupBatch=async function(e,r){let i=[];for(let e of r){const t=k(e.toBase58()),r=P(t,w);i.push(r)}return(await R.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let r=new t(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+r).toString()}))},exports.transferInstruction=L,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,i,a);let u;return u=i||(await R.retrieve(e,c)).registry.owner,L(o,c,r,u,i,a,s)},exports.updateInstruction=O,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await B(t),c=await E(n,a,s);let u;return u=a||(await R.retrieve(e,c)).registry.owner,O(o,c,new D(r),i,u)};
|
package/dist/record.d.ts
CHANGED
|
@@ -2,12 +2,20 @@ import { Record } from "./types/record";
|
|
|
2
2
|
import { Connection } from "@solana/web3.js";
|
|
3
3
|
import { NameRegistryState } from "./state";
|
|
4
4
|
/**
|
|
5
|
+
* @deprecated Use {@link getRecordKeySync} instead
|
|
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
11
|
export declare const getRecordKey: (domain: string, record: Record) => Promise<import("@solana/web3.js").PublicKey>;
|
|
12
|
+
/**
|
|
13
|
+
* This function can be used to derive a record key
|
|
14
|
+
* @param domain The .sol domain name
|
|
15
|
+
* @param record The record to derive the key for
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const getRecordKeySync: (domain: string, record: Record) => import("@solana/web3.js").PublicKey;
|
|
11
19
|
/**
|
|
12
20
|
* This function can be used to retrieve a specified record for the given domain name
|
|
13
21
|
* @param connection The Solana RPC connection object
|
package/package.json
CHANGED
package/src/record.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Record } from "./types/record";
|
|
2
2
|
import { Connection } from "@solana/web3.js";
|
|
3
|
-
import { getDomainKey } from "./utils";
|
|
3
|
+
import { getDomainKey, getDomainKeySync } from "./utils";
|
|
4
4
|
import { NameRegistryState } from "./state";
|
|
5
5
|
import { SOL_RECORD_SIG_LEN } from "./constants";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* @deprecated Use {@link getRecordKeySync} instead
|
|
8
9
|
* This function can be used to derive a record key
|
|
9
10
|
* @param domain The .sol domain name
|
|
10
11
|
* @param record The record to derive the key for
|
|
@@ -15,6 +16,17 @@ export const getRecordKey = async (domain: string, record: Record) => {
|
|
|
15
16
|
return pubkey;
|
|
16
17
|
};
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* This function can be used to derive a record key
|
|
21
|
+
* @param domain The .sol domain name
|
|
22
|
+
* @param record The record to derive the key for
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export const getRecordKeySync = (domain: string, record: Record) => {
|
|
26
|
+
const { pubkey } = getDomainKeySync(record + "." + domain, true);
|
|
27
|
+
return pubkey;
|
|
28
|
+
};
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* This function can be used to retrieve a specified record for the given domain name
|
|
20
32
|
* @param connection The Solana RPC connection object
|