Skip to content

Commit

Permalink
deps(dev): bump aegir from 37.12.1 to 38.1.7 (libp2p#84)
Browse files Browse the repository at this point in the history
* 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](ipfs/aegir@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] <[email protected]>

* chore: fix linting and deps

* chore: fix test

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
dependabot[bot] and achingbrain authored Mar 10, 2023
1 parent 3982918 commit 4cc5935
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -176,7 +176,7 @@
},
"devDependencies": {
"@libp2p/crypto": "^1.0.11",
"aegir": "^37.9.1",
"aegir": "^38.1.7",
"protons": "^6.0.0"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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' +
Expand Down
6 changes: 3 additions & 3 deletions src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const key = record.key
const keyString = uint8ArrayToString(key)
const parts = keyString.split('/')
Expand All @@ -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)
}

/**
Expand All @@ -40,7 +40,7 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
* @param {Uint8Array} key - A valid key is of the form `'/pk/<keymultihash>'`
* @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<void> => {
if (!(key instanceof Uint8Array)) {
throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
}
Expand Down
19 changes: 9 additions & 10 deletions test/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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())

Expand All @@ -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/
)
})
})

Expand All @@ -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)
}))
})

Expand All @@ -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)
})
})
})

0 comments on commit 4cc5935

Please sign in to comment.