1- import { ResolverOptions , DIDResolutionResult , ResolverRegistry , Resolver } from 'did-resolver'
1+ import { ResolverOptions , DIDResolutionResult , ResolverRegistry , Resolver } from 'did-resolver'
22import { createJWE , JWE , verifyJWS , resolveX25519Encrypters } from 'did-jwt'
33import { encodePayload , prepareCleartext , decodeCleartext } from 'dag-jose-utils'
44import { RPCClient } from 'rpc-utils'
55import { CID } from 'multiformats/cid'
66import { CacaoBlock , Cacao , Verifiers } from '@didtools/cacao'
77import { getEIP191Verifier } from '@didtools/pkh-ethereum'
8- import type { DagJWS , GeneralJWS } from '@didtools/codecs'
8+ import type { DagJWS , GeneralJWS } from '@didtools/codecs'
99import type { DIDProvider , DIDProviderClient } from './types.js'
1010import {
1111 fromDagJWS ,
@@ -113,8 +113,6 @@ function isResolver(resolver: Resolver | ResolverRegistry): resolver is Resolver
113113 return 'registry' in resolver && 'cache' in resolver
114114}
115115
116-
117-
118116/**
119117 * Interact with DIDs.
120118 */
@@ -263,7 +261,10 @@ export class DID {
263261 * @param options
264262 * @param payload
265263 */
266- async requestJWS < T extends string | Record < string , any > > ( options : CreateJWSOptions , payload : T ) : Promise < GeneralJWS > {
264+ async requestJWS < T extends string | Record < string , any > > (
265+ options : CreateJWSOptions ,
266+ payload : T
267+ ) : Promise < GeneralJWS > {
267268 if ( this . _id == null ) throw new Error ( 'DID is not authenticated' )
268269 if ( this . _client == null ) throw new Error ( 'No provider available' )
269270 const { jws } = await this . _client . request ( 'did_createJWS' , {
@@ -282,8 +283,8 @@ export class DID {
282283 * @param options Optional parameters
283284 */
284285 async createJWS < T extends string | Record < string , any > > (
285- payload : T ,
286- options : CreateJWSOptions = { }
286+ payload : T ,
287+ options : CreateJWSOptions = { }
287288 ) : Promise < DagJWS > {
288289 return await createJWSUsing ( {
289290 capability : this . _capability ,
@@ -405,9 +406,9 @@ export class DID {
405406}
406407
407408export type VerifyJWSParameters = {
408- resolve : ( url : string ) => Promise < DIDResolutionResult > ,
409- jws : string | DagJWS ,
410- options ?: VerifyJWSOptions ,
409+ resolve : ( url : string ) => Promise < DIDResolutionResult >
410+ jws : string | DagJWS
411+ options ?: VerifyJWSOptions
411412}
412413
413414export async function verifyJWSUsing ( params : VerifyJWSParameters ) : Promise < VerifyJWSResult > {
@@ -424,9 +425,7 @@ export async function verifyJWSUsing(params: VerifyJWSParameters): Promise<Verif
424425 if ( nextUpdate ) {
425426 // This version of the DID document has been revoked. Check if the JWS
426427 // was signed before the revocation happened.
427- const phaseOutMS = options . revocationPhaseOutSecs
428- ? options . revocationPhaseOutSecs * 1000
429- : 0
428+ const phaseOutMS = options . revocationPhaseOutSecs ? options . revocationPhaseOutSecs * 1000 : 0
430429 const revocationTime = new Date ( nextUpdate ) . valueOf ( ) + phaseOutMS
431430 const isEarlier = options . atTime && options . atTime . getTime ( ) < revocationTime
432431 const isLater = ! isEarlier
@@ -444,9 +443,9 @@ export async function verifyJWSUsing(params: VerifyJWSParameters): Promise<Verif
444443
445444 const signerDid = didResolutionResult . didDocument ?. id
446445 if (
447- options . issuer &&
448- options . issuer === options . capability ?. p . iss &&
449- signerDid === options . capability . p . aud
446+ options . issuer &&
447+ options . issuer === options . capability ?. p . iss &&
448+ signerDid === options . capability . p . aud
450449 ) {
451450 if ( ! options . verifiers ) throw new Error ( 'Registered verifiers needed for CACAO' )
452451 await Cacao . verify ( options . capability , {
@@ -462,9 +461,9 @@ export async function verifyJWSUsing(params: VerifyJWSParameters): Promise<Verif
462461 const controllers = extractControllers ( controllerProperty )
463462
464463 if (
465- options . capability ?. s &&
466- options . capability . p . aud === signerDid &&
467- controllers . includes ( options . capability . p . iss )
464+ options . capability ?. s &&
465+ options . capability . p . aud === signerDid &&
466+ controllers . includes ( options . capability . p . iss )
468467 ) {
469468 await Cacao . verify ( options . capability , {
470469 atTime : options . atTime ? options . atTime : undefined ,
@@ -481,7 +480,7 @@ export async function verifyJWSUsing(params: VerifyJWSParameters): Promise<Verif
481480
482481 const publicKeys = didResolutionResult . didDocument ?. verificationMethod || [ ]
483482 // verifyJWS will throw an error if the signature is invalid
484- await verifyJWS ( jws , publicKeys )
483+ verifyJWS ( jws , publicKeys )
485484 let payload
486485 try {
487486 payload = base64urlToJSON ( jws . split ( '.' ) [ 1 ] )
@@ -492,14 +491,14 @@ export async function verifyJWSUsing(params: VerifyJWSParameters): Promise<Verif
492491}
493492
494493export type CreateDagJWSUsingParameters = {
495- capability ?: Cacao ,
496- payload : Record < string , any > ,
497- options : CreateJWSOptions ,
498- request : ( options : CreateJWSOptions , payload : string ) => Promise < DagJWS > ,
494+ capability ?: Cacao
495+ payload : Record < string , any >
496+ options : CreateJWSOptions
497+ request : ( options : CreateJWSOptions , payload : string ) => Promise < DagJWS >
499498}
500499
501500export async function createDagJWSUsing (
502- params : CreateDagJWSUsingParameters ,
501+ params : CreateDagJWSUsingParameters
503502) : Promise < DagJWSResult > {
504503 const { cid, linkedBlock } = await encodePayload ( params . payload )
505504 const payloadCid = encodeBase64Url ( cid . bytes )
@@ -514,7 +513,7 @@ export async function createDagJWSUsing(
514513 const compatibleCID = CID . asCID ( cid )
515514 if ( ! compatibleCID ) {
516515 throw new Error (
517- 'CID of the JWS cannot be set to the encoded payload cid as they are incompatible'
516+ 'CID of the JWS cannot be set to the encoded payload cid as they are incompatible'
518517 )
519518 }
520519 jws . link = compatibleCID
@@ -527,10 +526,10 @@ export async function createDagJWSUsing(
527526}
528527
529528export type CreateJWSUsingParameters < T extends string | Record < string , any > > = {
530- capability ?: Cacao ,
531- payload : T ,
532- options : CreateJWSOptions ,
533- request : ( options : CreateJWSOptions , payload : T ) => Promise < DagJWS > ,
529+ capability ?: Cacao
530+ payload : T
531+ options : CreateJWSOptions
532+ request : ( options : CreateJWSOptions , payload : T ) => Promise < DagJWS >
534533}
535534
536535export async function createJWSUsing < T extends string | Record < string , any > > (
@@ -545,7 +544,7 @@ export async function createJWSUsing<T extends string | Record<string, any>>(
545544 const capCID = CID . asCID ( cacaoBlock . cid )
546545 if ( ! capCID ) {
547546 throw new Error (
548- `Capability CID of the JWS cannot be set to the capability payload cid as they are incompatible`
547+ `Capability CID of the JWS cannot be set to the capability payload cid as they are incompatible`
549548 )
550549 }
551550 params . options . protected = params . options . protected || { }
0 commit comments