import { useTonWallet } from"@tonconnect/ui-react"constwallet=useTonWallet()constgenerate=async (schemaId:string, appid:string) => {try {//check if you connect the Ton walletif (!wallet) {returnalert("Please connect the wallet") }// TON address for the Walletconstaddress=wallet.account.address//The appid of the project created in dev center constappid="39a00e9e-7e6d-461e-9b9d-d520b355d1c0"//The schemaId of the projectconstschemaId="c7eab8b7d7e44b05b41b613fe548edf5"constconnector=newTransgateConnect(appid)constisAvailable=awaitconnector.isTransgateAvailable()if (!isAvailable) {returnalert("Please install zkPass TransGate") }constres= (awaitconnector.launchWithTon(schemaId, address)) asResult } catch (err) {alert(JSON.stringify(err))console.log("error", err) } }
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 { Address as TonAddress, beginCell } from'@ton/ton';import { signVerify } from'@ton/crypto';const { taskId,allocatorSignature,validatorAddress } = res //return by TransgateconsttaskCell=beginCell().storeBuffer(Buffer.from(taskId,'ascii')).storeBuffer(Buffer.from(schema,'ascii')).storeBuffer(Buffer.from(validatorAddress,'hex')).endCell();
Verify the allocator signature
//task pub key is fixedconstTonTaskPubKey="6ab539926d899a69385d8c5a35bd8c3e650dbd0a0c5e3e9a3cca15867e11d884"//The result of the signature verification needs to return as true. const taskVerify = signVerify(taskCell.hash(), Buffer.from(allocatorSignature, 'hex'), Buffer.from(TonTaskPubKey, 'hex'));
Verify Validator Signature
Generate the validator message
import { Address as TonAddress, beginCell } from'@ton/ton';import { signVerify } from'@ton/crypto';const { taskId, uHash, validatorAddress, schema, validatorSignature, recipient, publicFieldsHash } = res //return by Transgate
constattestationCell=beginCell().storeRef(beginCell().storeBuffer(Buffer.from(taskId,'ascii')).storeBuffer(Buffer.from(schema,'ascii')).storeBuffer(Buffer.from(uHash.slice(2),'hex')).endCell(), ).storeAddress(TonAddress.parse(recipient)).storeRef(beginCell().storeBuffer(Buffer.from(publicFieldsHash.slice(2),'hex')).endCell()).endCell();
Verify the validator address
//The result of the signature verification needs to return as true.constattestationVerify=signVerify(attestationCell.hash(),Buffer.from(validatorSignature.slice(2),'hex'),Buffer.from(validatorAddress,'hex'), );
Here, we've only given the reference code for js verification. However, the result can also be verified on Ton.