@atcute/cid
Advanced tools
Comparing version 2.0.1 to 2.1.0
import { fromBase32, toBase32 } from '@atcute/multibase'; | ||
import { allocUnsafe, toSha256 } from '@atcute/uint8array'; | ||
import * as varint from '@atcute/varint'; | ||
@@ -8,6 +9,6 @@ export const CID_VERSION = 1; | ||
export const create = async (codec, data) => { | ||
const digest = new Uint8Array(await crypto.subtle.digest('sha-256', data)); | ||
const digest = await toSha256(data); | ||
const digestSize = digest.length; | ||
const digestLebSize = varint.encodingLength(digestSize); | ||
const bytes = new Uint8Array(3 + digestLebSize + digestSize); | ||
const bytes = allocUnsafe(3 + digestLebSize + digestSize); | ||
bytes[0] = CID_VERSION; | ||
@@ -92,3 +93,4 @@ bytes[1] = codec; | ||
export const toBinary = (cid) => { | ||
const bytes = new Uint8Array(1 + cid.bytes.length); | ||
const bytes = allocUnsafe(1 + cid.bytes.length); | ||
bytes[0] = 0; | ||
bytes.set(cid.bytes, 1); | ||
@@ -95,0 +97,0 @@ return bytes; |
import { fromBase32, toBase32 } from '@atcute/multibase'; | ||
import { allocUnsafe, toSha256 } from '@atcute/uint8array'; | ||
import * as varint from '@atcute/varint'; | ||
@@ -32,3 +33,3 @@ | ||
export const create = async (codec: 0x55 | 0x71, data: Uint8Array): Promise<Cid> => { | ||
const digest = new Uint8Array(await crypto.subtle.digest('sha-256', data)); | ||
const digest = await toSha256(data); | ||
@@ -38,3 +39,3 @@ const digestSize = digest.length; | ||
const bytes = new Uint8Array(3 + digestLebSize + digestSize); | ||
const bytes = allocUnsafe(3 + digestLebSize + digestSize); | ||
@@ -144,3 +145,4 @@ bytes[0] = CID_VERSION; | ||
export const toBinary = (cid: Cid): Uint8Array => { | ||
const bytes = new Uint8Array(1 + cid.bytes.length); | ||
const bytes = allocUnsafe(1 + cid.bytes.length); | ||
bytes[0] = 0; | ||
bytes.set(cid.bytes, 1); | ||
@@ -147,0 +149,0 @@ |
{ | ||
"type": "module", | ||
"name": "@atcute/cid", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "lightweight DASL CID codec library for AT Protocol", | ||
@@ -30,4 +30,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@atcute/multibase": "^1.0.1", | ||
"@atcute/varint": "^1.0.2" | ||
"@atcute/uint8array": "^1.0.0", | ||
"@atcute/varint": "^1.0.2", | ||
"@atcute/multibase": "^1.1.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
17715
322
3
+ Added@atcute/uint8array@^1.0.0
Updated@atcute/multibase@^1.1.0