bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 6쪽
vely and privately validate their data.
* Verifiability through 3P-TLS: the SDK helps developers seamlessly implement this 3P-TLS for secure data verification.
* Compatibility with HTTPS Websites: the SDK is designed to be compatible with any HTTPS website, making integration straightforward for developers and no additional APIs or licenses are required, simplifying the adoption process.
* Anti-Cheating Mechanisms: the SDK assists in implementing these anti-cheating mechanisms, ensuring the authenticity, integrity, and validity of the data.
* Memory-Efficient Zero-Knowledge Proofs: the SDK leverages VOLE-based IZK to achieve millisecond-level ZKP generation locally in the browser environment that contributes to the memory efficiency of the verification process.
* Versatile Application Scenarios: the SDK can be applied in various scenarios, including decentralized identity passes, DeFi lending protocols, healthcare data marketplaces, and other use cases where trust and privacy are crucial.
## Core Concepts
#### Schema
A Schema is a JSON-formatted file that defines the mapping of specific HTTP responses for the zkPass verification system. Additional details can be found in the [schema section](/developer-guides/js-sdk/schema).
#### TransGate
TransGate, consisting of a Chrome extension, Android app/Instant app, and iOS app/Clip, enables the secure and seamless transfer of private data between web2 and web3 environments. It operates on the client side, using the zkPass protocol to ensure a smooth and secure user experience when transferring data to various destinations.
#### Allocator Node
The allocator node generates verification task metadata, randomly selecting a validator for subsequent verification with the user. Once the task is generated, it uses its private key to sign the metadata and returns the metadata along with the signature.
#### Validator Node
The validator node plays a crucial role in the verification process. It participates in 3P-TLS and receives the zk-proof generated by the TransGate, verifies its authenticity, and then returns the final verification result along with its signature. Essentially, the validator node acts as an independent authority, ensuring the integrity and validity of the verification process before providing the outcome to the DApp.
## Role of JS-SDK
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2FU01Xl19I4ntEE4bxDCxk%2Fimage.png?alt=media&token=da776617-75ab-47f9-bddd-46c9897e0109" alt="" width="375"><figcaption></figcaption></figure>
The SDK serves as a bridge connecting the DApp and TransGate. It dispatches events to the event listener of TransGate, which then processes the event in its handler and returns the result to the SDK. Once the DApp receives the verification result from the SDK, it has the option to transform the result into an on-chain Identity, such as zkSBT, or store it off-chain for future use.
# How It Works
The Extension JS-SDK serves as a bridge connecting your DApp to the TransGate extension, enabling seamless zk verification capabilities for DApp. The diagram below illustrates the workflow of the verification process and the role/function of the JS-SDK in the entire process.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2FHthOhDPqyPmIENItJFAM%2FUntitled-2023-12-10-2202.png?alt=media&token=1addcfc3-eb06-42bf-a387-b85a83f1337b" alt=""><figcaption></figcaption></figure>
1. **User Prepares Verification:**
* The user begins by visiting the DApp and prepares the required verification based on a specified schema.
2. **DApp Initiates SDK:**
* The DApp activates the SDK, initiating the verification process using the provided schema data.
3. **SDK Connects to Allocator Node:**
* The SDK connects to the allocator node using the appid and schemaId to retrieve task information. The allocator node validates the parameters and returns the relevant task details.
4. **SDK Communicates with TransGate Extension:**
* The SDK transfers the task information to the zkPass TransGate extension. After confirming the parameters, the extension opens the designated data source website mentioned in the schema.
5. **User Login to Data Source:**
* The user logs in to the data source website using their username and password.
6. **Verification Process Initiates:**
* When the extension detects API requests as defined in the schema, the user starts the verification process.
7. **Establishment of 3P-TLS:**
* The extension, validator node, and data source server establish a secure 3P-TLS connection.
8. **Generation of zk-Proof:**
* After receiving the response from the data source, the extension generates a zk-proof and sends it to the validator node.
9. **Validator Node Verification:**
* The validator node verifies the zk-proof and returns the final verification result.
10. **Result Sent to Extension:**
* The extension receives the result and sends it back to the DApp through the SDK.
11. **DApp Validation:**
* Finally, the DApp validates the result and proceeds with the next steps based on its specific requirements.
# Quick Start
You can read [A Comprehensive Guide to Verifying Private Data with zkPass](https://medium.com/@jovells.appiah/a-comprehensive-guide-to-verifying-private-data-with-zkpass-0be35afec44a) before start to integrate zkPass TransGate-JS-SDK.
### Register and Config the Project in zkPass DevHub
***
Login [**zkPass DevHub**](http://dev.zkpass.org), connect the wallet.
<div data-full-width="false"><figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2FoBejX2XIXhX3O9gKooA2%2Fpika-1745831294401-1x.png?alt=media&token=ffd24dce-a09a-440d-95f1-7df4bb92954f" alt=""><figcaption></figcaption></figure></div>
Create a new project, enter project information.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2F7dLQvTMCj5PzybFmkJLF%2Fpika-1745831391653-1x.png?alt=media&token=eda72c69-297b-41f8-a165-4b0b69c9cf8e" alt=""><figcaption></figcaption></figure>
After "Create", a project is created with an appID.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2Fsc4TO5OqLmiv1t5DFao6%2Fpika-1745831945577-1x.png?alt=media&token=c634db10-bb69-4a8c-bcfd-8f3da5d10c17" alt=""><figcaption></figcaption></figure>
Click on 'Add Schema' and choose the schema category.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2Fgr4dFChCB66Vw4PyM9z1%2Fpika-1745831483489-1x.png?alt=media&token=26136926-b4c4-4539-afc3-470ae4d5ed19" alt=""><figcaption></figcaption></figure>
Choose a base schema (the base schema is a default template of schema without assertions).
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2FaVx5a3yDGao7ufbepOmR%2Fpika-1745831491354-1x.png?alt=media&token=26171ba3-fee8-4b47-842f-23c8382d2093" alt=""><figcaption></figcaption></figure>
Config the assertions based on the requirements.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2F0UQLtVLVCbj0XgWdlf1o%2Fpika-1745831787779-1x.png?alt=media&token=f19efa93-83e3-42e7-95b1-647a688b4952" alt=""><figcaption></figcaption></figure>
After 'Submit', a schema is created automatically with an unique schemaId for the project.
<figure><img src="https://2216484837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC2Jh1oquOpJPfwzD3x9L%2Fuploads%2FvJgbcX8BMSqixaHvryqW%2Fpika-1745831499376-1x.png?alt=media&token=a9aaf928-1af7-4872-9dd7-d70a92f55135" alt=""><figcaption></figcaption></figure>
Developers can add multiple schemas for the project.
::: info Once the schema is successfully created, it cannot be modified but can be deleted. Please carefully review before submitting. :::
### Integrate TransGate JS-SDK
***
Developers can install the package using either [NPM](https://www.npmjs.com/package/@zkpass/transgate-js-sdk) or [Yarn](https://yarnpkg.com/package?name=@zkpass/transgate-js-sdk)
**Using NPM**
```
npm install @zkpass/transgate-js-sdk
```
**Using Yarn**
```
yarn add @zkpass/transgate-js-sdk
```
Integrate the TransGate JS-SDK with your project
```javascript
const verify = async () => {
try {
// The appid of the project created in dev center
const appid = "8fb9d43c-2f24-424e-a98d-7ba34a5532f5"
// Create the connector instance
const connector = new TransgateConnect(appid)
// The schema id of the project
const schemaId = "516a720e-29a4-4307-ae7b-5aec286e446e"
// Launch the process of verification
// When running the TransGate SDK on a PC, if the user has not installed TransGate,
// a QR code will pop up. The user can scan it using the TransGate App on their
// phone to complete verification (iOS users can directly use the system scanner)
// or install TransGate from the Google Play Store. On mobile DApps,
// TransGate will automatically invoke the TransGate App.
// If it is not installed, the user will be prompted to install it.
const res = await connector.launch(schemaId)
//If you want to bind the user's address with the proof, the `launch` function
//also accepts a second parameter, which is the user's wallet address.
const address = "0xD038048D1AE4c04dF2759F33BFda969999999641"
const responseWithAddress = await connector.launch(schemaId, address)
// verifiy the res onchain/offchain based on the requirement
} catch (error) {
console.log('transgate error', error)
}
}
```
::: info TransGate download link is <https://chromewebstore.google.com/detail/zkpass-transgate/afkoofjocpbclhnldmmaphappihehpma> :::
::: info Please make sure the domain of DApp matches the configuration of the project in dev center. :::
### Validate the result
***
After receiving the verification result(`res`in code block), developers should validate it.
You can refer to [API References](/developer-guides/js-sdk/api-references#instance-methods) and [Generate proof and verify the result](/developer-guides/js-sdk/generate-proof-and-verify-the-result) for more information.
# Generate proof and verify the result
After running Transgate through the SDK, a proof will be returned. You can verify it locally or on-chain. We currently support the EVM ecosystem and the Solana ecosystem.
# EVM
### How to generate the proof with EVM?
```javascript
const generate = async (schemaId: string, appid: string) => {
try {
// The appid of the project created in dev center
const appid = "8fb9d43c-2f24-424e-a98d-7ba34a5532f5"
// Create the connector instance
const connector = new TransgateConnect(appid)
// Check if the TransGate extension is installed
// If it returns false, please prompt to install it from chrome web store
const isAvailable = await connector.isTransgateAvailable()
if (isAvailable) {
// The schema id of the project
const schemaId = "516a720e-29a4-4307-ae7b-5aec286e446e"
// Launch the process of verification
// This method can be invoked in a loop when dealing with multiple schemas
const res = await connector.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)
}
}
```
::: info 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
```javascript
import Web3 from "web3"
const web3 = new Web3()
const { taskId } = res //return by Transgate
const taskIdHex = Web3.utils.stringToHex(taskId)
const schemaIdHex = Web3.utils.stringToHex(schemaId)
const encodeParams = web3.eth.abi.encodeParameters(
["bytes32", "bytes32", "address"],
[taskIdHex, schemaIdHex, validatorAddress]
)
const paramsHash = Web3.utils.soliditySha3(encodeParams)
```
#### Recover the allocator address
```javascript
const signedAllocatorAddress = web3.eth.accounts.recover(paramsHash, allocatorSignature)
```
#### Check if the signed allocator address is registered. The current allocator address is fixed.
```javascript
return signedAllocatorAddress === "0x19a567b3b212a5b35bA0E3B600FbEd5c2eE9083d"
```
### Verify Validator Signature
#### Encode the validator message
```javascript
import Web3 from "web3"
const web3 = new Web3()
const { taskId, uHash, publicFieldsHash, recipient } = res //return by Transgate
const taskIdHex = Web3.utils.stringToHex(taskId)
const schemaIdHex = Web3.utils.stringToHex(schemaId)
const types = ["bytes32", "bytes32", "bytes32", "bytes32"]
const values = [taskIdHex, schemaIdHex, uHash, publicFieldsHash]
//If you add the wallet address as the second parameter when launch the Transgate
if (recipient) {
types.push("address")
values.push(recipient)
}
const encodeParams = web3.eth.abi.encodeParameters(types, values)
const paramsHash = Web3.utils.soliditySha3(encodeParams)
```
#### Recover the validator address
<pre class="language-javascript"><code class="lang-javascript"><strong>const signedValidatorAddress = web3.eth.accounts.recover(paramsHash, validatorSignature)
</strong></code></pre>
#### Verify if the signed validator address matches the address assigned by the allocator
```javascript
return signedValidatorAddress === validatorAddress
```
::: info Here, we've only given the reference code for off-chain verification. However, the result can also be verified on-chain. :::
# Solana
Only supports SDK version 0.2.0 and above.
### How to generate the proof with Solana?
```javascript
const generate = async (schemaId: string, appid: string) => {
try {
//check if you install the Phatom wallet
if (!("phantom" in window)) {
return alert("Please install Phantom wallet")
}
const provider = window.phantom?.solana
const resp = await provider?.connect() //connect wallet
const account = resp.publicKey.toString()
//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.launchWithSolana(schemaId, account)) as Result
} catch (err) {
alert(JSON.stringify(err))
console.log("error", err)
}
}
```
::: info 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
```javascript
import { Buffer } from "buffer"
import secp256k1 from "secp256k1"
import * as borsh from "borsh"
import sha3 from 'js-sha3'
//Attest struct for Solana
const SolanaTask = {
struct: {
task: 'string',
schema: 'string',
notary: 'string',
},
}
const { taskId, allocatorSignature, validatorAddress } = res //return by Transgate
const sig_bytes = hexToBytes(allocatorSignature.slice(2));
const signatureBytes = sig_bytes.slice(0, 64);
const recoverId = Array.from(sig_bytes.slice(64))[0];
const plaintext = borsh.serialize(SolanaTask, {
task: taskId,
schema: schema,
notary: validatorAddress,
});
const plaintextHash = Buffer.from(sha3.keccak_256.digest(Buffer.from(plaintext)));
```
#### Recover the allocator address
```javascript
const signedAllocatorAddress = secp256k1.ecdsaRecover(signatureBytes, recoverId, plaintextHash, false);
```
#### Check if the signed allocator address is registered. The current allocator address is fixed.
```javascript
return signedAllocatorAddress === "69e7d686e612ab57e3619f4a19a567b3b212a5b35ba0e3b600fbed5c2ee9083d"
```
### Verify Validator Signature
#### Generate the validator message
```javascript
import { Buffer } from "buffer"
import secp256k1 from "secp256k1"
import * as borsh from "borsh"
import sha3 from "js-sha3"
//Attest struct for Solana
const Attest = {
struct: {
task: "string",
schema: "string",
nullifier: "string",
recipient: "string",
publicFieldsHash: "string",
},
}
const { taskId, uHash, validatorAddress, schema, validatorSignature, recipient, publicFieldsHash } = res //return by Transgate
const sig_bytes = hexToBytes(validatorSignature.slice(2)) //skip the 0x
const signatureBytes = sig_bytes.slice(0, 64)
const recoverId = Array.from(sig_bytes.slice(64))[0]
const plaintext = borsh.serialize(Attest, {
task: taskId,
nullifier: uHash,
schema,
recipient,
publicFieldsHash,
})
const plaintextHash = Buffer.from(sha3.keccak_256.digest(Buffer.from(plaintext)))
```
#### Recover the validator address
```javascript
const signedValidatorAddress = secp256k1.ecdsaRecover(signatureBytes, recoverId, plaintextHash, false);
```
#### Verify if the signed validator address matches the address assigned by the allocator
```javascript
return signedValidatorAddress === validatorAddress
```
::: info Here, we've only given the reference code for js verification. However, the result can also be verified on Solana. :::
# Ton
Only supports SDK version 0.3.0 and above.
### 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)
}
}
```
::: info 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
```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,프로젝트로 돌아가기