create-bap-identity
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate BAP Identity
创建BAP身份
Create and manage BAP (Bitcoin Attestation Protocol) identities using the library.
bsv-bap使用库创建和管理BAP(Bitcoin Attestation Protocol)身份。
bsv-bapInstallation
安装
bash
bun add bsv-bap @bsv/sdkbash
bun add bsv-bap @bsv/sdkCreating an Identity
创建身份
typescript
import { BAP } from "bsv-bap";
import { PrivateKey } from "@bsv/sdk";
// Create BAP instance with new key
const privateKey = PrivateKey.fromRandom();
const bap = new BAP({ rootPk: privateKey.toWif() });
// Create identity
const identity = bap.newId("Alice Smith");
console.log("Identity Key:", identity.getIdentityKey());
console.log("Root Address:", identity.rootAddress);
console.log("Signing Address:", identity.getCurrentAddress());typescript
import { BAP } from "bsv-bap";
import { PrivateKey } from "@bsv/sdk";
// 使用新密钥创建BAP实例
const privateKey = PrivateKey.fromRandom();
const bap = new BAP({ rootPk: privateKey.toWif() });
// 创建身份
const identity = bap.newId("Alice Smith");
console.log("身份密钥:", identity.getIdentityKey());
console.log("根地址:", identity.rootAddress);
console.log("签名地址:", identity.getCurrentAddress());Key Derivation
密钥派生
BAP uses Type42 (BRC-42) key derivation with BRC-43 invoice numbers:
| Purpose | Invoice Number | Security Level |
|---|---|---|
| Signing key | | 1 (public protocol) |
| Friend encryption | | 2 (user-approved) |
BAP使用带有BRC-43发票编号的Type42(BRC-42)密钥派生方式:
| 用途 | 发票编号 | 安全级别 |
|---|---|---|
| 签名密钥 | | 1(公开协议) |
| 好友加密 | | 2(用户授权) |
Signing Messages
签名消息
typescript
import { Utils } from "@bsv/sdk";
const { toArray } = Utils;
// Sign a message
const message = toArray("Hello World", "utf8");
const { address, signature } = identity.signMessage(message);
// Verify (on any BAP instance)
const isValid = bap.verifySignature("Hello World", address, signature);typescript
import { Utils } from "@bsv/sdk";
const { toArray } = Utils;
// 签名消息
const message = toArray("Hello World", "utf8");
const { address, signature } = identity.signMessage(message);
// 验证(在任意BAP实例上)
const isValid = bap.verifySignature("Hello World", address, signature);Friend Encryption
好友加密
Derive friend-specific encryption keys for private communication:
typescript
// Get encryption pubkey for a friend (share in friend requests)
const friendPubKey = identity.getEncryptionPublicKeyWithSeed(friendBapId);
// Encrypt data for friend
const ciphertext = identity.encryptWithSeed("secret message", friendBapId);
// Decrypt data from friend
const plaintext = identity.decryptWithSeed(ciphertext, friendBapId);派生特定于好友的加密密钥以进行私密通信:
typescript
// 获取好友的加密公钥(在好友请求中分享)
const friendPubKey = identity.getEncryptionPublicKeyWithSeed(friendBapId);
// 为好友加密数据
const ciphertext = identity.encryptWithSeed("secret message", friendBapId);
// 解密来自好友的数据
const plaintext = identity.decryptWithSeed(ciphertext, friendBapId);Export/Import
导出/导入
typescript
// Export for backup
const backup = bap.exportForBackup("My Identity");
// { ids: "...", createdAt: "...", rootPk: "..." }
// Import from backup
const bap2 = new BAP({ rootPk: backup.rootPk });
bap2.importIds(backup.ids);typescript
// 导出用于备份
const backup = bap.exportForBackup("My Identity");
// { ids: "...", createdAt: "...", rootPk: "..." }
// 从备份导入
const bap2 = new BAP({ rootPk: backup.rootPk });
bap2.importIds(backup.ids);CLI Option
CLI选项
For quick operations, the package includes a CLI:
bsv-bapbash
npm install -g bsv-bap
bap create --name "Alice" # Create identity (~/.bap/identity.json)
bap sign "Hello World" # Sign message
bap verify "msg" "sig" "addr" # Verify signature
bap info # Show identity info
bap friend-pubkey <bapId> # Get friend encryption pubkey
bap encrypt <data> <bapId> # Encrypt for friend
bap decrypt <text> <bapId> # Decrypt from friend
bap export # Export backup JSON
bap import <file> # Import from backup为了快速操作,包包含一个CLI:
bsv-bapbash
npm install -g bsv-bap
bap create --name "Alice" # 创建身份(~/.bap/identity.json)
bap sign "Hello World" # 签名消息
bap verify "msg" "sig" "addr" # 验证签名
bap info # 显示身份信息
bap friend-pubkey <bapId> # 获取好友加密公钥
bap encrypt <data> <bapId> # 为好友加密数据
bap decrypt <text> <bapId> # 解密来自好友的数据
bap export # 导出备份JSON
bap import <file> # 从文件导入Next Steps
后续步骤
After creating an identity:
- Sign messages for authentication
- Share encryption pubkeys in friend requests
- Publish identity to blockchain for on-chain reputation
- Integrate with Sigma Identity for OAuth ()
@sigma-auth/better-auth-plugin
创建身份后:
- 签名消息以进行身份验证
- 在好友请求中分享加密公钥
- 将身份发布到区块链以获取链上声誉
- 与Sigma Identity集成以实现OAuth()
@sigma-auth/better-auth-plugin
Related Skills
相关技能
- - Type42 and BRC-43 key derivation patterns
key-derivation - - BSM, BRC-77, and Sigma signing protocols
message-signing - - bitcoin-backup CLI for .bep encrypted backups
encrypt-decrypt-backup
- - Type42和BRC-43密钥派生模式
key-derivation - - BSM、BRC-77和Sigma签名协议
message-signing - - 用于.bep加密备份的bitcoin-backup CLI
encrypt-decrypt-backup