From 4cc593576ccda281950f30aa6c8e769baa1aeee6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Mar 2023 10:43:43 +0100 Subject: [PATCH] deps(dev): bump aegir from 37.12.1 to 38.1.7 (#84) * deps(dev): bump aegir from 37.12.1 to 38.1.7 Bumps [aegir](https://github.com/ipfs/aegir) from 37.12.1 to 38.1.7. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v37.12.1...v38.1.7) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * chore: fix linting and deps * chore: fix test --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain --- package.json | 4 ++-- src/index.ts | 8 ++++---- src/selectors.ts | 4 ++-- src/utils.ts | 4 ++-- src/validators.ts | 6 +++--- test/validator.spec.ts | 19 +++++++++---------- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 28f75b7..63e2191 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "scripts": { "clean": "aegir clean", "lint": "aegir lint", - "dep-check": "aegir dep-check", + "dep-check": "aegir dep-check -i protons", "test": "aegir test", "test:node": "aegir test -t node", "test:chrome": "aegir test -t browser", @@ -176,7 +176,7 @@ }, "devDependencies": { "@libp2p/crypto": "^1.0.11", - "aegir": "^37.9.1", + "aegir": "^38.1.7", "protons": "^6.0.0" } } diff --git a/src/index.ts b/src/index.ts index db154db..d6e9ec3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,14 +23,14 @@ export class Libp2pRecord { this.timeReceived = timeReceived } - serialize () { + serialize (): Uint8Array { return Record.encode(this.prepareSerialize()) } /** * Return the object format ready to be given to the protobuf library. */ - prepareSerialize () { + prepareSerialize (): Record { return { key: this.key, value: this.value, @@ -41,7 +41,7 @@ export class Libp2pRecord { /** * Decode a protobuf encoded record */ - static deserialize (raw: Uint8Array | Uint8ArrayList) { + static deserialize (raw: Uint8Array | Uint8ArrayList): Libp2pRecord { const rec = Record.decode(raw) return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived)) @@ -50,7 +50,7 @@ export class Libp2pRecord { /** * Create a record from the raw object returned from the protobuf library */ - static fromDeserialized (obj: Record) { + static fromDeserialized (obj: Record): Libp2pRecord { const recvtime = utils.parseRFC3339(obj.timeReceived) if (obj.key == null) { diff --git a/src/selectors.ts b/src/selectors.ts index 3a3fe06..ed28d01 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -5,7 +5,7 @@ import type { Selectors } from '@libp2p/interface-dht' /** * Select the best record out of the given records */ -export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]) { +export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number { if (records.length === 0) { const errMsg = 'No records given' @@ -41,7 +41,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A * Simply returns the first record, as all valid public key * records are equal */ -function publickKey (k: Uint8Array, records: Uint8Array[]) { +function publickKey (k: Uint8Array, records: Uint8Array[]): number { return 0 } diff --git a/src/utils.ts b/src/utils.ts index 34ce927..b9ee448 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ * Convert a JavaScript date into an `RFC3339Nano` formatted * string */ -export function toRFC3339 (time: Date) { +export function toRFC3339 (time: Date): string { const year = time.getUTCFullYear() const month = String(time.getUTCMonth() + 1).padStart(2, '0') const day = String(time.getUTCDate()).padStart(2, '0') @@ -19,7 +19,7 @@ export function toRFC3339 (time: Date) { * Parses a date string formatted as `RFC3339Nano` into a * JavaScript Date object */ -export function parseRFC3339 (time: string) { +export function parseRFC3339 (time: string): Date { const rfc3339Matcher = new RegExp( // 2006-01-02T '(\\d{4})-(\\d{2})-(\\d{2})T' + diff --git a/src/validators.ts b/src/validators.ts index 298433f..3296460 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -10,7 +10,7 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals' * It runs the needed validators. * If verification fails the returned Promise will reject with the error. */ -export function verifyRecord (validators: Validators, record: Libp2pRecord) { +export async function verifyRecord (validators: Validators, record: Libp2pRecord): Promise { const key = record.key const keyString = uint8ArrayToString(key) const parts = keyString.split('/') @@ -28,7 +28,7 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) { throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE') } - return validator(key, record.value) + await validator(key, record.value) } /** @@ -40,7 +40,7 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) { * @param {Uint8Array} key - A valid key is of the form `'/pk/'` * @param {Uint8Array} publicKey - The public key to validate against (protobuf encoded). */ -const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) => { +const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array): Promise => { if (!(key instanceof Uint8Array)) { throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER') } diff --git a/test/validator.spec.ts b/test/validator.spec.ts index 3340bb5..e73ccc2 100644 --- a/test/validator.spec.ts +++ b/test/validator.spec.ts @@ -62,7 +62,7 @@ describe('validator', () => { }) describe('verifyRecord', () => { - it('calls matching validator', () => { + it('calls matching validator', async () => { const k = uint8ArrayFromString('/hello/you') const rec = new Libp2pRecord(k, uint8ArrayFromString('world'), new Date()) @@ -72,10 +72,10 @@ describe('validator', () => { expect(value).to.eql(uint8ArrayFromString('world')) } } - return validator.verifyRecord(validators, rec) + await validator.verifyRecord(validators, rec) }) - it('calls not matching any validator', () => { + it('calls not matching any validator', async () => { const k = uint8ArrayFromString('/hallo/you') const rec = new Libp2pRecord(k, uint8ArrayFromString('world'), new Date()) @@ -85,11 +85,10 @@ describe('validator', () => { expect(value).to.eql(uint8ArrayFromString('world')) } } - return expect( - () => validator.verifyRecord(validators, rec) - ).to.throw( - /Invalid record keytype/ - ) + await expect(validator.verifyRecord(validators, rec)) + .to.eventually.rejectedWith( + /Invalid record keytype/ + ) }) }) @@ -107,7 +106,7 @@ describe('validator', () => { it('does not error on valid record', async () => { return await Promise.all(cases.valid.publicKey.map(async (k) => { - return await validator.validators.pk(k, key.public.bytes) + await validator.validators.pk(k, key.public.bytes) })) }) @@ -132,7 +131,7 @@ describe('validator', () => { const hash = await pubKey.hash() const k = Uint8Array.of(...uint8ArrayFromString('/pk/'), ...hash) - return await validator.validators.pk(k, pubKey.bytes) + await validator.validators.pk(k, pubKey.bytes) }) }) })