New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ceramic-sdk/identifiers

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ceramic-sdk/identifiers - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

3

dist/codecs.d.ts

@@ -5,2 +5,3 @@ import { Type } from 'codeco';

* Verify if `input` is a StreamID string.
* @internal
*/

@@ -19,2 +20,2 @@ export declare function isStreamIDString(input: string): input is string;

*/
export declare const streamIDAsBytes: Type<StreamID, Uint8Array, Uint8Array>;
export declare const streamIDAsBytes: Type<StreamID, Uint8Array, Uint8Array | StreamID>;

@@ -5,2 +5,3 @@ import { Type, refinement, string } from 'codeco';

* Verify if `input` is a StreamID string.
* @internal
*/ export function isStreamIDString(input) {

@@ -32,3 +33,3 @@ try {

try {
return context.success(StreamID.fromBytes(input));
return context.success(StreamID.isInstance(input) ? input : StreamID.fromBytes(input));
} catch {

@@ -35,0 +36,0 @@ return context.failure();

@@ -93,2 +93,3 @@ import { CID } from 'multiformats/cid';

* String representation of CommitID.
* @internal
*/

@@ -95,0 +96,0 @@ [Symbol.toPrimitive](): string | Uint8Array;

@@ -159,3 +159,3 @@ function _ts_decorate(decorators, target, key, desc) {

*
* @returns {String}
* @internal
*/ [Symbol.for('nodejs.util.inspect.custom')]() {

@@ -166,2 +166,3 @@ return `CommitID(${this.toString()})`;

* String representation of CommitID.
* @internal
*/ [Symbol.toPrimitive]() {

@@ -168,0 +169,0 @@ return this.toString();

import { CID } from 'multiformats/cid';
import { type StreamTypeCode } from './constants.js';
/** @internal */
export declare function readVarint(bytes: Uint8Array): [number, Uint8Array, number];
/** @internal */
export declare function readCid(bytes: Uint8Array): [CID, Uint8Array];
/** @internal */
export type StreamIDComponents = {

@@ -10,2 +13,3 @@ kind: 'stream-id';

};
/** @internal */
export type CommitIDComponents = {

@@ -17,7 +21,10 @@ kind: 'commit-id';

};
/** @internal */
export type StreamRefComponents = StreamIDComponents | CommitIDComponents;
/**
* Parse StreamID or CommitID from bytes.
* @internal
*/
export declare function fromBytes(input: Uint8Array, title?: string): StreamRefComponents;
/** @internal */
export declare function fromString(input: string, title?: string): StreamRefComponents;

@@ -29,2 +36,4 @@ /**

* @param input - CID or string.
*
* @internal
*/

@@ -40,3 +49,5 @@ export declare function parseCID(input: unknown): CID | null;

* @param commit - representation of commit, be it CID, 0, `'0'`, `null`
*
* @internal
*/
export declare function parseCommit(genesis: CID, commit?: CID | string | number | null): CID | null;

@@ -6,3 +6,3 @@ import { base36 } from 'multiformats/bases/base36';

import { STREAMID_CODEC } from './constants.js';
export function readVarint(bytes) {
/** @internal */ export function readVarint(bytes) {
const value = varint.decode(bytes);

@@ -23,3 +23,3 @@ const readLength = varint.decode.bytes;

}
export function readCid(bytes) {
/** @internal */ export function readCid(bytes) {
const [cidVersion, cidVersionRemainder] = readVarint(bytes);

@@ -41,2 +41,3 @@ if (!isCidVersion(cidVersion)) {

* Parse StreamID or CommitID from bytes.
* @internal
*/ export function fromBytes(input, title = 'StreamRef') {

@@ -77,3 +78,3 @@ const [streamCodec, streamCodecRemainder] = readVarint(input);

*/ const URL_PATTERN = /(ceramic:\/\/|\/ceramic\/)?([a-zA-Z0-9]+)(\?commit=([a-zA-Z0-9]+))?/;
export function fromString(input, title = 'StreamRef') {
/** @internal */ export function fromString(input, title = 'StreamRef') {
const protocolMatch = URL_PATTERN.exec(input) || [];

@@ -100,2 +101,4 @@ const base = protocolMatch[2];

* @param input - CID or string.
*
* @internal
*/ export function parseCID(input) {

@@ -116,2 +119,4 @@ try {

* @param commit - representation of commit, be it CID, 0, `'0'`, `null`
*
* @internal
*/ export function parseCommit(genesis, commit = null) {

@@ -118,0 +123,0 @@ if (!commit) return null // Handle number 0, null and undefined

@@ -90,3 +90,2 @@ import { CID } from 'multiformats/cid';

* Copy of self. Exists to maintain compatibility with CommitID.
* @readonly
*/

@@ -108,2 +107,3 @@ get baseID(): StreamID;

* String representation of StreamID.
* @internal
*/

@@ -110,0 +110,0 @@ [Symbol.toPrimitive](): string;

@@ -139,3 +139,2 @@ function _ts_decorate(decorators, target, key, desc) {

* Copy of self. Exists to maintain compatibility with CommitID.
* @readonly
*/ get baseID() {

@@ -161,2 +160,3 @@ return new StreamID(this._type, this._cid);

* StreamId(k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws)
* @internal
*/ [Symbol.for('nodejs.util.inspect.custom')]() {

@@ -167,2 +167,3 @@ return `StreamID(${this.toString()})`;

* String representation of StreamID.
* @internal
*/ [Symbol.toPrimitive]() {

@@ -169,0 +170,0 @@ return this.toString();

@@ -8,7 +8,12 @@ import * as codec from '@ipld/dag-cbor';

type DigestCode = typeof sha256.code;
/** @internal */
export declare function createCID<T = unknown>(value: T): CID<T, CodecCode, DigestCode, 1>;
/** @internal */
export declare function getCodeByName(name: StreamTypeName): StreamTypeCode;
/** @internal */
export declare function getNameByCode(code: StreamTypeCode): StreamTypeName;
/** @internal */
export declare function randomCID(): CID;
/** @internal */
export declare function randomStreamID(type?: StreamType): StreamID;
export {};

@@ -7,3 +7,3 @@ import * as codec from '@ipld/dag-cbor';

import { StreamID } from './stream-id.js';
export function createCID(value) {
/** @internal */ export function createCID(value) {
const bytes = codec.encode(value);

@@ -14,3 +14,3 @@ // digest call is synchronous, no need to await

}
export function getCodeByName(name) {
/** @internal */ export function getCodeByName(name) {
const index = STREAM_TYPES[name];

@@ -22,3 +22,3 @@ if (index == null) {

}
export function getNameByCode(code) {
/** @internal */ export function getNameByCode(code) {
for (const [name, value] of Object.entries(STREAM_TYPES)){

@@ -31,8 +31,8 @@ if (value === code) {

}
export function randomCID() {
/** @internal */ export function randomCID() {
const randomBytes = globalThis.crypto.getRandomValues(new Uint8Array(32));
return CID.createV1(codec.code, create(sha256.code, randomBytes));
}
export function randomStreamID(type = 0) {
/** @internal */ export function randomStreamID(type = 0) {
return new StreamID(type, randomCID());
}
{
"name": "@ceramic-sdk/identifiers",
"version": "0.1.0",
"version": "0.2.0",
"author": "3Box Labs",

@@ -5,0 +5,0 @@ "license": "(Apache-2.0 OR MIT)",

# Ceramic identifiers
Ceramic streams and commits identifiers
## Installation
```sh
npm install @ceramic-sdk/identifiers
```
## Documentation
[API reference](https://github.com/ceramicstudio/ceramic-sdk/tree/main/docs/@ceramic-sdk/identifiers)
## License
Dual licensed under MIT and Apache 2
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc