Shawn Lu 1 년 전
부모
커밋
40b188fa28
1개의 변경된 파일115개의 추가작업 그리고 115개의 파일을 삭제
  1. 115 115
      src/faucet/faucet.ts

+ 115 - 115
src/faucet/faucet.ts

@@ -1,10 +1,11 @@
 import {
   forEachAsync,
+  generate2CaptchaProxyAgent,
   generateRandomString,
   getAxiosClient,
   getProxyAgent,
 } from '../utils'
-import { getAltchaPayload, solveHCaptcha } from './captcha'
+import { getAltchaPayload, getRecaptcha, solveHCaptcha } from './captcha'
 import { DBClient } from '../singletons'
 import { Status } from '../models/Status'
 import polly from 'polly-js'
@@ -13,7 +14,6 @@ import { ethers } from 'ethers'
 import { v4 as uuidv4 } from 'uuid'
 import axios from 'axios'
 import xrpl from 'xrpl'
-import crypto from 'crypto'
 
 export async function faucetAccount(address: string) {
   const client = getAxiosClient(true)
@@ -62,11 +62,36 @@ async function startFaucet(concurrency, index) {
   })
 }
 
-function hashWithSHA512(data) {
-  const hash = crypto.createHash('sha512')
-  hash.update(data)
-  return hash.digest('hex')
+function formatDateTime(date) {
+  function pad(number, length) {
+    return number.toString().padStart(length, '0')
+  }
+
+  const offset = -date.getTimezoneOffset()
+  const offsetSign = offset >= 0 ? '+' : '-'
+  const offsetHours = pad(Math.floor(Math.abs(offset) / 60), 2)
+  const offsetMinutes = pad(Math.abs(offset) % 60, 2)
+
+  return (
+    date.getFullYear() +
+    '-' +
+    pad(date.getMonth() + 1, 2) +
+    '-' +
+    pad(date.getDate(), 2) +
+    'T' +
+    pad(date.getHours(), 2) +
+    ':' +
+    pad(date.getMinutes(), 2) +
+    ':' +
+    pad(date.getSeconds(), 2) +
+    '.' +
+    pad(date.getMilliseconds(), 3) +
+    offsetSign +
+    offsetHours +
+    offsetMinutes
+  )
 }
+
 async function faucetLunch(concurrency: number = 8) {
   const now = new Date()
   const accounts = await DBClient.instance.account.findMany({
@@ -79,119 +104,82 @@ async function faucetLunch(concurrency: number = 8) {
     orderBy: {
       id: 'desc',
     },
-    take: 1,
   })
-  // f46818e3b5a63aa6bfe6bb0d5607e85e5caed881ac39bba8cd4de64c40dcfa4698bac6210218c23425af731232eae567017c2627f1a691cfb5c665a7b175a4fd
-  // 2a43da0eb4aeab62e6d44e19ea87c1a4bdd4c0a0e4e1ea4ef910769c9f97a2d8dd4a0df55942d51351f6f40a3a06214598a329e287dab31a1b11cf8975ed311e
-  // af7eedf65e0f44cd6a82c42d53b90c7e2c3b39285af4e0bee73914331185fd9f
-  // a3e6fcfd02c098840d0a934b6082f5c05004fad4b303178276ac8839f3717bd2
-  // e3b497c64a50dabdd4a41f5f7a94a91c874f53d88740a0c39100f175fe066c68
-  // 0x2bc04dc33a6c298be846d85062ffca9997f1f06b05bc85ae060327975aaf80fb55598d2bb2c2a9489134aaee06e08f1811ba843a0f503106f4cd6e159a86c2aa1c
-  // af7eedf65e0f44cd6a82c42d53b90c7e2c3b39285af4e0bee73914331185fd9fa3e6fcfd02c098840d0a934b6082f5c05004fad4b303178276ac8839f3717bd2
-  // 0xa383589e8ad01e29906abfb778a9d48c2e5c1980b1c6bfa971b1205e49b6b8f52ddeaa6cdc35f001e6c6f6bbc03c84f650bd5652d1f782f4a95694f55d26325c1c
   await forEachAsync(accounts, concurrency, async (account, index) => {
     console.log(`${index}/${accounts.length}: processing ${account.address}`)
-    if (!account.gmail) account.gmail = `${generateRandomString(8)}@gmail.com`
-    if (!account.xrpPrivateKey)
-      account.xrpPrivateKey = xrpl.Wallet.generate().seed
-    if (!account.duid) account.duid = uuidv4().toUpperCase()
-    const key = new MnemonicKey({ mnemonic: account.mnemonic })
-    const evmWallet = new ethers.Wallet(key.privateKey.toString('hex'))
-    const current = new Date().toISOString()
-    // const addCurrent = new Date(current.getTime() + 1000 * 60).toISOString()
-    // const message = JSON.stringify({ signedAt: new Date().toISOString() })
-    const first = hashWithSHA512(current.toString())
-    console.log(first)
-    const message = first
-    const second = await evmWallet.signMessage(first)
-    console.log(second)
-    const client = axios.create({
-      headers: {
-        'user-agent':
-          'Lunch/1.0 (xyz.lunchlunch.app; build:44; iOS 16.0.0) Alamofire/5.8.0',
-        'lunch-app-version': 44,
-        'lunch-fiat-currency': 'USD',
-        'lunch-app-duid': account.duid,
-      },
-      httpsAgent: getProxyAgent(),
-    })
-    await polly()
-      .waitAndRetry(0)
-      .executeForPromise(async () => {
-        const resp = await client.post(
-          'https://api.lunchlunch.xyz/v1/auth/sign-in',
-          {
-            walletAddress: evmWallet.address,
-            signedMessage: await evmWallet.signMessage(message),
-            rawMessage: message,
-          },
-        )
-        console.log(`${index}: sign-in success.`)
-        client.defaults.headers[
-          'authorization'
-        ] = `Bearer ${resp.data.accessToken}`
+    try {
+      if (!account.gmail) account.gmail = `${generateRandomString(8)}@gmail.com`
+      if (!account.xrpPrivateKey)
+        account.xrpPrivateKey = xrpl.Wallet.generate().seed
+      if (!account.duid) account.duid = uuidv4().toUpperCase()
 
-        console.log(resp.data.accessToken)
-        const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
-        const register = await client.post(
-          'https://api.lunchlunch.xyz/v1/member/register',
-          {
-            evmWalletAddress: evmWallet.address,
-            initiaWalletAddress: key.accAddress,
-            isImportedWallet: true,
-            firstInitiaWalletAddress: key.accAddress,
-            email: account.gmail,
-            xrplWalletAddress: xrplWallet.address,
-          },
-        )
-        console.log(`${index}: register done`)
-        await DBClient.instance.account.update({
-          where: { id: account.id },
-          data: {
-            lastRun: new Date(),
-            xrpPrivateKey: account.xrpPrivateKey,
-            gmail: account.gmail,
-            duid: account.duid,
-          },
-        })
+      const key = new MnemonicKey({ mnemonic: account.mnemonic })
+      const evmWallet = new ethers.Wallet(key.privateKey.toString('hex'))
+      const message = JSON.stringify({
+        signedAt: formatDateTime(new Date()),
       })
-    return
-    const flag = await polly()
-      .waitAndRetry(20)
-      .executeForPromise(async () => {
-        try {
-          client.defaults.httpsAgent = getProxyAgent()
-          const resp = await client.post(
-            'https://api.lunchlunch.xyz/v1/auth/sign-in',
-            {
-              walletAddress: evmWallet.address,
-              signedMessage: await evmWallet.signMessage(message),
-              rawMessage: message,
-            },
-          )
-          console.log(`${index}: sign-in success.`)
-          client.defaults.headers[
-            'authorization'
-          ] = `Bearer ${resp.data.accessToken}`
-          const airdropResp = await client.post(
-            'https://api.lunchlunch.xyz/v1/dish/submit-action/airdrop',
-            {
-              dishId: 43,
-            },
-          )
-          console.log(`${index}: airdrop done`)
-          return `true`
-        } catch (e) {
-          console.log(e.response.data)
-
-          if (e.response.data.statusCode === 429) {
-            throw e
-          } else {
-            return `error: ${e.response.data.toString()}`
-          }
-        }
+      const evmSignedMessage = await evmWallet.signMessage(message)
+      const rawMessage = ''
+      const deviceModel = 'Mi 9'
+      const deviceOS = 'Android 9'
+      const client = axios.create({
+        headers: {
+          'Lunch-Language': 'EN',
+          'lunch-fiat-currency': 'USD',
+          'lunch-app-duid': 'ddolHGLkR1efgLFeHNLCNM',
+          'lunch-app-version': '0.17.3',
+          'lun-app-build': 46,
+          'Lunch-Device-Model': deviceModel,
+          'Lunch-Device-OS': deviceOS,
+          'Lunch-Platform': 'Android',
+          'user-agent': `lunch/0.17.3(46) (Linux; ${deviceOS}; ${deviceModel} Build/PQ3B.190801.05281822)`,
+        },
+        httpsAgent: getProxyAgent(),
       })
-    if (flag === 'true') {
+
+      const resp = await client.post(
+        'https://api.lunchlunch.xyz/v1/auth/sign-in',
+        {
+          walletAddress: evmWallet.address,
+          signedMessage: evmSignedMessage,
+          rawMessage: rawMessage,
+        },
+      )
+      console.log(`${index}: sign-in success.`)
+      client.defaults.headers[
+        'authorization'
+      ] = `Bearer ${resp.data.accessToken}`
+
+      const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
+      try {
+        const memberResp = await client.get(
+          'https://api.lunchlunch.xyz/v1/member',
+        )
+      } catch (e) {
+
+      }
+
+      const register = await client.post(
+        'https://api.lunchlunch.xyz/v1/member/register',
+        {
+          evmWalletAddress: evmWallet.address,
+          initiaWalletAddress: key.accAddress,
+          isImportedWallet: true,
+          firstInitiaWalletAddress: key.accAddress,
+          email: account.gmail,
+          xrplWalletAddress: xrplWallet.address,
+        },
+      )
+      console.log(`${index}: register done`)
+
+      await client.post(
+        'https://api.lunchlunch.xyz/v1/dish/submit-action/airdrop',
+        {
+          dishId: 43,
+        },
+      )
+      console.log(`${index}: airdrop done`)
+
       await DBClient.instance.account.update({
         where: { id: account.id },
         data: {
@@ -202,12 +190,13 @@ async function faucetLunch(concurrency: number = 8) {
           duid: account.duid,
         },
       })
-    } else {
+    } catch (e) {
+      console.log(e)
       await DBClient.instance.account.update({
         where: { id: account.id },
         data: {
-          message: flag,
           status: Status.FaucetFailed,
+          message: e.message,
           lastRun: new Date(),
           xrpPrivateKey: account.xrpPrivateKey,
           gmail: account.gmail,
@@ -219,3 +208,14 @@ async function faucetLunch(concurrency: number = 8) {
 }
 
 await faucetLunch(1)
+//
+// const phase =
+//   'leave bone supply chair brain thunder giant fatigue winter shrimp father stairs'
+// const wallet = ethers.Wallet.fromPhrase(phase)
+// console.log(wallet.address)
+// const key = new MnemonicKey({
+//   mnemonic: phase,
+// })
+// const rawMessage =
+//   '809a55a47f136226b26cd6f12e61c4b641895e95f7eb43851005884cd8102bac2e231d14775fa9034745491d08910a1c0d0799ddf6926397dd05e733f62bcbb4'
+// const signedAmino = key.createSignatureAmino()