时光链.加密库
Go to file
2021-05-08 22:42:08 +08:00
.gitignore 改进 isSecword 防止数量不对导致 bitcore-mnemonics 异常。改进 isAddress 把 prefix 也纳入 TIC地址的校验。 2020-02-23 10:46:19 +08:00
.prettierrc.js 添加 .prettierrc.js 2020-11-05 09:48:13 +08:00
index.js crypto.sign/verify 在浏览器中不存在,换回原来的方案 2021-05-08 22:42:08 +08:00
package.json 把 eccrypto 换成 eccrypto-js 2021-05-07 16:29:20 +08:00
README.md u 2021-03-10 15:59:46 +08:00
README.xlsx 把 eccrypto 换成 eccrypto-js 2021-05-07 16:29:20 +08:00
test.js 用eccrypto加解密,用crypto签名。互相转换压缩和非压缩公钥 2020-02-20 13:36:44 +08:00

tic.crypto

时光链区块链密码学算法工具库:为区块链相关应用开发提供一套底层的基础算法工具库,用来处理哈希、加解密、签名、助记词、等等。

硬件环境

  • 机型Mac 或 PC 机
  • 内存8GB 以上
  • 硬盘500G 以上

软件环境

  • 操作系统:跨平台通用,支持 MacOS, Linux, Windows
  • 开发环境:推荐 Visual Studio Code
  • 运行环境nodejs 12.16 版本

安装指南

在前后端软件的 package.json 的依赖清单中引入本库:

npm install git+https://git.faronear.org/npm/tic.crypto#RELEASE_OR_BRANCH --save

用法

基本用法示例:

let ticCrypto=require('tic.crypto') // 引用
let sw=ticCrypto.randomSecword() // 生成一个随机的助记词(即密语)。或者使用现成的密语。
let kp=ticCrypto.secword2keypair(sw) // 把密语转换成公私钥
let address=ticCrypto.secword2address(sw) // 把密语转换成地址

编程接口规范

函数名 参数 备注
hash (data, option={hasher:'sha256', salt, input:'utf8', output:'hex'}) 哈希算法。给 input(=utf8 latin1 ascii)格式的输入 data 加 salt 后,根据 hasher(=sha256 md5 sha1 sha512 ripemd160),输出 output(=hex latin1 base64 buf)格式的哈希值。
isHashable (data)
isHash
encrypt (data, pwd, option={ cipher:'aes-256-cfb', input:'utf8', output:'hex' })
decrypt (data, pwd, option={ cipher:'aes-256-cfb', input:'hex', output:'utf8' })
sign (data, seckey, option)
isSignature
verify (data, signature, pubkey, option)
pass2keypair
secword2keypair 密语到公私钥 { pubkey, seckey }
seckey2pubkey
secword2account 密语到账户 { address, pubkey, seckey }
secword2address 密语到地址 address
isSecword
isSeckey
isPubkey
isAddress
pubkey2address
secword2seed
randomSecword (lang) lang=[ 'CHINESE', 'ENGLISH', 'FRENCH', 'ITALIAN', 'JAPANESE', 'SPANISH' ]
randomSeckey
randomKeypair
randomString
randomNumber
randomUuid: { [Function: v4] v1
getMerkleRoot
distanceSig
compareSig
sortSigList
getString2Sign
rsaSign
rsaVerify