Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: align CID/Link API with multiformats PR #47

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 14 additions & 9 deletions src/ucan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export interface UCANOptions<
export type Proof<
C extends Capability = Capability,
A extends number = number
> = Link<Model<C>, 1, typeof CBOR_CODE, A> | Link<JWT<C>, 1, typeof RAW_CODE, A>
> = Link<Model<C>, typeof CBOR_CODE, A> | Link<JWT<C>, typeof RAW_CODE, A>

/**
* Represents an IPLD block (including its CID) that can be decoded to data of type `T`.
Expand All @@ -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<T>
cid: Link<T, 1, C, A>
cid: Link<T, C, A, V>
}

/**
Expand Down Expand Up @@ -221,6 +222,8 @@ export type DID<T = unknown> = ToString<T, `did:${string}`>
*/
export interface DIDView extends ByteView<DID>, Identity {}

export type CIDVersion = 0 | 1

/**
* Represents an IPLD link to a specific data of type `T`.
*
Expand All @@ -232,10 +235,10 @@ export interface DIDView extends ByteView<DID>, Identity {}

export interface Link<
T extends unknown = unknown,
V extends 0 | 1 = 0 | 1,
C extends number = number,
A extends number = number
> extends CID<V, C, A>,
A extends number = number,
V extends CIDVersion = 1
> extends CID<C, A, V>,
Phantom<T> {}

/**
Expand All @@ -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<A>
readonly bytes: Uint8Array

// readonly asCID: this

toString<Prefix extends string>(encoder?: MultibaseEncoder<Prefix>): string
}