forked from kylingood/script_galxe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
claim.ts
83 lines (71 loc) · 3.19 KB
/
claim.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import crypto from 'crypto';
import { ethers } from 'ethers';
import { Galex } from './module';
import { appendFileSync } from 'fs';
const createKeccakHash = require('keccak');
const bscProvider = new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/bsc/a9603e82251e01bf7e40029505b09457e83ed9ceaa56043dbb9657f2b676ef05');
function encryptPassportData(data: any, password: string) {
var e = JSON.stringify(JSON.parse(data));
var n = createKeccakHash('keccak256').update(password).digest()
var o = crypto.randomBytes(12)
var r = crypto.createCipheriv("aes-256-gcm", n, o)
var c = r.update(e);
r.final("base64");
return "0x" + Buffer.concat([o, c, r.getAuthTag()]).toString("hex")
}
export const claimPassport = async (wallet: ethers.Wallet, password: string) => {
const account = new Galex({ privateKey: wallet.privateKey })
let { addressInfo } = await account.basicUserInfo();
if (addressInfo.passport.status === 'ISSUED_NOT_MINTED' && !addressInfo.passport.id) {
console.log(`[${wallet.address}] ${addressInfo.passport.status} 无法Mint Passport`)
return
}
if (addressInfo.passport.status === 'PENDING_PREPARE' || addressInfo.passport.status === 'PENDING_SAVE') {
let signature = await wallet.signMessage(`prepare_address_passport:${wallet.address.toLocaleLowerCase()}`);
const { preparePassport } = await account.preparePassport({ signature });
signature = await wallet.signMessage(`save_address_passport:${wallet.address.toLocaleLowerCase()}`);
const cipher = encryptPassportData(preparePassport.data, password)
await account.savePassport({ cipher, signature });
}
;({ addressInfo } = await account.basicUserInfo());
if (!addressInfo.passport.id) {
console.log(`[${wallet.address}] kyc认证未通过, 无法Mint Passport`)
// 将未过kyc的私钥追加到文件中,方便重新生成认证链接
appendFileSync('./unverify_keys.txt', `${wallet.privateKey}\n`)
return
}
// 获取mint信息
const { prepareParticipate } = await account.getPrepareParticipate({
signature: '',
campaignID: 'GCfBiUt5ye',
chain: 'BSC',
mintCount: 1,
})
const { mintFuncInfo, allow, signature } = prepareParticipate;
if (!mintFuncInfo || !allow) {
return console.log(`[${wallet.address}] 领取NFT/获取签名信息失败, ${prepareParticipate.disallowReason}}`)
}
const abi = ['function claim(uint256, address, uint256, uint256, bytes) payable']
const ca = '0x2D18f2d27D50C9b4013DEBA3D54f60996bD8847E';
const signer = wallet.connect(bscProvider);
const contract = new ethers.Contract(ca, abi, signer)
const balance = await bscProvider.getBalance(wallet.address);
const value = ethers.utils.parseEther('0.025');
if (balance.lt(value)) {
return console.log(`[${wallet.address}] Mint NFT失败: 余额不足`)
}
console.log(`[${wallet.address}] 开始领取NFT...`)
const tx = await contract.claim(
mintFuncInfo.powahs[0],
mintFuncInfo.nftCoreAddress,
mintFuncInfo.verifyIDs[0],
mintFuncInfo.powahs[0],
signature,
{
value,
gasPrice: ethers.utils.parseUnits('1', 'gwei'),
}
)
const reicept = await tx.wait();
console.log(`[${wallet.address}] 成功领取NFT tx: ${reicept.transactionHash}`)
}