Compare commits

..

2 Commits

Author SHA1 Message Date
Luk
450c6df357 add content_to_cid 2026-03-16 14:17:15 +08:00
Luk
c9a6afdb38 u 2026-02-07 11:34:38 +08:00
4 changed files with 21 additions and 1 deletions

View File

@@ -24,7 +24,7 @@
在前后端软件的 package.json 的依赖清单中引入本库:
```
npm install git+https://git.tic.cc/npm/tic-crypto#RELEASE_OR_BRANCH --save
npm install git+https://git.tic.cc/open/tic-crypto#RELEASE_OR_BRANCH --save
```
## 用法

View File

@@ -12,6 +12,7 @@
"eccrypto-js": "^5.4.0",
"ethereum-rsa": "^1.0.5",
"hdkey": "^2.0.1",
"ipfs-only-hash": "^4.0.0",
"js-crypto-key-utils": "^1.0.4",
"keccak": "^3.0.2",
"secp256k1": "^4.0.3",

View File

@@ -22,6 +22,12 @@
*.nosf/
*.nosf.*/
## everything 'git pull or fetch' will update `.git/FETCH_HEAD`, even if the content doesn't change. To avoid too many useless updates of this file in Seafile history:
FETCH_HEAD
*/FETCH_HEAD
.Trash/
.DS_Store
*/.DS_Store
@@ -48,12 +54,18 @@ _desktop.ini
node_modules/
*/node_modules/
package-lock.json
*/package-lock.json
pages4loader.json5
*/pages4loader.json5
.deploy_git/
*/.deploy_git/
# next.js 项目
.next/
*/.next/
# HBuilder 目录
unpackage/
*/unpackage/

View File

@@ -16,6 +16,7 @@ const hdkey = require('hdkey') // https://github.com/cryptocoinjs/hdkey // 或
const secp256k1 = require('secp256k1')
const base32encode = require('base32-encode')
const base32decode = require('base32-decode')
const ipfsOnlyHash = require('ipfs-only-hash')
const { TronWeb } = require('tronweb')
// 全部以hex为默认输入输出格式方便人的阅读以及方便函数之间统一接口
@@ -1527,6 +1528,12 @@ class TicCrypto {
return '04' + this.padStart(x.toString(16), 64, '0') + this.padStart(y.toString(16), 64, '0')
}
static async content_to_cid ({ content, ...option }) {
// {content: 'hello world', cidVersion: 0}
// content can be a string, a file, a stream
return await ipfsOnlyHash.of(content, option)
}
// cahex: content address hex. 最核心的纯hex的内容地址没有任何额外标记。同一个内容的 cahex 是唯一的,而 cid 是在 cahex 基础上有各种不同的编码转成字符串形式。cid建议叫做 caid.
static cid_to_cahex ({ cid }) {
try {