创建一个新模式,定义证明的结构和验证规则。此指令允许凭证授权方创建模式,指定证明应包含哪些字段以及它们应如何格式化。
参数
| 参数 | 类型 | 描述 |
|---|---|---|
payer | Signer | 将支付交易费用的账户 |
authority | Signer | 凭证的授权方 |
credential | PublicKey | Pda | 此模式将关联的凭证账户 |
schema | PublicKey | Pda | 要创建的模式账户 |
systemProgram | PublicKey | Pda | System Program 账户(默认为 '11111111111111111111111111111111') |
name | string | 模式的名称 |
description | string | 模式用途的详细描述 |
layout | ReadonlyUint8Array | 模式的二进制布局定义 |
fieldNames | string[] | 模式中字段的名称 |
返回值
返回一个 TransactionBuilder,可用于构建和发送交易。
示例
import { getCreateSchemaInstruction } from "sas-lib";const transaction = getCreateSchemaInstruction({payer: payerSigner,authority: authoritySigner,credential: credentialPublicKey,schema: schemaPublicKey,systemProgram: systemProgramPublicKey,name: "Identity Verification",description: "Schema for verifying user identity information",layout: schemaLayoutBytes,fieldNames: ["fullName", "dateOfBirth", "nationality"]});// Send the transactionawait transaction.sendAndConfirm();
重要说明
- 支付方必须是交易的签名者
- 授权方必须是交易的签名者,并且必须是凭证的授权方
- 模式账户必须可写
- 凭证账户必须可读
- 此操作需要 System Program 进行 rent 豁免计算
- 模式名称应具有描述性,并在凭证内唯一
- 描述应提供关于模式用途和使用方式的清晰信息
- 布局必须是定义证明数据结构的有效二进制格式
- fieldNames 数组必须与布局中定义的字段匹配
- 如有需要,模式可以稍后暂停
- 模式可以进行版本控制以支持数据结构的演进
- 在此模式下创建的所有证明都必须符合其结构
Is this page helpful?