X25519 关键协定 (@数字证书/x25519-key-agreement-key-2020)
An X25519 (Curve25519) DH (Diffie-Hellman) 关键执行与X25519 2020 Crypto套房合作.
目录
警卫
传统发展
背景情况
(从 digitalbazaar/x25519-key-agreement-key-2020 页:1
以提供类型脚本兼容性。 )
用于与 crypto-ld >= 5.0。 。 。 .
为了真正用这些密钥进行加密,我们建议您使用
页:1 minimal-cipher 图书馆.
这是一个低级库,用于生成并序列化 X25519 (Curve25519)
密钥对( 使用) nacl.box 盖下.
另见(相关规格):
安装
需要节点.js 12+
在当地安装(用于开发):
git clone https://github.com/digitalcredentials/x25519-key-agreement-key-2020.git
cd x25519-key-agreement-key-2020
npm install
使用量
导入中 :
const {X25519KeyAgreementKey2020} = require('@digitalcredentials/x25519-key-agreement-key-2020');
// Or, if you're testing code in the interactive Node CLI, right in this repo:
const {X25519KeyAgreementKey2020} = require('./');
生成中 :
const keyPair = await X25519KeyAgreementKey2020.generate({
controller: 'did:example:1234'
});
// ->
{
"id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"controller": "did:example:1234",
"type": "X25519KeyAgreementKey2020",
"publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"privateKeyMultibase": "z3weeMD56C1T347EmB6kYNS7trpQwjvtQCpCYRpqGz6mcemT"
}
将公钥序列化 :
keyPair.export({publicKey: true});
// ->
{
"id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"controller": "did:example:1234",
"type": "X25519KeyAgreementKey2020",
"publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM"
}
私人和公共钥匙的序列:
// a different key pair than the previous example
await keyPair.export({publicKey: true, privateKey: true})
// ->
{
"id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"controller": "did:example:1234",
"type": "X25519KeyAgreementKey2020",
"publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"privateKeyMultibase": "z3weeMD56C1T347EmB6kYNS7trpQwjvtQCpCYRpqGz6mcemT"
}
切换 :
// Loading public key only
const keyPair = await X25519KeyAgreementKey2020.from({
"id": "did:example:1234#z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM",
"controller": "did:example:1234",
"type": "X25519KeyAgreementKey2020",
"publicKeyMultibase": "z6LSeRSE5Em5oJpwdk3NBaLVERBS332ULC7EQq5EtMsmXhsM"
});
贡献
见 贡献文件来啊!
公关接受.
请遵照 标准读取 规格.
许可证
- MIT许可证 - DCC - TypeScript兼容.
- 新BSD许可证 (3-clause) 2020-2021 Digital Bazaar - 初始实施.