Ton

Only supports SDK version 0.3.0 and above.

How to generate the proof with Ton?

import { useTonWallet } from "@tonconnect/ui-react"

const wallet = useTonWallet()

const generate = async (schemaId: string, appid: string) => {
    try {
      //check if you connect the Ton wallet
      if (!wallet) {
        return alert("Please connect the wallet")
      }
      
      // TON address for the Wallet
      const address = wallet.account.address

      //The appid of the project created in dev center     
      const appid = "39a00e9e-7e6d-461e-9b9d-d520b355d1c0"
      //The schemaId of the project
      const schemaId = "c7eab8b7d7e44b05b41b613fe548edf5"
            
      const connector = new TransgateConnect(appid)
      
      const isAvailable = await connector.isTransgateAvailable()
      if (!isAvailable) {
        return alert("Please install zkPass TransGate")
      }
      
      const res = (await connector.launchWithTon(schemaId, address)) as Result

    } 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 Transgate

 const taskCell = 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 fixed
 const TonTaskPubKey = "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

const attestationCell = 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.
    const attestationVerify = 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.

Last updated

Feel free to contact us if you have any ideas