@tuwaio/nova-payments 0.3.0 → 0.5.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/README.md +12 -1
- package/dist/chunk-BPBRT7WV.cjs +1 -0
- package/dist/chunk-SB5LW2OQ.js +1 -0
- package/dist/de-PVPQNE4K.js +1 -0
- package/dist/de-RZFQ3674.cjs +1 -0
- package/dist/es-GOJORJOI.js +1 -0
- package/dist/es-LRJYQNXS.cjs +1 -0
- package/dist/evm/index.cjs +1 -1
- package/dist/evm/index.js +1 -1
- package/dist/i18n/index.cjs +1 -1
- package/dist/i18n/index.d.cts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.css +3 -0
- package/dist/index.d.cts +117 -31
- package/dist/index.d.ts +117 -31
- package/dist/index.js +2 -2
- package/dist/it-AHKP5KMI.cjs +1 -0
- package/dist/it-AYCHUHO5.js +1 -0
- package/dist/{locales-dTcrLl9B.d.cts → locales-fU-NVESw.d.cts} +41 -28
- package/dist/{locales-dTcrLl9B.d.ts → locales-fU-NVESw.d.ts} +41 -28
- package/dist/solana/index.cjs +1 -1
- package/dist/solana/index.js +1 -1
- package/dist/{types-DOxwRLyU.d.ts → types-DQDwgCpt.d.cts} +17 -1
- package/dist/{types-DOxwRLyU.d.cts → types-DQDwgCpt.d.ts} +17 -1
- package/dist/uk-3MU32HNY.js +1 -0
- package/dist/uk-ITONA5SG.cjs +1 -0
- package/dist/zhCN-EOV4NMX5.js +1 -0
- package/dist/zhCN-W2PLK7SO.cjs +1 -0
- package/package.json +3 -3
- package/dist/chunk-4HBN6N7D.cjs +0 -1
- package/dist/chunk-A2WIFZQB.js +0 -1
- package/dist/de-5UOOKHHH.cjs +0 -1
- package/dist/de-U3SERR3Y.js +0 -1
- package/dist/es-J6MJIGEI.js +0 -1
- package/dist/es-WSJ36B6Y.cjs +0 -1
- package/dist/it-KX7WWME3.js +0 -1
- package/dist/it-QORQLELA.cjs +0 -1
- package/dist/uk-GMKBC44N.js +0 -1
- package/dist/uk-R2A3XIGT.cjs +0 -1
- package/dist/zhCN-5JP4MWXH.cjs +0 -1
- package/dist/zhCN-AX2E4I6A.js +0 -1
package/dist/evm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a,b}from'../chunk-7HSDAUKN.js';import {OrbitAdapter,toEvmChainId,delay}from'@tuwaio/orbit-core';import {TransactionTracker}from'@tuwaio/pulsar-core';import {sendCalls,waitForCallsStatus,getPublicClient,signMessage,getConnectorClient,sendTransaction,writeContract,switchChain,getCapabilities,estimateGas,estimateFeesPerGas,getBalance,readContract,getConnection}from'@wagmi/core';import {hexToBigInt,http,erc20Abi,encodeFunctionData}from'viem';import {toSimple7702SmartAccount,createBundlerClient,createPaymasterClient}from'viem/account-abstraction';import {privateKeyToAccount,generatePrivateKey}from'viem/accounts';var
|
|
1
|
+
import {a,b}from'../chunk-7HSDAUKN.js';import {OrbitAdapter,toEvmChainId,delay}from'@tuwaio/orbit-core';import {TransactionTracker}from'@tuwaio/pulsar-core';import {payoutRecordText}from'@tuwaio/quasar-sdk/checkout';import {sendCalls,waitForCallsStatus,getPublicClient,verifyMessage,signMessage,getConnectorClient,sendTransaction,writeContract,switchChain,getCapabilities,estimateGas,estimateFeesPerGas,getBalance,readContract,getConnection}from'@wagmi/core';import {hexToBigInt,http,isHex,isAddressEqual,recoverMessageAddress,erc20Abi,encodeFunctionData}from'viem';import {toSimple7702SmartAccount,createBundlerClient,createPaymasterClient}from'viem/account-abstraction';import {privateKeyToAccount,generatePrivateKey}from'viem/accounts';var Z=18e4,ee=30*6e4,te=15e3,ae=25n;function y(t){let i=toEvmChainId(t);if(i===void 0)throw new Error(`${t} is not an EVM chain`);return i}function A(t){if(t.family!=="eip155")throw new Error(`${t.chainId} is not an EVM chain`);return t}function S(t){return t.token==="native"?{to:t.to,value:BigInt(t.amount)}:{to:t.token,data:encodeFunctionData({abi:erc20Abi,functionName:"transfer",args:[t.to,BigInt(t.amount)]})}}async function ne(t,i,u){try{return {gas:(await estimateGas(t,{account:i,chainId:u.chainId,...S(u)})*(100n+ae)+99n)/100n}}catch{return {}}}async function se(t){if(t?.type!=="walletConnect")return false;try{let i=await t.getProvider();return /^safe\b/i.test(i.session?.peer?.metadata?.name??"")}catch{return false}}var re=1e4;async function ie(t,i){let l=await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:i,params:[]}),signal:AbortSignal.timeout(re)})).json();if(l.error||l.result===void 0)throw new Error(l.error?.message??`${i} failed`);return l.result}function fe(t){let i=async()=>{let a$1=getConnection(t).connector;if(a$1?.id==="safe"||a$1?.type==="safe"||await se(a$1))throw new a("unsupported","A Safe wallet cannot pay this checkout")},u=async a$1=>{let n;try{n=await getConnection(t).connector?.getChainId();}catch{return}if(!(n===void 0||n===a$1))try{await switchChain(t,{chainId:a$1});}catch(e){let s=b(e);throw s==="declined"?new a("declined",`The wallet declined the switch to ${a$1}`,{cause:e,step:"switch"}):s!=="failed"?e:new a("switchFailed",`The wallet did not switch to ${a$1}`,{cause:e,step:"switch"})}},l=async(a,n,e)=>{for(;Date.now()<n;){try{let s=await waitForCallsStatus(t,{id:a,timeout:n-Date.now()});if(s.status==="failure")return;let r=s.status==="success"?s.receipts?.at(-1)?.transactionHash:void 0;if(r)return e?.(r)}catch{}await delay(void 0,te);}};return {family:"eip155",getBalance:async({chainId:a,account:n,token:e})=>{let s=y(a);return e==="native"?(await getBalance(t,{address:n,chainId:s})).value:readContract(t,{address:e,abi:erc20Abi,functionName:"balanceOf",args:[n],chainId:s})},estimateFee:async({instructions:a,account:n})=>{let e=A(a),s=await estimateGas(t,{account:n,chainId:e.chainId,...S(e)}),r=await estimateFeesPerGas(t,{chainId:e.chainId}),o=r.maxFeePerGas??r.gasPrice;if(o===void 0)return null;let c=t.chains.find(d=>d.id===e.chainId)?.nativeCurrency;return {amount:s*o,decimals:c?.decimals??18,symbol:c?.symbol??"ETH"}},canSponsorCalls:async({chainId:a,account:n})=>{try{return (await getCapabilities(t,{account:n,chainId:y(a)})).paymasterService?.supported===!0}catch{return false}},switchChain:async a=>{await switchChain(t,{chainId:y(a)});},sendTransfer:async({instructions:a,account:n})=>{let e=A(a);if(await i(),await u(e.chainId),e.token==="native"){let s=await ne(t,n,e);return sendTransaction(t,{account:n,chainId:e.chainId,to:e.to,value:BigInt(e.amount),...s})}return writeContract(t,{account:n,chainId:e.chainId,address:e.token,abi:erc20Abi,functionName:"transfer",args:[e.to,BigInt(e.amount)]})},signTransferAuthorization:async({typedData:a,account:n})=>{await i();let e=Number(a.domain.chainId);return await u(e),(await getConnectorClient(t,{chainId:e})).request({method:"eth_signTypedData_v4",params:[n,JSON.stringify(a)]})},signMessage:async({message:a,account:n,chainId:e})=>{await i();let s=toEvmChainId(e);return s!==void 0&&await u(s),signMessage(t,{account:n,message:a})},verifyPayoutRecord:async({record:a,signature:n,chainId:e})=>{if(!isHex(n))return false;let s=a.address,r=payoutRecordText(a);try{if(isAddressEqual(await recoverMessageAddress({message:r,signature:n}),s))return !0}catch{}let o=toEvmChainId(e);return o===void 0?false:verifyMessage(t,{address:s,message:r,signature:n,chainId:o})},followSponsoredCalls:({batchId:a,until:n,onLate:e})=>{l(a,n,e).catch(()=>{});},sendOneTimeRelay:async({chainId:a$1,call:n,paymasterUrl:e})=>{let s=toEvmChainId(a$1),r=s===void 0?void 0:getPublicClient(t,{chainId:s});if(s===void 0||!r)throw new a("unsupported",`The network ${a$1} is not configured`);let o=privateKeyToAccount(generatePrivateKey()),c=await toSimple7702SmartAccount({client:r,owner:o}),d=createBundlerClient({account:c,client:r,transport:http(e),paymaster:createPaymasterClient({transport:http(e)}),userOperation:{estimateFeesPerGas:async()=>{let p=await ie(e,"pimlico_getUserOperationGasPrice");return {maxFeePerGas:hexToBigInt(p.fast.maxFeePerGas),maxPriorityFeePerGas:hexToBigInt(p.fast.maxPriorityFeePerGas)}}}}),w=await o.signAuthorization({chainId:s,contractAddress:c.authorization.address,nonce:0});return d.sendUserOperation({calls:[{to:n.to,data:n.data}],authorization:w})},sendSponsoredCalls:async({calls:a$1,paymasterUrl:n,chainId:e,account:s,onSent:r,onAccepted:o,onLate:c})=>{await i(),await u(y(e));let{id:d}=await sendCalls(t,{account:s,chainId:y(e),calls:a$1.map(m=>({to:m.to,value:BigInt(m.value),data:m.data})),capabilities:{paymasterService:{url:n}}});o?.(d),r?.();let w=m=>(l(d,Date.now()+ee,c).catch(()=>{}),new a("sentUnconfirmed","The sponsored payment is not confirmed yet",{cause:m})),p=await waitForCallsStatus(t,{id:d,timeout:Z}).catch(m=>{throw w(m)});if(p.status==="failure")throw new a("failed","The sponsored payment failed");let C=p.status==="success"?p.receipts?.at(-1)?.transactionHash:void 0;if(!C)throw w();return C},explorerUrl:({chainId:a,txKey:n})=>{let s=t.chains.find(r=>r.id===toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/tx/${n}`:void 0},explorerAddressUrl:({chainId:a,address:n})=>{let s=t.chains.find(r=>r.id===toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/address/${n}`:void 0},pulsarTransaction:({txKey:a,instructions:n,account:e,connectorType:s,title:r,description:o,payload:c})=>{let d=A(n);return {adapter:OrbitAdapter.EVM,tracker:TransactionTracker.Ethereum,txKey:a,hash:a,chainId:d.chainId,from:e,to:d.token==="native"?d.to:d.token,type:"payment",connectorType:s,title:r,description:o,payload:c,pending:true,localTimestamp:Math.floor(Date.now()/1e3),isTrackedModalOpen:false}}}}export{fe as paymentsEVMAdapter};
|
package/dist/i18n/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkBPBRT7WV_cjs=require('../chunk-BPBRT7WV.cjs');Object.defineProperty(exports,"CHECKOUT_LOCALES",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.e}});Object.defineProperty(exports,"checkoutLocaleOf",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.f}});Object.defineProperty(exports,"defaultLabels",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.a}});Object.defineProperty(exports,"formatCountLabel",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.b}});Object.defineProperty(exports,"formatLabel",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.c}});Object.defineProperty(exports,"formatLabelParts",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.d}});Object.defineProperty(exports,"hasLabels",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.g}});Object.defineProperty(exports,"labelsForLocale",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.h}});Object.defineProperty(exports,"loadLabels",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.i}});Object.defineProperty(exports,"mergeLabels",{enumerable:true,get:function(){return chunkBPBRT7WV_cjs.j}});
|
package/dist/i18n/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NovaPaymentsLabels } from '../locales-
|
|
2
|
-
export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-
|
|
1
|
+
import { N as NovaPaymentsLabels } from '../locales-fU-NVESw.cjs';
|
|
2
|
+
export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-fU-NVESw.cjs';
|
|
3
3
|
export { formatCountLabel, formatLabel, formatLabelParts } from '@tuwaio/nova-core/utils';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NovaPaymentsLabels } from '../locales-
|
|
2
|
-
export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-
|
|
1
|
+
import { N as NovaPaymentsLabels } from '../locales-fU-NVESw.js';
|
|
2
|
+
export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-fU-NVESw.js';
|
|
3
3
|
export { formatCountLabel, formatLabel, formatLabelParts } from '@tuwaio/nova-core/utils';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/i18n/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{e as CHECKOUT_LOCALES,f as checkoutLocaleOf,a as defaultLabels,b as formatCountLabel,c as formatLabel,d as formatLabelParts,g as hasLabels,h as labelsForLocale,i as loadLabels,j as mergeLabels}from'../chunk-
|
|
1
|
+
export{e as CHECKOUT_LOCALES,f as checkoutLocaleOf,a as defaultLabels,b as formatCountLabel,c as formatLabel,d as formatLabelParts,g as hasLabels,h as labelsForLocale,i as loadLabels,j as mergeLabels}from'../chunk-SB5LW2OQ.js';
|