sui-keypair-cryptography

RandyPen 的头像作者 RandyPen

帮助 Claude Code 了解 Sui 区块链密钥对和密码学操作,提供密钥生成、签名、验证、地址派生和多重签名方案支持的指南和示例。在 Sui 开发中使用加密技术时或当用户提到密钥对、加密技术、签名或验证时使用。

📖 中文导读:帮助 Claude Code 了解 Sui 区块链密钥对和密码学操作,提供密钥生成、签名、验证、地址派生和多重签名方案支持的指南和示例。在 Sui 开发中使用加密技术时或当用户提到密钥对、加密技术、签名或验证时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: sui-keypair-cryptography description: "Helps Claude Code understand Sui blockchain keypair and cryptography operations, providing guidelines and examples for key generation, signing, verification, address derivation, and multi-signature scheme support. Use when working with cryptography in Sui development or when the user mentions keypairs, cryptography, signing, or verification."

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.

Quick Start

Installation and Import

// 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';

Basic Examples

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);

Core Components

Signer Abstract Class

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

Keypair Abstract Class

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

PublicKey Abstract Class

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

Supported Signature Schemes

For detailed information about supported signature schemes including Ed25519, Secp256k1, Secp256r1, and Passkey, see Signature Schemes.

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.

  • 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

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.