sui-keypair-cryptography

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Keypair and Cryptography Skill

密钥对与加密技能

Overview

概述

The keypair and cryptography module provides secure cryptographic operations for the Sui blockchain ecosystem, including key generation, signing, verification, and address derivation. It supports multiple signature schemes and provides a unified interface for cryptographic operations.
密钥对与加密模块为Sui区块链生态系统提供安全的加密操作,包括密钥生成、签名、验证和地址推导。它支持多种签名方案,并为加密操作提供统一接口。

Quick Start

快速开始

Installation and Import

安装与导入

typescript
// Import Ed25519 keypair
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';

// Import other signature schemes
import { Secp256k1Keypair } from '@mysten/sui/keypairs/secp256k1';
import { Secp256r1Keypair } from '@mysten/sui/keypairs/secp256r1';

// Import common utilities
import { mnemonicToSeed } from '@mysten/sui/cryptography';
// Note: generateMnemonic needs to be imported from @scure/bip39: import { generateMnemonic } from '@scure/bip39';
typescript
// Import Ed25519 keypair
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';

// Import other signature schemes
import { Secp256k1Keypair } from '@mysten/sui/keypairs/secp256k1';
import { Secp256r1Keypair } from '@mysten/sui/keypairs/secp256r1';

// Import common utilities
import { mnemonicToSeed } from '@mysten/sui/cryptography';
// 注意:generateMnemonic需要从@scure/bip39导入:import { generateMnemonic } from '@scure/bip39';

Basic Examples

基础示例

typescript
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { Transaction } from '@mysten/sui/transactions';

// Generate new keypair
const keypair = new Ed25519Keypair();

// Get address
const address = keypair.toSuiAddress();
console.log('Address:', address);

// Sign transaction
const tx = new Transaction();
// ... build transaction
const bytes = await tx.build({ client });
const { signature } = await keypair.signTransaction(bytes);

// Verify signature
const isValid = await keypair.getPublicKey().verifyTransaction(bytes, signature);
console.log('Signature valid:', isValid);
typescript
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { Transaction } from '@mysten/sui/transactions';

// 生成新的密钥对
const keypair = new Ed25519Keypair();

// 获取地址
const address = keypair.toSuiAddress();
console.log('Address:', address);

// 签名交易
const tx = new Transaction();
// ... 构建交易
const bytes = await tx.build({ client });
const { signature } = await keypair.signTransaction(bytes);

// 验证签名
const isValid = await keypair.getPublicKey().verifyTransaction(bytes, signature);
console.log('Signature valid:', isValid);

Core Components

核心组件

Signer Abstract Class

Signer抽象类

Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/keypair.ts
Signer
is the abstract base class for all signing operations, providing:
  • Message signing with intent scope
  • Transaction signing and execution
  • Personal message signing
  • Address derivation from public key
位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/keypair.ts
Signer
是所有签名操作的抽象基类,提供:
  • 带意图范围的消息签名
  • 交易签名与执行
  • 个人消息签名
  • 从公钥推导地址

Keypair Abstract Class

Keypair抽象类

Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/keypair.ts
Keypair
extends
Signer
, adding secret key management:
  • Secret key serialization/deserialization
  • Bech32 encoding for private keys
  • Multiple signature scheme support
位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/keypair.ts
Keypair
继承自
Signer
,新增了密钥管理功能:
  • 密钥序列化/反序列化
  • 私钥的Bech32编码
  • 多签名方案支持

PublicKey Abstract Class

PublicKey抽象类

Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/publickey.ts
PublicKey
is the base class for public key operations, providing:
  • Address derivation and verification
  • Signature verification
  • Multiple encoding formats
  • Intent-based verification
位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/publickey.ts
PublicKey
是公钥操作的基类,提供:
  • 地址推导与验证
  • 签名验证
  • 多种编码格式
  • 基于意图的验证

Supported Signature Schemes

支持的签名方案

For detailed information about supported signature schemes including Ed25519, Secp256k1, Secp256r1, and Passkey, see Signature Schemes.
关于支持的签名方案(包括Ed25519、Secp256k1、Secp256r1和Passkey)的详细信息,请参阅签名方案

Key Features

关键特性

For detailed information about key features including intent-based signing, address derivation, and private key management, see Key Features.
关于关键特性(包括基于意图的签名、地址推导和私钥管理)的详细信息,请参阅关键特性

Usage Patterns

使用模式

For detailed information about usage patterns including key generation, signing, verification, and serialization, see Usage Patterns.
关于使用模式(包括密钥生成、签名、验证和序列化)的详细信息,请参阅使用模式

Architecture Notes

架构说明

For detailed information about architecture notes including security design, intent system, and address generation, see Architecture Notes.
关于架构说明(包括安全设计、意图系统和地址生成)的详细信息,请参阅架构说明

Integration Points

集成点

For detailed information about integration points including transaction integration, wallet integration, and blockchain operations, see Integration Points.
关于集成点(包括交易集成、钱包集成和区块链操作)的详细信息,请参阅集成点

Advanced Features

高级特性

For detailed information about advanced features including multi-signature support, hardware security, and key rotation, see Advanced Features.
关于高级特性(包括多签名支持、硬件安全和密钥轮换)的详细信息,请参阅高级特性

Security Considerations

安全注意事项

For detailed information about security considerations including key protection, signature security, and best practices, see Security Considerations.
关于安全注意事项(包括密钥保护、签名安全和最佳实践)的详细信息,请参阅安全注意事项

Workflows

工作流程

For detailed information about workflows including secure key generation, transaction signing, and key recovery, see Workflows.
关于工作流程(包括安全密钥生成、交易签名和密钥恢复)的详细信息,请参阅工作流程

Best Practices

最佳实践

For detailed information about best practices including key management, signing practices, and address handling, see Best Practices.
关于最佳实践(包括密钥管理、签名实践和地址处理)的详细信息,请参阅最佳实践

Related Skills

相关技能

  • sui-transaction-building: Understand the application of keypairs in transaction signing
  • sui-bcs: Understand BCS serialization of public keys and signatures
  • sui-client: Understand integration with SuiClient
  • sui-transaction-building:了解密钥对在交易签名中的应用
  • sui-bcs:了解公钥与签名的BCS序列化
  • sui-client:了解与SuiClient的集成

References

参考资料

  • Source Code:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/
    and
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/keypairs/
  • Test Cases:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/__tests__/
  • TypeScript Type Definitions:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/types.ts
  • Security Guidelines: Sui official security best practices documentation

This skill helps Claude Code understand Sui keypair and cryptography operations, providing practical code examples and usage guidelines. When users need to handle key management, signing, and verification for the Sui blockchain, referring to this skill can provide accurate TypeScript code and best practices.
  • 源代码:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/keypairs/
  • 测试用例:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/__tests__/
  • TypeScript类型定义:
    https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/cryptography/types.ts
  • 安全指南: Sui官方安全最佳实践文档

本技能帮助Claude Code理解Sui密钥对与加密操作,提供实用的代码示例和使用指南。当用户需要为Sui区块链处理密钥管理、签名和验证时,参考本技能可获取准确的TypeScript代码和最佳实践。