@nexus-cross/pop 1.3.10-beta.2 → 1.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- var r=class extends Error{constructor(e,t,n){super(t),this.name="SafeDropError",this.code=e,this.details=n}};function m(i){return i.trim().replace(/^@/,"").toLowerCase()}function w(i){let e=i.baseUrl.replace(/\/$/,""),t=e.includes("?")?"&":"?";return`${e}${t}sender=${encodeURIComponent(i.sender)}#${encodeURIComponent(i.secret)}`}function b(i){let e=i.indexOf("#"),t=e===-1?i:i.slice(0,e),n=e===-1?"":i.slice(e+1),a=t.indexOf("?"),c=a===-1?"":t.slice(a+1);return{sender:E(c,"sender"),secret:n?decodeURIComponent(n):null}}function O(i){return`\u{1F381} You've received a one-pop drop! Claim your tokens here: ${i}`}function T(i,e){let t=[`text=${encodeURIComponent(i)}`];return e&&t.push(`recipient_id=${encodeURIComponent(e)}`),`https://x.com/messages/compose?${t.join("&")}`}function E(i,e){if(!i)return null;for(let t of i.split("&")){if(!t)continue;let n=t.indexOf("=");if(decodeURIComponent(n===-1?t:t.slice(0,n))===e)return decodeURIComponent(n===-1?"":t.slice(n+1))}return null}var u=class{constructor(e,t,n,a){this.chain=e;this.api=t;this.crypto=n;this.claimBaseUrl=a}async execute(e){if(!e.sender)throw new r("MISSING_SENDER","sender address is required");if(!e.recipient?.handle)throw new r("MISSING_RECIPIENT","recipient social handle is required");if(!e.token)throw new r("INVALID_TOKEN","token address is required (ERC20 only)");if(e.amount<=0n)throw new r("INVALID_AMOUNT","amount must be a positive BigInt");let t=e.secret??this.crypto.randomSecret();if(!t)throw new r("MISSING_SECRET","secret is empty");let n=this.crypto.keccak256(t),a=m(e.recipient.handle);if(!a)throw new r("MISSING_RECIPIENT","recipient handle normalizes to empty");let{claimAddress:c}=await this.api.createClaimWallet({sender:e.sender,recipient:e.recipient,message:e.message,envelopeId:e.envelopeId}),s={claimAddress:c,token:e.token,amount:e.amount,id:a,secretHash:n},{txHash:o}=this.chain.depositWithPermit?await this.chain.depositWithPermit(s):await this.approveThenDeposit(s);return{claimAddress:c,secretHash:n,withdrawLink:w({baseUrl:this.claimBaseUrl,sender:e.sender,secret:t}),depositTxHash:o}}approveThenDeposit(e){return this.chain.approve({token:e.token,amount:e.amount}).then(()=>this.chain.deposit(e))}};var N=BigInt(1800),_=30,f=class{constructor(e,t,n,a=()=>Date.now()){this.chain=e;this.api=t;this.crypto=n;this.now=a}async execute(e){let t=m(e.id);if(!t)throw new r("MISSING_RECIPIENT","batchClaim requires an id (social handle)");let n=this.api.requestBatchClaimSignature;if(!n)throw new r("API_ERROR","SafeDropApiPort.requestBatchClaimSignature is not implemented by the injected api adapter");let{getValidatorNonce:a,getValidatorClaimDigest:c,getValidator:s,withdrawByValidator:o}=this.chain;if(!a||!c||!s||!o)throw new r("CHAIN_ERROR","this chain adapter does not support batch claim (validator functions missing)");let I=await a.call(this.chain,{id:t}),A=e.deadline??BigInt(Math.floor(this.now()/1e3))+(e.deadlineTtlSeconds??N),d=await n.call(this.api,{id:t,oauth:e.oauth,nonce:I,deadline:A}),l=d.recipient;if(!l)throw new r("API_ERROR","batch-claim signature response has no recipient",{signed:d});if(e.recipient&&e.recipient.toLowerCase()!==l.toLowerCase())throw new r("SIGN_FAILED","validator signature is bound to a different recipient",{requested:e.recipient,signed:l});await this.assertRecipientPinnedOnChain(t,l);let R=await c.call(this.chain,{recipient:l,id:t,nonce:d.nonce,deadline:d.deadline});await this.assertSignedByValidator(R,d.signature,s.bind(this.chain));let x=e.maxCount??_,y=[],h=await this.liveCount(t);for(let g=0;h>BigInt(0);g+=1){let P=await o.call(this.chain,{recipient:l,id:t,nonce:d.nonce,deadline:d.deadline,maxCount:x,signature:d.signature});y.push(P);let D=await this.liveCount(t);if(D>=h)throw new r("CHAIN_ERROR","batch claim made no progress",{id:t,remaining:h.toString(),page:g,txHash:P});h=D}return{txHashes:y,recipient:l,id:t,nonce:d.nonce,deadline:d.deadline}}async assertRecipientPinnedOnChain(e,t){let n=this.chain.getClaimedRecipient;if(!n)return;let a=await n.call(this.chain,{id:e});if(!a||/^0x0+$/i.test(a))throw new r("DROP_NOT_FOUND","this id has not claimed individually yet \u2014 the first claim must be an individual withdraw",{id:e});if(a.toLowerCase()!==t.toLowerCase())throw new r("SIGN_FAILED","batch-claim recipient does not match the on-chain claimedRecipientOf(id)",{id:e,signed:t,onChain:a})}async assertSignedByValidator(e,t,n){if(!this.crypto.recoverAddress)return;let[a,c]=await Promise.all([this.crypto.recoverAddress({digest:e,signature:t}),n()]);if(a.toLowerCase()!==c.toLowerCase())throw new r("SIGN_FAILED","batch-claim signature does not recover to the on-chain validator (backend signed a different EIP-712 domain/type, or applied a personal_sign prefix)",{signer:a,validator:c,digest:e})}async liveCount(e){let t=this.chain.getLiveDropCount;if(!t)throw new r("CHAIN_ERROR","this chain adapter cannot read liveDropCountById (required to paginate batch claim)");return t.call(this.chain,{id:e})}};var C=class{constructor(e,t){this.chain=e;this.signer=t}async execute(e){if(!e.recipient)throw new r("MISSING_RECIPIENT","recipient address is required");if(!e.claimAddress)throw new r("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.secret)throw new r("MISSING_SECRET","secret is required");if(!e.claimKey)throw new r("MISSING_CLAIM_KEY","claim key is required");let t=await this.chain.getDrop(e.claimAddress);if(!t)throw new r("DROP_NOT_FOUND",`No drop for claim address ${e.claimAddress}`);let n=await this.chain.getClaimDigest({recipient:e.recipient,id:t.id,salt:t.salt}),a=await this.signer.signDigest({claimKey:e.claimKey,digest:n});return{txHash:await this.chain.withdraw({claimKey:e.claimKey,recipient:e.recipient,id:t.id,salt:t.salt,signature:a,secret:e.secret})}}};var S=class{constructor(e){this.chain=e}async execute(e){if(!e.claimAddress)throw new r("MISSING_CLAIM_ADDRESS","claim address is required");return{txHash:await this.chain.refund({claimAddress:e.claimAddress})}}};function p(i,e){if(!i)throw new r("API_ERROR",`SafeDropApiPort.${e} is not implemented by the injected api adapter`);return i}function J(i,e){let t=new u(e.chain,e.api,e.crypto,i.claimBaseUrl),n=new C(e.chain,e.signer),a=new S(e.chain),c=new f(e.chain,e.api,e.crypto),{api:s}=e;return{config:i,deposit:o=>t.execute(o),retrieveClaimKey:o=>s.retrieveClaimKey(o),withdraw:o=>n.execute(o),refund:o=>a.execute(o),getDrop:o=>e.chain.getDrop(o),listDrops:o=>p(s.listDrops,"listDrops").call(s,o),listEnvelopes:o=>p(s.listEnvelopes,"listEnvelopes").call(s,o),getLeaderboard:o=>p(s.getLeaderboard,"getLeaderboard").call(s,o),listHistories:o=>p(s.listHistories,"listHistories").call(s,o),getXConnection:()=>p(s.getXConnection,"getXConnection").call(s),connectX:o=>p(s.connectX,"connectX").call(s,o),disconnectX:()=>p(s.disconnectX,"disconnectX").call(s),batchClaim:o=>c.execute(o),requestBatchClaimSignature:o=>p(s.requestBatchClaimSignature,"requestBatchClaimSignature").call(s,o)}}export{r as a,m as b,w as c,b as d,O as e,T as f,u as g,f as h,C as i,S as j,J as k};