bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 14쪽 중 7쪽
ation on behalf of an attester. The attester must approve (sign) the attestation that is being created to prevent fraudulent attestations. In other words, you would not want someone making attestations using your wallet address without you approving the attestation content first - unapproved attestations could pose a major security threat. After attaining a signature from the user/attester, the attestation and signature can be sent to the backend we wrote above. Your frontend code should include the following:
```typescript
import {
EvmChains,
delegateSignAttestation
} from "@ethsign/sp-sdk";
const schemaId = "0x...";
const attestationData = {
...
};
const indexingValue = "0x...";
const res = await delegateSignAttestation(
{
schemaId: schemaId,
data: attestationData,
indexingValue: indexingValue
},
{ chain: EvmChains.sepolia }
);
const attResponse = await fetch(`${YOUR_BACKEND_URL}/delegate`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ attestation: res.attestation, delegationSignature: res.delegationSignature })
});
...
// You can now use `attResponse` for anything you need in your frontend code
```
## Recap
The general flow to create a delegated attestation using a backend is the following:
1. Generate the attestation content. This can be done on the frontend (as shown above) or on a dedicated backend (and then sent to the frontend for step 2).
2. Request a delegation signature from the user in a browser.
3. Forward the attestation and delegation signature to your dedicated backend.
4. Create the attestation, providing the attestation and delegation signature.
# Solidity
There are many reasons you may want to generate an attestation on behalf of a wallet interacting with your smart contract. However, this cannot be done without the wallet approving (signing) the attestation your smart contract is creating on their behalf. Signatures must be initiated from the frontend and forwarded to your smart contract to create the delegate attestation. Depending on your use case, it may make sense to generate the attestation object on the frontend, or you may need to generate it from the smart contract through a getter. For this tutorial, we will assume that the attestation is generated on the frontend, but we have examples [here](https://github.com/EthSign/sign-protocol-examples) to show how to create an attestation object in Solidity.
We will start with an empty solidity contract. We will need to import `ISP` and `Attestation` from `@ethsign/sign-protocol-evm`.
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ISP } from "@ethsign/sign-protocol-evm/src/interfaces/ISP.sol";
import { Attestation } from "@ethsign/sign-protocol-evm/src/models/Attestation.sol";
contract DelegateAttest is Ownable {
constructor() Ownable(_msgSender()) { }
}
```
We will keep track of the Sign Protocol contract address. Create state variables and helper functions to set these values. This variable will need to be set based on the network you deploy your contract on, which can be found [here](/for-builders/address-book). Your contract should now look something like the following:
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ISP } from "@ethsign/sign-protocol-evm/src/interfaces/ISP.sol";
import { Attestation } from "@ethsign/sign-protocol-evm/src/models/Attestation.sol";
contract DelegateAttest is Ownable {
ISP public spInstance;
constructor() Ownable(_msgSender()) { }
function setSPInstance(address instance) external onlyOwner {
spInstance = ISP(instance);
}
}
```
Create a function to handle delegate attestation creation. We will pass in the attestation object, indexing value, delegation signature, and extra data to mimic the Sign Protocol `attest` function, however, you can modify these parameters if you wish to hardcode the indexing value or extra data. The attestation object and delegation signature are required to create an attestation using delegation methods.
<pre class="language-solidity"><code class="lang-solidity">...
function createAttestation(Attestation calldata att, string calldata indexingKey, bytes calldata delegationSignature, bytes calldata extraData) external returns (uint64) {
<strong> uint64 attestationId = spInstance.attest(att, indexingKey, delegationSignature, extraData);
</strong> return attestationId;
}
...
</code></pre>
## (Frontend) Generating a Delegation Signature
This section must be implemented on your frontend. Delegation signatures are a mechanism to allow a third party to upload an attestation on behalf of an attester. The attester must approve (sign) the attestation that is being created to prevent fraudulent attestations. In other words, you would not want someone making attestations using your wallet address without you approving the attestation content first - unapproved attestations could pose a major security threat. After attaining a signature from the user/attester, the attestation and signature can be sent to the backend we wrote above. Your frontend code should include the following:
```typescript
import {
EvmChains,
delegateSignAttestation
} from "@ethsign/sp-sdk";
const schemaId = "0x...";
const attestationData = {
...
};
const indexingValue = "0x...";
const extraData = "0x...";
const res = await delegateSignAttestation(
{
schemaId: schemaId,
data: attestationData,
indexingValue: indexingValue
},
{ chain: EvmChains.sepolia }
);
const response = await yourSmartContract.createAttestation(res.attestation, indexingValue, res.delegationSignature, extraData);
...
// You can now use `response` for anything you need in your frontend code
```
## Recap
The general flow to create a delegated attestation using a backend is the following:
1. Generate the attestation content. This can be done on the frontend (as shown above) or from your smart contract (and requested by the frontend for step 2).
2. Request a delegation signature from the user in a browser.
3. Pass in the attestation and delegation signature to your smart contract.
4. Create the attestation in your smart contract, providing the attestation and delegation signature.
# Examples
# Attestation Discord Bot
### Overview
<figure><img src="https://3152654701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw182g9YzR34mTxEBTKXX%2Fuploads%2Fgit-blob-3988e072bd913069e89c7114fc53ba1d84e36a1c%2Fdiscord_00.png?alt=media" alt=""><figcaption><p>AttestationBot in action</p></figcaption></figure>
EthSign's AttestationBot is a gatekeeping bot centered around attestations. Users can attest anything; by simply choosing an attestation's schema ID, Discord server administrators can use attestations from a specific schema to verify users within their Discord community. For a user's Discord account to be verified, the user must create an attestation with the chosen schema ID and sign a message with their wallet address to link their Discord account. Discord administrators can also require that a specific `Result` field be set to `true` on the attestations to add another layer of verification. Once these checks pass verification, users will be granted a role in Discord, granting them desired access as defined by the verification role in the server.
### Discord Admin Command Reference
<figure><img src="https://3152654701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw182g9YzR34mTxEBTKXX%2Fuploads%2Fgit-blob-781bad075d8d27b73feae9118dbd27cf4040047d%2Fdiscord_01.png?alt=media" alt="" width="400"><figcaption><p>Configuring AttestationBot</p></figcaption></figure>
#### /register \<testnet> \<mode> \<schemaId> \<verifyAttestation> \[attester]
Register attestation data for the server's verification. Requires testnet (true/false), mode (on-chain/off-chain), the schema ID for verification, and whether or not to check the `Result` field (true/false). Optionally, Discord Server admins can supply an attester address for querying attestations created by a single address (a trusted delegate address).
#### /generate\_role \[name]
Generates a pre-defined Discord Role in the server with default permissions. If the name is left blank, the role's name will default to "Verified".
#### /set\_role \<role>
Sets the verification role to whichever role the user passes in as an argument.
#### /display\_count
If set to on, displays the number of verified users in the server.
### User Command Reference
#### /verify
DMs user a link for verification. Upon success, a role will be given to the user. Upon failure, tells the user why it failed (no role setup in server, no attestation linked to server, user already verified, etc).
## ID Format (Schema + Attestation)
IDs are generated in the following format: `{mode}_{chainType}_{chainId}_{id}`
Example schema ID: `onchain_evm_80001_0x3`
Example attestation ID: `onchain_evm_80001_0x11`
## Bot Initialization
#### 1. /register \<testnet> \<mode> \<schemaId> \<verifyAttestation> \[attester]
Register the Attestation-specific data for a server.
#### 2. /generate\_role or /set\_role
Set the verified role for a server.
#### 3. /display\_count (optional)
Show the number of verified users in a server.
#### 4. /verify
Users can now verify their Discord accounts to be granted special permissions as defined by the verified role.
## End User Verification Flow
1. Run /verify and click the link provided by direct message.
2. Connect MetaMask to the website.
3. Click the “Verify” button and sign the relevant message in MetaMask.
4. Return to Discord.
NOTE: If for any reason the role is removed from a verified Discord account in a Discord server, the user can simply re-run /verify and be granted the role without additional verification.
## Backend Endpoint Reference
#### /verify/:id
Validates request body message and signature for the given ID. If successful, the user is granted a role in the relevant Discord server, and the attestation ID is returned for display purposes. Failure will result in an error message.
#### /lookup/:id
Determines if the provided interaction ID exists in our backend. If successful, it will return data about the relevant Discord user for displaying on our frontend. Failure will result in an error message.
#### /interactions
Discord-specific endpoint used for all Discord bot commands generated through a Discord server.
#### /status
Used for pinging uptime of the server.
## Relevant Sign Protocol Code Examples
Querying for attestations and parsing the response:
```typescript
const endpoint = `${ATTESTATION_ENDPOINT}/index/attestations`;
// Use fetch() or axios to call the Sign Protocol indexing service:
const res = await AttestationRequest(
endpoint,
{
method: "GET",
// If we have an attester provided in the Discord Server's registration config,
// we need to use it as the attester when querying. Otherwise, the recipient
// (the address belonging to the user trying to verify themselves in Discord)
// will be our attester. Use the recipient as the indexingValue (provided when
// making an attestation) to query for the recipient when an attester is provided.
params: attester
? {
mode, // onchain/offchain
schemaId, // {mode}_{chainType}_{chainId}_{id}
attester: attester, // an address
indexingValue: recipient.toLowerCase() // an address
}
: {
mode, // onchain/offchain
schemaId, // {mode}_{chainType}_{chainId}_{id}
attester: recipient // an address
}
}
);
// Begin parsing the response from the indexing server.
if (!response.success) {
return { success: false, message: response?.message ?? "Attestation query failed." };
}
// Check if there is no data matching our query.
if (response.data?.total === 0) {
return { success: false, message: "No attestation for this address found." };
}
// Do something with the attestations found. We will "return" them in this example.
return {
success: true,
attestations: response.data.rows
};
```
Parsing the attestation data into a JSON Object:
```typescript
import { decodeAbiParameters } from "viem";
// List of attestations returned from indexing service.
const attestations = [...];
let dataObjects: any = [];
for (const att of attestations) {
// No data to parse.
if(!att.data) continue;
// Use viem's decodeAbiParameters() to parse the data.
// Note that this step may require slight modifications depending on the schema's
// data type, such as nested tuples or parsing pure strings.
const data = decodeAbiParameters(
att.dataLocation === "onchain" ? att.schema.data : [{ type: "string" }],
att.data
);
// Create a data object from the schema.
const obj: any = {};
data.forEach((item: any, i: number) => {
obj[att.schema.data[i].name] = item;
});
// Add the obj to dataObjects.
dataObjects.push(obj);
}
// Do something with the data objects we have recovered and populated in dataObjects.
// We can use the attestation data to determine if a user should be allowed into a
// Discord server based on some verification criteria, such as requiring an
// attestation's data to contain a field named "Result" with a value of "true".
```
# KYC-Gated Smart Contract Access Control
ZetaChain Airdrops 17.4M ZETA to Contributors Using TokenTable by EthSign
## Challenge <a href="#id-4476" id="id-4476"></a>
Under the ethos of progressive decentralization, L1 blockchains conduct airdrops to distribute ownership of the network to their community. Ideally, community members who participate in the network — by deploying smart contracts, testing applications, helping with ecosystem growth, etc.— are rewarded proportionately to the value they create.
A well-executed airdrop is essential in bootstrapping decentralization and real usage of a blockchain protocol and is also a huge marketing opportunity. ZetaChain allocated a total of 31.5M ZETA (1.5% of 2.1B ZETA total supply) to this [genesis mainnet airdrop](https://www.zetachain.com/blog/the-zetalabs-airdrop-pre-claim), with rewards allocated to over 800,000 contributors to ZetaLabs’ testnet. ([See full token distribution here](https://www.zetachain.com/docs/about/token-utility/distribution/)).
To ensure regulatory compliance, ZetaChain required KYC and AML checks on contributors receiving an airdrop greater than 200 ZETA; additionally, they prevented airdrop claiming from OFAC sanctioned geographies.
## Enter TokenTable <a href="#b726" id="b726"></a>
ZetaChain used EthSign’s [TokenTable ](https://www.tokentable.xyz/)to conduct their KYC-gated airdrop on January 31st, 2024. The engagement entailed the development of a custom version of TokenTable that facilitated a compliant, streamlined airdrop for both ZETA recipients and the ZetaChain team.
The following TokenTable modules were used to facilitate the ZetaChain airdrop:
* **KYC-Gated Smart Contract Access:** Integration of the reputable KYC/AML provider [SumSub](https://sumsub.com/) to verify the government identification and liveness of \~15,000 airdrop recipients. For these recipients, passing the KYC check is a smart-contract-enforced requirement to claim the airdrop.
* **Custom Claiming Interface:** Development of a co-branded TokenTable interface that recipients are routed to from ZetaHub to claim their airdrop. Users connecting to this custom interface from OFAC-sanctioned geographies will be blocked.
* **Pre-paid Gas Fees:** Before the airdrop, ZetaChain contributors could not obtain mainnet ZETA, so the [TokenTable Unlocker](broken://spaces/JP1jAQLitA1tqbIHqb4o/pages/evdFwVNh1DhoZAueoO8L) smart contract was outfitted with pre-pay gas fee functionality for claimers.
## Smart Contract Access Control via Sign Protocol <a href="#id-3ff7" id="id-3ff7"></a>
<figure><img src="https://3152654701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw182g9YzR34mTxEBTKXX%2Fuploads%2Fgit-blob-09d735de241b2c0a0442a3b4c8ef15e3d0bc18f7%2Fkyc_00.png?alt=media" alt=""><figcaption><p>A KYCHook that gates TokenTable claiming</p></figcaption></figure>
In order to restrict non-KYC’ed addresses from claiming ZETA via TokenTable, the off-chain KYC verification status of recipient addresses must be communicated to [TokenTable’s Unlocker](broken://spaces/JP1jAQLitA1tqbIHqb4o/pages/evdFwVNh1DhoZAueoO8L) smart contract.
[SIGN Attestation Protocol](https://medium.com/ethsign/attestations-sign-everything-onchain-01db9ebf39e7) was implemented in parallel with SumSub to a) bind the airdrop recipient's wallet address to an their KYC verification status, and b) to port recipient addresses’ KYC verification status on-chain so that TokenTable’s Unlocker smart contract can validate it.
The airdrop claiming flow is as follows:
1. Whitelisted wallets from non-sanctioned geographies are able to connect to [claims.zetachain.com](https://claims.zetachain.com/).
2. Claimers can view how much ZETA they have available to claim, and any lockup terms.
3. Conduct KYC verification via Sumsub by submitting their government ID.
4. To bind their address and KYC verification, claimers must use SIGN Protocol to sign an attestation message that is a hash of their address and KYC status.
5. The TokenTable Unlocker smart contract must validate the KYC attestation before enabling the associated wallet to claim its ZETA airdrop.
{% embed url="<https://youtu.be/BTm0Bp-dzQ0>" %}
You can check out the SIGN Protocol attestation smart contract that is [deployed on ZetaChain mainnet here](https://zetachain.blockscout.com/address/0x1BC26dd23b773806f080Acf65Cfb744166be9463)!
# Supported Networks
Sign Protocol's maintained smart contract deployments are listed below.
Maintained EVM deployments are upgraded to version `1.1.4` and are owned by `0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2`. Crossed-out networks are legacy deployments that are no longer maintained.
## Mainnet
| Network | Chain ID | Proxy | Version | Owner | GraphQL Subgraph |
| :----------: | -------: | :----------------------------------------: | ------- | :----------------------------------------: | ------------------------------------------------------------------------------------------------------------ |
| Ethereum | 1 | 0x3D8E699Db14d7781557fE94ad99d93Be180A6594 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-ethereum/v1.1.0/gn> |
| Optimism | 10 | 0x945C44803E92a3495C32be951052a62E45A5D964 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-op/v1.1.0/gn> |
| BNB | 56 | 0xe2C15B97F628B7Ad279D6b002cEDd414390b6D63 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-bnb/v1.1.2/gn> |
| Gnosis | 100 | 0x4e4af2a21ebf62850fD99Eb6253E1eFBb56098cD | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-gnosis/v1.1.0/gn> |
| Polygon | 137 | 0xe2C15B97F628B7Ad279D6b002cEDd414390b6D63 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-matic/v1.1.0/gn> |
| opBNB | 204 | 0x03688D459F172B058d39241456Ae213FC4E26941 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-opbnb/v1.1.0/gn> |
| Base | 8453 | 0x2b3224D080452276a76690341e5Cfa81A945a985 | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0isrycgi01wfgmhv3hrf/subgraphs/sp-base/v1.1.0/gn> |
| Arbitrum One | 42161 | 0x4e4af2a21ebf62850fD99Eb6253E1eFBb56098cD | 1.1.4 | 0xAE45849165E17Dc555B8264dD4Ae01a3F42344e2 | <https://api.goldsky.com/api/public/project\\_cls8h0i프로젝트로 돌아가기