@ipld/dag-ucan
Advanced tools
Comparing version 1.2.2-beta to 1.2.3-beta
export const name: "dag-ucan"; | ||
export const code: 85; | ||
export function encode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(ucan: UCAN.RAW<C>): UCAN.ByteView<UCAN.JWT<C>>; | ||
export function decode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(bytes: UCAN.ByteView<UCAN.JWT<C>>): UCAN.View<C>; | ||
export function encode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(ucan: UCAN.RAW<C>): UCAN.ByteView<UCAN.RAW<C>>; | ||
export function decode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(bytes: UCAN.RAW<C> | UCAN.ByteView<UCAN.RAW<C>>): UCAN.JWTView<C>; | ||
import * as UCAN from "../ucan.js"; | ||
import * as RAW from "multiformats/codecs/raw"; | ||
import * as View from "../view.js"; | ||
//# sourceMappingURL=raw.d.ts.map |
@@ -8,2 +8,3 @@ export const ED25519: 237; | ||
export function encode(bytes: Uint8Array): UCAN.ByteView<UCAN.DID>; | ||
export function from(input: UCAN.ByteView<UCAN.DID> | UCAN.DID): UCAN.DIDView; | ||
export type Code = typeof ED25519 | typeof RSA; | ||
@@ -10,0 +11,0 @@ import * as UCAN from "./ucan.js"; |
@@ -7,12 +7,12 @@ export * from "./ucan.js"; | ||
export const code: typeof CBOR.code | typeof RAW.code; | ||
export function encode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(ucan: UCAN.UCAN<C>): UCAN.ByteView<UCAN.Model<C>> | UCAN.ByteView<UCAN.JWT<C>>; | ||
export function decode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(bytes: UCAN.ByteView<UCAN.Model<C>> | UCAN.ByteView<UCAN.JWT<C>>): UCAN.View<C>; | ||
export function encode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(ucan: UCAN.UCAN<C>): UCAN.ByteView<UCAN.UCAN<C>>; | ||
export function decode<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(bytes: UCAN.ByteView<UCAN.UCAN<C>>): UCAN.View<C>; | ||
export function link<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(ucan: UCAN.UCAN<C>, options?: { | ||
hasher?: UCAN.MultihashHasher<number> | undefined; | ||
} | undefined): Promise<CID & UCAN.Proof<C, number>>; | ||
export function write<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>, A extends number = 18>(data: UCAN.UCAN<C>, { hasher }?: { | ||
} | undefined): Promise<UCAN.Proof<C, number> & CID>; | ||
export function write<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>, A extends number = number>(data: UCAN.UCAN<C>, { hasher }?: { | ||
hasher?: UCAN.MultihashHasher<A> | undefined; | ||
} | undefined): Promise<{ | ||
cid: CID & UCAN.Proof<C, A>; | ||
bytes: UCAN.ByteView<UCAN.JWT<C>> | UCAN.ByteView<UCAN.Model<C>>; | ||
cid: UCAN.Proof<C, number> & CID; | ||
bytes: UCAN.ByteView<UCAN.UCAN<C>>; | ||
data: UCAN.UCAN<C>; | ||
@@ -19,0 +19,0 @@ }>; |
@@ -67,6 +67,10 @@ import type { MultihashDigest, MultihashHasher } from "multiformats/hashes/interface"; | ||
} | ||
export interface RAW<C extends Capability = Capability> extends Model<C>, ByteView<JWT<C>> { | ||
export interface RAW<C extends Capability = Capability> extends ByteView<JWT<C>> { | ||
} | ||
export interface JWTView<C extends Capability = Capability> extends ByteView<JWT<C>>, View<C> { | ||
} | ||
export interface View<C extends Capability = Capability> extends Model<C> { | ||
readonly model: Model<C>; | ||
issuer: DIDView; | ||
audience: DIDView; | ||
} | ||
@@ -73,0 +77,0 @@ export interface UCANOptions<C extends Capability = Capability, A extends number = number> { |
export function cbor<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(data: UCAN.Model<C>): UCAN.View<C>; | ||
export function jwt<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(model: UCAN.Model<C>, bytes: UCAN.ByteView<UCAN.JWT<C>>): UCAN.View<C>; | ||
export function jwt<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>>(model: UCAN.Model<C>, bytes: UCAN.RAW<C>): UCAN.JWTView<C>; | ||
import * as UCAN from "./ucan.js"; | ||
@@ -16,4 +16,4 @@ /** | ||
get version(): `${number}.${number}.${number}`; | ||
get issuer(): UCAN.ByteView<UCAN.DID<unknown>>; | ||
get audience(): UCAN.ByteView<UCAN.DID<unknown>>; | ||
get issuer(): UCAN.DIDView; | ||
get audience(): UCAN.DIDView; | ||
/** | ||
@@ -45,3 +45,51 @@ * @returns {C[]} | ||
} | ||
import * as RAW from "multiformats/codecs/raw"; | ||
/** | ||
* @template {UCAN.Capability} C | ||
* @implements {UCAN.JWTView<C>} | ||
*/ | ||
declare class JWTView<C extends UCAN.Capability<UCAN.Ability, `${string}:${string}`>> extends Uint8Array implements UCAN.JWTView<C> { | ||
/** | ||
* @param {UCAN.Model<C>} model | ||
* @param {object} bytes | ||
* @param {ArrayBuffer} bytes.buffer | ||
* @param {number} [bytes.byteOffset] | ||
* @param {number} [bytes.byteLength] | ||
*/ | ||
constructor(model: UCAN.Model<C>, { buffer, byteOffset, byteLength }: { | ||
buffer: ArrayBuffer; | ||
byteOffset?: number | undefined; | ||
byteLength?: number | undefined; | ||
}); | ||
model: UCAN.Model<C>; | ||
get version(): `${number}.${number}.${number}`; | ||
get issuer(): UCAN.DIDView; | ||
get audience(): UCAN.DIDView; | ||
/** | ||
* @returns {C[]} | ||
*/ | ||
get capabilities(): C[]; | ||
/** | ||
* @returns {number} | ||
*/ | ||
get expiration(): number; | ||
/** | ||
* @returns {undefined|number} | ||
*/ | ||
get notBefore(): number | undefined; | ||
/** | ||
* @returns {undefined|string} | ||
*/ | ||
get nonce(): string | undefined; | ||
/** | ||
* @returns {UCAN.Fact[]} | ||
*/ | ||
get facts(): UCAN.Fact[]; | ||
/** | ||
* @returns {UCAN.Proof[]} | ||
*/ | ||
get proofs(): UCAN.Proof<UCAN.Capability<UCAN.Ability, `${string}:${string}`>, number>[]; | ||
get signature(): UCAN.Signature<C>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=view.d.ts.map |
{ | ||
"name": "@ipld/dag-ucan", | ||
"description": "UCAN codec for IPLD", | ||
"version": "1.2.2-beta", | ||
"version": "1.2.3-beta", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "UCAN", |
@@ -11,8 +11,8 @@ import * as UCAN from "../ucan.js" | ||
/** | ||
* Encodes given UCAN (in either JWT representation) and encodes it into | ||
* corresponding bytes representation. | ||
* Takes UCAN in RAW JWT representation and encodes it into binary | ||
* format. | ||
* | ||
* @template {UCAN.Capability} C | ||
* @param {UCAN.RAW<C>} ucan | ||
* @returns {UCAN.ByteView<UCAN.JWT<C>>} | ||
* @returns {UCAN.ByteView<UCAN.RAW<C>>} | ||
*/ | ||
@@ -24,5 +24,9 @@ export const encode = ucan => | ||
* @template {UCAN.Capability} C | ||
* @param {UCAN.ByteView<UCAN.JWT<C>>} bytes | ||
* @returns {UCAN.View<C>} | ||
* @param {UCAN.ByteView<UCAN.RAW<C>>|UCAN.RAW<C>} bytes | ||
* @returns {UCAN.JWTView<C>} | ||
*/ | ||
export const decode = bytes => View.jwt(Parser.parse(UTF8.decode(bytes)), bytes) | ||
export const decode = bytes => | ||
View.jwt( | ||
Parser.parse(UTF8.decode(/** @type {UCAN.RAW<C>} */ (bytes))), | ||
/** @type {UCAN.RAW<C>} */ (bytes) | ||
) |
@@ -66,2 +66,16 @@ import * as UCAN from "./ucan.js" | ||
/** | ||
* @param {UCAN.ByteView<UCAN.DID>|UCAN.DID} input | ||
* @returns {UCAN.DIDView} | ||
*/ | ||
export const from = input => { | ||
if (input instanceof DID) { | ||
return input | ||
} else if (input instanceof Uint8Array) { | ||
return decode(input) | ||
} else { | ||
return parse(input) | ||
} | ||
} | ||
class DID extends Uint8Array { | ||
@@ -68,0 +82,0 @@ did() { |
@@ -27,3 +27,3 @@ import * as UCAN from "./ucan.js" | ||
* @param {UCAN.UCAN<C>} ucan | ||
* @returns {UCAN.ByteView<UCAN.Model<C>>|UCAN.ByteView<UCAN.JWT<C>>} | ||
* @returns {UCAN.ByteView<UCAN.UCAN<C>>} | ||
*/ | ||
@@ -40,3 +40,3 @@ export const encode = ucan => | ||
* @template {UCAN.Capability} C | ||
* @param {UCAN.ByteView<UCAN.Model<C>>|UCAN.ByteView<UCAN.JWT<C>>} bytes | ||
* @param {UCAN.ByteView<UCAN.UCAN<C>>} bytes | ||
* @returns {UCAN.View<C>} | ||
@@ -69,5 +69,6 @@ */ | ||
* @template {UCAN.Capability} C | ||
* @template {number} [A=typeof sha256.code] | ||
* @template {number} [A=number] | ||
* @param {UCAN.UCAN<C>} data | ||
* @param {{hasher?: UCAN.MultihashHasher<A>}} [options] | ||
* @returns {Promise<{cid:UCAN.Proof<C> & CID, bytes: UCAN.ByteView<UCAN.UCAN<C>>, data: UCAN.UCAN<C> }>} | ||
*/ | ||
@@ -74,0 +75,0 @@ export const write = async ( |
@@ -69,11 +69,2 @@ import type { | ||
// export interface Data<C extends Capability = Capability> { | ||
// readonly header: Header | ||
// readonly body: Body<C> | ||
// readonly signature: Signature<[Header, Body<C>]> | ||
// } | ||
// export interface CBOR<C extends Capability = Capability> extends Data<C> { | ||
// readonly code: typeof code | ||
// } | ||
export interface Input<C extends Capability = Capability> { | ||
@@ -96,7 +87,13 @@ version: Version | ||
export interface RAW<C extends Capability = Capability> | ||
extends Model<C>, | ||
ByteView<JWT<C>> {} | ||
extends ByteView<JWT<C>> {} | ||
export interface JWTView<C extends Capability = Capability> | ||
extends ByteView<JWT<C>>, | ||
View<C> {} | ||
export interface View<C extends Capability = Capability> extends Model<C> { | ||
readonly model: Model<C> | ||
issuer: DIDView | ||
audience: DIDView | ||
} | ||
@@ -103,0 +100,0 @@ |
@@ -23,7 +23,7 @@ import * as UCAN from "./ucan.js" | ||
get issuer() { | ||
return this.model.issuer | ||
return DID.from(this.model.issuer) | ||
} | ||
get audience() { | ||
return this.model.audience | ||
return DID.from(this.model.audience) | ||
} | ||
@@ -82,3 +82,3 @@ | ||
* @template {UCAN.Capability} C | ||
* @implements {UCAN.View<C>} | ||
* @implements {UCAN.JWTView<C>} | ||
*/ | ||
@@ -106,7 +106,7 @@ class JWTView extends Uint8Array { | ||
get issuer() { | ||
return this.model.issuer | ||
return DID.from(this.model.issuer) | ||
} | ||
get audience() { | ||
return this.model.audience | ||
return DID.from(this.model.audience) | ||
} | ||
@@ -173,5 +173,5 @@ | ||
* @param {UCAN.Model<C>} model | ||
* @param {UCAN.ByteView<UCAN.JWT<C>>} bytes | ||
* @returns {UCAN.View<C>} | ||
* @param {UCAN.RAW<C>} bytes | ||
* @returns {UCAN.JWTView<C>} | ||
*/ | ||
export const jwt = (model, bytes) => new JWTView(model, bytes) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64313
1536