From 8079eb86d33fc5b4c760e334b0d5500d81844d6d Mon Sep 17 00:00:00 2001 From: Nico Krause Date: Wed, 11 Feb 2026 11:43:50 +0100 Subject: [PATCH] chore: apply prettier formatting across workspace files --- .github/workflows/release.yml | 3 +- packages/client/test/services/util.js | 6 ++-- packages/core/src/schema/did.js | 2 +- packages/core/test/cbor.spec.js | 2 +- packages/core/test/delegation.spec.js | 12 ++++---- packages/core/test/extra-schema.spec.js | 41 +++++++++++++++++++------ packages/core/test/utils.js | 2 +- packages/interface/src/lib.ts | 8 +++-- packages/server/src/handler.js | 3 +- packages/server/src/server.js | 11 ++++--- packages/server/test/server.spec.js | 30 ++++++++++-------- packages/transport/src/http.js | 5 ++- packages/transport/test/https.spec.js | 7 +++-- packages/transport/test/util.js | 2 +- packages/validator/src/error.js | 2 +- packages/validator/src/lib.js | 14 ++++----- packages/validator/test/session.spec.js | 23 ++++++++------ 17 files changed, 108 insertions(+), 65 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37a8a29d..7c6865da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,7 @@ jobs: if: ${{needs.release.outputs.releases_created}} runs-on: ubuntu-latest permissions: - id-token: write # Required for OIDC + id-token: write # Required for OIDC steps: # The logic below handles the npm publication: - name: Checkout @@ -56,4 +56,3 @@ jobs: - name: Publish run: pnpm -r publish --access=public - diff --git a/packages/client/test/services/util.js b/packages/client/test/services/util.js index 9ec88e01..9b9f7c02 100644 --- a/packages/client/test/services/util.js +++ b/packages/client/test/services/util.js @@ -1,6 +1,6 @@ export const ok = /** @type {(...args:Args) => Args extends [T] ? {ok:true, value:T extends undefined ? null : T} : {ok:true, value:null}}} */ ( - (value) => (value == undefined ? Ok : { ok: true, value }) + value => (value == undefined ? Ok : { ok: true, value }) ) const Ok = { ok: true, value: null } @@ -9,13 +9,13 @@ const Ok = { ok: true, value: null } * @param {T} value * @returns {T} */ -export const the = (value) => value +export const the = value => value /** * @param {string} reason * @returns {never} */ -export const panic = (reason) => { +export const panic = reason => { throw new Error(reason) } diff --git a/packages/core/src/schema/did.js b/packages/core/src/schema/did.js index 6853eb25..a8d8b92b 100644 --- a/packages/core/src/schema/did.js +++ b/packages/core/src/schema/did.js @@ -68,7 +68,7 @@ class DIDBytesSchema extends Schema.API { return Schema.error(`Expected a ${prefix} but got "${did}" instead`) } else { return { ok: /** @type {API.DID} */ (did) } - } + } } } diff --git a/packages/core/test/cbor.spec.js b/packages/core/test/cbor.spec.js index bf870ae8..9110a9e9 100644 --- a/packages/core/test/cbor.spec.js +++ b/packages/core/test/cbor.spec.js @@ -69,7 +69,7 @@ test('encode / decode', async () => { const o = {} const data = { a: o, - b: o + b: o, } assert.doesNotThrow(() => transcode(data)) diff --git a/packages/core/test/delegation.spec.js b/packages/core/test/delegation.spec.js index 84576149..4b612ad4 100644 --- a/packages/core/test/delegation.spec.js +++ b/packages/core/test/delegation.spec.js @@ -437,8 +437,8 @@ test('delegation.attach block in capabiliy', async () => { can: 'store/add', with: alice.did(), nb: { - inlineBlock: block.cid.link() - } + inlineBlock: block.cid.link(), + }, }, ], }) @@ -467,8 +467,8 @@ test('delegation.attach block in facts', async () => { facts: [ { [`${block.cid.link()}`]: block.cid.link() }, // @ts-expect-error Link has fact entry - block.cid.link() - ] + block.cid.link(), + ], }) ucan.attach(block) @@ -488,11 +488,11 @@ test('delegation.attach fails to attach block with not attached link', async () capabilities: [ { can: 'store/add', - with: alice.did() + with: alice.did(), }, ], }) const block = await getBlock({ test: 'inlineBlock' }) assert.throws(() => ucan.attach(block)) -}) \ No newline at end of file +}) diff --git a/packages/core/test/extra-schema.spec.js b/packages/core/test/extra-schema.spec.js index a00bffdd..4132b18d 100644 --- a/packages/core/test/extra-schema.spec.js +++ b/packages/core/test/extra-schema.spec.js @@ -418,7 +418,11 @@ test('URI.from', () => { Uint8Array.from([1, 2, 3]), /Unable to parse bytes as did:/, ], - [{ method: 'echo' }, DIDTools.parse('did:echo:hello'), { ok: 'did:echo:hello' }], + [ + { method: 'echo' }, + DIDTools.parse('did:echo:hello'), + { ok: 'did:echo:hello' }, + ], [ { method: 'foo' }, DIDTools.parse('did:echo:hello'), @@ -500,11 +504,16 @@ test('URI.from', () => { [undefined, /Expected value of type Uint8Array instead got undefined/], [null, /Expected value of type Uint8Array instead got null/], [Uint8Array.from([1, 2, 3]), /Unable to decode bytes as DID:/], - [DIDTools.parse('did:echo:1'), { ok: new Uint8Array([157, 26, 101, 99, 104, 111, 58, 49]) }], + [ + DIDTools.parse('did:echo:1'), + { ok: new Uint8Array([157, 26, 101, 99, 104, 111, 58, 49]) }, + ], ] for (const [input, out] of dataset) { - test(`Principal.read(${input == null ? input : `Uint8Array([${input}])`})`, () => { + test(`Principal.read(${ + input == null ? input : `Uint8Array([${input}])` + })`, () => { matchResult(Principal.read(input), out) }) } @@ -531,7 +540,11 @@ test('URI.from', () => { [ { method: 'echo' }, DIDTools.parse('did:echo:hello'), - { ok: new Uint8Array([157, 26, 101, 99, 104, 111, 58, 104, 101, 108, 108, 111]) } + { + ok: new Uint8Array([ + 157, 26, 101, 99, 104, 111, 58, 104, 101, 108, 108, 111, + ]), + }, ], [ { method: 'foo' }, @@ -541,7 +554,9 @@ test('URI.from', () => { ] for (const [options, input, out] of dataset) { - test(`Principal.match({ method: ${options.method == null ? options.method : `"${options.method}"`} }).read(${input == null ? input : `Uint8Array([${input}])`})`, () => { + test(`Principal.match({ method: ${ + options.method == null ? options.method : `"${options.method}"` + } }).read(${input == null ? input : `Uint8Array([${input}])`})`, () => { matchResult(Principal.match(options).read(input), out) }) } @@ -555,7 +570,7 @@ test('URI.from', () => { [ {}, DIDTools.parse('did:echo:bar'), - { ok: new Uint8Array([157, 26, 101, 99, 104, 111, 58, 98, 97, 114]) } + { ok: new Uint8Array([157, 26, 101, 99, 104, 111, 58, 98, 97, 114]) }, ], [{ method: 'echo' }, undefined, { ok: undefined }], [ @@ -576,8 +591,14 @@ test('URI.from', () => { ] for (const [options, input, out] of dataset) { - test(`Principal.match({ method: ${options.method == null ? options.method : `"${options.method}"`} }).optional().read(${input == null ? input : `Uint8Array([${input}])`})`, () => { - const schema = options.method ? Principal.match(options) : Principal.principal() + test(`Principal.match({ method: ${ + options.method == null ? options.method : `"${options.method}"` + } }).optional().read(${ + input == null ? input : `Uint8Array([${input}])` + })`, () => { + const schema = options.method + ? Principal.match(options) + : Principal.principal() matchResult(schema.optional().read(input), out) }) } @@ -596,7 +617,9 @@ test('URI.from', () => { ], ] for (const [did, errorExpectation] of dataset) { - test(`Principal.from(${did == null ? did : `Uint8Array([${did}])`})`, () => { + test(`Principal.from(${ + did == null ? did : `Uint8Array([${did}])` + })`, () => { let error try { Principal.from(did) diff --git a/packages/core/test/utils.js b/packages/core/test/utils.js index e0d105ba..7324a739 100644 --- a/packages/core/test/utils.js +++ b/packages/core/test/utils.js @@ -9,6 +9,6 @@ export async function getBlock(value) { return await Block.encode({ value, codec, - hasher + hasher, }) } diff --git a/packages/interface/src/lib.ts b/packages/interface/src/lib.ts index c4b7b905..3fa6ba18 100644 --- a/packages/interface/src/lib.ts +++ b/packages/interface/src/lib.ts @@ -45,7 +45,7 @@ import { Revoked, InferCapability, Authorization, - Reader + Reader, } from './capability.js' import type * as Transport from './transport.js' import type { Tuple, Block } from './transport.js' @@ -978,7 +978,9 @@ export interface HTTPError { /** * Options for UCAN validation. */ -export interface ValidatorOptions extends PrincipalResolver, Partial { +export interface ValidatorOptions + extends PrincipalResolver, + Partial { /** * Schema allowing invocations to be accepted for audiences other than the * service itself. @@ -1092,7 +1094,7 @@ export interface PrincipalParser { */ export interface PrincipalResolver { resolveDIDKey?: ( - did: UCAN.DID, + did: UCAN.DID ) => Await> } diff --git a/packages/server/src/handler.js b/packages/server/src/handler.js index 2d97ffc3..1accd141 100644 --- a/packages/server/src/handler.js +++ b/packages/server/src/handler.js @@ -52,7 +52,8 @@ export const provideAdvanced = // If audience schema is not provided we expect the audience to match // the server id. Users could pass `schema.string()` if they want to accept // any audience. - const audienceSchema = audience || options.audience || Schema.literal(options.id.did()) + const audienceSchema = + audience || options.audience || Schema.literal(options.id.did()) const result = audienceSchema.read(invocation.audience.did()) if (result.error) { return { error: new InvalidAudience({ cause: result.error }) } diff --git a/packages/server/src/server.js b/packages/server/src/server.js index 43e71a0b..d7a06e46 100644 --- a/packages/server/src/server.js +++ b/packages/server/src/server.js @@ -79,15 +79,18 @@ export const handle = async (server, request) => { } } else { const { encoder, decoder } = selection.ok - let message; + let message try { message = await decoder.decode(request) } catch (err) { - const errorMessage = err instanceof Error ? err.message : 'Unable to decode request' + const errorMessage = + err instanceof Error ? err.message : 'Unable to decode request' return { status: 400, headers: { 'Content-Type': 'text/plain' }, - body: new TextEncoder().encode(`Bad request: Malformed payload - ${errorMessage}`), + body: new TextEncoder().encode( + `Bad request: Malformed payload - ${errorMessage}` + ), } } const result = await execute(message, server) @@ -198,4 +201,4 @@ export const resolve = (service, path) => { } } return target -} \ No newline at end of file +} diff --git a/packages/server/test/server.spec.js b/packages/server/test/server.spec.js index 17f43b91..cc20f3e3 100644 --- a/packages/server/test/server.spec.js +++ b/packages/server/test/server.spec.js @@ -348,9 +348,10 @@ test('did:web principal resolve', async () => { }, codec: CAR.inbound, id: w3, - resolveDIDKey: did => did === account.did() - ? Server.ok([bob.did()]) - : Server.error(new DIDResolutionError(did)), + resolveDIDKey: did => + did === account.did() + ? Server.ok([bob.did()]) + : Server.error(new DIDResolutionError(did)), validateAuthorization: () => ({ ok: {} }), }) @@ -402,7 +403,7 @@ test('alternative audience', async () => { id: service, audience: Schema.or( Schema.literal('did:web:web3.storage'), - Schema.literal(alias.did()), + Schema.literal(alias.did()) ), validateAuthorization: () => ({ ok: {} }), }) @@ -604,9 +605,9 @@ test('should return 400 Bad Request for malformed payloads', async () => { const malformedRequest = { headers: { 'content-type': CAR.contentType, - 'accept': CAR.contentType + accept: CAR.contentType, }, - body: new Uint8Array([1, 2, 3]) + body: new Uint8Array([1, 2, 3]), } const response = await server.request(malformedRequest) @@ -628,10 +629,10 @@ test('should return 400 Bad Request for non-Error decoder failures', async () => decoder: { decode: async () => { throw 'Not an Error instance' - } - } - } - }) + }, + }, + }, + }), }, validateAuthorization: () => ({ ok: {} }), }) @@ -639,9 +640,9 @@ test('should return 400 Bad Request for non-Error decoder failures', async () => const malformedRequest = { headers: { 'content-type': CAR.contentType, - 'accept': CAR.contentType + accept: CAR.contentType, }, - body: new Uint8Array([1, 2, 3]) + body: new Uint8Array([1, 2, 3]), } const response = await server.request(malformedRequest) @@ -649,5 +650,8 @@ test('should return 400 Bad Request for non-Error decoder failures', async () => assert.equal(response.status, 400) assert.deepEqual(response.headers, { 'Content-Type': 'text/plain' }) const errorMessage = new TextDecoder().decode(response.body) - assert.match(errorMessage, /Bad request: Malformed payload - Unable to decode request/) + assert.match( + errorMessage, + /Bad request: Malformed payload - Unable to decode request/ + ) }) diff --git a/packages/transport/src/http.js b/packages/transport/src/http.js index b4df7730..5cfce071 100644 --- a/packages/transport/src/http.js +++ b/packages/transport/src/http.js @@ -68,7 +68,10 @@ class Channel { const buffer = response.ok ? await response.arrayBuffer() - : HTTPError.throw(`HTTP Request failed. ${this.method} ${this.url.href} → ${response.status}`, response) + : HTTPError.throw( + `HTTP Request failed. ${this.method} ${this.url.href} → ${response.status}`, + response + ) return { headers: response.headers.entries diff --git a/packages/transport/test/https.spec.js b/packages/transport/test/https.spec.js index fb93c308..0f17f695 100644 --- a/packages/transport/test/https.spec.js +++ b/packages/transport/test/https.spec.js @@ -100,8 +100,11 @@ test('headers from http channel are passed to fetch along with the request heade headers: { 'x-client': 'abc' }, }) - const requestHeaders = { 'x-test': 'test-value', 'content-type': 'text/plain' } - + const requestHeaders = { + 'x-test': 'test-value', + 'content-type': 'text/plain', + } + await channel.request({ headers: requestHeaders, body: UTF8.encode('ping'), diff --git a/packages/transport/test/util.js b/packages/transport/test/util.js index 60df4a58..9c805589 100644 --- a/packages/transport/test/util.js +++ b/packages/transport/test/util.js @@ -3,7 +3,7 @@ * @param {AsyncIterable|Iterable} iterable * @returns {Promise} */ -export const collect = async (iterable) => { +export const collect = async iterable => { const result = [] for await (const item of iterable) { result.push(item) diff --git a/packages/validator/src/error.js b/packages/validator/src/error.js index 9df79130..0712860a 100644 --- a/packages/validator/src/error.js +++ b/packages/validator/src/error.js @@ -334,7 +334,7 @@ export class Unauthorized extends Failure { failedProofs, }) { super() - this.name = /** @type {const} */ ('Unauthorized') + this.name = /** @type {const} */ ('Unauthorized') this.capability = capability this.delegationErrors = delegationErrors this.unknownCapabilities = unknownCapabilities diff --git a/packages/validator/src/lib.js b/packages/validator/src/lib.js index 8f8638a3..4a6f925a 100644 --- a/packages/validator/src/lib.js +++ b/packages/validator/src/lib.js @@ -108,7 +108,7 @@ const resolveProofs = async (proofs, config) => { } } catch (error) { errors.push( - new UnavailableProof(proof, /** @type {Error} */(error)) + new UnavailableProof(proof, /** @type {Error} */ (error)) ) } @@ -175,7 +175,7 @@ const resolveSources = async ({ delegation }, config) => { // track which proof in which capability the are from. for (const capability of proof.capabilities) { sources.push( - /** @type {API.Source} */({ + /** @type {API.Source} */ ({ capability, delegation: proof, }) @@ -263,7 +263,7 @@ export const claim = async ( if (validation.ok) { for (const capability of validation.ok.capabilities.values()) { sources.push( - /** @type {API.Source} */({ + /** @type {API.Source} */ ({ capability, delegation: validation.ok, }) @@ -450,7 +450,7 @@ const validate = async (delegation, proofs, config) => { if (UCAN.isExpired(delegation.data)) { return { error: new Expired( - /** @type {API.Delegation & {expiration: number}} */(delegation) + /** @type {API.Delegation & {expiration: number}} */ (delegation) ), } } @@ -458,7 +458,7 @@ const validate = async (delegation, proofs, config) => { if (UCAN.isTooEarly(delegation.data)) { return { error: new NotValidBefore( - /** @type {API.Delegation & {notBefore: number}} */(delegation) + /** @type {API.Delegation & {notBefore: number}} */ (delegation) ), } } @@ -525,7 +525,7 @@ const verifyAuthorization = async (delegation, proofs, config) => { verificationErrResults.push(verificationResult.error) } } - + // If no verifiers were found, there is no way to verify the signature if (verificationErrResults.length === 0) { return { error: new DIDKeyResolutionError(issuer) } @@ -535,7 +535,7 @@ const verifyAuthorization = async (delegation, proofs, config) => { const combinedMessage = verificationErrResults .map(err => err.message) .join('\n ') - + // @ts-expect-error - both error types have describe method, override it to return the concatenated message combinedError.describe = () => combinedMessage diff --git a/packages/validator/test/session.spec.js b/packages/validator/test/session.spec.js index efdeb32d..b2e2f69a 100644 --- a/packages/validator/test/session.spec.js +++ b/packages/validator/test/session.spec.js @@ -130,8 +130,8 @@ test('validate mailto attested by another service', async () => { await attest.delegate({ issuer: w3, audience: other, - with: w3.did() - }) + with: w3.did(), + }), ], }) @@ -405,7 +405,7 @@ test('fail unknown ucan/attest proof', async () => { return Schema.ok([otherService.toDIDKey()]) } return { error: new DIDKeyResolutionError(did) } - } + }, }) assert.containSubset(result, { @@ -660,7 +660,7 @@ test('fail when no verifiers found', async () => { capability: echo, principal: Verifier, validateAuthorization: () => ({ ok: {} }), - resolveDIDKey: () => ({ ok: [] }) + resolveDIDKey: () => ({ ok: [] }), }) assert.match( @@ -702,7 +702,7 @@ test('succeed with single valid verifier', async () => { capability: echo, principal: Verifier, validateAuthorization: () => ({ ok: {} }), - resolveDIDKey: () => ({ ok: [alice.toDIDKey()] }) + resolveDIDKey: () => ({ ok: [alice.toDIDKey()] }), }) assert.ok(result.ok) @@ -742,7 +742,12 @@ test('succeed with multiple verifiers and one valid', async () => { capability: echo, principal: Verifier, validateAuthorization: () => ({ ok: {} }), - resolveDIDKey: () => ({ ok: [`did:key:${other.did().split(':')[2]}`, `did:key:${alice.did().split(':')[2]}`] }) + resolveDIDKey: () => ({ + ok: [ + `did:key:${other.did().split(':')[2]}`, + `did:key:${alice.did().split(':')[2]}`, + ], + }), }) assert.ok(result.ok) @@ -776,13 +781,13 @@ test('fail with multiple invalid verifiers', async () => { capability: echo, principal: Verifier, validateAuthorization: () => ({ ok: {} }), - resolveDIDKey: (did) => { + resolveDIDKey: did => { if (did === account.did()) { // Return verifiers that don't match the account's actual key return { ok: [other1.toDIDKey(), other2.toDIDKey()] } } return { error: new DIDKeyResolutionError(did) } - } + }, }) console.log('Result:', result) @@ -792,4 +797,4 @@ test('fail with multiple invalid verifiers', async () => { `${result.error}`, /Proof .* does not has a valid signature from did:key:/ ) -}) \ No newline at end of file +})