rename 'cosh' to 'cahex', because cosh is a wrong naming which I didn't realize before. It is not hash, but simply hex.
This commit is contained in:
parent
c77f28fe30
commit
8e3ae5639f
16
ticc.js
16
ticc.js
@ -1516,8 +1516,8 @@ class TicCrypto {
|
||||
return '04' + this.padStart(x.toString(16), 64, '0') + this.padStart(y.toString(16), 64, '0')
|
||||
}
|
||||
|
||||
// cosh: content hash. 最核心的纯hex的内容地址,没有任何额外标记。同一个内容的cosh是唯一的,而cid是在cosh基础上有各种不同的编码。cid建议叫做 coid.
|
||||
static cid_to_cosh ({ cid }) {
|
||||
// cahex: content address hex. 最核心的纯hex的内容地址,没有任何额外标记。同一个内容的 cahex 是唯一的,而 cid 是在 cahex 基础上有各种不同的编码,转成字符串形式。cid建议叫做 caid.
|
||||
static cid_to_cahex ({ cid }) {
|
||||
try {
|
||||
if (/^[Q1]/.test(cid)) {
|
||||
return this.b58_to_hex(cid).slice(4) // 前2字节是 cid0 的字节序数标记
|
||||
@ -1537,7 +1537,7 @@ class TicCrypto {
|
||||
}
|
||||
}
|
||||
|
||||
static cosh_to_cid ({ cosh, cidBase = 'b32', cidVersion = 1, cidCodec = 'raw', cidAlgo = 'sha256' }) {
|
||||
static cahex_to_cid ({ cahex, cidBase = 'b32', cidVersion = 1, cidCodec = 'raw', cidAlgo = 'sha256' }) {
|
||||
// https://github.com/multiformats/multibase
|
||||
const multibase = {
|
||||
identity: 0x00,
|
||||
@ -1579,9 +1579,9 @@ class TicCrypto {
|
||||
}
|
||||
try {
|
||||
if (cidVersion === 0) {
|
||||
return this.hex_to_b58(`${multialgo[cidAlgo]}${Number(cosh.length / 2).toString(16)}${cosh}`)
|
||||
return this.hex_to_b58(`${multialgo[cidAlgo]}${Number(cahex.length / 2).toString(16)}${cahex}`)
|
||||
} else if (cidVersion === 1) {
|
||||
const fullHex = `01${multicodec[cidCodec]}${multialgo[cidAlgo]}${Number(cosh.length / 2).toString(16)}${cosh}`
|
||||
const fullHex = `01${multicodec[cidCodec]}${multialgo[cidAlgo]}${Number(cahex.length / 2).toString(16)}${cahex}`
|
||||
let converted = ''
|
||||
if (cidBase === 'b16') {
|
||||
converted = fullHex.toLowerCase()
|
||||
@ -1617,15 +1617,15 @@ class TicCrypto {
|
||||
try {
|
||||
if (key.length < 64 && /^bafkrei/.test(key)) {
|
||||
pextokenCid = key
|
||||
pextokenCosh = this.cid_to_cosh({ cid: pextokenCid })
|
||||
pextokenCosh = this.cid_to_cahex({ cid: pextokenCid })
|
||||
nftToid = BigInt('0x' + pextokenCosh).toString()
|
||||
} else if (key.length > 64 && /^\d+$/.test(key)) {
|
||||
nftToid = key
|
||||
pextokenCosh = BigInt(nftToid).toString(16)
|
||||
pextokenCid = this.cosh_to_cid({ cosh: pextokenCosh })
|
||||
pextokenCid = this.cahex_to_cid({ cahex: pextokenCosh })
|
||||
} else if (/^[0-9a-f]{64}$/.test(key)) {
|
||||
pextokenCosh = key
|
||||
pextokenCid = this.cosh_to_cid({ cosh: pextokenCosh })
|
||||
pextokenCid = this.cahex_to_cid({ cahex: pextokenCosh })
|
||||
nftToid = BigInt('0x' + pextokenCosh).toString()
|
||||
}
|
||||
tokenURI = pextokenCosh ? `https://ipfs.tic.cc/ipfs/f01551220${pextokenCosh}` : undefined
|
||||
|
Loading…
Reference in New Issue
Block a user