@ atcute/ crypto (中文(简体) )
aT 协议的加密公用设备.
npm install @atcute/crypto
此软件包为两个椭圆曲线系统提供密钥生成、签名和验证 aT议定书用于验证身份和存储数据:
p256: 使用 WebCrypto APIsecp256k1: 使用node:crypto在节点J,@noble/secp256k1其他地方
使用量
创建密钥页
import { Secp256k1PrivateKeyExportable, P256PrivateKeyExportable } from '@atcute/crypto';
// secp256k1 keypair
const keypair = await Secp256k1PrivateKeyExportable.createKeypair();
// p256 keypair
const p256Keypair = await P256PrivateKeyExportable.createKeypair();
签名数据
// sign() hashes the data and signs it
const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const sig = await keypair.sign(data);
导出公钥
// export as did:key format
const didKey = await keypair.exportPublicKey('did');
// -> "did:key:zQ3shVRtgqTRHC7Lj4DYScoDgReNpsDp3HBnuKBKt1FSXKQ38"
// export as multibase
const multibase = await keypair.exportPublicKey('multibase');
验证签名
import { verifySigWithDidKey } from '@atcute/crypto';
// verify using did:key (automatically detects curve type)
const ok = await verifySigWithDidKey(didKey, sig, data);