add content_to_cid
This commit is contained in:
7
ticc.js
7
ticc.js
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user