constgenerate=async (schemaId:string, appid:string) => {try {// The appid of the project created in dev centerconstappid="8fb9d43c-2f24-424e-a98d-7ba34a5532f5"// Create the connector instanceconstconnector=newTransgateConnect(appid)// Check if the TransGate extension is installed// If it returns false, please prompt to install it from chrome web storeconstisAvailable=awaitconnector.isTransgateAvailable()if (isAvailable) {// The schema id of the projectconstschemaId="516a720e-29a4-4307-ae7b-5aec286e446e"// Launch the process of verification// This method can be invoked in a loop when dealing with multiple schemasconstres=awaitconnector.launch(schemaId)//If you want to send the result to the blockchain, please add the wallet address as the second parameter.//const res = await connector.launch(schemaId, address)// verifiy the res onchain/offchain based on the requirement } else {console.log('Please install TransGate') } } catch (error) {console.log('transgate error', error) } }
The result includes two signatures: the allocator signature and the validator signature. Developers should verify both signatures based on the other returned fields.
Verify Allocator Signature
Encode the allocator message struct
import Web3 from"web3"constweb3=newWeb3()const { taskId } = res //return by TransgateconsttaskIdHex=Web3.utils.stringToHex(taskId)constschemaIdHex=Web3.utils.stringToHex(schemaId)constencodeParams=web3.eth.abi.encodeParameters( ["bytes32","bytes32","address"], [taskIdHex, schemaIdHex, validatorAddress])constparamsHash=Web3.utils.soliditySha3(encodeParams)
import Web3 from"web3"constweb3=newWeb3()const { taskId,uHash,publicFieldsHash,recipient } = res //return by TransgateconsttaskIdHex=Web3.utils.stringToHex(taskId)constschemaIdHex=Web3.utils.stringToHex(schemaId)consttypes= ["bytes32","bytes32","bytes32","bytes32"]constvalues= [taskIdHex, schemaIdHex, uHash, publicFieldsHash]//If you add the wallet address as the second parameter when launch the Transgateif (recipient) {types.push("address")values.push(recipient)}constencodeParams=web3.eth.abi.encodeParameters(types, values)constparamsHash=Web3.utils.soliditySha3(encodeParams)