Sign 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 14쪽 중 11쪽

ttestation by querying with an attestation ID. Body Parameters: ```graphql query getAttestation { attestation(id: "onchain_evm_80001_0x1") { # Write your query or mutation here attestationId attester attestTimestamp linkedAttestation chainId chainType data dataLocation transactionHash revokeTransactionHash id indexingValue mode recipients revoked revokeReason revokeTimestamp schema { id name registrant } validUntil } } ``` Response: ```json { "data": { "attestation": { "attestationId": "0x1", "attester": "0x9854E76134e6D729A633CED51042fF653f04f4C5", "attestTimestamp": 1705455448, "linkedAttestation": "", "chainId": "80001", "chainType": "evm", "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000033232320000000000000000000000000000000000000000000000000000000000", "dataLocation": "ONCHAIN", "transactionHash": "0x00ecb7e8c6d3ae6d0fab2432c1e7ccc3f1128716839c04b5b4a51457e9ce6eff", "revokeTransactionHash": "", "id": "onchain_evm_80001_0x1", "indexingValue": "", "mode": "onchain", "recipients": [], "revoked": false, "revokeReason": null, "revokeTimestamp": null, "schema": { "id": "onchain_evm_80001_0x1", "name": "xxx", "registrant": "0x9854E76134e6D729A633CED51042fF653f04f4C5" }, "validUntil": 0 } } } ``` ### Filtered Attestations ```typescript POST / graphql; ``` Query for a list of attestations. Results can be filtered, paginated, ordered, etc. according to GraphQL standards. Body Parameters: ```graphql query queryAttestations { pagedAttestations(page: 1) { total attestations { attestationId attester attestTimestamp linkedAttestation chainId chainType data dataLocation transactionHash revokeTransactionHash id indexingValue mode recipients revoked revokeReason revokeTimestamp schema { id schemaId name registrant data } validUntil } } } ``` Response: ```graphql { "data": { "pagedAttestations": { "total": 52, "attestations": [ { "attestationId": "0x21", "attester": "0x9854E76134e6D729A633CED51042fF653f04f4C5", "attestTimestamp": 1706065910, "linkedAttestation": "", "chainId": "80001", "chainType": "evm", "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000033232320000000000000000000000000000000000000000000000000000000000", "dataLocation": "ONCHAIN", "transactionHash": "0x0f0fb01c520add97a74d6125729053559c7cffb96a5f5871118b766e9a3ddbb7", "revokeTransactionHash": "0x2e0cda7c6222190c5065df8c8164ee26aec6132c98320733b2775c923fcca634", "id": "onchain_evm_80001_0x21", "indexingValue": "0x059e6B8008d34aC26581fD3ED8378AA93c7941EE", "mode": "onchain", "recipients": [], "revoked": true, "revokeReason": "test revoke", "revokeTimestamp": 1706065942, "schema": { "id": "onchain_evm_80001_0x1", "schemaId": "0x1", "name": "xxx", "registrant": "0x9854E76134e6D729A633CED51042fF653f04f4C5", "data": "[{\"name\":\"name\",\"type\":\"string\"}]" }, "validUntil": 0 }, ... ] } } } ``` # Writing Data # NPM SDK # Installation ### Installation Install the [`@ethsign/sp-sdk`](https://www.npmjs.com/package/@ethsign/sp-sdk) package to use the Sign Protocol SDK in your frontend or Node backend projects. ### Creating a Client Instance ```ts new SignProtocolClient(spMode, options); ``` #### Parameters | Name | Type | Description | | ------- | ----------------------------------------------- | -------------------------------------------------------------------------- | | spMode | `SpMode` | Whether the client is initialized in on-chain or Arweave (off-chain) mode. | | options | `OnChainClientOptions`, `OffChainClientOptions` | Client options based on `spMode`. | {% hint style="warning" %} NOTE: The `account` variable in `options` is marked as optional. If it is not provided, the SDK will use the provider from `window.ethereum` by default to derive an account. If a provider from `window.ethereum` cannot be located AND an account is not provided, calls to the SDK will fail. {% endhint %} #### Example ```typescript const { privateKeyToAccount } = require("viem/accounts"); const client = new SignProtocolClient(SpMode.OnChain, { chain: EvmChains.baseSepolia, account: privateKeyToAccount(privateKey), apiKey: 'xxx', // Get a key from https://developer.sign.global/ }); ``` # Usage # Schemas ## Types ### Schema (Onchain) | Name | Type | Description | | ------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | name | `string` | Schema name. | | description? | `string` | Schema description. | | revocable? | `boolean` | Whether Attestations that adopt this Schema can be revoked. | | maxValidFor? | `number` | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. | | hook? | `address` | The contract address of the hook for this schema. | | registrant | `address` | The wallet address of the user that registered this schema. | | dataLocation? | `DataLocationOnChain` | Where `Schema.data` is stored. See `DataLocation.DataLocation`. | | data | `SchemaItem[]` or `string` | The data format defining this schema's data structure. When `dataLocation=ONCHAIN`, data is `SchemaItem[]`, when `dataLocation=ARWEAVE or IPFS`, data is id of the data. | ### Schema (Offchain) | Name | Type | Description | | ------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | `string` | Schema name. | | description? | `string` | Schema description. | | revocable? | `boolean` | Whether Attestations that adopt this Schema can be revoked. | | maxValidFor? | `number` | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. | | dataLocation? | `DataLocationOffChain` | Where `Schema.data` is stored. See `DataLocation.DataLocation`. | | data | `SchemaItem[]` | The data format defining this schema's data structure. | ## Usage ### Registering a Schema ```ts async function createSchema( schema: Schema, options?: { getTxHash?: (txHash: `0x${string}`) => void } ): Promise<SchemaResult>; ``` #### Parameters | Name | Type | Description | | -------- | --------------------- | ------------------------------ | | schema | `Schema` | The schema being registered. | | options? | `CreateSchemaOptions` | Options for creating a schema. | #### CreateSchemaOptions | Name | Type | Description | | -------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------- | | delegationSignature? | string | The user's delegate signature for creating a schema on their behalf. Call `delegateSignSchema` to get this signature. | | getTxHash? | ``(txHash: `0x${string}`) => void`` | An optional callback that immediately returns the transaction hash. | #### Example ```typescript const res = await client.createSchema({ name: "Example", data: [{ name: "name", type: "string" }], }); ``` ### Retrieving a Schema ```ts async function getSchema(schemaId: string): Promise<Schema>; ``` #### Parameters | Name | Type | Description | | -------- | -------- | ----------------------------------------------- | | schemaId | `string` | The ID of the schema we are trying to retrieve. | #### Example ```typescript const res = await client.getSchema("0x3e"); ``` ### Delegating On-chain Schema Registration via ECDSA ```ts async function delegateSignSchema( schema: OnChainSchema, options: DelegateSignSchemaOptions ): Promise<SchemaDelegationSignature>; ``` #### Parameters | Name | Type | Description | | ------- | --------------------------- | ---------------------------------------- | | schema | `OnChainSchema` | An on-chain schema. | | options | `DelegateSignSchemaOptions` | Options for delegate signing the schema. | #### DelegateSignSchemaOptions | Name | Type | | | ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | chain | `EvmChains` | The EVM chain you are targetting. | | delegationAccount? | `PrivateKeyAccount` | The signer account that signs the message. See `viem/accounts`. If this is null, a signer from `window.ethereum` will be used. | | rpcUrl? | `string` | Optional RPC URL. | | walletClient? | `WalletClient` | Optional `WalletClient` from viem to use for transactions. | # Attestations ## Types ### Attestation (Onchain) | Name | Type | Description | | -------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | schemaId | `string` | Schema ID for this attestation. | | linkedAttestationId? | `string`, `null` | The ID of the attestation that this attestation references. | | validUntil? | `number` | Timestamp that this attestation is valid until. | | revoked? | `boolean`, `null` | Whether or not this attestation is revoked. | | recipients? | `string[]` | List of recipient addresses. | | indexingValue | `string` | The indexing value of this attestation. Can be used for filtering while querying using the indexing service. | | attester? | `address` | The attester's address. | | attestTimestamp? | `number` | Timestamp that the attestation was created. | | revokeTimestamp? | `number` | Timestamp that the attestation was revoked. | | dataLocation? | `DataLocationOnchain` | Where `Attestation.data` is stored. See `DataLocation.DataLocation`. | | data | `{ [key: string]: any }`, `string` | If `dataLocation` is `ONCHAIN`, `data` is the data object. Otherwise, data is a `string` of the CID from the storage provider. | ### Attestation (Offchain) | Name | Type | Description | | -------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------ | | schemaId | `string` | Schema ID for this attestation. | | linkedAttestationId? | `string`, `null` | The ID of the attestation that this attestation references. | | validUntil? | `number` | Timestamp that this attestation is valid until. | | revoked? | `boolean`, `null` | Whether or not this attestation is revoked. | | recipients? | `string[]` | List of recipient addresses. | | indexingValue | `string` | The indexing value of this attestation. Can be used for filtering while querying using the indexing service. | | attester? | `address` | The attester's address. | | dataLocation? | `DataLocationOffchain` | Where `Attestation.data` is stored. See `DataLocation.DataLocation`. | | data | `{ [key: string]: any }` | The data object to be stored with this attestation. | ## Creating Attestations {% hint style="warning" %} NOTE: You must provide an API key when initializing your SignClient to create offchain attestations. You can generate a key [here](https://developer.sign.global/). For more information, see [Installation](/for-builders/index-1/npm-sdk/installation). {% endhint %} ### Creating an Attestation ```ts async function createAttestation( attestation: Attestation, options?: CreateAttestationOnChainOptions ): Promise<AttestationResult>; ``` #### Parameters | Name | Type | Description | | ----------- | --------------------------------- | ------------------------------------ | | attestation | `Attestation` | An attestation object. | | options? | `CreateAttestationOnChainOptions` | Options for creating an attestation. | #### CreateAttestationOnChainOptions | Name | Type | Description | | ---------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------- | | resolverFeesETH? | `BigInt` | ETH fees to be sent to the schema hook, in wei. | | delegationSignature? | `string` | The attester's delegate signature when creating an attestation on their behalf. | | getTxHash? | ``(txHash: `0x${string}`) => void`` | An optional callback that immediately returns the transaction hash. | | recipientEncodingType? | `RecipientEncodingType` | Defines the attestation's recipient encoding type as either an address or string. | | extraData? | `0x${string}` | Extra data that is passed to the schema hook. This data is not stored by the Sign Protocol contract. | #### Example ```typescript const res = await client.createAttestation({ schemaId: "0x3e", data: { name: "a" }, indexingValue: "xxx", }); ``` ### Delegating On-chain Attestation via ECDSA ```ts async function delegateSignAttestation( attestation: Attestation, options: DelegateSignAttestationOptions ): Promise<AttestationDelegationSignature>; ``` #### Parameters | Name | Type | Description | | ----------- | -------------------------------- | ------------------------------------------- | | attestation | `Attestation` | An attestation object. | | options | `DelegateSignAttestationOptions` | Options for delegate attestation signature. | #### DelegateSignAttestationOptions | Name | Type | Description | | ---------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | chain | `EvmChains` | The EVM chain we are targeting. | | delegationAccount? | `PrivateKeyAccount` | The signer account that signs the message. See `viem/accounts`. If this is null, a signer from `window.ethereum` will be used. | | recipientEncodingType? | `RecipientEncodingType` | Defines the attestation's recipient encoding type as either an address or string. | | rpcUrl? | `string` | Optional RPC URL. | | walletClient? | `WalletClient` | Optional `WalletClient` from viem to use for transactions. | #### Example ```typescript const { privateKeyToAccount } = require("viem/accounts"); const delegationPrivateKey = "0x..."; const delegationResult = await delegateSignAttestation( { schemaId: "0x3e", data: { name: "a" }, indexingValue: "xxx" }, { chain: EvmChains.baseSepolia, delegationAccount: privateKeyToAccount(delegationPrivateKey), } ); const res = await client.createAttestation(delegationResult.attestation, { delegationSignature: delegationResult.delegationSignature, }); ``` ### Retrieving an Attestation ```ts async function getAttestation(attestationId: string): Promise<Attestation>; ``` #### Parameters | Name | Type | Description | | ------------- | -------- | ---------------------------------------------------- | | attestationId | `string` | The ID of the attestation we are trying to retrieve. | #### Example ```typescript const res = await client.getAttestation("0x44"); ``` ## Revoking Attestations ### Revoke an Attestation ```ts async function revokeAttestation( attestationId: string, options?: RevokeAttestationOptions ): Promise<RevokeAttestationResult>; ``` #### Parameters <table><thead><tr><th width="219">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>attestationId</td><td><code>string</code></td><td>The ID of the attestation we are revoking.</td></tr><tr><td>options?</td><td><code>RevokeAttestationOptions</code></td><td>Options for revoking an attestation.</td></tr></tbody></table> #### RevokeAttestationOptions <table><thead><tr><th width="219">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>reason?</td><td><code>string</code></td><td>Reason for the revocation.</td></tr><tr><td>delegateSignature?</td><td><code>string</code></td><td>The user's delegate signature when revoking an attestation on their behalf.</td></tr><tr><td>getTxHash?</td><td><code>(txHash: `0x${string}`) => void</code></td><td>An optional callback that immediately returns the transaction hash.</td></tr></tbody></table> #### Example ```typescript const res = await client.revokeAttestation("0x44"); ``` ### Delegating On-chain Revocation via ECDSA ```ts async function delegateSignRevokeAttestation( attestationId: string, options: { chain: EvmChains; delegationAccount?: PrivateKeyAccount; reason?: string; } ): Promise<RevokeDelegationSignature>; ``` #### Parameters | Name | Type | Description | | ------------- | -------------------------------------- | --------------------------------------------- | | attestationId | `string` | The ID of the attestation we are revoking. | | options | `DelegateSignRevokeAttestationOptions` | Options for delegate revoking an attestation. | #### DelegateSignRevokeAttestationOptions | Name | Type | Description | | ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | chain | `EvmChains` | The EVM chain we are targeting. | | delegationAccount? | `PrivateKeyAccount` | The signer account that signs the message. See `viem/accounts`. If this is null, a signer from `window.ethereum` will be used. | | reason? | `string` | Reason for the revocation. | | rpcUrl? | `string` | Optional RPC URL. | | walletClient? | `WalletClient` | Optional `WalletClient` from viem to use for transactions. | #### Example ```typescript const { privateKeyToAccount } = require("viem/accounts"); const delegationPrivateKey = "0x..."; const delegationResult = await delegateSignRevokeAttestation("0x46", { chain: EvmChains.baseSepolia, reason: "revoke reason", delegationAccount: privateKeyToAccount(delegationPrivateKey), }); const res = await client.revokeAttestation(delegationResult.attestationId, { reason: delegationResult.reason, delegationSignature: delegationResult.delegationSignature, }); ``` # Examples ### On-chain Mode ```tsx import { SignProtocolClient, SpMode, EvmChains, delegateSignAttestation, delegateSignRevokeAttestation, delegateSignSchema, } from "@ethsign/sp-sdk"; import { privateKeyToAccount } from "viem/accounts"; const privateKey = "0xabc"; // Optional const client = new SignProtocolClient(SpMode.OnChain, { chain: EvmChains.polygonMumbai, account: privateKeyToAccount(privateKey), // Optional if you are using an injected provider apiKey: 'xxx', // Optional, from https://developer.sign.global/ }); // Create schema const createSchemaRes = await client.createSchema({ name: "xxx", data: [{ name: "name", type: "string" }], }); // Delegated create schema const delegationPrivateKey = "0xaaaaa"; const info = await delegateSignSchema( { name: "xxx", data: [{ name: "name", type: "string" }], }, { chain: EvmChains.sepolia, delegationAccount: privateKeyToAccount(delegationPrivateKey), } ); const delegateCreateSchemaRes = await client.createSchema(info.schema, { delegationSignature: info.delegationSignature, }); // Create attestation const createAttestationRes = await client.createAttestation({ schemaId: "0x3", data: { name: "a" }, indexingValue: "xxx", }); // Delegated create attestation const delegationPrivateKey = "0xaaaaa"; const info = await delegateSignAttestation( { schemaId: "0x1", data: { name: "a" }, indexingValue: "xxx", }, { chain: EvmChains.sepolia, delegationAccount: privateKeyToAccount(delegationPrivateKey), } ); const delegationCreateAttestationRes = await client.createAttestation( info.attestation, { delegationSignature: info.delegationSignature, } ); // Revoke attestation const revokeAttestationRes = await client.revokeAttestation("0x3", { reason: "test", }); // Delegated revoke attestation const delegationPrivateKey = "0xaaaaa
프로젝트로 돌아가기