Examples
On-chain mode
import {
SignProtocolClient,
SpMode,
EvmChains,
delegateSignAttestation,
delegateSignRevokeAttestation,
delegateSignSchema,
} from "@ethsign/sp-sdk";
import { privateKeyToAccount } from "viem/accounts";
const privateKey = "0xabc"; // Optional
const delegationPrivateKey = "0xaaaaa"; // The account that signs delegated actions
const client = new SignProtocolClient(SpMode.OnChain, {
chain: EvmChains.sepolia,
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 schemaDelegation = await delegateSignSchema(
{
name: "xxx",
data: [{ name: "name", type: "string" }],
},
{
chain: EvmChains.sepolia,
delegationAccount: privateKeyToAccount(delegationPrivateKey),
}
);
const delegateCreateSchemaRes = await client.createSchema(schemaDelegation.schema, {
delegationSignature: schemaDelegation.delegationSignature,
});
// Create attestation
const createAttestationRes = await client.createAttestation({
schemaId: "0x3",
data: { name: "a" },
indexingValue: "xxx",
});
// Delegated create attestation
const attestationDelegation = await delegateSignAttestation(
{
schemaId: "0x1",
data: { name: "a" },
indexingValue: "xxx",
},
{
chain: EvmChains.sepolia,
delegationAccount: privateKeyToAccount(delegationPrivateKey),
}
);
const delegationCreateAttestationRes = await client.createAttestation(
attestationDelegation.attestation,
{
delegationSignature: attestationDelegation.delegationSignature,
}
);
// Revoke attestation
const revokeAttestationRes = await client.revokeAttestation("0x3", {
reason: "test",
});
// Delegated revoke attestation
const revokeDelegation = await delegateSignRevokeAttestation("0x3", {
chain: EvmChains.sepolia,
reason: "test",
delegationAccount: privateKeyToAccount(delegationPrivateKey),
});
const delegationRevokeAttestationRes = await client.revokeAttestation(
revokeDelegation.attestationId,
{
reason: revokeDelegation.reason,
delegationSignature: revokeDelegation.delegationSignature,
}
);
Off-chain (Arweave) mode
import {
SignProtocolClient,
SpMode,
EvmChains,
OffChainSignType,
} from "@ethsign/sp-sdk";
import { privateKeyToAccount } from "viem/accounts";
const privateKey = "0xabc"; // Optional
const client = new SignProtocolClient(SpMode.OffChain, {
signType: OffChainSignType.EvmEip712,
account: privateKeyToAccount(privateKey), // Optional
apiKey: 'xxx', // Required, from https://developer.sign.global/
});
// Create schema
const schemaInfo = await client.createSchema({
name: "xxx",
data: [{ name: "name", type: "string" }],
});
// Create attestation
const attestationInfo = await client.createAttestation({
schemaId: "xxxx", // `schemaInfo.schemaId` or other `schemaId`
data: { name: "a" },
indexingValue: "xxx",
});
// Revoke attestation
const attestationId = "xxx";
const revokeAttestationRes = await client.revokeAttestation(attestationId, {
reason: "test",
});