import { CallUserCertification } from './struct/CallUserCertification'; import { LocalStorage } from './interface/LocalStorage'; import { pubKey2Address } from './utils/getMnemonicObject' import { generateKeypairPem, AbiCode } from '@vf.js/pki'; import { ClientConfig } from './config/ClientConfig'; import { delUserFilesByKey, getAppXClient, getUserFiles, isAPP, setUserFiles, takeScreenshot } from './app-dsBridge' const ABIJSON = [ { "inputs": [ { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "transfer", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "mint", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, ] export async function main() { ClientConfig.address = '0f566f92f4d8b8e86aedef4c8d6ab990febbd02a'; let userObj = await LocalStorage.get(ClientConfig.address); // 证书 if (!userObj) { console.time('证书时间') // 生成证书 const keypairPem = generateKeypairPem({ "alg": 'EC', "curve": "secp256r1" }) // 生成地址 const address = pubKey2Address(keypairPem!.publicKeyPem); // 设置当前用户选择的地址 ClientConfig.address = address; const callUserCertification = new CallUserCertification(); callUserCertification.address = address; callUserCertification.setKeyPair(keypairPem?.privateKeyPem!, keypairPem?.publicKeyPem!) const certResult = await callUserCertification.send(); if (keypairPem && certResult.data) { await LocalStorage.set({ pemCertificate: certResult.data, pemPrivateKey: keypairPem?.privateKeyPem, pemPublicKey: keypairPem?.publicKeyPem, mnemonic: '', address: address, walletName: '' }); await LocalStorage.setG('selectedAddress', address); userObj = await LocalStorage.get(address); console.log('pemCertificate', certResult.data) console.log('pemPrivateKey', keypairPem?.privateKeyPem); console.log('pemPublicKey', keypairPem?.publicKeyPem); console.log('address', address); } console.timeEnd('证书时间') } // 交易 if (userObj && userObj.pemCertificate) { // console.time('交易时间') // const txResult = await sendTxRequest({ // 'orderNo': '123', // 'serialNo': '123', // "to": 'yx', // "value": 3 // }, d => d) // console.log('交易结果', txResult) } } export async function dsBridgesss() { console.log(navigator.userAgent) console.log('是否调用APP接口:', isAPP) console.log('test dsBridge v26') console.log('start getAppXClient'); const info = await getAppXClient() if (info) { ClientConfig.channelId = info.channelId; ClientConfig.platformId = info.platformId; ClientConfig.deviceId = info.deviceId; ClientConfig.sessionId = info.sessionId; } console.log('end getAppXClient', info.channelId); console.log('start setUserFiles') await setUserFiles('str', 'string'); console.log('end setUserFiles') console.log('start getUserFiles') const str = await getUserFiles('str'); console.log('end getUserFiles', str) console.log('start delUserFilesByKey') await delUserFilesByKey('str'); console.log('end delUserFilesByKey') console.log('start takeScreenshot'); await takeScreenshot(); console.log('end takeScreenshot'); console.log('end dsBridge') } export async function testABI() { const abi = new AbiCode(ABIJSON) const data = abi.encodeFunctionData("transfer", [ "52d04fa0094b3cacace768b4fa2984a00eeab4f8", // 转账到这个地址 '100000000000', // 6 是 USDC 的 decimals ]); debugger console.log(data); } export async function testMain(_bool: boolean) { console.log('是否识别APP宿主: ', isAPP) // testABI(); // if (_bool) { // main(); // dsBridgesss(); // } }