# Ton

### How to generate the proof with Ton?

```typescript
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)
    }
  }
```

{% hint style="info" %}
The result includes two signatures: the allocator signature and the validator signature. Developers should verify both signatures based on the other returned fields.&#x20;
{% endhint %}

### Verify Allocator Signature

#### Encode the allocator message struct

```typescript
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

```typescript
 //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

```javascript
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

```typescript
//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'),
    );
```

{% hint style="info" %}
Here, we've only given the reference code for js verification. However, the result can also be verified on Ton.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zkpass.org/developer-guides/js-sdk/generate-proof-and-verify-the-result/ton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
