From 7eb8c3fa872b16a92df69683a89cd3e04d67b122 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 15 Jun 2022 11:45:56 -0700 Subject: [PATCH] feat: align CID/Link API with multiformats PR --- package.json | 4 ++++ src/ucan.ts | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c981019..b665a78 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,10 @@ "types": "./dist/src/lib.d.ts", "import": "./src/lib.js" }, + "./did": { + "types": "./dist/src/did.d.ts", + "import": "./src/did.js" + }, "./src/lib.js": { "types": "./dist/src/lib.d.ts", "import": "./src/lib.js" diff --git a/src/ucan.ts b/src/ucan.ts index 111bace..e738d96 100644 --- a/src/ucan.ts +++ b/src/ucan.ts @@ -162,7 +162,7 @@ export interface UCANOptions< export type Proof< C extends Capability = Capability, A extends number = number -> = Link, 1, typeof CBOR_CODE, A> | Link, 1, typeof RAW_CODE, A> +> = Link, typeof CBOR_CODE, A> | Link, typeof RAW_CODE, A> /** * Represents an IPLD block (including its CID) that can be decoded to data of type `T`. @@ -174,10 +174,11 @@ export type Proof< export interface Block< T extends unknown = unknown, C extends number = number, - A extends number = number + A extends number = number, + V extends CIDVersion = 1 > { bytes: ByteView - cid: Link + cid: Link } /** @@ -221,6 +222,8 @@ export type DID = ToString */ export interface DIDView extends ByteView, Identity {} +export type CIDVersion = 0 | 1 + /** * Represents an IPLD link to a specific data of type `T`. * @@ -232,10 +235,10 @@ export interface DIDView extends ByteView, Identity {} export interface Link< T extends unknown = unknown, - V extends 0 | 1 = 0 | 1, C extends number = number, - A extends number = number -> extends CID, + A extends number = number, + V extends CIDVersion = 1 +> extends CID, Phantom {} /** @@ -249,19 +252,21 @@ export interface Link< * @see https://github.com/multiformats/js-multiformats/pull/161 which will likely * replace this definition once merged. * - * @template V - CID version * @template C - multicodec code corresponding to a codec content was encoded in * @template A - multicodec code corresponding to the hashing algorithm used to derive CID + * @template V - CID version */ export interface CID< - V extends 0 | 1 = 0 | 1, C extends number = number, - A extends number = number + A extends number = number, + V extends CIDVersion = CIDVersion > { readonly version: V readonly code: C readonly multihash: MultihashDigest readonly bytes: Uint8Array + // readonly asCID: this + toString(encoder?: MultibaseEncoder): string }