diff --git a/packages/common/src/index.spec.ts b/packages/common/src/index.spec.ts index d27130164..e203cd12f 100644 --- a/packages/common/src/index.spec.ts +++ b/packages/common/src/index.spec.ts @@ -24,22 +24,22 @@ describe("common", () => { it("has some expected values", () => { assert.deepEqual( [...integerToOctetStringLE(BigInt(256), 5)], - [0, 1, 0, 0, 0] + [0, 1, 0, 0, 0], ); assert.deepEqual( [...integerToOctetStringLE(BigInt(255), 5)], - [255, 0, 0, 0, 0] + [255, 0, 0, 0, 0], ); assert.deepEqual( [ ...integerToOctetStringLE( BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), - 10 + 10, ), ], - [0, 0, 0, 0, 0, 0, 32, 0, 0, 0] + [0, 0, 0, 0, 0, 0, 32, 0, 0, 0], ); }); @@ -49,11 +49,11 @@ describe("common", () => { for (const octetString of arr( numbers, - () => new Uint8Array(arr(bytes, () => Math.floor(Math.random() * 255))) + () => new Uint8Array(arr(bytes, () => Math.floor(Math.random() * 255))), )) { assert.deepEqual( octetString, - integerToOctetStringLE(octetStringToIntegerLE(octetString), bytes) + integerToOctetStringLE(octetStringToIntegerLE(octetString), bytes), ); } }); @@ -63,21 +63,21 @@ describe("common", () => { it("has some expected values", () => { assert.equal( BigInt(256), - octetStringToIntegerLE(new Uint8Array([0, 1, 0])) + octetStringToIntegerLE(new Uint8Array([0, 1, 0])), ); assert.equal( BigInt(255), - octetStringToIntegerLE(new Uint8Array([255, 0, 0, 0])) + octetStringToIntegerLE(new Uint8Array([255, 0, 0, 0])), ); assert.equal( BigInt(256) ** BigInt(3), - octetStringToIntegerLE(new Uint8Array([0, 0, 0, 1, 0])) + octetStringToIntegerLE(new Uint8Array([0, 0, 0, 1, 0])), ); assert.equal( BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), - octetStringToIntegerLE(new Uint8Array([0, 0, 0, 0, 0, 0, 32, 0, 0, 0])) + octetStringToIntegerLE(new Uint8Array([0, 0, 0, 0, 0, 0, 32, 0, 0, 0])), ); }); }); @@ -92,22 +92,22 @@ describe("common", () => { it("has some expected values", () => { assert.deepEqual( [...integerToOctetStringBE(BigInt(256), 5)], - [0, 0, 0, 1, 0] + [0, 0, 0, 1, 0], ); assert.deepEqual( [...integerToOctetStringBE(BigInt(255), 5)], - [0, 0, 0, 0, 255] + [0, 0, 0, 0, 255], ); assert.deepEqual( [ ...integerToOctetStringBE( BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), - 10 + 10, ), ], - [0, 0, 0, 32, 0, 0, 0, 0, 0, 0] + [0, 0, 0, 32, 0, 0, 0, 0, 0, 0], ); }); @@ -117,11 +117,11 @@ describe("common", () => { for (const octetString of arr( numbers, - () => new Uint8Array(arr(bytes, () => Math.floor(Math.random() * 255))) + () => new Uint8Array(arr(bytes, () => Math.floor(Math.random() * 255))), )) { assert.deepEqual( octetString, - integerToOctetStringBE(octetStringToIntegerBE(octetString), bytes) + integerToOctetStringBE(octetStringToIntegerBE(octetString), bytes), ); } }); @@ -131,21 +131,21 @@ describe("common", () => { it("has some expected values", () => { assert.equal( BigInt(256), - octetStringToIntegerBE(new Uint8Array([0, 1, 0])) + octetStringToIntegerBE(new Uint8Array([0, 1, 0])), ); assert.equal( BigInt(255), - octetStringToIntegerBE(new Uint8Array([0, 0, 0, 255])) + octetStringToIntegerBE(new Uint8Array([0, 0, 0, 255])), ); assert.equal( BigInt(256) ** BigInt(3), - octetStringToIntegerBE(new Uint8Array([0, 1, 0, 0, 0])) + octetStringToIntegerBE(new Uint8Array([0, 1, 0, 0, 0])), ); assert.equal( BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), - octetStringToIntegerBE(new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0, 0, 0])) + octetStringToIntegerBE(new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0, 0, 0])), ); }); }); diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 9b759b24f..04b7cbd59 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -5,7 +5,7 @@ export function integerToOctetStringBE(i: bigint, len: number): Uint8Array { const max = 256n ** BigInt(len); if (i >= max) { throw new Error( - `Integer ${i} too large for ${len} byte array (max ${max}).` + `Integer ${i} too large for ${len} byte array (max ${max}).`, ); } const octets = new Uint8Array(len); @@ -21,7 +21,7 @@ export function integerToOctetStringLE(i: bigint, len: number): Uint8Array { const max = 256n ** BigInt(len); if (i >= max) { throw new Error( - `Integer ${i} too large for ${len} byte array (max ${max}).` + `Integer ${i} too large for ${len} byte array (max ${max}).`, ); } const octets = new Uint8Array(len); @@ -37,7 +37,7 @@ export function octetStringToIntegerBE(octetString: Uint8Array): bigint { return octetString.reduceRight( (total, value, index) => total + 256n ** BigInt(octetString.length - index - 1) * BigInt(value), - 0n + 0n, ); } @@ -45,7 +45,7 @@ export function octetStringToIntegerBE(octetString: Uint8Array): bigint { export function octetStringToIntegerLE(octetString: Uint8Array): bigint { return octetString.reduce( (total, value, index) => total + 256n ** BigInt(index) * BigInt(value), - 0n + 0n, ); } diff --git a/packages/dap/src/aggregator.spec.ts b/packages/dap/src/aggregator.spec.ts index 8468d4c07..d80555c3a 100644 --- a/packages/dap/src/aggregator.spec.ts +++ b/packages/dap/src/aggregator.spec.ts @@ -16,7 +16,7 @@ describe("DAP Aggregator", () => { it("should append a trailing slash on construction from a string", () => { const aggregator = new Aggregator( "http://example.com/aggregator", - Role.Leader + Role.Leader, ); assert.equal(aggregator.url.toString(), "http://example.com/aggregator/"); @@ -25,7 +25,7 @@ describe("DAP Aggregator", () => { it("should append a trailing slash on construction from a URL", () => { const aggregator = new Aggregator( new URL("http://example.com/aggregator"), - Role.Leader + Role.Leader, ); assert.equal(aggregator.url.toString(), "http://example.com/aggregator/"); @@ -34,14 +34,14 @@ describe("DAP Aggregator", () => { it("has a convenience method to build helper aggregator", () => { assert.deepEqual( Aggregator.helper("http://example.com"), - new Aggregator("http://example.com", Role.Helper) + new Aggregator("http://example.com", Role.Helper), ); }); it("has a convenience method to build leader aggregator", () => { assert.deepEqual( Aggregator.leader("http://example.com"), - new Aggregator("http://example.com", Role.Leader) + new Aggregator("http://example.com", Role.Leader), ); }); @@ -54,7 +54,7 @@ describe("DAP Aggregator", () => { kem, Kdf.Sha256, Aead.AesGcm128, - Buffer.from(public_key) + Buffer.from(public_key), ); aggregator.hpkeConfigList = new HpkeConfigList([hpkeConfig]); @@ -62,7 +62,7 @@ describe("DAP Aggregator", () => { const aad = new InputShareAad( TaskId.random(), new ReportMetadata(ReportId.random(), Date.now() / 1000), - Buffer.alloc(0) + Buffer.alloc(0), ); const cipherText = aggregator.seal(inputShare, aad); @@ -73,7 +73,7 @@ describe("DAP Aggregator", () => { cipherText.encapsulatedContext, new InputShareInfo(Role.Leader).encode(), cipherText.payload, - aad.encode() + aad.encode(), ); assert.deepEqual(Buffer.from(open), inputShare.encode()); @@ -85,7 +85,7 @@ describe("DAP Aggregator", () => { const aad = new InputShareAad( TaskId.random(), new ReportMetadata(ReportId.random(), Date.now() / 1000), - Buffer.alloc(0) + Buffer.alloc(0), ); assert.throws(() => aggregator.seal(inputShare, aad)); diff --git a/packages/dap/src/aggregator.ts b/packages/dap/src/aggregator.ts index 6d581f520..e894a4395 100644 --- a/packages/dap/src/aggregator.ts +++ b/packages/dap/src/aggregator.ts @@ -8,7 +8,7 @@ export class Aggregator { constructor( url: URL | string, public role: Role, - public hpkeConfigList?: HpkeConfigList + public hpkeConfigList?: HpkeConfigList, ) { this.url = new URL(url); if (!this.url.pathname.endsWith("/")) { @@ -27,7 +27,7 @@ export class Aggregator { seal(inputShare: PlaintextInputShare, aad: InputShareAad): HpkeCiphertext { if (!this.hpkeConfigList) { throw new Error( - "Attempted to call Aggregator#seal before fetching a hpkeConfigList." + "Attempted to call Aggregator#seal before fetching a hpkeConfigList.", ); } return this.hpkeConfigList @@ -35,7 +35,7 @@ export class Aggregator { .seal( new InputShareInfo(this.role).encode(), inputShare.encode(), - aad.encode() + aad.encode(), ); } } diff --git a/packages/dap/src/ciphertext.spec.ts b/packages/dap/src/ciphertext.spec.ts index 16fb75568..58b898bbc 100644 --- a/packages/dap/src/ciphertext.spec.ts +++ b/packages/dap/src/ciphertext.spec.ts @@ -23,7 +23,7 @@ describe("DAP HpkeCiphertext", () => { const ciphertext = new HpkeCiphertext( 100, Buffer.alloc(5, 1), - Buffer.alloc(10, 255) + Buffer.alloc(10, 255), ); assert.deepEqual( ciphertext.encode(), @@ -33,7 +33,7 @@ describe("DAP HpkeCiphertext", () => { ...[1, 1, 1, 1, 1], // encapcapsulated context ...[0, 0, 0, 10], // payload length ...[255, 255, 255, 255, 255, 255, 255, 255, 255, 255], //payload - ]) + ]), ); }); }); diff --git a/packages/dap/src/ciphertext.ts b/packages/dap/src/ciphertext.ts index 2d9139138..87372aae1 100644 --- a/packages/dap/src/ciphertext.ts +++ b/packages/dap/src/ciphertext.ts @@ -5,7 +5,7 @@ export class HpkeCiphertext implements Encodable { constructor( public configId: number, public encapsulatedContext: Buffer, - public payload: Buffer + public payload: Buffer, ) { if (configId !== Math.floor(configId) || configId < 0 || configId > 255) { throw new Error("configId must be a uint8 (< 256)"); diff --git a/packages/dap/src/client.spec.ts b/packages/dap/src/client.spec.ts index 279c64538..a223cb1c8 100644 --- a/packages/dap/src/client.spec.ts +++ b/packages/dap/src/client.spec.ts @@ -23,7 +23,7 @@ interface ResponseSpec { function mockFetch(mocks: { [url: string]: ResponseSpec[] }): Fetch { function fakeFetch( input: RequestInfo, - init?: RequestInit | undefined + init?: RequestInit | undefined, ): Promise { fakeFetch.calls.push([input, init]); const responseSpec = mocks[input.toString()]; @@ -32,8 +32,8 @@ function mockFetch(mocks: { [url: string]: ResponseSpec[] }): Fetch { if (!response) { throw new Error( `received unhandled request.\n\nurl: ${input.toString()}.\n\nmocks: ${inspect( - mocks - ).slice(1, -1)}` + mocks, + ).slice(1, -1)}`, ); } @@ -41,7 +41,7 @@ function mockFetch(mocks: { [url: string]: ResponseSpec[] }): Fetch { new Response(Buffer.from(response.body || ""), { status: response.status || 200, headers: { "Content-Type": response.contentType || "text/plain" }, - }) + }), ); } @@ -56,7 +56,7 @@ function buildHpkeConfigList(): HpkeConfigList { hpke.Kem.DhP256HkdfSha256, hpke.Kdf.Sha256, hpke.Aead.AesGcm128, - Buffer.from(new hpke.Keypair(hpke.Kem.DhP256HkdfSha256).public_key) + Buffer.from(new hpke.Keypair(hpke.Kem.DhP256HkdfSha256).public_key), ), ]); } @@ -81,7 +81,7 @@ function buildParams(): { function withHpkeConfigs< Spec extends KnownVdafSpec, - Measurement extends VdafMeasurement + Measurement extends VdafMeasurement, >(dapClient: DAPClient): DAPClient { for (const aggregator of dapClient.aggregators) { aggregator.hpkeConfigList = buildHpkeConfigList(); @@ -98,7 +98,7 @@ describe("DAPClient", () => { }); assert.equal( client.taskId.toString(), - "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY" + "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY", ); }); @@ -107,13 +107,13 @@ describe("DAPClient", () => { ...buildParams(), taskId: Buffer.from( "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY", - "base64url" + "base64url", ), }); assert.equal( client.taskId.toString(), - "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY" + "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY", ); }); @@ -163,7 +163,7 @@ describe("DAPClient", () => { ...buildParams(), timePrecisionSeconds: "ten" as unknown as number, }), - (e: Error) => e.message == "timePrecisionSeconds must be a number" + (e: Error) => e.message == "timePrecisionSeconds must be a number", ); }); }); @@ -273,7 +273,7 @@ describe("DAPClient", () => { kem, kdf, aead, - Buffer.from(public_key) + Buffer.from(public_key), ), ]); } @@ -282,7 +282,7 @@ describe("DAPClient", () => { assert.equal(report.encryptedInputShares.length, 2); assert( Math.floor(Date.now() / 1000) - Number(report.metadata.time) < - 2 /*2 second delta, double the minimum batch duration*/ + 2 /*2 second delta, double the minimum batch duration*/, ); const aad = Buffer.concat([ @@ -293,7 +293,7 @@ describe("DAPClient", () => { for (const [[privateKey, role], share] of zip( privateKeys, - report.encryptedInputShares + report.encryptedInputShares, )) { const info = Buffer.from([ ...Buffer.from("dap-04 input share"), @@ -311,8 +311,8 @@ describe("DAPClient", () => { share.encapsulatedContext, info, share.payload, - aad - ) + aad, + ), ); } }); @@ -332,7 +332,7 @@ describe("DAPClient", () => { const client = withHpkeConfigs(new DAPClient(buildParams())); await assert.rejects( client.generateReport(-25.25), - /measurement -25.25 was not an integer/ // this is specific to the Sum circuit as configured + /measurement -25.25 was not an integer/, // this is specific to the Sum circuit as configured ); }); @@ -340,7 +340,7 @@ describe("DAPClient", () => { const client = withHpkeConfigs(new DAPClient(buildParams())); assert(client.aggregators[0].hpkeConfigList); client.aggregators[0].hpkeConfigList.configs[0].publicKey = Buffer.from( - "not a valid public key" + "not a valid public key", ); await assert.rejects(client.generateReport(21)); }); @@ -386,14 +386,14 @@ describe("DAPClient", () => { const request = new Request(url, args); assert.equal( request.url, - `https://a.example.com/v1/tasks/${taskId}/reports` + `https://a.example.com/v1/tasks/${taskId}/reports`, ); assert(!!args); assert.deepEqual(args.body, report.encode()); assert.equal(request.method, "PUT"); assert.equal( request.headers.get("Content-Type"), - "application/dap-report" + "application/dap-report", ); }); @@ -486,7 +486,7 @@ describe("DAPClient", () => { client.fetch = fetch; await assert.rejects( client.sendMeasurement(10), - (e) => e instanceof DAPError && e.shortType == "outdatedConfig" + (e) => e instanceof DAPError && e.shortType == "outdatedConfig", ); assert.equal(fetch.calls.length, 6); // we do not try again }); diff --git a/packages/dap/src/client.ts b/packages/dap/src/client.ts index e1cc961ed..f1522e7bd 100644 --- a/packages/dap/src/client.ts +++ b/packages/dap/src/client.ts @@ -52,7 +52,7 @@ export interface ClientParameters { type Fetch = ( input: RequestInfo, - init?: RequestInit | undefined + init?: RequestInit | undefined, ) => Promise; interface KnownVdafs { @@ -75,7 +75,7 @@ export type VdafMeasurement = Parameters< >[0]; function vdafFromSpec( spec: Spec, - shares = 2 + shares = 2, ): VdafInstance { switch (spec.type) { case "count": @@ -100,7 +100,7 @@ function vdafFromSpec( */ export class DAPClient< Spec extends KnownVdafSpec, - Measurement extends VdafMeasurement + Measurement extends VdafMeasurement, > { #vdaf: ClientVdaf; #taskId: TaskId; @@ -163,7 +163,7 @@ export class DAPClient< */ async generateReport( measurement: Measurement, - options?: ReportOptions + options?: ReportOptions, ): Promise { await this.fetchKeyConfiguration(); const reportId = ReportId.random(); @@ -172,7 +172,7 @@ export class DAPClient< await this.#vdaf.measurementToInputShares( measurement, reportId.encode(), - rand + rand, ); const time = roundedTime(this.#timePrecisionSeconds, options?.timestamp); @@ -181,8 +181,8 @@ export class DAPClient< const ciphertexts = this.#aggregators.map((aggregator, i) => aggregator.seal( new PlaintextInputShare(this.#extensions, inputShares[i]), - aad - ) + aad, + ), ); return new Report(metadata, publicShare, ciphertexts); @@ -205,7 +205,7 @@ export class DAPClient< method: "PUT", headers: { "Content-Type": CONTENT_TYPES.REPORT }, body, - } + }, ); if (!response.ok) { @@ -233,7 +233,7 @@ export class DAPClient< */ async sendMeasurement( measurement: Measurement, - options?: ReportOptions + options?: ReportOptions, ): Promise { const report = await this.generateReport(measurement, options); @@ -283,7 +283,7 @@ export class DAPClient< if (!response.ok) { throw await DAPError.fromResponse( response, - `fetchKeyConfiguration received a ${response.status} response, aborting` + `fetchKeyConfiguration received a ${response.status} response, aborting`, ); } @@ -291,16 +291,16 @@ export class DAPClient< if (blob.type !== CONTENT_TYPES.HPKE_CONFIG_LIST) { throw new Error( - `expected ${CONTENT_TYPES.HPKE_CONFIG_LIST} content-type header, aborting` + `expected ${CONTENT_TYPES.HPKE_CONFIG_LIST} content-type header, aborting`, ); } aggregator.hpkeConfigList = HpkeConfigList.parse( - await blob.arrayBuffer() + await blob.arrayBuffer(), ); aggregator.hpkeConfigList.selectConfig(); - }) + }), ); } } @@ -313,7 +313,7 @@ function aggregatorsFromParameters({ } function taskIdFromDefinition( - taskIdDefinition: Buffer | TaskId | string + taskIdDefinition: Buffer | TaskId | string, ): TaskId { if (taskIdDefinition instanceof TaskId) return taskIdDefinition; else return new TaskId(taskIdDefinition); diff --git a/packages/dap/src/encoding.spec.ts b/packages/dap/src/encoding.spec.ts index e57bc3066..7f126736d 100644 --- a/packages/dap/src/encoding.spec.ts +++ b/packages/dap/src/encoding.spec.ts @@ -23,7 +23,10 @@ class Uint16 implements Encodable { } class TestEncodable implements Encodable { - constructor(public array16: Uint16[], public opaque16: Buffer) {} + constructor( + public array16: Uint16[], + public opaque16: Buffer, + ) {} encode(): Buffer { return Buffer.concat([ encodeArray16(this.array16), @@ -42,7 +45,7 @@ context("encoding", () => { it("correctly encodes a two byte length description and then the full array", () => { assert.deepEqual( encodeArray16([new Uint16(65535), new Uint16(255)]), - Buffer.from([0, 4, 255, 255, 0, 255]) + Buffer.from([0, 4, 255, 255, 0, 255]), ); }); @@ -68,7 +71,7 @@ context("decoding", () => { it("correctly decodes", () => { assert.deepEqual( Parser.from(Buffer.from([0, 4, 255, 255, 0, 255])).array16(Uint16), - [new Uint16(65535), new Uint16(255)] + [new Uint16(65535), new Uint16(255)], ); }); @@ -81,7 +84,8 @@ context("decoding", () => { const parser = Parser.from(Buffer.from([0, 3, 255, 255, 0, 0])); assert.throws( () => parser.array16(Uint16), - (e: Error) => e.message === "expected to read exactly 3 but read 1 over" + (e: Error) => + e.message === "expected to read exactly 3 but read 1 over", ); }); }); @@ -91,7 +95,7 @@ context("TestEncodable", () => { it("can round trip a single parseable encodable", () => { const testEncodable = new TestEncodable( [5, 10, 15, 20].map((n) => new Uint16(n)), - Buffer.from("opaque") + Buffer.from("opaque"), ); const encoded = testEncodable.encode(); assert.deepEqual(TestEncodable.parse(encoded), testEncodable); @@ -101,17 +105,17 @@ context("TestEncodable", () => { const testEncodables = [ new TestEncodable( [5, 10, 15, 20].map((n) => new Uint16(n)), - Buffer.from("opaque") + Buffer.from("opaque"), ), new TestEncodable( [1, 2, 3].map((n) => new Uint16(n)), - Buffer.from("also opaque") + Buffer.from("also opaque"), ), ]; const encoded = encodeArray16(testEncodables); assert.deepEqual( Parser.from(encoded).array16(TestEncodable), - testEncodables + testEncodables, ); }); }); diff --git a/packages/dap/src/encoding.ts b/packages/dap/src/encoding.ts index 066671c99..09c2a207a 100644 --- a/packages/dap/src/encoding.ts +++ b/packages/dap/src/encoding.ts @@ -72,7 +72,7 @@ export class Parser { throw new Error( `expected to read exactly ${length} but read ${ this.index - endIndex - } over` + } over`, ); } @@ -81,7 +81,7 @@ export class Parser { slice(bytes: number): Buffer { return this.increment(bytes, () => - Buffer.from(this.buffer.subarray(this.index, this.index + bytes)) + Buffer.from(this.buffer.subarray(this.index, this.index + bytes)), ); } diff --git a/packages/dap/src/errors.spec.ts b/packages/dap/src/errors.spec.ts index 2c8a11e4d..7781f00dc 100644 --- a/packages/dap/src/errors.spec.ts +++ b/packages/dap/src/errors.spec.ts @@ -18,7 +18,7 @@ describe("DAPError", () => { new Response(JSON.stringify(sampleProblem), { headers: { "Content-Type": "application/problem+json" }, }), - "client context" + "client context", ); assert(error instanceof DAPError); @@ -29,7 +29,7 @@ describe("DAPError", () => { assert.equal(error.detail, sampleProblem.detail); assert.equal( error.message, - "unrecognizedTask: An endpoint received a message with an unknown task ID." + "unrecognizedTask: An endpoint received a message with an unknown task ID.", ); assert.equal(error.status, 400); assert.equal(error.instance, ".."); @@ -39,7 +39,7 @@ describe("DAPError", () => { it("returns a normal Error with the client context when the response isn't problem json", async () => { const error = await DAPError.fromResponse( new Response("doesn't matter"), - "client context" + "client context", ); assert(!(error instanceof DAPError)); diff --git a/packages/dap/src/errors.ts b/packages/dap/src/errors.ts index 5eb247a66..4f6cea0f6 100644 --- a/packages/dap/src/errors.ts +++ b/packages/dap/src/errors.ts @@ -34,7 +34,7 @@ export class DAPError extends Error { static async fromResponse( response: Response, - description: string + description: string, ): Promise { const contentType = response.headers.get("Content-Type"); if (contentType && contentType.match(/^application\/problem\+json/)) { diff --git a/packages/dap/src/extension.ts b/packages/dap/src/extension.ts index b0ed64e5e..b30f29cd9 100644 --- a/packages/dap/src/extension.ts +++ b/packages/dap/src/extension.ts @@ -6,7 +6,10 @@ enum ExtensionType { } export class Extension implements Encodable { - constructor(public extensionType: ExtensionType, public data: Buffer) {} + constructor( + public extensionType: ExtensionType, + public data: Buffer, + ) {} encode(): Buffer { throw new Error("tbd"); diff --git a/packages/dap/src/hpke.spec.ts b/packages/dap/src/hpke.spec.ts index 22e9ee34c..1a411c9d0 100644 --- a/packages/dap/src/hpke.spec.ts +++ b/packages/dap/src/hpke.spec.ts @@ -62,7 +62,7 @@ describe("HPKE", () => { keypair.public_key, info, plaintext, - aad + aad, ); const roundTrip = config.base_mode_open( @@ -70,7 +70,7 @@ describe("HPKE", () => { keyAndCiphertext.encapped_key, info, keyAndCiphertext.ciphertext, - aad + aad, ); assert.equal(startMessage, decoder.decode(roundTrip)); diff --git a/packages/dap/src/hpkeConfig.spec.ts b/packages/dap/src/hpkeConfig.spec.ts index 18afa9a58..7a8a6c65f 100644 --- a/packages/dap/src/hpkeConfig.spec.ts +++ b/packages/dap/src/hpkeConfig.spec.ts @@ -9,19 +9,19 @@ describe("DAP HpkeConfigList", () => { Kem.DhP256HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from("public key") + Buffer.from("public key"), ); const config2 = new HpkeConfig( 255, Kem.X25519HkdfSha256, Kdf.Sha384, Aead.ChaCha20Poly1305, - Buffer.from("public key") + Buffer.from("public key"), ); const list = new HpkeConfigList([config1, config2]); assert.deepEqual( [...list.encode()], - [0, 38, ...config1.encode(), ...config2.encode()] + [0, 38, ...config1.encode(), ...config2.encode()], ); }); @@ -31,18 +31,18 @@ describe("DAP HpkeConfigList", () => { Kem.DhP256HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from("public key") + Buffer.from("public key"), ); const config2 = new HpkeConfig( 255, Kem.X25519HkdfSha256, Kdf.Sha384, Aead.ChaCha20Poly1305, - Buffer.from("public key") + Buffer.from("public key"), ); const list = HpkeConfigList.parse( - Buffer.from([0, 38, ...config1.encode(), ...config2.encode()]) + Buffer.from([0, 38, ...config1.encode(), ...config2.encode()]), ); assert.deepEqual(list.configs, [config1, config2]); @@ -54,7 +54,7 @@ describe("DAP HpkeConfigList", () => { Kem.DhP256HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from("public key") + Buffer.from("public key"), ); const invalidConfig = new HpkeConfig( @@ -62,7 +62,7 @@ describe("DAP HpkeConfigList", () => { Kem.X25519HkdfSha256, Kdf.Sha512, Aead.ChaCha20Poly1305, - Buffer.from("public key") + Buffer.from("public key"), ); // none of these are known ids, so we skip the invalid config @@ -83,7 +83,7 @@ describe("DAP HpkeConfig", () => { Kem.DhP256HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from("public key") + Buffer.from("public key"), ); assert.deepEqual( @@ -95,7 +95,7 @@ describe("DAP HpkeConfig", () => { ...[0, 1], ...[0, 10], //length of "public key" ...Buffer.from("public key", "ascii"), - ] + ], ); }); @@ -108,7 +108,7 @@ describe("DAP HpkeConfig", () => { ...[0, 3], ...[0, 10], //length of "public key" ...Buffer.from("public key", "ascii"), - ]) + ]), ); assert.equal(config.publicKey.toString("ascii"), "public key"); @@ -155,7 +155,7 @@ describe("DAP HpkeConfig", () => { Kem.DhP256HkdfSha256, 50, Aead.ChaCha20Poly1305, - Buffer.alloc(10) + Buffer.alloc(10), ); }, /kdfId was 50 but must be one of the following:/); }); @@ -167,7 +167,7 @@ describe("DAP HpkeConfig", () => { Kem.DhP256HkdfSha256, Kdf.Sha512, 5, - Buffer.alloc(10) + Buffer.alloc(10), ); }, /aeadId was 5 but must be one of the following:/); }); @@ -180,14 +180,14 @@ describe("DAP HpkeConfig", () => { Kem.X25519HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from(wrongKeyType) + Buffer.from(wrongKeyType), ); assert.throws(() => { config.seal( Buffer.from("info"), Buffer.from("plaintext"), - Buffer.from("aad") + Buffer.from("aad"), ); }); }); @@ -198,14 +198,14 @@ describe("DAP HpkeConfig", () => { Kem.X25519HkdfSha256, Kdf.Sha256, Aead.AesGcm128, - Buffer.from("not a valid key") + Buffer.from("not a valid key"), ); assert.throws(() => { config.seal( Buffer.from("info"), Buffer.from("plaintext"), - Buffer.from("aad") + Buffer.from("aad"), ); }); }); @@ -219,7 +219,7 @@ describe("DAP HpkeConfig", () => { kem, Kdf.Sha256, Aead.AesGcm128, - Buffer.from(public_key) + Buffer.from(public_key), ); const info = Buffer.from("info"); @@ -234,7 +234,7 @@ describe("DAP HpkeConfig", () => { hpkeCipherText.encapsulatedContext, info, hpkeCipherText.payload, - aad + aad, ); assert.deepEqual(decrypted, plaintext); @@ -250,7 +250,7 @@ describe("DAP HpkeConfig", () => { kem, Kdf.Sha256, Aead.AesGcm128, - Buffer.from(public_key) + Buffer.from(public_key), ); const info = Buffer.from("info"); @@ -265,7 +265,7 @@ describe("DAP HpkeConfig", () => { hpkeCipherText.encapsulatedContext, info, hpkeCipherText.payload, - aad + aad, ); assert.deepEqual(decrypted, plaintext); diff --git a/packages/dap/src/hpkeConfig.ts b/packages/dap/src/hpkeConfig.ts index 696d8bb3c..80f629ef8 100644 --- a/packages/dap/src/hpkeConfig.ts +++ b/packages/dap/src/hpkeConfig.ts @@ -37,7 +37,7 @@ export class HpkeConfig implements Encodable { public kemId: hpke.Kem, public kdfId: hpke.Kdf, public aeadId: hpke.Aead, - public publicKey: Buffer + public publicKey: Buffer, ) { if (id !== Math.floor(id) || id < 0 || id > 255) { throw new Error("id must be an integer in [0, 255]"); @@ -50,7 +50,7 @@ export class HpkeConfig implements Encodable { private validate( e: { [key: string]: unknown }, - id: "kemId" | "kdfId" | "aeadId" + id: "kemId" | "kdfId" | "aeadId", ) { const actual = this[id]; @@ -62,7 +62,7 @@ export class HpkeConfig implements Encodable { .join("\n"); throw new Error( - `${id} was ${actual} but must be one of the following:\n${errorText}` + `${id} was ${actual} but must be one of the following:\n${errorText}`, ); } } @@ -74,7 +74,7 @@ export class HpkeConfig implements Encodable { parser.uint16(), parser.uint16(), parser.uint16(), - parser.opaque16() + parser.opaque16(), ); } @@ -101,13 +101,13 @@ export class HpkeConfig implements Encodable { this.publicKey, info, plaintext, - aad + aad, ); return new HpkeCiphertext( this.id, Buffer.from(text.encapped_key), - Buffer.from(text.ciphertext) + Buffer.from(text.ciphertext), ); } } diff --git a/packages/dap/src/report.spec.ts b/packages/dap/src/report.spec.ts index 323109215..ca95eaaac 100644 --- a/packages/dap/src/report.spec.ts +++ b/packages/dap/src/report.spec.ts @@ -18,13 +18,13 @@ describe("DAP Report", () => { const ciphertext1 = new HpkeCiphertext( 1, Buffer.alloc(5, 1), - Buffer.alloc(5, 1) + Buffer.alloc(5, 1), ); const ciphertext2 = new HpkeCiphertext( 2, Buffer.alloc(2, 2), - Buffer.alloc(2, 2) + Buffer.alloc(2, 2), ); const reportMetadata = new ReportMetadata(reportId, 0); @@ -41,7 +41,7 @@ describe("DAP Report", () => { ...[0, 0, 0, 17 + 11], // length of the combined ciphertext encodings ...ciphertext1.encode(), // tested in ciphertext.spec ...ciphertext2.encode(), - ]) + ]), ); }); }); @@ -57,7 +57,7 @@ describe("DAP ReportMetadata", () => { Buffer.from([ ...reportId.encode(), // tested in reportId.spec ...[0, 0, 0, 0, 0x3b, 0x9a, 0xca, 0x00], - ]) + ]), ); }); }); @@ -72,7 +72,7 @@ describe("DAP PlaintextInputShare", () => { ...[0, 0], //array16 extensions ...[0, 0, 0, payload.length], // opaque32 payload length ...payload, - ]) + ]), ); }); }); @@ -91,7 +91,7 @@ describe("DAP InputShareAad", () => { ...metadata.encode(), ...[0, 0, 0, publicShare.length], ///opaque32 public share ...publicShare, - ]) + ]), ); }); }); @@ -100,11 +100,11 @@ describe("DAP InputShareInfo", () => { it("encodes as expected", () => { assert.deepEqual( new InputShareInfo(Role.Helper).encode(), - Buffer.from([...Buffer.from("dap-04 input share"), 1, 3]) + Buffer.from([...Buffer.from("dap-04 input share"), 1, 3]), ); assert.deepEqual( new InputShareInfo(Role.Leader).encode(), - Buffer.from([...Buffer.from("dap-04 input share"), 1, 2]) + Buffer.from([...Buffer.from("dap-04 input share"), 1, 2]), ); }); }); diff --git a/packages/dap/src/report.ts b/packages/dap/src/report.ts index f7bcc04a2..ce84a64ff 100644 --- a/packages/dap/src/report.ts +++ b/packages/dap/src/report.ts @@ -12,7 +12,10 @@ import { DAP_VERSION, Role } from "./constants"; import { Extension } from "./extension"; export class ReportMetadata implements Encodable { - constructor(public reportID: ReportId, public time: number) {} + constructor( + public reportID: ReportId, + public time: number, + ) {} encode(): Buffer { const buffer = Buffer.alloc(24); @@ -26,7 +29,7 @@ export class Report implements Encodable { constructor( public metadata: ReportMetadata, public publicShare: Buffer, - public encryptedInputShares: HpkeCiphertext[] + public encryptedInputShares: HpkeCiphertext[], ) {} encode(): Buffer { @@ -39,7 +42,10 @@ export class Report implements Encodable { } export class PlaintextInputShare implements Encodable { - constructor(public extensions: Extension[], public payload: Buffer) {} + constructor( + public extensions: Extension[], + public payload: Buffer, + ) {} encode(): Buffer { return Buffer.concat([ @@ -53,7 +59,7 @@ export class InputShareAad implements Encodable { constructor( public taskId: TaskId, public metadata: ReportMetadata, - public publicShare: Buffer + public publicShare: Buffer, ) {} encode(): Buffer { diff --git a/packages/dap/src/reportId.spec.ts b/packages/dap/src/reportId.spec.ts index 1558fedd1..926bb8cff 100644 --- a/packages/dap/src/reportId.spec.ts +++ b/packages/dap/src/reportId.spec.ts @@ -27,7 +27,7 @@ describe("DAP ReportID", () => { Buffer.from([ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - ]) + ]), ); }); }); diff --git a/packages/dap/src/taskId.spec.ts b/packages/dap/src/taskId.spec.ts index 90378f429..45aef243b 100644 --- a/packages/dap/src/taskId.spec.ts +++ b/packages/dap/src/taskId.spec.ts @@ -20,8 +20,8 @@ describe("DAP TaskId", () => { const taskId = new TaskId( Buffer.from( "dd74c11f14ed500b48e75e8679766c5482a304f61534862617de2f1016f88dc6", - "hex" - ) + "hex", + ), ); assert.equal(taskId, "3XTBHxTtUAtI516GeXZsVIKjBPYVNIYmF94vEBb4jcY"); }); diff --git a/packages/dap/src/taskId.ts b/packages/dap/src/taskId.ts index 2c56c83e1..85fc5eefd 100644 --- a/packages/dap/src/taskId.ts +++ b/packages/dap/src/taskId.ts @@ -9,7 +9,7 @@ export class TaskId implements Encodable { if (typeof input === "string") { this.buffer = Buffer.from( input.replace(/-/g, "+").replace(/_/g, "/"), - "base64" + "base64", ); } else { this.buffer = input; @@ -17,7 +17,7 @@ export class TaskId implements Encodable { if (this.buffer.length !== 32) { throw new Error( - `expected TaskId to be 32 bytes long (${this.toString()})` + `expected TaskId to be 32 bytes long (${this.toString()})`, ); } } diff --git a/packages/field/src/PrimeField.spec.ts b/packages/field/src/PrimeField.spec.ts index 895c1a2ea..21887c867 100644 --- a/packages/field/src/PrimeField.spec.ts +++ b/packages/field/src/PrimeField.spec.ts @@ -412,23 +412,23 @@ describe("PrimeField;", () => { vTests.forEach(({ v1, v2, vr }) => { it(`should correctly add vectors ${strVector(v1)} and ${strVector( - v2 + v2, )}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); expect(F.addVectorElements(fv1, fv2).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); nTests.forEach(({ v1, n, vr }) => { it(`should correctly add vector ${strVector( - v1 + v1, )} and number ${n}`, () => { const fv1 = F.newVectorFrom(v1); expect(F.addVectorElements(fv1, n).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); @@ -463,23 +463,23 @@ describe("PrimeField;", () => { vTests.forEach(({ v1, v2, vr }) => { it(`should correctly subtract vectors ${strVector( - v1 + v1, )} and ${strVector(v2)}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); expect(F.subVectorElements(fv1, fv2).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); nTests.forEach(({ v1, n, vr }) => { it(`should correctly subtract number ${n} from vector ${strVector( - v1 + v1, )}`, () => { const fv1 = F.newVectorFrom(v1); expect(F.subVectorElements(fv1, n).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); @@ -514,23 +514,23 @@ describe("PrimeField;", () => { vTests.forEach(({ v1, v2, vr }) => { it(`should correctly multiply vectors ${strVector( - v1 + v1, )} and ${strVector(v2)}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); expect(F.mulVectorElements(fv1, fv2).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); nTests.forEach(({ v1, n, vr }) => { it(`should correctly multiply vector ${strVector( - v1 + v1, )} and number ${n}`, () => { const fv1 = F.newVectorFrom(v1); expect(F.mulVectorElements(fv1, n).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); @@ -632,23 +632,23 @@ describe("PrimeField;", () => { vTests.forEach(({ v1, v2, vr }) => { it(`should correctly divide vectors ${strVector( - v1 + v1, )} and ${strVector(v2)}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); expect(F.divVectorElements(fv1, fv2).values).to.deep.equal( - vr[Number(modulus)].map((n) => F.mod(n)) + vr[Number(modulus)].map((n) => F.mod(n)), ); }); }); nTests.forEach(({ v1, n, vr }) => { it(`should correctly divide vector ${strVector( - v1 + v1, )} by number ${n}`, () => { const fv1 = F.newVectorFrom(v1); expect(F.divVectorElements(fv1, n).values).to.deep.equal( - vr[Number(modulus)].map((n) => F.mod(n)) + vr[Number(modulus)].map((n) => F.mod(n)), ); }); }); @@ -682,23 +682,23 @@ describe("PrimeField;", () => { vTests.forEach(({ v1, v2, vr }) => { it(`should correctly raise vector ${strVector( - v1 + v1, )} to a power ${strVector(v2)}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); expect(F.expVectorElements(fv1, fv2).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); nTests.forEach(({ v1, n, vr }) => { it(`should correctly raise vector ${strVector( - v1 + v1, )} to a power ${n}`, () => { const fv1 = F.newVectorFrom(v1); expect(F.expVectorElements(fv1, n).values).to.deep.equal( - vr.map((n) => F.mod(n)) + vr.map((n) => F.mod(n)), ); }); }); @@ -722,7 +722,7 @@ describe("PrimeField;", () => { tests.forEach(({ v1, v2, r }) => { it(`should correctly combine vectors ${strVector( - v1 + v1, )} and ${strVector(v2)}`, () => { const fv1 = F.newVectorFrom(v1); const fv2 = F.newVectorFrom(v2); @@ -1482,7 +1482,7 @@ describe("PrimeField;", () => { const fp1 = F.newVectorFrom(p1); const fp2 = F.newVectorFrom(p2); expect(F.addPolys(fp1, fp2).values).to.deep.equal( - pr.map((n) => F.mod(n)) + pr.map((n) => F.mod(n)), ); }); }); @@ -1515,7 +1515,7 @@ describe("PrimeField;", () => { const fp1 = F.newVectorFrom(p1); const fp2 = F.newVectorFrom(p2); expect(F.subPolys(fp1, fp2).values).to.deep.equal( - pr.map((n) => F.mod(n)) + pr.map((n) => F.mod(n)), ); }); }); @@ -1558,7 +1558,7 @@ describe("PrimeField;", () => { const fp1 = F.newVectorFrom(p1); const fp2 = F.newVectorFrom(p2); expect(F.mulPolys(fp1, fp2).values).to.deep.equal( - pr.map((n) => F.mod(n)) + pr.map((n) => F.mod(n)), ); }); }); @@ -1596,7 +1596,7 @@ describe("PrimeField;", () => { const fp1 = F.newVectorFrom(p1); const fp2 = F.newVectorFrom(p2); expect(F.divPolys(fp1, fp2).values).to.deep.equal( - pr.map((n) => F.mod(n)) + pr.map((n) => F.mod(n)), ); }); }); @@ -1645,7 +1645,7 @@ describe("PrimeField;", () => { const fxs = F.newVectorFrom(xs); const fys = F.newVectorFrom(ys); expect(F.interpolate(fxs, fys).values).to.deep.equal( - poly.map((n) => F.mod(n)) + poly.map((n) => F.mod(n)), ); }); }); @@ -1670,7 +1670,7 @@ describe("PrimeField;", () => { ].forEach((poly) => { describe(`for polynom ${JSON.stringify(poly).replace( /"/g, - "" + "", )};`, () => { beforeEach(() => { F = new PrimeField(modulus); @@ -1684,13 +1684,13 @@ describe("PrimeField;", () => { it(`should return correctly polynom by interpolateRoots()`, () => { expect(F.interpolateRoots(xs, ys).values).to.deep.equal( - poly.map((n) => F.mod(n)) + poly.map((n) => F.mod(n)), ); }); it(`should return correctly polynom by interpolate()`, () => { expect(F.interpolate(xs, ys).values).to.deep.equal( - poly.map((n) => F.mod(n)) + poly.map((n) => F.mod(n)), ); }); diff --git a/packages/field/src/PrimeField.ts b/packages/field/src/PrimeField.ts index ef5cf0b88..f593c6280 100644 --- a/packages/field/src/PrimeField.ts +++ b/packages/field/src/PrimeField.ts @@ -156,7 +156,7 @@ export class PrimeField { : this.vectorElementsOp( this.mul.bind(this), a, - this.invVectorElements(b) + this.invVectorElements(b), ); } @@ -197,7 +197,7 @@ export class PrimeField { private vectorElementsOp( op: ArithmeticOperation, a: Vector, - b: Vector + b: Vector, ): Vector { const aValues = a.toValues(), bValues = b.toValues(); @@ -211,7 +211,7 @@ export class PrimeField { private vectorScalarOp( op: ArithmeticOperation, a: Vector, - b: bigint + b: bigint, ): Vector { const aValues = a.toValues(); const rValues = new Array(a.length); @@ -330,7 +330,7 @@ export class PrimeField { const x2 = x * x; const x3 = x2 * x; return this.mod( - pValues[0] + pValues[1] * x + pValues[2] * x2 + pValues[3] * x3 + pValues[0] + pValues[1] * x + pValues[2] * x2 + pValues[3] * x3, ); } case 5: { @@ -341,7 +341,7 @@ export class PrimeField { pValues[1] * x + pValues[2] * x2 + pValues[3] * x3 + - pValues[4] * x3 * x + pValues[4] * x3 * x, ); } default: { @@ -364,7 +364,7 @@ export class PrimeField { } if (p.length > rootsOfUnity.length) { throw new Error( - "Vectorial degree must be smaller than or equal to the number of roots of unity" + "Vectorial degree must be smaller than or equal to the number of roots of unity", ); } @@ -389,7 +389,7 @@ export class PrimeField { interpolate(xs: Vector, ys: Vector): Vector { if (xs.length !== ys.length) { throw new Error( - "Number of x coordinates must be the same as number of y coordinates" + "Number of x coordinates must be the same as number of y coordinates", ); } @@ -407,7 +407,7 @@ export class PrimeField { denominators[i] = this.evalPolyAt(numerators[i], xsValues[i]); } const invDenValues = this.invVectorElements( - this.newVectorFrom(denominators) + this.newVectorFrom(denominators), ).values; const yValues = ys.toValues(); @@ -441,7 +441,7 @@ export class PrimeField { if (ys instanceof Vector) { if (rootsOfUnity.length !== ys.length) { throw new Error( - "Number of roots of unity must be the same as number of y coordinates" + "Number of roots of unity must be the same as number of y coordinates", ); } const yValues = ys.toValues(); @@ -463,7 +463,7 @@ function fastFT( roots: readonly bigint[], depth: number, offset: number, - F: PrimeField + F: PrimeField, ): bigint[] { const step = 1 << depth; const resultLength = roots.length / step; diff --git a/packages/field/src/index.spec.ts b/packages/field/src/index.spec.ts index 44c940393..8d31eefea 100644 --- a/packages/field/src/index.spec.ts +++ b/packages/field/src/index.spec.ts @@ -35,7 +35,7 @@ function testField(field: Field, name: string) { it("has a sum reducer", () => { assert.equal( field.sum([field.modulus, 1n, 2n, 3n], (n) => n), - 6n + 6n, ); }); @@ -51,7 +51,7 @@ function testField(field: Field, name: string) { it("can do vector subtraction", () => { assert.deepEqual( field.vecSub([10n, 10n, 10n, 10n], [11n, 12n, 5n, 0n]), - [field.modulus - 1n, field.modulus - 2n, 5n, 10n] + [field.modulus - 1n, field.modulus - 2n, 5n, 10n], ); }); }); @@ -83,8 +83,8 @@ function testField(field: Field, name: string) { const roots = arr(count, (n) => field.exp( field.exp(field.generator, field.genOrder / BigInt(count)), - BigInt(n) - ) + BigInt(n), + ), ); const poly = field.fillRandom(count); diff --git a/packages/field/src/index.ts b/packages/field/src/index.ts index ab222435e..d764e4849 100644 --- a/packages/field/src/index.ts +++ b/packages/field/src/index.ts @@ -26,7 +26,7 @@ export class Field { this.encodedSize = encodedSize; this.generator = this.#primeField.exp( generatorParts.base, - generatorParts.exponent + generatorParts.exponent, ); } @@ -89,13 +89,13 @@ export class Field { const encodedSize = this.encodedSize; if (encoded.length % encodedSize !== 0) { throw new Error( - `could not decode, expected ${encoded.length} to be a multiple of ${encodedSize}` + `could not decode, expected ${encoded.length} to be a multiple of ${encodedSize}`, ); } return arr(encoded.length / encodedSize, (index) => { const n = octetStringToIntegerLE( - encoded.slice(index * encodedSize, (index + 1) * encodedSize) + encoded.slice(index * encodedSize, (index + 1) * encodedSize), ); if (n >= this.modulus) { throw new Error("decoded an element that is not in the field"); @@ -111,7 +111,7 @@ export class Field { sum(arr: T[], mapper: (value: T, index: number) => bigint): bigint { return arr.reduce( (sum, value, index) => this.add(sum, mapper(value, index)), - 0n + 0n, ); } } diff --git a/packages/interop-test-client/src/index.spec.ts b/packages/interop-test-client/src/index.spec.ts index 61010f151..478bd0d3c 100644 --- a/packages/interop-test-client/src/index.spec.ts +++ b/packages/interop-test-client/src/index.spec.ts @@ -17,20 +17,20 @@ function randomSuffix(): string { (_) => IDENTIFIER_ALPHABET[ Math.floor(Math.random() * IDENTIFIER_ALPHABET.length) - ] + ], ).join(""); } function spawnSyncAndThrow( command: string, - args: Array + args: Array, ): SpawnSyncReturns { const result = spawnSync(command, args, { encoding: "utf-8" }); if (result.error) { throw result.error; } else if (result.status !== null && result.status !== 0) { throw new Error( - `${command} failed with status code ${result.status}\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}` + `${command} failed with status code ${result.status}\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`, ); } else if (result.signal !== null) { throw new Error(`${command} was killed with signal ${result.signal}`); @@ -75,7 +75,7 @@ class Container { const match = /^0.0.0.0:([0-9]+)$/m.exec(result.stdout); if (!match) { throw new Error( - `docker port output coudl not be parsed, was ${result.stdout}` + `docker port output could not be parsed, was ${result.stdout}`, ); } this.port = parseInt(match[1], 10); @@ -92,7 +92,7 @@ class Container { /** Send an interoperation test API request, and return the response. */ async sendRequest( apiEndpoint: string, - requestBody: object + requestBody: object, ): Promise> { const response = await fetch( `http://127.0.0.1:${this.port}/internal/test/${apiEndpoint}`, @@ -102,7 +102,7 @@ class Container { "Content-Type": "application/json", }, body: JSON.stringify(requestBody), - } + }, ); return await checkResponseError(response); } @@ -111,12 +111,12 @@ class Container { /** Check the status field in a response, throw an error if it wasn't successful, and return the * response body otherwise. */ async function checkResponseError( - response: Response + response: Response, ): Promise> { if (response.status !== 200) { const body = await response.text(); throw new Error( - `Test API returned status code ${response.status}, body: ${body}` + `Test API returned status code ${response.status}, body: ${body}`, ); } const rawBody: unknown = await response.json(); @@ -179,7 +179,7 @@ class Aggregator extends Container { minBatchSize: number, timePrecisionSeconds: number, collectorHpkeConfig: string, - taskExpiration: number + taskExpiration: number, ): Promise { const requestBody: Record = { task_id: taskId.toString(), @@ -209,7 +209,7 @@ class Collector extends Container { taskId: EncodedBlob, leaderEndpoint: URL, vdaf: object, - collectorAuthToken: string + collectorAuthToken: string, ): Promise { const rawBody = await this.sendRequest("add_task", { task_id: taskId.toString(), @@ -234,7 +234,7 @@ class Collector extends Container { async collectionStart( taskId: EncodedBlob, batchIntervalStart: number, - batchIntervalDuration: number + batchIntervalDuration: number, ): Promise { const rawBody = await this.sendRequest("collection_start", { task_id: taskId.toString(), @@ -303,7 +303,7 @@ async function upload( helperEndpoint: URL, vdaf: object, measurement: unknown, - timePrecision: number + timePrecision: number, ): Promise { const response = await fetch( `http://127.0.0.1:${clientPort}/internal/test/upload`, @@ -320,7 +320,7 @@ async function upload( measurement: measurement, time_precision: timePrecision, }), - } + }, ); await checkResponseError(response); } @@ -361,7 +361,7 @@ async function waitForReady(port: number) { "Content-Type": "application/json", }, body: JSON.stringify({}), - } + }, ); if (response.status === 200) { return; @@ -382,7 +382,7 @@ async function runIntegrationTest( collector: Collector, vdaf: object, measurements: Array, - expectedResult: unknown + expectedResult: unknown, ) { const maxBatchQueryCount = 1; const minBatchSize = measurements.length; @@ -406,7 +406,7 @@ async function runIntegrationTest( taskId, leaderEndpoint, vdaf, - collectorAuthToken + collectorAuthToken, ); await leader.addTask( taskId, @@ -421,7 +421,7 @@ async function runIntegrationTest( minBatchSize, timePrecision, collectorHpkeConfig, - taskExpiration + taskExpiration, ); await helper.addTask( taskId, @@ -436,7 +436,7 @@ async function runIntegrationTest( minBatchSize, timePrecision, collectorHpkeConfig, - taskExpiration + taskExpiration, ); let leaderEndpointForClient: URL; @@ -445,12 +445,12 @@ async function runIntegrationTest( leaderEndpointForClient = new URL( leaderEndpoint .toString() - .replace(`${leader.name}:8080`, `127.0.0.1:${leader.port}`) + .replace(`${leader.name}:8080`, `127.0.0.1:${leader.port}`), ); helperEndpointForClient = new URL( helperEndpoint .toString() - .replace(`${helper.name}:8080`, `127.0.0.1:${helper.port}`) + .replace(`${helper.name}:8080`, `127.0.0.1:${helper.port}`), ); } else { leaderEndpointForClient = leaderEndpoint; @@ -466,14 +466,14 @@ async function runIntegrationTest( helperEndpointForClient, vdaf, measurement, - timePrecision + timePrecision, ); } const collectHandle = await collector.collectionStart( taskId, Math.floor(start.getTime() / 1000 / timePrecision) * timePrecision, - timePrecision * 2 + timePrecision * 2, ); for (let i = 0; i < 30; i++) { const collection = await collector.collectionPoll(collectHandle); @@ -494,8 +494,8 @@ async function runIntegrationTest( if (parseInt(collection.result[i], 10) !== expectedResult[i]) { throw new Error( `Aggregate result did not match, got ${JSON.stringify( - collection.result - )}, expected ${JSON.stringify(expectedResult)}` + collection.result, + )}, expected ${JSON.stringify(expectedResult)}`, ); } } @@ -505,7 +505,7 @@ async function runIntegrationTest( ) { if (parseInt(collection.result, 10) !== expectedResult) { throw new Error( - `Aggregate result did not match, got ${collection.result}, expected ${expectedResult}` + `Aggregate result did not match, got ${collection.result}, expected ${expectedResult}`, ); } } else { @@ -521,7 +521,7 @@ async function runIntegrationTestWithHostClient( clientPort: number, vdaf: object, measurement: Array, - expectedResult: unknown + expectedResult: unknown, ) { const suffix = randomSuffix(); const network = new Network(`divviup-ts-interop-${suffix}`); @@ -529,19 +529,19 @@ async function runIntegrationTestWithHostClient( const leader = new Aggregator( JANUS_INTEROP_AGGREGATOR_IMAGE, `leader-${suffix}`, - network + network, ); try { const helper = new Aggregator( JANUS_INTEROP_AGGREGATOR_IMAGE, `helper-${suffix}`, - network + network, ); try { const collector = new Collector( JANUS_INTEROP_COLLECTOR_IMAGE, `collector-${suffix}`, - network + network, ); try { await runIntegrationTest( @@ -552,7 +552,7 @@ async function runIntegrationTestWithHostClient( collector, vdaf, measurement, - expectedResult + expectedResult, ); } finally { collector.delete(); @@ -574,7 +574,7 @@ async function runIntegrationTestWithHostClient( function startServer(): Promise { return new Promise((resolve) => { const server: Server = app().listen(0, "127.0.0.1", 511, () => - resolve(server) + resolve(server), ); }); } @@ -590,7 +590,7 @@ describe("interoperation test", function () { clientPort, { type: "Prio3Count" }, arr(10, () => 1), - 10 + 10, ); } finally { server.close(); @@ -608,7 +608,7 @@ describe("interoperation test", function () { bits: "16", }, arr(10, (i) => `${i}`), - (9 * 10) / 2 + (9 * 10) / 2, ); } finally { server.close(); @@ -623,7 +623,7 @@ describe("interoperation test", function () { clientPort, { type: "Prio3Histogram", buckets: ["10", "100", "1000"] }, ["67", "216", "2012", "52", "10"], - [1, 2, 1, 1] + [1, 2, 1, 1], ); } finally { server.close(); diff --git a/packages/interop-test-client/src/index.ts b/packages/interop-test-client/src/index.ts index 3815e6cf5..c5c6afb35 100644 --- a/packages/interop-test-client/src/index.ts +++ b/packages/interop-test-client/src/index.ts @@ -153,12 +153,12 @@ function sanitizeRequest(rawBody: unknown): UploadRequest { bits = parseInt(vdaf.bits, 10); if (isNaN(bits)) { throw new Error( - "VDAF definition's `bits` parameter is not a valid base 10 integer" + "VDAF definition's `bits` parameter is not a valid base 10 integer", ); } } else { throw new Error( - "VDAF definition's `bits` parameter is not a number or string" + "VDAF definition's `bits` parameter is not a number or string", ); } if (typeof body.measurement !== "string") { @@ -179,13 +179,13 @@ function sanitizeRequest(rawBody: unknown): UploadRequest { } if (!Array.isArray(vdaf.buckets)) { throw new Error( - "VDAF definition's `buckets` parameter is not an array" + "VDAF definition's `buckets` parameter is not an array", ); } for (const bucketBoundary of vdaf.buckets) { if (typeof bucketBoundary !== "string") { throw new Error( - "VDAF defeinition's `buckets` parameter is not an array of strings" + "VDAF defeinition's `buckets` parameter is not an array of strings", ); } } diff --git a/packages/prg/src/index.spec.ts b/packages/prg/src/index.spec.ts index 1bcf6ce52..9c72b8381 100644 --- a/packages/prg/src/index.spec.ts +++ b/packages/prg/src/index.spec.ts @@ -35,7 +35,7 @@ describe("PrgSha3", () => { seed, dst, binder, - expandedLen + expandedLen, ); assert.equal(expandedVec.length, expandedLen); }); @@ -58,7 +58,7 @@ describe("PrgSha3", () => { derived_seed: Buffer.from(PrgSha3TestVector.derived_seed, "hex"), expanded_vec_field128: Buffer.from( PrgSha3TestVector.expanded_vec_field128, - "hex" + "hex", ), }; @@ -101,7 +101,7 @@ describe("PrgSha3", () => { seed, dst, binder, - expandedLen + expandedLen, ); assert.equal(expandedVec[expandedVec.length - 1], expectedLastElem); }); diff --git a/packages/prg/src/prg.ts b/packages/prg/src/prg.ts index e9a7d4c1d..ba367167f 100644 --- a/packages/prg/src/prg.ts +++ b/packages/prg/src/prg.ts @@ -7,7 +7,7 @@ export abstract class Prg { this: PrgConstructor, seed: Uint8Array, dst: Uint8Array, - binder: Uint8Array + binder: Uint8Array, ): Promise { return new this(seed, dst, binder).next(this.seedSize); } @@ -31,7 +31,7 @@ export abstract class Prg { seed: Uint8Array, dst: Uint8Array, binder: Uint8Array, - length: number + length: number, ): Promise { return new this(seed, dst, binder).nextVec(field, length); } @@ -43,13 +43,13 @@ export interface PrgConstructor { deriveSeed( seed: Uint8Array, dst: Uint8Array, - binder: Uint8Array + binder: Uint8Array, ): Promise; expandIntoVec( field: Field, seed: Uint8Array, dst: Uint8Array, binder: Uint8Array, - length: number + length: number, ): Promise; } diff --git a/packages/prg/src/sha3.ts b/packages/prg/src/sha3.ts index 23e75fb04..6474addfc 100644 --- a/packages/prg/src/sha3.ts +++ b/packages/prg/src/sha3.ts @@ -11,7 +11,7 @@ export const PrgSha3: PrgConstructor = class PrgSha3 extends Prg { super(); if (seed.length !== PrgSha3.seedSize) { throw new Error( - `PrgSha3 seed length must be exactly ${PrgSha3.seedSize}` + `PrgSha3 seed length must be exactly ${PrgSha3.seedSize}`, ); } this.#sha = new jsSHA("CSHAKE128", "UINT8ARRAY", { diff --git a/packages/prio3/src/circuit.ts b/packages/prio3/src/circuit.ts index da8eb5552..13dd6f1ac 100644 --- a/packages/prio3/src/circuit.ts +++ b/packages/prio3/src/circuit.ts @@ -56,13 +56,13 @@ export abstract class Circuit implements GenericCircuit { ensureValidEval(input: bigint[], jointRand: bigint[]) { if (input.length != this.inputLen) { throw new Error( - `expected input length to be ${this.inputLen} but it was ${input.length}` + `expected input length to be ${this.inputLen} but it was ${input.length}`, ); } if (jointRand.length != this.jointRandLen) { throw new Error( - `expected joint rand length to be ${this.jointRandLen} but it was ${jointRand.length}` + `expected joint rand length to be ${this.jointRandLen} but it was ${jointRand.length}`, ); } } diff --git a/packages/prio3/src/circuits/histogram.ts b/packages/prio3/src/circuits/histogram.ts index 71d2694de..26954a566 100644 --- a/packages/prio3/src/circuits/histogram.ts +++ b/packages/prio3/src/circuits/histogram.ts @@ -28,17 +28,17 @@ export class Histogram extends Circuit { const f = this.field; const rangeCheck = f.sum(input, (value, index) => - f.mul(f.exp(firstRand, BigInt(index + 1)), gadget.eval(f, [value])) + f.mul(f.exp(firstRand, BigInt(index + 1)), gadget.eval(f, [value])), ); const sumCheck = f.sum( [...input, f.mul(-1n, f.exp(BigInt(shares), -1n))], - (n) => n + (n) => n, ); return f.add( f.mul(secondRand, rangeCheck), - f.mul(f.exp(secondRand, 2n), sumCheck) + f.mul(f.exp(secondRand, 2n), sumCheck), ); } diff --git a/packages/prio3/src/circuits/proof.ts b/packages/prio3/src/circuits/proof.ts index 09652859b..975b9de31 100644 --- a/packages/prio3/src/circuits/proof.ts +++ b/packages/prio3/src/circuits/proof.ts @@ -57,8 +57,8 @@ export class Proof extends Circuit { new ProofGadget( proveRand.slice(proveRandIndex, (proveRandIndex += gadget.arity)), gadget, - this.gadgetCalls[index] - ) + this.gadgetCalls[index], + ), ); if (proveRand.length !== proveRandIndex) { diff --git a/packages/prio3/src/circuits/query.ts b/packages/prio3/src/circuits/query.ts index e02eac677..a7a1636a5 100644 --- a/packages/prio3/src/circuits/query.ts +++ b/packages/prio3/src/circuits/query.ts @@ -62,19 +62,19 @@ export class Query extends Circuit { wireSeeds, gadgetPoly, gadget, - calls + calls, ); }); if (proof.length !== this.proofLen) { throw new Error( - `expected proof length to be ${this.proofLen} but it was ${proof.length}` + `expected proof length to be ${this.proofLen} but it was ${proof.length}`, ); } if (proofIndex !== proof.length) { throw new Error( - `did not use all of proof (used ${proofIndex}/${proof.length})` + `did not use all of proof (used ${proofIndex}/${proof.length})`, ); } } diff --git a/packages/prio3/src/circuits/sum.ts b/packages/prio3/src/circuits/sum.ts index 20748df33..bf8e734f4 100644 --- a/packages/prio3/src/circuits/sum.ts +++ b/packages/prio3/src/circuits/sum.ts @@ -30,8 +30,8 @@ export class Sum extends Circuit { return field.sum(input, (value, index) => field.mul( field.exp(jointRandZero, BigInt(index + 1)), - poly.eval(field, [value]) - ) + poly.eval(field, [value]), + ), ); } @@ -43,7 +43,7 @@ export class Sum extends Circuit { throw new Error( `measurement ${measurement} was not an integer in [0, ${ 2 ** this.inputLen - })` + })`, ); } @@ -56,13 +56,13 @@ export class Sum extends Circuit { throw new Error( `measurement ${bigintMeasurement} was not an integer in [0, ${ 2 ** this.inputLen - })` + })`, ); } return arr( this.inputLen, - (index) => (bigintMeasurement >> BigInt(index)) & 1n + (index) => (bigintMeasurement >> BigInt(index)) & 1n, ); } @@ -70,7 +70,7 @@ export class Sum extends Circuit { const field = this.field; return [ field.sum(input, (value, index) => - field.mul(field.exp(2n, BigInt(index)), value) + field.mul(field.exp(2n, BigInt(index)), value), ), ]; } diff --git a/packages/prio3/src/flp.spec.ts b/packages/prio3/src/flp.spec.ts index 48c72eabd..9bd2e6e16 100644 --- a/packages/prio3/src/flp.spec.ts +++ b/packages/prio3/src/flp.spec.ts @@ -5,7 +5,7 @@ import { Flp } from "./flp"; export function runFlp( flp: Flp, input: bigint[], - shares: number + shares: number, ): boolean { const jointRand = flp.field.fillRandom(flp.jointRandLen); const proveRand = flp.field.fillRandom(flp.proveRandLen); @@ -60,7 +60,7 @@ class TestFlp implements Flp { _proof: bigint[], _queryRand: bigint[], _jointRand: bigint[], - _shares: number + _shares: number, ): bigint[] { return input; } diff --git a/packages/prio3/src/flp.ts b/packages/prio3/src/flp.ts index c23f74530..ab04353ec 100644 --- a/packages/prio3/src/flp.ts +++ b/packages/prio3/src/flp.ts @@ -19,7 +19,7 @@ export interface Flp { proof: bigint[], queryRand: bigint[], jointRand: bigint[], - shares: number + shares: number, ): bigint[]; decide(input: bigint[]): boolean; diff --git a/packages/prio3/src/gadget.ts b/packages/prio3/src/gadget.ts index 17ea37f8f..e5cbe356a 100644 --- a/packages/prio3/src/gadget.ts +++ b/packages/prio3/src/gadget.ts @@ -9,7 +9,7 @@ export abstract class Gadget { ensureArity(input: bigint[]) { if (input.length !== this.arity) { throw new Error( - `expected gadget input length (${input.length}) to equal arity (${this.arity}), but it did not` + `expected gadget input length (${input.length}) to equal arity (${this.arity}), but it did not`, ); } } diff --git a/packages/prio3/src/gadgets/query.ts b/packages/prio3/src/gadgets/query.ts index f2f464e91..b02e75425 100644 --- a/packages/prio3/src/gadgets/query.ts +++ b/packages/prio3/src/gadgets/query.ts @@ -14,7 +14,7 @@ export class Query extends Gadget { wireSeeds: bigint[], gadgetPoly: bigint[], gadget: Gadget, - calls: number + calls: number, ) { super(); this.gadget = gadget; @@ -28,7 +28,7 @@ export class Query extends Gadget { this.alpha = field.exp( field.generator, - field.genOrder / BigInt(wirePolyLength) + field.genOrder / BigInt(wirePolyLength), ); } @@ -41,7 +41,7 @@ export class Query extends Gadget { return field.evalPoly( this.gadgetPoly, - field.exp(this.alpha, BigInt(this.callCount)) + field.exp(this.alpha, BigInt(this.callCount)), ); } diff --git a/packages/prio3/src/genericFlp.spec.ts b/packages/prio3/src/genericFlp.spec.ts index 9c35e8d65..ede3d017f 100644 --- a/packages/prio3/src/genericFlp.spec.ts +++ b/packages/prio3/src/genericFlp.spec.ts @@ -32,7 +32,7 @@ function testCircuitGadgets(circuit: GenericCircuit) { function testCircuit( circuit: Circuit, input: bigint[], - expected: boolean + expected: boolean, ) { assert.equal(input.length, circuit.inputLen); assert.equal(circuit.truncate(input).length, circuit.outputLen); diff --git a/packages/prio3/src/genericFlp.ts b/packages/prio3/src/genericFlp.ts index ee42ca059..915ad5a1f 100644 --- a/packages/prio3/src/genericFlp.ts +++ b/packages/prio3/src/genericFlp.ts @@ -50,13 +50,13 @@ export class FlpGeneric implements Flp { const alpha = field.exp( this.field.generator, - this.field.genOrder / BigInt(p) + this.field.genOrder / BigInt(p), ); const wireInputs = arr(p, (k) => field.exp(alpha, BigInt(k))); const wirePolys = arr(gadget.arity, (j) => - this.field.interpolate(wireInputs, gadget.wire[j]) + this.field.interpolate(wireInputs, gadget.wire[j]), ); const gadgetPoly = gadget.evalPoly(field, wirePolys); @@ -78,7 +78,7 @@ export class FlpGeneric implements Flp { proof: bigint[], queryRand: bigint[], jointRand: bigint[], - shares: number + shares: number, ): bigint[] { const circuit = new Query(this.circuit, proof); const v = circuit.eval(input, jointRand, shares); @@ -86,7 +86,7 @@ export class FlpGeneric implements Flp { if (queryRand.length !== this.circuit.queryRandLen) { throw new Error( - `mismatched query rand length. expected ${this.circuit.queryRandLen} but got ${queryRand.length}` + `mismatched query rand length. expected ${this.circuit.queryRandLen} but got ${queryRand.length}`, ); } @@ -97,7 +97,7 @@ export class FlpGeneric implements Flp { if (field.exp(t, BigInt(p)) == 1n) { throw new Error( - "Degenerate point would leak gadget output to the verifier" + "Degenerate point would leak gadget output to the verifier", ); } @@ -105,19 +105,19 @@ export class FlpGeneric implements Flp { return [ ...verifier, ...gadget.wire.map((wire) => - field.evalPoly(field.interpolate(wireInput, wire), t) + field.evalPoly(field.interpolate(wireInput, wire), t), ), field.evalPoly(gadget.gadgetPoly, t), ]; }, - [v] + [v], ); } decide(verifier: bigint[]): boolean { if (verifier.length !== this.circuit.verifierLen) { throw new Error( - `expected verifier of length ${this.circuit.verifierLen} but got ${verifier.length}` + `expected verifier of length ${this.circuit.verifierLen} but got ${verifier.length}`, ); } @@ -138,7 +138,7 @@ export class FlpGeneric implements Flp { if (verifierIndex != this.circuit.verifierLen) { throw new Error( - `unused verifier (${verifierIndex} / ${this.circuit.verifierLen})` + `unused verifier (${verifierIndex} / ${this.circuit.verifierLen})`, ); } diff --git a/packages/prio3/src/prio3.spec.ts b/packages/prio3/src/prio3.spec.ts index d75c4164a..b9d26b7f2 100644 --- a/packages/prio3/src/prio3.spec.ts +++ b/packages/prio3/src/prio3.spec.ts @@ -29,7 +29,7 @@ describe("prio3 vdaf", () => { measurement: prep.measurement !== 0, })), }, - count + count, ); }); @@ -54,7 +54,7 @@ describe("prio3 vdaf", () => { assert.deepEqual(await histogram.test(null, [101]), [0, 0, 0, 1]); assert.deepEqual( await histogram.test(null, [0, 1, 5, 10, 15, 100, 101, 101]), - [2, 2, 2, 2] + [2, 2, 2, 2], ); assert.deepEqual(await histogram.test(null, [50]), [0, 0, 1, 0]); @@ -81,7 +81,7 @@ async function runPrio3( measurements: M[], nonces: Buffer[], verifyKey: Buffer, - rands: Buffer[] + rands: Buffer[], ): Promise> { const aggregationParameter = null; const testVector = await instantiation.run({ @@ -96,15 +96,15 @@ async function runPrio3( return { ...testVector, agg_shares: testVector.agg_shares.map((x) => - Buffer.from(field.encode(x)).toString("hex") + Buffer.from(field.encode(x)).toString("hex"), ), prep: testVector.prep.map((prep) => ({ ...prep, out_shares: prep.out_shares.map((outShare) => outShare.map((bigNumber) => - Buffer.from(field.encode([bigNumber])).toString("hex") - ) + Buffer.from(field.encode([bigNumber])).toString("hex"), + ), ), })), }; @@ -114,19 +114,19 @@ async function assertPrio3TestVector< Measurement, AggregationResult, TestVectorJson extends JsonTestVector, - Prio3Instantiation extends Prio3 + Prio3Instantiation extends Prio3, >( expectedTestVector: TestVectorJson, instantiation: Prio3Instantiation, - additional: { [key: string]: unknown } = {} + additional: { [key: string]: unknown } = {}, ) { const nonces = expectedTestVector.prep.map((prep) => - Buffer.from(prep.nonce, "hex") + Buffer.from(prep.nonce, "hex"), ); const verifyKey = Buffer.from(expectedTestVector.verify_key, "hex"); const measurements = expectedTestVector.prep.map((prep) => prep.measurement); const rands = measurements.map((_) => - Buffer.from(deterministicRandom(instantiation.randSize)) + Buffer.from(deterministicRandom(instantiation.randSize)), ); const actualTestVector = await runPrio3( @@ -134,7 +134,7 @@ async function assertPrio3TestVector< measurements, nonces, verifyKey, - rands + rands, ); assert.deepEqual({ ...actualTestVector, ...additional }, expectedTestVector); diff --git a/packages/prio3/src/prio3.ts b/packages/prio3/src/prio3.ts index 8ba0c82cc..d4313e1a4 100644 --- a/packages/prio3/src/prio3.ts +++ b/packages/prio3/src/prio3.ts @@ -56,7 +56,7 @@ export class Prio3 extends Vdaf< public readonly prg: PrgConstructor, public readonly flp: Flp, public readonly shares: number, - public readonly id: number + public readonly id: number, ) { super(); this.verifyKeySize = prg.seedSize; @@ -68,13 +68,13 @@ export class Prio3 extends Vdaf< async measurementToInputShares( measurement: Measurement, nonce: Buffer, - rand: Buffer + rand: Buffer, ): Promise { const { flp } = this; if (rand.length !== this.randSize) { throw new Error( - `rand length was ${rand.length} but must be ${this.randSize}` + `rand length was ${rand.length} but must be ${this.randSize}`, ); } @@ -84,7 +84,7 @@ export class Prio3 extends Vdaf< input, helperShares, nonce, - rand + rand, ); const { publicShare, jointRand } = await this.jointRand([ @@ -106,7 +106,7 @@ export class Prio3 extends Vdaf< _aggParam: AggregationParameter, nonce: Buffer, publicShare: Buffer, - encodedInputShare: Buffer + encodedInputShare: Buffer, ): Promise { const { prg, flp, field, shares } = this; const { jointRandLen } = flp; @@ -115,7 +115,7 @@ export class Prio3 extends Vdaf< const { blind, measurementShare, proofShare } = await this.decodeShare( aggregatorId, - encodedInputShare + encodedInputShare, ); const outputShare = flp.truncate(measurementShare); @@ -124,7 +124,7 @@ export class Prio3 extends Vdaf< flp.queryRandLen, Usage.QueryRandomness, verifyKey, - nonce + nonce, ); let jointRand: bigint[]; let correctedJointRand: Buffer; @@ -135,17 +135,17 @@ export class Prio3 extends Vdaf< jointRandParts[aggregatorId] = await this.deriveSeed( blind, Usage.JointRandPart, - [Uint8Array.of(aggregatorId), nonce, encoded] + [Uint8Array.of(aggregatorId), nonce, encoded], ); correctedJointRand = await this.deriveSeed( Buffer.alloc(prg.seedSize), Usage.JointRandSeed, - jointRandParts + jointRandParts, ); jointRand = await this.pseudorandom( jointRandLen, Usage.JointRandomness, - correctedJointRand + correctedJointRand, ); } else { jointRand = []; @@ -157,12 +157,12 @@ export class Prio3 extends Vdaf< proofShare, queryRand, jointRand, - shares + shares, ); const outboundMessage = this.encodePrepareShare( verifierShare, - jointRandParts[aggregatorId] + jointRandParts[aggregatorId], ); return { outputShare, correctedJointRand, outboundMessage }; @@ -170,7 +170,7 @@ export class Prio3 extends Vdaf< prepareNext( prepareState: PrepareState, - inbound: Buffer | null + inbound: Buffer | null, ): | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: OutputShare } { @@ -192,7 +192,7 @@ export class Prio3 extends Vdaf< prepSharesToPrepareMessage( _aggParam: AggregationParameter, - prepShares: Buffer[] + prepShares: Buffer[], ): Promise { const { flp, field, prg } = this; const { verifier, jointRandParts } = prepShares.reduce( @@ -204,7 +204,7 @@ export class Prio3 extends Vdaf< jointRandParts: [...jointRandParts, jointRandPart], }; }, - { verifier: fill(flp.verifierLen, 0n), jointRandParts: [] as Buffer[] } + { verifier: fill(flp.verifierLen, 0n), jointRandParts: [] as Buffer[] }, ); if (!flp.decide(verifier)) { @@ -215,7 +215,7 @@ export class Prio3 extends Vdaf< return this.deriveSeed( Buffer.alloc(prg.seedSize), Usage.JointRandSeed, - jointRandParts + jointRandParts, ); } else { return Promise.resolve(Buffer.alloc(0)); @@ -224,27 +224,27 @@ export class Prio3 extends Vdaf< outputSharesToAggregatorShare( _aggParam: AggregationParameter, - outShares: OutputShare[] + outShares: OutputShare[], ): AggregatorShare { const { field, flp } = this; return outShares.reduce( (agg, share) => field.vecAdd(agg, share), - fill(flp.outputLen, 0n) + fill(flp.outputLen, 0n), ); } aggregatorSharesToResult( _aggParam: AggregationParameter, aggShares: AggregatorShare[], - measurementCount: number + measurementCount: number, ): AggregationResult { const { field, flp } = this; return flp.decode( aggShares.reduce( (agg, share) => field.vecAdd(agg, share), - fill(flp.outputLen, 0n) + fill(flp.outputLen, 0n), ), - measurementCount + measurementCount, ); } @@ -252,7 +252,7 @@ export class Prio3 extends Vdaf< private async decodeShare( aggregatorId: number, - encoded: Buffer + encoded: Buffer, ): Promise { return aggregatorId == 0 ? this.decodeLeaderShare(encoded) @@ -274,7 +274,7 @@ export class Prio3 extends Vdaf< encodedSize * verifierLen + (this.useJointRand() ? seedSize : 0); if (input.length !== expectedLength) { throw new Error( - `expected prepare share to be ${expectedLength} bytes, but was ${input.length}` + `expected prepare share to be ${expectedLength} bytes, but was ${input.length}`, ); } @@ -285,7 +285,7 @@ export class Prio3 extends Vdaf< private encodePrepareShare( verifier: bigint[], - jointRandPart: Buffer | null + jointRandPart: Buffer | null, ): Buffer { const verifierEncoded = this.field.encode(verifier); @@ -300,7 +300,7 @@ export class Prio3 extends Vdaf< const { prg } = this; if (encoded.length !== (this.useJointRand() ? prg.seedSize : 0)) { throw new Error( - `expected prepare message to be ${prg.seedSize} bytes, but was ${encoded.length}` + `expected prepare message to be ${prg.seedSize} bytes, but was ${encoded.length}`, ); } return encoded; @@ -309,14 +309,14 @@ export class Prio3 extends Vdaf< private async deriveSeed( seed: Buffer, usage: Usage, - parts: Uint8Array[] + parts: Uint8Array[], ): Promise { return Buffer.from( await this.prg.deriveSeed( seed, this.domainSeparationTag(usage), - concat(parts) - ) + concat(parts), + ), ); } @@ -324,22 +324,22 @@ export class Prio3 extends Vdaf< input: bigint[], helperShares: Share[], nonce: Buffer, - rand: Buffer + rand: Buffer, ): Promise> { const { prg, field } = this; const measurementShare = helperShares.reduce( (measurementShare, helper) => field.vecSub(measurementShare, helper.measurementShare), - input + input, ); const wireMeasurementShare = Buffer.from( - this.field.encode(measurementShare) + this.field.encode(measurementShare), ); if (this.useJointRand()) { const blind = rand.subarray( helperShares.length * 3 * prg.seedSize, - (helperShares.length * 3 + 1) * prg.seedSize + (helperShares.length * 3 + 1) * prg.seedSize, ); const jointRandSeed = await this.deriveSeed(blind, Usage.JointRandPart, [ @@ -367,12 +367,12 @@ export class Prio3 extends Vdaf< private addProof( proof: bigint[], leader: Omit, - helpers: Share[] + helpers: Share[], ): Share[] { const { field } = this; const proofShare = helpers.reduce( (proofShare, helper) => field.vecSub(proofShare, helper.proofShare), - proof + proof, ); const wireProofShare = Buffer.from(field.encode(proofShare)); @@ -398,15 +398,15 @@ export class Prio3 extends Vdaf< [wireMeasurementShare, wireProofShare, blind] = arr(3, (offset) => rand.subarray( seedSize * (share * 3 + offset), - seedSize * (share * 3 + offset + 1) - ) + seedSize * (share * 3 + offset + 1), + ), ); } else { [wireMeasurementShare, wireProofShare] = arr(2, (offset) => rand.subarray( seedSize * (share * 2 + offset), - seedSize * (share * 2 + offset + 1) - ) + seedSize * (share * 2 + offset + 1), + ), ); blind = Buffer.alloc(0); } @@ -417,14 +417,14 @@ export class Prio3 extends Vdaf< inputLen, Usage.MeasurementShare, wireMeasurementShare, - shareId + shareId, ); const proofShare = await this.pseudorandom( proofLen, Usage.ProofShare, wireProofShare, - shareId + shareId, ); const jointRandSeed = this.useJointRand() @@ -443,7 +443,7 @@ export class Prio3 extends Vdaf< proofShare, jointRandSeed, }; - }) + }), ); } @@ -467,18 +467,18 @@ export class Prio3 extends Vdaf< (this.useJointRand() ? seedSize : 0); if (encoded.length != expectedLength) { throw new Error( - `expected leader share to be ${expectedLength} bytes but it was ${encoded.length}` + `expected leader share to be ${expectedLength} bytes but it was ${encoded.length}`, ); } const measurementShare = field.decode( - encoded.subarray(0, encodedSize * inputLen) + encoded.subarray(0, encodedSize * inputLen), ); const proofShare = field.decode( encoded.subarray( encodedSize * inputLen, - encodedSize * (inputLen + proofLen) - ) + encodedSize * (inputLen + proofLen), + ), ); const blind = encoded.subarray(encodedSize * (inputLen + proofLen)); @@ -487,7 +487,7 @@ export class Prio3 extends Vdaf< private async decodeHelperShare( aggregatorId: number, - encoded: Buffer + encoded: Buffer, ): Promise { const { prg, flp } = this; const { seedSize } = prg; @@ -496,7 +496,7 @@ export class Prio3 extends Vdaf< const expectedLength = seedSize * (this.useJointRand() ? 3 : 2); if (encoded.length != expectedLength) { throw new Error( - `expected helper share to be ${expectedLength} bytes but it was ${encoded.length}` + `expected helper share to be ${expectedLength} bytes but it was ${encoded.length}`, ); } @@ -504,14 +504,14 @@ export class Prio3 extends Vdaf< inputLen, Usage.MeasurementShare, encoded.subarray(0, seedSize), - aggregatorId + aggregatorId, ); const proofShare = await this.pseudorandom( proofLen, Usage.ProofShare, encoded.subarray(seedSize, seedSize * 2), - aggregatorId + aggregatorId, ); const blind = encoded.subarray(2 * seedSize); @@ -523,7 +523,7 @@ export class Prio3 extends Vdaf< len: number, usage: Usage, seed: Buffer, - binder?: number | Buffer + binder?: number | Buffer, ): Promise { const { prg, field } = this; return prg.expandIntoVec( @@ -533,7 +533,7 @@ export class Prio3 extends Vdaf< typeof binder === "number" ? Buffer.of(binder) : binder || Buffer.alloc(0), - len + len, ); } @@ -551,12 +551,12 @@ export class Prio3 extends Vdaf< return this.pseudorandom( flp.proveRandLen, Usage.ProveRandomness, - rand.subarray(proveIndex * seedSize, (proveIndex + 1) * seedSize) + rand.subarray(proveIndex * seedSize, (proveIndex + 1) * seedSize), ); } private async jointRand( - shares: { jointRandSeed: Buffer }[] + shares: { jointRandSeed: Buffer }[], ): Promise<{ jointRand: bigint[]; publicShare: Buffer }> { if (!this.useJointRand()) { return { jointRand: [], publicShare: Buffer.alloc(0) }; @@ -566,14 +566,14 @@ export class Prio3 extends Vdaf< const jointRandSeed = await this.deriveSeed( Buffer.alloc(prg.seedSize), Usage.JointRandSeed, - seeds + seeds, ); const publicShare = Buffer.concat(seeds); const jointRand = await this.pseudorandom( flp.jointRandLen, Usage.JointRandomness, - jointRandSeed + jointRandSeed, ); return { jointRand, publicShare }; @@ -593,12 +593,12 @@ export class Prio3 extends Vdaf< throw new Error( `unexpected public share length ${encoded.length}, expected ${ seedSize * shares - }` + }`, ); return { jointRandParts: arr(shares, (share) => - encoded.subarray(share * seedSize, (share + 1) * seedSize) + encoded.subarray(share * seedSize, (share + 1) * seedSize), ), }; } diff --git a/packages/vdaf/src/index.spec.ts b/packages/vdaf/src/index.spec.ts index 2f5594a8f..9251e5099 100644 --- a/packages/vdaf/src/index.spec.ts +++ b/packages/vdaf/src/index.spec.ts @@ -33,7 +33,7 @@ export class VdafTest extends Vdaf< async measurementToInputShares( measurement: Measurement, _nonce: Buffer, - rand: Buffer + rand: Buffer, ): Promise { const { field, shares } = this; const helperShares = await PrgSha3.expandIntoVec( @@ -41,11 +41,11 @@ export class VdafTest extends Vdaf< rand, Buffer.alloc(0), Buffer.alloc(0), - shares - 1 + shares - 1, ); const leaderShare = helperShares.reduce( (ls, hs) => field.sub(ls, hs), - BigInt(measurement) + BigInt(measurement), ); return Promise.resolve({ @@ -62,7 +62,7 @@ export class VdafTest extends Vdaf< _aggParam: AggregationParameter, _nonce: Buffer, _publicShare: Buffer, - inputShare: Buffer + inputShare: Buffer, ): Promise { return Promise.resolve({ inputRange: this.inputRange, @@ -72,7 +72,7 @@ export class VdafTest extends Vdaf< prepareNext( prepareState: PrepareState, - inbound: Buffer | null + inbound: Buffer | null, ): | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: bigint[] } { @@ -91,33 +91,33 @@ export class VdafTest extends Vdaf< prepSharesToPrepareMessage( _aggParam: AggregationParameter, - prepShares: Buffer[] + prepShares: Buffer[], ): Promise { const { field } = this; return Promise.resolve( Buffer.from( field.encode([ field.sum(prepShares, (encoded) => field.decode(encoded)[0]), - ]) - ) + ]), + ), ); } outputSharesToAggregatorShare( _aggParam: null, - outShares: bigint[][] + outShares: bigint[][], ): Buffer { return Buffer.from( - this.field.encode([this.field.sum(outShares, (share) => share[0])]) + this.field.encode([this.field.sum(outShares, (share) => share[0])]), ); } aggregatorSharesToResult( _aggParam: AggregationParameter, - aggShares: Buffer[] + aggShares: Buffer[], ): AggregationResult { return Number( - this.field.sum(aggShares, (aggShare) => this.field.decode(aggShare)[0]) + this.field.sum(aggShares, (aggShare) => this.field.decode(aggShare)[0]), ); } } diff --git a/packages/vdaf/src/index.ts b/packages/vdaf/src/index.ts index b0bc2f15f..c511d1b29 100644 --- a/packages/vdaf/src/index.ts +++ b/packages/vdaf/src/index.ts @@ -16,7 +16,7 @@ export abstract class Vdaf< PrepareState, AggregatorShare, AggregationResult, - OutputShare + OutputShare, > { abstract id: number; abstract shares: number; @@ -28,7 +28,7 @@ export abstract class Vdaf< abstract measurementToInputShares( measurement: Measurement, nonce: Buffer, - rand: Buffer + rand: Buffer, ): Promise; abstract initialPrepareState( @@ -37,30 +37,30 @@ export abstract class Vdaf< aggParam: AggregationParameter, nonce: Buffer, publicShare: Buffer, - inputShare: Buffer + inputShare: Buffer, ): Promise; abstract prepareNext( prepareState: PrepareState, - inbound: Buffer | null + inbound: Buffer | null, ): | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: OutputShare }; abstract prepSharesToPrepareMessage( aggParam: AggregationParameter, - prepShares: Buffer[] + prepShares: Buffer[], ): Promise; abstract outputSharesToAggregatorShare( aggParam: AggregationParameter, - outShares: OutputShare[] + outShares: OutputShare[], ): AggregatorShare; abstract aggregatorSharesToResult( aggParam: AggregationParameter, aggShares: AggregatorShare[], - measurementCount: number + measurementCount: number, ): AggregationResult; domainSeparationTag(usage: number): Buffer { @@ -100,7 +100,7 @@ export abstract class Vdaf< async test( aggregationParameter: AggregationParameter, - measurements: Measurement[] + measurements: Measurement[], ): Promise { return (await this.run({ aggregationParameter, measurements })).agg_result; } @@ -115,7 +115,7 @@ export interface ClientVdaf { measurementToInputShares( measurement: Measurement, nonce: Buffer, - rand: Buffer + rand: Buffer, ): Promise; } @@ -133,7 +133,7 @@ interface RunVdafArguments { } export async function runVdaf( - args: RunVdafArguments + args: RunVdafArguments, ): Promise> { const { vdaf, aggregationParameter, measurements } = args; const { verifyKeySize, randSize, nonceSize, rounds, shares } = vdaf; @@ -154,7 +154,7 @@ export async function runVdaf( const { publicShare, inputShares } = await vdaf.measurementToInputShares( measurement, nonce, - rand + rand, ); const prepTestVector: PrepTestVector = { @@ -175,9 +175,9 @@ export async function runVdaf( aggregationParameter, nonce, publicShare, - inputShares[aggregatorId] - ) - ) + inputShares[aggregatorId], + ), + ), ); let inbound: Buffer | null = null; @@ -190,14 +190,14 @@ export async function runVdaf( } states[aggregatorId] = out.prepareState; return out.prepareShare; - } + }, ); prepTestVector.prep_shares[round] = outbound.map(hex); inbound = await vdaf.prepSharesToPrepareMessage( aggregationParameter, - outbound + outbound, ); prepTestVector.prep_messages = [hex(inbound)]; @@ -212,18 +212,18 @@ export async function runVdaf( }); testVector.prep.push(prepTestVector); return prepTestVector.out_shares; - }) + }), ); const aggregatorShares = arr(shares, (aggregatorId) => { const aggregatorOutShares = outShares.reduce( (aggregatorOutShares, out) => [...aggregatorOutShares, out[aggregatorId]], - [] as OS[] + [] as OS[], ); const aggregatorShare = vdaf.outputSharesToAggregatorShare( aggregationParameter, - aggregatorOutShares + aggregatorOutShares, ); testVector.agg_shares.push(aggregatorShare); @@ -233,7 +233,7 @@ export async function runVdaf( const agg_result = vdaf.aggregatorSharesToResult( aggregationParameter, aggregatorShares, - measurements.length + measurements.length, ); return { ...testVector, agg_result }; @@ -260,7 +260,7 @@ export interface PrepTestVector { export function formatDomainSeparationTag( algorithmClass: number, algorithm: number, - usage: number + usage: number, ): Buffer { const buffer = Buffer.alloc(8); buffer.writeUInt8(VDAF_VERSION_NUMBER, 0);